Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect syntax in hover help for module #709

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions analysis/src/Hover.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open SharedTypes

let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
let showModuleTopLevel ~docstring ~isType ~name (topLevel : Module.item list) =
let contents =
topLevel
|> List.map (fun item ->
Expand All @@ -15,7 +15,10 @@ let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
|> String.concat "\n"
in
let full =
Markdown.codeBlock ("module " ^ name ^ " = {" ^ "\n" ^ contents ^ "\n}")
Markdown.codeBlock
("module "
^ (if isType then "type " ^ name ^ " = " else name ^ ": ")
^ "{" ^ "\n" ^ contents ^ "\n}")
in
let doc =
match docstring with
Expand All @@ -27,14 +30,15 @@ let showModuleTopLevel ~docstring ~name (topLevel : Module.item list) =
let rec showModule ~docstring ~(file : File.t) ~name
(declared : Module.t Declared.t option) =
match declared with
| None -> showModuleTopLevel ~docstring ~name file.structure.items
| None ->
showModuleTopLevel ~docstring ~isType:false ~name file.structure.items
| Some {item = Structure {items}; modulePath} ->
let name =
let isType =
match modulePath with
| ExportedModule {isType} when isType = true -> "type " ^ name
| _ -> name
| ExportedModule {isType} -> isType
| _ -> false
in
showModuleTopLevel ~docstring ~name items
showModuleTopLevel ~docstring ~isType ~name items
| Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) ->
(* show the interface *)
showModule ~docstring ~file ~name
Expand Down
10 changes: 5 additions & 5 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Hover src/Hover.res 3:5
{"contents": {"kind": "markdown", "value": "```rescript\ntype t = (int, float)\n```"}}

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

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

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

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

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

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

Hover src/Hover.res 91:10
Nothing at that position. Now trying to use completion.
Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/RecModules.res.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hover src/RecModules.res 18:12
{"contents": {"kind": "markdown", "value": "```rescript\nmodule C = {\n type t\n let createA: t => A.t\n}\n```"}}
{"contents": {"kind": "markdown", "value": "```rescript\nmodule C: {\n type t\n let createA: t => A.t\n}\n```"}}

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