public void SendDiagnostics(List <DiagnosticInfo> list) { var files = list.Select(l => l.Document).OrderBy(q => q).Distinct().ToList(); // If the computed set is empty it has to push the empty array to clear former diagnostics. foreach (var file in files) { PublishDiagnosticParams parameter = new PublishDiagnosticParams { Uri = file, Diagnostics = Array.Empty <Diagnostic>() }; _ = rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentPublishDiagnosticsName, parameter); } foreach (var file in files) { List <Diagnostic> diagnostics = new List <Diagnostic>(); foreach (var info in list) { DiagnosticSeverity severity = default; switch (info.Severify) { case DiagnosticInfo.Severity.Info: severity = DiagnosticSeverity.Information; break; case DiagnosticInfo.Severity.Warning: severity = DiagnosticSeverity.Warning; break; case DiagnosticInfo.Severity.Error: severity = DiagnosticSeverity.Error; break; } var document = target.CheckDoc(info.Document); (int, int)bs = new LanguageServer.Module().GetLineColumn(info.Start, document); (int, int)be = new LanguageServer.Module().GetLineColumn(info.End, document); Diagnostic diagnostic = new Diagnostic { Message = info.Message, Severity = severity, Range = new LspTypes.Range { Start = new Position(bs.Item1, bs.Item2), End = new Position(be.Item1, be.Item2) }, Code = "Test" + Enum.GetName(typeof(DiagnosticSeverity), severity) }; diagnostics.Add(diagnostic); } PublishDiagnosticParams parameter = new PublishDiagnosticParams { Uri = file, Diagnostics = diagnostics.ToArray() }; if (maxProblems > -1) { parameter.Diagnostics = parameter.Diagnostics.Take(maxProblems).ToArray(); } _ = rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentPublishDiagnosticsName, parameter); } }
public Task NotifyWithParameterObjectAsync(string targetName, object argument = null) => _rpc.NotifyWithParameterObjectAsync(targetName, argument);