command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

CompletionAction doesn't display all possible matches when the commandline matches a command name or alias

Open seanadams9 opened this issue 2 years ago • 1 comments

Tab completions are wrong when the command line text matches a command name or alias. With a cli with a lot commands/aliases this makes tab completion painful because you might hit an alias and then it doesn't go through other commands.

CompletionAction runs this parse:

        var completionParseResult = parseResult.RootCommandResult.Command.Parse(commandLineToComplete, parseResult.Configuration);

If it matches a command or alias, the completionParseResult is set to that command and GetCompletions is run jsut for that specific command.

Example below. When running [suggest:1] "t" I would expect it to show me "test-log-levels" and "test-log-colors" but it is just showing "--option1" which is also weird considering if it was the full completions for "t" it would be the following (what it displays with [suggest:2] "t")

--help
--option1
-?
-h
-o1
/?
/h
void Main()
{
	CliRootCommand cliRootCommand = new CliRootCommand();
	CliCommand command = new CliCommand("test-log-levels", "Show use of the different log levels by printing a log message at each level");
	command.Aliases.Add("t");
	command.Options.Add(new CliOption<bool>("--option1", "-o1"));
	CliCommand command2 = new CliCommand("test-log-colors", "Show use of the different log levels by printing a log message at each level");
	cliRootCommand.Subcommands.Add(command);
	cliRootCommand.Subcommands.Add(command2);

	string[] args = new string[] { "[suggest:1]",  "t"};
	var cliConfiguration = new CliConfiguration(cliRootCommand) { };
	
	var parseResult = cliConfiguration.Parse(args);
	int exitCode = parseResult.InvokeAsync().Result;
}

Planning to look into this a bit more, initial thoughts is the parsing for suggest should be different, "t" with position 1 it shouldn't just parse to the specific command, "t" position 2 should though since there is a space after.

seanadams9 avatar Jul 21 '23 22:07 seanadams9

@jonsequitur following up here, this bug is making for a painful tab completion experience for our CLI. I dug in a little bit but couldn't find anything obvious aside from the parsing logic when running the suggest directions needs to be reworked.

seanadams9 avatar Aug 17 '23 21:08 seanadams9