Skip to content

Commit 02569d3

Browse files
committed
some docs and todos on connection manager
1 parent 9e7337f commit 02569d3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,17 @@ export class DocumentConnectionManager {
123123
language
124124
);
125125

126+
// lazily load 1) the underlying library (1.5mb) and/or 2) a live WebSocket-
127+
// like connection: either already connected or potentiailly in the process
128+
// of connecting.
126129
const connection = await Private.connection(
127130
language,
128131
uris,
129132
this.on_new_connection
130133
);
131134

135+
// if connecting for the first time, all documents subsequent documents will
136+
// be re-opened and synced
132137
this.connections.set(virtual_document.id_path, connection);
133138

134139
if (connection.isReady) {
@@ -138,6 +143,11 @@ export class DocumentConnectionManager {
138143
return connection;
139144
}
140145

146+
/**
147+
* Fired the first time a connection is opened. These _should_ be the only
148+
* invocation of `.on` (once remaining LSPFeature.connection_handlers are made
149+
* singletons).
150+
*/
141151
on_new_connection = (connection: LSPConnection) => {
142152
connection.on('error', e => {
143153
console.warn(e);
@@ -165,6 +175,7 @@ export class DocumentConnectionManager {
165175
connection.on('serverInitialized', capabilities => {
166176
this.forEachDocumentOfConnection(connection, virtual_document => {
167177
connection.sendOpen(virtual_document.document_info);
178+
// TODO: is this still neccessary, e.g. for status bar to update responsively?
168179
this.initialized.emit({ connection, virtual_document });
169180
});
170181
});
@@ -196,6 +207,10 @@ export class DocumentConnectionManager {
196207
}
197208
}
198209

210+
/**
211+
* TODO: presently no longer referenced. A failing connection would close
212+
* the socket, triggering the language server on the other end to exit
213+
*/
199214
public async retry_to_connect(
200215
options: ISocketConnectionOptions,
201216
reconnect_delay: number,
@@ -286,16 +301,24 @@ export namespace DocumentConnectionManager {
286301
}
287302
}
288303

304+
/**
305+
* Namespace primarily for language-keyed cache of LSPConnections
306+
*/
289307
namespace Private {
290308
const _connections = new Map<string, LSPConnection>();
291309
let _promise: Promise<typeof ConnectionModuleType>;
292310

311+
/**
312+
* Return (or create and initialize) the WebSocket associated with the language
313+
*/
293314
export async function connection(
294315
language: string,
295316
uris: DocumentConnectionManager.IURIs,
296317
onCreate: (connection: LSPConnection) => void
297318
): Promise<LSPConnection> {
298319
if (_promise == null) {
320+
// TODO: consider lazy-loading _only_ the modules that _must_ be webpacked
321+
// with custom shims, e.g. `fs`
299322
_promise = import(
300323
/* webpackChunkName: "jupyter-lsp-connection" */ './connection'
301324
);

0 commit comments

Comments
 (0)