@@ -20,6 +20,11 @@ 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 {
24
+ binaryExists ,
25
+ runDumpCommand ,
26
+ runCompletionCommand ,
27
+ } from "./RescriptEditorSupport" ;
23
28
24
29
// https://microsoft.github.io/language-server-protocol/specification#initialize
25
30
// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
@@ -270,8 +275,11 @@ process.on("message", (msg: m.Message) => {
270
275
// TODO: incremental sync?
271
276
textDocumentSync : v . TextDocumentSyncKind . Full ,
272
277
documentFormattingProvider : true ,
273
- hoverProvider : true ,
274
- definitionProvider : true ,
278
+ hoverProvider : binaryExists ,
279
+ definitionProvider : binaryExists ,
280
+ completionProvider : binaryExists
281
+ ? { triggerCharacters : [ "." ] }
282
+ : undefined ,
275
283
} ,
276
284
} ;
277
285
let response : m . ResponseMessage = {
@@ -315,32 +323,68 @@ process.on("message", (msg: m.Message) => {
315
323
process . send ! ( response ) ;
316
324
}
317
325
} else if ( msg . method === p . HoverRequest . method ) {
318
- let dummyHoverResponse : m . ResponseMessage = {
326
+ let emptyHoverResponse : m . ResponseMessage = {
319
327
jsonrpc : c . jsonrpcVersion ,
320
328
id : msg . id ,
321
329
// type result = Hover | null
322
330
// type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
323
- result : { contents : "Time to go for a 20k run!" } ,
331
+ result : null ,
324
332
} ;
325
-
326
- process . send ! ( dummyHoverResponse ) ;
333
+ runDumpCommand ( msg , ( result ) => {
334
+ if ( result && result . hover ) {
335
+ let hoverResponse : m . ResponseMessage = {
336
+ ...emptyHoverResponse ,
337
+ result : {
338
+ contents : result . hover ,
339
+ } ,
340
+ } ;
341
+ process . send ! ( hoverResponse ) ;
342
+ } else {
343
+ process . send ! ( emptyHoverResponse ) ;
344
+ }
345
+ } ) ;
327
346
} else if ( msg . method === p . DefinitionRequest . method ) {
328
347
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
329
- let dummyDefinitionResponse : m . ResponseMessage = {
348
+ let emptyDefinitionResponse : m . ResponseMessage = {
330
349
jsonrpc : c . jsonrpcVersion ,
331
350
id : msg . id ,
332
351
// result should be: Location | Array<Location> | Array<LocationLink> | null
333
- result : {
334
- uri : msg . params . textDocument . uri ,
335
- range : {
336
- start : { line : 2 , character : 4 } ,
337
- end : { line : 2 , character : 12 } ,
338
- } ,
339
- } ,
352
+ result : null ,
340
353
// error: code and message set in case an exception happens during the definition request.
341
354
} ;
342
355
343
- process . send ! ( dummyDefinitionResponse ) ;
356
+ runDumpCommand ( msg , ( result ) => {
357
+ if ( result && result . definition ) {
358
+ let definitionResponse : m . ResponseMessage = {
359
+ ...emptyDefinitionResponse ,
360
+ result : {
361
+ uri : result . definition . uri || msg . params . textDocument . uri ,
362
+ range : result . definition . range ,
363
+ } ,
364
+ } ;
365
+ process . send ! ( definitionResponse ) ;
366
+ } else {
367
+ process . send ! ( emptyDefinitionResponse ) ;
368
+ }
369
+ } ) ;
370
+ } else if ( msg . method === p . CompletionRequest . method ) {
371
+ let emptyCompletionResponse : m . ResponseMessage = {
372
+ jsonrpc : c . jsonrpcVersion ,
373
+ id : msg . id ,
374
+ result : null ,
375
+ } ;
376
+ let code = getOpenedFileContent ( msg . params . textDocument . uri ) ;
377
+ runCompletionCommand ( msg , code , ( result ) => {
378
+ if ( result ) {
379
+ let definitionResponse : m . ResponseMessage = {
380
+ ...emptyCompletionResponse ,
381
+ result : result ,
382
+ } ;
383
+ process . send ! ( definitionResponse ) ;
384
+ } else {
385
+ process . send ! ( emptyCompletionResponse ) ;
386
+ }
387
+ } ) ;
344
388
} else if ( msg . method === p . DocumentFormattingRequest . method ) {
345
389
// technically, a formatting failure should reply with the error. Sadly
346
390
// the LSP alert box for these error replies sucks (e.g. doesn't actually
0 commit comments