Skip to content

Commit 87476a5

Browse files
theJasonHelmickJamesWTruherjoeyaiello
authored
Final: RFC0062 - Predictive IntelliSense (#289)
* updated pr predictive intellisense * Update 1-Draft/RFC00XX-PredIctive-IntelliSense.md Co-authored-by: James Truher [MSFT] <[email protected]> * updated pr predictive intellisense * updated pr predictive intellisense * removed reference to plugin as PSRL option * changed providers to plugins and cleanup * Corrections * Merge RFC0062 - Predictive IntelliSense as Final Co-authored-by: James Truher [MSFT] <[email protected]> Co-authored-by: Joey Aiello <[email protected]>
1 parent 42cc4fd commit 87476a5

10 files changed

+353
-0
lines changed

1-Draft/media/pi-arrow-Noun.gif

862 KB
Loading

1-Draft/media/pi-arrow-param.gif

859 KB
Loading

1-Draft/media/pi-arrow-verb.gif

380 KB
Loading

1-Draft/media/pi-color.png

79.4 KB
Loading

1-Draft/media/pi-color2.png

29 KB
Loading
37.2 KB
Loading

1-Draft/media/pi-fb.gif

2.02 MB
Loading

1-Draft/media/pred-listview.png

38.1 KB
Loading

1-Draft/media/pred-wlc.png

12.6 KB
Loading
+353
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
---
2+
RFC: RFC0062
3+
Author: Jason Helmick
4+
Status: Final
5+
Area: Shell
6+
Comments Due: 10/31/2020
7+
---
8+
9+
# Motivation
10+
11+
Tab completion has accelerated the success of both new and experienced PowerShell users. New users
12+
get the benefit of discovery; seeing available cmdlets and parameters as options while interactively
13+
typing. Experienced users receive the benefit of acceleration; typing less while using the **<tab>**
14+
key to quickly complete a command.
15+
16+
The increasing amount of technology translates to an increase in cmdlets and full command
17+
complexity. Predictive IntelliSense is an addition to the concept of Tab Completion to assist the
18+
user in successfully completing full commands.
19+
20+
## Predictive IntelliSense
21+
22+
The prediction suggestion appears as colored text following the user’s cursor. This enables new and
23+
experienced users of PowerShell to discover, edit, and execute full commands based on matching
24+
predictions from the user’s history or additional plugins.
25+
26+
Additional plugins enhance historic predictions by providing domain specific commands and task
27+
completions. Predictive IntelliSense includes an extension model to support the registration of
28+
additional plugins.
29+
30+
Predictions may be displayed in either **InlineView** or **ListView** depending on the user’s
31+
preference. Below, predictions are displayed with InlineView.
32+
33+
![image](./media/pred-wlc.png)
34+
35+
Below, predictions are displayed with a dropdown in ListView.
36+
37+
![image](./media/pred-listview.png)
38+
39+
## Release plan
40+
41+
Similar to tab completion, Predictive IntelliSense is implemented in both the PowerShell engine and
42+
presented through the PSReadLine module. In an effort to support the most PowerShell users, the
43+
presentation of history-based predictions will be available to the following versions:
44+
45+
- Windows Powershell 5.1
46+
- PowerShell 7.0+
47+
48+
Additional plugins require the the extension framework implemented in the PowerShell engine. Support
49+
for additional plugins is available in the following versions:
50+
51+
- PowerShell 7.2+
52+
53+
History-based predictions initial preview and ship plan:
54+
55+
- PSReadLine 2.1.0-beta2 currently available for download from PSGallery
56+
- PSReadLine 2.1.0-GA will ship with PowerShell 7.1
57+
- PSReadLine 2.1.0-GA will be available for download from PSGallery
58+
- History based prediction in the **InlineView**
59+
60+
Extension/Plugin support initial preview and ship plan:
61+
62+
- PSReadLine 2.2.0-beta1 planned availability in October 20
63+
- PSReadline 2.2.0-beta3 planned availability in June 21
64+
- PSReadLine 2.2.0-GA will ship with PowerShell 7.2
65+
- PSReadLine 2.2.0-GA will be available for download from PSGallery
66+
- Includes support for **InlineView** and **ListView**
67+
- Includes support for additional prediction source **HistoryAndPlugins**
68+
- Note: Windows PowerShell 5.1 and PowerShell 7.0 will only support prediction source **History**.
69+
PowerShell 7.2+ will support prediction sources **History** and **HistoryAndPlugins**
70+
71+
## Goals/Non-Goals
72+
73+
Goals:
74+
75+
- Provide suggestions from PSReadLine history
76+
- The user will be able to enable and disable Predictive IntelliSense
77+
- The user will be able to change between InlineView and ListView
78+
- The user will have keyboard shortcuts to navigate and edit a prediction
79+
- The user will be able to register additional plugins when desired
80+
- The user may customize the color of a prediction to support accessibility needs
81+
82+
Non-goals:
83+
84+
- The extension framework doesn't allow a plugin implementation to call into the Runspace where
85+
PSReadLine is running when providing predictive suggestions.
86+
- VSCode implementation. We agree this is important for a consistent experience and are working to
87+
bring this feature in a future release, but the user experience for VS Code is outside the scope of this RFC.
88+
89+
## Specification
90+
91+
The proposal is to add Predictive IntelliSense and an extension model to improve the user
92+
interactive experience.
93+
94+
### Key Design Considerations Predictive IntelliSense
95+
96+
Predictive IntelliSense displays the most likely match from command history. The prediction may
97+
change if a better match is found as the user types additional information. The predicted command
98+
may be accepted, edited, or ignored.
99+
100+
![Prediction - Historical](./media/pred-wlc.png)
101+
102+
### Install and Remove Predictive IntelliSense
103+
104+
Predictive IntelliSense application programming interface (API) is implemented in the PowerShell
105+
engine and presented through the PSReadLine module. To receive the benefits of Predictive
106+
IntelliSense based on your PowerShell version, download and install the PSReadLine module from
107+
PSGallery
108+
109+
The current release is PSReadLine 2.1.0 Beta 2:
110+
111+
```powershell
112+
Install-Module PSReadLine -RequiredVersion 2.1.0-beta2 -AllowPrerelease
113+
```
114+
115+
It is possible to unload or uninstall the PSReadLine module to disable Predictive IntelliSense. This
116+
creates a negative impact to customers as it would remove all features of PSReadLine. For this
117+
reason, Predictive IntelliSense has its own PSReadLine configuration to enable and disable
118+
predictions.
119+
120+
Note - When upgrading PowerShell preview versions, it's important to upgrade to the corresponding
121+
version of PSReadLine. Some beta versions may result in an error when PowerShell starts.
122+
123+
### Enabling and Disabling Predictions
124+
125+
By default, the feature Predictive IntelliSense is disabled. The impact of enabling this feature by
126+
default may cause new and existing users to become confused at the shell prompt. The feature is
127+
enabled and disabled with a PSReadLine command Set-PSReadLineOption that is executed at the shell
128+
prompt or in the user's Profile.
129+
130+
Predictive IntelliSense in PSReadLine 2.1.0-beta2 currently supports the following arguments for
131+
prediction source;
132+
133+
- None - This option disables Predictive IntelliSense
134+
- History - This option uses only the PSReadLine history for predictions
135+
136+
Starting with PSReadLine 2.2.0-beta1, Predictive IntelliSense will support the following arguments
137+
for prediction source;
138+
139+
- None - This option disables Predictive IntelliSense
140+
- History - This option uses only the PSReadLine history for predictions
141+
- HistoryAndPlugins - History provides initial completions, plugins provide additional completions.
142+
143+
To enable Predictive IntelliSense, enter the following command in the shell or in the users Profile:
144+
145+
```powershell
146+
Set-PSReadLineOption -PredictionSource History
147+
```
148+
149+
To disable Predictive IntelliSense, enter the following command in the shell or in the users Profile:
150+
151+
```powershell
152+
Set-PSReadLineOption -PredictionSource None
153+
```
154+
155+
### Changing the Prediction View
156+
157+
Beginning with 2.2.0-beta1, Predictions are displayed in one of two views depending on the user
158+
preference. The default view is InlineView.
159+
160+
- InlineView – This is the default view and displays the prediction inline with the user’s typing.
161+
This view is similar to other shells Fish and ZSH.
162+
- ListView – ListView provides a dropdown list of predictions below the line the user is typing.
163+
Users may quickly scan the list, highlight and select the desired prediction.
164+
165+
Users may change the view at the command line using the keybinding F2 or `Set-PSReadLineOption`. The
166+
`Set-PSReadLineOption` may be stored in the user's profile.
167+
168+
```powershell
169+
Set-PSReadLineOption -PredictionViewStyle ListView
170+
```
171+
172+
### Change the Prediction Color for Accessibility
173+
174+
By default, predictions appear on the same line the user is typing in a different customizable
175+
color. To support accessibility needs, the prediction color is settable in the shell or user's
176+
profile.
177+
178+
The default light-grey prediction text color;
179+
180+
```powershell
181+
Set-PSReadLineOption -Colors @{ InLinePrediction = "`e[38;5;238m"}
182+
```
183+
184+
Starting with PSReadLine 2.1.0-RC1, `Set-PSReadLineOption -Colors` array will include
185+
**InLinePrediction** to set the color of predictive text for **InLineView**.
186+
187+
Beginning with PSReadLine 2.2.0-beta1, `Set-PSReadLineOption -Colors` array will include;
188+
189+
- **ListPredictionColor** to set color for '>' and source names in **ListView**
190+
- **ListPredictionSelectionColor** to set color for the highlighted selection in **ListView**
191+
192+
Examples of user changing prediction color:
193+
194+
![pi-color](./media/pi-color.png)
195+
![pi-color](./media/pi-color2.png)
196+
![pi-color](./media/pi-color3-background.png)
197+
198+
```powershell
199+
Set-PSReadLineOption -Colors @{ InLinePrediction = '#8A0303'}
200+
Set-PSReadLineOption -Colors @{ InLinePrediction = '#2F7004'}
201+
Set-PSReadLineOption -Colors @{ InLinePrediction = "`e[36;7;238m"}
202+
```
203+
204+
Multiple types of color code values are supported in PSReadLine. For more information see
205+
Set-PSReadLineOption in
206+
[PSReadLine](https://docs.microsoft.com/en-us/powershell/module/PSReadline/Set-PSReadlineOption?view=powershell-7)
207+
208+
Examples of different color code values:
209+
210+
```powershell
211+
# Use a ConsoleColor enum
212+
Set-PSReadLineOption -Colors @{ InLinePrediction = 'DarkRed'}
213+
Set-PSReadLineOption -Colors @{ InLinePrediction = [ConsoleColor]::DarkRed}
214+
215+
# 24 bit color escape sequence on supported terminals
216+
Set-PSReadLineOption -Colors @{ InLinePrediction = "`e[38;5;100m"}
217+
218+
# RGB value
219+
Set-PSReadLineOption -Colors @{ InLinePrediction = "#8181f7"}
220+
```
221+
222+
### Key Bindings for Predictions
223+
224+
Key bindings control cursor movement and additional features within the prediction. To support users
225+
running Predictive IntelliSense on multiple platforms, key bindings are user-settable in the shell
226+
and a user’s PowerShell profile.
227+
228+
Example of setting a key binding in the shell or user’s profile:
229+
230+
```powershell
231+
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
232+
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
233+
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
234+
```
235+
236+
List of suggested key bindings defined in **SamplePSReadLineProfile.ps1**
237+
238+
Key Binding | PSReadLine Function | Description
239+
------------- | ------------------- | -----------
240+
Up Arrow | HistorySearchBackward | Move backward through history
241+
Down Arrow | HistorySearchForward | Move forward through history
242+
F7 | Profile Code | Opens Out-GridView with full history
243+
F1 | Profile Code | Opens the Help window for the current command or parameter
244+
F2 | Profile Code | Switches between InLineView and ListView
245+
Ctrl-b | Profile Code | Add command to history
246+
Ctrl-q | TabCompleteNext | Windows style Tab for Emacs mode
247+
Ctrl-Q | TabCompletePrevious | Windows style Tab for Emacs mode
248+
Ctrl-c | Copy | Clipboard interaction for Emacs mode
249+
Ctrl-v | Paste | Clipboard interaction for Emacs mode
250+
Ctrl-d,Ctrl-c | CaptureScreen | Captures screen for pasting to email or blog
251+
Alt-d | ShellKillWord | Token based movement bound to Emacs word movement
252+
Alt-Backspace | ShellBackwardKillWord | “
253+
Alt-b | ShellBackwardWord | “
254+
Alt-f | ShellForwardWord | “
255+
Alt-B | SelectShellBackwardWord| “
256+
Alt-F | SelectShellForwardWord | “
257+
“ or ‘ | Profile Code | Insert Smart quotes
258+
( or { or [ | Profile Code | Insert matching braces
259+
Backspace | Profile Code | Delete previous character
260+
Alt-w | Profile Code | Save current line in history – don’t execute
261+
Ctrl-V | Profile Code | Paste clipboard as a Here string
262+
Alt-( | Profile Code | Insert parenthesis around selection or entire line
263+
Alt-‘ | Profile Code | Toggle quotes on argument under cursor
264+
Alt-% | Profile Code | Replace aliases with resolved commands
265+
266+
### Search history based on cursor location
267+
268+
The history from PSReadLine is searchable when the user begins typing into the shell.
269+
Users may search the entire prediction history for commands matching under the current cursor
270+
position. Users may search history based on 'Verb', 'Noun' and 'Parameter' of a cmdlet
271+
using the up/down arrow keys.
272+
273+
- Searching history from cmdlet verb.
274+
![Verb](./media/pi-arrow-verb.gif)
275+
276+
- Searching history from cmdlet noun.
277+
![noun](./media/pi-arrow-noun.gif)
278+
279+
- Searching history from parameter.
280+
![Param](./media/pi-arrow-param.gif)
281+
282+
### Edit predictions before accepting the prediction
283+
284+
Users may navigate prediction tokens to make changes to parameters, arguments, and additional
285+
pipeline commands. The prediction model will update the displayed prediction from the closest
286+
matches in PSReadLine history or added provider.
287+
288+
In the example below, a user navigates the prediction, pausing to change the -Property argument and
289+
receiving an updated prediction.
290+
291+
![arg change](./media/pi-fb.gif)
292+
293+
## Prediction Extension Model
294+
295+
Additional plugins enhance historic predictions by providing domain specific commands and task
296+
completions. Plugins register with the PowerShell engine which includes an extension model
297+
to support the registration.
298+
299+
An RFC for this subsystem will be coming in the future. For more information about the extension
300+
model, see
301+
[Initial work of the subsystem plugin model](https://github.com/PowerShell/PowerShell/pull/13186)
302+
303+
## Extension Model Goals/Non-Goals
304+
305+
Goals:
306+
307+
- Provide extension model to support additional plugins
308+
- Support the discovery of plugins using `Get-PSSubsystem`
309+
- Provide Module owners method of registration
310+
- Provide improvements to the predictors through feedback
311+
312+
Non-goals:
313+
314+
- Register/Unregister-Subsystem cmdlets are not planned because it's targeting binary subsystem
315+
implementations, which should deal with registration/unregistration via APIs.
316+
- Server-side provider privacy is the responsibility of the provider module
317+
318+
## Extension Model Specification
319+
320+
### Discovery of Provider Metadata and Registration
321+
322+
Plugins are registered automatically to the PowerShell engine when the user installs a provider
323+
module. Removal of registration occurs when the module is removed.
324+
325+
Starting with PowerShell 7.1 Preview 7, and as an experimental feature of PowerShell 7.1-RC.1, the
326+
`Get-PSSubsystem` cmdlet is an experimental feature of the `PSSubsystemPluginModel`. To enable the
327+
experimental feature:
328+
329+
```powershell
330+
Enable-ExperimentalFeature -Name PSSubsystemPluginModel
331+
```
332+
333+
To list the currently installed plugins and their respective metadata such as version information:
334+
335+
```powershell
336+
Get-PSSubSystem -Kind CommandPredictor
337+
```
338+
339+
Example output with no additional plugins registered;
340+
341+
```output
342+
Kind SubsystemType IsRegistered Implementations
343+
---- ------------- ------------ ---------------
344+
CommandPredictor ICommandPredic… False {}
345+
```
346+
347+
Example output with an additional provider registered;
348+
349+
```output
350+
Kind SubsystemType IsRegistered Implementations
351+
---- ------------- ------------ ---------------
352+
CommandPredictor ICommandPredic… True {Az Predictor}
353+
```

0 commit comments

Comments
 (0)