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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package provider
import (
"github.com/grindlemire/go-tui/internal/lsp/gopls"
"github.com/grindlemire/go-tui/internal/tuigen"
)
func parseTestDoc(src string) *Document {
doc := &Document{
URI: "file:///test.gsx",
Content: src,
Version: 1,
}
lexer := tuigen.NewLexer("test.gsx", src)
parser := tuigen.NewParser(lexer)
ast, _ := parser.ParseFile()
doc.AST = ast
return doc
}
func makeCtx(doc *Document, nodeKind NodeKind, word string) *CursorContext {
return &CursorContext{
Document: doc,
NodeKind: nodeKind,
Word: word,
Scope: &Scope{},
}
}
type stubIndex struct {
components map[string]*ComponentInfo
functions map[string]*FuncInfo
params map[string]*ParamInfo
}
func newStubIndex() *stubIndex {
return &stubIndex{
components: make(map[string]*ComponentInfo),
functions: make(map[string]*FuncInfo),
params: make(map[string]*ParamInfo),
}
}
func (s *stubIndex) Lookup(name string) (*ComponentInfo, bool) {
info, ok := s.components[name]
return info, ok
}
func (s *stubIndex) LookupFunc(name string) (*FuncInfo, bool) {
info, ok := s.functions[name]
return info, ok
}
func (s *stubIndex) LookupParam(componentName, paramName string) (*ParamInfo, bool) {
key := componentName + "." + paramName
info, ok := s.params[key]
return info, ok
}
func (s *stubIndex) LookupFuncParam(funcName, paramName string) (*FuncParamInfo, bool) {
return nil, false
}
func (s *stubIndex) All() []string {
names := make([]string, 0, len(s.components))
for name := range s.components {
names = append(names, name)
}
return names
}
func (s *stubIndex) AllFunctions() []string {
names := make([]string, 0, len(s.functions))
for name := range s.functions {
names = append(names, name)
}
return names
}
type nilGoplsProxy struct{}
func (n *nilGoplsProxy) GetProxy() *gopls.GoplsProxy { return nil }
type nilVirtualFiles struct{}
func (n *nilVirtualFiles) GetVirtualFile(uri string) *gopls.CachedVirtualFile { return nil }
type stubDocAccessor struct {
docs []*Document
}
func (s *stubDocAccessor) GetDocument(uri string) *Document {
for _, d := range s.docs {
if d.URI == uri {
return d
}
}
return nil
}
func (s *stubDocAccessor) AllDocuments() []*Document {
return s.docs
}
type stubWorkspaceAST struct {
asts map[string]*tuigen.File
}
func (s *stubWorkspaceAST) GetWorkspaceAST(uri string) *tuigen.File {
return s.asts[uri]
}
func (s *stubWorkspaceAST) AllWorkspaceASTs() map[string]*tuigen.File {
return s.asts
}
|