Skip to content

Commit a128c36

Browse files
committed
Handle changes to powershell.cwd in restart prompt detection
1 parent 4473bd3 commit a128c36

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/features/UpdatePowerShell.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ export async function InvokePowerShellUpdateCheck(
164164
// Invoke the MSI via cmd.
165165
const msi = spawn("msiexec", ["/i", msiDownloadPath]);
166166

167-
msi.on("close", (code) => {
167+
msi.on("close", async () => {
168168
// Now that the MSI is finished, start the Integrated Console session.
169-
sessionManager.start();
169+
await sessionManager.start();
170170
fs.unlinkSync(msiDownloadPath);
171171
});
172172

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
172172
sessionManager.setLanguageClientConsumers(languageClientConsumers);
173173

174174
if (extensionSettings.startAutomatically) {
175-
sessionManager.start();
175+
await sessionManager.start();
176176
}
177177

178178
return {

src/session.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ export class SessionManager implements Middleware {
103103
this.languageClientConsumers = languageClientConsumers;
104104
}
105105

106-
public start(exeNameOverride?: string) {
106+
public async start(exeNameOverride?: string) {
107+
await Settings.validateCwdSetting();
107108
this.sessionSettings = Settings.load();
109+
108110
if (exeNameOverride) {
109111
this.sessionSettings.powerShellDefaultVersion = exeNameOverride;
110112
}
@@ -240,9 +242,9 @@ export class SessionManager implements Middleware {
240242
this.sessionStatus = SessionStatus.NotStarted;
241243
}
242244

243-
public restartSession(exeNameOverride?: string) {
245+
public async restartSession(exeNameOverride?: string) {
244246
this.stop();
245-
this.start(exeNameOverride);
247+
await this.start(exeNameOverride);
246248
}
247249

248250
public getSessionDetails(): utils.IEditorServicesSessionDetails {
@@ -387,14 +389,16 @@ export class SessionManager implements Middleware {
387389
}
388390
}
389391

390-
private onConfigurationUpdated() {
392+
private async onConfigurationUpdated() {
391393
const settings = Settings.load();
392394

393395
this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute;
394396

395397
// Detect any setting changes that would affect the session
396398
if (!this.suppressRestartPrompt &&
397-
(settings.powerShellDefaultVersion.toLowerCase() !==
399+
(settings.cwd.toLowerCase() !==
400+
this.sessionSettings.cwd.toLowerCase() ||
401+
settings.powerShellDefaultVersion.toLowerCase() !==
398402
this.sessionSettings.powerShellDefaultVersion.toLowerCase() ||
399403
settings.developer.editorServicesLogLevel.toLowerCase() !==
400404
this.sessionSettings.developer.editorServicesLogLevel.toLowerCase() ||
@@ -403,14 +407,13 @@ export class SessionManager implements Middleware {
403407
settings.integratedConsole.useLegacyReadLine !==
404408
this.sessionSettings.integratedConsole.useLegacyReadLine)) {
405409

406-
vscode.window.showInformationMessage(
410+
const response: string = await vscode.window.showInformationMessage(
407411
"The PowerShell runtime configuration has changed, would you like to start a new session?",
408-
"Yes", "No")
409-
.then((response) => {
412+
"Yes", "No");
413+
410414
if (response === "Yes") {
411-
this.restartSession();
415+
await this.restartSession();
412416
}
413-
});
414417
}
415418
}
416419

@@ -433,7 +436,7 @@ export class SessionManager implements Middleware {
433436
this.registeredCommands = [
434437
vscode.commands.registerCommand("PowerShell.RestartSession", () => { this.restartSession(); }),
435438
vscode.commands.registerCommand(this.ShowSessionMenuCommandName, () => { this.showSessionMenu(); }),
436-
vscode.workspace.onDidChangeConfiguration(() => this.onConfigurationUpdated()),
439+
vscode.workspace.onDidChangeConfiguration(async () => { await this.onConfigurationUpdated(); }),
437440
vscode.commands.registerCommand(
438441
"PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionConsole(isExecute); }),
439442
];
@@ -457,10 +460,10 @@ export class SessionManager implements Middleware {
457460
this.sessionSettings);
458461

459462
this.languageServerProcess.onExited(
460-
() => {
463+
async () => {
461464
if (this.sessionStatus === SessionStatus.Running) {
462465
this.setSessionStatus("Session Exited", SessionStatus.Failed);
463-
this.promptForRestart();
466+
await this.promptForRestart();
464467
}
465468
});
466469

@@ -503,11 +506,14 @@ export class SessionManager implements Middleware {
503506
});
504507
}
505508

506-
private promptForRestart() {
507-
vscode.window.showErrorMessage(
509+
private async promptForRestart() {
510+
const response: string = await vscode.window.showErrorMessage(
508511
"The PowerShell Integrated Console (PSIC) has stopped, would you like to restart it? (IntelliSense will not work unless the PSIC is active and unblocked.)",
509-
"Yes", "No")
510-
.then((answer) => { if (answer === "Yes") { this.restartSession(); }});
512+
"Yes", "No");
513+
514+
if (response === "Yes") {
515+
await this.restartSession();
516+
}
511517
}
512518

513519
private startLanguageClient(sessionDetails: utils.IEditorServicesSessionDetails) {
@@ -756,7 +762,7 @@ export class SessionManager implements Middleware {
756762
// rather than pull from the settings. The issue we prevent here is when a
757763
// workspace setting is defined which gets priority over user settings which
758764
// is what the change above sets.
759-
this.restartSession(exePath.displayName);
765+
await this.restartSession(exePath.displayName);
760766
}
761767

762768
private showSessionConsole(isExecute?: boolean) {
@@ -817,10 +823,10 @@ export class SessionManager implements Middleware {
817823

818824
new SessionMenuItem(
819825
"Restart Current Session",
820-
() => {
826+
async () => {
821827
// We pass in the display name so we guarantee that the session
822828
// will be the same PowerShell.
823-
this.restartSession(this.PowerShellExeDetails.displayName);
829+
await this.restartSession(this.PowerShellExeDetails.displayName);
824830
}),
825831

826832
new SessionMenuItem(

src/settings.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import vscode = require("vscode");
77
import utils = require("./utils");
8+
import os = require("os");
89

910
enum CodeFormattingPreset {
1011
Custom,
@@ -333,7 +334,7 @@ export async function validateCwdSetting(): Promise<string> {
333334
// If there were no workspace folders, or somehow they don't exist, use
334335
// the home directory.
335336
if (cwd === undefined || !utils.checkIfDirectoryExists(cwd)) {
336-
return process.cwd();
337+
return os.homedir();
337338
}
338339
return cwd;
339340
}

0 commit comments

Comments
 (0)