@@ -57,19 +57,14 @@ export default class Analyzer {
57
57
} )
58
58
}
59
59
60
- // Global map from uri to the tree-sitter document.
61
- private documents : Documents = { }
60
+ private uriToTreeSitterDocument : Documents = { }
62
61
63
- // Global mapping from uri to the contents of the file at that uri.
64
62
// We need this to find the word at a given point etc.
65
- private texts : Texts = { }
63
+ private uriToFileContent : Texts = { }
66
64
67
- // Global map of all the declarations that we've seen, indexed by file
68
- // and then name.
69
- private declarations : FileDeclarations = { }
65
+ private uriToDeclarations : FileDeclarations = { }
70
66
71
- // Global mapping from tree-sitter node type to vscode SymbolKind
72
- private kinds : Kinds = {
67
+ private treeSitterTypeToLSPKind : Kinds = {
73
68
// These keys are using underscores as that's the naming convention in tree-sitter.
74
69
environment_variable_assignment : LSP . SymbolKind . Variable ,
75
70
function_definition : LSP . SymbolKind . Function ,
@@ -80,8 +75,8 @@ export default class Analyzer {
80
75
*/
81
76
public findDefinition ( name : string ) : LSP . Location [ ] {
82
77
const symbols : LSP . SymbolInformation [ ] = [ ]
83
- Object . keys ( this . declarations ) . forEach ( uri => {
84
- const declarationNames = this . declarations [ uri ] [ name ] || [ ]
78
+ Object . keys ( this . uriToDeclarations ) . forEach ( uri => {
79
+ const declarationNames = this . uriToDeclarations [ uri ] [ name ] || [ ]
85
80
declarationNames . forEach ( d => symbols . push ( d ) )
86
81
} )
87
82
return symbols . map ( s => s . location )
@@ -92,7 +87,7 @@ export default class Analyzer {
92
87
*/
93
88
public findReferences ( name : string ) : LSP . Location [ ] {
94
89
const locations = [ ]
95
- Object . keys ( this . documents ) . forEach ( uri => {
90
+ Object . keys ( this . uriToTreeSitterDocument ) . forEach ( uri => {
96
91
this . findOccurrences ( uri , name ) . forEach ( l => locations . push ( l ) )
97
92
} )
98
93
return locations
@@ -103,8 +98,8 @@ export default class Analyzer {
103
98
* It's currently not scope-aware.
104
99
*/
105
100
public findOccurrences ( uri : string , query : string ) : LSP . Location [ ] {
106
- const doc = this . documents [ uri ]
107
- const contents = this . texts [ uri ]
101
+ const doc = this . uriToTreeSitterDocument [ uri ]
102
+ const contents = this . uriToFileContent [ uri ]
108
103
109
104
const locations = [ ]
110
105
@@ -134,7 +129,7 @@ export default class Analyzer {
134
129
* Find all symbol definitions in the given file.
135
130
*/
136
131
public findSymbols ( uri : string ) : LSP . SymbolInformation [ ] {
137
- const declarationsInFile = this . declarations [ uri ] || [ ]
132
+ const declarationsInFile = this . uriToDeclarations [ uri ] || [ ]
138
133
const ds = [ ]
139
134
Object . keys ( declarationsInFile ) . forEach ( n => {
140
135
declarationsInFile [ n ] . forEach ( d => ds . push ( d ) )
@@ -155,9 +150,9 @@ export default class Analyzer {
155
150
d . setInputString ( contents )
156
151
d . parse ( )
157
152
158
- this . documents [ uri ] = d
159
- this . declarations [ uri ] = { }
160
- this . texts [ uri ] = contents
153
+ this . uriToTreeSitterDocument [ uri ] = d
154
+ this . uriToDeclarations [ uri ] = { }
155
+ this . uriToFileContent [ uri ] = contents
161
156
162
157
const problems = [ ]
163
158
@@ -174,17 +169,17 @@ export default class Analyzer {
174
169
} else if ( TreeSitterUtil . isDefinition ( n ) ) {
175
170
const named = n . firstNamedChild
176
171
const name = contents . slice ( named . startIndex , named . endIndex )
177
- const namedDeclarations = this . declarations [ uri ] [ name ] || [ ]
172
+ const namedDeclarations = this . uriToDeclarations [ uri ] [ name ] || [ ]
178
173
179
174
namedDeclarations . push (
180
175
LSP . SymbolInformation . create (
181
176
name ,
182
- this . kinds [ n . type ] ,
177
+ this . treeSitterTypeToLSPKind [ n . type ] ,
183
178
TreeSitterUtil . range ( named ) ,
184
179
uri ,
185
180
) ,
186
181
)
187
- this . declarations [ uri ] [ name ] = namedDeclarations
182
+ this . uriToDeclarations [ uri ] [ name ] = namedDeclarations
188
183
}
189
184
} )
190
185
@@ -195,8 +190,8 @@ export default class Analyzer {
195
190
* Find the full word at the given point.
196
191
*/
197
192
public wordAtPoint ( uri : string , line : number , column : number ) : string | null {
198
- const document = this . documents [ uri ]
199
- const contents = this . texts [ uri ]
193
+ const document = this . uriToTreeSitterDocument [ uri ]
194
+ const contents = this . uriToFileContent [ uri ]
200
195
201
196
const node = document . rootNode . namedDescendantForPosition ( { row : line , column } )
202
197
0 commit comments