dotnet / dotnet/command-line-api

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

Aperta
#2,242 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Area-Completions
Lingua principale
C#
Stelle
3.7k
Fork
428
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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("--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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia in CompletionAction, nella chiamata di parse che usa RootCommandResult.Command.Parse, e confronta il comportamento per [suggest:1] e [suggest:2]. Riproduci l’esempio con l’alias `t` e verifica quale comando riceve GetCompletions. È completato quando [suggest:1] "t" include sia `test-log-levels` sia `test-log-colors`, mentre [suggest:2] "t" continua a fornire i completamenti specifici del comando.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
cli
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
43/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.