Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not include source generated documents in related document results #75718

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading