Skip to content

Add PS Core in select default shell on windows#72425#72689

Merged
Tyriar merged 14 commits intomicrosoft:masterfrom
roottool:add-PS-Core-in-Select-Default-Shell-on-Windows#72425
May 11, 2019
Merged

Add PS Core in select default shell on windows#72425#72689
Tyriar merged 14 commits intomicrosoft:masterfrom
roottool:add-PS-Core-in-Select-Default-Shell-on-Windows#72425

Conversation

@roottool
Copy link

Issue number

#72425

Description

This PR adds pwsh(PowerShell Core) in Select Default Terminal UI when VSCode is operated on Windows.
A file path of pwsh is got from registry.

Screenshot

getpwshDefaultPath

Here is a screenshot of a pattern with pwsh installed with a custom path.

Note

I wrote the below in added a function.

const shellNotFound = 'ShellNotFound';

We will find ShellNotFound in a shell path of Select Default Terminal UI if file://ShellNotFound exists and added a function can't get a shell path.
Because I can not write the below by #72601.

const shellNotFound = '';

I suggest to change from 'ShellNotFound' to '' if #72601 is fixed.

@msftclas
Copy link

msftclas commented Apr 21, 2019

CLA assistant check
All CLA requirements met.

@octref octref requested a review from sbatten April 22, 2019 07:18
@sbatten sbatten requested a review from Tyriar April 22, 2019 17:46
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

@sbatten please review the usage of vscode-windows-registry 🙂

useWSLexe = true;
}

const Registry = await import('vscode-windows-registry');
Copy link
Member

Choose a reason for hiding this comment

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

Let's move the await into _getShellPathFromRegistry and make that function async as well

* @param shellName The shell name to get the executable file path
* @returns The executable file path of shell or `'ShellNotFound'`
*/
private _getShellPathFromRegistry(Registry: typeof import('vscode-windows-registry'), shellName: string): string {
Copy link
Member

Choose a reason for hiding this comment

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

I think this function should be a little more targetted to just pwsh for now and then return either [] or [ 'path' ]

let shellPath;

try {
shellPath = Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', `SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\${shellName}.exe`, '');
Copy link
Member

Choose a reason for hiding this comment

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

This could be simplified:

try {
  return (grab from reg);
} catch () {
}
return [];

Copy link
Author

Choose a reason for hiding this comment

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

Registry.GetStringRegKey() function returns string or undefined.
https://github.com/Microsoft/vscode/blob/3a12b7ac2efd2f1f01a646ef5272313ad50bf618/src/typings/vscode-windows-registry.d.ts#L8
Therefore, this function needs a logic to convert from undefined to [].
But I referred your review when I fixed the code.

Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

I realized that using ! makes the logic unnecessary. So I deleted the logic.

sorry for the trouble!

@Tyriar Tyriar added this to the May 2019 milestone Apr 23, 2019
const Registry = await import('vscode-windows-registry');

try {
return [Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', `SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\${shellName}.exe`, '')!];
Copy link
Member

Choose a reason for hiding this comment

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

While this does compile, you'll still want to put it in a variable and check for undefined just in case as ! tells the typescript compiler to don't type check this making it less safe. If the key didn't exist (for some reason) this would return [undefined] which could break whatever is consuming the function.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for review,
That was a failure due to my lack of understanding.
I fixed this code.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Looks great! I'll verify and merge in the May release 🙂

@Tyriar Tyriar merged commit 73acf43 into microsoft:master May 11, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants