forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BicepReferencesHandler.cs
48 lines (42 loc) · 1.89 KB
/
BicepReferencesHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.Core.Navigation;
using Bicep.Core.Semantics;
using Bicep.LanguageServer.Providers;
using Bicep.LanguageServer.Utils;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Bicep.LanguageServer.Handlers
{
public class BicepReferencesHandler(ISymbolResolver symbolResolver, DocumentSelectorFactory documentSelectorFactory) : ReferencesHandlerBase
{
public override async Task<LocationContainer?> Handle(ReferenceParams request, CancellationToken cancellationToken)
{
await Task.CompletedTask;
var result = symbolResolver.ResolveSymbol(request.TextDocument.Uri, request.Position);
if (result == null)
{
return null;
}
if (result.Symbol is PropertySymbol)
{
// TODO: Implement for PropertySymbol
return null;
}
var references = result.Context.Compilation.GetEntrypointSemanticModel()
.FindReferences(result.Symbol)
.Where(referenceSyntax => request.Context.IncludeDeclaration || !(referenceSyntax is INamedDeclarationSyntax))
.Select(referenceSyntax => new Location
{
Uri = request.TextDocument.Uri,
Range = PositionHelper.GetNameRange(result.Context.LineStarts, referenceSyntax),
});
return new(references);
}
protected override ReferenceRegistrationOptions CreateRegistrationOptions(ReferenceCapability capability, ClientCapabilities clientCapabilities) => new()
{
DocumentSelector = documentSelectorFactory.CreateForBicepAndParams()
};
}
}