Skip to content

Commit fbd7876

Browse files
authored
Merge pull request #1936 from Tim-ats-d/nested-let-outline
Handle object expression inside a let in outline
2 parents 3865a38 + 726c605 commit fbd7876

File tree

3 files changed

+101
-23
lines changed

3 files changed

+101
-23
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ unreleased
1010
- `inlay-hints` fix inlay hints on function parameters (#1923)
1111
- Fix issues with ident validation and Lid comparison for occurrences (#1924)
1212
- Handle class type in outline (#1932)
13+
- Handle locally defined value in outline (#1936)
1314
+ ocaml-index
1415
- Improve the granularity of index reading by segmenting the marshalization
1516
of the involved data-structures. (#1889)

src/analysis/outline.ml

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ let mk ?(children = []) ~location ~deprecated outline_kind outline_type id =
4848
deprecated
4949
}
5050

51-
let get_class_field_desc_infos = function
52-
| Typedtree.Tcf_val (str_loc, _, _, _, _) -> Some (str_loc, `Value)
53-
| Typedtree.Tcf_method (str_loc, _, _) -> Some (str_loc, `Method)
54-
| _ -> None
55-
5651
let get_class_signature_field_desc_infos = function
5752
| Typedtree.Tctf_val (outline_name, _, _, _) -> Some (outline_name, `Value)
5853
| Typedtree.Tctf_method (outline_name, _, _, _) -> Some (outline_name, `Method)
@@ -69,13 +64,16 @@ let rec summarize node =
6964
let location = node.t_loc in
7065
match node.t_node with
7166
| Value_binding vb ->
67+
let children =
68+
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
69+
in
7270
let deprecated = Type_utils.is_deprecated vb.vb_attributes in
7371
begin
7472
match id_of_patt vb.vb_pat with
7573
| None -> None
7674
| Some ident ->
7775
let typ = outline_type ~env:node.t_env vb.vb_pat.pat_type in
78-
Some (mk ~location ~deprecated `Value typ ident)
76+
Some (mk ~children ~location ~deprecated `Value typ ident)
7977
end
8078
| Value_description vd ->
8179
let deprecated = Type_utils.is_deprecated vd.val_attributes in
@@ -155,26 +153,36 @@ let rec summarize node =
155153
(mk ~children ~location `ClassType None ctd.ci_id_class_type ~deprecated)
156154
| _ -> None
157155

156+
and get_val_elements node =
157+
match node.t_node with
158+
| Expression _ ->
159+
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
160+
| Class_expr _ | Class_structure _ -> get_class_elements node
161+
| _ -> Option.to_list (summarize node)
162+
158163
and get_class_elements node =
159164
match node.t_node with
160165
| Class_expr _ ->
161166
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
167+
| Class_field cf ->
168+
let children =
169+
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
170+
in
171+
cf.cf_desc |> get_class_field_desc_infos
172+
|> Option.map ~f:(fun (str_loc, outline_kind) ->
173+
let deprecated = Type_utils.is_deprecated cf.cf_attributes in
174+
{ Query_protocol.outline_name = str_loc.Location.txt;
175+
outline_kind;
176+
outline_type = None;
177+
location = str_loc.Location.loc;
178+
children;
179+
deprecated
180+
})
181+
|> Option.to_list
182+
| Class_field_kind _ ->
183+
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
162184
| Class_structure _ ->
163-
List.filter_map (Lazy.force node.t_children) ~f:(fun child ->
164-
match child.t_node with
165-
| Class_field cf -> begin
166-
cf.cf_desc |> get_class_field_desc_infos
167-
|> Option.map ~f:(fun (str_loc, outline_kind) ->
168-
let deprecated = Type_utils.is_deprecated cf.cf_attributes in
169-
{ Query_protocol.outline_name = str_loc.Location.txt;
170-
outline_kind;
171-
outline_type = None;
172-
location = str_loc.Location.loc;
173-
children = [];
174-
deprecated
175-
})
176-
end
177-
| _ -> None)
185+
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
178186
| Class_type { cltyp_desc = Tcty_signature { csig_fields; _ }; _ } ->
179187
List.filter_map csig_fields ~f:(fun field ->
180188
get_class_signature_field_desc_infos field.ctf_desc
@@ -190,6 +198,11 @@ and get_class_elements node =
190198
}))
191199
| _ -> []
192200

201+
and get_class_field_desc_infos = function
202+
| Typedtree.Tcf_val (str_loc, _, _, _field_kind, _) -> Some (str_loc, `Value)
203+
| Typedtree.Tcf_method (str_loc, _, _field_kind) -> Some (str_loc, `Method)
204+
| _ -> None
205+
193206
and get_mod_children node =
194207
List.concat_map (Lazy.force node.t_children) ~f:remove_mod_indir
195208

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,39 @@
1515
"name": "final_let",
1616
"kind": "Value",
1717
"type": "< foo : int >",
18-
"children": [],
18+
"children": [
19+
{
20+
"start": {
21+
"line": 68,
22+
"col": 2
23+
},
24+
"end": {
25+
"line": 71,
26+
"col": 7
27+
},
28+
"name": "c",
29+
"kind": "Value",
30+
"type": "< foo : int >",
31+
"children": [
32+
{
33+
"start": {
34+
"line": 70,
35+
"col": 13
36+
},
37+
"end": {
38+
"line": 70,
39+
"col": 16
40+
},
41+
"name": "foo",
42+
"kind": "Method",
43+
"type": null,
44+
"children": [],
45+
"deprecated": false
46+
}
47+
],
48+
"deprecated": false
49+
}
50+
],
1951
"deprecated": false
2052
},
2153
{
@@ -135,7 +167,39 @@
135167
"name": "b",
136168
"kind": "Value",
137169
"type": null,
138-
"children": [],
170+
"children": [
171+
{
172+
"start": {
173+
"line": 49,
174+
"col": 15
175+
},
176+
"end": {
177+
"line": 49,
178+
"col": 25
179+
},
180+
"name": "inside_a_b",
181+
"kind": "Method",
182+
"type": null,
183+
"children": [
184+
{
185+
"start": {
186+
"line": 50,
187+
"col": 10
188+
},
189+
"end": {
190+
"line": 50,
191+
"col": 31
192+
},
193+
"name": "x_inside_a_b",
194+
"kind": "Value",
195+
"type": "int",
196+
"children": [],
197+
"deprecated": false
198+
}
199+
],
200+
"deprecated": false
201+
}
202+
],
139203
"deprecated": false
140204
}
141205
],

0 commit comments

Comments
 (0)