File tree Expand file tree Collapse file tree
positron-python/src/client/positron Expand file tree Collapse file tree Original file line number Diff line number Diff 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' && / C o n n e c t i o n t o s e r v e r g o t c l o s e d / . 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,
Original file line number Diff line number Diff 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' && / C o n n e c t i o n t o s e r v e r g o t c l o s e d / . 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,
You can’t perform that action at this time.
0 commit comments