Skip to content

Add support for recursive modules. #219

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 4, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master
- ppx autocomplete: handle more atomic expressions to the rhs of `=` without braces (variant, polymorphic variant, function call, list literal, nested component, characters, templates).
- Autocomplete for function calls: only suggest labeled args that were not yet assigned.
- Add support for recursive modules.

## 1.1.1

Expand Down
16 changes: 13 additions & 3 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ open Typedtree
open SharedTypes

let itemsExtent items =
let open Typedtree in
match items with
| [] -> Location.none
| first :: _ ->
Expand All @@ -19,7 +18,6 @@ let itemsExtent items =
}

let sigItemsExtent items =
let open Typedtree in
match items with
| [] -> Location.none
| first :: _ ->
Expand Down Expand Up @@ -223,7 +221,7 @@ let forTypeDeclaration ~env ~(exported : exported)
in
{declared with item = MType (declared.item, recStatus)}

let forSignatureItem ~env ~(exported : exported)
let rec forSignatureItem ~env ~(exported : exported)
(item : Typedtree.signature_item) =
match item.sig_desc with
| Tsig_value {val_id; val_loc; val_name = name; val_desc; val_attributes} ->
Expand Down Expand Up @@ -252,6 +250,12 @@ let forSignatureItem ~env ~(exported : exported)
md_attributes exported.modules env.stamps.modules
in
[{declared with item = Module declared.item}]
| Tsig_recmodule modDecls ->
modDecls
|> List.map (fun modDecl ->
forSignatureItem ~env ~exported
{item with sig_desc = Tsig_module modDecl})
|> List.flatten
| Tsig_include {incl_mod; incl_type} ->
let env =
match getModuleTypePath incl_mod.mty_desc with
Expand Down Expand Up @@ -339,6 +343,12 @@ let rec forStructureItem ~env ~(exported : exported) item =
mb_attributes exported.modules env.stamps.modules
in
[{declared with item = Module declared.item}]
| Tstr_recmodule modDecls ->
modDecls
|> List.map (fun modDecl ->
forStructureItem ~env ~exported
{item with str_desc = Tstr_module modDecl})
|> List.flatten
| Tstr_modtype
{
mtd_name = name;
Expand Down
22 changes: 22 additions & 0 deletions analysis/tests/src/RecModules.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module rec A: {
type t

@send external child: t => B.t = "child"
} = A

and B: {
type t

@send external parent: t => A.t = "parent"
} = B

module C = {
type t

@send external createA: t => A.t = "createA"
}

module MC = C
// ^hov
module MA = A
// ^hov
6 changes: 6 additions & 0 deletions analysis/tests/src/expected/RecModules.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hover tests/src/RecModules.res 18:12
{"contents": "```rescript\nmodule C = {\n type t\n let createA: t => A.t\n}\n```"}

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