未验证 提交 86437420 编写于 作者: A Allison Chou 提交者: GitHub

Merge pull request #41619 from allisonchou/NexusDiagnosticBug

Fix for LSP diagnostic bugs
......@@ -164,10 +164,12 @@ public static LSP.DiagnosticSeverity DiagnosticSeverityToLspDiagnositcSeverity(D
{
switch (severity)
{
// TO-DO: Add new LSP diagnostic severity for hidden diagnostics
// https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1063158
case DiagnosticSeverity.Hidden:
return LSP.DiagnosticSeverity.Hint;
case DiagnosticSeverity.Info:
return LSP.DiagnosticSeverity.Information;
return LSP.DiagnosticSeverity.Hint;
case DiagnosticSeverity.Warning:
return LSP.DiagnosticSeverity.Warning;
case DiagnosticSeverity.Error:
......
......@@ -17,6 +17,7 @@
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Roslyn.Utilities;
using StreamJsonRpc;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
......@@ -79,7 +80,20 @@ public Task<InitializeResult> Initialize(JToken input, CancellationToken cancell
}
[JsonRpcMethod(Methods.InitializedName)]
public Task Initialized() => Task.CompletedTask;
public async Task Initialized()
{
// Publish diagnostics for all open documents immediately following initialization.
var solution = _workspace.CurrentSolution;
var openDocuments = _workspace.GetOpenDocumentIds();
foreach (var documentId in openDocuments)
{
var document = solution.GetDocument(documentId);
if (document != null)
{
await PublishDiagnosticsAsync(document).ConfigureAwait(false);
}
}
}
[JsonRpcMethod(Methods.ShutdownName)]
public object? Shutdown(CancellationToken _) => null;
......@@ -190,9 +204,7 @@ private async void DiagnosticService_DiagnosticsUpdated(object sender, Diagnosti
}
// LSP does not currently support publishing diagnostics incrememntally, so we re-publish all diagnostics.
var diagnostics = await GetDiagnosticsAsync(e.Solution, document, CancellationToken.None).ConfigureAwait(false);
var publishDiagnosticsParams = new PublishDiagnosticParams { Diagnostics = diagnostics, Uri = document.GetURI() };
await _jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentPublishDiagnosticsName, publishDiagnosticsParams).ConfigureAwait(false);
await PublishDiagnosticsAsync(document).ConfigureAwait(false);
}
}
catch (Exception ex) when (FatalError.ReportWithoutCrash(ex))
......@@ -200,9 +212,16 @@ private async void DiagnosticService_DiagnosticsUpdated(object sender, Diagnosti
}
}
private async Task<LanguageServer.Protocol.Diagnostic[]> GetDiagnosticsAsync(Solution solution, Document document, CancellationToken cancellationToken)
private async Task PublishDiagnosticsAsync(Document document)
{
var diagnostics = await GetDiagnosticsAsync(document, CancellationToken.None).ConfigureAwait(false);
var publishDiagnosticsParams = new PublishDiagnosticParams { Diagnostics = diagnostics, Uri = document.GetURI() };
await _jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentPublishDiagnosticsName, publishDiagnosticsParams).ConfigureAwait(false);
}
private async Task<LanguageServer.Protocol.Diagnostic[]> GetDiagnosticsAsync(Document document, CancellationToken cancellationToken)
{
var diagnostics = _diagnosticService.GetDiagnostics(solution.Workspace, document.Project.Id, document.Id, null, false, cancellationToken);
var diagnostics = _diagnosticService.GetDiagnostics(document.Project.Solution.Workspace, document.Project.Id, document.Id, null, false, cancellationToken);
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
return diagnostics.Select(diagnostic => new LanguageServer.Protocol.Diagnostic
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册