Skip to content

Commit 027b84e

Browse files
authored
Merge pull request #479 from krassowski/fix-connection-timeout-and-status
Increase connection timeout and improve status for initialization
2 parents a06e806 + 90c9576 commit 027b84e

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
- improved status icon contrast when status item is active ([#465])
1616
- connection manager now properly keeps track of notebooks when multiple notebooks are open ([#474])
1717
- new cells added after kernel restart now work properly; kernel changes are handled correctly ([#478])
18+
- increase total timeout for language server connection ([#479])
19+
- fix status communication during initialization ([#479])
1820

1921
[#449]: https://github.com/krassowski/jupyterlab-lsp/pull/449
2022
[#465]: https://github.com/krassowski/jupyterlab-lsp/pull/465
2123
[#474]: https://github.com/krassowski/jupyterlab-lsp/pull/474
2224
[#476]: https://github.com/krassowski/jupyterlab-lsp/pull/476
2325
[#478]: https://github.com/krassowski/jupyterlab-lsp/pull/478
26+
[#479]: https://github.com/krassowski/jupyterlab-lsp/pull/479
2427
[#480]: https://github.com/krassowski/jupyterlab-lsp/pull/480
2528
[#481]: https://github.com/krassowski/jupyterlab-lsp/pull/481
2629

packages/jupyterlab-lsp/src/components/statusbar.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ const shortMessageByStatus: StatusMap = {
423423
waiting: 'Waiting...',
424424
initialized: 'Fully initialized',
425425
initialized_but_some_missing: 'Initialized (additional servers needed)',
426-
initializing: 'Partially initialized',
426+
initializing: 'Initializing...',
427427
connecting: 'Connecting...'
428428
};
429429

@@ -555,15 +555,23 @@ export namespace LSPStatus {
555555
let initialized_documents = new Set<VirtualDocument>();
556556
let absent_documents = new Set<VirtualDocument>();
557557
// detected documents with LSP servers available
558-
let documents_with_servers = new Set<VirtualDocument>();
558+
let documents_with_available_servers = new Set<VirtualDocument>();
559+
// detected documents with LSP servers known
560+
let documents_with_known_servers = new Set<VirtualDocument>();
559561

560562
detected_documents.forEach((document, uri) => {
561563
let connection = this._connection_manager.connections.get(uri);
564+
let server_id = this._connection_manager.language_server_manager.getServerId(
565+
{ language: document.language }
566+
);
567+
if (server_id !== null) {
568+
documents_with_known_servers.add(document);
569+
}
562570
if (!connection) {
563571
absent_documents.add(document);
564572
return;
565573
} else {
566-
documents_with_servers.add(document);
574+
documents_with_available_servers.add(document);
567575
}
568576

569577
if (connection.isConnected) {
@@ -590,9 +598,14 @@ export namespace LSPStatus {
590598
status = 'waiting';
591599
} else if (initialized_documents.size === detected_documents.size) {
592600
status = 'initialized';
593-
} else if (initialized_documents.size === documents_with_servers.size) {
601+
} else if (
602+
initialized_documents.size === documents_with_available_servers.size &&
603+
detected_documents.size > documents_with_known_servers.size
604+
) {
594605
status = 'initialized_but_some_missing';
595-
} else if (connected_documents.size === documents_with_servers.size) {
606+
} else if (
607+
connected_documents.size === documents_with_available_servers.size
608+
) {
596609
status = 'initializing';
597610
} else {
598611
status = 'connecting';

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,43 @@ export class DocumentConnectionManager {
283283
}
284284
}
285285

286-
async connect(options: ISocketConnectionOptions) {
286+
async connect(
287+
options: ISocketConnectionOptions,
288+
firstTimeoutSeconds = 30,
289+
secondTimeoutMinutes = 5
290+
) {
287291
this.console.log('connection requested', options);
288292
let connection = await this.connect_socket(options);
289293

290294
let { virtual_document, document_path } = options;
291295

292296
if (!connection.isReady) {
293297
try {
294-
await until_ready(() => connection.isReady, 200, 200);
298+
// user feedback hinted that 40 seconds was too short and some users are willing to wait more;
299+
// to make the best of both worlds we first check frequently (6.6 times a second) for the first
300+
// 30 seconds, and show the warning early in case if something is wrong; we then continue retrying
301+
// for another 5 minutes, but only once per second.
302+
await until_ready(
303+
() => connection.isReady,
304+
Math.round((firstTimeoutSeconds * 1000) / 150),
305+
150
306+
);
295307
} catch {
296-
this.console.warn(`Connect timed out for ${virtual_document.uri}`);
297-
return;
308+
this.console.warn(
309+
`LSP: Connection to ${virtual_document.uri} timed out after ${firstTimeoutSeconds} seconds, will continue retrying for another ${secondTimeoutMinutes} minutes`
310+
);
311+
try {
312+
await until_ready(
313+
() => connection.isReady,
314+
60 * secondTimeoutMinutes,
315+
1000
316+
);
317+
} catch {
318+
this.console.warn(
319+
`LSP: Connection to ${virtual_document.uri} timed out again after ${secondTimeoutMinutes} minutes, giving up`
320+
);
321+
return;
322+
}
298323
}
299324
}
300325

0 commit comments

Comments
 (0)