forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBicepSemanticTokensHandler.cs
56 lines (48 loc) · 2.35 KB
/
BicepSemanticTokensHandler.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
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.LanguageServer.CompilationManager;
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 BicepSemanticTokensHandler : SemanticTokensHandlerBase
{
private readonly ICompilationManager compilationManager;
// TODO: Not sure if this needs to be shared.
private readonly SemanticTokensLegend legend = new();
public BicepSemanticTokensHandler(ICompilationManager compilationManager)
{
this.compilationManager = compilationManager;
}
protected override Task<SemanticTokensDocument> GetSemanticTokensDocument(ITextDocumentIdentifierParams @params, CancellationToken cancellationToken)
{
return Task.FromResult(new SemanticTokensDocument(this.legend));
}
protected override Task Tokenize(SemanticTokensBuilder builder, ITextDocumentIdentifierParams identifier, CancellationToken cancellationToken)
{
/*
* do not check for file extension here because that will prevent untitled files from getting syntax highlighting
*/
var compilationContext = this.compilationManager.GetCompilation(identifier.TextDocument.Uri);
if (compilationContext is not null)
{
SemanticTokenVisitor.BuildSemanticTokens(builder, compilationContext.Compilation.GetEntrypointSemanticModel());
}
return Task.CompletedTask;
}
protected override SemanticTokensRegistrationOptions CreateRegistrationOptions(SemanticTokensCapability capability, ClientCapabilities clientCapabilities) => new()
{
// the semantic tokens handler requests don't get routed like other handlers
// it seems we can only have one and it must be shared between all the language IDs we support
DocumentSelector = DocumentSelectorFactory.CreateForBicepAndParams(),
Legend = this.legend,
Full = new SemanticTokensCapabilityRequestFull
{
Delta = true
},
Range = true
};
}
}