Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01a692c

Browse files
committed
Return only variables for parameter expansion completions
1 parent c62c574 commit 01a692c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

‎server/src/analyser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ export default class Analyzer {
434434
return null
435435
}
436436

437+
public getAllVariableSymbols(): LSP.SymbolInformation[] {
438+
return this.getAllSymbols().filter(symbol => symbol.kind === LSP.SymbolKind.Variable)
439+
}
440+
437441
private getAllSymbols(): LSP.SymbolInformation[] {
438442
// NOTE: this could be cached, it takes < 1 ms to generate for a project with 250 bash files...
439443
const symbols: LSP.SymbolInformation[] = []

‎server/src/server.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { BashCompletionItem, CompletionItemDataType } from './types'
1313
import { uniqueBasedOnHash } from './util/array'
1414
import { getShellDocumentation } from './util/sh'
1515

16+
const PARAMETER_EXPANSION_PREFIXES = new Set(['$', '${', '${#'])
17+
1618
/**
1719
* The BashServer glues together the separate components to implement
1820
* the various parts of the Language Server Protocol.
@@ -304,19 +306,34 @@ export default class BashServer {
304306
})
305307
this.logRequest({ request: 'onCompletion', params, word })
306308

309+
if (word && word.startsWith('#')) {
310+
// Inside a comment block
311+
return []
312+
}
313+
307314
const currentUri = params.textDocument.uri
308315

316+
const shouldCompleteOnVariables = word
317+
? PARAMETER_EXPANSION_PREFIXES.has(word)
318+
: false
319+
309320
const symbolCompletions =
310321
word === null
311322
? []
312323
: 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+
}),
317330
currentUri,
318331
})
319332

333+
if (shouldCompleteOnVariables) {
334+
return symbolCompletions
335+
}
336+
320337
const reservedWordsCompletions = ReservedWords.LIST.map(reservedWord => ({
321338
label: reservedWord,
322339
kind: LSP.SymbolKind.Interface, // ??
@@ -357,11 +374,6 @@ export default class BashServer {
357374
]
358375

359376
if (word) {
360-
if (word.startsWith('#')) {
361-
// Inside a comment block
362-
return []
363-
}
364-
365377
// Filter to only return suffixes of the current word
366378
return allCompletions.filter(item => item.label.startsWith(word))
367379
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /