@@ -10,17 +10,16 @@ import {
1010 DidOpenTextDocumentNotification ,
1111 DidChangeTextDocumentNotification ,
1212 DidCloseTextDocumentNotification ,
13- Location ,
13+ CompletionItem ,
14+ Hover ,
1415} from "vscode-languageserver-protocol" ;
1516import * as utils from "./utils" ;
1617import * as c from "./constants" ;
1718import * as chokidar from "chokidar" ;
1819import { assert } from "console" ;
1920import { fileURLToPath } from "url" ;
2021import { ChildProcess } from "child_process" ;
21- import {
22- runCompletionCommand , runDefinitionCommand , runHoverCommand ,
23- } from "./RescriptEditorSupport" ;
22+ import { Location } from "vscode-languageserver" ;
2423
2524// https://microsoft.github.io/language-server-protocol/specification#initialize
2625// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
@@ -341,30 +340,59 @@ function onMessage(msg: m.Message) {
341340 send ( response ) ;
342341 }
343342 } else if ( msg . method === p . HoverRequest . method ) {
343+ let result : Hover | null = utils . runAnalysisAfterSanityCheck (
344+ msg ,
345+ ( filePath ) => [
346+ "hover" ,
347+ filePath ,
348+ msg . params . position . line ,
349+ msg . params . position . character ,
350+ ]
351+ ) ;
344352 let hoverResponse : m . ResponseMessage = {
345353 jsonrpc : c . jsonrpcVersion ,
346354 id : msg . id ,
347355 // type result = Hover | null
348356 // type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
349- result : runHoverCommand ( msg ) ,
357+ result,
350358 } ;
351359 send ( hoverResponse ) ;
352360 } else if ( msg . method === p . DefinitionRequest . method ) {
353361 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
362+ let result : Location | null = utils . runAnalysisAfterSanityCheck (
363+ msg ,
364+ ( filePath ) => [
365+ "definition" ,
366+ filePath ,
367+ msg . params . position . line ,
368+ msg . params . position . character ,
369+ ]
370+ ) ;
354371 let definitionResponse : m . ResponseMessage = {
355372 jsonrpc : c . jsonrpcVersion ,
356373 id : msg . id ,
357- // result should be: Location | Array<Location> | Array<LocationLink> | null
358- result : runDefinitionCommand ( msg ) ,
374+ result,
359375 // error: code and message set in case an exception happens during the definition request.
360376 } ;
361377 send ( definitionResponse ) ;
362378 } else if ( msg . method === p . CompletionRequest . method ) {
363379 let code = getOpenedFileContent ( msg . params . textDocument . uri ) ;
380+ let tmpname = utils . createFileInTempDir ( ) ;
381+ fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
382+ let result :
383+ | CompletionItem [ ]
384+ | null = utils . runAnalysisAfterSanityCheck ( msg , ( filePath ) => [
385+ "complete" ,
386+ filePath ,
387+ msg . params . position . line ,
388+ msg . params . position . character ,
389+ tmpname ,
390+ ] ) ;
391+ fs . unlink ( tmpname , ( ) => null ) ;
364392 let completionResponse : m . ResponseMessage = {
365393 jsonrpc : c . jsonrpcVersion ,
366394 id : msg . id ,
367- result : runCompletionCommand ( msg , code ) ,
395+ result,
368396 } ;
369397 send ( completionResponse ) ;
370398 } else if ( msg . method === p . DocumentFormattingRequest . method ) {
0 commit comments