Skip to content

Commit 1f482cc

Browse files
Merge pull request #199 from oxcaml/outline-include-includes
Make outline include things from `include` statements
2 parents ee6219e + 8705ba6 commit 1f482cc

File tree

3 files changed

+172
-9
lines changed

3 files changed

+172
-9
lines changed

src/analysis/outline.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,18 @@ and get_mod_children ~include_types node =
179179

180180
and remove_mod_indir ~include_types node =
181181
match node.t_node with
182-
| Module_expr _ | Module_type _ ->
183-
List.concat_map
184-
(Lazy.force node.t_children)
185-
~f:(remove_mod_indir ~include_types)
182+
| Module_expr _ | Module_type _ -> get_mod_children ~include_types node
186183
| _ -> remove_top_indir ~include_types node
187184

188185
and remove_top_indir ~include_types t =
189186
match t.t_node with
190-
| Structure _ | Signature _ ->
191-
List.concat_map
192-
~f:(remove_top_indir ~include_types)
193-
(Lazy.force t.t_children)
187+
| Structure _ | Signature _ -> get_mod_children ~include_types t
194188
| Signature_item _ | Structure_item _ ->
195-
List.filter_map (Lazy.force t.t_children) ~f:(summarize ~include_types)
189+
List.concat_map (Lazy.force t.t_children) ~f:(fun child ->
190+
match child.t_node with
191+
| Include_declaration _ | Include_description _ ->
192+
get_mod_children ~include_types child
193+
| _ -> summarize ~include_types child |> Option.to_list)
196194
| _ -> []
197195

198196
let get ~include_types browses =

tests/test-dirs/outline.t/foo.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,23 @@ type 'a point =
2626
; y : 'a
2727
; z : 'a
2828
}
29+
30+
include struct
31+
type t
32+
let x = 1
33+
include struct
34+
type u
35+
let y = "y"
36+
end
37+
end
38+
39+
module type S = sig
40+
include sig
41+
type t
42+
val x : int
43+
include sig
44+
type u
45+
val y : string
46+
end
47+
end
48+
end

tests/test-dirs/outline.t/run.t

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,142 @@
33
{
44
"class": "return",
55
"value": [
6+
{
7+
"start": {
8+
"line": 39,
9+
"col": 0
10+
},
11+
"end": {
12+
"line": 48,
13+
"col": 3
14+
},
15+
"name": "S",
16+
"kind": "Signature",
17+
"type": null,
18+
"children": [
19+
{
20+
"start": {
21+
"line": 45,
22+
"col": 6
23+
},
24+
"end": {
25+
"line": 45,
26+
"col": 20
27+
},
28+
"name": "y",
29+
"kind": "Value",
30+
"type": "string",
31+
"children": [],
32+
"deprecated": false
33+
},
34+
{
35+
"start": {
36+
"line": 44,
37+
"col": 6
38+
},
39+
"end": {
40+
"line": 44,
41+
"col": 12
42+
},
43+
"name": "u",
44+
"kind": "Type",
45+
"type": null,
46+
"children": [],
47+
"deprecated": false
48+
},
49+
{
50+
"start": {
51+
"line": 42,
52+
"col": 4
53+
},
54+
"end": {
55+
"line": 42,
56+
"col": 15
57+
},
58+
"name": "x",
59+
"kind": "Value",
60+
"type": "int",
61+
"children": [],
62+
"deprecated": false
63+
},
64+
{
65+
"start": {
66+
"line": 41,
67+
"col": 4
68+
},
69+
"end": {
70+
"line": 41,
71+
"col": 10
72+
},
73+
"name": "t",
74+
"kind": "Type",
75+
"type": null,
76+
"children": [],
77+
"deprecated": false
78+
}
79+
],
80+
"deprecated": false
81+
},
82+
{
83+
"start": {
84+
"line": 35,
85+
"col": 4
86+
},
87+
"end": {
88+
"line": 35,
89+
"col": 15
90+
},
91+
"name": "y",
92+
"kind": "Value",
93+
"type": "string",
94+
"children": [],
95+
"deprecated": false
96+
},
97+
{
98+
"start": {
99+
"line": 34,
100+
"col": 4
101+
},
102+
"end": {
103+
"line": 34,
104+
"col": 10
105+
},
106+
"name": "u",
107+
"kind": "Type",
108+
"type": null,
109+
"children": [],
110+
"deprecated": false
111+
},
112+
{
113+
"start": {
114+
"line": 32,
115+
"col": 2
116+
},
117+
"end": {
118+
"line": 32,
119+
"col": 11
120+
},
121+
"name": "x",
122+
"kind": "Value",
123+
"type": "int",
124+
"children": [],
125+
"deprecated": false
126+
},
127+
{
128+
"start": {
129+
"line": 31,
130+
"col": 2
131+
},
132+
"end": {
133+
"line": 31,
134+
"col": 8
135+
},
136+
"name": "t",
137+
"kind": "Type",
138+
"type": null,
139+
"children": [],
140+
"deprecated": false
141+
},
6142
{
7143
"start": {
8144
"line": 24,
@@ -261,3 +397,12 @@ Check that when we pass "-include-types false", every "type" is null.
261397
null
262398
null
263399
null
400+
null
401+
null
402+
null
403+
null
404+
null
405+
null
406+
null
407+
null
408+
null

0 commit comments

Comments
 (0)