Skip to content

[Feature] Workspace Setting for Integrated Console PS Version #2099

Closed

Description

Summary of the new feature

I work different projects, some require WinPS5 due to library dependencies, some use PS6+. Currently the integrated terminal that is used appears to be a "global" setting. If I switch it to PS6+ in one project and then open the other, it stays PS6+, this leads to annoying toggle back and forth.

I want to be able to set so that when I open a certain project or workspace, it remembers what integrated terminal version I was using for that workspace

Proposed technical implementation details (optional)

User/Workspace setting for powershell.integratedterminalversion that would match the string in the session picker dropdown, e.g. "Powershell", "Windows Powershell (x64)", "Powershell Preview", etc.

Activity

  1. changed the title [-][Feature] Workspace Setting for Integration Console PS Version[/-] [+][Feature] Workspace Setting for Integrated Console PS Version[/+] on Jul 23, 2019
  2. SydneyhSmith commented on Jul 23, 2019

    @SydneyhSmith
    Collaborator

    Thanks for opening this feature request Justin Grote (@JustinGrote)! I was looking through other issues and was wondering if you feel that #190 addresses the same concerns as you?

  3. JustinGrote commented on Jul 24, 2019

    @JustinGrote
    CollaboratorAuthor
  4. TylerLeonhardt commented on Jul 26, 2019

    @TylerLeonhardt
    Member
  5. JustinGrote commented on Jul 26, 2019

    @JustinGrote
    CollaboratorAuthor

    TylerLeonhardt my problems are likely related to #1586. I did some more extensive testing and found the following (using powershell-preview extension):

    1. powershell.powershellexepath gets populated immediately if you toggle shell from the lower right menu (or use Show Session Menu)
    2. It does not update if you specify a powershell.powershelldefaultversion and reload window.
    3. Killing the terminal after the reload reverts to this powershell.powershellexepath that was previously saved in (because it was never updated)

    For instance if you set powershelldefaultversion to "Powershell Preview" (added via AdditionalExePaths) but your last shell was "Windows Powershell (x64)", then PS Preview will load on reload, but if you kill the terminal via the trash icon and restart it, it comes back as "Windows Powershell (x64)"

    Fix
    Make it so that when the extension finds the selection via powershell.powershelldefaultversion, it immediately sets the settings.json "placeholder" in the same way that the session selection menu does.

    Alternatively, make a kill/reload of the terminal window follow the same discovery process as "first launch" and not just go with whatever powershellexepath is set to.

    Side bug
    If you set powershellexepath as a workspace setting, it doesn't get updated, so it is "sticky" and even if you toggle to another console it keeps coming back to whatever is set in workspace setting. This kind of meets my criteria, except I can't toggle to another version of powershell quickly without commenting it out if I want to test xplat compatability or something.

    That aside, it does seem to work on a workspace-level as long as I don't kill the window, so if the above bug is fixed I think we are good to go and can close this.

    EDIT: I can record a screengif of the behavior if you can't repro. Thanks!

  6. JustinGrote commented on Jul 26, 2019

    @JustinGrote
    CollaboratorAuthor

    Workaround

    Add this to your Microsoft.VSCode_profile.ps1

    #Todo: Detect Insiders vs. regular vscode
    if ($isWindows) {
        $vscodeSettingsPath = "$($env:APPDATA)\Code - Insiders\User\settings.json"
    } else {
        $vscodeSettingsPath = "$HOME/.config/Code - Insiders/User/settings.json"
    }
    $PowershellExePath = (Get-Process -id $pid).path -replace '\\','\\'
    $PowershellExePathRegex = '(?<="powershell\.powerShellExePath": ")(.+)(?=")'
    $vscodeSettings = gc -raw $vscodeSettingsPath
    $vscodeSettings -replace $PowershellExePathRegex,$PowershellExePath | Out-File -Encoding UTF8 $vscodeSettingsPath
    Remove-Variable PowershellExePath,PowershellExePathRegex,vscodeSettingsPath,vscodeSettings

    This will basically do the behavior I described above, and then whatever you set powershell.powershellDefaultVersion to will be sticky to that project, and stay that way if you terminal and reload a session. You can set a global user setting, as well as a per-workspace override, and it works fine. If you decide to switch session mid-session, will still be fine.

    You will get a nag message on startup if it had to switch runtimes that the runtime had switched and ask if you want to restart it, just ignore it.

  7. JustinGrote commented on Jul 26, 2019

    @JustinGrote
    CollaboratorAuthor

    Recommended Fix

    TylerLeonhardt There should be a call to changePowershellExePath here:

    if (powerShellDefaultVersion) {
    powerShellExePath = powerShellDefaultVersion.exePath;
    } else {

  8. SydneyhSmith commented on Jul 26, 2019

    @SydneyhSmith
    Collaborator

    Justin Grote (@JustinGrote) thanks for providing all this info and proposed work around...we just discussed this and the possible ramification and are worried that this would cause unexpected behavior when choosing a version from the session menu...you are correct though in that we need to make a fix to ensure that the default version specified in the settings is being used for any session not started by the session menu

  9. added
    Issue-Bug
    and removed
    Issue-Enhancement
    on Jul 26, 2019
  10. 9 remaining items

  11. JustinGrote commented on Nov 13, 2019

    @JustinGrote
    CollaboratorAuthor

    We no longer depend on powerShellExePath first for anything

    TylerLeonhardt I don't think this statement is accurate at least with the Nov 1st Powershell Preview, were his changes incorporated in that release?

    Whenever you switch shells with the lower right or the session menu command, it updates PS Exe Path at the usersettings level, and that seems to always override whatever I might have defined.

    I also did the following tests with the following session menu for reference:
    image

    1. Remove powershellExePath and PowershellDefaultVersion at both user and workspace level. Get this prompt, ignore it
      image

    2. Start terminal session, 5.1 (x64) comes up. powershellExePath still blank

    3. Manually set PowershellDefaultVersion user setting to "Powershell Preview (x64)" and reload window.

    4. Integrated terminal is still 5.1 x64, all settings still the same

    5. Repeat with workspace, no dice.

    6. Manually update powershellExePath and reload, it is now on Preview.

    7. Blank out again

    8. Try setting workspace PowershellDefaultVersion to "Windows Powershell (x64)"

    9. Reload window, no effect.

    10. Toggle it with session menu and reload window, it now works but that's because powershellExePath was populated.

  12. ghost added
    Needs: Maintainer Attention
    on Nov 13, 2019
  13. TylerLeonhardt commented on Nov 13, 2019

    @TylerLeonhardt
    Member

    Thanks for the details Justin Grote (@JustinGrote)! This sounds like a bug. We did the work to discover PowerShell exes but we still needed to hook that up to the session mention and some other inner stuff it seems...

  14. TylerLeonhardt commented on Nov 14, 2019

    @TylerLeonhardt
    Member

    Alright, I have a PR out to fix this bug by removing powerShellExePath from everything and showing a notification to help the user with the transition:
    #2099

  15. JustinGrote commented on Nov 14, 2019

    @JustinGrote
    CollaboratorAuthor

    TylerLeonhardt I think you meant #2304

  16. ghost added
    Needs: Maintainer Attention
    on Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions