CompletionSources not sorted properly when building HelpName default suggestions
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu tại dòng 142 của src/command-line-api/src/System.CommandLine/Option.cs và tái hiện thứ tự bằng mẫu CompletionItem trong issue. Theo dõi cách các giá trị CompletionContext rỗng và một phần được đưa vào quá trình sắp xếp, sau đó xác minh rằng các gợi ý trợ giúp và tính năng hoàn thành bằng tab tuân theo thứ tự được hiển thị trong issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The sorting logic done here when building the default help text from the list of completions is backward:
Since the ThenBy is on the Label, the resulting sorted collection is re-sorted by Label, as a primary order, not as a secondary order like SQL.
And, to hoist the current entry to the top of the list, the OrderBy needs to be OrderByDescending.
Here is an example that shows the bad behavior:
public static class Program
{
static CompletionItem[] sampleCompletions =
[
new ( "5", sortText: "05" ),
new ( "10", sortText: "10" ),
new ( "6", sortText: "06" ),
new ( "20", sortText: "10" ),
new ( "30", sortText: "30" )
];
public static async Task<int> Main ( string[] argv)
{
RootCommand root = new ( "example" );
Option<int> option = new ( "option" );
option.CompletionSources.Add ( static ctx => sampleCompletions );
root.Options.Add ( option );
await root.Parse ( [ "--help" ] ).InvokeAsync ( );
}
}
Output:
```text
Description:
example
Usage:
SnapsInAZfs [options]
Options:
option <10|20|30|5|6>
-?, -h, --help Show help and usage information
--version Show version information
Note the improperly ordered suggestions in the HelpName for option.
Here is why, isolated to what the line referenced at the top of the issue does:
CompletionContext theCompletionContext = CompletionContext.Empty;
IOrderedEnumerable<CompletionItem> improperlyOrdered = sampleCompletions
.OrderBy ( item => item.SortText.IndexOfCaseInsensitive ( theCompletionContext.WordToComplete ) )
.ThenBy ( item => item. Label, StringComparer.OrdinalIgnoreCase );
foreach ( CompletionItem c in improperlyOrdered )
{
Console.WriteLine ( c.Label );
}
Output:
10
20
30
5
6
Here is the fixed sorting code, as it applies to building HelpText (an empty context gets passed in):
IOrderedEnumerable<CompletionItem> properlyOrdered = sampleCompletions
.OrderByDescending ( item => item.Label.IndexOfCaseInsensitive ( theCompletionContext.WordToComplete ) )
.ThenBy ( item => item.SortText, StringComparer.OrdinalIgnoreCase );
foreach ( CompletionItem c in properlyOrdered )
{
Console.WriteLine ( c.Label );
}
Output:
5
6
10
20
30
And here is how it would look during tab completion, if the user had already entered "2" and then presses tab (simulated by giving it the "2" directly):
IOrderedEnumerable<CompletionItem> properlyOrderedWithPartialEntry = sampleCompletions
.OrderByDescending ( item => item.Label.IndexOfCaseInsensitive ( "2" ) )
.ThenBy ( item => item.SortText, StringComparer.OrdinalIgnoreCase );
foreach ( CompletionItem c in properlyOrderedWithPartialEntry )
{
Console.WriteLine ( c.Label );
}
Output:
20
5
6
10
30
The actual code to replace what is there now would be:
This is incorrect. See my follow-up comment that fixes it.
return completions
.OrderByDescending(item => item.Label.IndexOfCaseInsensitive(context.WordToComplete))
.ThenBy(symbol => symbol.SortText, StringComparer.OrdinalIgnoreCase);
Also, it may be worth pointing out that the extension method IndexOfCaseInsensitive does not use the same StringComparer as the code here. It uses invariant culture. This uses ordinal. So the two sorts aren't the same, necessarily, even if the values are identical.
- Ngôn ngữ chính
- C#
- Star
- 3.7k
- Fork
- 434
- Merge trung bình
- 6 giờ 27 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/command-line-api
-
German localization is incompleteCó thể đã có người làm @b-v-d-e-v đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2852 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translatedCó thể đã có người làm @JPBlanc đã nhận 116 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2822 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2792 · 2 bình luận · 16 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Argument.Arity` modify internal state on first get access.Có thể đã có người làm @zjdangge đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2704 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
GetCompletions should check exit code of invoked applicationCó thể đã có người làm @baradgur đã nhận 1288 ngày trước. Đang mởArea-Completions bug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/command-line-api#2137 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/command-line-api
Issue tương tự
-
Format request: .wbpzĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
KnifeLemon/Filee#294 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
gavin-wolfe/wolfden#104 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Still libmicrohttpd dependency is not removed properly from External-Dependency-Info.txt fileĐang mởtype/bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:framework
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
nunit/docs#1262 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[辞書] かんそうりつ->乾燥率Đang mở辞書
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày