Skip to content

Commit 51c85ca

Browse files
cknittzth
authored andcommitted
Fix incorrect syntax in hover help for module
1 parent 25caa49 commit 51c85ca

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

analysis/src/Hover.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open SharedTypes
22

3-
let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
3+
let showModuleTopLevel ~docstring ~isType ~name (topLevel : Module.item list) =
44
let contents =
55
topLevel
66
|> List.map (fun item ->
@@ -15,7 +15,10 @@ let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
1515
|> String.concat "\n"
1616
in
1717
let full =
18-
Markdown.codeBlock ("module " ^ name ^ " = {" ^ "\n" ^ contents ^ "\n}")
18+
Markdown.codeBlock
19+
("module "
20+
^ (if isType then "type " ^ name ^ " = " else name ^ ": ")
21+
^ "{" ^ "\n" ^ contents ^ "\n}")
1922
in
2023
let doc =
2124
match docstring with
@@ -27,14 +30,15 @@ let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
2730
let rec showModule ~docstring ~(file : File.t) ~name
2831
(declared : Module.t Declared.t option) =
2932
match declared with
30-
| None -> showModuleTopLevel ~docstring ~name file.structure.items
33+
| None ->
34+
showModuleTopLevel ~docstring ~isType:false ~name file.structure.items
3135
| Some {item = Structure {items}; modulePath} ->
32-
let name =
36+
let isType =
3337
match modulePath with
34-
| ExportedModule {isType} when isType = true -> "type " ^ name
35-
| _ -> name
38+
| ExportedModule {isType} -> isType
39+
| _ -> false
3640
in
37-
showModuleTopLevel ~docstring ~name items
41+
showModuleTopLevel ~docstring ~isType ~name items
3842
| Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) ->
3943
(* show the interface *)
4044
showModule ~docstring ~file ~name

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Hover src/Hover.res 3:5
55
{"contents": {"kind": "markdown", "value": "```rescript\ntype t = (int, float)\n```"}}
66

77
Hover src/Hover.res 6:7
8-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule Id = {\n type x = int\n}\n```"}}
8+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule Id: {\n type x = int\n}\n```"}}
99

1010
Hover src/Hover.res 19:11
11-
{"contents": {"kind": "markdown", "value": "\nThis module is commented\n```rescript\nmodule Dep = {\n let customDouble: int => int\n}\n```"}}
11+
{"contents": {"kind": "markdown", "value": "\nThis module is commented\n```rescript\nmodule Dep: {\n let customDouble: int => int\n}\n```"}}
1212

1313
Hover src/Hover.res 22:11
1414
{"contents": {"kind": "markdown", "value": "```rescript\nint => int\n```\n\nSome doc comment"}}
@@ -50,13 +50,13 @@ Definition src/Hover.res 60:14
5050
{"uri": "Hover.res", "range": {"start": {"line": 49, "character": 12}, "end": {"line": 49, "character": 18}}}
5151

5252
Hover src/Hover.res 63:9
53-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule IdDefinedTwice = {\n let y: int\n let _x: int\n}\n```"}}
53+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule IdDefinedTwice: {\n let y: int\n let _x: int\n}\n```"}}
5454

5555
Hover src/Hover.res 74:7
56-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A = {\n let x: int\n}\n```"}}
56+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A: {\n let x: int\n}\n```"}}
5757

5858
Hover src/Hover.res 77:7
59-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A = {\n let x: int\n}\n```"}}
59+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A: {\n let x: int\n}\n```"}}
6060

6161
Hover src/Hover.res 91:10
6262
Nothing at that position. Now trying to use completion.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Hover src/RecModules.res 18:12
2-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule C = {\n type t\n let createA: t => A.t\n}\n```"}}
2+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule C: {\n type t\n let createA: t => A.t\n}\n```"}}
33

44
Hover src/RecModules.res 20:12
5-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A = {\n type t\n let child: t => B.t\n}\n```"}}
5+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A: {\n type t\n let child: t => B.t\n}\n```"}}
66

0 commit comments

Comments
 (0)