-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentHighlightHandler.cs
49 lines (43 loc) · 1.95 KB
/
DocumentHighlightHandler.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
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using PseudoCode.Core.Runtime.Operations;
namespace PseudoCode.LSP;
public class DocumentHighlightHandler : DocumentHighlightHandlerBase
{
private readonly ILogger<DocumentHighlightHandler> _logger;
private readonly ILanguageServerConfiguration _configuration;
private readonly AnalysisService _analysisService;
private readonly DocumentSelector _documentSelector = DocumentSelector.ForLanguage("pseudocode");
public DocumentHighlightHandler(ILogger<DocumentHighlightHandler> logger, Foo foo,
ILanguageServerConfiguration configuration,
AnalysisService analysisService)
{
_logger = logger;
_configuration = configuration;
_analysisService = analysisService;
foo.SayFoo();
logger.LogWarning("hi document highlight");
}
protected override DocumentHighlightRegistrationOptions CreateRegistrationOptions(
DocumentHighlightCapability capability,
ClientCapabilities clientCapabilities) => new()
{
DocumentSelector = DocumentSelector.ForLanguage("pseudocode")
};
public override async Task<DocumentHighlightContainer?> Handle(DocumentHighlightParams request,
CancellationToken cancellationToken)
{
var (definition, range) =
Scope.GetHoveredVariable(_analysisService.GetAnalysis(request.TextDocument.Uri).AllDefinitions,
request.Position.ToLocation());
if (definition == null) return new DocumentHighlightContainer();
return new DocumentHighlightContainer(definition.References.Select(r => new DocumentHighlight
{
Range = r.ToRange(),
Kind = DocumentHighlightKind.Text
}));
}
}