Skip to content

Commit aac0fdb

Browse files
committed
Fix issues with switching and restarting the PowerShell session
This change fixes some issues with switching and restarting the active PowerShell session after our migration to the new vscode-languageclient package. They changed their error handling code in a way that caused our shutdown process to get stuck in a loop. Fixes #737 Fixes #782
1 parent adf7a1d commit aac0fdb

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"onCommand:PowerShell.SpecifyScriptArgs"
3535
],
3636
"dependencies": {
37-
"vscode-languageclient": "3.2.0"
37+
"vscode-languageclient": "^3.2.2"
3838
},
3939
"devDependencies": {
4040
"@types/node": "^6.0.40",

src/session.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import Settings = require('./settings');
1313

1414
import { Logger } from './logging';
1515
import { IFeature } from './feature';
16+
import { Message } from 'vscode-jsonrpc';
1617
import { StringDecoder } from 'string_decoder';
17-
import { LanguageClient, LanguageClientOptions, Executable, RequestType, RequestType0, NotificationType, StreamInfo } from 'vscode-languageclient';
18+
import { LanguageClient, LanguageClientOptions, Executable, RequestType, RequestType0, NotificationType, StreamInfo, ErrorAction, CloseAction } from 'vscode-languageclient';
1819

1920
export enum SessionStatus {
2021
NotStarted,
@@ -395,15 +396,13 @@ export class SessionManager {
395396

396397
vscode.window.onDidCloseTerminal(
397398
terminal => {
398-
this.log.write(os.EOL + "powershell.exe terminated or terminal UI was closed" + os.EOL);
399+
if (terminal === this.consoleTerminal) {
400+
this.log.write(os.EOL + "powershell.exe terminated or terminal UI was closed" + os.EOL);
399401

400-
if (this.languageServerClient != undefined) {
401-
this.languageServerClient.stop();
402-
}
403-
404-
if (this.sessionStatus === SessionStatus.Running) {
405-
this.setSessionStatus("Session exited", SessionStatus.Failed);
406-
this.promptForRestart();
402+
if (this.sessionStatus === SessionStatus.Running) {
403+
this.setSessionStatus("Session exited", SessionStatus.Failed);
404+
this.promptForRestart();
405+
}
407406
}
408407
});
409408

@@ -459,6 +458,19 @@ export class SessionManager {
459458
synchronize: {
460459
configurationSection: utils.PowerShellLanguageId,
461460
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
461+
},
462+
errorHandler: {
463+
// Override the default error handler to prevent it from
464+
// closing the LanguageClient incorrectly when the socket
465+
// hangs up (ECONNRESET errors).
466+
error: (error: any, message: Message, count: number): ErrorAction => {
467+
// TODO: Is there any error worth terminating on?
468+
return ErrorAction.Continue;
469+
},
470+
closed: () => {
471+
// We have our own restart experience
472+
return CloseAction.DoNotRestart
473+
}
462474
}
463475
}
464476

@@ -468,7 +480,6 @@ export class SessionManager {
468480
connectFunc,
469481
clientOptions);
470482

471-
472483
this.languageServerClient.onReady().then(
473484
() => {
474485
this.languageServerClient

0 commit comments

Comments
 (0)