diff --git a/extensions/positron-python/src/client/positron/lsp.ts b/extensions/positron-python/src/client/positron/lsp.ts index 89853eaa2743..fcdd01430ada 100644 --- a/extensions/positron-python/src/client/positron/lsp.ts +++ b/extensions/positron-python/src/client/positron/lsp.ts @@ -349,6 +349,21 @@ export class PythonLsp implements vscode.Disposable { this._outputChannel.appendLine('Waiting for client to initialize before stopping'); await this._initializing; + // Suppress the "Connection to server got closed" toast that + // vscode-languageclient force-shows when the connection close races + // with `stop()`: if the socket close handler fires while `$state === + // Stopping` (between `connection.dispose()` and the `finally` block + // in `shutdown()`), our `PythonErrorHandler.closed()` is bypassed and + // the notification is forced. See posit-dev/positron#7593. + const origError = this._client.error.bind(this._client); + this._client.error = (message, data, showNotification) => { + if (typeof message === 'string' && /Connection to server got closed/.test(message)) { + origError(message, data, false); + return; + } + origError(message, data, showNotification); + }; + // Ideally we'd just wait for `this._client!.stop()`. In practice, the // promise returned by `stop()` never resolves if the server side is // disconnected, so rather than awaiting it when the runtime has exited, diff --git a/extensions/positron-r/src/lsp.ts b/extensions/positron-r/src/lsp.ts index ddffa7d8f67e..30bc7aeabca6 100644 --- a/extensions/positron-r/src/lsp.ts +++ b/extensions/positron-r/src/lsp.ts @@ -289,6 +289,21 @@ export class ArkLsp implements vscode.Disposable { // partially initialized client. await this._initializing; + // Suppress the "Connection to server got closed" toast that + // vscode-languageclient force-shows when the connection close races + // with `stop()`: if the socket close handler fires while `$state === + // Stopping` (between `connection.dispose()` and the `finally` block + // in `shutdown()`), our `RErrorHandler.closed()` is bypassed and the + // notification is forced. See posit-dev/positron#7593. + const origError = this.client.error.bind(this.client); + this.client.error = (message, data, showNotification) => { + if (typeof message === 'string' && /Connection to server got closed/.test(message)) { + origError(message, data, false); + return; + } + origError(message, data, showNotification); + }; + // Ideally we'd just wait for `this._client!.stop()`. In practice, the // promise returned by `stop()` never resolves if the server side is // disconnected, so rather than awaiting it when the runtime has exited, diff --git a/test/e2e/tests/notebooks-positron/notebook-kernel-behavior.test.ts b/test/e2e/tests/notebooks-positron/notebook-kernel-behavior.test.ts index a60a7efb6ce1..a945a7447fe2 100644 --- a/test/e2e/tests/notebooks-positron/notebook-kernel-behavior.test.ts +++ b/test/e2e/tests/notebooks-positron/notebook-kernel-behavior.test.ts @@ -146,10 +146,7 @@ test.describe('Positron Notebooks: Kernel Behavior', { }); }); - test.skip('ensure existing notebooks use their correct interpreter kernel', - { - annotation: [{ type: 'issue', description: 'https://github.com/posit-dev/positron/issues/7593' }] // <--- test is failing on chromium only - }, + test('ensure existing notebooks use their correct interpreter kernel', async function ({ app, sessions }) { const { notebooksPositron } = app.workbench; const pythonNotebook = path.join('workspaces', 'data-explorer-update-datasets', 'pandas-update-dataframe.ipynb');