Skip to content

Commit e1fab1c

Browse files
authored
Return LSP diagnostics with their reported severity. (#77145)
For VSCode we were adjusting information diagnostics severity so that they would be reported as hints. We are moving this behavior to the client and allowing users to opt-in. Client-side PR: dotnet/vscode-csharp#7984 Part of dotnet/vscode-csharp#6723
2 parents daae3d8 + 6b30476 commit e1fab1c

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

src/LanguageServer/Protocol/Extensions/ProtocolConversions.Diagnostics.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static LSP.VSDiagnostic CreateLspDiagnostic(
107107
Code = diagnosticData.Id,
108108
CodeDescription = ProtocolConversions.HelpLinkToCodeDescription(diagnosticData.GetValidHelpLinkUri()),
109109
Message = diagnosticData.Message,
110-
Severity = ConvertDiagnosticSeverity(diagnosticData.Severity, supportsVisualStudioExtensions),
110+
Severity = ConvertDiagnosticSeverity(diagnosticData.Severity),
111111
Tags = ConvertTags(diagnosticData, isLiveSource, potentialDuplicate),
112112
DiagnosticRank = ConvertRank(diagnosticData),
113113
Range = GetRange(diagnosticData.DataLocation)
@@ -207,14 +207,13 @@ private static bool ShouldIncludeHiddenDiagnostic(DiagnosticData diagnosticData,
207207
return null;
208208
}
209209

210-
private static LSP.DiagnosticSeverity ConvertDiagnosticSeverity(DiagnosticSeverity severity, bool supportsVisualStudioExtensions)
210+
private static LSP.DiagnosticSeverity ConvertDiagnosticSeverity(DiagnosticSeverity severity)
211211
=> severity switch
212212
{
213213
// Hidden is translated in ConvertTags to pass along appropriate _ms tags
214214
// that will hide the item in a client that knows about those tags.
215215
DiagnosticSeverity.Hidden => LSP.DiagnosticSeverity.Hint,
216-
// VSCode shows information diagnostics as blue squiggles, and hint diagnostics as 3 dots. We prefer the latter rendering so we return hint diagnostics in vscode.
217-
DiagnosticSeverity.Info => supportsVisualStudioExtensions ? LSP.DiagnosticSeverity.Information : LSP.DiagnosticSeverity.Hint,
216+
DiagnosticSeverity.Info => LSP.DiagnosticSeverity.Information,
218217
DiagnosticSeverity.Warning => LSP.DiagnosticSeverity.Warning,
219218
DiagnosticSeverity.Error => LSP.DiagnosticSeverity.Error,
220219
_ => throw ExceptionUtilities.UnexpectedValue(severity),

src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -870,30 +870,6 @@ public async Task TestInfoDiagnosticsAreReportedAsInformationInVS(bool mutatingL
870870
Assert.Equal(LSP.DiagnosticSeverity.Information, results.Single().Diagnostics.Single().Severity);
871871
}
872872

873-
[Theory, CombinatorialData]
874-
public async Task TestInfoDiagnosticsAreReportedAsHintInVSCode(bool mutatingLspWorkspace)
875-
{
876-
var markup =
877-
@"class A
878-
{
879-
public A SomeA = new A();
880-
}";
881-
await using var testLspServer = await CreateTestWorkspaceWithDiagnosticsAsync(markup, mutatingLspWorkspace, BackgroundAnalysisScope.OpenFiles, useVSDiagnostics: false);
882-
883-
// Calling GetTextBuffer will effectively open the file.
884-
testLspServer.TestWorkspace.Documents.Single().GetTextBuffer();
885-
886-
var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();
887-
888-
await OpenDocumentAsync(testLspServer, document);
889-
890-
var results = await RunGetDocumentPullDiagnosticsAsync(
891-
testLspServer, document.GetURI(), useVSDiagnostics: false);
892-
893-
Assert.Equal("IDE0090", results.Single().Diagnostics.Single().Code);
894-
Assert.Equal(LSP.DiagnosticSeverity.Hint, results.Single().Diagnostics.Single().Severity);
895-
}
896-
897873
#endregion
898874

899875
#region Workspace Diagnostics

0 commit comments

Comments
 (0)