From 213aa9509afbcfe31a08842d2ae17e130ac80bfd Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 16 Jan 2021 17:46:49 +0000 Subject: [PATCH 1/3] Retry connection for 5.5 minutes total rather than 40 seconds --- .../jupyterlab-lsp/src/connection_manager.ts | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/jupyterlab-lsp/src/connection_manager.ts b/packages/jupyterlab-lsp/src/connection_manager.ts index be5462d9c..68538a50c 100644 --- a/packages/jupyterlab-lsp/src/connection_manager.ts +++ b/packages/jupyterlab-lsp/src/connection_manager.ts @@ -278,7 +278,11 @@ export class DocumentConnectionManager { } } - async connect(options: ISocketConnectionOptions) { + async connect( + options: ISocketConnectionOptions, + firstTimeoutSeconds = 30, + secondTimeoutMinutes = 5 + ) { console.log('LSP: connection requested', options); let connection = await this.connect_socket(options); @@ -286,10 +290,31 @@ export class DocumentConnectionManager { if (!connection.isReady) { try { - await until_ready(() => connection.isReady, 200, 200); + // user feedback hinted that 40 seconds was too short and some users are willing to wait more; + // to make the best of both worlds we first check frequently (6.6 times a second) for the first + // 30 seconds, and show the warning early in case if something is wrong; we then continue retrying + // for another 5 minutes, but only once per second. + await until_ready( + () => connection.isReady, + Math.round((firstTimeoutSeconds * 1000) / 150), + 150 + ); } catch { - console.warn(`LSP: Connect timed out for ${virtual_document.uri}`); - return; + console.warn( + `LSP: Connection to ${virtual_document.uri} timed out after ${firstTimeoutSeconds} seconds, will continue retrying for another ${secondTimeoutMinutes} minutes` + ); + try { + await until_ready( + () => connection.isReady, + 60 * secondTimeoutMinutes, + 1000 + ); + } catch { + console.warn( + `LSP: Connection to ${virtual_document.uri} timed out again after ${secondTimeoutMinutes} minutes, giving up` + ); + return; + } } } From 319428c90d1795ed2ea62f8157f9188964322dc2 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 16 Jan 2021 17:47:12 +0000 Subject: [PATCH 2/3] Only claim that servers are missing if they really are --- .../src/components/statusbar.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/jupyterlab-lsp/src/components/statusbar.tsx b/packages/jupyterlab-lsp/src/components/statusbar.tsx index e23cf6492..8aef96f21 100644 --- a/packages/jupyterlab-lsp/src/components/statusbar.tsx +++ b/packages/jupyterlab-lsp/src/components/statusbar.tsx @@ -408,7 +408,7 @@ const shortMessageByStatus: StatusMap = { waiting: 'Waiting...', initialized: 'Fully initialized', initialized_but_some_missing: 'Initialized (additional servers needed)', - initializing: 'Partially initialized', + initializing: 'Initializing...', connecting: 'Connecting...' }; @@ -540,15 +540,23 @@ export namespace LSPStatus { let initialized_documents = new Set(); let absent_documents = new Set(); // detected documents with LSP servers available - let documents_with_servers = new Set(); + let documents_with_available_servers = new Set(); + // detected documents with LSP servers known + let documents_with_known_servers = new Set(); detected_documents.forEach((document, uri) => { let connection = this._connection_manager.connections.get(uri); + let server_id = this._connection_manager.language_server_manager.getServerId( + { language: document.language } + ); + if (server_id !== null) { + documents_with_known_servers.add(document); + } if (!connection) { absent_documents.add(document); return; } else { - documents_with_servers.add(document); + documents_with_available_servers.add(document); } if (connection.isConnected) { @@ -573,9 +581,14 @@ export namespace LSPStatus { status = 'waiting'; } else if (initialized_documents.size === detected_documents.size) { status = 'initialized'; - } else if (initialized_documents.size === documents_with_servers.size) { + } else if ( + initialized_documents.size === documents_with_available_servers.size && + detected_documents.size > documents_with_known_servers.size + ) { status = 'initialized_but_some_missing'; - } else if (connected_documents.size === documents_with_servers.size) { + } else if ( + connected_documents.size === documents_with_available_servers.size + ) { status = 'initializing'; } else { status = 'connecting'; From 2095a6fb49eeb52cd217fa3da90b66f7d2e29388 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 16 Jan 2021 18:06:18 +0000 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5692e37c..2e52d6065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,14 @@ - improved status icon contrast when status item is active ([#465]) - connection manager now properly keeps track of notebooks when multiple notebooks are open ([#474]) - new cells added after kernel restart now work properly; kernel changes are handled correctly ([#478]) + - increase total timeout for language server connection ([#479]) + - fix status communication during initialization ([#479]) [#449]: https://github.com/krassowski/jupyterlab-lsp/pull/449 [#465]: https://github.com/krassowski/jupyterlab-lsp/pull/465 [#474]: https://github.com/krassowski/jupyterlab-lsp/pull/474 [#478]: https://github.com/krassowski/jupyterlab-lsp/pull/478 +[#479]: https://github.com/krassowski/jupyterlab-lsp/pull/479 ### `jupyter-lsp 1.0.1` (unreleased)