-
Notifications
You must be signed in to change notification settings - Fork 0
/
completions.go
63 lines (54 loc) · 1.43 KB
/
completions.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
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
57
58
59
60
61
62
63
package tekton
import (
"fmt"
yaml_helper "github.com/cezarguimaraes/tekton-ls/internal/yaml"
"github.com/goccy/go-yaml"
protocol "github.com/tliron/glsp/protocol_3_16"
)
// completion defines a contextual completion. That is, a text to be suggested,
// and a yaml path required for it to be valid.
type completion struct {
context *yaml.Path
text string
}
// CompletionCandidate holds the text of a completion and the Tekton object
// to which it refers.
type CompletionCandidate struct {
// Text is the completion to be suggested.
Text string
// Value is the Tekton object to which the completion refers.
Value Meta
}
// String implements fmt.Stringer for CompletionCandidate.
func (c CompletionCandidate) String() string {
return c.Text
}
// Completion returns a list of completion suggestion given a position in
// a Tekton Document.
func (d *Document) completions(pos protocol.Position) []fmt.Stringer {
res := []fmt.Stringer{}
for _, id := range d.identifiers {
cs := id.meta.Completions()
for _, c := range cs {
if c.context != nil {
// contextual completion
ctx, err := c.context.FilterNode(d.ast.Body)
if err != nil {
continue
}
if ctx == nil {
continue
}
pos := yaml_helper.FindNode(ctx, int(pos.Line)+1, int(pos.Character)+1)
if pos == nil {
continue
}
}
res = append(res, CompletionCandidate{
Text: c.text,
Value: id.meta,
})
}
}
return res
}