PowerShell / PowerShell/PowerShell-RFC

RFC for ArgumentCompleter base class

Open
#270 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
467
Forks
140
Avg merge
9m
Merged PRs (30d)
1

Description

#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);
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the referenced issue #269 and the proposed ArgumentCompleter example in this RFC. Work through the requested common behaviors—quoting arguments, matching WordToComplete, and sorting results—and define the base-class API and completion semantics. Done means the RFC has a settled design for custom argument completers and consistent completion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.