@@ -20,6 +20,11 @@ import * as chokidar from "chokidar";
2020import { assert } from "console" ;
2121import { fileURLToPath } from "url" ;
2222import { ChildProcess } from "child_process" ;
23+ import {
24+ binaryExists ,
25+ runDumpCommand ,
26+ runCompletionCommand ,
27+ } from "./RescriptEditorSupport" ;
2328
2429// https://microsoft.github.io/language-server-protocol/specification#initialize
2530// 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) => {
270275// TODO: incremental sync?
271276textDocumentSync :v . TextDocumentSyncKind . Full ,
272277documentFormattingProvider :true ,
273- hoverProvider :true ,
274- definitionProvider :true ,
278+ hoverProvider :binaryExists ,
279+ definitionProvider :binaryExists ,
280+ completionProvider :binaryExists
281+ ?{ triggerCharacters :[ "." ] }
282+ :undefined ,
275283} ,
276284} ;
277285let response :m . ResponseMessage = {
@@ -315,32 +323,68 @@ process.on("message", (msg: m.Message) => {
315323process . send ! ( response ) ;
316324}
317325} else if ( msg . method === p . HoverRequest . method ) {
318- let dummyHoverResponse :m . ResponseMessage = {
326+ let emptyHoverResponse :m . ResponseMessage = {
319327jsonrpc :c . jsonrpcVersion ,
320328id :msg . id ,
321329// type result = Hover | null
322330// type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
323- result :{ contents : "Time to go for a 20k run!" } ,
331+ result :null ,
324332} ;
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+ } ) ;
327346} else if ( msg . method === p . DefinitionRequest . method ) {
328347// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
329- let dummyDefinitionResponse :m . ResponseMessage = {
348+ let emptyDefinitionResponse :m . ResponseMessage = {
330349jsonrpc :c . jsonrpcVersion ,
331350id :msg . id ,
332351// 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 ,
340353// error: code and message set in case an exception happens during the definition request.
341354} ;
342355
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+ } ) ;
344388} else if ( msg . method === p . DocumentFormattingRequest . method ) {
345389// technically, a formatting failure should reply with the error. Sadly
346390// the LSP alert box for these error replies sucks (e.g. doesn't actually