Skip to content

Commit e678c2e

Browse files
authored
don't filter available commands in the extension (microsoft#236101)
1 parent a690eb6 commit e678c2e

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

extensions/terminal-suggest/src/terminalSuggestMain.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ export async function getCompletionItemsFromSpecs(specs: Fig.Spec[], terminalCon
251251
const items: vscode.TerminalCompletionItem[] = [];
252252
let filesRequested = false;
253253
let foldersRequested = false;
254-
let specificSuggestionsProvided = false;
255254
const firstCommand = getFirstCommand(terminalContext.commandLine);
256255
for (const spec of specs) {
257256
const specLabels = getLabel(spec);
@@ -297,15 +296,13 @@ export async function getCompletionItemsFromSpecs(specs: Fig.Spec[], terminalCon
297296
if (!argsCompletions) {
298297
continue;
299298
}
300-
specificSuggestionsProvided = true;
301299
const argCompletions = argsCompletions.items;
302300
foldersRequested = foldersRequested || argsCompletions.foldersRequested;
303301
filesRequested = filesRequested || argsCompletions.filesRequested;
304302
let cwd: vscode.Uri | undefined;
305303
if (shellIntegrationCwd && (filesRequested || foldersRequested)) {
306304
cwd = await resolveCwdFromPrefix(prefix, shellIntegrationCwd) ?? shellIntegrationCwd;
307305
}
308-
specificSuggestionsProvided = argsCompletions.specificSuggestionsProvided;
309306
return { items: argCompletions, filesRequested, foldersRequested, cwd };
310307
}
311308
}
@@ -322,17 +319,17 @@ export async function getCompletionItemsFromSpecs(specs: Fig.Spec[], terminalCon
322319
continue;
323320
}
324321
items.push(...argsCompletions.items);
325-
specificSuggestionsProvided = argsCompletions.specificSuggestionsProvided;
326322
filesRequested = filesRequested || argsCompletions.filesRequested;
327323
foldersRequested = foldersRequested || argsCompletions.foldersRequested;
328324
}
329325
}
330326
}
331-
332-
if (!specificSuggestionsProvided && (filesRequested === foldersRequested)) {
327+
const shouldShowCommands = !terminalContext.commandLine.substring(0, terminalContext.cursorPosition).trimStart().includes(' ');
328+
if (shouldShowCommands && (filesRequested === foldersRequested)) {
333329
// Include builitin/available commands in the results
330+
const labels = new Set(items.map(i => i.label));
334331
for (const command of availableCommands) {
335-
if ((!terminalContext.commandLine.trim() || firstCommand && command.startsWith(firstCommand)) && !items.find(item => item.label === command)) {
332+
if (!labels.has(command)) {
336333
items.push(createCompletionItem(terminalContext.cursorPosition, prefix, command));
337334
}
338335
}
@@ -361,7 +358,7 @@ export async function getCompletionItemsFromSpecs(specs: Fig.Spec[], terminalCon
361358
return { items, filesRequested, foldersRequested, cwd };
362359
}
363360

364-
function getCompletionItemsFromArgs(args: Fig.SingleOrArray<Fig.Arg> | undefined, currentPrefix: string, terminalContext: { commandLine: string; cursorPosition: number }): { items: vscode.TerminalCompletionItem[]; filesRequested: boolean; foldersRequested: boolean; specificSuggestionsProvided: boolean } | undefined {
361+
function getCompletionItemsFromArgs(args: Fig.SingleOrArray<Fig.Arg> | undefined, currentPrefix: string, terminalContext: { commandLine: string; cursorPosition: number }): { items: vscode.TerminalCompletionItem[]; filesRequested: boolean; foldersRequested: boolean } | undefined {
365362
if (!args) {
366363
return;
367364
}
@@ -395,7 +392,7 @@ function getCompletionItemsFromArgs(args: Fig.SingleOrArray<Fig.Arg> | undefined
395392
continue;
396393
}
397394
if (!arg.isVariadic && twoWordsBefore === suggestionLabel && wordBefore?.trim() === '') {
398-
return { items: [], filesRequested, foldersRequested, specificSuggestionsProvided: false };
395+
return { items: [], filesRequested, foldersRequested };
399396
}
400397
if (suggestionLabel && suggestionLabel.startsWith(currentPrefix.trim())) {
401398
const description = typeof suggestion !== 'string' ? suggestion.description : '';
@@ -404,11 +401,11 @@ function getCompletionItemsFromArgs(args: Fig.SingleOrArray<Fig.Arg> | undefined
404401
}
405402
}
406403
if (items.length) {
407-
return { items, filesRequested, foldersRequested, specificSuggestionsProvided: true };
404+
return { items, filesRequested, foldersRequested };
408405
}
409406
}
410407
}
411-
return { items, filesRequested, foldersRequested, specificSuggestionsProvided: false };
408+
return { items, filesRequested, foldersRequested };
412409
}
413410

414411
function osIsWindows(): boolean {

extensions/terminal-suggest/src/test/terminalSuggestMain.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function createCodeTestSpecs(executable: string): ITestSpec2[] {
5656
{ input: `${executable} |`, expectedCompletions: codeOptions },
5757
{ input: `${executable} --locale |`, expectedCompletions: localeOptions },
5858
{ input: `${executable} --diff |`, expectedResourceRequests: { type: 'files', cwd: testCwd } },
59-
{ input: `${executable} -di|`, expectedCompletions: codeOptions.filter(o => o.startsWith('di')), expectedResourceRequests: { type: 'both', cwd: testCwd } },
6059
{ input: `${executable} --diff ./file1 |`, expectedResourceRequests: { type: 'files', cwd: testCwd } },
6160
{ input: `${executable} --merge |`, expectedResourceRequests: { type: 'files', cwd: testCwd } },
6261
{ input: `${executable} --merge ./file1 ./file2 |`, expectedResourceRequests: { type: 'files', cwd: testCwd } },

0 commit comments

Comments
 (0)