@@ -10,17 +10,16 @@ import {
10
10
DidOpenTextDocumentNotification ,
11
11
DidChangeTextDocumentNotification ,
12
12
DidCloseTextDocumentNotification ,
13
- Location ,
13
+ CompletionItem ,
14
+ Hover ,
14
15
} from "vscode-languageserver-protocol" ;
15
16
import * as utils from "./utils" ;
16
17
import * as c from "./constants" ;
17
18
import * as chokidar from "chokidar" ;
18
19
import { assert } from "console" ;
19
20
import { fileURLToPath } from "url" ;
20
21
import { ChildProcess } from "child_process" ;
21
- import {
22
- runCompletionCommand , runDefinitionCommand , runHoverCommand ,
23
- } from "./RescriptEditorSupport" ;
22
+ import { Location } from "vscode-languageserver" ;
24
23
25
24
// https://microsoft.github.io/language-server-protocol/specification#initialize
26
25
// 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) {
341
340
send ( response ) ;
342
341
}
343
342
} 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
+ ) ;
344
352
let hoverResponse : m . ResponseMessage = {
345
353
jsonrpc : c . jsonrpcVersion ,
346
354
id : msg . id ,
347
355
// type result = Hover | null
348
356
// type Hover = {contents: MarkedString | MarkedString[] | MarkupContent, range?: Range}
349
- result : runHoverCommand ( msg ) ,
357
+ result,
350
358
} ;
351
359
send ( hoverResponse ) ;
352
360
} else if ( msg . method === p . DefinitionRequest . method ) {
353
361
// 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
+ ) ;
354
371
let definitionResponse : m . ResponseMessage = {
355
372
jsonrpc : c . jsonrpcVersion ,
356
373
id : msg . id ,
357
- // result should be: Location | Array<Location> | Array<LocationLink> | null
358
- result : runDefinitionCommand ( msg ) ,
374
+ result,
359
375
// error: code and message set in case an exception happens during the definition request.
360
376
} ;
361
377
send ( definitionResponse ) ;
362
378
} else if ( msg . method === p . CompletionRequest . method ) {
363
379
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 ) ;
364
392
let completionResponse : m . ResponseMessage = {
365
393
jsonrpc : c . jsonrpcVersion ,
366
394
id : msg . id ,
367
- result : runCompletionCommand ( msg , code ) ,
395
+ result,
368
396
} ;
369
397
send ( completionResponse ) ;
370
398
} else if ( msg . method === p . DocumentFormattingRequest . method ) {
0 commit comments