Skip to content

Commit

Permalink
Merge pull request dotnet#73395 from dibarbet/fix_expanded_message
Browse files Browse the repository at this point in the history
Use null for diagnostic ExpandedMessage so the client falls back appr…
  • Loading branch information
dibarbet committed May 9, 2024
1 parent 8b7d080 commit 45dd487
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ LSP.VSDiagnostic CreateLspDiagnostic(

if (capabilities.HasVisualStudioLspCapability())
{
var expandedMessage = string.IsNullOrEmpty(diagnosticData.Description) ? null : diagnosticData.Description;
diagnostic.DiagnosticType = diagnosticData.Category;
diagnostic.ExpandedMessage = diagnosticData.Description;
diagnostic.ExpandedMessage = expandedMessage;
diagnostic.Projects =
[
new VSDiagnosticProjectInformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ static void Main(string[] args)
Assert.Equal(vsDiagnostic.ExpandedMessage, AnalyzersResources.Avoid_unused_parameters_in_your_code_If_the_parameter_cannot_be_removed_then_change_its_name_so_it_starts_with_an_underscore_and_is_optionally_followed_by_an_integer_such_as__comma__1_comma__2_etc_These_are_treated_as_special_discard_symbol_names);
}

[Theory, CombinatorialData, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2050705")]
public async Task TestDocumentDiagnosticsUsesNullForExpandedMessage(bool mutatingLspWorkspace)
{
var markup =
@"class A {";
await using var testLspServer = await CreateTestWorkspaceWithDiagnosticsAsync(markup, mutatingLspWorkspace, BackgroundAnalysisScope.OpenFiles, useVSDiagnostics: true);

// Calling GetTextBuffer will effectively open the file.
testLspServer.TestWorkspace.Documents.Single().GetTextBuffer();

var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();

await OpenDocumentAsync(testLspServer, document);

var results = await RunGetDocumentPullDiagnosticsAsync(
testLspServer, document.GetURI(), useVSDiagnostics: true);

Assert.Equal("CS1513", results.Single().Diagnostics.Single().Code);
var vsDiagnostic = (VSDiagnostic)results.Single().Diagnostics.Single();
Assert.Null(vsDiagnostic.ExpandedMessage);
}

[Theory, CombinatorialData]
public async Task TestDocumentTodoCommentsDiagnosticsForOpenFile_NoCategory(bool useVSDiagnostics, bool mutatingLspWorkspace)
{
Expand Down

0 comments on commit 45dd487

Please sign in to comment.