Skip to content

Commit e31b7b1

Browse files
committed
Find metadata reference for alias
1 parent 228059e commit e31b7b1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,20 @@ public override async ValueTask OnReferencesFoundAsync(IAsyncEnumerable<SourceRe
253253

254254
// If we have no document span, our location may be in metadata or may be a namespace.
255255
var symbol = await SymbolFinder.FindSymbolAtPositionAsync(_document, _position, cancellationToken).ConfigureAwait(false);
256-
if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind is SymbolKind.Namespace or SymbolKind.Alias)
256+
if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind is SymbolKind.Namespace)
257257
{
258258
// Either:
259259
// (1) We couldn't find the location in metadata and it's not in any of our known documents.
260260
// (2) The symbol is a namespace (and therefore has no location).
261261
return null;
262262
}
263263

264+
if (symbol is IAliasSymbol aliasSymbol)
265+
{
266+
// If the location symbol is an alias symbol, we need to get the target symbol to find the original location in metadata.
267+
symbol = aliasSymbol.Target;
268+
}
269+
264270
var options = _globalOptions.GetMetadataAsSourceOptions();
265271
var declarationFile = await _metadataAsSourceFileService.GetGeneratedFileAsync(
266272
_workspace, _document.Project, symbol, signaturesOnly: true, options: options, cancellationToken: cancellationToken).ConfigureAwait(false);

src/LanguageServer/ProtocolUnitTests/References/FindAllReferencesHandlerTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ void M()
318318
await using var testLspServer = await CreateTestLspServerAsync(markup, mutatingLspWorkspace, CapabilitiesWithVSExtensions);
319319

320320
var results = await RunFindAllReferencesAsync(testLspServer, testLspServer.GetLocations("caret").First());
321-
AssertLocationsEqual(testLspServer.GetLocations("reference"), results.Select(result => result.Location).WhereNotNull());
321+
Assert.Equal(3, results.Length);
322+
Assert.True(results[0].Location.DocumentUri.ToString().EndsWith("String.cs"));
323+
324+
AssertLocationsEqual(testLspServer.GetLocations("reference"), results.Skip(1).Select(r => r.Location));
322325
}
323326

324327
private static LSP.ReferenceParams CreateReferenceParams(LSP.Location caret, IProgress<object> progress)

0 commit comments

Comments
 (0)