Skip to content

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Apr 30, 2020

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
Member Author

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

@daxian-dbw daxian-dbw mentioned this pull request May 5, 2020
@lzybkr
Copy link
Contributor

lzybkr commented May 6, 2020

    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
Contributor

lzybkr commented May 6, 2020

    {

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)

@daxian-dbw
Copy link
Member Author

@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.

@daxian-dbw
Copy link
Member Author

daxian-dbw commented May 8, 2020

@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.

@daxian-dbw
Copy link
Member Author

daxian-dbw commented May 9, 2020

@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

@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
Member Author

@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
Copy link

nippyin commented Jul 15, 2020

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

@nippyin add it to your $profile

@nippyin
Copy link

nippyin commented Jul 15, 2020

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

@rkeithhill
Copy link
Contributor

rkeithhill commented Jul 15, 2020

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

nippyin commented Jul 15, 2020

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
Copy link
Contributor

rkeithhill commented Jul 16, 2020

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

musm commented Oct 14, 2020

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

@musm
Copy link

musm commented Oct 14, 2020

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

SSvilen commented Oct 23, 2020

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

@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