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

resolve module aliases in hover #820

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## master

#### :nail_care: Polish

- Resolve module aliases in hover. https://github.com/rescript-lang/rescript-vscode/pull/820

## 1.20.0

#### :rocket: New Feature
Expand Down
16 changes: 9 additions & 7 deletions analysis/src/Hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let showModuleTopLevel ~docstring ~isType ~name (topLevel : Module.item list) =
in
Some (doc ^ full)

let rec showModule ~docstring ~(file : File.t) ~name
let rec showModule ~docstring ~(file : File.t) ~package ~name
(declared : Module.t Declared.t option) =
match declared with
| None ->
Expand All @@ -41,10 +41,12 @@ let rec showModule ~docstring ~(file : File.t) ~name
showModuleTopLevel ~docstring ~isType ~name items
| Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) ->
(* show the interface *)
showModule ~docstring ~file ~name
showModule ~docstring ~file ~name ~package
(Some {declared with item = moduleTypeItem})
| Some {item = Ident path} ->
Some ("Unable to resolve module reference " ^ Path.name path)
| Some ({item = Ident path} as declared) -> (
match References.resolveModuleReference ~file ~package declared with
| None -> Some ("Unable to resolve module reference " ^ Path.name path)
| Some (_, declared) -> showModule ~docstring ~file ~name ~package declared)

type extractedType = {
name: string;
Expand Down Expand Up @@ -179,7 +181,7 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
| Some d -> (d.name.txt, d.docstring)
| None -> (file.moduleName, file.structure.docstring)
in
showModule ~docstring ~name ~file declared))
showModule ~docstring ~name ~file declared ~package))
| LModule (GlobalReference (moduleName, path, tip)) -> (
match ProcessCmt.fileForModule ~package moduleName with
| None -> None
Expand All @@ -199,14 +201,14 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
| Some d -> (d.name.txt, d.docstring)
| None -> (file.moduleName, file.structure.docstring)
in
showModule ~docstring ~name ~file declared))))
showModule ~docstring ~name ~file ~package declared))))
| LModule NotFound -> None
| TopLevelModule name -> (
match ProcessCmt.fileForModule ~package name with
| None -> None
| Some file ->
showModule ~docstring:file.structure.docstring ~name:file.moduleName ~file
None)
~package None)
| Typed (_, _, Definition (_, (Field _ | Constructor _))) -> None
| Constant t ->
Some
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/Hover.res
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@ let coolVariant = CoolVariant

// switch x { | {someField} => someField }
// ^hov

module Arr = Belt.Array
// ^hov
3 changes: 3 additions & 0 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,6 @@ ContextPath Value[x]
Path x
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```"}}

Hover src/Hover.res 263:8
{"contents": {"kind": "markdown", "value": "\n [`Belt.Array`]()\n\n **mutable array**: Utilities functions\n\n```rescript\nmodule Array: {\n module Id\n module Array\n module SortArray\n module MutableQueue\n module MutableStack\n module List\n module Range\n module Set\n module Map\n module MutableSet\n module MutableMap\n module HashSet\n module HashMap\n module Option\n module Result\n module Int\n module Float\n}\n```"}}