You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there are ways to register a scriptblock as a completer with Register-ArgumentCompleter, and on cmdlets it's possible to use the [ArgumentCompleter()] attribute to specify an IArgumentCompleter for a parameter. But there's no way to specify a completer for an ordinary command that I know of that doesn't involve executing a scriptblock.
By this I mean, you can use Register-ArgumentCompleter or you can use override TabCompletion2, but I'd really like a nicer hook for:
I'd love to see more ways of extending completion! One of the biggest things that's always stopped me from working on anything to extend general completion is that it's all or nothing. If you override TabExpansion2, then anyone else trying to do the same will completely override you. I'd love to see something like an interface that can be registered in the engine to incrementally augment completion. Something like:
publicinterfaceICompletionExtension{IEnumerable<CompletionResult>CompleteComment(CompletionContextcontext);IEnumerable<CompletionResult>CompleteMember(CompletionContextcontext);IEnumerable<CompletionResult>CompleteCommandParameter(CompletionContextcontext);IEnumerable<CompletionResult>CompleteCommandArgument(CompletionContextcontext);// Other cherry picked methods from CompletionCompleters/CompletionAnalysis here.}publicclassCompletionEngine{publicvoidRegisterCompletionExtension(ICompletionExtensionextension);publicvoidUnregisterCompletionExtension(ICompletionExtensionextension);// Mirroring CommandCompletion.CompleteInputpublicCommandCompletionCompleteInput(Astast,Token[]tokens,IScriptPositionpositionOfCursor,Hashtableoptions);}publicpartialclassEngineIntrinsics{publicCompletionEngineCompletion{get;}}
Reacted by Rain Sallow (/u/ta11ow), Rob Holt, Flavien MICHALECZEK, Keith Hill and __
Thinking more about the request I believe it is an edge case. Can you show other use cases (besides UnixCompleters)?
If we compare PowerShell and Bash design both do the some - register a script for completion of a command. So who else would need a rapper like UnixCompleters?
Keith Hill (@rkeithhill) I want to see examples. I only see UnixCompleters scenario and it is very specific, edge scenario. PowerShell already implement completions and API for customizations. We need to be sensitive to what exactly we need to add if necessary.
Ilya (@iSazonov) that's gonna be hard to show. Any time I've had a similar idea I've thrown it away once I got to the "oh I have to make 100 script block wrappers" step because it felt real dirty.
Also probably wouldn't be too hard to add. Might be able to get away with switching the internal dictionary to store Func<string, CommandAst, int, object> and generating a thin wrapper delegate around registered script blocks.
I also feel that sometimes it is convenient for authors of binary modules to write a completer on C# than a script block.
For them, we could enhance the Register-ArgumentCompleter cmdlet and allow registering code that implements a new interface.
Still requires running a pipeline though. That's too slow for something executed in a profile or for many commands. We need a lightweight registration mechanism that doesn't require a runspace, the pipeline thread or parameter binding.
Activity
SeeminglyScience commentedon Oct 7, 2019
I'd love to see more ways of extending completion! One of the biggest things that's always stopped me from working on anything to extend general completion is that it's all or nothing. If you override
TabExpansion2, then anyone else trying to do the same will completely override you. I'd love to see something like an interface that can be registered in the engine to incrementally augment completion. Something like:iSazonov commentedon Oct 9, 2019
I hope we combine this in one engine with #10741.
iSazonov commentedon Jul 29, 2020
Thinking more about the request I believe it is an edge case. Can you show other use cases (besides UnixCompleters)?
If we compare PowerShell and Bash design both do the some - register a script for completion of a command. So who else would need a rapper like UnixCompleters?
rkeithhill commentedon Aug 1, 2020
Ilya (@iSazonov) Wouldn't this feature apply to any completions that someone wants to implement in a binary (C#-based) module?
iSazonov commentedon Aug 2, 2020
Keith Hill (@rkeithhill) I want to see examples. I only see UnixCompleters scenario and it is very specific, edge scenario. PowerShell already implement completions and API for customizations. We need to be sensitive to what exactly we need to add if necessary.
SeeminglyScience commentedon Aug 2, 2020
Ilya (@iSazonov) that's gonna be hard to show. Any time I've had a similar idea I've thrown it away once I got to the "oh I have to make 100 script block wrappers" step because it felt real dirty.
SeeminglyScience commentedon Aug 2, 2020
Also probably wouldn't be too hard to add. Might be able to get away with switching the internal dictionary to store
Func<string, CommandAst, int, object>and generating a thin wrapper delegate around registered script blocks.iSazonov commentedon Aug 2, 2020
On the other hand, small and simple scripts can be more attractive (easy to write, easy to debug) than one huge script or code.
SeeminglyScience commentedon Aug 2, 2020
Yeah for sure it can be. Sometimes code is complicated though 🤷
iSazonov commentedon Aug 3, 2020
Thanks for confirmation my thoughts.
I also feel that sometimes it is convenient for authors of binary modules to write a completer on C# than a script block.
For them, we could enhance the Register-ArgumentCompleter cmdlet and allow registering code that implements a new interface.
rjmholt commentedon Aug 3, 2020
Still requires running a pipeline though. That's too slow for something executed in a profile or for many commands. We need a lightweight registration mechanism that doesn't require a runspace, the pipeline thread or parameter binding.
iSazonov commentedon Aug 3, 2020
If you agreed that the cmdlet could register a binary completer our next step would be to recognize the need to add new public API to do this.
rjmholt commentedon Aug 3, 2020
Oh, yes, absolutely;
Register-ArgumentCompletershould support a parameter set that takes a completer object instead of a ScriptBlockiSazonov commentedon Aug 4, 2020
So we could discuss follow signatures:
microsoft-github-policy-service commentedon Nov 16, 2023
microsoft-github-policy-service commentedon Nov 16, 2023
microsoft-github-policy-service commentedon Nov 23, 2023