Skip to content

Discover new PowerShell installations, fix startup issue with Windows PowerShell #2238

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

Merged
merged 48 commits into from
Oct 29, 2019

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Oct 10, 2019

PR Summary

Fixes #2217.

Gets rid of the default PowerShell and available PowerShell list logic in favour of a lazily generated list of PowerShells.

This resolves the issue where the PowerShell extension wouldn't start if PowerShell Core is not installed.

It also adds discovery of the PowerShell MSIX installation.

Discovery of the PowerShell .NET Core Global Tool has been added but is commented out, since a bug in this release persists that prevents passing command arguments needed to start the extension.

TODO: Add more tests

Tests refactored and added.

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

@TylerLeonhardt
Copy link
Member

@rjmholt can you make a goal of this to be that someone could copy this code and use it in their own project?

The Azure Data Studio folks want this.

@rjmholt rjmholt changed the title Discover new PowerShell installations, fix startup issue with Windows PowerShell WIP: Discover new PowerShell installations, fix startup issue with Windows PowerShell Oct 11, 2019
@rjmholt
Copy link
Contributor Author

rjmholt commented Oct 15, 2019

@TylerLeonhardt It looks like we need to merge PowerShell/PowerShellEditorServices#1066 to get tests to proceed

@TylerLeonhardt
Copy link
Member

Yep - that was needed

Co-Authored-By: Tyler James Leonhardt <[email protected]>
: getDefaultPowerShellPath(this.platformDetails, this.sessionSettings.useX86Host);
// No need to resolve this path, since the finder guarantees its existence
const firstPowerShell = this.powershellExeFinder.getFirstAvailablePowerShellInstallation();
return firstPowerShell && firstPowerShell.exePath || null;
Copy link
Member

Choose a reason for hiding this comment

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

The && and throwing me off here. Does that return firstPowerShell if firstPowerShell and firstPowerShell.exePath are truthy - else null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

&& returns either the falsey argument, or if both are truthy, the rightmost.

So "Hello" && "there" evaluates to "there'.

So a common idiom I've seen is to use it like obj?.property

Copy link
Member

Choose a reason for hiding this comment

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

oh I see. How about ternary instead? Maybe a little cleaner and more well known?

Suggested change
return firstPowerShell && firstPowerShell.exePath || null;
return firstPowerShell ? firstPowerShell.exePath : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not as safe: if exePath is not defined, then the first will give a known default when the second does not

suite("Platform module", () => {
let tempEnv: NodeJS.ProcessEnv;

suite("PlatformDetails", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for rewriting these!

rjmholt and others added 2 commits October 29, 2019 15:46
@rjmholt
Copy link
Contributor Author

rjmholt commented Oct 29, 2019

@TylerLeonhardt ready for review

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM! (one comment that I'm not blocking on)

@TylerLeonhardt
Copy link
Member

as soon as CI passes feel free to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to start PowerShell extension on Windows without PS 6+ installed
4 participants