Skip to content

Add basic support for inline predictive suggestion - #1496

Merged
Dongbo Wang (daxian-dbw) merged 6 commits into
PowerShell:masterfrom
daxian-dbw:fish
May 9, 2020
Merged

Dongbo Wang (daxian-dbw) merged 6 commits into
PowerShell:masterfrom
daxian-dbw:fish

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Apr 30, 2020 •

Copy link
Copy Markdown
Member

This PR is to merge the existing predictive suggestion changes to the master branch.
Changes were refactored and cleaned up. Also tests are added.

  • Currently, the only suggestion source is the PSReadLine history file.
  • By default, the suggestion text is rendered with the dark black color \x1b[38;5;238m, which works OK with a black background.
    You can change it by running Set-PSReadLineOption -Colors @{ Prediction = '<your-choice-of-color>' }
  • Parameter -PredictionSource is added to Set-PSReadLineOption, currently with the options None and History.
    The value is None by default, meaning that the predictive suggestion feature is disabled by default.
    A user can enable the prediction feature by set it to History. The feature cannot be enabled when the console output doesn't support VT.
  • Make AcceptSuggestion and AcceptNextSuggestionWord bindable.
  • Also fix System.ArgumentOutOfRangeException PSReadLine: 2.1.0-beta1 PowerShell: 7.1.0-preview.2 #1495
Microsoft Reviewers: Open in CodeFlow

@daxian-dbw

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) Steve Lee (@SteveL-MSFT) Gentle ping :) Please take a look when you have time. Thanks!

Comment thread docs/Set-PSReadLineOption.md Resolved
Comment thread docs/Set-PSReadLineOption.md Resolved
Comment thread docs/Set-PSReadLineOption.md Resolved
Comment thread PSReadLine/BasicEditing.cs Resolved
Comment thread PSReadLine/Changes.txt Resolved
Comment thread PSReadLine/Changes.txt Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Suggestion.cs Resolved
Comment thread PSReadLine/History.cs Resolved
Comment thread PSReadLine/PublicAPI.cs Resolved
Comment thread PSReadLine/PublicAPI.cs Resolved
Comment thread PSReadLine/Render.cs Resolved
Comment thread PSReadLine/Render.cs Resolved
Comment thread PSReadLine/Render.cs Resolved
@lzybkr

Copy link
Copy Markdown
Contributor
    private bool LineIsMultiLine()

Duplicate logic - you should just call your new function with _buffer as the parameter.


Refers to: PSReadLine/Render.cs:1211 in e876ffc. [](commit_id = e876ffc, deletion_comment = False)

@lzybkr

Copy link
Copy Markdown
Contributor
    {

Duplicate logic - just call your new function with _buffer as the first parameter.


Refers to: PSReadLine/Words.cs:92 in e876ffc. [](commit_id = e876ffc, deletion_comment = False)

Comment thread PSReadLine/Suggestion.cs Resolved
Comment thread PSReadLine/Words.cs Resolved
@daxian-dbw

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) I'm not sure what these 2 comments are referring to: #1496 (comment) #1496 (comment). Can you please clarify them a bit?

Other than that, I'm almost done addressing the comments, and will push the changes tomorrow.

Comment thread PSReadLine/Words.cs Resolved
@daxian-dbw

Dongbo Wang (daxian-dbw) commented May 8, 2020 •

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) I think I addressed all comments. A summary:

  1. Two settings are used: -PredictionSource and PredictionViewStyle
    PredictionSource -- options are None and History today;
    PredictionViewStyle -- option is Default only today.
  2. Make the predictive suggestion feature turned off by default (PredictionSource is none by default)
  3. Make AcceptSuggestion and AcceptNextSuggestionWord bindable.
  4. Refactor to use the existing patterns as well as avoid redundant logic.
  5. Add more tests.

Comment thread PSReadLine/BasicEditing.cs Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Cmdlets.cs Resolved
Comment thread PSReadLine/Render.cs Resolved
Comment thread PSReadLine/Suggestion.cs Resolved
Comment thread PSReadLine/Suggestion.cs Resolved
Comment thread PSReadLine/Suggestion.cs Resolved
@daxian-dbw

Dongbo Wang (daxian-dbw) commented May 9, 2020 •

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) All your comments are addressed. The refactoring changes to SelfInsert was separated out to #1510.
Summaries:

  1. PredictionViewStyle and its related code is removed until another view is implemented.
  2. Not support the predictive suggestion feature when the legacy console is in use.
  3. Ignore arg for AcceptSuggestion
  4. Removed LineIsMultiLine(string text)
  5. Renamed the field to _lastUserInput

@JustinGrote

Copy link
Copy Markdown

Dongbo Wang (@daxian-dbw) I had a question about this. There is the new AcceptSuggestion bind, but even if it is unbound, ForwardChar bound to rightarrow still does the completion. Is this intended or am I missing something?

@daxian-dbw

Copy link
Copy Markdown
Member Author

Justin Grote (@JustinGrote) The function ForwardChar has AcceptSuggestion built in, and similarly, ForwardWord has AcceptNextSuggestionWord built in.
The functions AcceptSuggestion and AcceptNextSuggestionWord are made public and bindable so as to allow users to use different key bindings to accept suggestion text.
For example, here is a sample to make RightArrow to accept next word instead the entire suggestion text.

@nippyin

Sandeep Sharma (nippyin) commented Jul 15, 2020 •

Copy link
Copy Markdown

When i run this command Set-PSReadLineOption -PredictionSource History. I expect following settings to be persistent. PredictionSource : History

However, after VScode restart or new instance launch this is again set to None.
image

@JustinGrote

Copy link
Copy Markdown

Sandeep Sharma (@nippyin) add it to your $profile

@nippyin

Copy link
Copy Markdown

Sandeep Sharma (@nippyin) add it to your $profile
Thanks Justin, can you share me the syntax please.

@rkeithhill

Keith Hill (rkeithhill) commented Jul 15, 2020 •

Copy link
Copy Markdown
Contributor

The syntax is the same - just put that command in your profile script located at this path $profile.CurrentUserAllHosts. Well, execute that to get the path. For me, that path is:

C:\Users\Keith\Documents\PowerShell\profile.ps1

It will be a bit different for you (different username at least).

If the file doesn't exist, create it. Then place this line in the file:

Set-PSReadLineOption -PredictionSource History

Now, whenever you start PowerShell, it will have this setting configured.

@nippyin

Copy link
Copy Markdown

he syntax is the same - j

this is nice, however is there VScode settings for this where we can set the parameter value as History? something similar to "powershell.codeFormatting.autoCorrectAliases": true

@rkeithhill

Keith Hill (rkeithhill) commented Jul 16, 2020 •

Copy link
Copy Markdown
Contributor

The above would apply to all PowerShell hosts including the VSCode terminal and PS Integrated Console. To be clear, this is PSReadLine module configuration - not specific to VSCode. That said, if for some reason you only want this setting configured in the PS Integrated Console in VSCode, then put the command in the PSIC's profile script: $HOME\Documents\PowerShell\Microsoft.VSCode_profile.ps1.

@musm

Copy link
Copy Markdown

This is a really nice feature, many thanks.

Is it not possible to have <tab> complete the suggested completion, instead of having to use the <right> arrow key?

@JustinGrote

Copy link
Copy Markdown

@musm

Mustafa Mohamad (musm) commented Oct 14, 2020 •

Copy link
Copy Markdown

Right now mine is set to Function yet that doesn't seem to want to complete predictive suggestions. Any chance you know why or which keybinding I need to change it to? The documentation isn't clear on this one.

It looks like you need to set AcceptSuggestion Is it possible to set the keybinding to frist try to AcceptSuggestion (f it exists) and if not do a Complete?

@SSvilen

Copy link
Copy Markdown

Hello,

I saw Jason Helmick showing PredictionViewStyle during the session with Jeffrey on Ignite, but I don't see that feature anywhere - even in the RC. Will this be implemented at all?

@JustinGrote

Copy link
Copy Markdown

Svilen (@SSvilen) my understanding is that it is on a private branch and will surface for 2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.ArgumentOutOfRangeException PSReadLine: 2.1.0-beta1 PowerShell: 7.1.0-preview.2

7 participants