@@ -20,6 +20,8 @@ import * as chokidar from "chokidar";
20
20
import { assert } from "console" ;
21
21
import { fileURLToPath } from "url" ;
22
22
import { ChildProcess } from "child_process" ;
23
+ import { runDumpCommand } from "./dumpCommand" ;
24
+
23
25
24
26
// https://microsoft.github.io/language-server-protocol/specification#initialize
25
27
// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
@@ -313,32 +315,50 @@ process.on("message", (msg: m.Message) => {
313
315
process . send ! ( response ) ;
314
316
}
315
317
} else if ( msg . method === p . HoverRequest . method ) {
316
- let dummyHoverResponse : m . ResponseMessage = {
318
+ let emptyHoverResponse : m . ResponseMessage = {
317
319
jsonrpc : c . jsonrpcVersion ,
318
320
id : msg . id ,
319
321
// type result = Hover | null
320
322
// type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
321
- result : { contents : "Time to go for a 20k run!" } ,
323
+ result : null ,
322
324
} ;
323
-
324
- process . send ! ( dummyHoverResponse ) ;
325
+ runDumpCommand ( msg , ( result ) => {
326
+ if ( result && result . hover ) {
327
+ let hoverResponse : m . ResponseMessage = {
328
+ ...emptyHoverResponse ,
329
+ result : {
330
+ contents : result . hover ,
331
+ } ,
332
+ } ;
333
+ process . send ! ( hoverResponse ) ;
334
+ } else {
335
+ process . send ! ( emptyHoverResponse ) ;
336
+ }
337
+ } ) ;
325
338
} else if ( msg . method === p . DefinitionRequest . method ) {
326
339
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
327
- let dummyDefinitionResponse : m . ResponseMessage = {
340
+ let emptyDefinitionResponse : m . ResponseMessage = {
328
341
jsonrpc : c . jsonrpcVersion ,
329
342
id : msg . id ,
330
343
// result should be: Location | Array<Location> | Array<LocationLink> | null
331
- result : {
332
- uri : msg . params . textDocument . uri ,
333
- range : {
334
- start : { line : 2 , character : 4 } ,
335
- end : { line : 2 , character : 12 } ,
336
- } ,
337
- } ,
344
+ result : null ,
338
345
// error: code and message set in case an exception happens during the definition request.
339
346
} ;
340
347
341
- process . send ! ( dummyDefinitionResponse ) ;
348
+ runDumpCommand ( msg , ( result ) => {
349
+ if ( result && result . definition ) {
350
+ let definitionResponse : m . ResponseMessage = {
351
+ ...emptyDefinitionResponse ,
352
+ result : {
353
+ uri : result . definition . uri || msg . params . textDocument . uri ,
354
+ range : result . definition . range ,
355
+ } ,
356
+ } ;
357
+ process . send ! ( definitionResponse ) ;
358
+ } else {
359
+ process . send ! ( emptyDefinitionResponse ) ;
360
+ }
361
+ } ) ;
342
362
} else if ( msg . method === p . DocumentFormattingRequest . method ) {
343
363
// technically, a formatting failure should reply with the error. Sadly
344
364
// the LSP alert box for these error replies sucks (e.g. doesn't actually
0 commit comments