@@ -123,12 +123,17 @@ export class DocumentConnectionManager {
123
123
language
124
124
) ;
125
125
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.
126
129
const connection = await Private . connection (
127
130
language ,
128
131
uris ,
129
132
this . on_new_connection
130
133
) ;
131
134
135
+ // if connecting for the first time, all documents subsequent documents will
136
+ // be re-opened and synced
132
137
this . connections . set ( virtual_document . id_path , connection ) ;
133
138
134
139
if ( connection . isReady ) {
@@ -138,6 +143,11 @@ export class DocumentConnectionManager {
138
143
return connection ;
139
144
}
140
145
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
+ */
141
151
on_new_connection = ( connection : LSPConnection ) => {
142
152
connection . on ( 'error' , e => {
143
153
console . warn ( e ) ;
@@ -165,6 +175,7 @@ export class DocumentConnectionManager {
165
175
connection . on ( 'serverInitialized' , capabilities => {
166
176
this . forEachDocumentOfConnection ( connection , virtual_document => {
167
177
connection . sendOpen ( virtual_document . document_info ) ;
178
+ // TODO: is this still neccessary, e.g. for status bar to update responsively?
168
179
this . initialized . emit ( { connection, virtual_document } ) ;
169
180
} ) ;
170
181
} ) ;
@@ -196,6 +207,10 @@ export class DocumentConnectionManager {
196
207
}
197
208
}
198
209
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
+ */
199
214
public async retry_to_connect (
200
215
options : ISocketConnectionOptions ,
201
216
reconnect_delay : number ,
@@ -286,16 +301,24 @@ export namespace DocumentConnectionManager {
286
301
}
287
302
}
288
303
304
+ /**
305
+ * Namespace primarily for language-keyed cache of LSPConnections
306
+ */
289
307
namespace Private {
290
308
const _connections = new Map < string , LSPConnection > ( ) ;
291
309
let _promise : Promise < typeof ConnectionModuleType > ;
292
310
311
+ /**
312
+ * Return (or create and initialize) the WebSocket associated with the language
313
+ */
293
314
export async function connection (
294
315
language : string ,
295
316
uris : DocumentConnectionManager . IURIs ,
296
317
onCreate : ( connection : LSPConnection ) => void
297
318
) : Promise < LSPConnection > {
298
319
if ( _promise == null ) {
320
+ // TODO: consider lazy-loading _only_ the modules that _must_ be webpacked
321
+ // with custom shims, e.g. `fs`
299
322
_promise = import (
300
323
/* webpackChunkName: "jupyter-lsp-connection" */ './connection'
301
324
) ;
0 commit comments