11import process from "process" ;
22import * 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" ;
44import * as v from "vscode-languageserver" ;
55import * as rpc from "vscode-jsonrpc" ;
66import * as path from "path" ;
@@ -40,7 +40,7 @@ let projectsFiles: Map<
4040// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
4141
4242// 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 = ( _ ) => { } ;
4444
4545let sendUpdatedDiagnostics = ( ) => {
4646 projectsFiles . forEach ( ( { filesWithDiagnostics } , projectRootPath ) => {
@@ -343,15 +343,14 @@ function onMessage(msg: m.Message) {
343343 send ( response ) ;
344344 }
345345 } 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+ ] ) ;
355354 let hoverResponse : m . ResponseMessage = {
356355 jsonrpc : c . jsonrpcVersion ,
357356 id : msg . id ,
@@ -362,15 +361,16 @@ function onMessage(msg: m.Message) {
362361 send ( hoverResponse ) ;
363362 } else if ( msg . method === p . DefinitionRequest . method ) {
364363 // 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 , [
368369 "definition" ,
369370 filePath ,
370- msg . params . position . line ,
371- msg . params . position . character ,
372- ]
373- ) ;
371+ params . position . line ,
372+ params . position . character ,
373+ ] ) ;
374374 let definitionResponse : m . ResponseMessage = {
375375 jsonrpc : c . jsonrpcVersion ,
376376 id : msg . id ,
@@ -380,13 +380,15 @@ function onMessage(msg: m.Message) {
380380 send ( definitionResponse ) ;
381381 } else if ( msg . method === p . ReferencesRequest . method ) {
382382 // 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 ) ;
383385 let result : Location | null = utils . runAnalysisAfterSanityCheck (
384- msg ,
385- ( filePath ) => [
386+ filePath ,
387+ [
386388 "references" ,
387389 filePath ,
388- msg . params . position . line ,
389- msg . params . position . character ,
390+ params . position . line ,
391+ params . position . character ,
390392 ]
391393 ) ;
392394 let definitionResponse : m . ResponseMessage = {
@@ -398,31 +400,35 @@ function onMessage(msg: m.Message) {
398400 send ( definitionResponse ) ;
399401 } else if ( msg . method === p . DocumentSymbolRequest . method ) {
400402 // 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 ) ;
401405 let result :
402406 | SymbolInformation [ ]
403- | null = utils . runAnalysisAfterSanityCheck ( msg , ( filePath ) => [
404- "documentSymbol" ,
405- filePath ,
406- ] ) ;
407+ | null = utils . runAnalysisAfterSanityCheck ( filePath , [
408+ "documentSymbol" ,
409+ filePath ,
410+ ] ) ;
407411 let definitionResponse : m . ResponseMessage = {
408412 jsonrpc : c . jsonrpcVersion ,
409413 id : msg . id ,
410414 result,
411415 } ;
412416 send ( definitionResponse ) ;
413417 } 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 ) ;
415421 let tmpname = utils . createFileInTempDir ( ) ;
416422 fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
417423 let result :
418424 | 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+ ] ) ;
426432 fs . unlink ( tmpname , ( ) => null ) ;
427433 let completionResponse : m . ResponseMessage = {
428434 jsonrpc : c . jsonrpcVersion ,
0 commit comments