@@ -27,8 +27,14 @@ export default class BashServer {
27
27
) : Promise < BashServer > {
28
28
const parser = await initializeParser ( )
29
29
30
+ const { PATH } = process . env
31
+
32
+ if ( ! PATH ) {
33
+ throw new Error ( 'Expected PATH environment variable to be set' )
34
+ }
35
+
30
36
return Promise . all ( [
31
- Executables . fromPath ( process . env . PATH ) ,
37
+ Executables . fromPath ( PATH ) ,
32
38
Analyzer . fromRoot ( { connection, rootPath, parser } ) ,
33
39
] ) . then ( xs => {
34
40
const executables = xs [ 0 ]
@@ -128,11 +134,17 @@ export default class BashServer {
128
134
)
129
135
}
130
136
131
- private async onHover ( params : LSP . TextDocumentPositionParams ) : Promise < LSP . Hover > {
137
+ private async onHover (
138
+ params : LSP . TextDocumentPositionParams ,
139
+ ) : Promise < LSP . Hover | null > {
132
140
const word = this . getWordAtPoint ( params )
133
141
134
142
this . logRequest ( { request : 'onHover' , params, word } )
135
143
144
+ if ( ! word ) {
145
+ return null
146
+ }
147
+
136
148
const explainshellEndpoint = config . getExplainshellEndpoint ( )
137
149
if ( explainshellEndpoint ) {
138
150
this . connection . console . log ( `Query ${ explainshellEndpoint } ` )
@@ -185,9 +197,12 @@ export default class BashServer {
185
197
return null
186
198
}
187
199
188
- private onDefinition ( params : LSP . TextDocumentPositionParams ) : LSP . Definition {
200
+ private onDefinition ( params : LSP . TextDocumentPositionParams ) : LSP . Definition | null {
189
201
const word = this . getWordAtPoint ( params )
190
202
this . logRequest ( { request : 'onDefinition' , params, word } )
203
+ if ( ! word ) {
204
+ return null
205
+ }
191
206
return this . analyzer . findDefinition ( word )
192
207
}
193
208
@@ -203,22 +218,23 @@ export default class BashServer {
203
218
204
219
private onDocumentHighlight (
205
220
params : LSP . TextDocumentPositionParams ,
206
- ) : LSP . DocumentHighlight [ ] {
221
+ ) : LSP . DocumentHighlight [ ] | null {
207
222
const word = this . getWordAtPoint ( params )
208
223
this . logRequest ( { request : 'onDocumentHighlight' , params, word } )
209
-
210
224
if ( ! word ) {
211
- return [ ]
225
+ return null
212
226
}
213
-
214
227
return this . analyzer
215
228
. findOccurrences ( params . textDocument . uri , word )
216
229
. map ( n => ( { range : n . range } ) )
217
230
}
218
231
219
- private onReferences ( params : LSP . ReferenceParams ) : LSP . Location [ ] {
232
+ private onReferences ( params : LSP . ReferenceParams ) : LSP . Location [ ] | null {
220
233
const word = this . getWordAtPoint ( params )
221
234
this . logRequest ( { request : 'onReferences' , params, word } )
235
+ if ( ! word ) {
236
+ return null
237
+ }
222
238
return this . analyzer . findReferences ( word )
223
239
}
224
240
@@ -228,12 +244,15 @@ export default class BashServer {
228
244
229
245
const currentUri = params . textDocument . uri
230
246
231
- const symbolCompletions = getCompletionItemsForSymbols ( {
232
- symbols : this . analyzer . findSymbolsMatchingWord ( {
233
- word,
234
- } ) ,
235
- currentUri,
236
- } )
247
+ const symbolCompletions =
248
+ word === null
249
+ ? [ ]
250
+ : getCompletionItemsForSymbols ( {
251
+ symbols : this . analyzer . findSymbolsMatchingWord ( {
252
+ word,
253
+ } ) ,
254
+ currentUri,
255
+ } )
237
256
238
257
const reservedWordsCompletions = ReservedWords . LIST . map ( reservedWord => ( {
239
258
label : reservedWord ,
@@ -288,11 +307,11 @@ export default class BashServer {
288
307
}
289
308
290
309
private async onCompletionResolve (
291
- item : BashCompletionItem ,
310
+ item : LSP . CompletionItem ,
292
311
) : Promise < LSP . CompletionItem > {
293
312
const {
294
313
data : { name, type } ,
295
- } = item
314
+ } = item as BashCompletionItem
296
315
297
316
this . connection . console . log ( `onCompletionResolve name=${ name } type=${ type } ` )
298
317
0 commit comments