@@ -13,7 +13,7 @@ import {
1313 IDocumentConnectionData ,
1414 ISocketConnectionOptions
1515} from '../connection_manager' ;
16- import { ILSPExtension } from '../index' ;
16+ import { ILSPExtension , ILSPLogConsole } from '../index' ;
1717import { IFeatureEditorIntegration , IFeature } from '../feature' ;
1818import { EditorAdapter } from '../editor_integration/editor_adapter' ;
1919import IEditor = CodeEditor . IEditor ;
@@ -92,6 +92,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
9292 public connection_manager : DocumentConnectionManager ;
9393 public status_message : StatusMessage ;
9494 protected isDisposed = false ;
95+ console : ILSPLogConsole ;
9596
9697 protected app : JupyterFrontEnd ;
9798
@@ -124,6 +125,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
124125 this . adapters = new Map ( ) ;
125126 this . status_message = new StatusMessage ( ) ;
126127 this . isConnected = false ;
128+ this . console = extension . console . scope ( 'WidgetAdapter' ) ;
127129
128130 // set up signal connections
129131 this . widget . context . saveState . connect ( this . on_save_state , this ) ;
@@ -143,8 +145,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
143145 manager : DocumentConnectionManager ,
144146 { virtual_document } : IDocumentConnectionData
145147 ) {
146- console . log (
147- 'LSP: connection closed, disconnecting adapter' ,
148+ this . console . log (
149+ 'connection closed, disconnecting adapter' ,
148150 virtual_document . id_path
149151 ) ;
150152 if ( virtual_document !== this . virtual_editor ?. virtual_document ) {
@@ -245,7 +247,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
245247
246248 // reconnect
247249 this . connect_document ( this . virtual_editor . virtual_document , true ) . catch (
248- console . warn
250+ this . console . warn
249251 ) ;
250252 }
251253
@@ -273,7 +275,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
273275 */
274276 public update_documents ( ) {
275277 if ( this . isDisposed ) {
276- console . warn ( 'Cannot update documents: adapter disposed' ) ;
278+ this . console . warn ( 'Cannot update documents: adapter disposed' ) ;
277279 return ;
278280 }
279281 return this . virtual_editor . virtual_document . update_manager . update_documents (
@@ -301,8 +303,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
301303 // refresh the document on the LSP server
302304 this . document_changed ( virtual_document , virtual_document , true ) ;
303305
304- console . log (
305- 'LSP: virtual document(s) for' ,
306+ this . console . log (
307+ 'virtual document(s) for' ,
306308 this . document_path ,
307309 'have been initialized'
308310 ) ;
@@ -329,7 +331,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
329331 ) ;
330332
331333 const connection_context = await this . connect ( virtual_document ) . catch (
332- console . warn
334+ this . console . warn
333335 ) ;
334336
335337 if ( ! send_open ) {
@@ -341,7 +343,9 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
341343 virtual_document . document_info
342344 ) ;
343345 } else {
344- console . warn ( `Connection for ${ virtual_document . path } was not opened` ) ;
346+ this . console . warn (
347+ `Connection for ${ virtual_document . path } was not opened`
348+ ) ;
345349 }
346350 }
347351
@@ -364,7 +368,10 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
364368 virtual_document : this . create_virtual_document ( )
365369 } ) ;
366370 if ( virtual_editor == null ) {
367- console . error ( 'Could not initialize a VirtualEditor for adapter: ' , this ) ;
371+ this . console . error (
372+ 'Could not initialize a VirtualEditor for adapter: ' ,
373+ this
374+ ) ;
368375 return ;
369376 }
370377 this . virtual_editor = virtual_editor ;
@@ -414,7 +421,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
414421 is_init = false
415422 ) {
416423 if ( this . isDisposed ) {
417- console . warn ( 'Cannot swap document: adapter disposed' ) ;
424+ this . console . warn ( 'Cannot swap document: adapter disposed' ) ;
418425 return ;
419426 }
420427
@@ -425,11 +432,11 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
425432 let adapter = this . adapters . get ( virtual_document . id_path ) ;
426433
427434 if ( ! connection ?. isReady ) {
428- console . log ( 'LSP: Skipping document update signal: connection not ready' ) ;
435+ this . console . log ( 'Skipping document update signal: connection not ready' ) ;
429436 return ;
430437 }
431438 if ( adapter == null ) {
432- console . log ( 'LSP: Skipping document update signal: adapter not ready' ) ;
439+ this . console . log ( 'Skipping document update signal: adapter not ready' ) ;
433440 return ;
434441 }
435442
@@ -456,7 +463,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
456463 await adapter . updateAfterChange ( ) ;
457464 } )
458465 . then ( )
459- . catch ( console . warn ) ;
466+ . catch ( this . console . warn ) ;
460467 }
461468 }
462469
@@ -486,7 +493,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
486493 private async connect ( virtual_document : VirtualDocument ) {
487494 let language = virtual_document . language ;
488495
489- console . log ( `LSP: will connect using language: ${ language } ` ) ;
496+ this . console . log ( `will connect using language: ${ language } ` ) ;
490497
491498 let options : ISocketConnectionOptions = {
492499 virtual_document,
@@ -553,17 +560,18 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
553560 let adapter = new EditorAdapter (
554561 this . virtual_editor ,
555562 virtual_document ,
556- adapter_features
563+ adapter_features ,
564+ this . console
557565 ) ;
558- console . log ( 'LSP: Adapter for' , this . document_path , 'is ready.' ) ;
566+ this . console . log ( 'Adapter for' , this . document_path , 'is ready.' ) ;
559567 // the client is now fully ready: signal to the server that the document is "open"
560568 connection . sendOpenWhenReady ( virtual_document . document_info ) ;
561569 return adapter ;
562570 }
563571
564572 private async onContentChanged ( _slot : any ) {
565573 // update the virtual documents (sending the updates to LSP is out of scope here)
566- this . update_finished = this . update_documents ( ) . catch ( console . warn ) ;
574+ this . update_finished = this . update_documents ( ) . catch ( this . console . warn ) ;
567575 await this . update_finished ;
568576 }
569577
0 commit comments