Skip to content

Add support for transitive module references. #221

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

Merged
merged 1 commit into from
May 5, 2021
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
9 changes: 9 additions & 0 deletions analysis/src/Hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ let newHover ~full:{SharedTypes.file; package} locItem =
typeString :: docstring)
in
Some (String.concat "\n\n" parts)


module A = struct end

module B = A

module C = B

module D = C
9 changes: 7 additions & 2 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ let alternateDeclared ~(file : File.t) ~package declared tip =
| Some declared -> Some (file, extra, declared)))
| _ -> None)

let rec resolveModuleReference ~file ~package (declared : moduleKind declared) =
let rec resolveModuleReference ?(pathsSeen = []) ~file ~package
(declared : moduleKind declared) =
match declared.item with
| Structure _ -> Some (file, Some declared)
| Constraint (_moduleItem, moduleTypeItem) ->
resolveModuleReference ~file ~package {declared with item = moduleTypeItem}
resolveModuleReference ~pathsSeen ~file ~package
{declared with item = moduleTypeItem}
| Ident path -> (
let env = QueryEnv.fromFile file in
match ProcessCmt.fromCompilerPath ~env path with
Expand Down Expand Up @@ -226,6 +228,9 @@ let rec resolveModuleReference ~file ~package (declared : moduleKind declared) =
| `Stamp stamp -> (
match Hashtbl.find_opt file.stamps.modules stamp with
| None -> None
| Some ({item = Ident path} as md) when not (List.mem path pathsSeen) ->
(* avoid possible infinite loops *)
resolveModuleReference ~file ~package ~pathsSeen:(path :: pathsSeen) md
| Some md -> Some (file, Some md))
| `GlobalMod name -> (
match ProcessCmt.fileForModule ~package name with
Expand Down
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ Hover tests/src/Hover.res 71:7
{"contents": "```rescript\nmodule A = {\n let x: int\n}\n```"}

Hover tests/src/Hover.res 74:7
{"contents": "Unable to resolve module reference A"}
{"contents": "```rescript\nmodule A = {\n let x: int\n}\n```"}