@@ -16,12 +16,18 @@ import { IFeature } from './feature';
16
16
import { Message } from 'vscode-jsonrpc' ;
17
17
import { PowerShellProcess } from './process' ;
18
18
import { StringDecoder } from 'string_decoder' ;
19
+
19
20
import {
20
21
LanguageClient , LanguageClientOptions , Executable ,
21
22
RequestType , RequestType0 , NotificationType ,
22
23
StreamInfo , ErrorAction , CloseAction , RevealOutputChannelOn ,
23
24
Middleware , ResolveCodeLensSignature } from 'vscode-languageclient' ;
24
25
26
+ import {
27
+ OperatingSystem , PlatformDetails , getDefaultPowerShellPath ,
28
+ getPlatformDetails , fixWindowsPowerShellPath ,
29
+ getPowerShellExeItems } from './platform' ;
30
+
25
31
export enum SessionStatus {
26
32
NotStarted ,
27
33
Initializing ,
@@ -35,12 +41,12 @@ export class SessionManager implements Middleware {
35
41
private ShowSessionMenuCommandName = "PowerShell.ShowSessionMenu" ;
36
42
37
43
private hostVersion : string ;
38
- private isWindowsOS : boolean ;
39
44
private editorServicesArgs : string ;
40
45
private powerShellExePath : string = "" ;
41
46
private sessionStatus : SessionStatus ;
42
47
private suppressRestartPrompt : boolean ;
43
48
private focusConsoleOnExecute : boolean ;
49
+ private platformDetails : PlatformDetails ;
44
50
private extensionFeatures : IFeature [ ] = [ ] ;
45
51
private statusBarItem : vscode . StatusBarItem ;
46
52
private languageServerProcess : PowerShellProcess ;
@@ -61,7 +67,7 @@ export class SessionManager implements Middleware {
61
67
private requiredEditorServicesVersion : string ,
62
68
private log : Logger ) {
63
69
64
- this . isWindowsOS = os . platform ( ) == "win32" ;
70
+ this . platformDetails = getPlatformDetails ( ) ;
65
71
66
72
// Get the current version of this extension
67
73
this . hostVersion =
@@ -542,9 +548,53 @@ export class SessionManager implements Middleware {
542
548
this . sessionSettings . developer . powerShellExePath ||
543
549
"" ) . trim ( ) ;
544
550
551
+ if ( this . platformDetails . operatingSystem === OperatingSystem . Windows &&
552
+ powerShellExePath . length > 0 ) {
553
+
554
+ // Check the path bitness
555
+ let fixedPath =
556
+ fixWindowsPowerShellPath (
557
+ powerShellExePath ,
558
+ this . platformDetails ) ;
559
+
560
+ if ( fixedPath !== powerShellExePath ) {
561
+ let bitness = this . platformDetails . isOS64Bit ? 64 : 32 ;
562
+ // Show deprecation message with fix action.
563
+ // We don't need to wait on this to complete
564
+ // because we can finish gathering the configured
565
+ // PowerShell path without the fix
566
+ vscode
567
+ . window
568
+ . showWarningMessage (
569
+ `The specified PowerShell path is incorrect for ${ bitness } -bit VS Code, using '${ fixedPath } ' instead.` ,
570
+ "Fix Setting Automatically" )
571
+ . then ( choice => {
572
+ if ( choice ) {
573
+ this . suppressRestartPrompt = true ;
574
+ Settings
575
+ . change (
576
+ "powerShellExePath" ,
577
+ this . sessionSettings . developer . powerShellExePath ,
578
+ true )
579
+ . then ( ( ) => {
580
+ return Settings . change (
581
+ "developer.powerShellExePath" ,
582
+ undefined ,
583
+ true )
584
+ } )
585
+ . then ( ( ) => {
586
+ this . suppressRestartPrompt = false ;
587
+ } ) ;
588
+ }
589
+ } ) ;
590
+
591
+ powerShellExePath = fixedPath ;
592
+ }
593
+ }
594
+
545
595
return powerShellExePath . length > 0
546
596
? this . resolvePowerShellPath ( powerShellExePath )
547
- : this . getDefaultPowerShellPath ( this . sessionSettings . useX86Host ) ;
597
+ : getDefaultPowerShellPath ( this . platformDetails , this . sessionSettings . useX86Host ) ;
548
598
}
549
599
550
600
private changePowerShellExePath ( exePath : string ) {
@@ -554,78 +604,6 @@ export class SessionManager implements Middleware {
554
604
. then ( ( ) => this . restartSession ( ) ) ;
555
605
}
556
606
557
- private getPowerShellExeItems ( ) : PowerShellExeDetails [ ] {
558
-
559
- var paths : PowerShellExeDetails [ ] = [ ] ;
560
-
561
- if ( this . isWindowsOS ) {
562
- const is64Bit = process . env . hasOwnProperty ( 'PROCESSOR_ARCHITEW6432' ) ;
563
- const rootInstallPath = ( is64Bit ? process . env . ProgramW6432 : process . env . ProgramFiles ) + '\\PowerShell' ;
564
-
565
- if ( fs . existsSync ( rootInstallPath ) ) {
566
- var psCorePaths =
567
- fs . readdirSync ( rootInstallPath )
568
- . map ( item => path . join ( rootInstallPath , item ) )
569
- . filter ( item => fs . lstatSync ( item ) . isDirectory ( ) )
570
- . map ( item => {
571
- return {
572
- versionName : `PowerShell Core ${ path . parse ( item ) . base } ` ,
573
- exePath : path . join ( item , "powershell.exe" )
574
- } ;
575
- } ) ;
576
-
577
- if ( psCorePaths ) {
578
- paths = paths . concat ( psCorePaths ) ;
579
- }
580
- }
581
-
582
- if ( is64Bit ) {
583
- paths . push ( {
584
- versionName : "Windows PowerShell (x64)" ,
585
- exePath : process . env . windir + '\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe'
586
- } )
587
- }
588
-
589
- paths . push ( {
590
- versionName : "Windows PowerShell (x86)" ,
591
- exePath : process . env . windir + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
592
- } )
593
- }
594
- else {
595
- paths . push ( {
596
- versionName : "PowerShell Core" ,
597
- exePath :
598
- os . platform ( ) === "darwin"
599
- ? "/usr/local/bin/powershell"
600
- : "/usr/bin/powershell"
601
- } ) ;
602
- }
603
-
604
- return paths ;
605
- }
606
-
607
- private getDefaultPowerShellPath ( use32Bit : boolean ) : string | null {
608
-
609
- // Find the path to powershell.exe based on the current platform
610
- // and the user's desire to run the x86 version of PowerShell
611
- var powerShellExePath = undefined ;
612
-
613
- if ( this . isWindowsOS ) {
614
- powerShellExePath =
615
- use32Bit || ! process . env . hasOwnProperty ( 'PROCESSOR_ARCHITEW6432' )
616
- ? process . env . windir + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
617
- : process . env . windir + '\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe' ;
618
- }
619
- else if ( os . platform ( ) == "darwin" ) {
620
- powerShellExePath = "/usr/local/bin/powershell" ;
621
- }
622
- else {
623
- powerShellExePath = "/usr/bin/powershell" ;
624
- }
625
-
626
- return this . resolvePowerShellPath ( powerShellExePath ) ;
627
- }
628
-
629
607
private resolvePowerShellPath ( powerShellExePath : string ) : string {
630
608
var resolvedPath = path . resolve ( __dirname , powerShellExePath ) ;
631
609
@@ -679,7 +657,7 @@ export class SessionManager implements Middleware {
679
657
680
658
var currentExePath = this . powerShellExePath . toLowerCase ( ) ;
681
659
var powerShellItems =
682
- this . getPowerShellExeItems ( )
660
+ getPowerShellExeItems ( this . platformDetails )
683
661
. filter ( item => item . exePath . toLowerCase ( ) !== currentExePath )
684
662
. map ( item => {
685
663
return new SessionMenuItem (
@@ -748,11 +726,6 @@ export class SessionManager implements Middleware {
748
726
}
749
727
}
750
728
751
- interface PowerShellExeDetails {
752
- versionName : string ;
753
- exePath : string ;
754
- }
755
-
756
729
class SessionMenuItem implements vscode . QuickPickItem {
757
730
public description : string ;
758
731
0 commit comments