Skip to content

Commit 7a368ce

Browse files
committed
Prepare infra for hover on unsaved.
Try to use completion infra to hover on unsaved code.
1 parent 4b0301d commit 7a368ce

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

analysis/src/Cli.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let main () =
7070
| [_; "completion"; path; line; col; currentFile] ->
7171
Commands.completion ~debug:false ~path
7272
~pos:(int_of_string line, int_of_string col)
73-
~currentFile
73+
~currentFile ~forHover:false
7474
| [_; "definition"; path; line; col] ->
7575
Commands.definition ~path ~line:(int_of_string line)
7676
~col:(int_of_string col)

analysis/src/Commands.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let completion ~debug ~path ~pos ~currentFile =
1+
let completion ~debug ~path ~pos ~currentFile ~forHover =
22
let result =
33
let textOpt = Files.readFile currentFile in
44
match textOpt with
@@ -22,7 +22,7 @@ let completion ~debug ~path ~pos ~currentFile =
2222
let package = full.package in
2323
completable
2424
|> NewCompletions.processCompletable ~debug ~package ~pos ~scope
25-
~env)
25+
~env ~forHover)
2626
in
2727
completionItems
2828
in
@@ -316,7 +316,8 @@ let test ~path =
316316
in
317317
Printf.fprintf cout "%s\n" lineToOutput);
318318
close_out cout;
319-
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
319+
completion ~debug:true ~path ~pos:(line, col) ~currentFile
320+
~forHover:false;
320321
Sys.remove currentFile
321322
| "hig" ->
322323
print_endline ("Highlight " ^ path);

analysis/src/NewCompletions.ml

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open SharedTypes
33
let domLabels =
44
let bool = "bool" in
55
let float = "float" in
6-
let int = "int" in
6+
let int = "int" in
77
let string = "string" in
88
[
99
("ariaDetails", string);
@@ -703,6 +703,7 @@ let detail name (kind : Completion.kind) =
703703
| Type {decl} -> decl |> Shared.declToString name
704704
| Value typ -> typ |> Shared.typeToString
705705
| ObjLabel typ -> typ |> Shared.typeToString
706+
| Label typString -> typString
706707
| Module _ -> "module"
707708
| FileModule _ -> "file module"
708709
| Field ({typ}, s) -> name ^ ": " ^ (typ |> Shared.typeToString) ^ "\n\n" ^ s
@@ -1311,7 +1312,7 @@ let getOpens ~rawOpens ~package ~env =
13111312
(* Last open takes priority *)
13121313
List.rev resolvedOpens
13131314

1314-
let processCompletable ~debug ~package ~scope ~env ~pos
1315+
let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
13151316
(completable : Completable.t) =
13161317
let rawOpens = Scope.getRawOpens scope in
13171318
let opens = getOpens ~rawOpens ~package ~env in
@@ -1330,20 +1331,18 @@ let processCompletable ~debug ~package ~scope ~env ~pos
13301331
~env ~exact:false ~scope
13311332
|> List.map completionToItem
13321333
| Cjsx ([id], prefix, identsSeen) when String.uncapitalize_ascii id = id ->
1333-
let mkLabel_ name typString =
1334-
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
1334+
let mkLabel (name, typString) =
1335+
Completion.create ~name ~kind:(Label typString) ~env
13351336
in
1336-
let mkLabel (name, typ) = mkLabel_ name typ in
13371337
let keyLabels =
1338-
if Utils.startsWith "key" prefix then [mkLabel_ "key" "string"] else []
1338+
if Utils.startsWith "key" prefix then [mkLabel ("key", "string")] else []
13391339
in
1340-
if domLabels = [] then []
1341-
else
1342-
(domLabels
1343-
|> List.filter (fun (name, _t) ->
1344-
Utils.startsWith name prefix && not (List.mem name identsSeen))
1345-
|> List.map mkLabel)
1346-
@ keyLabels
1340+
(domLabels
1341+
|> List.filter (fun (name, _t) ->
1342+
Utils.startsWith name prefix && not (List.mem name identsSeen))
1343+
|> List.map mkLabel)
1344+
@ keyLabels
1345+
|> List.map completionToItem
13471346
| Cjsx (componentPath, prefix, identsSeen) ->
13481347
let labels =
13491348
match componentPath @ ["make"] |> findTypeOfValue with
@@ -1389,7 +1388,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos
13891388
| None -> []
13901389
in
13911390
let mkLabel_ name typString =
1392-
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
1391+
Completion.create ~name ~kind:(Label typString) ~env
13931392
in
13941393
let mkLabel (name, typ) = mkLabel_ name (typ |> Shared.typeToString) in
13951394
let keyLabels =
@@ -1399,13 +1398,13 @@ let processCompletable ~debug ~package ~scope ~env ~pos
13991398
else
14001399
(labels
14011400
|> List.filter (fun (name, _t) ->
1402-
Utils.startsWith name prefix && not (List.mem name identsSeen))
1401+
Utils.startsWith name prefix
1402+
&& (forHover || not (List.mem name identsSeen)))
14031403
|> List.map mkLabel)
14041404
@ keyLabels
1405+
|> List.map completionToItem
14051406
| Cdecorator prefix ->
1406-
let mkDecorator name =
1407-
mkItem ~name ~kind:4 ~deprecated:None ~detail:"" ~docstring:[]
1408-
in
1407+
let mkDecorator name = Completion.create ~name ~kind:(Label "") ~env in
14091408
[
14101409
"as";
14111410
"deriving";
@@ -1445,7 +1444,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos
14451444
else decorator
14461445
in
14471446
dec2)
1448-
|> List.map mkDecorator
1447+
|> List.map mkDecorator |> List.map completionToItem
14491448
| CnamedArg (cp, prefix, identsSeen) ->
14501449
let labels =
14511450
match
@@ -1475,11 +1474,9 @@ let processCompletable ~debug ~package ~scope ~env ~pos
14751474
| None -> []
14761475
in
14771476
let mkLabel (name, typ) =
1478-
mkItem ~name ~kind:4 ~deprecated:None
1479-
~detail:(typ |> Shared.typeToString)
1480-
~docstring:[]
1477+
Completion.create ~name ~kind:(Label (typ |> Shared.typeToString)) ~env
14811478
in
14821479
labels
14831480
|> List.filter (fun (name, _t) ->
14841481
Utils.startsWith name prefix && not (List.mem name identsSeen))
1485-
|> List.map mkLabel
1482+
|> List.map mkLabel |> List.map completionToItem

analysis/src/SharedTypes.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ module Completion = struct
209209
| Module of Module.t
210210
| Value of Types.type_expr
211211
| ObjLabel of Types.type_expr
212+
| Label of string
212213
| Type of Type.t
213214
| Constructor of Constructor.t * string
214215
| Field of field * string
@@ -233,6 +234,7 @@ module Completion = struct
233234
| FileModule _ -> 9
234235
| Constructor (_, _) -> 4
235236
| ObjLabel _ -> 4
237+
| Label _ -> 4
236238
| Field (_, _) -> 5
237239
| Type _ -> 22
238240
| Value _ -> 12

0 commit comments

Comments
 (0)