Skip to content

Commit 14b1516

Browse files
authored
do not allow duplicate flags (#240292)
1 parent 00fc449 commit 14b1516

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

Diff for: extensions/terminal-suggest/src/terminalSuggestMain.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,17 @@ export async function collectCompletionItemResult(command: Command, parsedArgume
289289
if (!specArgs) {
290290
return { filesRequested, foldersRequested };
291291
}
292-
292+
const flagsToExclude = kind === vscode.TerminalCompletionItemKind.Flag ? parsedArguments?.passedOptions.map(option => option.name).flat() : undefined;
293293
if (Array.isArray(specArgs)) {
294294
for (const item of specArgs) {
295295
const suggestionLabels = getLabel(item);
296-
if (!suggestionLabels) {
296+
if (!suggestionLabels?.length) {
297297
continue;
298298
}
299299
for (const label of suggestionLabels) {
300+
if (flagsToExclude?.includes(label)) {
301+
continue;
302+
}
300303
items.push(
301304
createCompletionItem(
302305
terminalContext.cursorPosition,
@@ -311,6 +314,9 @@ export async function collectCompletionItemResult(command: Command, parsedArgume
311314
}
312315
} else {
313316
for (const [label, item] of Object.entries(specArgs)) {
317+
if (flagsToExclude?.includes(label)) {
318+
continue;
319+
}
314320
items.push(
315321
createCompletionItem(
316322
terminalContext.cursorPosition,
@@ -332,7 +338,7 @@ export async function collectCompletionItemResult(command: Command, parsedArgume
332338
await addSuggestions(parsedArguments.completionObj.subcommands, vscode.TerminalCompletionItemKind.Method);
333339
}
334340
if (parsedArguments.suggestionFlags & SuggestionFlag.Options) {
335-
await addSuggestions(parsedArguments.completionObj.options, vscode.TerminalCompletionItemKind.Flag);
341+
await addSuggestions(parsedArguments.completionObj.options, vscode.TerminalCompletionItemKind.Flag, parsedArguments);
336342
}
337343

338344
return { filesRequested, foldersRequested };

Diff for: extensions/terminal-suggest/src/test/completions/code.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export function createCodeTestSpecs(executable: string): ITestSpec[] {
4141
{ input: `${executable} --log |`, expectedCompletions: logOptions },
4242
{ input: `${executable} --sync |`, expectedCompletions: syncOptions },
4343
{ input: `${executable} --extensions-dir |`, expectedResourceRequests: { type: 'folders', cwd: testPaths.cwd } },
44-
{ input: `${executable} --list-extensions |`, expectedCompletions: codeSpecOptions, expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
45-
{ input: `${executable} --show-versions |`, expectedCompletions: codeSpecOptions, expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
44+
{ input: `${executable} --list-extensions |`, expectedCompletions: codeSpecOptions.filter(c => c !== '--list-extensions'), expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
45+
{ input: `${executable} --show-versions |`, expectedCompletions: codeSpecOptions.filter(c => c !== '--show-versions'), expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
4646
{ input: `${executable} --category |`, expectedCompletions: categoryOptions },
4747
{ input: `${executable} --category a|`, expectedCompletions: categoryOptions },
4848

Diff for: extensions/terminal-suggest/src/test/completions/upstream/ls.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ export const lsTestSuiteSpec: ISuiteSpec = {
7272
{ input: 'ls -a|', expectedCompletions: allOptions },
7373

7474
// Duplicate option
75-
// TODO: Duplicate options should not be presented https://github.com/microsoft/vscode/issues/239607
76-
// { input: 'ls -a -|', expectedCompletions: removeArrayEntry(allOptions, '-a'), expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
75+
{ input: 'ls -a -|', expectedCompletions: allOptions.filter(o => o !== '-a'), expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
7776

7877
// Relative paths
7978
{ input: 'ls c|', expectedCompletions: allOptions, expectedResourceRequests: { type: 'both', cwd: testPaths.cwd } },
@@ -89,3 +88,4 @@ export const lsTestSuiteSpec: ISuiteSpec = {
8988
{ input: 'ls ../sibling|', expectedCompletions: allOptions, expectedResourceRequests: { type: 'both', cwd: testPaths.cwdParent } },
9089
]
9190
};
91+

Diff for: extensions/terminal-suggest/src/test/fig.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ export const figGenericTestSuites: ISuiteSpec[] = [
9393
testSpecs: [
9494
{ input: 'foo |', expectedCompletions: ['--bar', '--baz'] },
9595
{ input: 'foo bar|', expectedCompletions: ['--bar', '--baz'] },
96-
// TODO: Duplicate options should not be presented https://github.com/microsoft/vscode/issues/239607
97-
// { input: 'foo --bar |', expectedCompletions: ['--baz'] },
98-
// { input: 'foo --baz |', expectedCompletions: ['--bar'] },
96+
{ input: 'foo --bar |', expectedCompletions: ['--baz'] },
97+
{ input: 'foo --baz |', expectedCompletions: ['--bar'] },
9998
]
10099
},
101100
{

0 commit comments

Comments
 (0)