vscode-powershell
vscode-powershell copied to clipboard
Integrate with tool version managers like Aqua and mise
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all issues to ensure it has not already been reported.
Summary
There are now multiple multiplatform tools that can manage PowerShell versions as any other dev tool, like:
- Aqua: https://aquaproj.github.io/
- mise: https://mise.jdx.dev/
- Uses Aqua registry (and other sources)
It'd be cool of vscode-powershell somehow could integrate with external tools for easily setting what PowerShell version to run for a session. It doesn't have to be tool specific, but maybe instead of hardcoding a path to pwsh.exe one could do trigger a command:
mise use pwsh@<version_supplied_by_vscode_powershell>; mise where pwsh@<version_supplied_by_vscode_powershell>
Which then tells what path to pwsh.exe vscode-powershell should use.
Proposed Design
No response
I think this is two asks both of which are feasible:
-
Teach VS Code to search for PowerShell installations in the directories that mise, Aqua, etc. install them. An example would be https://github.com/PowerShell/vscode-powershell/blob/0c5f2f8c23add289b3909c352f0c28213ac38537/src/platform.ts#L340 and the most annoying part frankly would be adding the appropriate test coverage. I'm happy to accept a PR for this as long as it comes with citation of documentation as to why it's now looking where. When done correctly, it should make those installed versions available in the PowerShell session menu, and should name them accurately. No defaults should change. This would essentially allow the user to skip manually adding these installations to
powershell.powerShellAdditionalExePaths. They could access these PowerShells just by running "Show Session Menu" (or clicking the PowerShell langauage status icon) and could set it as a default by its name. -
Teach mise, Aqua, etc. to edit the current workspace's
powershell.powerShellDefaultVersionsetting to the name of the desired PowerShell as it shows in the additional PowerShells after (1) is completed when running e.g.mise use. This is out of scope of this project and would be something to work on with those developers.
Note that I'm saying this with no familiarity with these exact tools, and am assuming they operate somewhat like the Python and Ruby environment managers.
I've found a way to do this now using a combination of mise and Scoop.
Scoop can create shims, which will create a .exe that can be pointed to by vscode-powershell.
mise alias for pwsh
mise uses powershell-core as name for PowerShell. I prefer pwsh. So I added following to the mise config.toml:
[alias]
pwsh = 'aqua:PowerShell/PowerShell'
After that you can do mise use --global [email protected], instead of mise use --global [email protected].
Scoop shims for specific pwsh version
My two shims for v7.4 and v7.5:
PS > scoop shim add pwsh75 mise "exec [email protected] -- pwsh"
PS > scoop shim add pwsh74 mise "exec [email protected] -- pwsh"
PS > (Get-Command -Name 'pwsh*').Path
C:\Users\olav.birkeland\scoop\persist\mise\mise\installs\pwsh\7.5.0\pwsh.exe
C:\Users\olav.birkeland\SCOOP\apps\mise\current\mise\installs\pwsh\7.5.0\pwsh.exe
C:\Users\olav.birkeland\scoop\shims\pwsh74.exe
C:\Users\olav.birkeland\scoop\shims\pwsh75.exe
PS >
Windows Terminal
Can use commands and thus mise directly like so in settings.json:
[
{
"commandline": "mise exec [email protected] -- pwsh -NoLogo",
"guid": "{f1781ba6-28e5-4be2-85cf-56a9937de9de}",
"hidden": false,
"icon": "ms-appx:///ProfileIcons/pwsh.png",
"name": "PowerShell 7.5 (mise)",
"startingDirectory": "%USERPROFILE%"
},
{
"commandline": "mise exec [email protected] -- pwsh -NoLogo",
"guid": "{f12194ee-663f-4a48-9d6e-166b464afee9}",
"hidden": false,
"icon": "ms-appx:///ProfileIcons/pwsh.png",
"name": "PowerShell 7.4 (mise)",
"startingDirectory": "%USERPROFILE%"
}
]
VSCode built in terminal
Can use commands too. VSCode settings.json:
{
"terminal.integrated.defaultProfile.windows": "PowerShell v7.5 (mise)",
"terminal.integrated.profiles.windows": {
"PowerShell v7.4 (mise)": {
"args": [
"exec",
"[email protected]",
"--",
"pwsh",
"-NoLogo",
"-NoExit",
"-ExecutionPolicy",
"RemoteSigned"
],
"icon": "terminal-powershell",
"overrideName": true,
"path": "mise"
},
"PowerShell v7.5 (mise)": {
"args": [
"exec",
"[email protected]",
"--",
"pwsh",
"-NoLogo",
"-NoExit",
"-ExecutionPolicy",
"RemoteSigned"
],
"icon": "terminal-powershell",
"overrideName": true,
"path": "mise"
},
"Windows PowerShell (x64)": {
"args": [
"/NoLogo",
"/NoExit",
"/ExecutionPolicy",
"RemoteSigned"
],
"overrideName": true,
"path": "${env:SystemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
},
"Windows PowerShell (x86)": {
"args": [
"/NoLogo",
"/NoExit",
"/ExecutionPolicy",
"RemoteSigned"
],
"icon": "terminal-powershell",
"overrideName": true,
"path": "${env:SystemRoot}\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe"
}
}
}
VSCode + vscode-powershell
Requires path, can't use command. Here one can use the Scoop shims. VSCode settings.json:
{
"powershell.powerShellAdditionalExePaths": {
"PowerShell v7.5": "C:\\Users\\olav.birkeland\\scoop\\shims\\pwsh75.exe",
"PowerShell v7.4": "C:\\Users\\olav.birkeland\\scoop\\shims\\pwsh74.exe"
},
"powershell.powerShellDefaultVersion": "PowerShell v7.5"
}