-
Notifications
You must be signed in to change notification settings - Fork 305
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
Add the prediction ListView
and also hook up with the CommandPrediction
APIs introduced in PS 7.1
#1909
Conversation
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. |
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.
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! |
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:
ListView
to the predictive intellisense feature in PSReadLine.CommandPrediction
APIs 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
:InlineView
andListView
.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 usesDarkYellow
as the foreground color.ListPredictionSelectedColor
-- set color for indicating a list item is selected. By default, it usesDarkBlack
as 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.InlineView
andListView
with a hotkey F2 (SwitchPredictionView
).Feedback Trigger
The
CommandPrediction
has 2 APIs for the host client to provide feedback to the predictor plugin/module:OnSuggestionAccepted
,OnCommandLineAccepted
.OnCommandLineAccepted
is triggered when the current command line is accepted (AcceptLine
). Call toAcceptLine
due to Ctrl+c is filtered out.OnSuggestionAccepted
is 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:
History
can be used as the prediction source. ThePlugin
andHistoryAndPlugin
options forPredictionSource
only work with PS 7.1+.ListView
works on all supported downlevel PowerShell versions when using theHistory
prediction source.We are still shipping only a single
Microsoft.PowerShell.PSReadLine2.dll
that 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:net461
version of thePolyfiller.dll
contains the stub definitions ofCommandPrediction
and related types.net5.0
version of thePolyfiller.dll
contains type forwarders that forwards theCommandPrediction
and related types to the 7.1+ version ofSystem.Management.Automation.dll
.By loading the right
Polyfiller.dll
, theMicrosoft.PowerShell.PSReadLine2.dll
built againstnet461
can work on all supported versions of PowerShell.To make sure the right
Polyfiller.dll
is loaded, PSReadLine registers a handler toAppDomain.CurrentDomain.AssemblyResolve
upon module loading and unregisters the handler during module unloading. The handler decides whichPolyfiller.dll
to use based on the current .NET version (Environment.Version
).Build and Tests
Build scripts were updated to build PSReadLine with multi-target
net461
andnet5.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
CommandPrediction
APIs mockable, by adding corresponding member methods toIPSConsoleReadLineMockableMethods
.Also fix #1591
PR Checklist
Microsoft Reviewers: Open in CodeFlow