-
Notifications
You must be signed in to change notification settings - Fork 1
/
definition.go
31 lines (23 loc) · 900 Bytes
/
definition.go
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
package analysis
import (
"context"
"go.lsp.dev/protocol"
"github.com/kurtosis-tech/vscode-kurtosis/starlark-lsp/pkg/document"
"github.com/kurtosis-tech/vscode-kurtosis/starlark-lsp/pkg/query"
)
func (a *Analyzer) Definition(ctx context.Context, doc document.Document, pos protocol.Position) []protocol.Location {
symbol := a.SymbolAtPosition(doc, pos)
// this might be because no matching symbol was found, or because it's a builtin with no location
if !symbol.HasLocation() {
return nil
}
pt := query.PositionToPoint(pos)
// if pos is already on the definition, then don't return a navigation destination
// (it feels weird to get the navigate cursor and click and have it seemingly do nothing)
if symbol.Location.URI == doc.URI() && query.RangeContainsPoint(query.SitterRange(symbol.Location.Range), pt) {
return nil
}
return []protocol.Location{
symbol.Location,
}
}