@@ -19,7 +19,7 @@ import * as chokidar from "chokidar";
1919import { assert } from "console" ;
2020import { fileURLToPath } from "url" ;
2121import { ChildProcess } from "child_process" ;
22- import { WorkspaceEdit } from "vscode-languageserver" ;
22+ import { WorkspaceEdit } from "vscode-languageserver" ;
2323import { TextEdit } from "vscode-languageserver-types" ;
2424
2525// https://microsoft.github.io/language-server-protocol/specification#initialize
@@ -355,58 +355,50 @@ function onMessage(msg: m.Message) {
355355 } else if ( msg . method === p . HoverRequest . method ) {
356356 let params = msg . params as p . HoverParams ;
357357 let filePath = fileURLToPath ( params . textDocument . uri ) ;
358- let result : typeof p . HoverRequest . type = utils . runAnalysisAfterSanityCheck (
358+ let response = utils . runAnalysisCommand (
359359 filePath ,
360- [ "hover" , filePath , params . position . line , params . position . character ]
360+ [ "hover" , filePath , params . position . line , params . position . character ] ,
361+ msg
361362 ) ;
362- let hoverResponse : m . ResponseMessage = {
363- jsonrpc : c . jsonrpcVersion ,
364- id : msg . id ,
365- // type result = Hover | null
366- // type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
367- result,
368- } ;
369- send ( hoverResponse ) ;
363+ send ( response ) ;
370364 } else if ( msg . method === p . DefinitionRequest . method ) {
371365 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
372366 let params = msg . params as p . DefinitionParams ;
373367 let filePath = fileURLToPath ( params . textDocument . uri ) ;
374- let result : typeof p . DefinitionRequest . type = utils . runAnalysisAfterSanityCheck (
368+ let response = utils . runAnalysisCommand (
375369 filePath ,
376370 [
377371 "definition" ,
378372 filePath ,
379373 params . position . line ,
380374 params . position . character ,
381- ]
375+ ] ,
376+ msg
382377 ) ;
383- let definitionResponse : m . ResponseMessage = {
384- jsonrpc : c . jsonrpcVersion ,
385- id : msg . id ,
386- result,
387- // error: code and message set in case an exception happens during the definition request.
388- } ;
389- send ( definitionResponse ) ;
378+ send ( response ) ;
390379 } else if ( msg . method === p . RenameRequest . method ) {
391380 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
392381 let params = msg . params as p . RenameParams ;
393382 let filePath = fileURLToPath ( params . textDocument . uri ) ;
394- let locations : p . Location [ ] | null = utils . getReferencesForPosition ( filePath , params . position ) ;
383+ let locations : p . Location [ ] | null = utils . getReferencesForPosition (
384+ filePath ,
385+ params . position
386+ ) ;
395387 let result : WorkspaceEdit | null ;
396388 if ( locations === null ) {
397389 result = null ;
398390 } else {
399391 let changes : { [ uri : string ] : TextEdit [ ] } = { } ;
400392 locations . forEach ( ( { uri, range } ) => {
401- let textEdit : TextEdit = { range, newText : params . newName } ;
393+ let textEdit : TextEdit = { range, newText : params . newName } ;
402394 if ( uri in changes ) {
403395 changes [ uri ] . push ( textEdit ) ;
404396 } else {
405- changes [ uri ] = [ textEdit ]
397+ changes [ uri ] = [ textEdit ] ;
406398 }
407399 } ) ;
408400
409- result = { changes} ;
401+ result = { changes } ;
410402 }
411403
412404 let renameResponse : m . ResponseMessage = {
@@ -420,7 +412,10 @@ function onMessage(msg: m.Message) {
420412 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
421413 let params = msg . params as p . ReferenceParams ;
422414 let filePath = fileURLToPath ( params . textDocument . uri ) ;
423- let result : typeof p . ReferencesRequest . type = utils . getReferencesForPosition ( filePath , params . position ) ;
415+ let result : typeof p . ReferencesRequest . type = utils . getReferencesForPosition (
416+ filePath ,
417+ params . position
418+ ) ;
424419 let definitionResponse : m . ResponseMessage = {
425420 jsonrpc : c . jsonrpcVersion ,
426421 id : msg . id ,
@@ -432,39 +427,31 @@ function onMessage(msg: m.Message) {
432427 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
433428 let params = msg . params as p . DocumentSymbolParams ;
434429 let filePath = fileURLToPath ( params . textDocument . uri ) ;
435- let result : typeof p . DocumentSymbolRequest . type = utils . runAnalysisAfterSanityCheck (
430+ let response = utils . runAnalysisCommand (
436431 filePath ,
437- [ "documentSymbol" , filePath ]
432+ [ "documentSymbol" , filePath ] ,
433+ msg
438434 ) ;
439- let definitionResponse : m . ResponseMessage = {
440- jsonrpc : c . jsonrpcVersion ,
441- id : msg . id ,
442- result,
443- } ;
444- send ( definitionResponse ) ;
435+ send ( response ) ;
445436 } else if ( msg . method === p . CompletionRequest . method ) {
446437 let params = msg . params as p . ReferenceParams ;
447438 let filePath = fileURLToPath ( params . textDocument . uri ) ;
448439 let code = getOpenedFileContent ( params . textDocument . uri ) ;
449440 let tmpname = utils . createFileInTempDir ( ) ;
450441 fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
451- let result : typeof p . CompletionRequest . type = utils . runAnalysisAfterSanityCheck (
442+ let response = utils . runAnalysisCommand (
452443 filePath ,
453444 [
454445 "completion" ,
455446 filePath ,
456447 params . position . line ,
457448 params . position . character ,
458449 tmpname ,
459- ]
450+ ] ,
451+ msg
460452 ) ;
461453 fs . unlink ( tmpname , ( ) => null ) ;
462- let completionResponse : m . ResponseMessage = {
463- jsonrpc : c . jsonrpcVersion ,
464- id : msg . id ,
465- result,
466- } ;
467- send ( completionResponse ) ;
454+ send ( response ) ;
468455 } else if ( msg . method === p . DocumentFormattingRequest . method ) {
469456 // technically, a formatting failure should reply with the error. Sadly
470457 // the LSP alert box for these error replies sucks (e.g. doesn't actually
0 commit comments