Skip to content

Use powerShellDefaultVersion everywhere and stop using powerShellExePath #2304

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

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Nov 14, 2019

PR Summary

fixes #2099

At long last, this PR removes the use of the powerShellExePath setting. @rkeithhill added an awesome feature a while back which allowed folks to be more granular with what version of PowerShell they want to use via the session menu.

This PR does the following:

  • Any operation that previously changed powerShellExePath now changes powerShellDefaultVersion

  • If the user has powerShellExePath and powerShellDefaultVersion set, a notification appears to remove the powerShellExePath from the settings.
    image

  • If the user has powerShellExePath but not powerShellDefaultVersion, a notification appears to remove powerShellExePath and shows the session menu so the user can choose which version they want to use.
    image

This does mess up users who have set powerShellExePath to "non well-known" locations... but I think those will be a small case... also, to help those folks and other folks who want to add additional PS exes, I added an item to the session menu that tells people they can modify a setting to add additional PS exes.

image

For this, it just jumps to the settings.json but in the future maybe we could have a little wizard that helps with adding them.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@JustinGrote
Copy link
Collaborator

@TylerLeonhardt does this cover user settings, workspace settings, and folder settings and the precedence order therein (folder > workspace > user)?

@TylerLeonhardt
Copy link
Member Author

This should only change the user setting of powershell.powerShellDefaultVersion and vscode should automatically give us the settings, upon loading the extension, in the correct precedence.

Has this not been the case?

@JustinGrote
Copy link
Collaborator

JustinGrote commented Nov 14, 2019

Last I checked powershell.PowershellDefaultversion didn't work at the folder settings level (e.g. .vscode/settings.json), just seeing if this respects it as well.

Sorry, I'm really bad at reviewing Typescript :/

EDIT: But this has usually been because of PowershellExePath, maybe it'll work now. Adding a test maybe?

EDIT2: I forgot "workspace settings" encompasses both folder settings and workspace file settings. It should work fine. I'll download the .vsix from the azure pipelines build and try it out.

@JustinGrote
Copy link
Collaborator

Looks like most everything works. Workspace setting overrides user settings, and if you change user settings with workspace settings already set, it doesn't override it (as expected).

I'll code review for one specific behavior I think should be different, if I can find it...

@JustinGrote
Copy link
Collaborator

JustinGrote commented Nov 14, 2019

Found it.

await configuration.update(settingName, newValue, global);

So the settings change method always only writes to the user settings, which leads to the following undesirable scenario:

  1. User sets workspace setting to Powershell Preview
  2. User forgets they did this
  3. User chooses the picker and chooses Windows Powershell (x64)
  4. User wonders why their shell is still Powershell Preview after reload (because workspace setting still takes precedence), they keep clicking the toggle and it doesn't change, leading to frustration.

Try it, you keep trying to change the session and it keeps going back to whatever the workspace setting is, because only the user setting is getting updated but the workspace setting takes precedence.

The behavior for Session Menu should be (IMHO):

  1. If only user settings is set, current behavior (update user settings)
  2. If workspace/folder setting is set, it should update wherever the lowest precedence order setting is configured (folder > workspace file > user settings)

I'm not sure if this should be true for all powershell settings (adjust default change method behavior) or if it should just be true for this setting (add a new change method overload that addititionally allows specification of the settings scope, including an 'auto' that would detect the lowest level the setting has been set and update it at that level)

Caveat

The one rub here is that if a module author has set this in the workspace for his repository as an indicator to the user which powershell to use, it will get changed and potentially committed back to the repository by the user as they try out different shells.

The fix for this is probably out of scope (and just tell the user "dont do it" or block .vscode commit updates) but an idea could be something along the lines of:

  1. Add additional workspace setting for project authors (e.g. powershell.powerShellRecommendedVersion yes/no) to indicate the powershell version they specified is what should be used for the project.
  2. If powershell.powerShellRecommendedVersion is set and a workspace setting for powerShellDefaultVersion exists, if Session Menu is used, it should pop up a toast warning after selection mentioning the shell they have selected is not what the project author recommends, and then asking them if they want to switch anyways (yes/no).

In addition, potentially add setting to make shell changes nonpersistent, where it will switch to the shell but not update the workspace setting.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Nov 14, 2019

Also: Potential regression - I've tried the CI build on two computers, and it prompted to remove PSExePath. After it prompted for reload it crashed with:

reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Server.PsesLanguageServer.<>c.<<StartAsync>b__18_3>d.MoveNext() in D:\a\1\PowerShellEditorServices\src\PowerShellEditorServices\Server\PsesLanguageServer.cs:line 114 --- End of stack trace from previous location where exception was thrown --- at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle(InitializeParams request, CancellationToken token) at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next) at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)...

However doing a Developer: Reload window and it works fine. A minor item but may be worth investigating.

@TylerLeonhardt
Copy link
Member Author

@JustinGrote thanks for pointing that out! That is an issue. I've addressed it in the last commit.

Here's what we do now - the session menu will always impact user settings. In the future we could have a nice wizard that does more... but for now, it will always impact user settings. That said, with that last commit we force the extension to start with the PowerShell exe that was chosen no matter what the workspace setting is set to.

@TylerLeonhardt
Copy link
Member Author

Also: Potential regression

Looks like the crash came from PowerShellEditorServices... how consistent is that repro? I cant seem to repro at all.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Nov 15, 2019 via email

@TylerLeonhardt
Copy link
Member Author

Hmm interesting. I'll give it a try a few times but I don't think it's this change's fault. That's a PowerShell Editor Services issue.

This PR is ready for a real review now.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Nov 19, 2019

@TylerLeonhardt #2311 might be a bug from this I ran into since I'm running the VSIX from this PR. So far I can consistently reproduce by starting the powershell editor in an "empty" vscode window (no folder opened) and starting a new powershell file.

@TylerLeonhardt
Copy link
Member Author

nice find - got a PR out to fix it.

src/session.ts Outdated
@@ -691,53 +629,15 @@ export class SessionManager implements Middleware {
SessionStatus.Failed);
}

private changePowerShellExePath(exePath: string) {
private changePowerShellDefaultVersion(exePath: IPowerShellExeDetails) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would be a simple async method now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

src/settings.ts Outdated
@@ -69,7 +69,7 @@ export interface IDebuggingSettings {

export interface IDeveloperSettings {
featureFlags?: string[];
powerShellExePath?: string;
// This setting is no longer used but is here to assist in cleaning up the users settings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What setting does this comment apply to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops - removed that.

@TylerLeonhardt TylerLeonhardt merged commit b9eafbb into PowerShell:master Nov 26, 2019
@TylerLeonhardt TylerLeonhardt deleted the use-powershelldefaultversion-everywhere branch November 26, 2019 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Workspace Setting for Integrated Console PS Version
3 participants