I am struggling to migrate working from Powershell ISE to VS Code for PowerShell programming.
The biggest issue so far is to get ISE-like experience. People writing on the internet about VS Code setting "Toggle ISE mode" are wrong.
Because it only styles Window GUI and location in VS Code to look like ISE. I don't want to have just tab suggestion list when I type beginning of the PowerShell cmdlet name. Because it is useless.
I don't see a point in the list of 30 suggestions when I type:
Get-Win...
and press Ctrl+Space, because I cannot select any of them to complete my typing. It basically tells you have to press TAB 30 times to get desired cmdlet name or continue writing cmdlet name to make it more specific.
I am missing essential ISE functionality in VS Code, which is very useful. I include a screenshot so show exactly what I mean.
Please help me to find and enable this option in VS Code as I still can't migrate to VS Code because it doesn't work.
Preface:
I'm assuming that you're talking about the experience in the integrated terminal of VSCode (Visual Studio Code), and the answer below therefore applies to terminals (consoles) in general.
By contrast, with the PowerShell extension installed, you already do get the desired experience in editor tabs, i.e. list-based completion suggestions that appear automatically as you type.
While the answer below in principle applies to both the modern, cross-platform PowerShell (Core) 7 edition of PowerShell and the legacy Windows PowerShell edition, in the latter you must manually install a recent-enough version of PSReadLine
, e.g. with
Install-Module -Force -Scope CurrentUser PSReadLine
to get automatic predictions, and, importantly, you're limited to the history of previously submitted commands as the prediction source - plug-ins aren't supported.
tl;dr
While the predictive IntelliSense feature of the PSReadLine
module that ships with PowerShell does support offering completions automatically as you type, including - by opt-in - in list form (see below), out of the box there is currently no support for syntax-based completions, only for history-based ones.
However, said feature supports a plug-in model in PowerShell 7, allowing third parties to implement their own prediction sources, including a hypothetical syntax-based one. As of this writing, I'm not aware of such a module; see below for how to potentially implement one yourself.
For now, the closest approximation is to configure the regular, syntax-based tab-completion to present a list of possible completions instead of the default in-line representation. That said, this requires you to press Tab explicitly (or a different key, if you prefer) in order to display the list (and the list appearance differs from the one presented by the prediction feature):
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
PSReadLine
configuration, it affects the current session only; to make it take effect in future ones too, add the command to your $PROFILE
file.In a PowerShell terminal (console), including VSCode's integrated terminal, being offered completion predictions (suggestions) automatically, as you type, is provided by the built-in PSReadLine
module's predictive IntelliSense feature (which I'll just call prediction feature below):
The prediction feature is enabled by default, with the command history and plug-in modules both serving as prediction sources:
# This is the PowerShell 7 default; pass 'None' to *disable* predictions
# altogether, or 'History' / 'Plugin' to limit them to being sourced from
# the command history / plugin modules only.
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
History
(and None
) is supported, i.e. there's no support for plug-ins.The default prediction view is in-line; in order to get a list view, as in the ISE, you must run:
# The default is 'InlineView'
Set-PSReadLineOption -PredictionView ListView
As noted, PSReadLine
configuration commands (see Set-PSReadLineOption
) that should take effect in all future sessions must be added to your $PROFILE
file.
[PowerShell 7 only] PowerShell (as of v7.4.x) ships with no plug-ins, but (primarily third-party) plug-ins are available via the PowerShell Gallery by searching for "predictor".
Among them is a Microsoft-published module, CompletionPredictor
, which, however, is a sample module to illustrate the techniques of implementing a predictor plug-in module, as described in How to create a command-line predictor, which notes that such modules must be implemented as binary modules, i.e. (typically) in C#.
While this module is just a sample that implements syntax-based completion for just a few hard-coded commands, it could be used as the basis for a future plug-in module that could bring the full, syntax-based tab-completion functionality to the prediction feature.