File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed
packages/jupyterlab-lsp/src Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -294,21 +294,29 @@ export abstract class JupyterLabWidgetAdapter
294
294
this . on_foreign_document_opened ,
295
295
this
296
296
) ;
297
-
298
- await this . connect ( virtual_document ) . catch ( console . warn ) ;
297
+ return await this . connect ( virtual_document ) . catch ( console . warn ) ;
299
298
}
300
299
301
300
protected async on_foreign_document_opened (
302
301
host : VirtualDocument ,
303
302
context : IForeignContext
304
303
) {
305
304
const { foreign_document } = context ;
306
- this . connect_document ( foreign_document ) . catch ( console . warn ) ;
305
+
306
+ const connection_context = await this . connect_document ( foreign_document ) ;
307
307
308
308
foreign_document . foreign_document_closed . connect (
309
309
this . on_foreign_document_closed ,
310
310
this
311
311
) ;
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
+ }
312
320
}
313
321
314
322
on_foreign_document_closed ( host : VirtualDocument , context : IForeignContext ) {
@@ -453,6 +461,8 @@ export abstract class JupyterLabWidgetAdapter
453
461
adapter_features
454
462
) ;
455
463
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 ) ;
456
466
return adapter ;
457
467
}
458
468
Original file line number Diff line number Diff line change @@ -14,8 +14,26 @@ import { until_ready } from './utils';
14
14
interface ILSPOptions extends ILspOptions { }
15
15
16
16
export class LSPConnection extends LspWsConnection {
17
+ protected documentsToOpen : IDocumentInfo [ ] ;
18
+
17
19
constructor ( options : ILSPOptions ) {
18
20
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
+ }
19
37
}
20
38
21
39
public sendSelectiveChange (
Original file line number Diff line number Diff line change @@ -145,10 +145,6 @@ export class DocumentConnectionManager {
145
145
// be re-opened and synced
146
146
this . connections . set ( virtual_document . id_path , connection ) ;
147
147
148
- if ( connection . isReady ) {
149
- connection . sendOpen ( virtual_document . document_info ) ;
150
- }
151
-
152
148
return connection ;
153
149
}
154
150
@@ -183,7 +179,6 @@ export class DocumentConnectionManager {
183
179
184
180
connection . on ( 'serverInitialized' , capabilities => {
185
181
this . forEachDocumentOfConnection ( connection , virtual_document => {
186
- connection . sendOpen ( virtual_document . document_info ) ;
187
182
// TODO: is this still neccessary, e.g. for status bar to update responsively?
188
183
this . initialized . emit ( { connection, virtual_document } ) ;
189
184
} ) ;
You can’t perform that action at this time.
0 commit comments