-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
69 lines (58 loc) · 1.45 KB
/
context.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
64
65
66
67
68
69
package errgoengine
type MainError struct {
ErrorNode *StackTraceEntry
Document *Document
Nearest SyntaxNode
Context any
}
func (err *MainError) DocumentPath() string {
return err.ErrorNode.DocumentPath
}
type ContextData struct {
*Store
Analyzer LanguageAnalyzer
WorkingPath string
CurrentDocumentPath string
Variables map[string]string
TraceStack TraceStack
MainError *MainError
}
func NewContextData(store *Store, workingPath string) *ContextData {
return &ContextData{
Store: store,
WorkingPath: workingPath,
Variables: make(map[string]string),
TraceStack: TraceStack{},
}
}
func (data *ContextData) MainDocumentPath() string {
if data.MainError != nil && data.MainError.ErrorNode != nil {
return data.MainError.DocumentPath()
}
return data.CurrentDocumentPath
}
func (data *ContextData) FindSymbol(name string, pos int) Symbol {
path := data.MainDocumentPath()
sym := data.Store.FindSymbol(path, name, pos)
if sym == nil {
return data.Analyzer.FindSymbol(name)
}
return sym
}
func (data *ContextData) AddVariable(name string, value string) {
if data.Variables == nil {
data.Variables = make(map[string]string)
}
data.Variables[name] = value
}
func (data *ContextData) AddVariables(vars map[string]string) {
if len(vars) == 0 {
return
}
if data.Variables == nil {
data.Variables = make(map[string]string)
}
for k, v := range vars {
data.Variables[k] = v
}
}