mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: showing option suggestions after variadic arg (#118)
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -65,7 +65,7 @@ const lex = (command: string): CommandToken[] => {
|
||||
tokens.push({
|
||||
token: command.slice(readingIdx),
|
||||
complete: false,
|
||||
isOption: false,
|
||||
isOption: readingFlag,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ export const getArgDrivenRecommendation = async (
|
||||
...(await templateSuggestions(args[0].template, activeArg?.filterStrategy, partialCmd)),
|
||||
];
|
||||
|
||||
if ((activeArg.isOptional && !activeArg.isVariadic) || (activeArg.isVariadic && activeArg.isOptional && !variadicArgBound)) {
|
||||
if (activeArg.isOptional || (activeArg.isVariadic && variadicArgBound)) {
|
||||
suggestions.push(...subcommandSuggestions(subcommand.subcommands, activeArg?.filterStrategy, partialCmd));
|
||||
suggestions.push(...optionSuggestions(allOptions, acceptedTokens, activeArg?.filterStrategy, partialCmd));
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ exports[`parseCommand cmd -f 1`] = `
|
||||
},
|
||||
{
|
||||
"complete": false,
|
||||
"isOption": false,
|
||||
"isOption": true,
|
||||
"token": "-f",
|
||||
},
|
||||
]
|
||||
@@ -194,7 +194,7 @@ exports[`parseCommand cmd -f 2`] = `
|
||||
},
|
||||
{
|
||||
"complete": false,
|
||||
"isOption": false,
|
||||
"isOption": true,
|
||||
"token": "-f",
|
||||
},
|
||||
]
|
||||
@@ -329,3 +329,18 @@ exports[`parseCommand cmd1 | cmd2 1`] = `
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`parseCommand cmd1 - 1`] = `
|
||||
[
|
||||
{
|
||||
"complete": true,
|
||||
"isOption": false,
|
||||
"token": "cmd1",
|
||||
},
|
||||
{
|
||||
"complete": false,
|
||||
"isOption": true,
|
||||
"token": "-",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -470,11 +470,49 @@ exports[`parseCommand noArgsArgumentGiven 1`] = `
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`parseCommand noOptionsSuggestedAfterVariadicArg 1`] = `
|
||||
exports[`parseCommand noOptionsSuggestedDuringVariadicArg 1`] = `
|
||||
{
|
||||
"charactersToDrop": 3,
|
||||
"suggestions": [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`parseCommand optionsSuggestedAfterVariadicArg 1`] = `
|
||||
{
|
||||
"argumentDescription": undefined,
|
||||
"charactersToDrop": 1,
|
||||
"suggestions": [],
|
||||
"suggestions": [
|
||||
{
|
||||
"allNames": [
|
||||
"-@",
|
||||
],
|
||||
"description": "Display extended attribute keys and sizes in long (-l) output",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "-@",
|
||||
"priority": 50,
|
||||
},
|
||||
{
|
||||
"allNames": [
|
||||
"-1",
|
||||
],
|
||||
"description": "(The numeric digit \`\`one''.) Force output to be one entry per line. This is the default when output is not to a terminal",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "-1",
|
||||
"priority": 50,
|
||||
},
|
||||
{
|
||||
"allNames": [
|
||||
"-A",
|
||||
],
|
||||
"description": "List all entries except for . and ... Always set for the super-user",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "-A",
|
||||
"priority": 50,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ const testData = [
|
||||
{ command: `cmd "value' ` },
|
||||
{ command: `cmd "value'\\"\\"" ` },
|
||||
{ command: `cmd1 | cmd2 ` },
|
||||
{ command: `cmd1 -` },
|
||||
];
|
||||
|
||||
describe(`parseCommand`, () => {
|
||||
|
||||
@@ -12,7 +12,8 @@ const testData = [
|
||||
{ name: "exclusiveOnOption", command: "ag --affinity --no" },
|
||||
{ name: "providedSuggestion", command: "bw completion --shell " },
|
||||
{ name: "fullyTypedSuggestion", command: "ls -W" },
|
||||
{ name: "noOptionsSuggestedAfterVariadicArg", command: "ls item -" },
|
||||
{ name: "optionsSuggestedAfterVariadicArg", command: "ls item -", maxSuggestions: 3 },
|
||||
{ name: "noOptionsSuggestedDuringVariadicArg", command: "ls -W ite" },
|
||||
{ name: "providedArgDescription", command: "act completion bash -a " },
|
||||
{ name: "completedOptionWithArg", command: "act completion bash -a 'actor' " },
|
||||
{ name: "command", command: "sudo git sta" },
|
||||
|
||||
Reference in New Issue
Block a user