PowerShell / PowerShell/PowerShell-RFC
RFC for ArgumentCompleter base class
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- PowerShell
- Star
- 467
- Fork
- 140
- Merge trung bình
- 9 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
#269
Provide a base class, ArgumentCompleter, to simplify writing custom argument completers
Some common tasks need to be done almost every time a completer is written.
Things like quoting arguments if they contain spaces, matching against WordToComplete, and ensuring that the results are sorted is another such task.
Motivation
As a Developer,
I can use the base class when writing custom argument completers,
so that results are achieved faster, with high quality, and
so that users get a consistent completion experience.
User Experience
using namespace System.Management.Automation;
public class GetCommitCompleter : ArgumentCompleter
{
// override simplified completer
protected override CompletionResultSortKind AddCompletionsFor(string commandName, string parameterName, IDictionary fakeBoundParameters)
{
switch (parameterName)
{
case nameof(GitRebaseCommand.CommitHash):
CompleteGitCommitHash();
break;
}
return CompletionResultSortKind.Sorted;
}
private void CompleteGitCommitHash()
{
var user = GetFakeBoundParameter<string>("User");
foreach(var commit in GitExe.Log())
{
if (user is { } u && commit.User != u){
continue;
}
// use a function to complete if the text or tooltip matches WordToComplete
CompleteMatching(text: commit.Hash, tooltip: $"{commit.User}\r\n{commit.Description}}": CompletionMatch.AnyContainsWithWordToComplete);
}
}
}
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.
Hướng nghiên cứu
Bắt đầu bằng cách đọc issue được tham chiếu #269 và ví dụ ArgumentCompleter được đề xuất trong RFC này. Xem xét các hành vi chung được yêu cầu—đặt đối số trong dấu ngoặc kép, khớp với WordToComplete và sắp xếp kết quả—rồi xác định API của lớp cơ sở và ngữ nghĩa hoàn thành. Công việc được xem là hoàn tất khi RFC có thiết kế đã được thống nhất cho các ArgumentCompleter tùy chỉnh và hành vi hoàn thành nhất quán.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell
- Lĩnh vực
- cli
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100