Skip to content

Fix LSP references for using alias #78819

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

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -253,7 +253,7 @@ public override async ValueTask OnReferencesFoundAsync(IAsyncEnumerable<SourceRe

// If we have no document span, our location may be in metadata or may be a namespace.
var symbol = await SymbolFinder.FindSymbolAtPositionAsync(_document, _position, cancellationToken).ConfigureAwait(false);
if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind == SymbolKind.Namespace)
if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind is SymbolKind.Namespace or SymbolKind.Alias)
{
// Either:
// (1) We couldn't find the location in metadata and it's not in any of our known documents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,27 @@ class PREPROCESSING_SYMBOL
AssertHighlightCount(results, expectedDefinitionCount: 0, expectedWrittenReferenceCount: 0, expectedReferenceCount: 3);
}

[Theory, CombinatorialData]
public async Task TestFindReferencesAsync_UsingAlias(bool mutatingLspWorkspace)
{
var markup =
"""
using {|caret:MyType|} = System.{|reference:String|};

class SomeClassToExtract
{
void M()
{
{|reference:MyType|} p;
}
}
""";
await using var testLspServer = await CreateTestLspServerAsync(markup, mutatingLspWorkspace, CapabilitiesWithVSExtensions);

var results = await RunFindAllReferencesAsync(testLspServer, testLspServer.GetLocations("caret").First());
AssertLocationsEqual(testLspServer.GetLocations("reference"), results.Select(result => result.Location).WhereNotNull());
}

private static LSP.ReferenceParams CreateReferenceParams(LSP.Location caret, IProgress<object> progress)
=> new LSP.ReferenceParams()
{
Expand Down
Loading