-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow access to Roslyn diagnostics from Razor
- Loading branch information
1 parent
dc87898
commit 3f63a01
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Tools/ExternalAccess/Razor/Cohost/Handlers/Diagnostics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.LanguageServer; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using LSP = Roslyn.LanguageServer.Protocol; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers; | ||
|
||
internal static class Diagnostics | ||
{ | ||
public static async Task<ImmutableArray<LSP.Diagnostic>> GetDocumentDiagnosticsAsync(Document document, bool supportsVisualStudioExtensions, CancellationToken cancellationToken) | ||
{ | ||
var globalOptionsService = document.Project.Solution.Services.ExportProvider.GetService<IGlobalOptionService>(); | ||
var diagnosticAnalyzerService = document.Project.Solution.Services.ExportProvider.GetService<IDiagnosticAnalyzerService>(); | ||
|
||
var diagnostics = await diagnosticAnalyzerService.GetDiagnosticsForSpanAsync(document, range: null, cancellationToken).ConfigureAwait(false); | ||
|
||
var project = document.Project; | ||
// isLiveSource means build might override a diagnostics, but this method is only used by tooling, so builds aren't relevant | ||
const bool IsLiveSource = false; | ||
// Potential duplicate is only set for workspace diagnostics | ||
const bool PotentialDuplicate = false; | ||
|
||
var result = ArrayBuilder<LSP.Diagnostic>.GetInstance(capacity: diagnostics.Length); | ||
foreach (var diagnostic in diagnostics) | ||
{ | ||
result.AddRange(ProtocolConversions.ConvertDiagnostic(diagnostic, supportsVisualStudioExtensions, project, IsLiveSource, PotentialDuplicate, globalOptionsService)); | ||
} | ||
|
||
return result.ToImmutableAndFree(); | ||
} | ||
} |