mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: infinite loop when argument is given when spec doesn't have an argument (#113)
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -266,5 +266,10 @@ const runSubcommand = async (
|
||||
return; // not subcommand or option & no args exist
|
||||
}
|
||||
|
||||
return runArg(tokens, getArgs(subcommand.args), subcommand, allOptions, acceptedTokens, false, false);
|
||||
const args = getArgs(subcommand.args);
|
||||
if (args.length != 0) {
|
||||
return runArg(tokens, args, subcommand, allOptions, acceptedTokens, false, false);
|
||||
}
|
||||
// if the subcommand has no args specified, fallback to the subcommand and ignore this item
|
||||
return runSubcommand(tokens.slice(1), subcommand, persistentOptions, acceptedTokens.concat(activeToken));
|
||||
};
|
||||
|
||||
@@ -432,6 +432,44 @@ exports[`parseCommand loadSpec 1`] = `
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`parseCommand noArgsArgumentGiven 1`] = `
|
||||
{
|
||||
"charactersToDrop": 0,
|
||||
"suggestions": [
|
||||
{
|
||||
"allNames": [
|
||||
"--analyzer-output",
|
||||
],
|
||||
"description": "Static analyzer report output format",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "--analyzer-output",
|
||||
"priority": 50,
|
||||
},
|
||||
{
|
||||
"allNames": [
|
||||
"--analyze",
|
||||
],
|
||||
"description": "Run the static analyzer",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "--analyze",
|
||||
"priority": 50,
|
||||
},
|
||||
{
|
||||
"allNames": [
|
||||
"-arcmt-migrate-emit-errors",
|
||||
],
|
||||
"description": "Emit ARC errors even if the migrator can fix them",
|
||||
"icon": "🔗",
|
||||
"insertValue": undefined,
|
||||
"name": "-arcmt-migrate-emit-errors",
|
||||
"priority": 50,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`parseCommand noOptionsSuggestedAfterVariadicArg 1`] = `
|
||||
{
|
||||
"argumentDescription": undefined,
|
||||
|
||||
@@ -18,13 +18,17 @@ const testData = [
|
||||
{ name: "command", command: "sudo git sta" },
|
||||
{ name: "nestedNonCommands", command: "az az ", skip: true }, // TODO: fix skipped test
|
||||
{ name: "loadSpec", command: "aws acm add" },
|
||||
{ name: "noArgsArgumentGiven", command: "gcc lab ", maxSuggestions: 3 },
|
||||
];
|
||||
|
||||
describe(`parseCommand`, () => {
|
||||
testData.forEach(({ command, name, skip }) => {
|
||||
testData.forEach(({ command, name, skip, maxSuggestions }) => {
|
||||
if (skip) return;
|
||||
test(name, async () => {
|
||||
const suggestions = await getSuggestions(command);
|
||||
if (suggestions != null && suggestions.suggestions != null) {
|
||||
suggestions.suggestions = suggestions?.suggestions.slice(0, maxSuggestions);
|
||||
}
|
||||
expect(suggestions).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user