Skip to content

Commit 251c495

Browse files
committed
Update startup logic to handle session failure reasons
These used to be sent given that the logic existed, but the server was no longer sending them at all. Now that it does, we can handle them.
1 parent 9cf9c5d commit 251c495

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/session.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export enum RunspaceType {
4444
export interface IEditorServicesSessionDetails {
4545
status: string;
4646
reason: string;
47-
detail: string;
4847
powerShellVersion: string;
4948
channel: string;
5049
languageServicePort: number;
@@ -430,7 +429,7 @@ export class SessionManager implements Middleware {
430429

431430
private async startPowerShell(): Promise<PowerShellProcess | undefined> {
432431
if (this.PowerShellExeDetails === undefined) {
433-
this.setSessionFailure("Unable to find PowerShell.");
432+
void this.setSessionFailedGetPowerShell("Unable to find PowerShell, try installing it?");
434433
return;
435434
}
436435

@@ -498,10 +497,10 @@ export class SessionManager implements Middleware {
498497
void this.setSessionFailedOpenBug("Language client failed to start: " + (err instanceof Error ? err.message : "unknown"));
499498
}
500499
} else if (this.sessionDetails.status === "failed") { // Server started but indicated it failed
501-
if (this.sessionDetails.reason === "unsupported") {
500+
if (this.sessionDetails.reason === "powerShellVersion") {
502501
void this.setSessionFailedGetPowerShell(`PowerShell ${this.sessionDetails.powerShellVersion} is not supported, please update!`);
503-
} else if (this.sessionDetails.reason === "languageMode") {
504-
this.setSessionFailure(`PowerShell language features are disabled due to an unsupported LanguageMode: ${this.sessionDetails.detail}`);
502+
} else if (this.sessionDetails.reason === "dotNetVersion") { // Only applies to PowerShell 5.1
503+
void this.setSessionFailedGetDotNet(".NET Framework is out-of-date, please install at least 4.8!");
505504
} else {
506505
void this.setSessionFailedOpenBug(`PowerShell could not be started for an unknown reason: ${this.sessionDetails.reason}`);
507506
}
@@ -728,7 +727,7 @@ Type 'help' to get help.
728727
try {
729728
await this.languageClient.start();
730729
} catch (err) {
731-
this.setSessionFailure("Could not start language service: ", err instanceof Error ? err.message : "unknown");
730+
void this.setSessionFailedOpenBug("Could not start language service: " + (err instanceof Error ? err.message : "unknown"));
732731
return;
733732
}
734733

@@ -799,11 +798,6 @@ Type 'help' to get help.
799798
this.setSessionStatus("Executing...", SessionStatus.Busy);
800799
}
801800

802-
private setSessionFailure(message: string, ...additionalMessages: string[]): void {
803-
this.setSessionStatus("Initialization Error!", SessionStatus.Failed);
804-
void this.logger.writeAndShowError(message, ...additionalMessages);
805-
}
806-
807801
private async setSessionFailedOpenBug(message: string): Promise<void> {
808802
this.setSessionStatus("Initialization Error!", SessionStatus.Failed);
809803
await this.logger.writeAndShowErrorWithActions(message, [{
@@ -825,6 +819,17 @@ Type 'help' to get help.
825819
);
826820
}
827821

822+
private async setSessionFailedGetDotNet(message: string): Promise<void> {
823+
this.setSessionStatus("Initialization Error!", SessionStatus.Failed);
824+
await this.logger.writeAndShowErrorWithActions(message, [{
825+
prompt: "Open .NET Framework Documentation",
826+
action: async (): Promise<void> => {
827+
await vscode.env.openExternal(
828+
vscode.Uri.parse("https://dotnet.microsoft.com/en-us/download/dotnet-framework"));
829+
}}]
830+
);
831+
}
832+
828833
private async changePowerShellDefaultVersion(exePath: IPowerShellExeDetails): Promise<void> {
829834
this.suppressRestartPrompt = true;
830835
try {

0 commit comments

Comments
 (0)