diff --git a/OmniSharp.sln b/OmniSharp.sln index 76a7afeab5..c7744573da 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -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 @@ -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 @@ -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} diff --git a/src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs b/src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs deleted file mode 100644 index ef2498dea3..0000000000 --- a/src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace OmniSharp.Mef -{ - public class ProjectSystemMetadata - { - public string Name { get; set; } - } -} diff --git a/src/OmniSharp.Abstractions/Services/IUpdates.cs b/src/OmniSharp.Abstractions/Services/IUpdates.cs deleted file mode 100644 index 4c70f27a1d..0000000000 --- a/src/OmniSharp.Abstractions/Services/IUpdates.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace OmniSharp.Services -{ - public interface IWaitableProjectSystem: IProjectSystem - { - Task WaitForUpdatesAsync(); - } -} diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index cb57bb455c..796deda7dc 100644 --- a/src/OmniSharp.DotNet/DotNetProjectSystem.cs +++ b/src/OmniSharp.DotNet/DotNetProjectSystem.cs @@ -25,7 +25,7 @@ namespace OmniSharp.DotNet { [ExportProjectSystem(ProjectSystemNames.DotNetProjectSystem), Shared] - public class DotNetProjectSystem : IWaitableProjectSystem + public class DotNetProjectSystem : IProjectSystem { private const string CompilationConfiguration = "Debug"; @@ -424,10 +424,5 @@ private static LanguageVersion ParseLanguageVersion(string value) return languageVersion; } - - async Task IWaitableProjectSystem.WaitForUpdatesAsync() - { - await ((IProjectSystem)this).GetWorkspaceModelAsync(new WorkspaceInformationRequest()); - } } } diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 2e4b82f130..cc1247c072 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -27,11 +27,9 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); - var projectSystems = compositionHost.GetExports>(); - var ps = projectSystems.Select(n => n.Value); - var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); - - foreach (var projectSystem in orderedProjectSystems) + var projectSystems = compositionHost.GetExports(); + + foreach (var projectSystem in projectSystems) { try { diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index d86f0d5a72..74ba90e759 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -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; @@ -210,10 +210,5 @@ async Task IProjectSystem.GetProjectModelAsync(string filePath) return new MSBuildProjectInfo(projectFileInfo); } - - public async Task WaitForUpdatesAsync() - { - await _manager.WaitForQueueEmptyAsync(); - } } } diff --git a/src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs b/src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs deleted file mode 100644 index 054fb93707..0000000000 --- a/src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Composition; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using OmniSharp.FileSystem; -using OmniSharp.FileWatching; -using OmniSharp.Mef; -using OmniSharp.Models.WorkspaceInformation; -using OmniSharp.Services; - -namespace OmniSharp.MiscellaneousFile -{ - [ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)] - [ExtensionOrder(After = ProjectSystemNames.DotNetProjectSystem)] - [ExportProjectSystem(ProjectSystemNames.MiscellaneousFilesProjectSystem), Shared] - public class MiscellaneousFilesProjectSystem : IProjectSystem - { - private const string miscFileExtension = ".cs"; - public string Key => ProjectSystemNames.MiscellaneousFilesProjectSystem; - public string Language => LanguageNames.CSharp; - IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; - public bool EnabledByDefault { get; } = true; - - private readonly OmniSharpWorkspace _workspace; - private readonly IFileSystemWatcher _fileSystemWatcher; - private readonly FileSystemHelper _fileSystemHelper; - private readonly List _projectSystems; - private readonly ILogger _logger; - - [ImportingConstructor] - public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, - ILoggerFactory loggerFactory, [ImportMany] IEnumerable> projectSystems) - { - _workspace = workspace; - _fileSystemWatcher = fileSystemWatcher; - _fileSystemHelper = fileSystemHelper; - _logger = loggerFactory.CreateLogger(); - _projectSystems = projectSystems - .Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || - ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem) - .Select(ps => ps.Value) - .Cast() - .ToList(); - } - - Task IProjectSystem.GetProjectModelAsync(string filePath) - { - return Task.FromResult(null); - } - - Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request) - { - return Task.FromResult(null); - } - - void IProjectSystem.Initalize(IConfiguration configuration) - { - var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); - foreach (var filePath in allFiles) - TryAddMiscellaneousFile(filePath); - - _fileSystemWatcher.Watch(miscFileExtension, OnMiscellaneousFileChanged); - } - - private async void TryAddMiscellaneousFile(string filePath) - { - //wait for the project systems to finish processing the updates - foreach (var projectSystem in _projectSystems) - { - await projectSystem.WaitForUpdatesAsync(); - } - - var absoluteFilePath = new FileInfo(filePath).FullName; - if (!File.Exists(absoluteFilePath)) - return; - - if (_workspace.TryAddMiscellaneousDocument(absoluteFilePath, Language) != null) - { - _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); - } - } - - private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType) - { - if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || - changeType == FileChangeType.Create) - { - TryAddMiscellaneousFile(filePath); - } - - else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || - changeType == FileChangeType.Delete) - { - RemoveFromWorkspace(filePath); - } - } - - private void RemoveFromWorkspace(string filePath) - { - if (_workspace.TryRemoveMiscellaneousDocument(filePath)) - { - _logger.LogDebug($"Removed file '{filePath}' from the workspace."); - } - } - } -} diff --git a/src/OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj b/src/OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj deleted file mode 100644 index 89bb4ca4c4..0000000000 --- a/src/OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net461 - AnyCPU - - - - - - - - - - - - diff --git a/src/OmniSharp.Roslyn/BufferManager.cs b/src/OmniSharp.Roslyn/BufferManager.cs index ded2c544f8..9b5b2ff815 100644 --- a/src/OmniSharp.Roslyn/BufferManager.cs +++ b/src/OmniSharp.Roslyn/BufferManager.cs @@ -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; @@ -17,11 +18,15 @@ public class BufferManager private readonly IDictionary> _transientDocuments = new Dictionary>(StringComparer.OrdinalIgnoreCase); private readonly ISet _transientDocumentIds = new HashSet(); private readonly object _lock = new object(); + private readonly IFileSystemWatcher _fileSystemWatcher; + private readonly Action _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) @@ -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) + { + _fileSystemWatcher.Watch(fileName, OnFileChanged); + return true; + } + return false; } - - var sourceText = SourceText.From(fileContent); - var documentInfos = new List(); - 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(); + 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 FindProjectsByFileName(string fileName) { var fileInfo = new FileInfo(fileName); diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 6ed38b5f0c..1e0a9b0bc9 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -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; @@ -26,10 +27,10 @@ public class OmniSharpWorkspace : Workspace private readonly ConcurrentDictionary miscDocumentsProjectInfos = new ConcurrentDictionary(); [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(); } diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index 6b7ca88600..29ee1a386c 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -8,7 +8,6 @@ - diff --git a/tests/OmniSharp.Cake.Tests/LineIndexHelperFacts.cs b/tests/OmniSharp.Cake.Tests/LineIndexHelperFacts.cs index 9fa0d1f4d6..3dc6f031f4 100644 --- a/tests/OmniSharp.Cake.Tests/LineIndexHelperFacts.cs +++ b/tests/OmniSharp.Cake.Tests/LineIndexHelperFacts.cs @@ -59,7 +59,7 @@ private static OmniSharpWorkspace CreateSimpleWorkspace(string fileName, string var workspace = new OmniSharpWorkspace( new HostServicesAggregator( Enumerable.Empty(), new LoggerFactory()), - new LoggerFactory()); + new LoggerFactory(), null); var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "ProjectNameVal", "AssemblyNameVal", LanguageNames.CSharp); diff --git a/tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs b/tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs deleted file mode 100644 index 9933b8fd08..0000000000 --- a/tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs +++ /dev/null @@ -1 +0,0 @@ -[assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)] diff --git a/tests/OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj b/tests/OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj deleted file mode 100644 index 7837179d01..0000000000 --- a/tests/OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - net461 - AnyCPU - true - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/BufferFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferFacts.cs index e0bc99202c..9ff43c80eb 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/BufferFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferFacts.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using Microsoft.Extensions.Logging; +using OmniSharp.FileWatching; using OmniSharp.Models.ChangeBuffer; using OmniSharp.Roslyn.CSharp.Services.Buffer; using OmniSharp.Services; @@ -17,7 +18,7 @@ public class BufferFacts var workspace = new OmniSharpWorkspace( new HostServicesAggregator( Enumerable.Empty(), new LoggerFactory()), - new LoggerFactory()); + new LoggerFactory(), new ManualFileSystemWatcher()); var service = new ChangeBufferService(workspace); diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerFacts.cs index a868cd9691..2eb53cf89f 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerFacts.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using OmniSharp.FileWatching; using OmniSharp.Models; using OmniSharp.Models.UpdateBuffer; using OmniSharp.Services; @@ -41,12 +42,12 @@ public async Task UpdateBufferIgnoresVoidRequests() } [Fact] - public async Task UpdateBufferIgnoresFilePathsThatDontMatchAProjectPath() + public async Task UpdateBufferIgnoresNonCsFilePathsThatDontMatchAProjectPath() { var workspace = GetWorkspaceWithProjects(); - await workspace.BufferManager.UpdateBufferAsync(new Request() { FileName = Path.Combine("some", " path.cs"), Buffer = "enum E {}" }); - var documents = workspace.GetDocuments(Path.Combine("some", "path.cs")); + await workspace.BufferManager.UpdateBufferAsync(new Request() { FileName = Path.Combine("some", " path.fs"), Buffer = "enum E {}" }); + var documents = workspace.GetDocuments(Path.Combine("some", "path.fs")); Assert.Empty(documents); } @@ -97,7 +98,7 @@ public async Task UpdateBufferFindsProjectBasedOnNearestPath() var workspace = new OmniSharpWorkspace( new HostServicesAggregator( Enumerable.Empty(), new LoggerFactory()), - new LoggerFactory()); + new LoggerFactory(), new ManualFileSystemWatcher()); TestHelpers.AddProjectToWorkspace(workspace, filePath: Path.Combine("src", "root", "foo.csproj"), @@ -164,7 +165,7 @@ private static OmniSharpWorkspace GetWorkspaceWithProjects() var workspace = new OmniSharpWorkspace( new HostServicesAggregator( Enumerable.Empty(), new LoggerFactory()), - new LoggerFactory()); + new LoggerFactory(), new ManualFileSystemWatcher()); TestHelpers.AddProjectToWorkspace(workspace, filePath: Path.Combine("src", "project.json"), diff --git a/tests/OmniSharp.MiscellaneousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerMiscFilesFacts.cs similarity index 84% rename from tests/OmniSharp.MiscellaneousFiles.Tests/EndpointFacts.cs rename to tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerMiscFilesFacts.cs index 9fd6d7647a..c3ed03acec 100644 --- a/tests/OmniSharp.MiscellaneousFiles.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/BufferManagerMiscFilesFacts.cs @@ -15,25 +15,24 @@ using Xunit; using Xunit.Abstractions; -namespace OmniSharp.MiscellaneousFiles.Tests +namespace OmniSharp.Tests { - public class EndpointFacts : AbstractTestFixture + public class BufferManagerMiscFilesFacts : AbstractTestFixture { - public EndpointFacts(ITestOutputHelper output) + public BufferManagerMiscFilesFacts(ITestOutputHelper output) : base(output) { } [Fact] - public async Task Returns_only_syntactic_diagnotics() + public async Task Adds_Misc_Document_Which_Supports_Only_syntactic_diagnostics() { using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { var testfile = new TestFile("a.cs", "class C { b a = new b(); int n }"); using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var request = new CodeCheckRequest() { FileName = filePath }; var actual = await host.GetResponse(OmniSharpEndpoints.CodeCheck, request); Assert.Single(actual.QuickFixes); @@ -43,7 +42,7 @@ public async Task Returns_only_syntactic_diagnotics() } [Fact] - public async Task Returns_Signature_help() + public async Task Adds_Misc_Document_Which_Supports_Signature_help() { const string source = @"class Program @@ -57,8 +56,7 @@ public static void Main(){ { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var point = testfile.Content.GetPointFromPosition(); var request = new SignatureHelpRequest() { @@ -79,13 +77,12 @@ public static void Main(){ } [Fact] - public async Task Returns_Implementations() + public async Task Adds_Misc_Document_Which_Supports_Implementations() { const string source = @" public class MyClass { public MyClass() { Fo$$o(); } - public void Foo() {} }"; @@ -94,8 +91,7 @@ public void Foo() {} { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var point = testfile.Content.GetPointFromPosition(); var request = new FindImplementationsRequest() { @@ -113,14 +109,13 @@ public void Foo() {} } [Fact] - public async Task Returns_Usages() + public async Task Adds_Misc_Document_Which_Supports_Usages() { const string source = @" public class F$$oo { public string prop { get; set; } } - public class FooConsumer { public FooConsumer() @@ -135,9 +130,7 @@ public FooConsumer() { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); - + var filePath = await AddTestFile(host, testProject, testfile); var point = testfile.Content.GetPointFromPosition(); var request = new FindUsagesRequest() { @@ -154,7 +147,7 @@ public FooConsumer() } [Fact] - public async Task Returns_Symbols() + public async Task Adds_Misc_Document_Which_Supports_Symbols() { const string source = @" namespace Some.Long.Namespace @@ -170,7 +163,6 @@ private string Property } private string Method() {} private string Method(string param) {} - private class Nested { private string NestedMethod() {} @@ -183,8 +175,7 @@ private string NestedMethod() {} { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var actual = await host.GetResponse(OmniSharpEndpoints.FindSymbols, null); var symbols = actual.QuickFixes.Select(q => q.Text); @@ -206,14 +197,13 @@ private string NestedMethod() {} } [Fact] - public async Task Returns_FixUsings() + public async Task Adds_Misc_Document_Which_Supports_FixUsings() { const string code = @" namespace nsA { public class classX{} } - namespace OmniSharp { public class class1 @@ -232,7 +222,6 @@ namespace nsA { public class classX{} } - namespace OmniSharp { public class class1 @@ -249,9 +238,8 @@ public method1() { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); - var request = new FixUsingsRequest(){ FileName = filePath }; + var filePath = await AddTestFile(host, testProject, testfile); + var request = new FixUsingsRequest() { FileName = filePath }; var actual = await host.GetResponse(OmniSharpEndpoints.FixUsings, request); Assert.Equal(expectedCode.Replace("\r\n", "\n"), actual.Buffer.Replace("\r\n", "\n")); } @@ -259,7 +247,7 @@ public method1() } [Fact] - public async Task Returns_TypeLookup() + public async Task Adds_Misc_Document_Which_Supports_TypeLookup() { const string code = @"class F$$oo {}"; var testfile = new TestFile("a.cs", code); @@ -267,8 +255,7 @@ public async Task Returns_TypeLookup() { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var service = host.GetRequestHandler(OmniSharpEndpoints.TypeLookup); var point = testfile.Content.GetPointFromPosition(); var request = new TypeLookupRequest @@ -308,10 +295,8 @@ public static void Main(){ { using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath1 = AddTestFile(testProject, testfile1); - var filePath2 = AddTestFile(testProject, testfile2); - await WaitForFileUpdate(filePath1, host); - await WaitForFileUpdate(filePath2, host); + var filePath1 = await AddTestFile(host, testProject, testfile1); + var filePath2 = await AddTestFile(host, testProject, testfile2); var point = testfile1.Content.GetPointFromPosition(); var request = new SignatureHelpRequest() { @@ -332,7 +317,7 @@ public static void Main(){ } [Fact] - public async Task Handles_File_Deletion() + public async Task Handles_Misc_File_Deletion() { //When the file is deleted the diagnostics must not be returned using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) @@ -340,8 +325,7 @@ public async Task Handles_File_Deletion() var testfile = new TestFile("a.cs", "class C { b a = new b(); int n }"); using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = AddTestFile(testProject, testfile); - await WaitForFileUpdate(filePath, host); + var filePath = await AddTestFile(host, testProject, testfile); var request = new CodeCheckRequest() { FileName = filePath }; var actual = await host.GetResponse(OmniSharpEndpoints.CodeCheck, request); Assert.Single(actual.QuickFixes); @@ -353,9 +337,11 @@ public async Task Handles_File_Deletion() } } - private string AddTestFile(ITestProject testProject, TestFile testfile) + private async Task AddTestFile(OmniSharpTestHost host, ITestProject testProject, TestFile testfile) { - return testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); + var filePath = testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); + await host.Workspace.BufferManager.UpdateBufferAsync(new Request() { FileName = filePath, Buffer = testfile.Content.Text.ToString() }); + return filePath; } private async Task WaitForFileUpdate(string filePath, OmniSharpTestHost host, FileWatching.FileChangeType changeType = FileWatching.FileChangeType.Create) diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index fb78cc746f..7741ca5ff9 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -15,7 +15,6 @@ using OmniSharp.DotNetTest.Models; using OmniSharp.Eventing; using OmniSharp.Mef; -using OmniSharp.MiscellaneousFile; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild; using OmniSharp.Options; @@ -42,7 +41,6 @@ public class OmniSharpTestHost : DisposableObject typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, // OmniSharp.Roslyn typeof(RoslynFeaturesHostServicesProvider).GetTypeInfo().Assembly, // OmniSharp.Roslyn.CSharp typeof(CakeProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Cake - typeof(MiscellaneousFilesProjectSystem).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles }); private readonly TestServiceProvider _serviceProvider; diff --git a/tests/TestUtility/TestHelpers.cs b/tests/TestUtility/TestHelpers.cs index 7af0b6cfce..a2f4c34a75 100644 --- a/tests/TestUtility/TestHelpers.cs +++ b/tests/TestUtility/TestHelpers.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Scripting.Hosting; using Microsoft.Extensions.Logging; using OmniSharp; +using OmniSharp.FileWatching; using OmniSharp.Script; using OmniSharp.Services; @@ -15,7 +16,7 @@ public static class TestHelpers { public static OmniSharpWorkspace CreateCsxWorkspace(TestFile testFile) { - var workspace = new OmniSharpWorkspace(new HostServicesAggregator(Enumerable.Empty(), new LoggerFactory()), new LoggerFactory()); + var workspace = new OmniSharpWorkspace(new HostServicesAggregator(Enumerable.Empty(), new LoggerFactory()), new LoggerFactory(), new ManualFileSystemWatcher()); AddCsxProjectToWorkspace(workspace, testFile); return workspace; } diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index ede88fae3d..14de90b483 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -9,7 +9,6 @@ -