Skip to content

Commit 01786d7

Browse files
committed
add open queue to connection, trigger from adapter instead of connection manager
1 parent f294ffb commit 01786d7

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

packages/jupyterlab-lsp/src/adapters/jupyterlab/jl_adapter.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,29 @@ export abstract class JupyterLabWidgetAdapter
294294
this.on_foreign_document_opened,
295295
this
296296
);
297-
298-
await this.connect(virtual_document).catch(console.warn);
297+
return await this.connect(virtual_document).catch(console.warn);
299298
}
300299

301300
protected async on_foreign_document_opened(
302301
host: VirtualDocument,
303302
context: IForeignContext
304303
) {
305304
const { foreign_document } = context;
306-
this.connect_document(foreign_document).catch(console.warn);
305+
306+
const connection_context = await this.connect_document(foreign_document);
307307

308308
foreign_document.foreign_document_closed.connect(
309309
this.on_foreign_document_closed,
310310
this
311311
);
312+
313+
if (connection_context) {
314+
connection_context.connection.sendOpenWhenReady(
315+
foreign_document.document_info
316+
);
317+
} else {
318+
console.warn(`Connection for ${foreign_document.path} was not be opened`);
319+
}
312320
}
313321

314322
on_foreign_document_closed(host: VirtualDocument, context: IForeignContext) {
@@ -453,6 +461,8 @@ export abstract class JupyterLabWidgetAdapter
453461
adapter_features
454462
);
455463
console.log('LSP: Adapter for', this.document_path, 'is ready.');
464+
// the client is now fully ready: signal to the server that the document is "open"
465+
connection.sendOpenWhenReady(virtual_document.document_info);
456466
return adapter;
457467
}
458468

packages/jupyterlab-lsp/src/connection.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,26 @@ import { until_ready } from './utils';
1414
interface ILSPOptions extends ILspOptions {}
1515

1616
export class LSPConnection extends LspWsConnection {
17+
protected documentsToOpen: IDocumentInfo[];
18+
1719
constructor(options: ILSPOptions) {
1820
super(options);
21+
this.documentsToOpen = [];
22+
}
23+
24+
sendOpenWhenReady(documentInfo: IDocumentInfo) {
25+
if (this.isReady) {
26+
this.sendOpen(documentInfo);
27+
} else {
28+
this.documentsToOpen.push(documentInfo);
29+
}
30+
}
31+
32+
protected onServerInitialized(params: lsProtocol.InitializeResult) {
33+
super.onServerInitialized(params);
34+
while (this.documentsToOpen.length) {
35+
this.sendOpen(this.documentsToOpen.pop());
36+
}
1937
}
2038

2139
public sendSelectiveChange(

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ export class DocumentConnectionManager {
145145
// be re-opened and synced
146146
this.connections.set(virtual_document.id_path, connection);
147147

148-
if (connection.isReady) {
149-
connection.sendOpen(virtual_document.document_info);
150-
}
151-
152148
return connection;
153149
}
154150

@@ -183,7 +179,6 @@ export class DocumentConnectionManager {
183179

184180
connection.on('serverInitialized', capabilities => {
185181
this.forEachDocumentOfConnection(connection, virtual_document => {
186-
connection.sendOpen(virtual_document.document_info);
187182
// TODO: is this still neccessary, e.g. for status bar to update responsively?
188183
this.initialized.emit({ connection, virtual_document });
189184
});

0 commit comments

Comments
 (0)