Skip to content

CompleteInput: Add Ability to find the command associated with a parameter #25796

@JustinGrote

Description

@JustinGrote

Summary of the new feature / enhancement

Story

As a PowerShell tool developer, I want to determine what command is associated with a parameter found via CompleteInput, so I can resolve and display the help for that parameter in intellisense

For example, in the PowerShell Extension for VSCode, I should be able to display the parameter help for Uri when hovered or in the tab completion info:

Image

Proposed technical implementation details (optional)

Problem

Currently, the AST logic that does completion input for parameters does not expose what command it found for the purposes of the parameter resolution, only the matching parameters.

if (firstSplatUse is not null && firstSplatUse.Parent is CommandAst command)
{
var binding = new PseudoParameterBinder()
.DoPseudoParameterBinding(
command,
pipeArgumentType: null,
paramAstAtCursor: null,
PseudoParameterBinder.BindingType.ParameterCompletion);
if (binding is null)
{
return null;
}
var results = new List<CompletionResult>();
foreach (var parameter in binding.UnboundParameters)
{
if (!excludedKeys.Contains(parameter.Parameter.Name)
&& (wordToComplete is null || parameter.Parameter.Name.StartsWith(wordToComplete, StringComparison.OrdinalIgnoreCase)))
{
results.Add(new CompletionResult(parameter.Parameter.Name, parameter.Parameter.Name, CompletionResultType.ParameterName, $"[{parameter.Parameter.Type.Name}]"));
}
}
if (results.Count > 0)
{
return results;
}
}

There are several code paths where parameter resolution occurs, pretty much wherever PseudoParameterBinding is present.

var binding = new PseudoParameterBinder().DoPseudoParameterBinding(commandAst, null, null, bindingType: PseudoParameterBinder.BindingType.ArgumentCompletion);

Suggested Implementation

Add a out CommandAst? boundCommand argument for SMA.CommandCompletion.CompleteInput that allows specification of an argument that will output a CommandAst of the bound command if the completion was a parameter completion. Update existing CompleteInput overrides to call this method, ignoring the boundcommand parameter. This keeps the API binary compatible.

I'm willing to PR the changes.

NOTE: This change would be complimentary to #25108, to be able to look up command help separately and provide a help link to the bound command in addition to what the tooltip help provides.

CC @MartinGC94 @jborean93 @andyleejordan for feedback or alternate implementation suggestions.

The biggest issue I see is that PSES/etc. would have to either use reflection or ship a separate 7.Next binary to use this feature in the near term.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.WG-Interactive-Consolethe console experienceWG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions