|
1 | | -let completion ~debug ~path ~pos ~currentFile ~forHover = |
2 | | - let result = |
3 | | - let textOpt = Files.readFile currentFile in |
4 | | - match textOpt with |
5 | | - | None | Some "" -> [] |
6 | | - | Some text -> |
7 | | - let completions = |
8 | | - match |
9 | | - CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos |
10 | | - ~currentFile ~text |
11 | | - with |
12 | | - | None -> [] |
13 | | - | Some (completable, scope) -> ( |
14 | | - if debug then |
15 | | - Printf.printf "Completable: %s\n" |
16 | | - (SharedTypes.Completable.toString completable); |
17 | | - (* Only perform expensive ast operations if there are completables *) |
18 | | - match Cmt.fromPath ~path with |
19 | | - | None -> [] |
20 | | - | Some full -> |
21 | | - let env = SharedTypes.QueryEnv.fromFile full.file in |
22 | | - let package = full.package in |
23 | | - completable |
24 | | - |> CompletionBackEnd.processCompletable ~debug ~package ~pos ~scope |
25 | | - ~env ~forHover) |
26 | | - in |
27 | | - completions |> List.map CompletionBackEnd.completionToItem |
28 | | - in |
| 1 | +let getCompletions ~debug ~path ~pos ~currentFile ~forHover = |
| 2 | + let textOpt = Files.readFile currentFile in |
| 3 | + match textOpt with |
| 4 | + | None | Some "" -> [] |
| 5 | + | Some text -> ( |
| 6 | + match |
| 7 | + CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos |
| 8 | + ~currentFile ~text |
| 9 | + with |
| 10 | + | None -> [] |
| 11 | + | Some (completable, scope) -> ( |
| 12 | + if debug then |
| 13 | + Printf.printf "Completable: %s\n" |
| 14 | + (SharedTypes.Completable.toString completable); |
| 15 | + (* Only perform expensive ast operations if there are completables *) |
| 16 | + match Cmt.fromPath ~path with |
| 17 | + | None -> [] |
| 18 | + | Some full -> |
| 19 | + let env = SharedTypes.QueryEnv.fromFile full.file in |
| 20 | + let package = full.package in |
| 21 | + completable |
| 22 | + |> CompletionBackEnd.processCompletable ~debug ~package ~pos ~scope ~env |
| 23 | + ~forHover)) |
| 24 | + |
| 25 | +let completion ~debug ~path ~pos ~currentFile = |
29 | 26 | print_endline |
30 | | - (result |> List.map Protocol.stringifyCompletionItem |> Protocol.array) |
| 27 | + (getCompletions ~debug ~path ~pos ~currentFile ~forHover:false |
| 28 | + |> List.map CompletionBackEnd.completionToItem |
| 29 | + |> List.map Protocol.stringifyCompletionItem |
| 30 | + |> Protocol.array) |
31 | 31 |
|
32 | | -let hover ~path ~line ~col = |
| 32 | +let hover ~path ~line ~col ~currentFile ~debug = |
33 | 33 | let result = |
34 | 34 | match Cmt.fromPath ~path with |
35 | 35 | | None -> Protocol.null |
36 | 36 | | Some ({file} as full) -> ( |
37 | 37 | match References.getLocItem ~full ~line ~col with |
38 | | - | None -> Protocol.null |
| 38 | + | None -> ( |
| 39 | + let completions = |
| 40 | + getCompletions ~debug ~path ~pos:(line, col) ~currentFile |
| 41 | + ~forHover:true |
| 42 | + in |
| 43 | + match completions with |
| 44 | + | {kind = Label typString} :: _ -> |
| 45 | + Protocol.stringifyHover {contents = Hover.codeBlock typString} |
| 46 | + | _ -> Protocol.null) |
39 | 47 | | Some locItem -> ( |
40 | 48 | let isModule = |
41 | 49 | match locItem.locType with |
@@ -273,7 +281,7 @@ let test ~path = |
273 | 281 | print_endline |
274 | 282 | ("Hover " ^ path ^ " " ^ string_of_int line ^ ":" |
275 | 283 | ^ string_of_int col); |
276 | | - hover ~path ~line ~col |
| 284 | + hover ~path ~line ~col ~currentFile:path ~debug:true |
277 | 285 | | "ref" -> |
278 | 286 | print_endline |
279 | 287 | ("References " ^ path ^ " " ^ string_of_int line ^ ":" |
@@ -316,8 +324,7 @@ let test ~path = |
316 | 324 | in |
317 | 325 | Printf.fprintf cout "%s\n" lineToOutput); |
318 | 326 | close_out cout; |
319 | | - completion ~debug:true ~path ~pos:(line, col) ~currentFile |
320 | | - ~forHover:false; |
| 327 | + completion ~debug:true ~path ~pos:(line, col) ~currentFile; |
321 | 328 | Sys.remove currentFile |
322 | 329 | | "hig" -> |
323 | 330 | print_endline ("Highlight " ^ path); |
|
0 commit comments