Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add support for Miscellaneous Files #1252

Merged
merged 59 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a784769
Basic of the orphan file system
akshita31 Jun 28, 2018
f0cc59e
Initialise the project system
akshita31 Jun 28, 2018
b26552b
add csproj
akshita31 Jun 29, 2018
48548a7
Test using MSBuildProjectSystem
akshita31 Jul 3, 2018
774cc9b
Orphan file system using the msbuild system
akshita31 Jul 4, 2018
2d46149
Remove unnecessary change
akshita31 Jul 4, 2018
27266dd
csproj temp
akshita31 Jul 5, 2018
6f972d0
Get only syntactic diagnostics for misc files
akshita31 Jul 6, 2018
7bb4708
Logic to delete the document
akshita31 Jul 9, 2018
bf59f02
Edit csproj
akshita31 Jul 9, 2018
0db4d70
Rename to misc files
akshita31 Jul 9, 2018
8e6baec
Order the project systems
akshita31 Jul 10, 2018
439e9ad
Ordering failing
akshita31 Jul 10, 2018
2bbfe5b
Order project systems based on DisplayName
akshita31 Jul 11, 2018
35e2630
Remove orphan system
akshita31 Jul 11, 2018
999bf3f
Put inside the partial class
akshita31 Jul 11, 2018
81321cd
Clean up the miscellanous file system
akshita31 Jul 11, 2018
7e6ba33
Tests for the misc project system
akshita31 Jul 23, 2018
eba6ae2
Make MEF work
Jul 23, 2018
af435a6
Merge pull request #1 from rchande/MEFfix
akshita31 Jul 23, 2018
895cf5b
Returns only semantic diagnostics running
akshita31 Jul 24, 2018
c422035
Add more failing tests
akshita31 Jul 24, 2018
57bfbc5
Clean up
akshita31 Jul 25, 2018
48b4c26
Extension Ordering working for the project systems
akshita31 Jul 25, 2018
9a9cfa9
Merge master
akshita31 Jul 30, 2018
36af94b
Clean the solution
akshita31 Jul 30, 2018
11251b0
Change the target framework
akshita31 Jul 30, 2018
dd73d39
Add references
akshita31 Jul 30, 2018
2b599a6
Rename project system
akshita31 Jul 31, 2018
42c9049
Add few tests
akshita31 Jul 31, 2018
d0574cb
Refactor the tests to add a method to the test host
akshita31 Aug 1, 2018
6d8201a
Remove roslyn dependency in abstractions
akshita31 Aug 1, 2018
7a419ed
use only one project for all the miscellanous files
akshita31 Aug 2, 2018
def58ec
Add project system names class
akshita31 Aug 2, 2018
5788c37
Modifying the files changed facts to use absolute path instead of rel…
akshita31 Aug 2, 2018
9a8d447
Add the empty project
akshita31 Aug 2, 2018
c7158ba
Add the IUpdates interface
akshita31 Aug 2, 2018
c243202
Add absolute paths for the misc file system
akshita31 Aug 7, 2018
3cf76e6
Merge remote-tracking branch 'upstream/master' into orphan_system
akshita31 Aug 7, 2018
98e4de3
Add dotnet project system for the updates
akshita31 Aug 8, 2018
6228db3
CR feedback
akshita31 Aug 8, 2018
069d6f0
Remove comment
akshita31 Aug 9, 2018
2e5e7fc
Add project handling in the workspace
akshita31 Aug 9, 2018
850f3fd
Merge remote-tracking branch 'origin/orphan_system' into orphan_system
akshita31 Aug 9, 2018
f89946d
Add assembly info
akshita31 Aug 9, 2018
20bf194
Deal with race condition between project system updates
akshita31 Aug 9, 2018
4163f3f
add property type
akshita31 Aug 9, 2018
9e2e0b9
CR feedback
akshita31 Aug 10, 2018
6dfca92
Move the check for the Misc files into the workspace
akshita31 Aug 10, 2018
c5db9c9
edit comment
akshita31 Aug 10, 2018
2a3666a
Merge branch 'master' into orphan_system
akshita31 Aug 10, 2018
7a70a07
Check for the project id for the document
akshita31 Aug 10, 2018
ce3a437
Dont keep track of the documents in the project system
akshita31 Aug 10, 2018
2355ded
Add test for multiple files
akshita31 Aug 10, 2018
b8d11e2
Add test to handle deletion
akshita31 Aug 10, 2018
67003aa
Call TryRemoveMiscDocument
akshita31 Aug 12, 2018
4d3e853
Naming consistency
akshita31 Aug 13, 2018
f0d3255
Use the default references same as the script system
akshita31 Aug 13, 2018
cdecdad
CR feedback
akshita31 Aug 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion OmniSharp.sln
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
Expand All @@ -11,7 +12,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}"
Expand Down Expand Up @@ -68,6 +69,10 @@ 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}"
Copy link
Member

@filipw filipw Aug 13, 2018

Choose a reason for hiding this comment

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

why are the project + folder + namespace called OmniSharp.MiscellaneousFile (singular) but everywhere we refer to MiscellaneousFiles (plural)? I believe for consistency, the project and folder and namespace should be renamed to OmniSharp.MiscellaneousFiles too

EndProject
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
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -390,6 +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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -421,6 +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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E}
Expand Down
18 changes: 18 additions & 0 deletions src/OmniSharp.Abstractions/Mef/ExportProjectSystemAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Composition;
using OmniSharp.Services;

namespace OmniSharp.Mef
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class ExportProjectSystemAttribute: ExportAttribute
{
public string Name { get; }

public ExportProjectSystemAttribute(string name) : base(typeof(IProjectSystem))
{
Name = name;
}
}
}
7 changes: 7 additions & 0 deletions src/OmniSharp.Abstractions/Mef/ProjectSystemMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OmniSharp.Mef
{
public class ProjectSystemMetadata
{
public string Name { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp.Abstractions/ProjectSystemNames.cs
Original file line number Diff line number Diff line change
@@ -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 MiscellaneousFilesProjectSystem = "MiscellaneousFilesProjectSystem";
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp.Abstractions/Services/IUpdates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace OmniSharp.Services
{
public interface IWaitableProjectSystem: IProjectSystem
{
Task WaitForUpdatesAsync();
}
}
3 changes: 2 additions & 1 deletion src/OmniSharp.Cake/CakeProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +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
{
[Export(typeof(IProjectSystem)), Shared]
[ExportProjectSystem(ProjectSystemNames.CakeProjectSystem), Shared]
public class CakeProjectSystem : IProjectSystem
{
private readonly OmniSharpWorkspace _workspace;
Expand Down
10 changes: 8 additions & 2 deletions src/OmniSharp.DotNet/DotNetProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
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
{
[Export(typeof(IProjectSystem)), Shared]
public class DotNetProjectSystem : IProjectSystem
[ExportProjectSystem(ProjectSystemNames.DotNetProjectSystem), Shared]
public class DotNetProjectSystem : IWaitableProjectSystem
{
private const string CompilationConfiguration = "Debug";

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

return languageVersion;
}

async Task IWaitableProjectSystem.WaitForUpdatesAsync()
{
await ((IProjectSystem)this).GetWorkspaceModelAsync(new WorkspaceInformationRequest());
}
}
}
9 changes: 7 additions & 2 deletions src/OmniSharp.Host/WorkspaceInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
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;
using OmniSharp.Services;
using OmniSharp.Utilities;

namespace OmniSharp
{
Expand All @@ -24,9 +27,11 @@ public static void Initialize(

var projectEventForwarder = compositionHost.GetExport<ProjectEventForwarder>();
projectEventForwarder.Initialize();
var projectSystems = compositionHost.GetExports<Lazy<IProjectSystem, ProjectSystemMetadata>>();
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should hide that logic in some generic extension method? this way it could be reused in the future against other potentially ordered look ups like i.e.

foreach (var workspaceOptionsProvider in compositionHost.GetExports<IWorkspaceOptionsProvider>())

var ps = projectSystems.Select(n => n.Value);
var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList<IProjectSystem, ExportProjectSystemAttribute>(ps, eps => eps.Name);

// Initialize all the project systems
foreach (var projectSystem in compositionHost.GetExports<IProjectSystem>())
foreach (var projectSystem in orderedProjectSystems)
{
try
{
Expand Down
10 changes: 8 additions & 2 deletions src/OmniSharp.MSBuild/ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,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;
Expand All @@ -20,8 +21,8 @@

namespace OmniSharp.MSBuild
{
[Export(typeof(IProjectSystem)), Shared]
public class ProjectSystem : IProjectSystem
[ExportProjectSystem(ProjectSystemNames.MSBuildProjectSystem), Shared]
public class ProjectSystem : IWaitableProjectSystem
{
private readonly IOmniSharpEnvironment _environment;
private readonly OmniSharpWorkspace _workspace;
Expand Down Expand Up @@ -209,5 +210,10 @@ async Task<object> IProjectSystem.GetProjectModelAsync(string filePath)

return new MSBuildProjectInfo(projectFileInfo);
}

public async Task WaitForUpdatesAsync()
{
await _manager.WaitForQueueEmptyAsync();
}
}
}
111 changes: 111 additions & 0 deletions src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OmniSharp.FileSystem;
using OmniSharp.FileWatching;
using OmniSharp.Mef;
using OmniSharp.Models.WorkspaceInformation;
using OmniSharp.Services;

namespace OmniSharp.MiscellaneousFile
{
[ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)]
[ExtensionOrder(After = ProjectSystemNames.DotNetProjectSystem)]
[ExportProjectSystem(ProjectSystemNames.MiscellaneousFilesProjectSystem), Shared]
public class MiscellaneousFilesProjectSystem : IProjectSystem
{
private const string miscFileExtension = ".cs";
public string Key => ProjectSystemNames.MiscellaneousFilesProjectSystem;
public string Language => LanguageNames.CSharp;
IEnumerable<string> IProjectSystem.Extensions => new[] { miscFileExtension };
public bool EnabledByDefault { get; } = true;

private readonly OmniSharpWorkspace _workspace;
private readonly IFileSystemWatcher _fileSystemWatcher;
private readonly FileSystemHelper _fileSystemHelper;
private readonly List<IWaitableProjectSystem> _projectSystems;
private readonly ILogger _logger;

[ImportingConstructor]
public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper,
ILoggerFactory loggerFactory, [ImportMany] IEnumerable<Lazy<IProjectSystem, ProjectSystemMetadata>> projectSystems)
{
_workspace = workspace;
_fileSystemWatcher = fileSystemWatcher;
_fileSystemHelper = fileSystemHelper;
_logger = loggerFactory.CreateLogger<MiscellaneousFilesProjectSystem>();
_projectSystems = projectSystems
.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem ||
ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem)
.Select(ps => ps.Value)
.Cast<IWaitableProjectSystem>()
.ToList();
}

Task<object> IProjectSystem.GetProjectModelAsync(string filePath)
{
return Task.FromResult<object>(null);
}

Task<object> IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request)
{
return Task.FromResult<object>(null);
}

void IProjectSystem.Initalize(IConfiguration configuration)
{
var allFiles = _fileSystemHelper.GetFiles("**/*.cs");
foreach (var filePath in allFiles)
TryAddMiscellaneousFile(filePath);

_fileSystemWatcher.Watch(miscFileExtension, OnMiscellaneousFileChanged);
}

private async void TryAddMiscellaneousFile(string filePath)
{
//wait for the project systems to finish processing the updates
foreach (var projectSystem in _projectSystems)
{
await projectSystem.WaitForUpdatesAsync();
}

var absoluteFilePath = new FileInfo(filePath).FullName;
if (!File.Exists(absoluteFilePath))
return;

if (_workspace.TryAddMiscellaneousDocument(absoluteFilePath, Language) != null)
{
_logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace");
}
}

private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType)
{
if (changeType == FileChangeType.Unspecified && File.Exists(filePath) ||
changeType == FileChangeType.Create)
{
TryAddMiscellaneousFile(filePath);
}

else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) ||
changeType == FileChangeType.Delete)
{
RemoveFromWorkspace(filePath);
}
}

private void RemoveFromWorkspace(string filePath)
{
if (_workspace.TryRemoveMiscellaneousDocument(filePath))
{
_logger.LogDebug($"Removed file '{filePath}' from the workspace.");
}
}
}
}
17 changes: 17 additions & 0 deletions src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OmniSharp.Abstractions\OmniSharp.Abstractions.csproj" />
<ProjectReference Include="..\OmniSharp.Roslyn\OmniSharp.Roslyn.csproj" />
</ItemGroup>

</Project>
15 changes: 12 additions & 3 deletions src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ internal static DiagnosticLocation ToDiagnosticLocation(this Diagnostic diagnost
};
}

internal static async Task<IEnumerable<DiagnosticLocation>> FindDiagnosticLocationsAsync(this IEnumerable<Document> documents)
internal static async Task<IEnumerable<DiagnosticLocation>> FindDiagnosticLocationsAsync(this IEnumerable<Document> documents, OmniSharpWorkspace workspace)
{
if (documents == null || !documents.Any()) return Enumerable.Empty<DiagnosticLocation>();

var items = new List<DiagnosticLocation>();
foreach (var document in documents)
{
var semanticModel = await document.GetSemanticModelAsync();
IEnumerable<Diagnostic> diagnostics = semanticModel.GetDiagnostics();
IEnumerable<Diagnostic> 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()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<QuickFixResponse> 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);
}
}
Expand Down
Loading