@@ -13,6 +13,8 @@ import { BashCompletionItem, CompletionItemDataType } from './types'
13
13
import { uniqueBasedOnHash } from './util/array'
14
14
import { getShellDocumentation } from './util/sh'
15
15
16
+ const PARAMETER_EXPANSION_PREFIXES = new Set ( [ '$' , '${' , '${#' ] )
17
+
16
18
/**
17
19
* The BashServer glues together the separate components to implement
18
20
* the various parts of the Language Server Protocol.
@@ -304,19 +306,34 @@ export default class BashServer {
304
306
} )
305
307
this . logRequest ( { request : 'onCompletion' , params, word } )
306
308
309
+ if ( word && word . startsWith ( '#' ) ) {
310
+ // Inside a comment block
311
+ return [ ]
312
+ }
313
+
307
314
const currentUri = params . textDocument . uri
308
315
316
+ const shouldCompleteOnVariables = word
317
+ ? PARAMETER_EXPANSION_PREFIXES . has ( word )
318
+ : false
319
+
309
320
const symbolCompletions =
310
321
word === null
311
322
? [ ]
312
323
: this . getCompletionItemsForSymbols ( {
313
- symbols : this . analyzer . findSymbolsMatchingWord ( {
314
- exactMatch : false ,
315
- word,
316
- } ) ,
324
+ symbols : shouldCompleteOnVariables
325
+ ? this . analyzer . getAllVariableSymbols ( )
326
+ : this . analyzer . findSymbolsMatchingWord ( {
327
+ exactMatch : false ,
328
+ word,
329
+ } ) ,
317
330
currentUri,
318
331
} )
319
332
333
+ if ( shouldCompleteOnVariables ) {
334
+ return symbolCompletions
335
+ }
336
+
320
337
const reservedWordsCompletions = ReservedWords . LIST . map ( reservedWord => ( {
321
338
label : reservedWord ,
322
339
kind : LSP . SymbolKind . Interface , // ??
@@ -357,11 +374,6 @@ export default class BashServer {
357
374
]
358
375
359
376
if ( word ) {
360
- if ( word . startsWith ( '#' ) ) {
361
- // Inside a comment block
362
- return [ ]
363
- }
364
-
365
377
// Filter to only return suffixes of the current word
366
378
return allCompletions . filter ( item => item . label . startsWith ( word ) )
367
379
}
0 commit comments