dotnet / dotnet/command-line-api

SymbolToComplete fails to detect correct symbol to complete when position is given

Open
#1,519 0 comments 0 reactions 0 assignees View on GitHub
Area-Completions
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

The following test cases fail:

```C#
[Fact]
public void Custom_Completion_Handler_Can_Parse_At_Position_BeforeBool()
{
var command = new CustomCompletionCommand("command")
{
new Argument("args")
};
var parser = new CommandLineBuilder(command).Build();
var completions = parser.Parse("command sub -b").GetCompletions(position: 12);

completions.Select(item => item.Label)
.Should()
.BeEquivalentTo("--str"); //actual "true", "false"
}

[Theory]
[InlineData("command sub --str")]
public void Custom_Completion_Handler_Can_Parse_At_Position_BeforeStr(string input)
{
var command = new CustomCompletionCommand("command")
{
new Argument("args")
};
var parser = new CommandLineBuilder(command).Build();
var completions = parser.Parse(input).GetCompletions(position: 12);

completions.Select(item => item.Label)
.Should()
.BeEquivalentTo("-b"); //actual: empty
}

private class CustomCompletionCommand : Command
{
public CustomCompletionCommand(string name, string description = null)
: base(name, description)
{
}

public override IEnumerable GetCompletions(CompletionContext context)
{
Command sub = new Command("sub");
Option str = new Option("--str");
Option b = new Option("-b");
sub.AddOption(str);
sub.AddOption(b);
this.AddCommand(sub);

var parser = new CommandLineBuilder(this).Build();
TextCompletionContext textCompletionContext = context as TextCompletionContext;
return parser.Parse(textCompletionContext.CommandLineText).GetCompletions(textCompletionContext.CursorPosition);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.