question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give more completion context info to argument completers

See original GitHub issue

Summary of the new feature/enhancement

Argument completers get the following parameters: $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters

This is great but I would like to also get: $cursorPosition, ref $replacementLength, ref $replacementIndex
This will enable completion for substrings, like the string you provide to the Filter parameter for Get-CimInstance.

Example: Get-CimInstance Win32_Process -Filter "Name = 'pwsh.exe'"
If my cursor is in the “Name” area my argument completer would show Win32_Process properties and if my cursor is in the “=” area it would show operators.

If you want to do this today you either have to assume the cursor is always at the end of the line or just show all possible options with no regard for the cursor position.

Proposed technical implementation details (optional)

Add the cursorPosition parameter to the list of parameters given to argument completers and if passing objects by reference is possible do that for replacementLength and replacementIndex.
If it’s not possible to set the replacement length/index from the argument completer then argument completers will just have to keep that in mind and use the whole string as a completion result.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
SeeminglySciencecommented, Jun 3, 2021

I think that example is fine because script block doesn’t have cmdletBinding specified.

With the way that the scriptblock is called (ScriptBlock.Invoke), CmdletBinding is ignored. Shouldn’t be an issue.

2reactions
powercodecommented, May 25, 2021

I think we would need to add a new interface IArgumentCompeleter2 with the required methods.

The engine would first check for the new interface and fall back to the old.

Read more comments on GitHub >

github_iconTop Results From Across the Web

About functions argument completion - PowerShell
An argument completer allows you to provide dynamic tab completion, at run time for any command that you specify. For more information, see ......
Read more >
Completing Parameter Values With Other ... - Rohn's Blog
It turns out, this is pretty simple with argument completers using PSv5+ (you can do this in PSv3+, but you'll want to take...
Read more >
Argument Completion Attributes - powershell.one
Enable argument completion for your own function parameters and make them so much easier to use! Some lesser-known attributes can help you.
Read more >
Getting the default argument completion values in ...
I am trying to extend the default argument completion i get when pressing CTRL+SPACE, so that the tool-tip line at the very bottom...
Read more >
Add a way to lazily autoload argument completers #17283
This implementation has an issue where if the module is large (slow to load), there may be a considerable delay before the completions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found