You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GetCompletions provides completions even when ParseResult has errors #1696
Currently, I have the issues fixing some of tab completion issues for reparsing in dotnet new as I'm not able to evaluate if current input is correct for given command or not while doing tab completion.
GetCompletions provides the result even when the string is surely wrong for given command
ParseResult.Errors contains error even when the string is a valid input for the command, but not yet complete.
varmyCommand=newCommand("new");varoption=newOption<string>("--test"){IsRequired=true,Arity=newArgumentArity(1,1)};option.FromAmong("val1","val2");myCommand.AddOption(option);varparseResult=myCommand.Parse($" new --lang a --test ");//this example has option --lang which is not definedvarcompletions=parseResult.GetCompletions();Assert.Empty(completions);//fails, completions have "val1", "val2"
Expectation is that completions are not returned as --lang a is already not a valid option. parseResult.Errors is not empty and have 3 errors:
▶ | [0] | {Required argument missing for option: '--test'.} |
▶ | [1] | {Unrecognized command or argument '--lang'.} |
▶ | [2] | {Unrecognized command or argument 'a'.} |
1 and 2 are expected, but not 0 as this option still may be completed.
varmyCommand=newCommand("new");varoption=newOption<string>("--test"){IsRequired=true,Arity=newArgumentArity(1,1)};option.FromAmong("val1","val2");myCommand.AddOption(option);varparseResult=myCommand.Parse($" new --test ");
parseResult.Errors is not empty, and has a following entry:
▶ | [0] | {Required argument missing for option: '--test'.} |
But the input is a valid input, just not completed. So error is not expected here.
Those scenarios are not allowing to make an decision whether the command line input is correct for a given command, and completions returned should be included to overall result.
changed the title [-]`GetCompletions` provides a completions even when `ParseResult` has errors[/-][+]`GetCompletions` provides completions even when `ParseResult` has errors[/+]on Mar 31, 2022
This is by design and pretty common. I would say the errors are correct, but do not indicate that the text is invalid for the purpose of completion. Completions are almost always calculated against invalid input in any language.
Tricks exist such as inserting virtual tokens in order to make a better guess at what the correct completion would be. Consider this broken C# code:
Activity
[-]`GetCompletions` provides a completions even when `ParseResult` has errors[/-][+]`GetCompletions` provides completions even when `ParseResult` has errors[/+]jonsequitur commentedon Mar 31, 2022
This is by design and pretty common. I would say the errors are correct, but do not indicate that the text is invalid
for the purpose of completion. Completions are almost always calculated against invalid input in any language.Tricks exist such as inserting virtual tokens in order to make a better guess at what the correct completion would be. Consider this broken C# code:
You can get correct completions on
"".subeven though there's noclassdeclaration.