Skip to content

Handle object expression inside a let in outline #1936

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 5 commits into from
May 27, 2025
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ unreleased
- `inlay-hints` fix inlay hints on function parameters (#1923)
- Fix issues with ident validation and Lid comparison for occurrences (#1924)
- Handle class type in outline (#1932)
- Handle locally defined value in outline (#1936)
+ ocaml-index
- Improve the granularity of index reading by segmenting the marshalization
of the involved data-structures. (#1889)
Expand Down
55 changes: 34 additions & 21 deletions src/analysis/outline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ let mk ?(children = []) ~location ~deprecated outline_kind outline_type id =
deprecated
}

let get_class_field_desc_infos = function
| Typedtree.Tcf_val (str_loc, _, _, _, _) -> Some (str_loc, `Value)
| Typedtree.Tcf_method (str_loc, _, _) -> Some (str_loc, `Method)
| _ -> None

let get_class_signature_field_desc_infos = function
| Typedtree.Tctf_val (outline_name, _, _, _) -> Some (outline_name, `Value)
| Typedtree.Tctf_method (outline_name, _, _, _) -> Some (outline_name, `Method)
Expand All @@ -69,13 +64,16 @@ let rec summarize node =
let location = node.t_loc in
match node.t_node with
| Value_binding vb ->
let children =
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
in
let deprecated = Type_utils.is_deprecated vb.vb_attributes in
begin
match id_of_patt vb.vb_pat with
| None -> None
| Some ident ->
let typ = outline_type ~env:node.t_env vb.vb_pat.pat_type in
Some (mk ~location ~deprecated `Value typ ident)
Some (mk ~children ~location ~deprecated `Value typ ident)
end
| Value_description vd ->
let deprecated = Type_utils.is_deprecated vd.val_attributes in
Expand Down Expand Up @@ -155,26 +153,36 @@ let rec summarize node =
(mk ~children ~location `ClassType None ctd.ci_id_class_type ~deprecated)
| _ -> None

and get_val_elements node =
match node.t_node with
| Expression _ ->
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
| Class_expr _ | Class_structure _ -> get_class_elements node
| _ -> Option.to_list (summarize node)

and get_class_elements node =
match node.t_node with
| Class_expr _ ->
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
| Class_field cf ->
let children =
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
in
cf.cf_desc |> get_class_field_desc_infos
|> Option.map ~f:(fun (str_loc, outline_kind) ->
let deprecated = Type_utils.is_deprecated cf.cf_attributes in
{ Query_protocol.outline_name = str_loc.Location.txt;
outline_kind;
outline_type = None;
location = str_loc.Location.loc;
children;
deprecated
})
|> Option.to_list
| Class_field_kind _ ->
List.concat_map (Lazy.force node.t_children) ~f:get_val_elements
| Class_structure _ ->
List.filter_map (Lazy.force node.t_children) ~f:(fun child ->
match child.t_node with
| Class_field cf -> begin
cf.cf_desc |> get_class_field_desc_infos
|> Option.map ~f:(fun (str_loc, outline_kind) ->
let deprecated = Type_utils.is_deprecated cf.cf_attributes in
{ Query_protocol.outline_name = str_loc.Location.txt;
outline_kind;
outline_type = None;
location = str_loc.Location.loc;
children = [];
deprecated
})
end
| _ -> None)
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
| Class_type { cltyp_desc = Tcty_signature { csig_fields; _ }; _ } ->
List.filter_map csig_fields ~f:(fun field ->
get_class_signature_field_desc_infos field.ctf_desc
Expand All @@ -190,6 +198,11 @@ and get_class_elements node =
}))
| _ -> []

and get_class_field_desc_infos = function
| Typedtree.Tcf_val (str_loc, _, _, _field_kind, _) -> Some (str_loc, `Value)
| Typedtree.Tcf_method (str_loc, _, _field_kind) -> Some (str_loc, `Method)
| _ -> None

and get_mod_children node =
List.concat_map (Lazy.force node.t_children) ~f:remove_mod_indir

Expand Down
68 changes: 66 additions & 2 deletions tests/test-dirs/outline.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,39 @@
"name": "final_let",
"kind": "Value",
"type": "< foo : int >",
"children": [],
"children": [
{
"start": {
"line": 68,
"col": 2
},
"end": {
"line": 71,
"col": 7
},
"name": "c",
"kind": "Value",
"type": "< foo : int >",
"children": [
{
"start": {
"line": 70,
"col": 13
},
"end": {
"line": 70,
"col": 16
},
"name": "foo",
"kind": "Method",
"type": null,
"children": [],
"deprecated": false
}
],
"deprecated": false
}
],
"deprecated": false
},
{
Expand Down Expand Up @@ -135,7 +167,39 @@
"name": "b",
"kind": "Value",
"type": null,
"children": [],
"children": [
{
"start": {
"line": 49,
"col": 15
},
"end": {
"line": 49,
"col": 25
},
"name": "inside_a_b",
"kind": "Method",
"type": null,
"children": [
{
"start": {
"line": 50,
"col": 10
},
"end": {
"line": 50,
"col": 31
},
"name": "x_inside_a_b",
"kind": "Value",
"type": "int",
"children": [],
"deprecated": false
}
],
"deprecated": false
}
],
"deprecated": false
}
],
Expand Down
Loading