-
Notifications
You must be signed in to change notification settings - Fork 319
Add the prediction ListView and also hook up with the CommandPrediction APIs introduced in PS 7.1
#1909
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
Conversation
theJasonHelmick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PM RFC #262 to reflect property and value changes, including keybindings, described here.
|
@SteveL-MSFT @PaulHigin and @iSazonov Thanks for the review! I addressed all comment except for the header to be used for new code in PSReadLine. Please take another look when you get a chance. |
PaulHigin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor comment.
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, how many does MSFT team want to support for Windows PowerShell? I mean polyfill.dll could be enhanced in separate repo and reused as nuget package.
|
@iSazonov The way |
I'm just wondering if PowerShell Polyfill will be a separate project so that other developer can benefit from it. |
That's sort of difficult to do well without also shipping the 7.1 version of the polyfill with 7.1 itself. Otherwise you'd either need a proxy assembly that registers the resolve event handler, or require the package consumer to set one up themselves. I think there is potentially a lot of value in shipping the It's worth discussing but probably out of scope for this PR. |
|
@SeeminglyScience @iSazonov We can use PSReadLine as an experiment to see how the |
… results; 2. Similarly, avoid refreshing suggestion results for `DigitArgument` binding, which only changes the status line, not the user input line; 3. Fix a bug -- `Ctrl+c` incorrectly triggers OnCommandLineAccepted; 4. Have OnSuggestionAccepted hooked up with relatively high accuracy.
…epted as the command line
- temporarily disable list view - write warning about list view temporarily disabled for 'Get-PSReadLineOption' - write warning about list view temporarily disabled for 'Set-PSReadLineOption -PredictionViewStyle ListView'
f5358c2 to
f77a0f5
Compare
|
@SteveL-MSFT Can you please review again? Thanks! |
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright headers can be updated as a separate PR
PR Summary
Feature Overview
Major feature level changes:
ListViewto the predictive intellisense feature in PSReadLine.CommandPredictionAPIs introduced in PS 7.1, so when using PSReadLine with PS 7.1, a user can import a predictor module and PSReadLine can render the suggestions returned from the predictor module.There will be 4 options for the
PredictionSource:None,History,Plugin,HistoryAndPlugin.None-- disable the predictive intellisense feature, which is the default.History-- enable the predictive intellisense feature, and use the PSReadLine history as the only source.Plugin-- enable the predictive intellisense feature, and use the plugins (CommandPrediction) as the only source.HistoryAndPlugin-- enable the predictive intellisense feature, and use both history and plugin as the sources.There will be 2 views for the
PredictionViewStyle:InlineViewandListView.InlineView-- the style as existing today, similar as in fish shell and zsh.ListView-- suggestions are rendered in a drop down list, and users can select using UpArrow and DownArrow.Two more color settings were added to support customization of the
ListView:ListPredictionColor-- set color for the leading>character and the trailing source name, e.g.[History]. By default, it usesDarkYellowas the foreground color.ListPredictionSelectedColor-- set color for indicating a list item is selected. By default, it usesDarkBlackas the background color.Handling of Commonly Used Keys
To improve the user experience, some commonly used keys/functionalities are specially handled:
RevertLine) -- in the list view, it will revert to the original line, no matter whether or not a list item is selected, and clear the list view. So UpArrow and DownArrow can then be used to navigate history commands as normal.Undo) -- in the list view, it will revert to the original line, no matter whether or not a list item is selected, but keep the list view.DigitArgument) -- in the list view, the digit argument won't refresh the suggestion results, and it can be used together with UpArrow and DownArrow to speed up the selection.InlineViewandListViewwith a hotkey F2 (SwitchPredictionView).Feedback Trigger
The
CommandPredictionhas 2 APIs for the host client to provide feedback to the predictor plugin/module:OnSuggestionAccepted,OnCommandLineAccepted.OnCommandLineAcceptedis triggered when the current command line is accepted (AcceptLine). Call toAcceptLinedue to Ctrl+c is filtered out.OnSuggestionAcceptedis triggered differently based on the prediction view in use:InlineView-- callback is triggered when either the suggestion is accepted via RightArrow, or the next word of the suggestion is accepted via Ctrl+f (ForwardWord).ListView-- callback is triggered whenWork with downlevel PowerShell
On supported downlevel PowerShell versions, such as Windows PowerShell 5.1 and PowerShell 7.0:
Historycan be used as the prediction source. ThePluginandHistoryAndPluginoptions forPredictionSourceonly work with PS 7.1+.ListViewworks on all supported downlevel PowerShell versions when using theHistoryprediction source.We are still shipping only a single
Microsoft.PowerShell.PSReadLine2.dllthat is built targetingnet461. To bridge it with different PowerShell runtimes (PS7.1+ vs. downlevel), I introduced theMicrosoft.PowerShell.PSReadLine.Polyfiller.dll. The module structure is shown as follows:net461version of thePolyfiller.dllcontains the stub definitions ofCommandPredictionand related types.net5.0version of thePolyfiller.dllcontains type forwarders that forwards theCommandPredictionand related types to the 7.1+ version ofSystem.Management.Automation.dll.By loading the right
Polyfiller.dll, theMicrosoft.PowerShell.PSReadLine2.dllbuilt againstnet461can work on all supported versions of PowerShell.To make sure the right
Polyfiller.dllis loaded, PSReadLine registers a handler toAppDomain.CurrentDomain.AssemblyResolveupon module loading and unregisters the handler during module unloading. The handler decides whichPolyfiller.dllto use based on the current .NET version (Environment.Version).Build and Tests
Build scripts were updated to build PSReadLine with multi-target
net461andnet5.0. Also, the artifacts are packaged in the structure as shown above.12 xUnit tests were added and each of them contains quite amount of sub tests. The new test code is more than 1300 line.
To test the plugin scenario, I made the use of the new
CommandPredictionAPIs mockable, by adding corresponding member methods toIPSConsoleReadLineMockableMethods.Also fix #1591
PR Checklist
Microsoft Reviewers: Open in CodeFlow