@@ -19,7 +19,7 @@ import * as chokidar from "chokidar";
19
19
import { assert } from "console" ;
20
20
import { fileURLToPath } from "url" ;
21
21
import { ChildProcess } from "child_process" ;
22
- import { WorkspaceEdit } from "vscode-languageserver" ;
22
+ import { WorkspaceEdit } from "vscode-languageserver" ;
23
23
import { TextEdit } from "vscode-languageserver-types" ;
24
24
25
25
// https://microsoft.github.io/language-server-protocol/specification#initialize
@@ -355,58 +355,50 @@ function onMessage(msg: m.Message) {
355
355
} else if ( msg . method === p . HoverRequest . method ) {
356
356
let params = msg . params as p . HoverParams ;
357
357
let filePath = fileURLToPath ( params . textDocument . uri ) ;
358
- let result : typeof p . HoverRequest . type = utils . runAnalysisAfterSanityCheck (
358
+ let response = utils . runAnalysisCommand (
359
359
filePath ,
360
- [ "hover" , filePath , params . position . line , params . position . character ]
360
+ [ "hover" , filePath , params . position . line , params . position . character ] ,
361
+ msg
361
362
) ;
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 ) ;
370
364
} else if ( msg . method === p . DefinitionRequest . method ) {
371
365
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
372
366
let params = msg . params as p . DefinitionParams ;
373
367
let filePath = fileURLToPath ( params . textDocument . uri ) ;
374
- let result : typeof p . DefinitionRequest . type = utils . runAnalysisAfterSanityCheck (
368
+ let response = utils . runAnalysisCommand (
375
369
filePath ,
376
370
[
377
371
"definition" ,
378
372
filePath ,
379
373
params . position . line ,
380
374
params . position . character ,
381
- ]
375
+ ] ,
376
+ msg
382
377
) ;
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 ) ;
390
379
} else if ( msg . method === p . RenameRequest . method ) {
391
380
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
392
381
let params = msg . params as p . RenameParams ;
393
382
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
+ ) ;
395
387
let result : WorkspaceEdit | null ;
396
388
if ( locations === null ) {
397
389
result = null ;
398
390
} else {
399
391
let changes : { [ uri : string ] : TextEdit [ ] } = { } ;
400
392
locations . forEach ( ( { uri, range } ) => {
401
- let textEdit : TextEdit = { range, newText : params . newName } ;
393
+ let textEdit : TextEdit = { range, newText : params . newName } ;
402
394
if ( uri in changes ) {
403
395
changes [ uri ] . push ( textEdit ) ;
404
396
} else {
405
- changes [ uri ] = [ textEdit ]
397
+ changes [ uri ] = [ textEdit ] ;
406
398
}
407
399
} ) ;
408
400
409
- result = { changes} ;
401
+ result = { changes } ;
410
402
}
411
403
412
404
let renameResponse : m . ResponseMessage = {
@@ -420,7 +412,10 @@ function onMessage(msg: m.Message) {
420
412
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
421
413
let params = msg . params as p . ReferenceParams ;
422
414
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
+ ) ;
424
419
let definitionResponse : m . ResponseMessage = {
425
420
jsonrpc : c . jsonrpcVersion ,
426
421
id : msg . id ,
@@ -432,39 +427,31 @@ function onMessage(msg: m.Message) {
432
427
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
433
428
let params = msg . params as p . DocumentSymbolParams ;
434
429
let filePath = fileURLToPath ( params . textDocument . uri ) ;
435
- let result : typeof p . DocumentSymbolRequest . type = utils . runAnalysisAfterSanityCheck (
430
+ let response = utils . runAnalysisCommand (
436
431
filePath ,
437
- [ "documentSymbol" , filePath ]
432
+ [ "documentSymbol" , filePath ] ,
433
+ msg
438
434
) ;
439
- let definitionResponse : m . ResponseMessage = {
440
- jsonrpc : c . jsonrpcVersion ,
441
- id : msg . id ,
442
- result,
443
- } ;
444
- send ( definitionResponse ) ;
435
+ send ( response ) ;
445
436
} else if ( msg . method === p . CompletionRequest . method ) {
446
437
let params = msg . params as p . ReferenceParams ;
447
438
let filePath = fileURLToPath ( params . textDocument . uri ) ;
448
439
let code = getOpenedFileContent ( params . textDocument . uri ) ;
449
440
let tmpname = utils . createFileInTempDir ( ) ;
450
441
fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
451
- let result : typeof p . CompletionRequest . type = utils . runAnalysisAfterSanityCheck (
442
+ let response = utils . runAnalysisCommand (
452
443
filePath ,
453
444
[
454
445
"completion" ,
455
446
filePath ,
456
447
params . position . line ,
457
448
params . position . character ,
458
449
tmpname ,
459
- ]
450
+ ] ,
451
+ msg
460
452
) ;
461
453
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 ) ;
468
455
} else if ( msg . method === p . DocumentFormattingRequest . method ) {
469
456
// technically, a formatting failure should reply with the error. Sadly
470
457
// the LSP alert box for these error replies sucks (e.g. doesn't actually
0 commit comments