Skip to content

Commit b027d50

Browse files
committed
Hover: missing ```rescript for built-in types.
1 parent ac78c6c commit b027d50

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

analysis/src/Hover.ml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ let digConstructor ~env ~getModule path =
44
| `Stamp stamp -> (
55
match Hashtbl.find_opt env.file.stamps.types stamp with
66
| None -> None
7-
| Some t -> Some (env, t) )
7+
| Some t -> Some (env, t))
88
| `Exported (env, name) -> (
99
match Hashtbl.find_opt env.exported.types name with
1010
| None -> None
1111
| Some stamp -> (
1212
match Hashtbl.find_opt env.file.stamps.types stamp with
1313
| None -> None
14-
| Some t -> Some (env, t) ) )
14+
| Some t -> Some (env, t)))
1515
| _ -> None
1616

1717
let codeBlock code = Printf.sprintf "```rescript\n%s\n```" code
@@ -21,22 +21,23 @@ let showModuleTopLevel ~docstring ~name
2121
let contents =
2222
topLevel
2323
|> List.map (fun item ->
24-
match item.SharedTypes.item with
25-
(* TODO pretty print module contents *)
26-
| SharedTypes.MType ({decl}, recStatus) ->
27-
" " ^ (decl |> Shared.declToString ~recStatus item.name.txt)
28-
| Module _ -> " module " ^ item.name.txt
29-
| MValue typ ->
30-
" let " ^ item.name.txt ^ ": " ^ (typ |> Shared.typeToString)) (* TODO indent *)
24+
match item.SharedTypes.item with
25+
(* TODO pretty print module contents *)
26+
| SharedTypes.MType ({decl}, recStatus) ->
27+
" " ^ (decl |> Shared.declToString ~recStatus item.name.txt)
28+
| Module _ -> " module " ^ item.name.txt
29+
| MValue typ ->
30+
" let " ^ item.name.txt ^ ": " ^ (typ |> Shared.typeToString))
31+
(* TODO indent *)
3132
|> String.concat "\n"
3233
in
33-
let full = "module " ^ name ^ " = {" ^ "\n" ^ contents ^ "\n}" in
34+
let full = codeBlock ("module " ^ name ^ " = {" ^ "\n" ^ contents ^ "\n}") in
3435
let doc =
3536
match docstring with
3637
| [] -> ""
3738
| _ :: _ -> "\n" ^ (docstring |> String.concat "\n") ^ "\n"
3839
in
39-
Some (doc ^ codeBlock full)
40+
Some (doc ^ full)
4041

4142
let showModule ~docstring ~(file : SharedTypes.file) ~name
4243
(declared : SharedTypes.moduleKind SharedTypes.declared option) =
@@ -65,7 +66,7 @@ let newHover ~(file : SharedTypes.file) ~getModule loc =
6566
| Some d -> (d.name.txt, d.docstring)
6667
| None -> (file.moduleName, file.contents.docstring)
6768
in
68-
showModule ~docstring ~name ~file declared ) )
69+
showModule ~docstring ~name ~file declared))
6970
| LModule (GlobalReference (moduleName, path, tip)) -> (
7071
match getModule moduleName with
7172
| None -> None
@@ -88,25 +89,26 @@ let newHover ~(file : SharedTypes.file) ~getModule loc =
8889
| Some d -> (d.name.txt, d.docstring)
8990
| None -> (file.moduleName, file.contents.docstring)
9091
in
91-
showModule ~docstring ~name ~file declared ) ) ) ) )
92+
showModule ~docstring ~name ~file declared)))))
9293
| LModule NotFound -> None
9394
| TopLevelModule name -> (
9495
match getModule name with
9596
| None -> None
9697
| Some file ->
9798
showModule ~docstring:file.contents.docstring ~name:file.moduleName ~file
98-
None )
99+
None)
99100
| Typed (_, Definition (_, (Field _ | Constructor _))) -> None
100101
| Constant t ->
101102
Some
102-
( match t with
103-
| Const_int _ -> "int"
104-
| Const_char _ -> "char"
105-
| Const_string _ -> "string"
106-
| Const_float _ -> "float"
107-
| Const_int32 _ -> "int32"
108-
| Const_int64 _ -> "int64"
109-
| Const_nativeint _ -> "int" )
103+
(codeBlock
104+
(match t with
105+
| Const_int _ -> "int"
106+
| Const_char _ -> "char"
107+
| Const_string _ -> "string"
108+
| Const_float _ -> "float"
109+
| Const_int32 _ -> "int32"
110+
| Const_int64 _ -> "int64"
111+
| Const_nativeint _ -> "int"))
110112
| Typed (t, locKind) ->
111113
let fromType ~docstring typ =
112114
let typeString = codeBlock (typ |> Shared.typeToString) in
@@ -122,7 +124,7 @@ let newHover ~(file : SharedTypes.file) ~getModule loc =
122124
Utils.startsWith (Path.name path) "Js.Fn.arity"
123125
in
124126
if isUncurriedInternal then None
125-
else Some (decl |> Shared.declToString txt, docstring) )
127+
else Some (decl |> Shared.declToString txt, docstring))
126128
in
127129
let typeString, docstring =
128130
match extraTypeInfo with
@@ -155,6 +157,6 @@ let newHover ~(file : SharedTypes.file) ~getModule loc =
155157
typeString :: codeBlock (txt ^ argsString) :: docstring
156158
| `Field {typ} ->
157159
let typeString, docstring = typ |> fromType ~docstring in
158-
typeString :: docstring )
160+
typeString :: docstring)
159161
in
160162
Some (String.concat "\n\n" parts)

analysis/tests/src/Hover.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ let make = (~name) => React.string(name)
4040

4141
@react.component
4242
let make2 = (~name:string) => React.string(name)
43-
// ^hov
43+
// ^hov
44+
45+
let num = 34
46+
// ^hov

analysis/tests/src/expected/Hover.res.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ Hover tests/src/Hover.res 37:13
2525
Hover tests/src/Hover.res 41:13
2626
{"contents": "```rescript\nstring\n```"}
2727

28+
Hover tests/src/Hover.res 44:10
29+
{"contents": "```rescript\nint\n```"}
30+

0 commit comments

Comments
 (0)