Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the addition and deletion of Miscellaneous files to the Buffer Manager #1277

Merged
merged 8 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions OmniSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Stdio.Driver", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Script.Tests", "tests\OmniSharp.Script.Tests\OmniSharp.Script.Tests.csproj", "{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.MiscellaneousFiles", "src\OmniSharp.MiscellaneousFiles\OmniSharp.MiscellaneousFiles.csproj", "{49358F28-883B-4FA0-B853-8774A732E188}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.MiscellaneousFiles.Tests", "tests\OmniSharp.MiscellaneousFiles.Tests\OmniSharp.MiscellaneousFiles.Tests.csproj", "{51F1D224-A543-48C5-BD37-139B935E71D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -395,30 +391,6 @@ Global
{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}.Release|x64.Build.0 = Release|Any CPU
{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}.Release|x86.ActiveCfg = Release|Any CPU
{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}.Release|x86.Build.0 = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|x64.ActiveCfg = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|x64.Build.0 = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|x86.ActiveCfg = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Debug|x86.Build.0 = Debug|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|Any CPU.Build.0 = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|x64.ActiveCfg = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|x64.Build.0 = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|x86.ActiveCfg = Release|Any CPU
{49358F28-883B-4FA0-B853-8774A732E188}.Release|x86.Build.0 = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|x64.ActiveCfg = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|x64.Build.0 = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Debug|x86.Build.0 = Debug|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|Any CPU.Build.0 = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|x64.ActiveCfg = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|x64.Build.0 = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|x86.ActiveCfg = Release|Any CPU
{51F1D224-A543-48C5-BD37-139B935E71D8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -450,8 +422,6 @@ Global
{BC640CBF-F6E2-42EA-9D61-FB6E515AEA44} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{D2A78CEE-B278-476F-AF34-A7D6F792F973} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
{49358F28-883B-4FA0-B853-8774A732E188} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{51F1D224-A543-48C5-BD37-139B935E71D8} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E}
Expand Down
7 changes: 0 additions & 7 deletions src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/OmniSharp.Abstractions/Services/IUpdates.cs

This file was deleted.

7 changes: 1 addition & 6 deletions src/OmniSharp.DotNet/DotNetProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace OmniSharp.DotNet
{
[ExportProjectSystem(ProjectSystemNames.DotNetProjectSystem), Shared]
public class DotNetProjectSystem : IWaitableProjectSystem
public class DotNetProjectSystem : IProjectSystem
{
private const string CompilationConfiguration = "Debug";

Expand Down Expand Up @@ -424,10 +424,5 @@ private static LanguageVersion ParseLanguageVersion(string value)

return languageVersion;
}

async Task IWaitableProjectSystem.WaitForUpdatesAsync()
{
await ((IProjectSystem)this).GetWorkspaceModelAsync(new WorkspaceInformationRequest());
}
}
}
8 changes: 3 additions & 5 deletions src/OmniSharp.Host/WorkspaceInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public static void Initialize(

var projectEventForwarder = compositionHost.GetExport<ProjectEventForwarder>();
projectEventForwarder.Initialize();
var projectSystems = compositionHost.GetExports<Lazy<IProjectSystem, ProjectSystemMetadata>>();
var ps = projectSystems.Select(n => n.Value);
var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList<IProjectSystem, ExportProjectSystemAttribute>(ps, eps => eps.Name);

foreach (var projectSystem in orderedProjectSystems)
var projectSystems = compositionHost.GetExports<IProjectSystem>();

foreach (var projectSystem in projectSystems)
{
try
{
Expand Down
7 changes: 1 addition & 6 deletions src/OmniSharp.MSBuild/ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace OmniSharp.MSBuild
{
[ExportProjectSystem(ProjectSystemNames.MSBuildProjectSystem), Shared]
public class ProjectSystem : IWaitableProjectSystem
public class ProjectSystem : IProjectSystem
{
private readonly IOmniSharpEnvironment _environment;
private readonly OmniSharpWorkspace _workspace;
Expand Down Expand Up @@ -210,10 +210,5 @@ async Task<object> IProjectSystem.GetProjectModelAsync(string filePath)

return new MSBuildProjectInfo(projectFileInfo);
}

public async Task WaitForUpdatesAsync()
{
await _manager.WaitForQueueEmptyAsync();
}
}
}
111 changes: 0 additions & 111 deletions src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs

This file was deleted.

This file was deleted.

63 changes: 42 additions & 21 deletions src/OmniSharp.Roslyn/BufferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.FileWatching;
using OmniSharp.Models;
using OmniSharp.Models.ChangeBuffer;
using OmniSharp.Models.UpdateBuffer;
Expand All @@ -17,11 +18,15 @@ public class BufferManager
private readonly IDictionary<string, IEnumerable<DocumentId>> _transientDocuments = new Dictionary<string, IEnumerable<DocumentId>>(StringComparer.OrdinalIgnoreCase);
private readonly ISet<DocumentId> _transientDocumentIds = new HashSet<DocumentId>();
private readonly object _lock = new object();
private readonly IFileSystemWatcher _fileSystemWatcher;
private readonly Action<string, FileChangeType> _onFileChanged;

public BufferManager(OmniSharpWorkspace workspace)
public BufferManager(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher)
{
_workspace = workspace;
_workspace.WorkspaceChanged += OnWorkspaceChanged;
_fileSystemWatcher = fileSystemWatcher;
_onFileChanged = OnFileChanged;
}

public async Task UpdateBufferAsync(Request request)
Expand Down Expand Up @@ -128,37 +133,53 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
var projects = FindProjectsByFileName(fileName);
if (!projects.Any())
{
if (fileName.EndsWith(".cs") && _workspace.TryAddMiscellaneousDocument(fileName, LanguageNames.CSharp) != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say something about adding .csx here but they have different project rules anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be doing a case-insensitive EndsWith here to ensure that we also catch .CS.

{
_fileSystemWatcher.Watch(fileName, OnFileChanged);
return true;
}

return false;
}

var sourceText = SourceText.From(fileContent);
var documentInfos = new List<DocumentInfo>();
foreach (var project in projects)
else
{
var id = DocumentId.CreateNewId(project.Id);
var version = VersionStamp.Create();
var documentInfo = DocumentInfo.Create(
id, fileName, filePath: fileName,
loader: TextLoader.From(TextAndVersion.Create(sourceText, version)));
var sourceText = SourceText.From(fileContent);
var documentInfos = new List<DocumentInfo>();
foreach (var project in projects)
{
var id = DocumentId.CreateNewId(project.Id);
var version = VersionStamp.Create();
var documentInfo = DocumentInfo.Create(
id, fileName, filePath: fileName,
loader: TextLoader.From(TextAndVersion.Create(sourceText, version)));

documentInfos.Add(documentInfo);
}
documentInfos.Add(documentInfo);
}

lock (_lock)
{
var documentIds = documentInfos.Select(document => document.Id);
_transientDocuments.Add(fileName, documentIds);
_transientDocumentIds.UnionWith(documentIds);
}
lock (_lock)
{
var documentIds = documentInfos.Select(document => document.Id);
_transientDocuments.Add(fileName, documentIds);
_transientDocumentIds.UnionWith(documentIds);
}

foreach (var documentInfo in documentInfos)
{
_workspace.AddDocument(documentInfo);
foreach (var documentInfo in documentInfos)
{
_workspace.AddDocument(documentInfo);
}
}

return true;
}

private void OnFileChanged(string filePath, FileChangeType changeType)
{
if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || changeType == FileChangeType.Delete)
{
_workspace.TryRemoveMiscellaneousDocument(filePath);
}
}

private IEnumerable<Project> FindProjectsByFileName(string fileName)
{
var fileInfo = new FileInfo(fileName);
Expand Down
5 changes: 3 additions & 2 deletions src/OmniSharp.Roslyn/OmniSharpWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using OmniSharp.FileWatching;
using OmniSharp.Roslyn;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Utilities;
Expand All @@ -26,10 +27,10 @@ public class OmniSharpWorkspace : Workspace
private readonly ConcurrentDictionary<string, ProjectInfo> miscDocumentsProjectInfos = new ConcurrentDictionary<string, ProjectInfo>();

[ImportingConstructor]
public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory)
public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory, IFileSystemWatcher fileSystemWatcher)
: base(aggregator.CreateHostServices(), "Custom")
{
BufferManager = new BufferManager(this);
BufferManager = new BufferManager(this, fileSystemWatcher);
_logger = loggerFactory.CreateLogger<OmniSharpWorkspace>();
}

Expand Down
1 change: 0 additions & 1 deletion src/OmniSharp.Stdio/OmniSharp.Stdio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<ItemGroup>
<ProjectReference Include="..\OmniSharp.LanguageServerProtocol\OmniSharp.LanguageServerProtocol.csproj" />
<ProjectReference Include="..\OmniSharp.Host\OmniSharp.Host.csproj" />
<ProjectReference Include="..\OmniSharp.MiscellaneousFiles\OmniSharp.MiscellaneousFiles.csproj" />
<ProjectReference Include="..\OmniSharp.Roslyn.CSharp\OmniSharp.Roslyn.CSharp.csproj" />
<ProjectReference Include="..\OmniSharp.DotNet\OmniSharp.DotNet.csproj" />
<ProjectReference Include="..\OmniSharp.DotNetTest\OmniSharp.DotNetTest.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion tests/OmniSharp.Cake.Tests/LineIndexHelperFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static OmniSharpWorkspace CreateSimpleWorkspace(string fileName, string
var workspace = new OmniSharpWorkspace(
new HostServicesAggregator(
Enumerable.Empty<IHostServicesProvider>(), new LoggerFactory()),
new LoggerFactory());
new LoggerFactory(), null);

var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(),
"ProjectNameVal", "AssemblyNameVal", LanguageNames.CSharp);
Expand Down
1 change: 0 additions & 1 deletion tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs

This file was deleted.

Loading