Skip to content

Commit ddd41dc

Browse files
authored
Merge pull request #1942 from voodoos/selection-loc-in-outline
Add a new `selection` field to outline that contains symbols locations
2 parents 754ec9e + ced4333 commit ddd41dc

File tree

7 files changed

+784
-95
lines changed

7 files changed

+784
-95
lines changed

.github/workflows/changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ on:
88
jobs:
99
Changelog-Entry-Check:
1010
name: Check Changelog Action
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: tarides/changelog-check-action@v3

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ unreleased
1515
fixes #1913)
1616
- Downstreamed a typer fix from 5.3.X that would trigger assertions linked
1717
to scopes bit masks when backtracking the typer cache (#1935)
18+
- Add a new selection field to outline results that contains the location of
19+
the symbol itself. (#1942)
1820
+ ocaml-index
1921
- Improve the granularity of index reading by segmenting the marshalization
2022
of the involved data-structures. (#1889)

src/analysis/outline.ml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ open Typedtree
3535
open Browse_raw
3636
open Browse_tree
3737

38-
let id_of_patt = function
39-
| { pat_desc = Tpat_var (id, _, _); _ } -> Some id
38+
let name_of_patt = function
39+
| { pat_desc = Tpat_var (_, name, _); _ } -> Some name
4040
| _ -> None
4141

42-
let mk ?(children = []) ~location ~deprecated outline_kind outline_type id =
42+
let mk ?(children = []) ~location ~deprecated outline_kind outline_type
43+
(name : string Location.loc) =
4344
{ Query_protocol.outline_kind;
4445
outline_type;
4546
location;
47+
selection = name.loc;
4648
children;
47-
outline_name = Ident.name id;
49+
outline_name = name.txt;
4850
deprecated
4951
}
5052

@@ -69,38 +71,38 @@ let rec summarize node =
6971
in
7072
let deprecated = Type_utils.is_deprecated vb.vb_attributes in
7173
begin
72-
match id_of_patt vb.vb_pat with
74+
match name_of_patt vb.vb_pat with
7375
| None -> None
74-
| Some ident ->
76+
| Some name ->
7577
let typ = outline_type ~env:node.t_env vb.vb_pat.pat_type in
76-
Some (mk ~children ~location ~deprecated `Value typ ident)
78+
Some (mk ~children ~location ~deprecated `Value typ name)
7779
end
7880
| Value_description vd ->
7981
let deprecated = Type_utils.is_deprecated vd.val_attributes in
8082
let typ = outline_type ~env:node.t_env vd.val_val.val_type in
81-
Some (mk ~location ~deprecated `Value typ vd.val_id)
83+
Some (mk ~location ~deprecated `Value typ vd.val_name)
8284
| Module_declaration md ->
8385
let children = get_mod_children node in
8486
begin
85-
match md.md_id with
86-
| None -> None
87-
| Some id ->
87+
match md.md_name with
88+
| { txt = None; _ } -> None
89+
| { txt = Some txt; loc } ->
8890
let deprecated = Type_utils.is_deprecated md.md_attributes in
89-
Some (mk ~children ~location ~deprecated `Module None id)
91+
Some (mk ~children ~location ~deprecated `Module None { txt; loc })
9092
end
9193
| Module_binding mb ->
9294
let children = get_mod_children node in
9395
begin
94-
match mb.mb_id with
95-
| None -> None
96-
| Some id ->
96+
match mb.mb_name with
97+
| { txt = None; _ } -> None
98+
| { txt = Some txt; loc } ->
9799
let deprecated = Type_utils.is_deprecated mb.mb_attributes in
98-
Some (mk ~children ~location ~deprecated `Module None id)
100+
Some (mk ~children ~location ~deprecated `Module None { txt; loc })
99101
end
100102
| Module_type_declaration mtd ->
101103
let children = get_mod_children node in
102104
let deprecated = Type_utils.is_deprecated mtd.mtd_attributes in
103-
Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_id)
105+
Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_name)
104106
| Type_declaration td ->
105107
let children =
106108
List.concat_map (Lazy.force node.t_children) ~f:(fun child ->
@@ -110,15 +112,15 @@ let rec summarize node =
110112
match x.t_node with
111113
| Constructor_declaration c ->
112114
let deprecated = Type_utils.is_deprecated c.cd_attributes in
113-
mk `Constructor None c.cd_id ~deprecated ~location:c.cd_loc
115+
mk `Constructor None c.cd_name ~deprecated ~location:c.cd_loc
114116
| Label_declaration ld ->
115117
let deprecated = Type_utils.is_deprecated ld.ld_attributes in
116-
mk `Label None ld.ld_id ~deprecated ~location:ld.ld_loc
118+
mk `Label None ld.ld_name ~deprecated ~location:ld.ld_loc
117119
| _ -> assert false (* ! *))
118120
| _ -> [])
119121
in
120122
let deprecated = Type_utils.is_deprecated td.typ_attributes in
121-
Some (mk ~children ~location ~deprecated `Type None td.typ_id)
123+
Some (mk ~children ~location ~deprecated `Type None td.typ_name)
122124
| Type_extension te ->
123125
let name = Path.name te.tyext_path in
124126
let children =
@@ -132,25 +134,25 @@ let rec summarize node =
132134
outline_kind = `Type;
133135
outline_type = None;
134136
location;
137+
selection = te.tyext_txt.loc;
135138
children;
136139
deprecated
137140
}
138141
| Extension_constructor ec ->
139142
let deprecated = Type_utils.is_deprecated ec.ext_attributes in
140-
Some (mk ~location `Exn None ec.ext_id ~deprecated)
143+
Some (mk ~location `Exn None ec.ext_name ~deprecated)
141144
| Class_declaration cd ->
142145
let children =
143146
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
144147
in
145148
let deprecated = Type_utils.is_deprecated cd.ci_attributes in
146-
Some (mk ~children ~location `Class None cd.ci_id_class_type ~deprecated)
149+
Some (mk ~children ~location `Class None cd.ci_id_name ~deprecated)
147150
| Class_type_declaration ctd ->
148151
let children =
149152
List.concat_map (Lazy.force node.t_children) ~f:get_class_elements
150153
in
151154
let deprecated = Type_utils.is_deprecated ctd.ci_attributes in
152-
Some
153-
(mk ~children ~location `ClassType None ctd.ci_id_class_type ~deprecated)
155+
Some (mk ~children ~location `ClassType None ctd.ci_id_name ~deprecated)
154156
| _ -> None
155157

156158
and get_val_elements node =
@@ -175,6 +177,7 @@ and get_class_elements node =
175177
outline_kind;
176178
outline_type = None;
177179
location = str_loc.Location.loc;
180+
selection = str_loc.loc;
178181
children;
179182
deprecated
180183
})
@@ -192,6 +195,7 @@ and get_class_elements node =
192195
outline_kind;
193196
outline_type = None;
194197
location = field.ctf_loc;
198+
selection = field.ctf_loc;
195199
(* TODO: could we have more precised location information? *)
196200
children = [];
197201
deprecated

src/commands/query_json.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ let rec json_of_outline outline =
323323
outline_kind;
324324
outline_type;
325325
location;
326+
selection;
326327
children;
327328
deprecated
328329
} =
@@ -334,7 +335,8 @@ let rec json_of_outline outline =
334335
| None -> `Null
335336
| Some typ -> `String typ );
336337
("children", `List (json_of_outline children));
337-
("deprecated", `Bool deprecated)
338+
("deprecated", `Bool deprecated);
339+
("selection", with_location selection [])
338340
]
339341
in
340342
List.map ~f:json_of_item outline

src/frontend/query_protocol.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ and item =
9292
| `Method ];
9393
outline_type : string option;
9494
deprecated : bool;
95-
location : Location_aux.t;
95+
location : Location.t;
96+
selection : Location.t;
9697
children : outline
9798
}
9899

tests/test-dirs/outline-recovery.t

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@
3636
"kind": "Module",
3737
"type": null,
3838
"children": [],
39-
"deprecated": false
39+
"deprecated": false,
40+
"selection": {
41+
"start": {
42+
"line": 4,
43+
"col": 9
44+
},
45+
"end": {
46+
"line": 4,
47+
"col": 10
48+
}
49+
}
4050
},
4151
{
4252
"start": {
@@ -51,7 +61,17 @@
5161
"kind": "Module",
5262
"type": null,
5363
"children": [],
54-
"deprecated": false
64+
"deprecated": false,
65+
"selection": {
66+
"start": {
67+
"line": 3,
68+
"col": 9
69+
},
70+
"end": {
71+
"line": 3,
72+
"col": 10
73+
}
74+
}
5575
},
5676
{
5777
"start": {
@@ -66,10 +86,30 @@
6686
"kind": "Module",
6787
"type": null,
6888
"children": [],
69-
"deprecated": false
89+
"deprecated": false,
90+
"selection": {
91+
"start": {
92+
"line": 2,
93+
"col": 9
94+
},
95+
"end": {
96+
"line": 2,
97+
"col": 10
98+
}
99+
}
70100
}
71101
],
72-
"deprecated": false
102+
"deprecated": false,
103+
"selection": {
104+
"start": {
105+
"line": 1,
106+
"col": 7
107+
},
108+
"end": {
109+
"line": 1,
110+
"col": 11
111+
}
112+
}
73113
}
74114
],
75115
"notifications": []

0 commit comments

Comments
 (0)