Skip to content

Commit cb70032

Browse files
committed
Fix connection error notification on restart
1 parent 00c11b3 commit cb70032

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

  • extensions
    • positron-python/src/client/positron
    • positron-r/src

extensions/positron-python/src/client/positron/lsp.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,21 @@ export class PythonLsp implements vscode.Disposable {
349349
this._outputChannel.appendLine('Waiting for client to initialize before stopping');
350350
await this._initializing;
351351

352+
// Suppress the "Connection to server got closed" toast that
353+
// vscode-languageclient force-shows when the connection close races
354+
// with `stop()`: if the socket close handler fires while `$state ===
355+
// Stopping` (between `connection.dispose()` and the `finally` block
356+
// in `shutdown()`), our `PythonErrorHandler.closed()` is bypassed and
357+
// the notification is forced. See posit-dev/positron#7593.
358+
const origError = this._client.error.bind(this._client);
359+
this._client.error = (message, data, showNotification) => {
360+
if (typeof message === 'string' && /Connection to server got closed/.test(message)) {
361+
origError(message, data, false);
362+
return;
363+
}
364+
origError(message, data, showNotification);
365+
};
366+
352367
// Ideally we'd just wait for `this._client!.stop()`. In practice, the
353368
// promise returned by `stop()` never resolves if the server side is
354369
// disconnected, so rather than awaiting it when the runtime has exited,

extensions/positron-r/src/lsp.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ export class ArkLsp implements vscode.Disposable {
289289
// partially initialized client.
290290
await this._initializing;
291291

292+
// Suppress the "Connection to server got closed" toast that
293+
// vscode-languageclient force-shows when the connection close races
294+
// with `stop()`: if the socket close handler fires while `$state ===
295+
// Stopping` (between `connection.dispose()` and the `finally` block
296+
// in `shutdown()`), our `RErrorHandler.closed()` is bypassed and the
297+
// notification is forced. See posit-dev/positron#7593.
298+
const origError = this.client.error.bind(this.client);
299+
this.client.error = (message, data, showNotification) => {
300+
if (typeof message === 'string' && /Connection to server got closed/.test(message)) {
301+
origError(message, data, false);
302+
return;
303+
}
304+
origError(message, data, showNotification);
305+
};
306+
292307
// Ideally we'd just wait for `this._client!.stop()`. In practice, the
293308
// promise returned by `stop()` never resolves if the server side is
294309
// disconnected, so rather than awaiting it when the runtime has exited,

0 commit comments

Comments
 (0)