Skip to content

Commit 2a8adf5

Browse files
author
Jackson Kearl
committed
Better handle suggestion enablement in SuggestEnabledInput
Fixes microsoft#89541.
1 parent 2524412 commit 2a8adf5

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ export class SuggestEnabledInput extends Widget implements IThemable {
187187
provideCompletionItems: (model: ITextModel, position: Position, _context: modes.CompletionContext) => {
188188
let query = model.getValue();
189189

190-
let wordStart = query.lastIndexOf(' ', position.column - 1) + 1;
191-
let alreadyTypedCount = position.column - wordStart - 1;
190+
const zeroIndexedColumn = position.column - 1;
191+
192+
let zeroIndexedWordStart = query.lastIndexOf(' ', zeroIndexedColumn - 1) + 1;
193+
let alreadyTypedCount = zeroIndexedColumn - zeroIndexedWordStart;
192194

193195
// dont show suggestions if the user has typed something, but hasn't used the trigger character
194-
if (alreadyTypedCount > 0 && (validatedSuggestProvider.triggerCharacters).indexOf(query[wordStart]) === -1) { return { suggestions: [] }; }
196+
if (alreadyTypedCount > 0 && validatedSuggestProvider.triggerCharacters.indexOf(query[zeroIndexedWordStart]) === -1) {
197+
return { suggestions: [] };
198+
}
195199

196200
return {
197201
suggestions: suggestionProvider.provideResults(query).map(result => {

src/vs/workbench/contrib/extensions/common/extensionQuery.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ export class Query {
1212
}
1313

1414
static suggestions(query: string): string[] {
15-
const commands = ['installed', 'outdated', 'enabled', 'disabled', 'builtin', 'recommended', 'sort', 'category', 'tag', 'ext', 'id'];
15+
const commands = ['installed', 'outdated', 'enabled', 'disabled', 'builtin', 'recommended', 'sort', 'category', 'tag', 'ext', 'id'] as const;
1616
const subcommands = {
1717
'sort': ['installs', 'rating', 'name'],
1818
'category': ['"programming languages"', 'snippets', 'linters', 'themes', 'debuggers', 'formatters', 'keymaps', '"scm providers"', 'other', '"extension packs"', '"language packs"'],
1919
'tag': [''],
2020
'ext': [''],
2121
'id': ['']
22-
};
22+
} as const;
2323

24-
let queryContains = (substr: string) => query.indexOf(substr) > -1;
25-
let hasSort = subcommands.sort.some(subcommand => queryContains(`@sort:${subcommand}`));
26-
let hasCategory = subcommands.category.some(subcommand => queryContains(`@category:${subcommand}`));
24+
const queryContains = (substr: string) => query.indexOf(substr) > -1;
25+
const hasSort = subcommands.sort.some(subcommand => queryContains(`@sort:${subcommand}`));
26+
const hasCategory = subcommands.category.some(subcommand => queryContains(`@category:${subcommand}`));
2727

2828
return flatten(
2929
commands.map(command => {
3030
if (hasSort && command === 'sort' || hasCategory && command === 'category') {
3131
return [];
3232
}
33-
if ((subcommands as any)[command]) {
34-
return (subcommands as any)[command].map((subcommand: string) => `@${command}:${subcommand}${subcommand === '' ? '' : ' '}`);
33+
if (command in subcommands) {
34+
return (subcommands as Record<string, readonly string[]>)[command]
35+
.map(subcommand => `@${command}:${subcommand}${subcommand === '' ? '' : ' '}`);
3536
}
3637
else {
3738
return [`@${command} `];
3839
}
3940
}));
40-
4141
}
4242

4343
static parse(value: string): Query {

0 commit comments

Comments
 (0)