public async Task <ImmutableArray <Diagnostic> > GetDiagnosticsAsync(Document document, CancellationToken cancellationToken) { var lspClient = _roslynLspClientServiceFactory.ActiveLanguageServerClient; if (lspClient == null) { return(ImmutableArray <Diagnostic> .Empty); } var textDocumentParams = new TextDocumentParams { TextDocument = new LSP.TextDocumentIdentifier { Uri = lspClient.ProtocolConverter.ToProtocolUri(new Uri(document.FilePath)) } }; var request = new LSP.LspRequest <TextDocumentParams, RoslynDiagnostic[]>(Methods.GetDocumentDiagnosticsName); var lspDiagnostics = await lspClient.RequestAsync(request, textDocumentParams, cancellationToken).ConfigureAwait(false); if (lspDiagnostics == null) { return(ImmutableArray <Diagnostic> .Empty); } var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var diagnostics = ImmutableArray.CreateBuilder <Diagnostic>(); foreach (var diagnostic in lspDiagnostics) { var location = Location.Create(document.FilePath, ProtocolConversions.RangeToTextSpan(diagnostic.Range, text), ProtocolConversions.RangeToLinePositionSpan(diagnostic.Range)); var severity = ToDiagnosticSeverity(diagnostic.Severity); var diag = Diagnostic.Create(diagnostic.Code ?? "VSLS", string.Empty, diagnostic.Message, severity, severity, true, severity == DiagnosticSeverity.Error ? 0 : 1, location: location, customTags: diagnostic.Tags); diagnostics.Add(diag); } return(diagnostics.ToImmutableArray()); }