22// ISC licence is, quote, "functionally equivalent to the simplified BSD and MIT licenses,
33// but without language deemed unnecessary following the Berne Convention." (Wikipedia).
44// Introduced modifications are BSD licenced, copyright JupyterLab development team.
5+ import { Signal } from '@lumino/signaling' ;
56import {
67 IDocumentInfo ,
78 ILspOptions ,
89 IPosition ,
910 LspWsConnection
1011} from 'lsp-ws-connection' ;
11- import * as lsProtocol from 'vscode-languageserver-protocol' ;
12+ import type * as rpc from 'vscode-jsonrpc' ;
13+ import type * as lsProtocol from 'vscode-languageserver-protocol' ;
1214
1315import { until_ready } from './utils' ;
1416
1517interface ILSPOptions extends ILspOptions {
1618 serverIdentifier ?: string ;
1719}
1820
21+ interface ConnectionSignal < T > extends Signal < LSPConnection , T > {
22+ // empty
23+ }
24+
25+ interface INamespace {
26+ [ index : string ] : ConnectionSignal < any > | ( ( params : any ) => void ) ;
27+ }
28+
29+ interface ILSPNotifications {
30+ $ : {
31+ logTrace : ConnectionSignal < rpc . LogTraceParams > ;
32+ setTrace : ( params : rpc . SetTraceParams ) => void ;
33+ } ;
34+ window : {
35+ showMessage : ConnectionSignal < lsProtocol . ShowMessageParams > ;
36+ logMessage : ConnectionSignal < lsProtocol . LogMessageParams > ;
37+ } ;
38+ [ index : string ] : INamespace ;
39+ }
40+
1941export class LSPConnection extends LspWsConnection {
2042 protected documentsToOpen : IDocumentInfo [ ] ;
2143 public serverIdentifier : string ;
44+ public notifications : ILSPNotifications ;
2245
2346 constructor ( options : ILSPOptions ) {
2447 super ( options ) ;
2548 this . serverIdentifier = options ?. serverIdentifier ;
2649 this . documentsToOpen = [ ] ;
50+ this . notifications = {
51+ $ : {
52+ logTrace : new Signal ( this ) ,
53+ setTrace : params => {
54+ this . connection . sendNotification ( '$/setTrace' , params ) ;
55+ }
56+ } ,
57+ window : {
58+ showMessage : new Signal ( this ) ,
59+ logMessage : new Signal ( this )
60+ }
61+ } ;
2762 }
2863
2964 sendOpenWhenReady ( documentInfo : IDocumentInfo ) {
@@ -39,6 +74,20 @@ export class LSPConnection extends LspWsConnection {
3974 while ( this . documentsToOpen . length ) {
4075 this . sendOpen ( this . documentsToOpen . pop ( ) ) ;
4176 }
77+ for ( const namespaceName in this . notifications ) {
78+ const namespace = this . notifications [ namespaceName ] ;
79+ for ( const memberName in namespace ) {
80+ const endpoint = namespace [ memberName ] ;
81+ if ( endpoint instanceof Signal ) {
82+ this . connection . onNotification (
83+ `${ namespaceName } /${ memberName } ` ,
84+ params => {
85+ endpoint . emit ( params ) ;
86+ }
87+ ) ;
88+ }
89+ }
90+ }
4291 }
4392
4493 public sendSelectiveChange (
0 commit comments