@@ -20,6 +20,8 @@ import * as chokidar from "chokidar";
2020import { assert } from "console" ;
2121import { fileURLToPath } from "url" ;
2222import { ChildProcess } from "child_process" ;
23+ import { runDumpCommand } from "./dumpCommand" ;
24+
2325
2426// https://microsoft.github.io/language-server-protocol/specification#initialize
2527// 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) => {
313315 process . send ! ( response ) ;
314316 }
315317 } else if ( msg . method === p . HoverRequest . method ) {
316- let dummyHoverResponse : m . ResponseMessage = {
318+ let emptyHoverResponse : m . ResponseMessage = {
317319 jsonrpc : c . jsonrpcVersion ,
318320 id : msg . id ,
319321 // type result = Hover | null
320322 // type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
321- result : { contents : "Time to go for a 20k run!" } ,
323+ result : null ,
322324 } ;
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+ } ) ;
325338 } else if ( msg . method === p . DefinitionRequest . method ) {
326339 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
327- let dummyDefinitionResponse : m . ResponseMessage = {
340+ let emptyDefinitionResponse : m . ResponseMessage = {
328341 jsonrpc : c . jsonrpcVersion ,
329342 id : msg . id ,
330343 // 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 ,
338345 // error: code and message set in case an exception happens during the definition request.
339346 } ;
340347
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+ } ) ;
342362 } else if ( msg . method === p . DocumentFormattingRequest . method ) {
343363 // technically, a formatting failure should reply with the error. Sadly
344364 // the LSP alert box for these error replies sucks (e.g. doesn't actually
0 commit comments