Skip to content

Commit f105db8

Browse files
committed
Add support for recursive modules.
Fixes #194
1 parent f26cb6b commit f105db8

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## master
22
- ppx autocomplete: handle more atomic expressions to the rhs of `=` without braces (variant, polymorphic variant, function call, list literal, nested component, characters, templates).
33
- Autocomplete for function calls: only suggest labeled args that were not yet assigned.
4+
- Add support for recursive modules.
45

56
## 1.1.1
67

analysis/src/ProcessCmt.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ open Typedtree
22
open SharedTypes
33

44
let itemsExtent items =
5-
let open Typedtree in
65
match items with
76
| [] -> Location.none
87
| first :: _ ->
@@ -19,7 +18,6 @@ let itemsExtent items =
1918
}
2019

2120
let sigItemsExtent items =
22-
let open Typedtree in
2321
match items with
2422
| [] -> Location.none
2523
| first :: _ ->
@@ -223,7 +221,7 @@ let forTypeDeclaration ~env ~(exported : exported)
223221
in
224222
{declared with item = MType (declared.item, recStatus)}
225223

226-
let forSignatureItem ~env ~(exported : exported)
224+
let rec forSignatureItem ~env ~(exported : exported)
227225
(item : Typedtree.signature_item) =
228226
match item.sig_desc with
229227
| Tsig_value {val_id; val_loc; val_name = name; val_desc; val_attributes} ->
@@ -252,6 +250,12 @@ let forSignatureItem ~env ~(exported : exported)
252250
md_attributes exported.modules env.stamps.modules
253251
in
254252
[{declared with item = Module declared.item}]
253+
| Tsig_recmodule modDecls ->
254+
modDecls
255+
|> List.map (fun modDecl ->
256+
forSignatureItem ~env ~exported
257+
{item with sig_desc = Tsig_module modDecl})
258+
|> List.flatten
255259
| Tsig_include {incl_mod; incl_type} ->
256260
let env =
257261
match getModuleTypePath incl_mod.mty_desc with
@@ -339,6 +343,12 @@ let rec forStructureItem ~env ~(exported : exported) item =
339343
mb_attributes exported.modules env.stamps.modules
340344
in
341345
[{declared with item = Module declared.item}]
346+
| Tstr_recmodule modDecls ->
347+
modDecls
348+
|> List.map (fun modDecl ->
349+
forStructureItem ~env ~exported
350+
{item with str_desc = Tstr_module modDecl})
351+
|> List.flatten
342352
| Tstr_modtype
343353
{
344354
mtd_name = name;

analysis/tests/src/RecModules.res

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module rec A: {
2+
type t
3+
4+
@send external child: t => B.t = "child"
5+
} = A
6+
7+
and B: {
8+
type t
9+
10+
@send external parent: t => A.t = "parent"
11+
} = B
12+
13+
module C = {
14+
type t
15+
16+
@send external createA: t => A.t = "createA"
17+
}
18+
19+
module MC = C
20+
// ^hov
21+
module MA = A
22+
// ^hov
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hover tests/src/RecModules.res 18:12
2+
{"contents": "```rescript\nmodule C = {\n type t\n let createA: t => A.t\n}\n```"}
3+
4+
Hover tests/src/RecModules.res 20:12
5+
{"contents": "```rescript\nmodule A = {\n type t\n let child: t => B.t\n}\n```"}
6+

0 commit comments

Comments
 (0)