Skip to content

Predictive IntelliSense #1468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
theJasonHelmick opened this issue Apr 13, 2020 · 15 comments
Closed

Predictive IntelliSense #1468

theJasonHelmick opened this issue Apr 13, 2020 · 15 comments
Assignees
Labels

Comments

@theJasonHelmick
Copy link
Collaborator

Reference issue: RFC#687

Predictive IntelliSense is an addition to the interactive experience to assist in command discovery
and accelerate full command execution. This enables new and experienced users of PowerShell to
discover, edit, and execute full commands based on matching predictions from the users history or
additional provider.

pi-static

Tab Completion has accelerated the success of both new and experienced PowerShell users. New users get the benefit of discovery; seeing available cmdlets and parameters as options while interactively typing. Experienced users receive the benefit of acceleration; typing less while using the key to quickly complete a command.

The increasing amount of technology translates to an increase in cmdlets and full command
complexity. Predictive IntelliSense is an addition to the concept of Tab Completion; helping the
user discover, build and edit full commands based on the users history or additional plugins.

The proposal is to add Predictive IntelliSense and enhancements for MenuComplete/Dynamic Help to the users interactive experience.

Predictive IntelliSense Protoype maybe found on PSGallery.

Proposed technical implementation details

  1. Predictive IntelliSense displays a best match command completion from command history. The
    prediction may change if a better match is found as the user types additional information. The
    predicted command may be accepted, edited, or ignored. It may be possible to support additional
    predictive providers.

pi-static

  1. Predictions are searchable and may be edited. Additional key bindings may be added to the users
    Profile as in the example below:
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete
Set-PSReadLineKeyHandler -Key "Ctrl+f" -Function ForwardWord
Set-PSReadLineKeyHandler -Key "Ctrl+b" -Function BackwardWord
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
  1. Predictions are searchable based on the current cursor position.
  • Searching history from cmdlet verb.

pi-arrow-verb

  • Searching histroy from cmdlet noun.

pi-arrow-Noun

  • Searching history from parameter.

pi-arrow-param

  1. Predictions may be edited by stepping-through the parameters and arguments.
  • Moving forward and backward using additional key bindings.

pi-fb

  • Note: Changing the parameter/argument, changes the prediction.

pi-fb-arg

  1. MenuComplete/Dynamic Help is a current feature of PSReadLine. When combined with Predictive IntelliSense, MenuComplete provides additonal discovery and help information.
  • MenuComplete providing cmdlet discovery and help.

mc-noun2

  • MenuComplete providing parameter discovery and help.

mc-param

Open discussion items:

  • Should the number of lines displayed for MenuComplete be restricted and what should that
    restriction be?
  • Should an interactive cursor-based scroll bar for paging be included?
  • What should the content of Dynamic Help include?

mc-realestate

  1. Full cmdlet help is accessible using a key binding to access the help in a virtual terminal. An
    additional key binding will return the user from the virtual terminal to the previous screen.

dh-f1

  1. Predictive IntelliSense Accessibility is managed through the users profile.

pi-color

pi-color2

Set-PSReadLineOption -Colors @{ Prediction = '#8A0303'}
Set-PSReadLineOption -Colors @{ Prediction = '#2F7004'}

pi-color2-fb

Multiple color code values are supported currently in PSReadLine.

Examples of different color code values:

Set-PSReadLineOption -Colors @{ Prediction = 'DarkRed'}
 # Use a ConsoleColor enum
Set-PSReadLineOption -Colors @{ Prediction = [ConsoleColor]::DarkRed}
 # 24 bit color escape sequence
Set-PSReadLineOption -Colors @{ Prediction = "$([char]0x1b)[38;5;100m"}
 # RGB value
Set-PSReadLineOption -Colors @{ Prediction = "#8181f7"}
  1. Predictive IntelliSense Extensibility

It may be possible to support 1st party and 3rd party predictive plugins.

@theJasonHelmick theJasonHelmick added the Issue-Enhancement It's a feature request. label Apr 13, 2020
@ghost ghost added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Apr 13, 2020
@TylerLeonhardt
Copy link
Member

I'd also love to see proposed PowerShell API additions so that this isn't a shell-only feature. Something like this would be really nice in editors as well, for example.

@Windos
Copy link

Windos commented Apr 13, 2020

What should the content of Dynamic Help include?

For cmdlets/functions it should show the synopsis. Syntax sounds helpful, but on bigger commands with lots of parameters and parameter sets it's... unwieldy.

For parameters it should should show the helpmessage, that normally only surfaces at the mandatory prompt when you type !?

Predictive IntelliSense Extensibility

I want to have this available in VS Code.

As a module author, I want to be able to inject common use cases for my modules' functions.

@bergmeister
Copy link
Contributor

Predictions should also be based on the current working directory. Example: In some local repos I might do a git pull origin master but in others I do a git pull origin develop

@sheldonhull
Copy link

This is amazing. Subscribed. I posted in the slack channel for vscode asking what magical vodoo was happening, as I had never seen this and it felt like such a natural thing to have. Didn't realize it got rolled out with the insiders powershell extension. Looking forward to the improvements. #win

@p0W3RH311
Copy link

p0W3RH311 commented Apr 14, 2020

it's work on non VT ?

@TylerLeonhardt
Copy link
Member

One other thing about the Dynamic Help feature... the PowerShell extension has been providing this experience for a while (see the box on the right):

image

It's called the completionItem/resolve request as a part of the language server protocol.

The idea here is... for a completion, give me more details about it... but only send the request for more details when it is highlighted.

However, the PowerShell extension goes a step further to provide syntax as you're typing parameters too:

image

VS Code decided it was a good idea to separate this into it's own request called the Signature Help Request.

There are a lot of learning from the PowerShell extension and LSP that can be leveraged in the design of the features outlined here. Please consider them in the design.

@daxian-dbw daxian-dbw removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Apr 20, 2020
@jszabo98
Copy link

jszabo98 commented May 5, 2020

This is pretty cool. The first thing I do in my $profile is

set-psreadlineoption -editmode emacs

so that pressing tab lists all the choices at once.

@IarwainBen-adar
Copy link

I just upgraded to the prerelease version of PSReadLine and I see real potential for this feature. As it is now, though, I find the history-biased suggestions a bit frustrating. Consider this scenario:

  • current working directory is c:\foo\bar\baz
  • at some point in the past, I have entered the command cd ..\qux
  • unfortunately, c:\foo\bar has no subdirectory named qux
  • nevertheless, while sitting at c:\foo\bar\baz, as soon as I type cd .. a ghostly \qux is suggested to me — a completely invalid path

Overall this seems far less useful than it would be if it were suggesting valid completions of the partially-typed command line. I'm fairly new to PSReadLine, so I'm sorry if this is a naive question, but is it possible to configure this behavior? Or to validate potential completions before suggesting them (and then not suggest invalid completions at all)?

@brunovieira97
Copy link

I just upgraded to the prerelease version of PSReadLine and I see real potential for this feature. As it is now, though, I find the history-biased suggestions a bit frustrating. Consider this scenario:

  • current working directory is c:\foo\bar\baz
  • at some point in the past, I have entered the command cd ..\qux
  • unfortunately, c:\foo\bar has no subdirectory named qux
  • nevertheless, while sitting at c:\foo\bar\baz, as soon as I type cd .. a ghostly \qux is suggested to me — a completely invalid path

Overall this seems far less useful than it would be if it were suggesting valid completions of the partially-typed command line. I'm fairly new to PSReadLine, so I'm sorry if this is a naive question, but is it possible to configure this behavior? Or to validate potential completions before suggesting them (and then not suggest invalid completions at all)?

AFAIK this happens because, currently, the only prediction source available is the commands history. Since it's a WIP, there's room for improvement, and probably the first would be to get history entries and then only let through (to the user) the ones that really would apply to his current terminal state (directory, Git repo, etc).

@rdhar
Copy link

rdhar commented Dec 29, 2020

Looking at #687, it looks like some progress has been made with the following:

# Search auto-completion from history
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

# Show auto-complete predictions from history
Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource history
Get-PSReadLineOption | ForEach-Object predictionsource

That said, still nowhere near as feature-rich as PowerShell's VS Code extension.

@theJasonHelmick
Copy link
Collaborator Author

This feature, along with Dynamic Help, is currently in PSReadLine 2.2.0-beta4 and is available on the Powershell Gallery. Please file issues for feedback in the PSReadLine repository.

Predictive IntelliSense is planned to ship GA in January 2022.

@ToxicSmurf
Copy link

Sorry but how do I turn this off?

@gwitsch
Copy link

gwitsch commented Nov 22, 2022

How can i turn this off?

@gwitsch
Copy link

gwitsch commented Nov 22, 2022

Found the solution to disable it here:
https://devblogs.microsoft.com/powershell/announcing-psreadline-2-1-with-predictive-intellisense/?WT.mc_id=-blog-scottha

Running this command, disabled it
Set-PSReadLineOption -PredictionSource None

The trick to set the option for all new terminals, was to update the PowerShell profile.
First type notepad $PROFILE in the terminal and then add the following content to the opened file:

Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource None

Save the file and reopen the terminal to verify the option.

@jiasli
Copy link

jiasli commented May 17, 2023

@gwitsch, thanks for the information. It is super helpful.

Apparently, not everyone likes InlineView for -PredictionViewStyle (see this reddit post). Personally, I find it distracting and prefer ListView.

However, instead of totally disabling Predictive IntelliSense using Set-PSReadLineOption -PredictionSource None, is it possible to keep its functionality but not automatically show the suggestions (both InlineView and ListView)? In that case, I can manually trigger the ListView with some sort of shortcut, such as F2(SwitchPredictionView). I currently use F8 (HistorySearchBackward) but it is apparently not as fancy as Predictive IntelliSense ListView.

Most IDEs support turning suggestions off.

PyCharm:

image

VS Code: https://code.visualstudio.com/docs/editor/intellisense#_settings

SeryiBaran added a commit to SeryiBaran/win-configs that referenced this issue Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests