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.

Adding Predictive IntelliSense to PowerShell VSCode Extension

See original GitHub issue

Adding Predictive IntelliSense to PowerShell VSCode Extension

Summary of new feature

Predictive IntelliSense is an addition to the concept of tab completion that assists the user in successfully completing commands. This enables new and experienced users of PowerShell to discover, edit, and execute full commands based on matching predictions from the users history and additional domain specific plugins such as Az.Tools.Predictor.

PowerShell users would benefit from predictions in VSCode Terminal (PowerShell Integrated Console) and Editor:

  • PowerShell users with previous cmdlet experience receive suggestions from history and additional plugins, accelerating the time to command completion. Historical predictions come from the users PSReadLine history of completed commands, allowing them to quickly accept the prediction.

  • PowerShell users without previous cmdlet experience receive guided suggestions from plugin predictors like Az.Tools.Predictor to help successfully complete the command. These plugins may provide a range of guided assistance in the form of complete commands or suggesting parameters and arguments.

Terminal

Terminal (PowerShell Integrated Console), should have the same features as PowerShell (shell) with predictions as described in this blog.

This includes InLineView and ListView for predictions, switchable with F2 key.

  • Example of InLineView in PowerShell Integrated Console:

Picture1

  • Example of ListView in PowerShell Integrated Console:

PowerShelt Integrated Console v2021 2 2

Editor

Displaying predictions in the editor could be similar to IntelliCode for Visual Studio described here.

When the user begins to type a cmdlet, a prediction using InLineView appears above other cmdlet names. A star indicates that the suggestion comes from a predictor, followed by the InLineView prediction, followed by the prediction source.

Editor1

After the cmdlet name, when the user types dash (-) to begin a parameter, the first suggestion pair (parameter and argument) is displayed along with the prediction source. As the user continues to type the next parameter with a dash, the next suggestion pair is displayed until the prediction is complete.

Editor2

In the above example, the Az.Tools.Predictor will suggest the parameter and argument based on:

  • Examples - Ml-based plugins may learn the most common uses of a cmdlet from documentation examples.
  • Reuse - If the parameter and argument pair has been previously typed within the current session, the predictor will supply the previously typed argument.
  • Syntax - If no examples or history is available, the predictor will display the parameter with the Object type for the argument.

Enabling/Disabling

Predictions are enabled and disabled using the Set-PSReadLineOption -PredictionSource <argument> and may be stored in the users profile. Accepted values for the argument are None, History, HistoryAndPlugin.

Configuring a predictor

Customizing prediction color, keybindings, and additional plugins is accomplished through PSReadLine Set-PSReadLineOption and Set-PSReadLineKeyHandler cmdlets. Custom settings may be stored in the users profile.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
daxian-dbwcommented, May 13, 2021

The static type CommandPrediction contains the APIs to obtain prediction results, see https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs#L53 But, to be honest, I’m not very confident how effective those APIs are aligned with the VSCode editor scenario. For the editor experience, it may be better for the prediction to not go through SMA at all, but work in a similar way as IntelliCode.

1reaction
TylerLeonhardtcommented, May 4, 2021

Yeah it is. Some extensions have “smart snippets” that are better than normal snippets because they can be context aware. Just have to add a CompletionItem to the list of Completions getting sent back to vscode.

whether you’re completing a whole line, or just a word, it doesn’t really matter. Details: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliSense in Visual Studio Code
IntelliSense. IntelliSense is a general term for various code editing features including: code completion, parameter info, quick info, and member lists.
Read more >
PSReadLine 2.2.6 enables Predictive Intellisense by default
Predictions are enabled by default. Previously, to enable predictions, customers were required to add the following to their PowerShell profile:
Read more >
5 Essential Features in VS Code for PowerShell | CBT Nuggets
One of the best features of VS Code is Intellisense, otherwise known as tab completion for other code editors. Intellisense is a tool...
Read more >
Adding Predictive IntelliSense to my Windows Terminal ...
I've long said You should be customizing your PowerShell Prompt with ...
Read more >
Optimizing Visual Studio Code for Powershell Development
I've used VSCode as my primary Powershell environment for over 3 years and have tried a lot of extensions and settings, and now...
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