1
1
import * as events from 'events' ;
2
2
3
+ import 'setimmediate' ;
3
4
import type * as protocol from 'vscode-languageserver-protocol' ;
4
5
import type { LocationLink } from 'vscode-languageserver-types' ;
5
- import { ConsoleLogger , MessageConnection , listen } from 'vscode-ws-jsonrpc' ;
6
+ import type * as rpc from 'vscode-ws-jsonrpc' ;
7
+ import { listen , ConsoleLogger } from 'vscode-ws-jsonrpc' ;
6
8
7
9
import {
8
10
registerServerCapability ,
@@ -27,16 +29,13 @@ import {
27
29
* - initializeParams() was extracted, and can be modified by subclasses
28
30
* - typescript 3.7 was adopted to clean up deep references
29
31
*/
30
- export class LspWsConnection
31
- extends events . EventEmitter
32
- implements ILspConnection
33
- {
32
+ export class LspWsConnection extends events . EventEmitter implements ILspConnection {
34
33
public isConnected = false ;
35
34
public isInitialized = false ;
36
35
public documentInfo : ILspOptions ;
37
36
public serverCapabilities : protocol . ServerCapabilities ;
38
37
protected socket : WebSocket ;
39
- protected connection : MessageConnection ;
38
+ protected connection : rpc . MessageConnection ;
40
39
protected openedUris = new Map < string , boolean > ( ) ;
41
40
private rootUri : string ;
42
41
@@ -58,7 +57,7 @@ export class LspWsConnection
58
57
listen ( {
59
58
webSocket : this . socket ,
60
59
logger : new ConsoleLogger ( ) ,
61
- onConnection : ( connection : MessageConnection ) => {
60
+ onConnection : ( connection : rpc . MessageConnection ) => {
62
61
connection . listen ( ) ;
63
62
this . isConnected = true ;
64
63
@@ -165,16 +164,14 @@ export class LspWsConnection
165
164
166
165
const message : protocol . InitializeParams = this . initializeParams ( ) ;
167
166
168
- this . connection
169
- . sendRequest < protocol . InitializeResult > ( 'initialize' , message )
170
- . then (
171
- params => {
172
- this . onServerInitialized ( params ) ;
173
- } ,
174
- e => {
175
- console . warn ( 'lsp-ws-connection initialization failure' , e ) ;
176
- }
177
- ) ;
167
+ this . connection . sendRequest < protocol . InitializeResult > ( 'initialize' , message ) . then (
168
+ params => {
169
+ this . onServerInitialized ( params ) ;
170
+ } ,
171
+ e => {
172
+ console . warn ( 'lsp-ws-connection initialization failure' , e ) ;
173
+ }
174
+ ) ;
178
175
}
179
176
180
177
sendOpen ( documentInfo : IDocumentInfo ) {
@@ -186,10 +183,7 @@ export class LspWsConnection
186
183
version : documentInfo . version
187
184
} as protocol . TextDocumentItem
188
185
} ;
189
- void this . connection . sendNotification (
190
- 'textDocument/didOpen' ,
191
- textDocumentMessage
192
- ) ;
186
+ this . connection . sendNotification ( 'textDocument/didOpen' , textDocumentMessage ) ;
193
187
this . openedUris . set ( documentInfo . uri , true ) ;
194
188
this . sendChange ( documentInfo ) ;
195
189
}
@@ -209,10 +203,7 @@ export class LspWsConnection
209
203
} as protocol . VersionedTextDocumentIdentifier ,
210
204
contentChanges : [ { text : documentInfo . text } ]
211
205
} ;
212
- void this . connection . sendNotification (
213
- 'textDocument/didChange' ,
214
- textDocumentChange
215
- ) ;
206
+ this . connection . sendNotification ( 'textDocument/didChange' , textDocumentChange ) ;
216
207
documentInfo . version ++ ;
217
208
}
218
209
@@ -228,28 +219,17 @@ export class LspWsConnection
228
219
} as protocol . VersionedTextDocumentIdentifier ,
229
220
text : documentInfo . text
230
221
} ;
231
- void this . connection . sendNotification (
232
- 'textDocument/didSave' ,
233
- textDocumentChange
234
- ) ;
222
+ this . connection . sendNotification ( 'textDocument/didSave' , textDocumentChange ) ;
235
223
}
236
224
237
- public sendConfigurationChange (
238
- settings : protocol . DidChangeConfigurationParams
239
- ) {
225
+ public sendConfigurationChange ( settings : protocol . DidChangeConfigurationParams ) {
240
226
if ( ! this . isReady ) {
241
227
return ;
242
228
}
243
229
244
- void this . connection . sendNotification (
245
- 'workspace/didChangeConfiguration' ,
246
- settings
247
- ) ;
230
+ this . connection . sendNotification ( 'workspace/didChangeConfiguration' , settings ) ;
248
231
}
249
232
250
- /**
251
- * @deprecated
252
- */
253
233
public async getHoverTooltip (
254
234
location : IPosition ,
255
235
documentInfo : IDocumentInfo ,
@@ -281,9 +261,6 @@ export class LspWsConnection
281
261
return hover ;
282
262
}
283
263
284
- /**
285
- * @deprecated
286
- */
287
264
public async getCompletion (
288
265
location : IPosition ,
289
266
token : ITokenInfo ,
@@ -328,10 +305,7 @@ export class LspWsConnection
328
305
return ;
329
306
}
330
307
void this . connection
331
- . sendRequest < protocol . CompletionItem > (
332
- 'completionItem/resolve' ,
333
- completionItem
334
- )
308
+ . sendRequest < protocol . CompletionItem > ( 'completionItem/resolve' , completionItem )
335
309
. then ( result => {
336
310
this . emit ( 'completionResolved' , result ) ;
337
311
} ) ;
@@ -384,7 +358,6 @@ export class LspWsConnection
384
358
385
359
/**
386
360
* Request the locations of all matching document symbols
387
- * @deprecated
388
361
*/
389
362
public async getDocumentHighlights (
390
363
location : IPosition ,
@@ -395,17 +368,18 @@ export class LspWsConnection
395
368
return ;
396
369
}
397
370
398
- const highlights = await this . connection . sendRequest <
399
- protocol . DocumentHighlight [ ]
400
- > ( 'textDocument/documentHighlight' , {
401
- textDocument : {
402
- uri : documentInfo . uri
403
- } ,
404
- position : {
405
- line : location . line ,
406
- character : location . ch
407
- }
408
- } as protocol . TextDocumentPositionParams ) ;
371
+ const highlights = await this . connection . sendRequest < protocol . DocumentHighlight [ ] > (
372
+ 'textDocument/documentHighlight' ,
373
+ {
374
+ textDocument : {
375
+ uri : documentInfo . uri
376
+ } ,
377
+ position : {
378
+ line : location . line ,
379
+ character : location . ch
380
+ }
381
+ } as protocol . TextDocumentPositionParams
382
+ ) ;
409
383
410
384
if ( emit ) {
411
385
this . emit ( 'highlight' , highlights , documentInfo . uri ) ;
@@ -417,7 +391,6 @@ export class LspWsConnection
417
391
/**
418
392
* Request a link to the definition of the current symbol. The results will not be displayed
419
393
* unless they are within the same file URI
420
- * @deprecated
421
394
*/
422
395
public async getDefinition (
423
396
location : IPosition ,
@@ -453,7 +426,6 @@ export class LspWsConnection
453
426
/**
454
427
* Request a link to the type definition of the current symbol. The results will not be displayed
455
428
* unless they are within the same file URI
456
- * @deprecated
457
429
*/
458
430
public async getTypeDefinition (
459
431
location : IPosition ,
@@ -489,7 +461,6 @@ export class LspWsConnection
489
461
/**
490
462
* Request a link to the implementation of the current symbol. The results will not be displayed
491
463
* unless they are within the same file URI
492
- * @deprecated
493
464
*/
494
465
public getImplementation ( location : IPosition , documentInfo : IDocumentInfo ) {
495
466
if ( ! this . isReady || ! this . isImplementationSupported ( ) ) {
@@ -517,7 +488,6 @@ export class LspWsConnection
517
488
/**
518
489
* Request a link to all references to the current symbol. The results will not be displayed
519
490
* unless they are within the same file URI
520
- * @deprecated
521
491
*/
522
492
public async getReferences (
523
493
location : IPosition ,
@@ -555,49 +525,41 @@ export class LspWsConnection
555
525
556
526
/**
557
527
* The characters that trigger completion automatically.
558
- * @deprecated
559
528
*/
560
529
public getLanguageCompletionCharacters ( ) : string [ ] {
561
530
return this . serverCapabilities ?. completionProvider ?. triggerCharacters || [ ] ;
562
531
}
563
532
564
533
/**
565
534
* The characters that trigger signature help automatically.
566
- * @deprecated
567
535
*/
568
536
public getLanguageSignatureCharacters ( ) : string [ ] {
569
- return (
570
- this . serverCapabilities ?. signatureHelpProvider ?. triggerCharacters || [ ]
571
- ) ;
537
+ return this . serverCapabilities ?. signatureHelpProvider ?. triggerCharacters || [ ] ;
572
538
}
573
539
574
540
/**
575
541
* Does the server support go to definition?
576
- * @deprecated
577
542
*/
578
543
public isDefinitionSupported ( ) {
579
544
return ! ! this . serverCapabilities ?. definitionProvider ;
580
545
}
581
546
582
547
/**
583
548
* Does the server support go to type definition?
584
- * @deprecated
585
549
*/
586
550
public isTypeDefinitionSupported ( ) {
587
551
return ! ! this . serverCapabilities ?. typeDefinitionProvider ;
588
552
}
589
553
590
554
/**
591
555
* Does the server support go to implementation?
592
- * @deprecated
593
556
*/
594
557
public isImplementationSupported ( ) {
595
558
return ! ! this . serverCapabilities ?. implementationProvider ;
596
559
}
597
560
598
561
/**
599
562
* Does the server support find all references?
600
- * @deprecated
601
563
*/
602
564
public isReferencesSupported ( ) {
603
565
return ! ! this . serverCapabilities ?. referencesProvider ;
@@ -606,8 +568,8 @@ export class LspWsConnection
606
568
protected onServerInitialized ( params : protocol . InitializeResult ) {
607
569
this . isInitialized = true ;
608
570
this . serverCapabilities = params . capabilities ;
609
- void this . connection . sendNotification ( 'initialized' , { } ) ;
610
- void this . connection . sendNotification ( 'workspace/didChangeConfiguration' , {
571
+ this . connection . sendNotification ( 'initialized' , { } ) ;
572
+ this . connection . sendNotification ( 'workspace/didChangeConfiguration' , {
611
573
settings : { }
612
574
} ) ;
613
575
this . emit ( 'serverInitialized' , this . serverCapabilities ) ;
0 commit comments