From a784769fd9dd043db1c038167dc130de32a63763 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 28 Jun 2018 14:42:49 -0700 Subject: [PATCH 01/54] Basic of the orphan file system --- OmniSharp.OrphanFiles/OrphanFileSystem.cs | 45 ++++++++++++++++++++++ OmniSharp.sln | 17 +++++++- src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 OmniSharp.OrphanFiles/OrphanFileSystem.cs diff --git a/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/OmniSharp.OrphanFiles/OrphanFileSystem.cs new file mode 100644 index 0000000000..77c11301f1 --- /dev/null +++ b/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Composition; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using OmniSharp.Models.WorkspaceInformation; +using OmniSharp.Services; + +namespace OmniSharp.OrphanFiles +{ + [Export(typeof(IProjectSystem)), Shared] + public class OrphanFileSystem : IProjectSystem + { + string IProjectSystem.Key => throw new NotImplementedException(); + + string IProjectSystem.Language => throw new NotImplementedException(); + + IEnumerable IProjectSystem.Extensions => throw new NotImplementedException(); + + bool IProjectSystem.EnabledByDefault => throw new NotImplementedException(); + + private readonly OmniSharpWorkspace _workspace; + + [ImportingConstructor] + public OrphanFileSystem(OmniSharpWorkspace workspace) + { + _workspace = workspace; + } + + Task IProjectSystem.GetProjectModelAsync(string filePath) + { + throw new NotImplementedException(); + } + + Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request) + { + throw new NotImplementedException(); + } + + void IProjectSystem.Initalize(IConfiguration configuration) + { + throw new NotImplementedException(); + } + } +} diff --git a/OmniSharp.sln b/OmniSharp.sln index 21aeb2e8ac..4462748ab2 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -68,7 +68,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Http.Driver", "sr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Stdio.Driver", "src\OmniSharp.Stdio.Driver\OmniSharp.Stdio.Driver.csproj", "{D2A78CEE-B278-476F-AF34-A7D6F792F973}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.Script.Tests", "tests\OmniSharp.Script.Tests\OmniSharp.Script.Tests.csproj", "{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}" +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.OrphanFiles", "OmniSharp.OrphanFiles\OmniSharp.OrphanFiles.csproj", "{7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -404,6 +406,18 @@ 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 + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x64.ActiveCfg = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x64.Build.0 = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x86.ActiveCfg = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x86.Build.0 = Debug|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|Any CPU.Build.0 = Release|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x64.ActiveCfg = Release|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x64.Build.0 = Release|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x86.ActiveCfg = Release|Any CPU + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -436,6 +450,7 @@ 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} + {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36} = {2C348365-A9D8-459E-9276-56FC46AAEE31} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E} diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index b7b18e9764..849c2a86ed 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -6,6 +6,7 @@ + From f0cc59ea2c11931dfd041b7dc2a92dec122c094d Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 28 Jun 2018 16:49:57 -0700 Subject: [PATCH 02/54] Initialise the project system --- OmniSharp.OrphanFiles/OrphanFileSystem.cs | 46 +++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/OmniSharp.OrphanFiles/OrphanFileSystem.cs index 77c11301f1..16ec7e1706 100644 --- a/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -1,8 +1,13 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Composition; +using System.IO; using System.Threading.Tasks; +using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; +using OmniSharp.FileSystem; +using OmniSharp.FileWatching; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.Services; @@ -11,20 +16,22 @@ namespace OmniSharp.OrphanFiles [Export(typeof(IProjectSystem)), Shared] public class OrphanFileSystem : IProjectSystem { - string IProjectSystem.Key => throw new NotImplementedException(); - - string IProjectSystem.Language => throw new NotImplementedException(); - + public string Key { get; } = "MsBuild"; + public string Language { get; } = LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => throw new NotImplementedException(); + public bool EnabledByDefault { get; } = true; - bool IProjectSystem.EnabledByDefault => throw new NotImplementedException(); - + private readonly ConcurrentDictionary _projects = new ConcurrentDictionary(); private readonly OmniSharpWorkspace _workspace; + private readonly IFileSystemWatcher _fileSystemWatcher; + private readonly FileSystemHelper _fileSystemHelper; [ImportingConstructor] - public OrphanFileSystem(OmniSharpWorkspace workspace) + public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper) { _workspace = workspace; + _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); + _fileSystemHelper = fileSystemHelper; } Task IProjectSystem.GetProjectModelAsync(string filePath) @@ -39,7 +46,30 @@ Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest r void IProjectSystem.Initalize(IConfiguration configuration) { - throw new NotImplementedException(); + var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); + var solution = _workspace.CurrentSolution; + string assemblyName = Guid.NewGuid().ToString("N"); + + foreach (var file in allFiles) + { + if (_workspace.GetDocument(file) == null) + { + var doc = _workspace.GetDocument(file); + //implies the document doesnot exist in the workspace currently + var project = ProjectInfo.Create( + filePath: file, + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: Path.GetFileName(file), + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + //TODO: Ask if there should be other languages as well + language: Language); + + _workspace.AddProject(project); + _workspace.AddDocument(project.Id, file); + } + } } } } From b26552b4c073c88e2c36f97f8fe17dbbbc2d776f Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 29 Jun 2018 15:39:41 -0700 Subject: [PATCH 03/54] add csproj --- .../OmniSharp.OrphanFiles.csproj | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj diff --git a/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj b/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj new file mode 100644 index 0000000000..6b3dc4f1eb --- /dev/null +++ b/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj @@ -0,0 +1,29 @@ + + + + net46 + AnyCPU + + + + + + + + + + + ..\..\..\..\Documents\omnisharp\Microsoft.Extensions.Configuration.dll + + + ..\..\..\..\Documents\omnisharp\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.ComponentModel.Composition.dll + + + ..\..\..\..\Documents\omnisharp\System.Composition.AttributedModel.dll + + + + From 48548a78cd1e7af7a64236414505772b1b401cc4 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 3 Jul 2018 15:16:35 -0700 Subject: [PATCH 04/54] Test using MSBuildProjectSystem --- OmniSharp.OrphanFiles/OrphanFileSystem.cs | 15 ++++++++++----- src/OmniSharp.MSBuild/ProjectSystem.cs | 1 + src/OmniSharp.Roslyn/ProjectEventForwarder.cs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/OmniSharp.OrphanFiles/OrphanFileSystem.cs index 16ec7e1706..3f9c5c9568 100644 --- a/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -9,6 +9,8 @@ using OmniSharp.FileSystem; using OmniSharp.FileWatching; using OmniSharp.Models.WorkspaceInformation; +using OmniSharp.MSBuild; +using OmniSharp.Roslyn; using OmniSharp.Services; namespace OmniSharp.OrphanFiles @@ -25,13 +27,15 @@ public class OrphanFileSystem : IProjectSystem private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; + private readonly ProjectSystem _msbuildSystem; [ImportingConstructor] - public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper) + public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, [Import] ProjectSystem msbuildSystem) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; + _msbuildSystem = msbuildSystem; } Task IProjectSystem.GetProjectModelAsync(string filePath) @@ -52,11 +56,12 @@ void IProjectSystem.Initalize(IConfiguration configuration) foreach (var file in allFiles) { - if (_workspace.GetDocument(file) == null) + var project = await _projectEventforwarder.GetProjectInformationAsync(file); + if (project == null) { var doc = _workspace.GetDocument(file); //implies the document doesnot exist in the workspace currently - var project = ProjectInfo.Create( + var newProject = ProjectInfo.Create( filePath: file, id: ProjectId.CreateNewId(), version: VersionStamp.Create(), @@ -66,8 +71,8 @@ void IProjectSystem.Initalize(IConfiguration configuration) //TODO: Ask if there should be other languages as well language: Language); - _workspace.AddProject(project); - _workspace.AddDocument(project.Id, file); + _workspace.AddProject(newProject); + _workspace.AddDocument(newProject.Id, file); } } } diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 4d432acf18..62745162bf 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -20,6 +20,7 @@ namespace OmniSharp.MSBuild { + [Export(typeof(ProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class ProjectSystem : IProjectSystem { diff --git a/src/OmniSharp.Roslyn/ProjectEventForwarder.cs b/src/OmniSharp.Roslyn/ProjectEventForwarder.cs index bb0f16fb26..082d9cf214 100644 --- a/src/OmniSharp.Roslyn/ProjectEventForwarder.cs +++ b/src/OmniSharp.Roslyn/ProjectEventForwarder.cs @@ -81,7 +81,7 @@ private void OnWorkspaceChanged(object source, WorkspaceChangeEventArgs args) } } - private async Task GetProjectInformationAsync(string fileName) + public async Task GetProjectInformationAsync(string fileName) { var response = new ProjectInformationResponse(); From 774cc9b793157bd324b09e1c1853114e680a55fb Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jul 2018 13:46:13 -0700 Subject: [PATCH 05/54] Orphan file system using the msbuild system --- OmniSharp.sln | 32 +++++------ .../OrphanFileSystem.cs | 57 +++++++++++-------- src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 2 +- 3 files changed, 50 insertions(+), 41 deletions(-) rename {OmniSharp.OrphanFiles => src/OmniSharp.OrphanFiles}/OrphanFileSystem.cs (56%) diff --git a/OmniSharp.sln b/OmniSharp.sln index 4462748ab2..9ce8af6473 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2005 MinimumVisualStudioVersion = 10.0.40219.1 @@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection ProjectSection(FolderGlobals) = preProject - global_1json__JSONSchema = http://json.schemastore.org/global + global_1json__JSONSchema = http://json.schemastore.org/global EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}" @@ -70,7 +70,7 @@ 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.OrphanFiles", "OmniSharp.OrphanFiles\OmniSharp.OrphanFiles.csproj", "{7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.OrphanFiles", "src\OmniSharp.OrphanFiles\OmniSharp.OrphanFiles.csproj", "{2BF50528-38C4-4928-9FB2-7539A3C20DA8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -406,18 +406,18 @@ 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 - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x64.ActiveCfg = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x64.Build.0 = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x86.ActiveCfg = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Debug|x86.Build.0 = Debug|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|Any CPU.Build.0 = Release|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x64.ActiveCfg = Release|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x64.Build.0 = Release|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x86.ActiveCfg = Release|Any CPU - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36}.Release|x86.Build.0 = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x64.ActiveCfg = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x64.Build.0 = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x86.ActiveCfg = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x86.Build.0 = Debug|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|Any CPU.Build.0 = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x64.ActiveCfg = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x64.Build.0 = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.ActiveCfg = Release|Any CPU + {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -450,7 +450,7 @@ 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} - {7B831B42-07CC-4F20-AAF0-B2B4DD6C1F36} = {2C348365-A9D8-459E-9276-56FC46AAEE31} + {2BF50528-38C4-4928-9FB2-7539A3C20DA8} = {2C348365-A9D8-459E-9276-56FC46AAEE31} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E} diff --git a/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs similarity index 56% rename from OmniSharp.OrphanFiles/OrphanFileSystem.cs rename to src/OmniSharp.OrphanFiles/OrphanFileSystem.cs index 3f9c5c9568..a22b3c33e4 100644 --- a/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using OmniSharp.FileSystem; using OmniSharp.FileWatching; using OmniSharp.Models.WorkspaceInformation; @@ -18,7 +19,7 @@ namespace OmniSharp.OrphanFiles [Export(typeof(IProjectSystem)), Shared] public class OrphanFileSystem : IProjectSystem { - public string Key { get; } = "MsBuild"; + public string Key { get; } = "OrphanFiles"; public string Language { get; } = LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => throw new NotImplementedException(); public bool EnabledByDefault { get; } = true; @@ -27,53 +28,61 @@ public class OrphanFileSystem : IProjectSystem private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; - private readonly ProjectSystem _msbuildSystem; + private readonly IProjectSystem _projectSystem; + private readonly ILogger _logger; [ImportingConstructor] - public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, [Import] ProjectSystem msbuildSystem) + public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [Import] ProjectSystem projectSystem) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; - _msbuildSystem = msbuildSystem; + _logger = loggerFactory.CreateLogger(); + _projectSystem = projectSystem; } Task IProjectSystem.GetProjectModelAsync(string filePath) { - throw new NotImplementedException(); + return Task.FromResult(null); } Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request) { - throw new NotImplementedException(); + return Task.FromResult(null); } void IProjectSystem.Initalize(IConfiguration configuration) { var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); var solution = _workspace.CurrentSolution; - string assemblyName = Guid.NewGuid().ToString("N"); foreach (var file in allFiles) { - var project = await _projectEventforwarder.GetProjectInformationAsync(file); - if (project == null) - { - var doc = _workspace.GetDocument(file); - //implies the document doesnot exist in the workspace currently - var newProject = ProjectInfo.Create( - filePath: file, - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: Path.GetFileName(file), - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - //TODO: Ask if there should be other languages as well - language: Language); + AddFileToWorkSpace(file); + } + } + + private async void AddFileToWorkSpace(string filename) + { + string assemblyName = Guid.NewGuid().ToString("N"); + await _projectSystem.GetProjectModelAsync(filename); + var document = _workspace.GetDocument(filename); + if (document == null) + { + var newProject = ProjectInfo.Create( + filePath: filename, + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: Path.GetFileName(filename), + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + //TODO: Ask if there should be other languages as well + language: Language); + + _workspace.AddProject(newProject); + _workspace.AddDocument(newProject.Id, filename); - _workspace.AddProject(newProject); - _workspace.AddDocument(newProject.Id, file); - } + _logger.LogInformation($"Successfully added file '{filename}' to workspace"); } } } diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index 849c2a86ed..0cf1fa5d5a 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -6,9 +6,9 @@ - + From 2d4614966a5fb259774d74c3a55368dee3bb9159 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jul 2018 13:47:49 -0700 Subject: [PATCH 06/54] Remove unnecessary change --- src/OmniSharp.Roslyn/ProjectEventForwarder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn/ProjectEventForwarder.cs b/src/OmniSharp.Roslyn/ProjectEventForwarder.cs index 082d9cf214..bb0f16fb26 100644 --- a/src/OmniSharp.Roslyn/ProjectEventForwarder.cs +++ b/src/OmniSharp.Roslyn/ProjectEventForwarder.cs @@ -81,7 +81,7 @@ private void OnWorkspaceChanged(object source, WorkspaceChangeEventArgs args) } } - public async Task GetProjectInformationAsync(string fileName) + private async Task GetProjectInformationAsync(string fileName) { var response = new ProjectInformationResponse(); From 27266dda9591e92e68f3acf4101e1c918a156e44 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jul 2018 17:19:45 -0700 Subject: [PATCH 07/54] csproj temp --- .../OmniSharp.OrphanFiles.csproj | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) rename {OmniSharp.OrphanFiles => src/OmniSharp.OrphanFiles}/OmniSharp.OrphanFiles.csproj (53%) diff --git a/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj b/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj similarity index 53% rename from OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj rename to src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj index 6b3dc4f1eb..b7064d6fbd 100644 --- a/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj +++ b/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj @@ -5,19 +5,12 @@ AnyCPU - - - - + + + - - ..\..\..\..\Documents\omnisharp\Microsoft.Extensions.Configuration.dll - - - ..\..\..\..\Documents\omnisharp\Microsoft.Extensions.Configuration.Abstractions.dll - ..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.ComponentModel.Composition.dll From 6f972d07889b5cc5b2195dcd428687a83510a0cb Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 6 Jul 2018 15:53:31 -0700 Subject: [PATCH 08/54] Get only syntactic diagnostics for misc files --- src/OmniSharp.OrphanFiles/OrphanFileSystem.cs | 31 ++++--------------- .../Helpers/DiagnosticExtensions.cs | 15 +++++++-- .../Services/Diagnostics/CodeCheckService.cs | 2 +- .../Diagnostics/CSharpDiagnosticService.cs | 2 +- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 30 ++++++++++++++++++ 5 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs index a22b3c33e4..0441e19ad3 100644 --- a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -54,35 +54,16 @@ Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest r void IProjectSystem.Initalize(IConfiguration configuration) { var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); - var solution = _workspace.CurrentSolution; - - foreach (var file in allFiles) - { - AddFileToWorkSpace(file); - } + AddMiscellanousFiles(allFiles); } - private async void AddFileToWorkSpace(string filename) + private async void AddMiscellanousFiles(IEnumerable allFiles) { - string assemblyName = Guid.NewGuid().ToString("N"); - await _projectSystem.GetProjectModelAsync(filename); - var document = _workspace.GetDocument(filename); - if (document == null) + foreach (var filePath in allFiles) { - var newProject = ProjectInfo.Create( - filePath: filename, - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: Path.GetFileName(filename), - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - //TODO: Ask if there should be other languages as well - language: Language); - - _workspace.AddProject(newProject); - _workspace.AddDocument(newProject.Id, filename); - - _logger.LogInformation($"Successfully added file '{filename}' to workspace"); + //wait for the project system to get initialised + await _projectSystem.GetProjectModelAsync(filePath); + _workspace.AddMiscellanousFile(filePath, Language); } } } diff --git a/src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs b/src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs index a2b89de94d..94380327b6 100644 --- a/src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs +++ b/src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs @@ -24,15 +24,24 @@ internal static DiagnosticLocation ToDiagnosticLocation(this Diagnostic diagnost }; } - internal static async Task> FindDiagnosticLocationsAsync(this IEnumerable documents) + internal static async Task> FindDiagnosticLocationsAsync(this IEnumerable documents, OmniSharpWorkspace workspace) { if (documents == null || !documents.Any()) return Enumerable.Empty(); var items = new List(); foreach (var document in documents) { - var semanticModel = await document.GetSemanticModelAsync(); - IEnumerable diagnostics = semanticModel.GetDiagnostics(); + IEnumerable diagnostics; + if (workspace.IsCapableOfSemanticDiagnostics(document)) + { + var semanticModel = await document.GetSemanticModelAsync(); + diagnostics = semanticModel.GetDiagnostics(); + } + else + { + var syntaxModel = await document.GetSyntaxTreeAsync(); + diagnostics = syntaxModel.GetDiagnostics(); + } foreach (var quickFix in diagnostics.Select(d => d.ToDiagnosticLocation())) { diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/CodeCheckService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/CodeCheckService.cs index a857343f2a..4a09494f81 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/CodeCheckService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/CodeCheckService.cs @@ -27,7 +27,7 @@ public async Task Handle(CodeCheckRequest request) ? _workspace.GetDocuments(request.FileName) : _workspace.CurrentSolution.Projects.SelectMany(project => project.Documents); - var quickFixes = await documents.FindDiagnosticLocationsAsync(); + var quickFixes = await documents.FindDiagnosticLocationsAsync(_workspace); return new QuickFixResponse(quickFixes); } } diff --git a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticService.cs b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticService.cs index 35fc89fe39..03e733f669 100644 --- a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticService.cs @@ -140,7 +140,7 @@ private async Task Dequeue() private async Task ProcessNextItem(string filePath) { var documents = _workspace.GetDocuments(filePath); - var items = await documents.FindDiagnosticLocationsAsync(); + var items = await documents.FindDiagnosticLocationsAsync(_workspace); return new DiagnosticResult() { diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index d0e371ca5e..dac11576f0 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -21,12 +21,15 @@ public class OmniSharpWorkspace : Workspace private readonly ILogger _logger; + private HashSet _miscellanousFiles; + [ImportingConstructor] public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory) : base(aggregator.CreateHostServices(), "Custom") { BufferManager = new BufferManager(this); _logger = loggerFactory.CreateLogger(); + _miscellanousFiles = new HashSet(); } public override bool CanOpenDocuments => true; @@ -224,5 +227,32 @@ private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText _logger.LogError(e, $"Error saving document {fullPath}"); } } + + public void AddMiscellanousFile(string filePath, string language) + { + if (GetDocument(filePath) == null) + { + string assemblyName = Guid.NewGuid().ToString("N"); + var newProject = ProjectInfo.Create( + filePath: filePath, + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: Path.GetFileName(filePath), + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: language); + + AddProject(newProject); + var documentId = AddDocument(newProject.Id, filePath); + _miscellanousFiles.Add(documentId); + _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); + } + } + + public bool IsCapableOfSemanticDiagnostics(Document document) + { + var documentId = GetDocumentId(document.FilePath); + return !_miscellanousFiles.Contains(documentId); + } } } From 7bb47082982e5b742920a07c2717b3ebde138247 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Jul 2018 12:11:55 -0700 Subject: [PATCH 09/54] Logic to delete the document --- src/OmniSharp.MSBuild/ProjectSystem.cs | 5 ++ src/OmniSharp.OrphanFiles/OrphanFileSystem.cs | 49 +++++++++++++++---- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 35 ++++++------- 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 62745162bf..3f9feb82a9 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -210,5 +210,10 @@ async Task IProjectSystem.GetProjectModelAsync(string filePath) return new MSBuildProjectInfo(projectFileInfo); } + + public async Task hasCompletedUpdateRequest() + { + await _manager.WaitForQueueEmptyAsync(); + } } } diff --git a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs index 0441e19ad3..37f68661ed 100644 --- a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs @@ -19,16 +19,17 @@ namespace OmniSharp.OrphanFiles [Export(typeof(IProjectSystem)), Shared] public class OrphanFileSystem : IProjectSystem { + private string miscFileExtension = ".cs"; public string Key { get; } = "OrphanFiles"; public string Language { get; } = LanguageNames.CSharp; - IEnumerable IProjectSystem.Extensions => throw new NotImplementedException(); + IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; - private readonly ConcurrentDictionary _projects = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _documents = new ConcurrentDictionary(); private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; - private readonly IProjectSystem _projectSystem; + private readonly ProjectSystem _projectSystem; private readonly ILogger _logger; [ImportingConstructor] @@ -54,16 +55,46 @@ Task IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest r void IProjectSystem.Initalize(IConfiguration configuration) { var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); - AddMiscellanousFiles(allFiles); + foreach (var filePath in allFiles) + AddIfMiscellanousFile(filePath); + + _fileSystemWatcher.Watch(miscFileExtension, onFileChanged); } - private async void AddMiscellanousFiles(IEnumerable allFiles) + private async void AddIfMiscellanousFile(string filePath) { - foreach (var filePath in allFiles) + //wait for the project system to get initialised + await _projectSystem.hasCompletedUpdateRequest(); + if (_workspace.GetDocument(filePath) == null) + { + var documentId =_workspace.AddMiscellanousFile(filePath, Language); + _documents.TryAdd(filePath, documentId); + _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); + } + } + + private void onFileChanged(string filePath, FileChangeType changeType) + { + if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || + changeType == FileChangeType.Create) + { + AddIfMiscellanousFile(filePath); + } + + else if(changeType == FileChangeType.Unspecified && !File.Exists(filePath) || + changeType == FileChangeType.Delete) + { + RemoveFromWorkspace(filePath); + } + } + + private void RemoveFromWorkspace(string filePath) + { + if (_documents.TryRemove(filePath, out var documentId)) { - //wait for the project system to get initialised - await _projectSystem.GetProjectModelAsync(filePath); - _workspace.AddMiscellanousFile(filePath, Language); + _workspace.RemoveDocument(documentId); + //ToDo: Identify if we need to remove the project here and how + _logger.LogInformation($"Removed file '{filePath}' from the workspace."); } } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index dac11576f0..5a08cb8e1b 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -228,25 +228,22 @@ private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText } } - public void AddMiscellanousFile(string filePath, string language) - { - if (GetDocument(filePath) == null) - { - string assemblyName = Guid.NewGuid().ToString("N"); - var newProject = ProjectInfo.Create( - filePath: filePath, - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: Path.GetFileName(filePath), - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - language: language); - - AddProject(newProject); - var documentId = AddDocument(newProject.Id, filePath); - _miscellanousFiles.Add(documentId); - _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); - } + public DocumentId AddMiscellanousFile(string filePath, string language) + { + string assemblyName = Guid.NewGuid().ToString("N"); + var project = ProjectInfo.Create( + filePath: filePath, + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: Path.GetFileName(filePath), + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: language); + + AddProject(project); + var documentId = AddDocument(project.Id, filePath); + _miscellanousFiles.Add(documentId); + return documentId; } public bool IsCapableOfSemanticDiagnostics(Document document) From bf59f022d8b76c02b1f88b46c105292b9cf27287 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Jul 2018 12:25:54 -0700 Subject: [PATCH 10/54] Edit csproj --- src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj b/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj index b7064d6fbd..0e4a077c72 100644 --- a/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj +++ b/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj @@ -10,13 +10,4 @@ - - - ..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.ComponentModel.Composition.dll - - - ..\..\..\..\Documents\omnisharp\System.Composition.AttributedModel.dll - - - From 0db4d7007d508d656bdbfa7b60de061dd9e1fb96 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Jul 2018 15:57:14 -0700 Subject: [PATCH 11/54] Rename to misc files --- OmniSharp.sln | 5 +++-- .../MiscellanousFiles.cs} | 7 ++++--- .../OmniSharp.MiscellanousFiles.csproj} | 0 src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) rename src/{OmniSharp.OrphanFiles/OrphanFileSystem.cs => OmniSharp.MiscellanousFiles/MiscellanousFiles.cs} (90%) rename src/{OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj => OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj} (100%) diff --git a/OmniSharp.sln b/OmniSharp.sln index 9ce8af6473..b5a3645a26 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -1,4 +1,5 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2005 MinimumVisualStudioVersion = 10.0.40219.1 @@ -70,7 +71,7 @@ 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.OrphanFiles", "src\OmniSharp.OrphanFiles\OmniSharp.OrphanFiles.csproj", "{2BF50528-38C4-4928-9FB2-7539A3C20DA8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.MiscellanousFiles", "src\OmniSharp.MiscellanousFiles\OmniSharp.MiscellanousFiles.csproj", "{2BF50528-38C4-4928-9FB2-7539A3C20DA8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs similarity index 90% rename from src/OmniSharp.OrphanFiles/OrphanFileSystem.cs rename to src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 37f68661ed..1884225bd2 100644 --- a/src/OmniSharp.OrphanFiles/OrphanFileSystem.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -16,8 +16,9 @@ namespace OmniSharp.OrphanFiles { + [ExtensionOrder(After = nameof(ProjectSystem))] [Export(typeof(IProjectSystem)), Shared] - public class OrphanFileSystem : IProjectSystem + public class MiscellanousFiles : IProjectSystem { private string miscFileExtension = ".cs"; public string Key { get; } = "OrphanFiles"; @@ -33,12 +34,12 @@ public class OrphanFileSystem : IProjectSystem private readonly ILogger _logger; [ImportingConstructor] - public OrphanFileSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [Import] ProjectSystem projectSystem) + public MiscellanousFiles(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [Import] ProjectSystem projectSystem) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); _projectSystem = projectSystem; } diff --git a/src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj b/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj similarity index 100% rename from src/OmniSharp.OrphanFiles/OmniSharp.OrphanFiles.csproj rename to src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index 0cf1fa5d5a..53c21e8b5b 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -8,7 +8,7 @@ - + From 8e6baecf3dabfb2d54f47cef0af4219fadc401ef Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 10 Jul 2018 13:51:09 -0700 Subject: [PATCH 12/54] Order the project systems --- .../OmniSharp.Abstractions.csproj | 1 + .../Utilities/ExtensionOrderer.Graph.cs} | 24 +++--- .../Utilities/ExtensionOrderer.Node.cs | 71 ++++++++++++++++ src/OmniSharp.Cake/CakeProjectSystem.cs | 2 + src/OmniSharp.DotNet/DotNetProjectSystem.cs | 2 + src/OmniSharp.Host/WorkspaceInitializer.cs | 14 ++- src/OmniSharp.MSBuild/ProjectSystem.cs | 2 + .../MiscellanousFiles.cs | 5 +- .../Refactoring/V2/BaseCodeActionService.cs | 8 +- .../V2/CodeActionsOrder.ProviderNode.cs | 85 ------------------- src/OmniSharp.Script/ScriptProjectSystem.cs | 2 + src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 2 +- 12 files changed, 113 insertions(+), 105 deletions(-) rename src/{OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.Graph.cs => OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs} (69%) create mode 100644 src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs delete mode 100644 src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.ProviderNode.cs diff --git a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj index 810b1fb324..069209f92a 100644 --- a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj +++ b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj @@ -7,6 +7,7 @@ + diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.Graph.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs similarity index 69% rename from src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.Graph.cs rename to src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs index 79c8a007c5..f555a0e37a 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.Graph.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs @@ -1,28 +1,28 @@ // Adapted from ExtensionOrderer in Roslyn using System.Collections.Generic; -namespace OmniSharp.Roslyn.CSharp.Services.Refactoring.V2 +namespace OmniSharp.Utilities { internal class Graph { //Dictionary to map between nodes and the names - private Dictionary> Nodes { get; } - private List> AllNodes { get; } - private Graph(List> nodesList) + private Dictionary> Nodes { get; } + private IEnumerable> AllNodes { get; } + private Graph(IEnumerable> nodesList) { - Nodes = new Dictionary>(); + Nodes = new Dictionary>(); AllNodes = nodesList; } - internal static Graph GetGraph(List> nodesList) + internal static Graph GetGraph(IEnumerable> nodesList) { var graph = new Graph(nodesList); - foreach (ProviderNode node in graph.AllNodes) + foreach (Node node in graph.AllNodes) { - graph.Nodes[node.ProviderName] = node; + graph.Nodes[node.Name] = node; } - foreach (ProviderNode node in graph.AllNodes) + foreach (Node node in graph.AllNodes) { foreach (var before in node.Before) { @@ -59,7 +59,7 @@ public bool HasCycles() public List TopologicalSort() { List result = new List(); - var seenNodes = new HashSet>(); + var seenNodes = new HashSet>(); foreach (var node in AllNodes) { @@ -69,7 +69,7 @@ public List TopologicalSort() return result; } - private void Visit(ProviderNode node, List result, HashSet> seenNodes) + private void Visit(Node node, List result, HashSet> seenNodes) { if (seenNodes.Add(node)) { @@ -78,7 +78,7 @@ private void Visit(ProviderNode node, List result, HashSet Visit(before, result, seenNodes); } - result.Add(node.Provider); + result.Add(node.Extension); } } } diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs new file mode 100644 index 0000000000..9def0e6424 --- /dev/null +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs @@ -0,0 +1,71 @@ +// Adapted from ExtensionOrderer in Roslyn +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.CodeAnalysis; + +namespace OmniSharp.Utilities +{ + internal class Node + { + public string Name { get; set; } + public List Before { get; set; } + public List After { get; set; } + public TNode Extension { get; set; } + public HashSet> NodesBeforeMeSet { get; set; } + + public static Node From(TNode extension, Func nameExtractor) where TNodeAttribute: Attribute + { + //we are getting two attributes here, how do we decide what name to use and what to do .... :/ + var attribute = extension.GetType().GetCustomAttribute(); + string name = nameExtractor(attribute); + //string name = string.Empty; + var orderAttributes = extension.GetType().GetCustomAttributes(true); + return new Node(extension, name, orderAttributes); + } + + private Node(TNode extension, string name, IEnumerable orderAttributes) + { + Extension = extension; + Name = name; + Before = new List(); + After = new List(); + NodesBeforeMeSet = new HashSet>(); + foreach(var attribute in orderAttributes) + { + AddAttribute(attribute); + } + } + + private void AddAttribute(ExtensionOrderAttribute attribute) + { + if (attribute.Before != null) + Before.Add(attribute.Before); + if (attribute.After != null) + After.Add(attribute.After); + } + + internal bool CheckForCycles() + { + return CheckForCycles(new HashSet>()); + } + + private bool CheckForCycles(HashSet> seenNodes) + { + if (!seenNodes.Add(this)) + { + //Cycle detected + return true; + } + + foreach (var before in this.NodesBeforeMeSet) + { + if (before.CheckForCycles(seenNodes)) + return true; + } + + seenNodes.Remove(this); + return false; + } + } +} diff --git a/src/OmniSharp.Cake/CakeProjectSystem.cs b/src/OmniSharp.Cake/CakeProjectSystem.cs index 28ff198a7c..606aca5ce6 100644 --- a/src/OmniSharp.Cake/CakeProjectSystem.cs +++ b/src/OmniSharp.Cake/CakeProjectSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -22,6 +23,7 @@ namespace OmniSharp.Cake { + [DisplayName(nameof(CakeProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class CakeProjectSystem : IProjectSystem { diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index cb073018a9..7b341d364b 100644 --- a/src/OmniSharp.DotNet/DotNetProjectSystem.cs +++ b/src/OmniSharp.DotNet/DotNetProjectSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -23,6 +24,7 @@ namespace OmniSharp.DotNet { + [DisplayName(nameof(DotNetProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class DotNetProjectSystem : IProjectSystem { diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index ffe3c0b766..1a8a3000dc 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Composition; using System.Composition.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -8,6 +11,7 @@ using OmniSharp.Roslyn; using OmniSharp.Roslyn.Options; using OmniSharp.Services; +using OmniSharp.Utilities; namespace OmniSharp { @@ -24,9 +28,17 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); + var projectSystems = compositionHost.GetExports(); + var nodes = new List>(); + foreach(var projectSystem in projectSystems) + { + nodes.Add(Node.From(projectSystem, attribute => attribute.DisplayName)); + } + var graph = Graph.GetGraph(nodes); + var sortedList = graph.TopologicalSort(); // Initialize all the project systems - foreach (var projectSystem in compositionHost.GetExports()) + foreach (var projectSystem in sortedList) { try { diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 3f9feb82a9..f0ec3cc424 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.ComponentModel; using System.Composition; using System.IO; using System.Threading.Tasks; @@ -20,6 +21,7 @@ namespace OmniSharp.MSBuild { + [DisplayName(nameof(ProjectSystem))] [Export(typeof(ProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class ProjectSystem : IProjectSystem diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 1884225bd2..2ad3a056f7 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Composition; using System.IO; using System.Threading.Tasks; @@ -11,16 +12,16 @@ using OmniSharp.FileWatching; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild; -using OmniSharp.Roslyn; using OmniSharp.Services; namespace OmniSharp.OrphanFiles { + [DisplayName(nameof(MiscellanousFiles))] [ExtensionOrder(After = nameof(ProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class MiscellanousFiles : IProjectSystem { - private string miscFileExtension = ".cs"; + private readonly string miscFileExtension = ".cs"; public string Key { get; } = "OrphanFiles"; public string Language { get; } = LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs index 8c213387b8..03db2e43c7 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs @@ -151,7 +151,7 @@ private async Task AppendFixesAsync(Document document, TextSpan span, IEnumerabl private List GetSortedCodeFixProviders() { - var nodesList = new List>(); + var nodesList = new List>(); var providerList = new List(); foreach (var provider in this.Providers) @@ -159,7 +159,7 @@ private List GetSortedCodeFixProviders() foreach (var codeFixProvider in provider.CodeFixProviders) { providerList.Add(codeFixProvider); - nodesList.Add(ProviderNode.From(codeFixProvider)); + nodesList.Add(Node.From(codeFixProvider,attribute => attribute.Name)); } } @@ -174,7 +174,7 @@ private List GetSortedCodeFixProviders() private List GetSortedCodeRefactoringProviders() { - var nodesList = new List>(); + var nodesList = new List>(); var providerList = new List(); foreach (var provider in this.Providers) @@ -182,7 +182,7 @@ private List GetSortedCodeRefactoringProviders() foreach (var codeRefactoringProvider in provider.CodeRefactoringProviders) { providerList.Add(codeRefactoringProvider); - nodesList.Add(ProviderNode.From(codeRefactoringProvider)); + nodesList.Add(Node.From(codeRefactoringProvider, attribute => attribute.Name)); } } diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.ProviderNode.cs b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.ProviderNode.cs deleted file mode 100644 index 92be73ac8a..0000000000 --- a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/CodeActionsOrder.ProviderNode.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Adapted from ExtensionOrderer in Roslyn -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CodeRefactorings; - -namespace OmniSharp.Roslyn.CSharp.Services.Refactoring.V2 -{ - internal class ProviderNode - { - public string ProviderName { get; set; } - public List Before { get; set; } - public List After { get; set; } - public TProvider Provider { get; set; } - public HashSet> NodesBeforeMeSet { get; set; } - - public static ProviderNode From(TProvider provider) - { - string providerName = ""; - if (provider is CodeFixProvider) - { - var exportAttribute = provider.GetType().GetCustomAttribute(typeof(ExportCodeFixProviderAttribute)); - if (exportAttribute is ExportCodeFixProviderAttribute fixAttribute && fixAttribute.Name != null) - { - providerName = fixAttribute.Name; - } - } - else - { - var exportAttribute = provider.GetType().GetCustomAttribute(typeof(ExportCodeRefactoringProviderAttribute)); - if (exportAttribute is ExportCodeRefactoringProviderAttribute refactoringAttribute && refactoringAttribute.Name != null) - { - providerName = refactoringAttribute.Name; - } - } - - var orderAttributes = provider.GetType().GetCustomAttributes(typeof(ExtensionOrderAttribute), true).Select(attr => (ExtensionOrderAttribute)attr).ToList(); - return new ProviderNode(provider, providerName, orderAttributes); - } - - private ProviderNode(TProvider provider, string providerName, List orderAttributes) - { - Provider = provider; - ProviderName = providerName; - Before = new List(); - After = new List(); - NodesBeforeMeSet = new HashSet>(); - orderAttributes.ForEach(attr => AddAttribute(attr)); - } - - private void AddAttribute(ExtensionOrderAttribute attribute) - { - if (attribute.Before != null) - Before.Add(attribute.Before); - if (attribute.After != null) - After.Add(attribute.After); - } - - internal bool CheckForCycles() - { - return CheckForCycles(new HashSet>()); - } - - private bool CheckForCycles(HashSet> seenNodes) - { - if (!seenNodes.Add(this)) - { - //Cycle detected - return true; - } - - foreach (var before in this.NodesBeforeMeSet) - { - if (before.CheckForCycles(seenNodes)) - return true; - } - - seenNodes.Remove(this); - return false; - } - } -} diff --git a/src/OmniSharp.Script/ScriptProjectSystem.cs b/src/OmniSharp.Script/ScriptProjectSystem.cs index e243c8fb92..e375bdb8b7 100644 --- a/src/OmniSharp.Script/ScriptProjectSystem.cs +++ b/src/OmniSharp.Script/ScriptProjectSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -17,6 +18,7 @@ namespace OmniSharp.Script { + [DisplayName(nameof(ScriptProjectSystem))] [Export(typeof(IProjectSystem)), Shared] public class ScriptProjectSystem : IProjectSystem { diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index 53c21e8b5b..e5eacb1ec1 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -8,7 +8,7 @@ - + From 439e9ad12d7dd27a732ece029a0204c63aa8b788 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 10 Jul 2018 16:50:06 -0700 Subject: [PATCH 13/54] Ordering failing --- .../Utilities/ExtensionOrderer.Node.cs | 12 +++--- .../Utilities/ExtensionOrderer.cs | 24 +++++++++++ .../Refactoring/V2/BaseCodeActionService.cs | 42 ++----------------- 3 files changed, 35 insertions(+), 43 deletions(-) create mode 100644 src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs index 9def0e6424..25fcc59267 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs @@ -14,12 +14,14 @@ internal class Node public TNode Extension { get; set; } public HashSet> NodesBeforeMeSet { get; set; } - public static Node From(TNode extension, Func nameExtractor) where TNodeAttribute: Attribute + public static Node From(TNode extension, Func nameExtractor) where TNodeAttribute : Attribute { - //we are getting two attributes here, how do we decide what name to use and what to do .... :/ + string name = string.Empty; var attribute = extension.GetType().GetCustomAttribute(); - string name = nameExtractor(attribute); - //string name = string.Empty; + if (attribute is TNodeAttribute && !string.IsNullOrEmpty(nameExtractor(attribute))) + { + name = nameExtractor(attribute); + } var orderAttributes = extension.GetType().GetCustomAttributes(true); return new Node(extension, name, orderAttributes); } @@ -31,7 +33,7 @@ private Node(TNode extension, string name, IEnumerable Before = new List(); After = new List(); NodesBeforeMeSet = new HashSet>(); - foreach(var attribute in orderAttributes) + foreach (var attribute in orderAttributes) { AddAttribute(attribute); } diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs new file mode 100644 index 0000000000..5df41afb26 --- /dev/null +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OmniSharp.Utilities +{ + static class ExtensionOrderer + { + /* Returns a sorted order of the nodes if such a sorting exists, else returns the unsorted list */ + public static IEnumerable GetOrderedOrUnorderedList(IEnumerable unsortedList, Func nameExtractor) where TAttribute: Attribute + { + var nodesList = unsortedList.Select(elem => Node.From(elem, nameExtractor)); + var graph = Graph.GetGraph(nodesList); + if (graph.HasCycles()) + { + return unsortedList; + } + + return graph.TopologicalSort(); + } + } +} diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs index 03db2e43c7..9d74803837 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs @@ -151,48 +151,14 @@ private async Task AppendFixesAsync(Document document, TextSpan span, IEnumerabl private List GetSortedCodeFixProviders() { - var nodesList = new List>(); - var providerList = new List(); - - foreach (var provider in this.Providers) - { - foreach (var codeFixProvider in provider.CodeFixProviders) - { - providerList.Add(codeFixProvider); - nodesList.Add(Node.From(codeFixProvider,attribute => attribute.Name)); - } - } - - var graph = Graph.GetGraph(nodesList); - if (graph.HasCycles()) - { - return providerList; - } - - return graph.TopologicalSort(); + var providerList = this.Providers.SelectMany(provider => provider.CodeFixProviders); + return ExtensionOrderer.GetOrderedOrUnorderedList(providerList, attribute => attribute.Name).ToList(); } private List GetSortedCodeRefactoringProviders() { - var nodesList = new List>(); - var providerList = new List(); - - foreach (var provider in this.Providers) - { - foreach (var codeRefactoringProvider in provider.CodeRefactoringProviders) - { - providerList.Add(codeRefactoringProvider); - nodesList.Add(Node.From(codeRefactoringProvider, attribute => attribute.Name)); - } - } - - var graph = Graph.GetGraph(nodesList); - if (graph.HasCycles()) - { - return providerList; - } - - return graph.TopologicalSort(); + var providerList = this.Providers.SelectMany(provider => provider.CodeRefactoringProviders); + return ExtensionOrderer.GetOrderedOrUnorderedList(providerList, attribute => attribute.Name).ToList(); } private bool HasFix(CodeFixProvider codeFixProvider, string diagnosticId) From 2bbfe5b01080e2c84da5bceedc7038e74510eb99 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 10 Jul 2018 18:07:12 -0700 Subject: [PATCH 14/54] Order project systems based on DisplayName --- .../Utilities/ExtensionOrderer.Graph.cs | 6 +++--- .../Utilities/ExtensionOrderer.cs | 11 +++-------- src/OmniSharp.Host/WorkspaceInitializer.cs | 13 +++---------- tests/TestUtility/TestUtility.csproj | 1 + 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs index f555a0e37a..fcf63030cf 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs @@ -7,13 +7,13 @@ internal class Graph { //Dictionary to map between nodes and the names private Dictionary> Nodes { get; } - private IEnumerable> AllNodes { get; } - private Graph(IEnumerable> nodesList) + private List> AllNodes { get; } + private Graph(List> nodesList) { Nodes = new Dictionary>(); AllNodes = nodesList; } - internal static Graph GetGraph(IEnumerable> nodesList) + internal static Graph GetGraph(List> nodesList) { var graph = new Graph(nodesList); diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs index 5df41afb26..1f201f3873 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs @@ -11,14 +11,9 @@ static class ExtensionOrderer /* Returns a sorted order of the nodes if such a sorting exists, else returns the unsorted list */ public static IEnumerable GetOrderedOrUnorderedList(IEnumerable unsortedList, Func nameExtractor) where TAttribute: Attribute { - var nodesList = unsortedList.Select(elem => Node.From(elem, nameExtractor)); - var graph = Graph.GetGraph(nodesList); - if (graph.HasCycles()) - { - return unsortedList; - } - - return graph.TopologicalSort(); + var nodesList = unsortedList.Select(elem => Node.From(elem, nameExtractor)); + var graph = Graph.GetGraph(nodesList.ToList()); + return graph.HasCycles() ? unsortedList : graph.TopologicalSort(); } } } diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 1a8a3000dc..ba5f725472 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -29,16 +29,9 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); var projectSystems = compositionHost.GetExports(); - var nodes = new List>(); - foreach(var projectSystem in projectSystems) - { - nodes.Add(Node.From(projectSystem, attribute => attribute.DisplayName)); - } - var graph = Graph.GetGraph(nodes); - var sortedList = graph.TopologicalSort(); - - // Initialize all the project systems - foreach (var projectSystem in sortedList) + var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(projectSystems, attribute => attribute.DisplayName); + + foreach (var projectSystem in orderedProjectSystems) { try { diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index f33ce183c1..c13697e46b 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -9,6 +9,7 @@ + From 35e263005edb53a397423d5c8d06da5aa982cf3b Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 10 Jul 2018 18:10:45 -0700 Subject: [PATCH 15/54] Remove orphan system --- src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 2ad3a056f7..da02985400 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -14,7 +14,7 @@ using OmniSharp.MSBuild; using OmniSharp.Services; -namespace OmniSharp.OrphanFiles +namespace OmniSharp.MicellanousFiles { [DisplayName(nameof(MiscellanousFiles))] [ExtensionOrder(After = nameof(ProjectSystem))] @@ -22,7 +22,7 @@ namespace OmniSharp.OrphanFiles public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; - public string Key { get; } = "OrphanFiles"; + public string Key { get; } = "MiscellanousFiles"; public string Language { get; } = LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; From 999bf3fb0d70c432f109645d8ef9e95a4493e824 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 10 Jul 2018 18:14:09 -0700 Subject: [PATCH 16/54] Put inside the partial class --- .../Utilities/ExtensionOrderer.Graph.cs | 109 +++++++++--------- .../Utilities/ExtensionOrderer.Node.cs | 97 ++++++++-------- .../Utilities/ExtensionOrderer.cs | 2 +- 3 files changed, 107 insertions(+), 101 deletions(-) diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs index fcf63030cf..4abd245418 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs @@ -3,82 +3,85 @@ namespace OmniSharp.Utilities { - internal class Graph + static partial class ExtensionOrderer { - //Dictionary to map between nodes and the names - private Dictionary> Nodes { get; } - private List> AllNodes { get; } - private Graph(List> nodesList) + internal class Graph { - Nodes = new Dictionary>(); - AllNodes = nodesList; - } - internal static Graph GetGraph(List> nodesList) - { - var graph = new Graph(nodesList); - - foreach (Node node in graph.AllNodes) + //Dictionary to map between nodes and the names + private Dictionary> Nodes { get; } + private List> AllNodes { get; } + private Graph(List> nodesList) { - graph.Nodes[node.Name] = node; + Nodes = new Dictionary>(); + AllNodes = nodesList; } - - foreach (Node node in graph.AllNodes) + internal static Graph GetGraph(List> nodesList) { - foreach (var before in node.Before) + var graph = new Graph(nodesList); + + foreach (Node node in graph.AllNodes) { - if (graph.Nodes.ContainsKey(before)) - { - var beforeNode = graph.Nodes[before]; - beforeNode.NodesBeforeMeSet.Add(node); - } + graph.Nodes[node.Name] = node; } - foreach (var after in node.After) + foreach (Node node in graph.AllNodes) { - if (graph.Nodes.ContainsKey(after)) + foreach (var before in node.Before) { - var afterNode = graph.Nodes[after]; - node.NodesBeforeMeSet.Add(afterNode); + if (graph.Nodes.ContainsKey(before)) + { + var beforeNode = graph.Nodes[before]; + beforeNode.NodesBeforeMeSet.Add(node); + } + } + + foreach (var after in node.After) + { + if (graph.Nodes.ContainsKey(after)) + { + var afterNode = graph.Nodes[after]; + node.NodesBeforeMeSet.Add(afterNode); + } } } - } - return graph; - } + return graph; + } - public bool HasCycles() - { - foreach (var node in this.AllNodes) + public bool HasCycles() { - if (node.CheckForCycles()) - return true; + foreach (var node in this.AllNodes) + { + if (node.CheckForCycles()) + return true; + } + return false; } - return false; - } - - public List TopologicalSort() - { - List result = new List(); - var seenNodes = new HashSet>(); - foreach (var node in AllNodes) + public List TopologicalSort() { - Visit(node, result, seenNodes); - } + List result = new List(); + var seenNodes = new HashSet>(); - return result; - } + foreach (var node in AllNodes) + { + Visit(node, result, seenNodes); + } - private void Visit(Node node, List result, HashSet> seenNodes) - { - if (seenNodes.Add(node)) + return result; + } + + private void Visit(Node node, List result, HashSet> seenNodes) { - foreach (var before in node.NodesBeforeMeSet) + if (seenNodes.Add(node)) { - Visit(before, result, seenNodes); - } + foreach (var before in node.NodesBeforeMeSet) + { + Visit(before, result, seenNodes); + } - result.Add(node.Extension); + result.Add(node.Extension); + } } } } diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs index 25fcc59267..383570f8f5 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs @@ -6,68 +6,71 @@ namespace OmniSharp.Utilities { - internal class Node + static partial class ExtensionOrderer { - public string Name { get; set; } - public List Before { get; set; } - public List After { get; set; } - public TNode Extension { get; set; } - public HashSet> NodesBeforeMeSet { get; set; } - - public static Node From(TNode extension, Func nameExtractor) where TNodeAttribute : Attribute + internal class Node { - string name = string.Empty; - var attribute = extension.GetType().GetCustomAttribute(); - if (attribute is TNodeAttribute && !string.IsNullOrEmpty(nameExtractor(attribute))) + public string Name { get; set; } + public List Before { get; set; } + public List After { get; set; } + public TNode Extension { get; set; } + public HashSet> NodesBeforeMeSet { get; set; } + + public static Node From(TNode extension, Func nameExtractor) where TNodeAttribute : Attribute { - name = nameExtractor(attribute); + string name = string.Empty; + var attribute = extension.GetType().GetCustomAttribute(); + if (attribute is TNodeAttribute && !string.IsNullOrEmpty(nameExtractor(attribute))) + { + name = nameExtractor(attribute); + } + var orderAttributes = extension.GetType().GetCustomAttributes(true); + return new Node(extension, name, orderAttributes); } - var orderAttributes = extension.GetType().GetCustomAttributes(true); - return new Node(extension, name, orderAttributes); - } - private Node(TNode extension, string name, IEnumerable orderAttributes) - { - Extension = extension; - Name = name; - Before = new List(); - After = new List(); - NodesBeforeMeSet = new HashSet>(); - foreach (var attribute in orderAttributes) + private Node(TNode extension, string name, IEnumerable orderAttributes) { - AddAttribute(attribute); + Extension = extension; + Name = name; + Before = new List(); + After = new List(); + NodesBeforeMeSet = new HashSet>(); + foreach (var attribute in orderAttributes) + { + AddAttribute(attribute); + } } - } - - private void AddAttribute(ExtensionOrderAttribute attribute) - { - if (attribute.Before != null) - Before.Add(attribute.Before); - if (attribute.After != null) - After.Add(attribute.After); - } - internal bool CheckForCycles() - { - return CheckForCycles(new HashSet>()); - } + private void AddAttribute(ExtensionOrderAttribute attribute) + { + if (attribute.Before != null) + Before.Add(attribute.Before); + if (attribute.After != null) + After.Add(attribute.After); + } - private bool CheckForCycles(HashSet> seenNodes) - { - if (!seenNodes.Add(this)) + internal bool CheckForCycles() { - //Cycle detected - return true; + return CheckForCycles(new HashSet>()); } - foreach (var before in this.NodesBeforeMeSet) + private bool CheckForCycles(HashSet> seenNodes) { - if (before.CheckForCycles(seenNodes)) + if (!seenNodes.Add(this)) + { + //Cycle detected return true; - } + } - seenNodes.Remove(this); - return false; + foreach (var before in this.NodesBeforeMeSet) + { + if (before.CheckForCycles(seenNodes)) + return true; + } + + seenNodes.Remove(this); + return false; + } } } } diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs index 1f201f3873..93ab08cf10 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs +++ b/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs @@ -6,7 +6,7 @@ namespace OmniSharp.Utilities { - static class ExtensionOrderer + static partial class ExtensionOrderer { /* Returns a sorted order of the nodes if such a sorting exists, else returns the unsorted list */ public static IEnumerable GetOrderedOrUnorderedList(IEnumerable unsortedList, Func nameExtractor) where TAttribute: Attribute From 81321cd3e99831cbeaf6db702fbe593bfb0b2ee0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Jul 2018 16:19:58 -0700 Subject: [PATCH 17/54] Clean up the miscellanous file system --- src/OmniSharp.MSBuild/ProjectSystem.cs | 2 +- .../MiscellanousFiles.cs | 30 +++++++++++------ src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 32 ++++++++----------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index f0ec3cc424..6632ed6621 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -213,7 +213,7 @@ async Task IProjectSystem.GetProjectModelAsync(string filePath) return new MSBuildProjectInfo(projectFileInfo); } - public async Task hasCompletedUpdateRequest() + public async Task HasCompletedUpdateRequest() { await _manager.WaitForQueueEmptyAsync(); } diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index da02985400..874a1ef4e4 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -27,7 +27,7 @@ public class MiscellanousFiles : IProjectSystem IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; - private readonly ConcurrentDictionary _documents = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _projects = new ConcurrentDictionary(); private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; @@ -60,22 +60,33 @@ void IProjectSystem.Initalize(IConfiguration configuration) foreach (var filePath in allFiles) AddIfMiscellanousFile(filePath); - _fileSystemWatcher.Watch(miscFileExtension, onFileChanged); + _fileSystemWatcher.Watch(miscFileExtension, OnMiscellanousFileChanged); } private async void AddIfMiscellanousFile(string filePath) { //wait for the project system to get initialised - await _projectSystem.hasCompletedUpdateRequest(); + await _projectSystem.HasCompletedUpdateRequest(); if (_workspace.GetDocument(filePath) == null) { - var documentId =_workspace.AddMiscellanousFile(filePath, Language); - _documents.TryAdd(filePath, documentId); + string assemblyName = Guid.NewGuid().ToString("N"); + var projectInfo = ProjectInfo.Create( + filePath: filePath, + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: Path.GetFileName(filePath), + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: Language); + + _workspace.AddProject(projectInfo); + _workspace.AddMiscellanousFileDocument(projectInfo.Id, filePath); + _projects[filePath] = projectInfo; _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); } } - private void onFileChanged(string filePath, FileChangeType changeType) + private void OnMiscellanousFileChanged(string filePath, FileChangeType changeType) { if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || changeType == FileChangeType.Create) @@ -92,11 +103,10 @@ private void onFileChanged(string filePath, FileChangeType changeType) private void RemoveFromWorkspace(string filePath) { - if (_documents.TryRemove(filePath, out var documentId)) + if (_projects.TryRemove(filePath, out var project)) { - _workspace.RemoveDocument(documentId); - //ToDo: Identify if we need to remove the project here and how - _logger.LogInformation($"Removed file '{filePath}' from the workspace."); + _workspace.RemoveMiscellanousFileDocument(project.Id); + _logger.LogDebug($"Removed file '{filePath}' from the workspace."); } } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 5a08cb8e1b..c09184dada 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -86,6 +86,20 @@ public void AddDocument(DocumentInfo documentInfo) OnDocumentAdded(documentInfo); } + public void AddMiscellanousFileDocument(ProjectId projectId, string filePath) + { + var documentId = AddDocument(projectId, filePath); + _miscellanousFiles.Add(documentId); + } + + public void RemoveMiscellanousFileDocument(ProjectId projectId) + { + var project = CurrentSolution.GetProject(projectId); + var id = project.DocumentIds.First(); + _miscellanousFiles.Remove(id); + RemoveProject(projectId); + } + public DocumentId AddDocument(ProjectId projectId, string filePath, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) { var documentId = DocumentId.CreateNewId(projectId); @@ -228,24 +242,6 @@ private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText } } - public DocumentId AddMiscellanousFile(string filePath, string language) - { - string assemblyName = Guid.NewGuid().ToString("N"); - var project = ProjectInfo.Create( - filePath: filePath, - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: Path.GetFileName(filePath), - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - language: language); - - AddProject(project); - var documentId = AddDocument(project.Id, filePath); - _miscellanousFiles.Add(documentId); - return documentId; - } - public bool IsCapableOfSemanticDiagnostics(Document document) { var documentId = GetDocumentId(document.FilePath); From 7e6ba334214b5d66edddfa616b264ba1df94b2c0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 23 Jul 2018 15:24:05 -0700 Subject: [PATCH 18/54] Tests for the misc project system --- OmniSharp.sln | 15 ++++++ .../Mef/ExportIProjectSystemAttribute.cs | 18 ++++++++ src/OmniSharp.Cake/CakeProjectSystem.cs | 5 +- src/OmniSharp.DotNet/DotNetProjectSystem.cs | 5 +- src/OmniSharp.Host/WorkspaceInitializer.cs | 4 +- src/OmniSharp.MSBuild/ProjectSystem.cs | 5 +- .../MiscellanousFiles.cs | 6 +-- src/OmniSharp.Script/ScriptProjectSystem.cs | 5 +- .../HelloWorld/HelloWorld.csproj | 8 ++++ .../ProjectWithMiscFile/HelloWorld/Program.cs | 12 +++++ .../AssemblyInfo.cs | 1 + .../DiagnosticsFacts.cs | 46 +++++++++++++++++++ .../OmniSharp.MiscellanousFiles.Tests.csproj | 27 +++++++++++ tests/TestUtility/OmniSharpTestHost.cs | 2 + 14 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs create mode 100644 test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj create mode 100644 test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs create mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs create mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs create mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj diff --git a/OmniSharp.sln b/OmniSharp.sln index b5a3645a26..28fa2c78ec 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -73,6 +73,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Script.Tests", "t EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.MiscellanousFiles", "src\OmniSharp.MiscellanousFiles\OmniSharp.MiscellanousFiles.csproj", "{2BF50528-38C4-4928-9FB2-7539A3C20DA8}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.MiscellanousFiles.Tests", "tests\OmniSharp.MiscellanousFiles.Tests\OmniSharp.MiscellanousFiles.Tests.csproj", "{CFDBAAF4-C579-4514-9A25-EA132CD47C65}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -419,6 +421,18 @@ Global {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x64.Build.0 = Release|Any CPU {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.ActiveCfg = Release|Any CPU {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.Build.0 = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x64.ActiveCfg = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x64.Build.0 = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x86.ActiveCfg = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x86.Build.0 = Debug|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|Any CPU.Build.0 = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x64.ActiveCfg = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x64.Build.0 = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x86.ActiveCfg = Release|Any CPU + {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -452,6 +466,7 @@ Global {D2A78CEE-B278-476F-AF34-A7D6F792F973} = {2C348365-A9D8-459E-9276-56FC46AAEE31} {9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47} {2BF50528-38C4-4928-9FB2-7539A3C20DA8} = {2C348365-A9D8-459E-9276-56FC46AAEE31} + {CFDBAAF4-C579-4514-9A25-EA132CD47C65} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E} diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs new file mode 100644 index 0000000000..169354ae55 --- /dev/null +++ b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs @@ -0,0 +1,18 @@ +using OmniSharp.Services; +using System; +using System.ComponentModel.Composition; + +namespace OmniSharp.Mef +{ + [MetadataAttribute] + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class ExportIProjectSystemAttribute: ExportAttribute + { + public string Name; + + public ExportIProjectSystemAttribute(string name) : base(name, typeof(IProjectSystem)) + { + Name = name; + } + } +} diff --git a/src/OmniSharp.Cake/CakeProjectSystem.cs b/src/OmniSharp.Cake/CakeProjectSystem.cs index 606aca5ce6..fd140d66f5 100644 --- a/src/OmniSharp.Cake/CakeProjectSystem.cs +++ b/src/OmniSharp.Cake/CakeProjectSystem.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -17,14 +16,14 @@ using OmniSharp.FileSystem; using OmniSharp.FileWatching; using OmniSharp.Helpers; +using OmniSharp.Mef; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.Roslyn.Utilities; using OmniSharp.Services; namespace OmniSharp.Cake { - [DisplayName(nameof(CakeProjectSystem))] - [Export(typeof(IProjectSystem)), Shared] + [ExportIProjectSystem(nameof(CakeProjectSystem)), Shared] public class CakeProjectSystem : IProjectSystem { private readonly OmniSharpWorkspace _workspace; diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index 7b341d364b..7143c0010f 100644 --- a/src/OmniSharp.DotNet/DotNetProjectSystem.cs +++ b/src/OmniSharp.DotNet/DotNetProjectSystem.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -18,14 +17,14 @@ using OmniSharp.Eventing; using OmniSharp.FileWatching; using OmniSharp.Helpers; +using OmniSharp.Mef; using OmniSharp.Models.Events; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.Services; namespace OmniSharp.DotNet { - [DisplayName(nameof(DotNetProjectSystem))] - [Export(typeof(IProjectSystem)), Shared] + [ExportIProjectSystem(nameof(DotNetProjectSystem)), Shared] public class DotNetProjectSystem : IProjectSystem { private const string CompilationConfiguration = "Debug"; diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index ba5f725472..78b67dbe27 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -29,8 +29,8 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); var projectSystems = compositionHost.GetExports(); - var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(projectSystems, attribute => attribute.DisplayName); - + var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(projectSystems, _=> null); + foreach (var projectSystem in orderedProjectSystems) { try diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 6632ed6621..79121ba753 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.ComponentModel; using System.Composition; using System.IO; using System.Threading.Tasks; @@ -11,6 +10,7 @@ using OmniSharp.Eventing; using OmniSharp.FileSystem; using OmniSharp.FileWatching; +using OmniSharp.Mef; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild.Discovery; using OmniSharp.MSBuild.Models; @@ -21,9 +21,8 @@ namespace OmniSharp.MSBuild { - [DisplayName(nameof(ProjectSystem))] [Export(typeof(ProjectSystem))] - [Export(typeof(IProjectSystem)), Shared] + [ExportIProjectSystem(nameof(ProjectSystem)), Shared] public class ProjectSystem : IProjectSystem { private readonly IOmniSharpEnvironment _environment; diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 874a1ef4e4..b722200e50 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -10,15 +10,15 @@ using Microsoft.Extensions.Logging; using OmniSharp.FileSystem; using OmniSharp.FileWatching; +using OmniSharp.Mef; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild; using OmniSharp.Services; -namespace OmniSharp.MicellanousFiles +namespace OmniSharp.MiscellanousFiles { - [DisplayName(nameof(MiscellanousFiles))] [ExtensionOrder(After = nameof(ProjectSystem))] - [Export(typeof(IProjectSystem)), Shared] + [ExportIProjectSystem(nameof(MiscellanousFiles)), Shared] public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; diff --git a/src/OmniSharp.Script/ScriptProjectSystem.cs b/src/OmniSharp.Script/ScriptProjectSystem.cs index e375bdb8b7..8be4eb26da 100644 --- a/src/OmniSharp.Script/ScriptProjectSystem.cs +++ b/src/OmniSharp.Script/ScriptProjectSystem.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; @@ -13,13 +12,13 @@ using Microsoft.Extensions.Logging; using OmniSharp.FileSystem; using OmniSharp.FileWatching; +using OmniSharp.Mef; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.Services; namespace OmniSharp.Script { - [DisplayName(nameof(ScriptProjectSystem))] - [Export(typeof(IProjectSystem)), Shared] + [ExportIProjectSystem(nameof(ScriptProjectSystem)), Shared] public class ScriptProjectSystem : IProjectSystem { private const string CsxExtension = ".csx"; diff --git a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj new file mode 100644 index 0000000000..23df6047ff --- /dev/null +++ b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs new file mode 100644 index 0000000000..8168c80511 --- /dev/null +++ b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace HelloWorld +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs b/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs new file mode 100644 index 0000000000..9933b8fd08 --- /dev/null +++ b/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)] diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs new file mode 100644 index 0000000000..342551db90 --- /dev/null +++ b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; +using OmniSharp.Models.CodeCheck; +using OmniSharp.Models.FilesChanged; +using OmniSharp.Roslyn.CSharp.Services.Diagnostics; +using OmniSharp.Roslyn.CSharp.Services.Files; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.MiscellanousFiles.Tests +{ + public class DiagnosticsFacts : AbstractTestFixture + { + public DiagnosticsFacts(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public async Task Returns_only_semantic_diagnotics() + { + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld")) + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = testProject.AddDisposableFile("a.cs", "class C { int n = true; }"); + var service = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); + await service.Handle(new[] + { + new FilesChangedRequest + { + FileName = filePath, + ChangeType = FileWatching.FileChangeType.Create + } + }); + + await Task.Delay(2000); + + var service1 = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); + var quickFixes = await service1.Handle(new CodeCheckRequest()); + + // back off for 2 seconds to let the watcher and workspace process new projects + Assert.Single(quickFixes.QuickFixes); + } + } + } +} diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj b/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj new file mode 100644 index 0000000000..cd8b8326ee --- /dev/null +++ b/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj @@ -0,0 +1,27 @@ + + + + net46 + AnyCPU + true + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 2d547b1ed1..c884e10319 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -14,6 +14,7 @@ using OmniSharp.DotNetTest.Models; using OmniSharp.Eventing; using OmniSharp.Mef; +using OmniSharp.MiscellanousFiles; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild; using OmniSharp.Options; @@ -39,6 +40,7 @@ public class OmniSharpTestHost : DisposableObject typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, // OmniSharp.Roslyn typeof(RoslynFeaturesHostServicesProvider).GetTypeInfo().Assembly, // OmniSharp.Roslyn.CSharp typeof(CakeProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Cake + typeof(MiscellanousFiles).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles }); private readonly TestServiceProvider _serviceProvider; From eba6ae2298d96745958e2abac50a0bc6da55d503 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 23 Jul 2018 16:19:34 -0700 Subject: [PATCH 19/54] Make MEF work --- .../Mef/ExportIProjectSystemAttribute.cs | 15 ++++++++--- .../Mef/IOrderableMetadata.cs | 26 +++++++++++++++++++ src/OmniSharp.Host/WorkspaceInitializer.cs | 8 ++++-- .../MiscellanousFiles.cs | 4 +-- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs index 169354ae55..d8ad417a6c 100644 --- a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs +++ b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs @@ -1,6 +1,6 @@ using OmniSharp.Services; using System; -using System.ComponentModel.Composition; +using System.Composition; namespace OmniSharp.Mef { @@ -8,11 +8,20 @@ namespace OmniSharp.Mef [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class ExportIProjectSystemAttribute: ExportAttribute { - public string Name; + public string Name { get; } + public string Before { get; } + public string After { get; } - public ExportIProjectSystemAttribute(string name) : base(name, typeof(IProjectSystem)) + public ExportIProjectSystemAttribute(string name, string before="", string after="") : base(typeof(IProjectSystem)) { Name = name; + Before = before; + After = after; } } + + public class ProjectSystemMetadata + { + string Name { get; set; } + } } diff --git a/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs b/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs new file mode 100644 index 0000000000..78cf12c760 --- /dev/null +++ b/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OmniSharp.Mef +{ + internal interface IOrderableMetadata + { + [DefaultValue("")] + string After { get; } + [DefaultValue("")] + string Before { get; } + string Name { get; } + } + + class OrderableMetadata + { + public string After { get; set; } + + public string Before { get; set; } + public string Name { get; set; } + } +} diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 78b67dbe27..c4bc8b860a 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -3,10 +3,12 @@ using System.ComponentModel; using System.Composition; using System.Composition.Hosting; +using System.Linq; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using OmniSharp.Mef; using OmniSharp.Options; using OmniSharp.Roslyn; using OmniSharp.Roslyn.Options; @@ -28,8 +30,10 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); - var projectSystems = compositionHost.GetExports(); - var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(projectSystems, _=> null); + var projectSystems = compositionHost.GetExports>(); + var ps = projectSystems.Select(n => n.Value); + var qs = projectSystems.Select(n => n.Metadata); + var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); foreach (var projectSystem in orderedProjectSystems) { diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index b722200e50..e2385fe33c 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -17,8 +17,8 @@ namespace OmniSharp.MiscellanousFiles { - [ExtensionOrder(After = nameof(ProjectSystem))] - [ExportIProjectSystem(nameof(MiscellanousFiles)), Shared] + //[ExtensionOrder(After = nameof(ProjectSystem))] + [ExportIProjectSystem("Misc files", after: nameof(ProjectSystem)), Shared] public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; From 895cf5b8cf95c8efb7e0bdd317b92820623b004e Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 23 Jul 2018 19:14:10 -0700 Subject: [PATCH 20/54] Returns only semantic diagnostics running --- .../HelloWorld/HelloWorld.csproj | 8 -------- .../ProjectWithMiscFile/HelloWorld/Program.cs | 12 ------------ .../DiagnosticsFacts.cs | 17 +++++++++-------- 3 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj delete mode 100644 test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs diff --git a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj deleted file mode 100644 index 23df6047ff..0000000000 --- a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/HelloWorld.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - netcoreapp2.1 - - - diff --git a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs b/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs deleted file mode 100644 index 8168c80511..0000000000 --- a/test-assets/test-projects/ProjectWithMiscFile/HelloWorld/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace HelloWorld -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs index 342551db90..e41a9c1acc 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs +++ b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using OmniSharp.Models.CodeCheck; using OmniSharp.Models.FilesChanged; using OmniSharp.Roslyn.CSharp.Services.Diagnostics; @@ -19,12 +20,12 @@ public DiagnosticsFacts(ITestOutputHelper output) [Fact] public async Task Returns_only_semantic_diagnotics() { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = testProject.AddDisposableFile("a.cs", "class C { int n = true; }"); - var service = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); - await service.Handle(new[] + var filePath = testProject.AddDisposableFile("a.cs", "class C { b a = new b(); int n }"); + var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); + await fileChangedService.Handle(new[] { new FilesChangedRequest { @@ -35,11 +36,11 @@ await service.Handle(new[] await Task.Delay(2000); - var service1 = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); - var quickFixes = await service1.Handle(new CodeCheckRequest()); + var codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); + var quickFixes = await codeCheckService.Handle(new CodeCheckRequest()); - // back off for 2 seconds to let the watcher and workspace process new projects Assert.Single(quickFixes.QuickFixes); + Assert.Equal("; expected", quickFixes.QuickFixes.First().Text); } } } From c422035d9bbbbc1e637c3e5c53aa362ef9d7f36a Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 24 Jul 2018 16:25:28 -0700 Subject: [PATCH 21/54] Add more failing tests --- .../DiagnosticsFacts.cs | 71 +++++++++++++++---- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs index e41a9c1acc..ed1f0fc00d 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs +++ b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs @@ -1,9 +1,12 @@ using System.Linq; using System.Threading.Tasks; +using OmniSharp.Mef; using OmniSharp.Models.CodeCheck; using OmniSharp.Models.FilesChanged; +using OmniSharp.Models.SignatureHelp; using OmniSharp.Roslyn.CSharp.Services.Diagnostics; using OmniSharp.Roslyn.CSharp.Services.Files; +using OmniSharp.Roslyn.CSharp.Services.Signatures; using TestUtility; using Xunit; using Xunit.Abstractions; @@ -18,15 +21,63 @@ public DiagnosticsFacts(ITestOutputHelper output) } [Fact] - public async Task Returns_only_semantic_diagnotics() + public async Task Returns_only_syntactic_diagnotics() { using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) - using (var host = CreateOmniSharpHost(testProject.Directory)) { - var filePath = testProject.AddDisposableFile("a.cs", "class C { b a = new b(); int n }"); - var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); - await fileChangedService.Handle(new[] + var testFile = new TestFile("a.cs", "class C { b a = new b(); int n }"); + using (var host = await AddMiscellanousFile(testProject, testFile)) { + var codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); + var quickFixes = await codeCheckService.Handle(new CodeCheckRequest()); + Assert.Single(quickFixes.QuickFixes); + Assert.Equal("; expected", quickFixes.QuickFixes.First().Text); + } + } + } + + [Fact] + public async Task Returns_signature_help() + { + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + const string source = +@"class Program +{ + public static void Main(){ + System.Guid.NewGuid($$); + } +}"; + var testFile = new TestFile("a.cs", source); + using (var host = await AddMiscellanousFile(testProject, testFile)) + { + var service = host.GetRequestHandler(OmniSharpEndpoints.SignatureHelp); + var point = testFile.Content.GetPointFromPosition(); + var request = new SignatureHelpRequest() + { + FileName = testFile.FileName, + Line = point.Line, + Column = point.Offset, + Buffer = testFile.Content.Code + }; + + var actual = await service.Handle(request); + Assert.Single(actual.Signatures); + Assert.Equal(0, actual.ActiveParameter); + Assert.Equal(0, actual.ActiveSignature); + Assert.Equal("NewGuid", actual.Signatures.ElementAt(0).Name); + Assert.Empty(actual.Signatures.ElementAt(0).Parameters); + } + } + } + + private async Task AddMiscellanousFile(ITestProject testProject, TestFile testfile) + { + var host = CreateOmniSharpHost(testProject.Directory); + var filePath = testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); + var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); + await fileChangedService.Handle(new[] + { new FilesChangedRequest { FileName = filePath, @@ -34,14 +85,8 @@ await fileChangedService.Handle(new[] } }); - await Task.Delay(2000); - - var codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); - var quickFixes = await codeCheckService.Handle(new CodeCheckRequest()); - - Assert.Single(quickFixes.QuickFixes); - Assert.Equal("; expected", quickFixes.QuickFixes.First().Text); - } + await Task.Delay(2000); + return host; } } } From 57bfbc51eae8077d3bf8bdacac752cb9f845112b Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 24 Jul 2018 18:05:38 -0700 Subject: [PATCH 22/54] Clean up --- .../Mef/ExportIProjectSystemAttribute.cs | 10 +++------- src/OmniSharp.Host/WorkspaceInitializer.cs | 1 - src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs index d8ad417a6c..37b82804c9 100644 --- a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs +++ b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs @@ -1,6 +1,7 @@ -using OmniSharp.Services; -using System; +using System; using System.Composition; +using Microsoft.CodeAnalysis; +using OmniSharp.Services; namespace OmniSharp.Mef { @@ -19,9 +20,4 @@ public ExportIProjectSystemAttribute(string name, string before="", string after After = after; } } - - public class ProjectSystemMetadata - { - string Name { get; set; } - } } diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index c4bc8b860a..822fdffdc3 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -32,7 +32,6 @@ public static void Initialize( projectEventForwarder.Initialize(); var projectSystems = compositionHost.GetExports>(); var ps = projectSystems.Select(n => n.Value); - var qs = projectSystems.Select(n => n.Metadata); var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); foreach (var projectSystem in orderedProjectSystems) diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index e2385fe33c..a805bb549e 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -18,7 +18,7 @@ namespace OmniSharp.MiscellanousFiles { //[ExtensionOrder(After = nameof(ProjectSystem))] - [ExportIProjectSystem("Misc files", after: nameof(ProjectSystem)), Shared] + [ExportIProjectSystem("MiscellanousFiles", after: nameof(ProjectSystem)), Shared] public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; From 48b4c2630233ecaadbd51ff7d205bb99bdc7a80f Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 25 Jul 2018 11:06:20 -0700 Subject: [PATCH 23/54] Extension Ordering working for the project systems --- .../Mef/ExportIProjectSystemAttribute.cs | 8 ++----- .../Mef/IOrderableMetadata.cs | 23 ++----------------- src/OmniSharp.Host/WorkspaceInitializer.cs | 2 +- src/OmniSharp.MSBuild/ProjectSystem.cs | 1 - .../MiscellanousFiles.cs | 10 ++++---- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs index 37b82804c9..e006a44538 100644 --- a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs +++ b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs @@ -10,14 +10,10 @@ namespace OmniSharp.Mef public class ExportIProjectSystemAttribute: ExportAttribute { public string Name { get; } - public string Before { get; } - public string After { get; } - - public ExportIProjectSystemAttribute(string name, string before="", string after="") : base(typeof(IProjectSystem)) + + public ExportIProjectSystemAttribute(string name) : base(typeof(IProjectSystem)) { Name = name; - Before = before; - After = after; } } } diff --git a/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs b/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs index 78cf12c760..ef2498dea3 100644 --- a/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs +++ b/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs @@ -1,26 +1,7 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OmniSharp.Mef +namespace OmniSharp.Mef { - internal interface IOrderableMetadata + public class ProjectSystemMetadata { - [DefaultValue("")] - string After { get; } - [DefaultValue("")] - string Before { get; } - string Name { get; } - } - - class OrderableMetadata - { - public string After { get; set; } - - public string Before { get; set; } public string Name { get; set; } } } diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 822fdffdc3..4b444a5e52 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -30,7 +30,7 @@ public static void Initialize( var projectEventForwarder = compositionHost.GetExport(); projectEventForwarder.Initialize(); - var projectSystems = compositionHost.GetExports>(); + var projectSystems = compositionHost.GetExports>(); var ps = projectSystems.Select(n => n.Value); var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 79121ba753..14bad34d92 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -21,7 +21,6 @@ namespace OmniSharp.MSBuild { - [Export(typeof(ProjectSystem))] [ExportIProjectSystem(nameof(ProjectSystem)), Shared] public class ProjectSystem : IProjectSystem { diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index a805bb549e..f4cd9cc305 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Composition; using System.IO; +using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; @@ -17,8 +18,8 @@ namespace OmniSharp.MiscellanousFiles { - //[ExtensionOrder(After = nameof(ProjectSystem))] - [ExportIProjectSystem("MiscellanousFiles", after: nameof(ProjectSystem)), Shared] + [ExtensionOrder(After = nameof(ProjectSystem))] + [ExportIProjectSystem("MiscellanousFiles"), Shared] public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; @@ -35,13 +36,14 @@ public class MiscellanousFiles : IProjectSystem private readonly ILogger _logger; [ImportingConstructor] - public MiscellanousFiles(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [Import] ProjectSystem projectSystem) + public MiscellanousFiles(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, + ILoggerFactory loggerFactory, [ImportMany] IEnumerable> projectSystems) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; _logger = loggerFactory.CreateLogger(); - _projectSystem = projectSystem; + _projectSystem = (ProjectSystem)projectSystems.Where(ps => ps.Metadata.Name == nameof(ProjectSystem)).First().Value; } Task IProjectSystem.GetProjectModelAsync(string filePath) From 36af94ba488188027fda2704621b412599411746 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 30 Jul 2018 13:57:00 -0700 Subject: [PATCH 24/54] Clean the solution --- OmniSharp.sln | 15 --------------- ...erableMetadata.cs => ProjectSystemMetadata.cs} | 0 .../OmniSharp.MiscellanousFiles.csproj | 4 ++-- 3 files changed, 2 insertions(+), 17 deletions(-) rename src/OmniSharp.Abstractions/Mef/{IOrderableMetadata.cs => ProjectSystemMetadata.cs} (100%) diff --git a/OmniSharp.sln b/OmniSharp.sln index 28fa2c78ec..dc576175c5 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -25,8 +25,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Stdio.Tests", "te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Abstractions", "src\OmniSharp.Abstractions\OmniSharp.Abstractions.csproj", "{0C54BE83-EF9E-4419-B654-A0760745BF80}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Nuget", "src\OmniSharp.Nuget\OmniSharp.Nuget.csproj", "{AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Plugins", "src\OmniSharp.Plugins\OmniSharp.Plugins.csproj", "{1C9AE254-6076-4EE6-80FD-B0AE4E16347D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Roslyn.CSharp", "src\OmniSharp.Roslyn.CSharp\OmniSharp.Roslyn.CSharp.csproj", "{ED1A82CB-2741-45F5-A28B-7C36EFDF9746}" @@ -133,18 +131,6 @@ Global {0C54BE83-EF9E-4419-B654-A0760745BF80}.Release|x64.Build.0 = Release|Any CPU {0C54BE83-EF9E-4419-B654-A0760745BF80}.Release|x86.ActiveCfg = Release|Any CPU {0C54BE83-EF9E-4419-B654-A0760745BF80}.Release|x86.Build.0 = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|x64.ActiveCfg = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|x64.Build.0 = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|x86.ActiveCfg = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Debug|x86.Build.0 = Debug|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|Any CPU.Build.0 = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|x64.ActiveCfg = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|x64.Build.0 = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|x86.ActiveCfg = Release|Any CPU - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981}.Release|x86.Build.0 = Release|Any CPU {1C9AE254-6076-4EE6-80FD-B0AE4E16347D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1C9AE254-6076-4EE6-80FD-B0AE4E16347D}.Debug|Any CPU.Build.0 = Debug|Any CPU {1C9AE254-6076-4EE6-80FD-B0AE4E16347D}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -442,7 +428,6 @@ Global {A4F5FE6B-D3B4-4B63-A949-44E12AB8D535} = {2C348365-A9D8-459E-9276-56FC46AAEE31} {AB5A975C-378B-45DC-AD69-50D808338AC2} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47} {0C54BE83-EF9E-4419-B654-A0760745BF80} = {2C348365-A9D8-459E-9276-56FC46AAEE31} - {AF01C2BD-58CD-4E19-869F-5B9B8E9BA981} = {2C348365-A9D8-459E-9276-56FC46AAEE31} {1C9AE254-6076-4EE6-80FD-B0AE4E16347D} = {2C348365-A9D8-459E-9276-56FC46AAEE31} {ED1A82CB-2741-45F5-A28B-7C36EFDF9746} = {2C348365-A9D8-459E-9276-56FC46AAEE31} {4F5FC4AF-3977-4ECB-9B58-D16E8024BC97} = {2C348365-A9D8-459E-9276-56FC46AAEE31} diff --git a/src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs b/src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs similarity index 100% rename from src/OmniSharp.Abstractions/Mef/IOrderableMetadata.cs rename to src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs diff --git a/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj b/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj index 0e4a077c72..0e3e2c596e 100644 --- a/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj +++ b/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj @@ -1,7 +1,7 @@ - + - net46 + net461 AnyCPU From 11251b006e397b1e7dabbc447caccb465017b5e6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 30 Jul 2018 14:10:26 -0700 Subject: [PATCH 25/54] Change the target framework --- .../OmniSharp.MiscellanousFiles.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj b/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj index cd8b8326ee..7837179d01 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj +++ b/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj @@ -1,7 +1,7 @@  - net46 + net461 AnyCPU true From dd73d39631d118010ea073878b54755555e5f4ea Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 30 Jul 2018 15:19:27 -0700 Subject: [PATCH 26/54] Add references --- src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj index bdbde24a85..5f79698bd9 100644 --- a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj +++ b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj @@ -7,6 +7,7 @@ + From 2b599a6b3c7b5f2f620a4c041d51117dabc03e6f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 31 Jul 2018 14:21:38 -0700 Subject: [PATCH 27/54] Rename project system --- .../Mef/ExportIProjectSystemAttribute.cs | 4 ++-- src/OmniSharp.Cake/CakeProjectSystem.cs | 2 +- src/OmniSharp.DotNet/DotNetProjectSystem.cs | 2 +- src/OmniSharp.Host/WorkspaceInitializer.cs | 2 +- src/OmniSharp.MSBuild/ProjectSystem.cs | 2 +- src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs | 2 +- src/OmniSharp.Script/ScriptProjectSystem.cs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs index e006a44538..1d119b7ce8 100644 --- a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs +++ b/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs @@ -7,11 +7,11 @@ namespace OmniSharp.Mef { [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class ExportIProjectSystemAttribute: ExportAttribute + public class ExportProjectSystemAttribute: ExportAttribute { public string Name { get; } - public ExportIProjectSystemAttribute(string name) : base(typeof(IProjectSystem)) + public ExportProjectSystemAttribute(string name) : base(typeof(IProjectSystem)) { Name = name; } diff --git a/src/OmniSharp.Cake/CakeProjectSystem.cs b/src/OmniSharp.Cake/CakeProjectSystem.cs index fd140d66f5..4edf81de18 100644 --- a/src/OmniSharp.Cake/CakeProjectSystem.cs +++ b/src/OmniSharp.Cake/CakeProjectSystem.cs @@ -23,7 +23,7 @@ namespace OmniSharp.Cake { - [ExportIProjectSystem(nameof(CakeProjectSystem)), Shared] + [ExportProjectSystem(nameof(CakeProjectSystem)), Shared] public class CakeProjectSystem : IProjectSystem { private readonly OmniSharpWorkspace _workspace; diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index 7143c0010f..b7805716e2 100644 --- a/src/OmniSharp.DotNet/DotNetProjectSystem.cs +++ b/src/OmniSharp.DotNet/DotNetProjectSystem.cs @@ -24,7 +24,7 @@ namespace OmniSharp.DotNet { - [ExportIProjectSystem(nameof(DotNetProjectSystem)), Shared] + [ExportProjectSystem(nameof(DotNetProjectSystem)), Shared] public class DotNetProjectSystem : IProjectSystem { private const string CompilationConfiguration = "Debug"; diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 4b444a5e52..8becf2515d 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -32,7 +32,7 @@ public static void Initialize( projectEventForwarder.Initialize(); var projectSystems = compositionHost.GetExports>(); var ps = projectSystems.Select(n => n.Value); - var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); + var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList(ps, eps => eps.Name); foreach (var projectSystem in orderedProjectSystems) { diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 14bad34d92..bae590a152 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -21,7 +21,7 @@ namespace OmniSharp.MSBuild { - [ExportIProjectSystem(nameof(ProjectSystem)), Shared] + [ExportProjectSystem(nameof(ProjectSystem)), Shared] public class ProjectSystem : IProjectSystem { private readonly IOmniSharpEnvironment _environment; diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index f4cd9cc305..6481194e78 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -19,7 +19,7 @@ namespace OmniSharp.MiscellanousFiles { [ExtensionOrder(After = nameof(ProjectSystem))] - [ExportIProjectSystem("MiscellanousFiles"), Shared] + [ExportProjectSystem("MiscellanousFiles"), Shared] public class MiscellanousFiles : IProjectSystem { private readonly string miscFileExtension = ".cs"; diff --git a/src/OmniSharp.Script/ScriptProjectSystem.cs b/src/OmniSharp.Script/ScriptProjectSystem.cs index 0efa60ad06..b4c0417d2e 100644 --- a/src/OmniSharp.Script/ScriptProjectSystem.cs +++ b/src/OmniSharp.Script/ScriptProjectSystem.cs @@ -18,7 +18,7 @@ namespace OmniSharp.Script { - [ExportIProjectSystem(nameof(ScriptProjectSystem)), Shared] + [ExportProjectSystem(nameof(ScriptProjectSystem)), Shared] public class ScriptProjectSystem : IProjectSystem { private const string CsxExtension = ".csx"; From 42c9049af5a309869fcfce9fbe0656377831d0f7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 31 Jul 2018 16:37:28 -0700 Subject: [PATCH 28/54] Add few tests --- .../DiagnosticsFacts.cs | 92 ----- .../EndpointFacts.cs | 319 ++++++++++++++++++ 2 files changed, 319 insertions(+), 92 deletions(-) delete mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs create mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs deleted file mode 100644 index ed1f0fc00d..0000000000 --- a/tests/OmniSharp.MiscellanousFiles.Tests/DiagnosticsFacts.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using OmniSharp.Mef; -using OmniSharp.Models.CodeCheck; -using OmniSharp.Models.FilesChanged; -using OmniSharp.Models.SignatureHelp; -using OmniSharp.Roslyn.CSharp.Services.Diagnostics; -using OmniSharp.Roslyn.CSharp.Services.Files; -using OmniSharp.Roslyn.CSharp.Services.Signatures; -using TestUtility; -using Xunit; -using Xunit.Abstractions; - -namespace OmniSharp.MiscellanousFiles.Tests -{ - public class DiagnosticsFacts : AbstractTestFixture - { - public DiagnosticsFacts(ITestOutputHelper output) - : base(output) - { - } - - [Fact] - public async Task Returns_only_syntactic_diagnotics() - { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) - { - var testFile = new TestFile("a.cs", "class C { b a = new b(); int n }"); - using (var host = await AddMiscellanousFile(testProject, testFile)) - { - var codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); - var quickFixes = await codeCheckService.Handle(new CodeCheckRequest()); - Assert.Single(quickFixes.QuickFixes); - Assert.Equal("; expected", quickFixes.QuickFixes.First().Text); - } - } - } - - [Fact] - public async Task Returns_signature_help() - { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) - { - const string source = -@"class Program -{ - public static void Main(){ - System.Guid.NewGuid($$); - } -}"; - var testFile = new TestFile("a.cs", source); - using (var host = await AddMiscellanousFile(testProject, testFile)) - { - var service = host.GetRequestHandler(OmniSharpEndpoints.SignatureHelp); - var point = testFile.Content.GetPointFromPosition(); - var request = new SignatureHelpRequest() - { - FileName = testFile.FileName, - Line = point.Line, - Column = point.Offset, - Buffer = testFile.Content.Code - }; - - var actual = await service.Handle(request); - Assert.Single(actual.Signatures); - Assert.Equal(0, actual.ActiveParameter); - Assert.Equal(0, actual.ActiveSignature); - Assert.Equal("NewGuid", actual.Signatures.ElementAt(0).Name); - Assert.Empty(actual.Signatures.ElementAt(0).Parameters); - } - } - } - - private async Task AddMiscellanousFile(ITestProject testProject, TestFile testfile) - { - var host = CreateOmniSharpHost(testProject.Directory); - var filePath = testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); - var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); - await fileChangedService.Handle(new[] - { - new FilesChangedRequest - { - FileName = filePath, - ChangeType = FileWatching.FileChangeType.Create - } - }); - - await Task.Delay(2000); - return host; - } - } -} diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs new file mode 100644 index 0000000000..147f193f90 --- /dev/null +++ b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs @@ -0,0 +1,319 @@ +using System.Linq; +using System.Threading.Tasks; +using OmniSharp.Models.CodeCheck; +using OmniSharp.Models.FilesChanged; +using OmniSharp.Models.FindImplementations; +using OmniSharp.Models.FindUsages; +using OmniSharp.Models.FixUsings; +using OmniSharp.Models.SignatureHelp; +using OmniSharp.Models.TypeLookup; +using OmniSharp.Roslyn.CSharp.Services.Diagnostics; +using OmniSharp.Roslyn.CSharp.Services.Files; +using OmniSharp.Roslyn.CSharp.Services.Navigation; +using OmniSharp.Roslyn.CSharp.Services.Refactoring; +using OmniSharp.Roslyn.CSharp.Services.Signatures; +using OmniSharp.Roslyn.CSharp.Services.Types; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.MiscellanousFiles.Tests +{ + public class EndpointFacts : AbstractTestFixture + { + public EndpointFacts(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public async Task Returns_only_syntactic_diagnotics() + { + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + + 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 codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); + var actual = await codeCheckService.Handle(new CodeCheckRequest() { FileName = filePath }); + Assert.Single(actual.QuickFixes); + Assert.Equal("; expected", actual.QuickFixes.First().Text); + } + } + } + + [Fact] + public async Task Returns_Signature_help() + { + const string source = +@"class Program +{ + public static void Main(){ + System.Guid.NewGuid($$); + } +}"; + var testfile = new TestFile("a.cs", source); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.SignatureHelp); + var point = testfile.Content.GetPointFromPosition(); + var request = new SignatureHelpRequest() + { + FileName = filePath, + Line = point.Line, + Column = point.Offset, + Buffer = testfile.Content.Code + }; + + var actual = await service.Handle(request); + Assert.Single(actual.Signatures); + Assert.Equal(0, actual.ActiveParameter); + Assert.Equal(0, actual.ActiveSignature); + Assert.Equal("NewGuid", actual.Signatures.ElementAt(0).Name); + Assert.Empty(actual.Signatures.ElementAt(0).Parameters); + } + } + } + + [Fact] + public async Task Returns_Implementations() + { + const string source = @" + public class MyClass + { + public MyClass() { Fo$$o(); } + + public void Foo() {} + }"; + + var testfile = new TestFile("a.cs", source); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.FindImplementations); + var point = testfile.Content.GetPointFromPosition(); + var request = new FindImplementationsRequest() + { + FileName = filePath, + Line = point.Line, + Column = point.Offset, + Buffer = testfile.Content.Code + }; + + var actual = await service.Handle(request); + Assert.Single(actual.QuickFixes); + Assert.Equal("public void Foo() {}", actual.QuickFixes.First().Text.Trim()); + } + } + } + + [Fact] + public async Task Returns_Usages() + { + const string source = @" + public class F$$oo + { + public string prop { get; set; } + } + + public class FooConsumer + { + public FooConsumer() + { + var temp = new Foo(); + var prop = foo.prop; + } + }"; + + var testfile = new TestFile("a.cs", source); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.FindUsages); + var point = testfile.Content.GetPointFromPosition(); + var request = new FindUsagesRequest() + { + FileName = filePath, + Line = point.Line, + Column = point.Offset, + Buffer = testfile.Content.Code + }; + + var actual = await service.Handle(request); + Assert.Equal(2, actual.QuickFixes.Count()); + } + } + } + + [Fact] + public async Task Returns_Symbols() + { + const string source = @" + namespace Some.Long.Namespace + { + public class Foo + { + private string _field = 0; + private string AutoProperty { get; } + private string Property + { + get { return _field; } + set { _field = value; } + } + private string Method() {} + private string Method(string param) {} + + private class Nested + { + private string NestedMethod() {} + } + } + }"; + + var testfile = new TestFile("a.cs", source); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.FindSymbols); + var actual = await service.Handle(null); + var symbols = actual.QuickFixes.Select(q => q.Text); + + var expected = new[] + { + "Foo", + "_field", + "AutoProperty", + "Property", + "Method()", + "Method(string param)", + "Nested", + "NestedMethod()" + }; + + Assert.Equal(expected, symbols); + } + } + } + + [Fact] + public async Task Returns_FixUsings() + { + const string code = @" +namespace nsA +{ + public class classX{} +} + +namespace OmniSharp +{ + public class class1 + { + public method1() + { + var c1 = new classX(); + } + } +}"; + + const string expectedCode = @" +using nsA; + +namespace nsA +{ + public class classX{} +} + +namespace OmniSharp +{ + public class class1 + { + public method1() + { + var c1 = new classX(); + } + } +}"; + + var testfile = new TestFile("a.cs", code); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.FixUsings); + var request = new FixUsingsRequest + { + FileName = filePath + }; + + var actual = await service.Handle(request); + Assert.Equal(expectedCode.Replace("\r\n", "\n"), actual.Buffer.Replace("\r\n", "\n")); + } + } + } + + [Fact] + public async Task Returns_TypeLookup() + { + const string code = @"class F$$oo {}"; + var testfile = new TestFile("a.cs", code); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + { + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filePath = AddTestFile(testProject, testfile); + await WaitForFileUpdate(filePath, host); + var service = host.GetRequestHandler(OmniSharpEndpoints.TypeLookup); + var point = testfile.Content.GetPointFromPosition(); + var request = new TypeLookupRequest + { + FileName = filePath, + Line = point.Line, + Column = point.Offset, + }; + + var actual = await service.Handle(request); + Assert.Equal("Foo", actual.Type); + } + } + } + + + private string AddTestFile(ITestProject testProject, TestFile testfile) + { + return testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); + } + + private async Task WaitForFileUpdate(string filePath, OmniSharpTestHost host) + { + var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); + await fileChangedService.Handle(new[] + { + new FilesChangedRequest + { + FileName = filePath, + ChangeType = FileWatching.FileChangeType.Create + } + }); + + await Task.Delay(2000); + } + } +} From d0574cbee250b26620a20be1ee2b3b5ccb102bd7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 16:10:41 -0700 Subject: [PATCH 29/54] Refactor the tests to add a method to the test host --- .../MiscellanousFiles.cs | 1 - .../EndpointFacts.cs | 28 +++++++------------ tests/TestUtility/OmniSharpTestHost.cs | 8 ++++++ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 6481194e78..687df911d9 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.ComponentModel; using System.Composition; using System.IO; using System.Linq; diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs index 147f193f90..42665ff275 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs @@ -37,8 +37,8 @@ public async Task Returns_only_syntactic_diagnotics() { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var codeCheckService = host.GetRequestHandler(OmniSharpEndpoints.CodeCheck); - var actual = await codeCheckService.Handle(new CodeCheckRequest() { FileName = filePath }); + var request = new CodeCheckRequest() { FileName = filePath }; + var actual = await host.GetResponse(OmniSharpEndpoints.CodeCheck, request); Assert.Single(actual.QuickFixes); Assert.Equal("; expected", actual.QuickFixes.First().Text); } @@ -62,7 +62,6 @@ public static void Main(){ { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var service = host.GetRequestHandler(OmniSharpEndpoints.SignatureHelp); var point = testfile.Content.GetPointFromPosition(); var request = new SignatureHelpRequest() { @@ -72,7 +71,7 @@ public static void Main(){ Buffer = testfile.Content.Code }; - var actual = await service.Handle(request); + var actual = await host.GetResponse(OmniSharpEndpoints.SignatureHelp, request); Assert.Single(actual.Signatures); Assert.Equal(0, actual.ActiveParameter); Assert.Equal(0, actual.ActiveSignature); @@ -100,7 +99,6 @@ public void Foo() {} { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var service = host.GetRequestHandler(OmniSharpEndpoints.FindImplementations); var point = testfile.Content.GetPointFromPosition(); var request = new FindImplementationsRequest() { @@ -110,7 +108,7 @@ public void Foo() {} Buffer = testfile.Content.Code }; - var actual = await service.Handle(request); + var actual = await host.GetResponse(OmniSharpEndpoints.FindImplementations, request); Assert.Single(actual.QuickFixes); Assert.Equal("public void Foo() {}", actual.QuickFixes.First().Text.Trim()); } @@ -142,7 +140,7 @@ public FooConsumer() { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var service = host.GetRequestHandler(OmniSharpEndpoints.FindUsages); + var point = testfile.Content.GetPointFromPosition(); var request = new FindUsagesRequest() { @@ -152,7 +150,7 @@ public FooConsumer() Buffer = testfile.Content.Code }; - var actual = await service.Handle(request); + var actual = await host.GetResponse(OmniSharpEndpoints.FindUsages, request); Assert.Equal(2, actual.QuickFixes.Count()); } } @@ -190,8 +188,7 @@ private string NestedMethod() {} { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var service = host.GetRequestHandler(OmniSharpEndpoints.FindSymbols); - var actual = await service.Handle(null); + var actual = await host.GetResponse(OmniSharpEndpoints.FindSymbols, null); var symbols = actual.QuickFixes.Select(q => q.Text); var expected = new[] @@ -257,13 +254,8 @@ public method1() { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); - var service = host.GetRequestHandler(OmniSharpEndpoints.FixUsings); - var request = new FixUsingsRequest - { - FileName = filePath - }; - - var actual = await service.Handle(request); + 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")); } } @@ -289,7 +281,7 @@ public async Task Returns_TypeLookup() Column = point.Offset, }; - var actual = await service.Handle(request); + var actual = await host.GetResponse(OmniSharpEndpoints.TypeLookup, request); Assert.Equal("Foo", actual.Type); } } diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 4f6a775003..760f62296e 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -216,5 +217,12 @@ public void ClearWorkspace() Workspace.RemoveProject(projectId); } } + + public Task GetResponse( + string endpoint, TRequest request) + { + var service = GetRequestHandler>(endpoint); + return service.Handle(request); + } } } From 6d8201a3300c7a99a550140978dab1d7fdaac9e4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 16:26:05 -0700 Subject: [PATCH 30/54] Remove roslyn dependency in abstractions --- ...jectSystemAttribute.cs => ExportProjectSystemAttribute.cs} | 1 - src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj | 1 - src/OmniSharp.Host/WorkspaceInitializer.cs | 3 --- .../Utilities/ExtensionOrderer.Graph.cs | 0 .../Utilities/ExtensionOrderer.Node.cs | 0 .../Utilities/ExtensionOrderer.cs | 4 +--- tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs | 3 +++ 7 files changed, 4 insertions(+), 8 deletions(-) rename src/OmniSharp.Abstractions/Mef/{ExportIProjectSystemAttribute.cs => ExportProjectSystemAttribute.cs} (93%) rename src/{OmniSharp.Abstractions => OmniSharp.Roslyn}/Utilities/ExtensionOrderer.Graph.cs (100%) rename src/{OmniSharp.Abstractions => OmniSharp.Roslyn}/Utilities/ExtensionOrderer.Node.cs (100%) rename src/{OmniSharp.Abstractions => OmniSharp.Roslyn}/Utilities/ExtensionOrderer.cs (88%) diff --git a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs b/src/OmniSharp.Abstractions/Mef/ExportProjectSystemAttribute.cs similarity index 93% rename from src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs rename to src/OmniSharp.Abstractions/Mef/ExportProjectSystemAttribute.cs index 1d119b7ce8..b1736d0d1f 100644 --- a/src/OmniSharp.Abstractions/Mef/ExportIProjectSystemAttribute.cs +++ b/src/OmniSharp.Abstractions/Mef/ExportProjectSystemAttribute.cs @@ -1,6 +1,5 @@ using System; using System.Composition; -using Microsoft.CodeAnalysis; using OmniSharp.Services; namespace OmniSharp.Mef diff --git a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj index 5f79698bd9..bdbde24a85 100644 --- a/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj +++ b/src/OmniSharp.Abstractions/OmniSharp.Abstractions.csproj @@ -7,7 +7,6 @@ - diff --git a/src/OmniSharp.Host/WorkspaceInitializer.cs b/src/OmniSharp.Host/WorkspaceInitializer.cs index 8becf2515d..2e4b82f130 100644 --- a/src/OmniSharp.Host/WorkspaceInitializer.cs +++ b/src/OmniSharp.Host/WorkspaceInitializer.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Composition; using System.Composition.Hosting; using System.Linq; using Microsoft.Extensions.Configuration; diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs b/src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.Graph.cs similarity index 100% rename from src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Graph.cs rename to src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.Graph.cs diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs b/src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.Node.cs similarity index 100% rename from src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.Node.cs rename to src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.Node.cs diff --git a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs b/src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.cs similarity index 88% rename from src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs rename to src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.cs index 93ab08cf10..dfc39e9f09 100644 --- a/src/OmniSharp.Abstractions/Utilities/ExtensionOrderer.cs +++ b/src/OmniSharp.Roslyn/Utilities/ExtensionOrderer.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace OmniSharp.Utilities { - static partial class ExtensionOrderer + public static partial class ExtensionOrderer { /* Returns a sorted order of the nodes if such a sorting exists, else returns the unsorted list */ public static IEnumerable GetOrderedOrUnorderedList(IEnumerable unsortedList, Func nameExtractor) where TAttribute: Attribute diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs index 42665ff275..2395c3bfa2 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs @@ -1,8 +1,11 @@ using System.Linq; using System.Threading.Tasks; +using OmniSharp.Mef; +using OmniSharp.Models; using OmniSharp.Models.CodeCheck; using OmniSharp.Models.FilesChanged; using OmniSharp.Models.FindImplementations; +using OmniSharp.Models.FindSymbols; using OmniSharp.Models.FindUsages; using OmniSharp.Models.FixUsings; using OmniSharp.Models.SignatureHelp; From 7a419ed02d09f899904cc6d3b235c1c8d5db016e Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 17:04:44 -0700 Subject: [PATCH 31/54] use only one project for all the miscellanous files --- .../MiscellanousFiles.cs | 29 +++++++++++-------- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 11 ++++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 687df911d9..8760277ba3 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -27,12 +27,13 @@ public class MiscellanousFiles : IProjectSystem IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; - private readonly ConcurrentDictionary _projects = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _documents = new ConcurrentDictionary(); private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; private readonly ProjectSystem _projectSystem; private readonly ILogger _logger; + private ProjectId _projectId; [ImportingConstructor] public MiscellanousFiles(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, @@ -70,19 +71,23 @@ private async void AddIfMiscellanousFile(string filePath) await _projectSystem.HasCompletedUpdateRequest(); if (_workspace.GetDocument(filePath) == null) { - string assemblyName = Guid.NewGuid().ToString("N"); - var projectInfo = ProjectInfo.Create( - filePath: filePath, + if (this._projectId == null) + { + string assemblyName = Guid.NewGuid().ToString("N"); + //If not project exists for the Misc files, create one + var projectInfo = ProjectInfo.Create( id: ProjectId.CreateNewId(), version: VersionStamp.Create(), - name: Path.GetFileName(filePath), + name: "MiscellanousFiles", metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, assemblyName: assemblyName, language: Language); - _workspace.AddProject(projectInfo); - _workspace.AddMiscellanousFileDocument(projectInfo.Id, filePath); - _projects[filePath] = projectInfo; + _workspace.AddProject(projectInfo); + _projectId = projectInfo.Id; + } + + _documents[filePath] = _workspace.AddMiscellanousFileDocument(_projectId, filePath); _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); } } @@ -95,18 +100,18 @@ private void OnMiscellanousFileChanged(string filePath, FileChangeType changeTyp AddIfMiscellanousFile(filePath); } - else if(changeType == FileChangeType.Unspecified && !File.Exists(filePath) || + else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || changeType == FileChangeType.Delete) { - RemoveFromWorkspace(filePath); + RemoveFromWorkspace(filePath); } } private void RemoveFromWorkspace(string filePath) { - if (_projects.TryRemove(filePath, out var project)) + if (_documents.TryRemove(filePath, out var documentId)) { - _workspace.RemoveMiscellanousFileDocument(project.Id); + _workspace.RemoveMiscellanousFileDocument(documentId); _logger.LogDebug($"Removed file '{filePath}' from the workspace."); } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index c09184dada..a809ec11c7 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -86,18 +86,17 @@ public void AddDocument(DocumentInfo documentInfo) OnDocumentAdded(documentInfo); } - public void AddMiscellanousFileDocument(ProjectId projectId, string filePath) + public DocumentId AddMiscellanousFileDocument(ProjectId projectId, string filePath) { var documentId = AddDocument(projectId, filePath); _miscellanousFiles.Add(documentId); + return documentId; } - public void RemoveMiscellanousFileDocument(ProjectId projectId) + public void RemoveMiscellanousFileDocument(DocumentId documentId) { - var project = CurrentSolution.GetProject(projectId); - var id = project.DocumentIds.First(); - _miscellanousFiles.Remove(id); - RemoveProject(projectId); + _miscellanousFiles.Remove(documentId); + RemoveDocument(documentId); } public DocumentId AddDocument(ProjectId projectId, string filePath, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) From def58ece8f1ebbe2f470bc409e7b1c2050ec58b9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 17:19:44 -0700 Subject: [PATCH 32/54] Add project system names class --- src/OmniSharp.Abstractions/ProjectSystemNames.cs | 11 +++++++++++ src/OmniSharp.Cake/CakeProjectSystem.cs | 2 +- src/OmniSharp.DotNet/DotNetProjectSystem.cs | 2 +- src/OmniSharp.MSBuild/ProjectSystem.cs | 2 +- src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs | 12 ++++++------ src/OmniSharp.Script/ScriptProjectSystem.cs | 2 +- tests/TestUtility/OmniSharpTestHost.cs | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/OmniSharp.Abstractions/ProjectSystemNames.cs diff --git a/src/OmniSharp.Abstractions/ProjectSystemNames.cs b/src/OmniSharp.Abstractions/ProjectSystemNames.cs new file mode 100644 index 0000000000..bd56022121 --- /dev/null +++ b/src/OmniSharp.Abstractions/ProjectSystemNames.cs @@ -0,0 +1,11 @@ +namespace OmniSharp +{ + public static class ProjectSystemNames + { + public const string MSBuildProjectSystem = "MSBuildProjectSystem"; + public const string CakeProjectSystem = "CakeProjectSystem"; + public const string DotNetProjectSystem = "DotNetProjectSystem"; + public const string ScriptProjectSystem = "ScriptProjectSystem"; + public const string MiscellanousFilesProjectSystem = "MiscellanousFilesProjectSystem"; + } +} diff --git a/src/OmniSharp.Cake/CakeProjectSystem.cs b/src/OmniSharp.Cake/CakeProjectSystem.cs index 4edf81de18..63d1b60860 100644 --- a/src/OmniSharp.Cake/CakeProjectSystem.cs +++ b/src/OmniSharp.Cake/CakeProjectSystem.cs @@ -23,7 +23,7 @@ namespace OmniSharp.Cake { - [ExportProjectSystem(nameof(CakeProjectSystem)), Shared] + [ExportProjectSystem(ProjectSystemNames.CakeProjectSystem), Shared] public class CakeProjectSystem : IProjectSystem { private readonly OmniSharpWorkspace _workspace; diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index b7805716e2..796deda7dc 100644 --- a/src/OmniSharp.DotNet/DotNetProjectSystem.cs +++ b/src/OmniSharp.DotNet/DotNetProjectSystem.cs @@ -24,7 +24,7 @@ namespace OmniSharp.DotNet { - [ExportProjectSystem(nameof(DotNetProjectSystem)), Shared] + [ExportProjectSystem(ProjectSystemNames.DotNetProjectSystem), Shared] public class DotNetProjectSystem : IProjectSystem { private const string CompilationConfiguration = "Debug"; diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index bae590a152..6c962ac147 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -21,7 +21,7 @@ namespace OmniSharp.MSBuild { - [ExportProjectSystem(nameof(ProjectSystem)), Shared] + [ExportProjectSystem(ProjectSystemNames.MSBuildProjectSystem), Shared] public class ProjectSystem : IProjectSystem { private readonly IOmniSharpEnvironment _environment; diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 8760277ba3..cc5fdc7949 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -17,9 +17,9 @@ namespace OmniSharp.MiscellanousFiles { - [ExtensionOrder(After = nameof(ProjectSystem))] - [ExportProjectSystem("MiscellanousFiles"), Shared] - public class MiscellanousFiles : IProjectSystem + [ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)] + [ExportProjectSystem(ProjectSystemNames.MiscellanousFilesProjectSystem), Shared] + public class MiscellanousFilesProjectSystem : IProjectSystem { private readonly string miscFileExtension = ".cs"; public string Key { get; } = "MiscellanousFiles"; @@ -36,14 +36,14 @@ public class MiscellanousFiles : IProjectSystem private ProjectId _projectId; [ImportingConstructor] - public MiscellanousFiles(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, + public MiscellanousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [ImportMany] IEnumerable> projectSystems) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; - _logger = loggerFactory.CreateLogger(); - _projectSystem = (ProjectSystem)projectSystems.Where(ps => ps.Metadata.Name == nameof(ProjectSystem)).First().Value; + _logger = loggerFactory.CreateLogger(); + _projectSystem = (ProjectSystem)projectSystems.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem).First().Value; } Task IProjectSystem.GetProjectModelAsync(string filePath) diff --git a/src/OmniSharp.Script/ScriptProjectSystem.cs b/src/OmniSharp.Script/ScriptProjectSystem.cs index b4c0417d2e..d4b7dd9633 100644 --- a/src/OmniSharp.Script/ScriptProjectSystem.cs +++ b/src/OmniSharp.Script/ScriptProjectSystem.cs @@ -18,7 +18,7 @@ namespace OmniSharp.Script { - [ExportProjectSystem(nameof(ScriptProjectSystem)), Shared] + [ExportProjectSystem(ProjectSystemNames.ScriptProjectSystem), Shared] public class ScriptProjectSystem : IProjectSystem { private const string CsxExtension = ".csx"; diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 760f62296e..6bd183a4eb 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -42,7 +42,7 @@ public class OmniSharpTestHost : DisposableObject typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, // OmniSharp.Roslyn typeof(RoslynFeaturesHostServicesProvider).GetTypeInfo().Assembly, // OmniSharp.Roslyn.CSharp typeof(CakeProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Cake - typeof(MiscellanousFiles).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles + typeof(MiscellanousFilesProjectSystem).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles }); private readonly TestServiceProvider _serviceProvider; From 5788c37937eafdb5c19fa928e22be0a13f65025f Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 18:14:03 -0700 Subject: [PATCH 33/54] Modifying the files changed facts to use absolute path instead of relative By adding the misc files support, the file that was being added by the test was being treated as a miscellanous file and being added to the workspace. However since the path being passed was relative, an exception was being thrown. --- .../EndpointFacts.cs | 14 +++++++------- .../FilesChangedFacts.cs | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs index 2395c3bfa2..af8bbdbbd6 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs @@ -32,7 +32,7 @@ public EndpointFacts(ITestOutputHelper output) [Fact] public async Task Returns_only_syntactic_diagnotics() { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { var testfile = new TestFile("a.cs", "class C { b a = new b(); int n }"); @@ -59,7 +59,7 @@ public static void Main(){ } }"; var testfile = new TestFile("a.cs", source); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { @@ -96,7 +96,7 @@ public void Foo() {} }"; var testfile = new TestFile("a.cs", source); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { @@ -137,7 +137,7 @@ public FooConsumer() }"; var testfile = new TestFile("a.cs", source); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { @@ -185,7 +185,7 @@ private string NestedMethod() {} }"; var testfile = new TestFile("a.cs", source); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { @@ -251,7 +251,7 @@ public method1() }"; var testfile = new TestFile("a.cs", code); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { @@ -269,7 +269,7 @@ public async Task Returns_TypeLookup() { const string code = @"class F$$oo {}"; var testfile = new TestFile("a.cs", code); - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMiscFile")) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { using (var host = CreateOmniSharpHost(testProject.Directory)) { diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs index 7e63762e79..800f7f80f4 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs @@ -37,19 +37,20 @@ public async Task TestFileAddedToMSBuildWorkspaceOnCreation() } [Fact] - public void TestMultipleDirectoryWatchers() + public async void TestMultipleDirectoryWatchers() { - using (var host = CreateEmptyOmniSharpHost()) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) + using (var host = CreateOmniSharpHost(testProject.Directory)) { var watcher = host.GetExport(); - + var filepath = testProject.AddDisposableFile("FileName.cs"); bool firstWatcherCalled = false; bool secondWatcherCalled = false; watcher.Watch("", (path, changeType) => { firstWatcherCalled = true; }); watcher.Watch("", (path, changeType) => { secondWatcherCalled = true; }); var handler = GetRequestHandler(host); - handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); + await handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); Assert.True(firstWatcherCalled); Assert.True(secondWatcherCalled); @@ -57,17 +58,17 @@ public void TestMultipleDirectoryWatchers() } [Fact] - public void TestFileExtensionWatchers() + public async void TestFileExtensionWatchers() { - using (var host = CreateEmptyOmniSharpHost()) + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) + using (var host = CreateOmniSharpHost(testProject.Directory)) { var watcher = host.GetExport(); - + var filepath = testProject.AddDisposableFile("FileName.cs"); var extensionWatcherCalled = false; watcher.Watch(".cs", (path, changeType) => { extensionWatcherCalled = true; }); - var handler = GetRequestHandler(host); - handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); + await handler.Handle(new[] { new FilesChangedRequest() { FileName = filepath, ChangeType = FileChangeType.Create } }); Assert.True(extensionWatcherCalled); } From 9a8d4471688ec0b56c03b1aaaf5e72f76b73828e Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 2 Aug 2018 12:16:19 -0700 Subject: [PATCH 34/54] Add the empty project --- test-assets/test-projects/EmptyProject/README.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test-assets/test-projects/EmptyProject/README.txt diff --git a/test-assets/test-projects/EmptyProject/README.txt b/test-assets/test-projects/EmptyProject/README.txt new file mode 100644 index 0000000000..e69de29bb2 From c7158bab98108a8ba0dae4bf63ace3b8d4ea8608 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 2 Aug 2018 13:02:47 -0700 Subject: [PATCH 35/54] Add the IUpdates interface --- src/OmniSharp.Abstractions/Services/IUpdates.cs | 9 +++++++++ src/OmniSharp.MSBuild/ProjectSystem.cs | 4 ++-- src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs | 7 +++---- .../OmniSharp.MiscellanousFiles.csproj | 6 +++++- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/OmniSharp.Abstractions/Services/IUpdates.cs diff --git a/src/OmniSharp.Abstractions/Services/IUpdates.cs b/src/OmniSharp.Abstractions/Services/IUpdates.cs new file mode 100644 index 0000000000..4320bae5b4 --- /dev/null +++ b/src/OmniSharp.Abstractions/Services/IUpdates.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace OmniSharp.Services +{ + public interface IUpdates + { + Task WaitForUpdatesAsync(); + } +} diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index 6c962ac147..c3f2243745 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 : IProjectSystem + public class ProjectSystem : IProjectSystem, IUpdates { private readonly IOmniSharpEnvironment _environment; private readonly OmniSharpWorkspace _workspace; @@ -211,7 +211,7 @@ async Task IProjectSystem.GetProjectModelAsync(string filePath) return new MSBuildProjectInfo(projectFileInfo); } - public async Task HasCompletedUpdateRequest() + public async Task WaitForUpdatesAsync() { await _manager.WaitForQueueEmptyAsync(); } diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index cc5fdc7949..07f6b4b58b 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -12,7 +12,6 @@ using OmniSharp.FileWatching; using OmniSharp.Mef; using OmniSharp.Models.WorkspaceInformation; -using OmniSharp.MSBuild; using OmniSharp.Services; namespace OmniSharp.MiscellanousFiles @@ -31,7 +30,7 @@ public class MiscellanousFilesProjectSystem : IProjectSystem private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; - private readonly ProjectSystem _projectSystem; + private readonly IUpdates _projectSystem; private readonly ILogger _logger; private ProjectId _projectId; @@ -43,7 +42,7 @@ public MiscellanousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemW _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; _logger = loggerFactory.CreateLogger(); - _projectSystem = (ProjectSystem)projectSystems.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem).First().Value; + _projectSystem = (IUpdates)projectSystems.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem).First().Value; } Task IProjectSystem.GetProjectModelAsync(string filePath) @@ -68,7 +67,7 @@ void IProjectSystem.Initalize(IConfiguration configuration) private async void AddIfMiscellanousFile(string filePath) { //wait for the project system to get initialised - await _projectSystem.HasCompletedUpdateRequest(); + await _projectSystem.WaitForUpdatesAsync(); if (_workspace.GetDocument(filePath) == null) { if (this._projectId == null) diff --git a/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj b/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj index 0e3e2c596e..89bb4ca4c4 100644 --- a/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj +++ b/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj @@ -5,9 +5,13 @@ AnyCPU + + + + - + From c243202b31f2f39fe2d4e061b483234d6acbe5a7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 7 Aug 2018 13:42:15 -0700 Subject: [PATCH 36/54] Add absolute paths for the misc file system --- .../MiscellanousFiles.cs | 9 ++++++--- .../FilesChangedFacts.cs | 19 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index 07f6b4b58b..a95b711f40 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -66,8 +66,11 @@ void IProjectSystem.Initalize(IConfiguration configuration) private async void AddIfMiscellanousFile(string filePath) { - //wait for the project system to get initialised + //wait for the project system to get initialise await _projectSystem.WaitForUpdatesAsync(); + var absoluteFilePath = new FileInfo(filePath).FullName; + if (!File.Exists(absoluteFilePath)) + return; if (_workspace.GetDocument(filePath) == null) { if (this._projectId == null) @@ -86,8 +89,8 @@ private async void AddIfMiscellanousFile(string filePath) _projectId = projectInfo.Id; } - _documents[filePath] = _workspace.AddMiscellanousFileDocument(_projectId, filePath); - _logger.LogInformation($"Successfully added file '{filePath}' to workspace"); + _documents[absoluteFilePath] = _workspace.AddMiscellanousFileDocument(_projectId, absoluteFilePath); + _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs index 800f7f80f4..7e63762e79 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs @@ -37,20 +37,19 @@ public async Task TestFileAddedToMSBuildWorkspaceOnCreation() } [Fact] - public async void TestMultipleDirectoryWatchers() + public void TestMultipleDirectoryWatchers() { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) - using (var host = CreateOmniSharpHost(testProject.Directory)) + using (var host = CreateEmptyOmniSharpHost()) { var watcher = host.GetExport(); - var filepath = testProject.AddDisposableFile("FileName.cs"); + bool firstWatcherCalled = false; bool secondWatcherCalled = false; watcher.Watch("", (path, changeType) => { firstWatcherCalled = true; }); watcher.Watch("", (path, changeType) => { secondWatcherCalled = true; }); var handler = GetRequestHandler(host); - await handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); + handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); Assert.True(firstWatcherCalled); Assert.True(secondWatcherCalled); @@ -58,17 +57,17 @@ public async void TestMultipleDirectoryWatchers() } [Fact] - public async void TestFileExtensionWatchers() + public void TestFileExtensionWatchers() { - using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) - using (var host = CreateOmniSharpHost(testProject.Directory)) + using (var host = CreateEmptyOmniSharpHost()) { var watcher = host.GetExport(); - var filepath = testProject.AddDisposableFile("FileName.cs"); + var extensionWatcherCalled = false; watcher.Watch(".cs", (path, changeType) => { extensionWatcherCalled = true; }); + var handler = GetRequestHandler(host); - await handler.Handle(new[] { new FilesChangedRequest() { FileName = filepath, ChangeType = FileChangeType.Create } }); + handler.Handle(new[] { new FilesChangedRequest() { FileName = "FileName.cs", ChangeType = FileChangeType.Create } }); Assert.True(extensionWatcherCalled); } From 98e4de31463902bc5606f38b31419297d6130b16 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 8 Aug 2018 14:55:26 -0700 Subject: [PATCH 37/54] Add dotnet project system for the updates --- src/OmniSharp.DotNet/DotNetProjectSystem.cs | 7 ++++++- .../MiscellanousFiles.cs | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index 796deda7dc..fe9cad882c 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 : IProjectSystem + public class DotNetProjectSystem : IProjectSystem, IUpdates { private const string CompilationConfiguration = "Debug"; @@ -424,5 +424,10 @@ private static LanguageVersion ParseLanguageVersion(string value) return languageVersion; } + + async Task IUpdates.WaitForUpdatesAsync() + { + await ((IProjectSystem)this).GetWorkspaceModelAsync(new WorkspaceInformationRequest()); + } } } diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs index a95b711f40..d22040ec60 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs @@ -17,6 +17,7 @@ namespace OmniSharp.MiscellanousFiles { [ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)] + [ExtensionOrder(After = ProjectSystemNames.DotNetProjectSystem)] [ExportProjectSystem(ProjectSystemNames.MiscellanousFilesProjectSystem), Shared] public class MiscellanousFilesProjectSystem : IProjectSystem { @@ -30,7 +31,7 @@ public class MiscellanousFilesProjectSystem : IProjectSystem private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; - private readonly IUpdates _projectSystem; + private readonly List _projectSystems; private readonly ILogger _logger; private ProjectId _projectId; @@ -42,7 +43,13 @@ public MiscellanousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemW _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; _logger = loggerFactory.CreateLogger(); - _projectSystem = (IUpdates)projectSystems.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem).First().Value; + _projectSystems = projectSystems. + Where + (ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || + ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem). + Select(ps => ps.Value). + Select(ps => ps as IUpdates) + .ToList(); } Task IProjectSystem.GetProjectModelAsync(string filePath) @@ -66,8 +73,12 @@ void IProjectSystem.Initalize(IConfiguration configuration) private async void AddIfMiscellanousFile(string filePath) { - //wait for the project system to get initialise - await _projectSystem.WaitForUpdatesAsync(); + //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; From 6228db312390acad084c8484c5d529dd2e7d3d92 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 8 Aug 2018 16:51:39 -0700 Subject: [PATCH 38/54] CR feedback --- OmniSharp.sln | 56 +++++++-------- .../ProjectSystemNames.cs | 2 +- .../Services/IUpdates.cs | 2 +- src/OmniSharp.DotNet/DotNetProjectSystem.cs | 4 +- src/OmniSharp.MSBuild/ProjectSystem.cs | 2 +- .../MiscellaneousFileProjectSystem.cs} | 70 ++++++++++--------- .../OmniSharp.MiscellaneousFile.csproj} | 0 src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 4 +- src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 2 +- .../EndpointFacts.cs | 7 +- .../OmniSharp.MiscellaneousFile.Tests.csproj} | 0 .../AssemblyInfo.cs | 1 - tests/TestUtility/OmniSharpTestHost.cs | 4 +- tests/TestUtility/TestUtility.csproj | 2 +- 14 files changed, 77 insertions(+), 79 deletions(-) rename src/{OmniSharp.MiscellanousFiles/MiscellanousFiles.cs => OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs} (64%) rename src/{OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj => OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj} (100%) rename tests/{OmniSharp.MiscellanousFiles.Tests => OmniSharp.MiscellaneousFile.Tests}/EndpointFacts.cs (97%) rename tests/{OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj => OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj} (100%) delete mode 100644 tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs diff --git a/OmniSharp.sln b/OmniSharp.sln index dc576175c5..4cb04fe997 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -69,9 +69,9 @@ 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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.MiscellanousFiles", "src\OmniSharp.MiscellanousFiles\OmniSharp.MiscellanousFiles.csproj", "{2BF50528-38C4-4928-9FB2-7539A3C20DA8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.MiscellaneousFile", "src\OmniSharp.MiscellaneousFile\OmniSharp.MiscellaneousFile.csproj", "{23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.MiscellanousFiles.Tests", "tests\OmniSharp.MiscellanousFiles.Tests\OmniSharp.MiscellanousFiles.Tests.csproj", "{CFDBAAF4-C579-4514-9A25-EA132CD47C65}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.MiscellaneousFile.Tests", "tests\OmniSharp.MiscellaneousFile.Tests\OmniSharp.MiscellaneousFile.Tests.csproj", "{B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -395,30 +395,30 @@ 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 - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x64.ActiveCfg = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x64.Build.0 = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x86.ActiveCfg = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Debug|x86.Build.0 = Debug|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|Any CPU.Build.0 = Release|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x64.ActiveCfg = Release|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x64.Build.0 = Release|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.ActiveCfg = Release|Any CPU - {2BF50528-38C4-4928-9FB2-7539A3C20DA8}.Release|x86.Build.0 = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x64.ActiveCfg = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x64.Build.0 = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x86.ActiveCfg = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Debug|x86.Build.0 = Debug|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|Any CPU.Build.0 = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x64.ActiveCfg = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x64.Build.0 = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x86.ActiveCfg = Release|Any CPU - {CFDBAAF4-C579-4514-9A25-EA132CD47C65}.Release|x86.Build.0 = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x64.ActiveCfg = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x64.Build.0 = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x86.ActiveCfg = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x86.Build.0 = Debug|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|Any CPU.Build.0 = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x64.ActiveCfg = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x64.Build.0 = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x86.ActiveCfg = Release|Any CPU + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x86.Build.0 = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x64.ActiveCfg = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x64.Build.0 = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x86.ActiveCfg = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x86.Build.0 = Debug|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|Any CPU.Build.0 = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x64.ActiveCfg = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x64.Build.0 = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x86.ActiveCfg = Release|Any CPU + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -450,8 +450,8 @@ 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} - {2BF50528-38C4-4928-9FB2-7539A3C20DA8} = {2C348365-A9D8-459E-9276-56FC46AAEE31} - {CFDBAAF4-C579-4514-9A25-EA132CD47C65} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47} + {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA} = {2C348365-A9D8-459E-9276-56FC46AAEE31} + {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E} diff --git a/src/OmniSharp.Abstractions/ProjectSystemNames.cs b/src/OmniSharp.Abstractions/ProjectSystemNames.cs index bd56022121..ef468dc4d2 100644 --- a/src/OmniSharp.Abstractions/ProjectSystemNames.cs +++ b/src/OmniSharp.Abstractions/ProjectSystemNames.cs @@ -6,6 +6,6 @@ public static class ProjectSystemNames public const string CakeProjectSystem = "CakeProjectSystem"; public const string DotNetProjectSystem = "DotNetProjectSystem"; public const string ScriptProjectSystem = "ScriptProjectSystem"; - public const string MiscellanousFilesProjectSystem = "MiscellanousFilesProjectSystem"; + public const string MiscellaneousFilesProjectSystem = "MiscellaneousFilesProjectSystem"; } } diff --git a/src/OmniSharp.Abstractions/Services/IUpdates.cs b/src/OmniSharp.Abstractions/Services/IUpdates.cs index 4320bae5b4..4c70f27a1d 100644 --- a/src/OmniSharp.Abstractions/Services/IUpdates.cs +++ b/src/OmniSharp.Abstractions/Services/IUpdates.cs @@ -2,7 +2,7 @@ namespace OmniSharp.Services { - public interface IUpdates + public interface IWaitableProjectSystem: IProjectSystem { Task WaitForUpdatesAsync(); } diff --git a/src/OmniSharp.DotNet/DotNetProjectSystem.cs b/src/OmniSharp.DotNet/DotNetProjectSystem.cs index fe9cad882c..cb57bb455c 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 : IProjectSystem, IUpdates + public class DotNetProjectSystem : IWaitableProjectSystem { private const string CompilationConfiguration = "Debug"; @@ -425,7 +425,7 @@ private static LanguageVersion ParseLanguageVersion(string value) return languageVersion; } - async Task IUpdates.WaitForUpdatesAsync() + async Task IWaitableProjectSystem.WaitForUpdatesAsync() { await ((IProjectSystem)this).GetWorkspaceModelAsync(new WorkspaceInformationRequest()); } diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index c3f2243745..d86f0d5a72 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 : IProjectSystem, IUpdates + public class ProjectSystem : IWaitableProjectSystem { private readonly IOmniSharpEnvironment _environment; private readonly OmniSharpWorkspace _workspace; diff --git a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs similarity index 64% rename from src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs rename to src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index d22040ec60..598c43163b 100644 --- a/src/OmniSharp.MiscellanousFiles/MiscellanousFiles.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -14,15 +14,15 @@ using OmniSharp.Models.WorkspaceInformation; using OmniSharp.Services; -namespace OmniSharp.MiscellanousFiles +namespace OmniSharp.MiscellaneousFile { [ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)] [ExtensionOrder(After = ProjectSystemNames.DotNetProjectSystem)] - [ExportProjectSystem(ProjectSystemNames.MiscellanousFilesProjectSystem), Shared] - public class MiscellanousFilesProjectSystem : IProjectSystem + [ExportProjectSystem(ProjectSystemNames.MiscellaneousFilesProjectSystem), Shared] + public class MiscellaneousFilesProjectSystem : IProjectSystem { - private readonly string miscFileExtension = ".cs"; - public string Key { get; } = "MiscellanousFiles"; + private const string miscFileExtension = ".cs"; + public string Key { get; } = "MiscellaneousFiles"; public string Language { get; } = LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; @@ -31,24 +31,23 @@ public class MiscellanousFilesProjectSystem : IProjectSystem private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; - private readonly List _projectSystems; + private readonly List _projectSystems; private readonly ILogger _logger; private ProjectId _projectId; [ImportingConstructor] - public MiscellanousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, + public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, ILoggerFactory loggerFactory, [ImportMany] IEnumerable> projectSystems) { _workspace = workspace; _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); _fileSystemHelper = fileSystemHelper; - _logger = loggerFactory.CreateLogger(); - _projectSystems = projectSystems. - Where - (ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || - ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem). - Select(ps => ps.Value). - Select(ps => ps as IUpdates) + _logger = loggerFactory.CreateLogger(); + _projectSystems = projectSystems + .Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || + ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem) + .Select(ps => ps.Value) + .Cast() .ToList(); } @@ -66,15 +65,15 @@ void IProjectSystem.Initalize(IConfiguration configuration) { var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); foreach (var filePath in allFiles) - AddIfMiscellanousFile(filePath); + AddIfMiscellaneousFile(filePath); - _fileSystemWatcher.Watch(miscFileExtension, OnMiscellanousFileChanged); + _fileSystemWatcher.Watch(miscFileExtension, OnMiscellaneousFileChanged); } - private async void AddIfMiscellanousFile(string filePath) + private async void AddIfMiscellaneousFile(string filePath) { //wait for the project systems to finish processing the updates - foreach(var projectSystem in _projectSystems) + foreach (var projectSystem in _projectSystems) { await projectSystem.WaitForUpdatesAsync(); } @@ -82,35 +81,40 @@ private async void AddIfMiscellanousFile(string filePath) var absoluteFilePath = new FileInfo(filePath).FullName; if (!File.Exists(absoluteFilePath)) return; + if (_workspace.GetDocument(filePath) == null) { - if (this._projectId == null) + if (_projectId == null) { - string assemblyName = Guid.NewGuid().ToString("N"); - //If not project exists for the Misc files, create one - var projectInfo = ProjectInfo.Create( - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: "MiscellanousFiles", - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - language: Language); - + var projectInfo = CreateNewProject(); _workspace.AddProject(projectInfo); _projectId = projectInfo.Id; } - _documents[absoluteFilePath] = _workspace.AddMiscellanousFileDocument(_projectId, absoluteFilePath); + _documents[absoluteFilePath] = _workspace.AddMiscellaneousFileDocument(_projectId, absoluteFilePath); _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } } - private void OnMiscellanousFileChanged(string filePath, FileChangeType changeType) + private ProjectInfo CreateNewProject() + { + string assemblyName = Guid.NewGuid().ToString("N"); + //If not project exists for the Misc files, create one + return ProjectInfo.Create( + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: "MiscellaneousFiles", + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: Language); + } + + private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType) { if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || changeType == FileChangeType.Create) { - AddIfMiscellanousFile(filePath); + AddIfMiscellaneousFile(filePath); } else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || @@ -124,7 +128,7 @@ private void RemoveFromWorkspace(string filePath) { if (_documents.TryRemove(filePath, out var documentId)) { - _workspace.RemoveMiscellanousFileDocument(documentId); + _workspace.RemoveMiscellaneousFileDocument(documentId); _logger.LogDebug($"Removed file '{filePath}' from the workspace."); } } diff --git a/src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj b/src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj similarity index 100% rename from src/OmniSharp.MiscellanousFiles/OmniSharp.MiscellanousFiles.csproj rename to src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index a809ec11c7..c8c71055b8 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -86,14 +86,14 @@ public void AddDocument(DocumentInfo documentInfo) OnDocumentAdded(documentInfo); } - public DocumentId AddMiscellanousFileDocument(ProjectId projectId, string filePath) + public DocumentId AddMiscellaneousFileDocument(ProjectId projectId, string filePath) { var documentId = AddDocument(projectId, filePath); _miscellanousFiles.Add(documentId); return documentId; } - public void RemoveMiscellanousFileDocument(DocumentId documentId) + public void RemoveMiscellaneousFileDocument(DocumentId documentId) { _miscellanousFiles.Remove(documentId); RemoveDocument(documentId); diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index c7baf68f2d..dfe49ff654 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -8,7 +8,7 @@ - + diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs similarity index 97% rename from tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs rename to tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs index af8bbdbbd6..3822f80e3c 100644 --- a/tests/OmniSharp.MiscellanousFiles.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs @@ -1,6 +1,5 @@ using System.Linq; using System.Threading.Tasks; -using OmniSharp.Mef; using OmniSharp.Models; using OmniSharp.Models.CodeCheck; using OmniSharp.Models.FilesChanged; @@ -10,17 +9,13 @@ using OmniSharp.Models.FixUsings; using OmniSharp.Models.SignatureHelp; using OmniSharp.Models.TypeLookup; -using OmniSharp.Roslyn.CSharp.Services.Diagnostics; using OmniSharp.Roslyn.CSharp.Services.Files; -using OmniSharp.Roslyn.CSharp.Services.Navigation; -using OmniSharp.Roslyn.CSharp.Services.Refactoring; -using OmniSharp.Roslyn.CSharp.Services.Signatures; using OmniSharp.Roslyn.CSharp.Services.Types; using TestUtility; using Xunit; using Xunit.Abstractions; -namespace OmniSharp.MiscellanousFiles.Tests +namespace OmniSharp.MiscellaneousFiles.Tests { public class EndpointFacts : AbstractTestFixture { diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj b/tests/OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj similarity index 100% rename from tests/OmniSharp.MiscellanousFiles.Tests/OmniSharp.MiscellanousFiles.Tests.csproj rename to tests/OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj diff --git a/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs b/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs deleted file mode 100644 index 9933b8fd08..0000000000 --- a/tests/OmniSharp.MiscellanousFiles.Tests/AssemblyInfo.cs +++ /dev/null @@ -1 +0,0 @@ -[assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)] diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 6bd183a4eb..fb78cc746f 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -15,7 +15,7 @@ using OmniSharp.DotNetTest.Models; using OmniSharp.Eventing; using OmniSharp.Mef; -using OmniSharp.MiscellanousFiles; +using OmniSharp.MiscellaneousFile; using OmniSharp.Models.WorkspaceInformation; using OmniSharp.MSBuild; using OmniSharp.Options; @@ -42,7 +42,7 @@ public class OmniSharpTestHost : DisposableObject typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, // OmniSharp.Roslyn typeof(RoslynFeaturesHostServicesProvider).GetTypeInfo().Assembly, // OmniSharp.Roslyn.CSharp typeof(CakeProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Cake - typeof(MiscellanousFilesProjectSystem).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles + typeof(MiscellaneousFilesProjectSystem).GetTypeInfo().Assembly // OmniSharp.MiscellanousFiles }); private readonly TestServiceProvider _serviceProvider; diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index 8dcff9406c..d35e5636f6 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -9,7 +9,7 @@ - + From 069d6f093eb4da002e39fd8d947c70fadafd84c4 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 8 Aug 2018 18:54:02 -0700 Subject: [PATCH 39/54] Remove comment --- .../MiscellaneousFileProjectSystem.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index 598c43163b..96901c0264 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -98,14 +98,12 @@ private async void AddIfMiscellaneousFile(string filePath) private ProjectInfo CreateNewProject() { - string assemblyName = Guid.NewGuid().ToString("N"); - //If not project exists for the Misc files, create one return ProjectInfo.Create( id: ProjectId.CreateNewId(), version: VersionStamp.Create(), name: "MiscellaneousFiles", metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, + assemblyName: Guid.NewGuid().ToString("N"), language: Language); } From 2e5e7fc586229bd1db163973dd1209ae9da76558 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 13:41:58 -0700 Subject: [PATCH 40/54] Add project handling in the workspace --- .../MiscellaneousFileProjectSystem.cs | 23 +---------------- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index 598c43163b..537ec5accd 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -33,7 +33,6 @@ public class MiscellaneousFilesProjectSystem : IProjectSystem private readonly FileSystemHelper _fileSystemHelper; private readonly List _projectSystems; private readonly ILogger _logger; - private ProjectId _projectId; [ImportingConstructor] public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, @@ -84,31 +83,11 @@ private async void AddIfMiscellaneousFile(string filePath) if (_workspace.GetDocument(filePath) == null) { - if (_projectId == null) - { - var projectInfo = CreateNewProject(); - _workspace.AddProject(projectInfo); - _projectId = projectInfo.Id; - } - - _documents[absoluteFilePath] = _workspace.AddMiscellaneousFileDocument(_projectId, absoluteFilePath); + _documents[absoluteFilePath] = _workspace.AddMiscellaneousFileDocument(absoluteFilePath, Language); _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } } - private ProjectInfo CreateNewProject() - { - string assemblyName = Guid.NewGuid().ToString("N"); - //If not project exists for the Misc files, create one - return ProjectInfo.Create( - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: "MiscellaneousFiles", - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - language: Language); - } - private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType) { if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index c8c71055b8..380be6bc98 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -23,6 +23,8 @@ public class OmniSharpWorkspace : Workspace private HashSet _miscellanousFiles; + private ProjectInfo MiscFilesProjectInfo; + [ImportingConstructor] public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory) : base(aggregator.CreateHostServices(), "Custom") @@ -86,13 +88,32 @@ public void AddDocument(DocumentInfo documentInfo) OnDocumentAdded(documentInfo); } - public DocumentId AddMiscellaneousFileDocument(ProjectId projectId, string filePath) + public DocumentId AddMiscellaneousFileDocument(string filePath, string language) { - var documentId = AddDocument(projectId, filePath); + if (MiscFilesProjectInfo == null) + { + MiscFilesProjectInfo = CreateMiscFilesProject(language); + AddProject(MiscFilesProjectInfo); + } + + var documentId = AddDocument(MiscFilesProjectInfo.Id, filePath); _miscellanousFiles.Add(documentId); return documentId; } + private ProjectInfo CreateMiscFilesProject(string language) + { + string assemblyName = Guid.NewGuid().ToString("N"); + //If not project exists for the Misc files, create one + return ProjectInfo.Create( + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: "MiscellaneousFiles", + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: language); + } + public void RemoveMiscellaneousFileDocument(DocumentId documentId) { _miscellanousFiles.Remove(documentId); From f89946d7968bc313b5edefaa73195d4e05a73f52 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 14:02:10 -0700 Subject: [PATCH 41/54] Add assembly info --- tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs b/tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs new file mode 100644 index 0000000000..9933b8fd08 --- /dev/null +++ b/tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)] From 20bf194693759e6b34a731bfb5eaed43d9c4db87 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 16:32:26 -0700 Subject: [PATCH 42/54] Deal with race condition between project system updates --- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 380be6bc98..1a8167c8e5 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -85,6 +85,16 @@ public void RemoveMetadataReference(ProjectId projectId, MetadataReference metad public void AddDocument(DocumentInfo documentInfo) { + var documentId = GetDocumentId(documentInfo.FilePath); + if (documentId != null && _miscellanousFiles.Contains(documentId)) + { + //if the file has already been added as a misc file, + //because of a possible race condition between the updates of the project systems, + //remove the misc file and add it the document as required + _miscellanousFiles.Remove(documentId); + RemoveDocument(documentId); + } + OnDocumentAdded(documentInfo); } From 4163f3fb0385ea36b8afa7b9a9681e4087e4d4de Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 16:34:16 -0700 Subject: [PATCH 43/54] add property type --- .../MiscellaneousFileProjectSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index 537ec5accd..f3d34e8894 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -22,8 +22,8 @@ namespace OmniSharp.MiscellaneousFile public class MiscellaneousFilesProjectSystem : IProjectSystem { private const string miscFileExtension = ".cs"; - public string Key { get; } = "MiscellaneousFiles"; - public string Language { get; } = LanguageNames.CSharp; + public string Key => "MiscellaneousFiles"; + public string Language => LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; From 9e2e0b91955944b4df7ffdf594bb24f54bcb5b63 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 17:12:43 -0700 Subject: [PATCH 44/54] CR feedback --- .../MiscellaneousFileProjectSystem.cs | 4 +-- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 30 +++++++++---------- .../EndpointFacts.cs | 1 - 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index f3d34e8894..077ae65618 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -22,7 +22,7 @@ namespace OmniSharp.MiscellaneousFile public class MiscellaneousFilesProjectSystem : IProjectSystem { private const string miscFileExtension = ".cs"; - public string Key => "MiscellaneousFiles"; + public string Key => ProjectSystemNames.MiscellaneousFilesProjectSystem; public string Language => LanguageNames.CSharp; IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; @@ -44,7 +44,7 @@ public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystem _logger = loggerFactory.CreateLogger(); _projectSystems = projectSystems .Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || - ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem) + ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem) .Select(ps => ps.Value) .Cast() .ToList(); diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 1a8167c8e5..21a1270d2a 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -21,9 +21,9 @@ public class OmniSharpWorkspace : Workspace private readonly ILogger _logger; - private HashSet _miscellanousFiles; + private HashSet _miscellaneousFiles; - private ProjectInfo MiscFilesProjectInfo; + private ProjectInfo miscFilesProjectInfo; [ImportingConstructor] public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory) @@ -31,7 +31,7 @@ public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory logg { BufferManager = new BufferManager(this); _logger = loggerFactory.CreateLogger(); - _miscellanousFiles = new HashSet(); + _miscellaneousFiles = new HashSet(); } public override bool CanOpenDocuments => true; @@ -86,12 +86,12 @@ public void RemoveMetadataReference(ProjectId projectId, MetadataReference metad public void AddDocument(DocumentInfo documentInfo) { var documentId = GetDocumentId(documentInfo.FilePath); - if (documentId != null && _miscellanousFiles.Contains(documentId)) + if (documentId != null && _miscellaneousFiles.Contains(documentId)) { - //if the file has already been added as a misc file, - //because of a possible race condition between the updates of the project systems, - //remove the misc file and add it the document as required - _miscellanousFiles.Remove(documentId); + // if the file has already been added as a misc file, + // because of a possible race condition between the updates of the project systems, + // remove the misc file and add the document as required + _miscellaneousFiles.Remove(documentId); RemoveDocument(documentId); } @@ -100,14 +100,14 @@ public void AddDocument(DocumentInfo documentInfo) public DocumentId AddMiscellaneousFileDocument(string filePath, string language) { - if (MiscFilesProjectInfo == null) + if (miscFilesProjectInfo == null) { - MiscFilesProjectInfo = CreateMiscFilesProject(language); - AddProject(MiscFilesProjectInfo); + miscFilesProjectInfo = CreateMiscFilesProject(language); + AddProject(miscFilesProjectInfo); } - var documentId = AddDocument(MiscFilesProjectInfo.Id, filePath); - _miscellanousFiles.Add(documentId); + var documentId = AddDocument(miscFilesProjectInfo.Id, filePath); + _miscellaneousFiles.Add(documentId); return documentId; } @@ -126,7 +126,7 @@ private ProjectInfo CreateMiscFilesProject(string language) public void RemoveMiscellaneousFileDocument(DocumentId documentId) { - _miscellanousFiles.Remove(documentId); + _miscellaneousFiles.Remove(documentId); RemoveDocument(documentId); } @@ -275,7 +275,7 @@ private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText public bool IsCapableOfSemanticDiagnostics(Document document) { var documentId = GetDocumentId(document.FilePath); - return !_miscellanousFiles.Contains(documentId); + return !_miscellaneousFiles.Contains(documentId); } } } diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs index 3822f80e3c..f103b492bb 100644 --- a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs @@ -29,7 +29,6 @@ public async Task Returns_only_syntactic_diagnotics() { 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)) { From 6dfca929a39de18872d10ed78a19d27dfa6677f4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 17:51:54 -0700 Subject: [PATCH 45/54] Move the check for the Misc files into the workspace --- .../MiscellaneousFileProjectSystem.cs | 7 ++++--- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index 077ae65618..cabf7d2149 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -39,7 +39,7 @@ public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystem ILoggerFactory loggerFactory, [ImportMany] IEnumerable> projectSystems) { _workspace = workspace; - _fileSystemWatcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher)); + _fileSystemWatcher = fileSystemWatcher; _fileSystemHelper = fileSystemHelper; _logger = loggerFactory.CreateLogger(); _projectSystems = projectSystems @@ -81,9 +81,10 @@ private async void AddIfMiscellaneousFile(string filePath) if (!File.Exists(absoluteFilePath)) return; - if (_workspace.GetDocument(filePath) == null) + var documentId = _workspace.TryAddMiscellaneousFileDocument(absoluteFilePath, Language); + if (documentId!= null) { - _documents[absoluteFilePath] = _workspace.AddMiscellaneousFileDocument(absoluteFilePath, Language); + _documents[absoluteFilePath] = documentId; _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 21a1270d2a..630b841233 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -98,8 +98,11 @@ public void AddDocument(DocumentInfo documentInfo) OnDocumentAdded(documentInfo); } - public DocumentId AddMiscellaneousFileDocument(string filePath, string language) + public DocumentId TryAddMiscellaneousFileDocument(string filePath, string language) { + if (GetDocument(filePath) != null) + return null; //if thw workspace already knows about his document then it is not a miscellaneous document + if (miscFilesProjectInfo == null) { miscFilesProjectInfo = CreateMiscFilesProject(language); From c5db9c95926813b44573a316f53c45ebe59bf206 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Aug 2018 17:56:29 -0700 Subject: [PATCH 46/54] edit comment --- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 630b841233..993a6e5fe2 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -101,7 +101,7 @@ public void AddDocument(DocumentInfo documentInfo) public DocumentId TryAddMiscellaneousFileDocument(string filePath, string language) { if (GetDocument(filePath) != null) - return null; //if thw workspace already knows about his document then it is not a miscellaneous document + return null; //if the workspace already knows about this document then it is not a miscellaneous document if (miscFilesProjectInfo == null) { From 7a70a0726e14532574190f67624290ea3c7eda05 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Aug 2018 10:07:00 -0700 Subject: [PATCH 47/54] Check for the project id for the document --- .../MiscellaneousFileProjectSystem.cs | 11 ++++-- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 39 ++++++++----------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index cabf7d2149..5c01e6a99a 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -81,10 +81,13 @@ private async void AddIfMiscellaneousFile(string filePath) if (!File.Exists(absoluteFilePath)) return; - var documentId = _workspace.TryAddMiscellaneousFileDocument(absoluteFilePath, Language); - if (documentId!= null) + var documentId = _documents.GetOrAdd(absoluteFilePath, _workspace.TryAddMiscellaneousFileDocument(absoluteFilePath, Language)); + if (documentId == null) + { + _documents.TryRemove(absoluteFilePath, out var id); + } + else { - _documents[absoluteFilePath] = documentId; _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } } @@ -108,7 +111,7 @@ private void RemoveFromWorkspace(string filePath) { if (_documents.TryRemove(filePath, out var documentId)) { - _workspace.RemoveMiscellaneousFileDocument(documentId); + _workspace.RemoveDocument(documentId); _logger.LogDebug($"Removed file '{filePath}' from the workspace."); } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 993a6e5fe2..3740bc91d2 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -21,8 +21,6 @@ public class OmniSharpWorkspace : Workspace private readonly ILogger _logger; - private HashSet _miscellaneousFiles; - private ProjectInfo miscFilesProjectInfo; [ImportingConstructor] @@ -31,7 +29,6 @@ public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory logg { BufferManager = new BufferManager(this); _logger = loggerFactory.CreateLogger(); - _miscellaneousFiles = new HashSet(); } public override bool CanOpenDocuments => true; @@ -86,12 +83,11 @@ public void RemoveMetadataReference(ProjectId projectId, MetadataReference metad public void AddDocument(DocumentInfo documentInfo) { var documentId = GetDocumentId(documentInfo.FilePath); - if (documentId != null && _miscellaneousFiles.Contains(documentId)) + if (documentId != null && IsMiscellaneousDocument(documentId)) { // if the file has already been added as a misc file, // because of a possible race condition between the updates of the project systems, // remove the misc file and add the document as required - _miscellaneousFiles.Remove(documentId); RemoveDocument(documentId); } @@ -105,32 +101,25 @@ public DocumentId TryAddMiscellaneousFileDocument(string filePath, string langua if (miscFilesProjectInfo == null) { - miscFilesProjectInfo = CreateMiscFilesProject(language); - AddProject(miscFilesProjectInfo); + var projectInfo = CreateMiscFilesProject(language); + AddProject(projectInfo); + miscFilesProjectInfo = projectInfo; } var documentId = AddDocument(miscFilesProjectInfo.Id, filePath); - _miscellaneousFiles.Add(documentId); return documentId; } private ProjectInfo CreateMiscFilesProject(string language) { string assemblyName = Guid.NewGuid().ToString("N"); - //If not project exists for the Misc files, create one return ProjectInfo.Create( - id: ProjectId.CreateNewId(), - version: VersionStamp.Create(), - name: "MiscellaneousFiles", - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, - assemblyName: assemblyName, - language: language); - } - - public void RemoveMiscellaneousFileDocument(DocumentId documentId) - { - _miscellaneousFiles.Remove(documentId); - RemoveDocument(documentId); + id: ProjectId.CreateNewId(), + version: VersionStamp.Create(), + name: "MiscellaneousFiles", + metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + assemblyName: assemblyName, + language: language); } public DocumentId AddDocument(ProjectId projectId, string filePath, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) @@ -277,8 +266,12 @@ private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText public bool IsCapableOfSemanticDiagnostics(Document document) { - var documentId = GetDocumentId(document.FilePath); - return !_miscellaneousFiles.Contains(documentId); + return !IsMiscellaneousDocument(document.Id); + } + + private bool IsMiscellaneousDocument(DocumentId documentId) + { + return miscFilesProjectInfo!=null && documentId.ProjectId == miscFilesProjectInfo.Id; } } } From ce3a437db8e788e8c0a53e0d622daadfca8b6163 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Aug 2018 12:07:58 -0700 Subject: [PATCH 48/54] Dont keep track of the documents in the project system --- .../MiscellaneousFileProjectSystem.cs | 18 +++------- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 34 ++++++++++++------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs index 5c01e6a99a..054fb93707 100644 --- a/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs +++ b/src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Composition; using System.IO; @@ -27,7 +26,6 @@ public class MiscellaneousFilesProjectSystem : IProjectSystem IEnumerable IProjectSystem.Extensions => new[] { miscFileExtension }; public bool EnabledByDefault { get; } = true; - private readonly ConcurrentDictionary _documents = new ConcurrentDictionary(); private readonly OmniSharpWorkspace _workspace; private readonly IFileSystemWatcher _fileSystemWatcher; private readonly FileSystemHelper _fileSystemHelper; @@ -64,12 +62,12 @@ void IProjectSystem.Initalize(IConfiguration configuration) { var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); foreach (var filePath in allFiles) - AddIfMiscellaneousFile(filePath); + TryAddMiscellaneousFile(filePath); _fileSystemWatcher.Watch(miscFileExtension, OnMiscellaneousFileChanged); } - private async void AddIfMiscellaneousFile(string filePath) + private async void TryAddMiscellaneousFile(string filePath) { //wait for the project systems to finish processing the updates foreach (var projectSystem in _projectSystems) @@ -81,12 +79,7 @@ private async void AddIfMiscellaneousFile(string filePath) if (!File.Exists(absoluteFilePath)) return; - var documentId = _documents.GetOrAdd(absoluteFilePath, _workspace.TryAddMiscellaneousFileDocument(absoluteFilePath, Language)); - if (documentId == null) - { - _documents.TryRemove(absoluteFilePath, out var id); - } - else + if (_workspace.TryAddMiscellaneousDocument(absoluteFilePath, Language) != null) { _logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); } @@ -97,7 +90,7 @@ private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeTy if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || changeType == FileChangeType.Create) { - AddIfMiscellaneousFile(filePath); + TryAddMiscellaneousFile(filePath); } else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || @@ -109,9 +102,8 @@ private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeTy private void RemoveFromWorkspace(string filePath) { - if (_documents.TryRemove(filePath, out var documentId)) + if (_workspace.TryRemoveMiscellaneousDocument(filePath)) { - _workspace.RemoveDocument(documentId); _logger.LogDebug($"Removed file '{filePath}' from the workspace."); } } diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 3740bc91d2..21bf6a7492 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Composition; using System.IO; @@ -21,7 +22,7 @@ public class OmniSharpWorkspace : Workspace private readonly ILogger _logger; - private ProjectInfo miscFilesProjectInfo; + private readonly ConcurrentDictionary miscDocumentsProjectInfos = new ConcurrentDictionary(); [ImportingConstructor] public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory) @@ -90,36 +91,43 @@ public void AddDocument(DocumentInfo documentInfo) // remove the misc file and add the document as required RemoveDocument(documentId); } - + OnDocumentAdded(documentInfo); } - public DocumentId TryAddMiscellaneousFileDocument(string filePath, string language) + public DocumentId TryAddMiscellaneousDocument(string filePath, string language) { if (GetDocument(filePath) != null) return null; //if the workspace already knows about this document then it is not a miscellaneous document - - if (miscFilesProjectInfo == null) - { - var projectInfo = CreateMiscFilesProject(language); - AddProject(projectInfo); - miscFilesProjectInfo = projectInfo; - } - var documentId = AddDocument(miscFilesProjectInfo.Id, filePath); + var projectInfo = miscDocumentsProjectInfos.GetOrAdd(language, CreateMiscFilesProject(language)); + var documentId = AddDocument(projectInfo.Id, filePath); return documentId; } + public bool TryRemoveMiscellaneousDocument(string filePath) + { + var documentId = GetDocumentId(filePath); + if (documentId == null || !IsMiscellaneousDocument(documentId)) + return false; + + RemoveDocument(documentId); + return true; + } + private ProjectInfo CreateMiscFilesProject(string language) { string assemblyName = Guid.NewGuid().ToString("N"); - return ProjectInfo.Create( + var projectInfo = ProjectInfo.Create( id: ProjectId.CreateNewId(), version: VersionStamp.Create(), name: "MiscellaneousFiles", metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, assemblyName: assemblyName, language: language); + + AddProject(projectInfo); + return projectInfo; } public DocumentId AddDocument(ProjectId projectId, string filePath, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) @@ -271,7 +279,7 @@ public bool IsCapableOfSemanticDiagnostics(Document document) private bool IsMiscellaneousDocument(DocumentId documentId) { - return miscFilesProjectInfo!=null && documentId.ProjectId == miscFilesProjectInfo.Id; + return miscDocumentsProjectInfos.Where(p => p.Value.Id == documentId.ProjectId).Any(); } } } From 2355dedc96391b016ad8c0ec24ba9e3308966445 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Aug 2018 12:40:23 -0700 Subject: [PATCH 49/54] Add test for multiple files --- .../EndpointFacts.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs index f103b492bb..c7b47e4fef 100644 --- a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs @@ -284,6 +284,53 @@ public async Task Returns_TypeLookup() } } + [Fact] + public async Task Adds_Multiple_Misc_Files_To_Same_project() + { + const string source1 = +@"class Program +{ + public static void Main(){ + A a = new A(4, $$5); + } +}"; + + const string source2 = +@"class A +{ + A(int a, int b) + { + } +}"; + var testfile1 = new TestFile("file1.cs", source1); + var testfile2 = new TestFile("file2.cs", source2); + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) + { + 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 point = testfile1.Content.GetPointFromPosition(); + var request = new SignatureHelpRequest() + { + FileName = filePath1, + Line = point.Line, + Column = point.Offset, + Buffer = testfile1.Content.Code + }; + + var actual = await host.GetResponse(OmniSharpEndpoints.SignatureHelp, request); + Assert.Single(actual.Signatures); + Assert.Equal(1, actual.ActiveParameter); + Assert.Equal(0, actual.ActiveSignature); + Assert.Equal("A", actual.Signatures.ElementAt(0).Name); + Assert.Equal(2, actual.Signatures.ElementAt(0).Parameters.Count()); + } + } + } + private string AddTestFile(ITestProject testProject, TestFile testfile) { From b8d11e2761f7a3368230f851ad11ac448d2d1ba8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Aug 2018 13:10:40 -0700 Subject: [PATCH 50/54] Add test to handle deletion --- .../EndpointFacts.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs index c7b47e4fef..9fd6d7647a 100644 --- a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs +++ b/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs @@ -331,13 +331,34 @@ public static void Main(){ } } + [Fact] + public async Task Handles_File_Deletion() + { + //When the file is deleted the diagnostics must not be returned + 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 request = new CodeCheckRequest() { FileName = filePath }; + var actual = await host.GetResponse(OmniSharpEndpoints.CodeCheck, request); + Assert.Single(actual.QuickFixes); + + await WaitForFileUpdate(filePath, host, FileWatching.FileChangeType.Delete); + actual = await host.GetResponse(OmniSharpEndpoints.CodeCheck, request); + Assert.Empty(actual.QuickFixes); + } + } + } private string AddTestFile(ITestProject testProject, TestFile testfile) { return testProject.AddDisposableFile(testfile.FileName, testfile.Content.Text.ToString()); } - private async Task WaitForFileUpdate(string filePath, OmniSharpTestHost host) + private async Task WaitForFileUpdate(string filePath, OmniSharpTestHost host, FileWatching.FileChangeType changeType = FileWatching.FileChangeType.Create) { var fileChangedService = host.GetRequestHandler(OmniSharpEndpoints.FilesChanged); await fileChangedService.Handle(new[] @@ -345,7 +366,7 @@ await fileChangedService.Handle(new[] new FilesChangedRequest { FileName = filePath, - ChangeType = FileWatching.FileChangeType.Create + ChangeType = changeType } }); From 67003aadb3fb2518e7511b6bc0308fc7704ae4b9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 12 Aug 2018 15:36:34 -0700 Subject: [PATCH 51/54] Call TryRemoveMiscDocument --- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 21bf6a7492..14700825ec 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -83,14 +83,10 @@ public void RemoveMetadataReference(ProjectId projectId, MetadataReference metad public void AddDocument(DocumentInfo documentInfo) { - var documentId = GetDocumentId(documentInfo.FilePath); - if (documentId != null && IsMiscellaneousDocument(documentId)) - { - // if the file has already been added as a misc file, - // because of a possible race condition between the updates of the project systems, - // remove the misc file and add the document as required - RemoveDocument(documentId); - } + // if the file has already been added as a misc file, + // because of a possible race condition between the updates of the project systems, + // remove the misc file and add the document as required + TryRemoveMiscellaneousDocument(documentInfo.FilePath); OnDocumentAdded(documentInfo); } From 4d3e85372b7ddb002158449c48f5b3e8b390bda4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Aug 2018 14:24:55 -0700 Subject: [PATCH 52/54] Naming consistency --- OmniSharp.sln | 56 +++++++++---------- .../MiscellaneousFilesProjectSystem.cs} | 0 .../OmniSharp.MiscellaneousFiles.csproj} | 0 src/OmniSharp.Stdio/OmniSharp.Stdio.csproj | 2 +- .../AssemblyInfo.cs | 0 .../EndpointFacts.cs | 0 ...OmniSharp.MiscellaneousFiles.Tests.csproj} | 0 tests/TestUtility/TestUtility.csproj | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) rename src/{OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs => OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs} (100%) rename src/{OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj => OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj} (100%) rename tests/{OmniSharp.MiscellaneousFile.Tests => OmniSharp.MiscellaneousFiles.Tests}/AssemblyInfo.cs (100%) rename tests/{OmniSharp.MiscellaneousFile.Tests => OmniSharp.MiscellaneousFiles.Tests}/EndpointFacts.cs (100%) rename tests/{OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj => OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj} (100%) diff --git a/OmniSharp.sln b/OmniSharp.sln index 4cb04fe997..76a7afeab5 100644 --- a/OmniSharp.sln +++ b/OmniSharp.sln @@ -69,9 +69,9 @@ 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.MiscellaneousFile", "src\OmniSharp.MiscellaneousFile\OmniSharp.MiscellaneousFile.csproj", "{23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}" +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.MiscellaneousFile.Tests", "tests\OmniSharp.MiscellaneousFile.Tests\OmniSharp.MiscellaneousFile.Tests.csproj", "{B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}" +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 @@ -395,30 +395,30 @@ 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 - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x64.ActiveCfg = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x64.Build.0 = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x86.ActiveCfg = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Debug|x86.Build.0 = Debug|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|Any CPU.Build.0 = Release|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x64.ActiveCfg = Release|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x64.Build.0 = Release|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x86.ActiveCfg = Release|Any CPU - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA}.Release|x86.Build.0 = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x64.ActiveCfg = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x64.Build.0 = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x86.ActiveCfg = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Debug|x86.Build.0 = Debug|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|Any CPU.Build.0 = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x64.ActiveCfg = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x64.Build.0 = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.Release|x86.ActiveCfg = Release|Any CPU - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24}.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 +450,8 @@ 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} - {23A91D15-B178-45A9-8F7A-B0CE1F7A8DAA} = {2C348365-A9D8-459E-9276-56FC46AAEE31} - {B37D4AF9-BD6F-4B18-A8EF-4E5EC04F7D24} = {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.MiscellaneousFile/MiscellaneousFileProjectSystem.cs b/src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs similarity index 100% rename from src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs rename to src/OmniSharp.MiscellaneousFiles/MiscellaneousFilesProjectSystem.cs diff --git a/src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj b/src/OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj similarity index 100% rename from src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj rename to src/OmniSharp.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.csproj diff --git a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj index dfe49ff654..6b7ca88600 100644 --- a/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj +++ b/src/OmniSharp.Stdio/OmniSharp.Stdio.csproj @@ -8,7 +8,7 @@ - + diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs b/tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs similarity index 100% rename from tests/OmniSharp.MiscellaneousFile.Tests/AssemblyInfo.cs rename to tests/OmniSharp.MiscellaneousFiles.Tests/AssemblyInfo.cs diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs b/tests/OmniSharp.MiscellaneousFiles.Tests/EndpointFacts.cs similarity index 100% rename from tests/OmniSharp.MiscellaneousFile.Tests/EndpointFacts.cs rename to tests/OmniSharp.MiscellaneousFiles.Tests/EndpointFacts.cs diff --git a/tests/OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj b/tests/OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj similarity index 100% rename from tests/OmniSharp.MiscellaneousFile.Tests/OmniSharp.MiscellaneousFile.Tests.csproj rename to tests/OmniSharp.MiscellaneousFiles.Tests/OmniSharp.MiscellaneousFiles.Tests.csproj diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index d35e5636f6..ede88fae3d 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -9,7 +9,7 @@ - + From f0d325580358818fc52b816322cc77d7e8b593ee Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Aug 2018 15:23:54 -0700 Subject: [PATCH 53/54] Use the default references same as the script system --- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 4 +- .../DefaultMetadataReferencesHelper.cs | 42 +++++++++++++++++++ src/OmniSharp.Script/ScriptContextProvider.cs | 27 +----------- 3 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index 14700825ec..a87982ea9e 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.Extensions.Logging; using OmniSharp.Roslyn; +using OmniSharp.Roslyn.Utilities; using OmniSharp.Utilities; namespace OmniSharp @@ -118,7 +119,8 @@ private ProjectInfo CreateMiscFilesProject(string language) id: ProjectId.CreateNewId(), version: VersionStamp.Create(), name: "MiscellaneousFiles", - metadataReferences: new MetadataReference[] { MetadataReference.CreateFromFile((typeof(object).Assembly).Location) }, + metadataReferences: DefaultMetadataReferencesHelper.GetDefaultMetadataReferencesLocations() + .Select(loc => MetadataReference.CreateFromFile(loc)), assemblyName: assemblyName, language: language); diff --git a/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs b/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs new file mode 100644 index 0000000000..f552bf9e7d --- /dev/null +++ b/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace OmniSharp.Roslyn.Utilities +{ + public static class DefaultMetadataReferencesHelper + { + public static IEnumerable GetDefaultMetadataReferencesLocations() + { + var assemblies = new[] + { + typeof(object).GetTypeInfo().Assembly, + typeof(Enumerable).GetTypeInfo().Assembly, + typeof(Stack<>).GetTypeInfo().Assembly, + typeof(Lazy<,>).GetTypeInfo().Assembly, + FromName("System.Runtime"), + FromName("mscorlib") + }; + + return assemblies + .Where(a => a != null) + .Select(a => a.Location) + .Distinct(); + + Assembly FromName(string assemblyName) + { + try + { + return Assembly.Load(new AssemblyName(assemblyName)); + } + catch + { + return null; + } + } + } + } +} diff --git a/src/OmniSharp.Script/ScriptContextProvider.cs b/src/OmniSharp.Script/ScriptContextProvider.cs index a97cd2d648..a6026094bb 100644 --- a/src/OmniSharp.Script/ScriptContextProvider.cs +++ b/src/OmniSharp.Script/ScriptContextProvider.cs @@ -117,20 +117,7 @@ public ScriptContext CreateScriptContext(ScriptOptions scriptOptions) private void AddDefaultClrMetadataReferences(HashSet commonReferences, HashSet assemblyReferences) { - var assemblies = new[] - { - typeof(object).GetTypeInfo().Assembly, - typeof(Enumerable).GetTypeInfo().Assembly, - typeof(Stack<>).GetTypeInfo().Assembly, - typeof(Lazy<,>).GetTypeInfo().Assembly, - FromName("System.Runtime"), - FromName("mscorlib") - }; - - var references = assemblies - .Where(a => a != null) - .Select(a => a.Location) - .Distinct() + var references = DefaultMetadataReferencesHelper.GetDefaultMetadataReferencesLocations() .Select(l => { assemblyReferences.Add(l); @@ -141,18 +128,6 @@ private void AddDefaultClrMetadataReferences(HashSet commonRe { commonReferences.Add(reference); } - - Assembly FromName(string assemblyName) - { - try - { - return Assembly.Load(new AssemblyName(assemblyName)); - } - catch - { - return null; - } - } } private void AddMetadataReference(ISet referenceCollection, HashSet assemblyReferences, string fileReference) From cdecdad80995610e45a405a5b04d162b6af214b8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Aug 2018 15:30:17 -0700 Subject: [PATCH 54/54] CR feedback --- src/OmniSharp.Roslyn/OmniSharpWorkspace.cs | 2 +- .../Utilities/DefaultMetadataReferencesHelper.cs | 4 ++-- src/OmniSharp.Script/ScriptContextProvider.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs index a87982ea9e..495f88a6ca 100644 --- a/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs +++ b/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs @@ -119,7 +119,7 @@ private ProjectInfo CreateMiscFilesProject(string language) id: ProjectId.CreateNewId(), version: VersionStamp.Create(), name: "MiscellaneousFiles", - metadataReferences: DefaultMetadataReferencesHelper.GetDefaultMetadataReferencesLocations() + metadataReferences: DefaultMetadataReferenceHelper.GetDefaultMetadataReferenceLocations() .Select(loc => MetadataReference.CreateFromFile(loc)), assemblyName: assemblyName, language: language); diff --git a/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs b/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs index f552bf9e7d..7c4ce122ec 100644 --- a/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs +++ b/src/OmniSharp.Roslyn/Utilities/DefaultMetadataReferencesHelper.cs @@ -7,9 +7,9 @@ namespace OmniSharp.Roslyn.Utilities { - public static class DefaultMetadataReferencesHelper + public static class DefaultMetadataReferenceHelper { - public static IEnumerable GetDefaultMetadataReferencesLocations() + public static IEnumerable GetDefaultMetadataReferenceLocations() { var assemblies = new[] { diff --git a/src/OmniSharp.Script/ScriptContextProvider.cs b/src/OmniSharp.Script/ScriptContextProvider.cs index a6026094bb..95b5967f9d 100644 --- a/src/OmniSharp.Script/ScriptContextProvider.cs +++ b/src/OmniSharp.Script/ScriptContextProvider.cs @@ -117,7 +117,7 @@ public ScriptContext CreateScriptContext(ScriptOptions scriptOptions) private void AddDefaultClrMetadataReferences(HashSet commonReferences, HashSet assemblyReferences) { - var references = DefaultMetadataReferencesHelper.GetDefaultMetadataReferencesLocations() + var references = DefaultMetadataReferenceHelper.GetDefaultMetadataReferenceLocations() .Select(l => { assemblyReferences.Add(l);