1
1
import process from "process" ;
2
2
import * as p from "vscode-languageserver-protocol" ;
3
- import * as m from "vscode-jsonrpc/lib/messages" ;
3
+ import * as m from "vscode-jsonrpc/lib/common/ messages" ;
4
4
import * as v from "vscode-languageserver" ;
5
5
import * as rpc from "vscode-jsonrpc" ;
6
6
import * as path from "path" ;
@@ -40,7 +40,7 @@ let projectsFiles: Map<
40
40
// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
41
41
42
42
// will be properly defined later depending on the mode (stdio/node-rpc)
43
- let send : ( msg : m . Message ) => void = ( _ ) => { } ;
43
+ let send : ( msg : m . Message ) => void = ( _ ) => { } ;
44
44
45
45
let sendUpdatedDiagnostics = ( ) => {
46
46
projectsFiles . forEach ( ( { filesWithDiagnostics } , projectRootPath ) => {
@@ -343,15 +343,14 @@ function onMessage(msg: m.Message) {
343
343
send ( response ) ;
344
344
}
345
345
} else if ( msg . method === p . HoverRequest . method ) {
346
- let result : Hover | null = utils . runAnalysisAfterSanityCheck (
347
- msg ,
348
- ( filePath ) => [
349
- "hover" ,
350
- filePath ,
351
- msg . params . position . line ,
352
- msg . params . position . character ,
353
- ]
354
- ) ;
346
+ let params = msg . params as p . HoverParams ;
347
+ let filePath = fileURLToPath ( params . textDocument . uri ) ;
348
+ let result : Hover | null = utils . runAnalysisAfterSanityCheck ( filePath , [
349
+ "hover" ,
350
+ filePath ,
351
+ params . position . line ,
352
+ params . position . character ,
353
+ ] ) ;
355
354
let hoverResponse : m . ResponseMessage = {
356
355
jsonrpc : c . jsonrpcVersion ,
357
356
id : msg . id ,
@@ -362,15 +361,16 @@ function onMessage(msg: m.Message) {
362
361
send ( hoverResponse ) ;
363
362
} else if ( msg . method === p . DefinitionRequest . method ) {
364
363
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
365
- let result : Location [ ] | null = utils . runAnalysisAfterSanityCheck (
366
- msg ,
367
- ( filePath ) => [
364
+ let params = msg . params as p . DefinitionParams ;
365
+ let filePath = fileURLToPath ( params . textDocument . uri ) ;
366
+ let result :
367
+ | Location [ ]
368
+ | null = utils . runAnalysisAfterSanityCheck ( filePath , [
368
369
"definition" ,
369
370
filePath ,
370
- msg . params . position . line ,
371
- msg . params . position . character ,
372
- ]
373
- ) ;
371
+ params . position . line ,
372
+ params . position . character ,
373
+ ] ) ;
374
374
let definitionResponse : m . ResponseMessage = {
375
375
jsonrpc : c . jsonrpcVersion ,
376
376
id : msg . id ,
@@ -380,13 +380,15 @@ function onMessage(msg: m.Message) {
380
380
send ( definitionResponse ) ;
381
381
} else if ( msg . method === p . ReferencesRequest . method ) {
382
382
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
383
+ let params = msg . params as p . ReferenceParams ;
384
+ let filePath = fileURLToPath ( params . textDocument . uri ) ;
383
385
let result : Location | null = utils . runAnalysisAfterSanityCheck (
384
- msg ,
385
- ( filePath ) => [
386
+ filePath ,
387
+ [
386
388
"references" ,
387
389
filePath ,
388
- msg . params . position . line ,
389
- msg . params . position . character ,
390
+ params . position . line ,
391
+ params . position . character ,
390
392
]
391
393
) ;
392
394
let definitionResponse : m . ResponseMessage = {
@@ -398,31 +400,35 @@ function onMessage(msg: m.Message) {
398
400
send ( definitionResponse ) ;
399
401
} else if ( msg . method === p . DocumentSymbolRequest . method ) {
400
402
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
403
+ let params = msg . params as p . DocumentSymbolParams ;
404
+ let filePath = fileURLToPath ( params . textDocument . uri ) ;
401
405
let result :
402
406
| SymbolInformation [ ]
403
- | null = utils . runAnalysisAfterSanityCheck ( msg , ( filePath ) => [
404
- "documentSymbol" ,
405
- filePath ,
406
- ] ) ;
407
+ | null = utils . runAnalysisAfterSanityCheck ( filePath , [
408
+ "documentSymbol" ,
409
+ filePath ,
410
+ ] ) ;
407
411
let definitionResponse : m . ResponseMessage = {
408
412
jsonrpc : c . jsonrpcVersion ,
409
413
id : msg . id ,
410
414
result,
411
415
} ;
412
416
send ( definitionResponse ) ;
413
417
} else if ( msg . method === p . CompletionRequest . method ) {
414
- let code = getOpenedFileContent ( msg . params . textDocument . uri ) ;
418
+ let params = msg . params as p . ReferenceParams ;
419
+ let filePath = fileURLToPath ( params . textDocument . uri ) ;
420
+ let code = getOpenedFileContent ( params . textDocument . uri ) ;
415
421
let tmpname = utils . createFileInTempDir ( ) ;
416
422
fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
417
423
let result :
418
424
| CompletionItem [ ]
419
- | null = utils . runAnalysisAfterSanityCheck ( msg , ( filePath ) => [
420
- "complete" ,
421
- filePath ,
422
- msg . params . position . line ,
423
- msg . params . position . character ,
424
- tmpname ,
425
- ] ) ;
425
+ | null = utils . runAnalysisAfterSanityCheck ( filePath , [
426
+ "complete" ,
427
+ filePath ,
428
+ params . position . line ,
429
+ params . position . character ,
430
+ tmpname ,
431
+ ] ) ;
426
432
fs . unlink ( tmpname , ( ) => null ) ;
427
433
let completionResponse : m . ResponseMessage = {
428
434
jsonrpc : c . jsonrpcVersion ,
0 commit comments