Skip to content

Commit

Permalink
Merge pull request #75718 from dibarbet/related_documents_sg
Browse files Browse the repository at this point in the history
Do not include source generated documents in related document results
  • Loading branch information
dibarbet authored Nov 4, 2024
2 parents 985a2a3 + ba3372b commit f2eab90
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void ProduceItems(
foreach (var syntaxReference in symbol.DeclaringSyntaxReferences)
{
var documentId = solution.GetDocument(syntaxReference.SyntaxTree)?.Id;
if (documentId != null && seenDocumentIds.Add(documentId))
if (documentId != null && !documentId.IsSourceGenerated && seenDocumentIds.Add(documentId))
callback(documentId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Test.Utilities;
using Roslyn.Test.Utilities.TestGenerators;
using Roslyn.Utilities;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -174,4 +175,39 @@ class Y

AssertJsonEquals(results2, expectedResult);
}

[Theory, CombinatorialData]
public async Task DoesNotIncludeSourceGeneratedDocuments(bool mutatingLspWorkspace, bool useProgress)
{
var source =
"""
namespace M
{
class A
{
public {|caret:|}B b;
}
}
""";
var generated =
"""
namespace M
{
class B
{
}
}
""";

await using var testLspServer = await CreateTestLspServerAsync(source, mutatingLspWorkspace);
await AddGeneratorAsync(new SingleFileTestGenerator(generated), testLspServer.TestWorkspace);

var project = testLspServer.TestWorkspace.CurrentSolution.Projects.Single();
var results = await RunGetRelatedDocumentsAsync(
testLspServer,
project.Documents.First().GetURI(),
useProgress: useProgress);

Assert.Empty(results);
}
}

0 comments on commit f2eab90

Please sign in to comment.