Skip to content

Commit b1edfd9

Browse files
panglesdjonludlam
authored andcommitted
Add semantic anchors for extension constructors
They get an entry in the `uid_to_loc` table, so we need to add them to the `loc_to_ident` table as well for semantic anchor to work. Signed-off-by: Paul-Elliot <[email protected]>
1 parent 0149366 commit b1edfd9

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

src/loader/ident_env.cppo.ml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ type item = [
6363
| `Class of Ident.t * Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
6464
| `ClassType of Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
6565
| `Exception of Ident.t * Warnings.loc option
66-
(* Exceptions are never hidden, but we need to add it to the [loc_to_ident]
67-
table. *)
66+
(* Exceptions needs to be added to the [loc_to_ident] table. *)
67+
| `Extension of Ident.t * Warnings.loc option
68+
(* Extension constructor also need to be added to the [loc_to_ident] table,
69+
since they get an entry in the [uid_to_loc] table. *)
6870
]
6971

7072
type items =
@@ -315,6 +317,14 @@ let rec extract_structure_tree_items : bool -> Typedtree.structure_item list ->
315317
`Exception (tyexn_constructor.ext_id, Some tyexn_constructor.ext_loc) :: extract_structure_tree_items hide_item rest
316318
#endif
317319

320+
#if OCAML_VERSION < (4,14,0)
321+
| { str_desc = Tstr_typext _; _} :: rest -> extract_structure_tree_items hide_item rest
322+
#else
323+
| { str_desc = Tstr_typext { tyext_constructors; _ }; _} :: rest ->
324+
let x = List.map (fun { ext_id; ext_loc; _ } -> `Extension (ext_id, Some ext_loc)) tyext_constructors in
325+
x @ extract_structure_tree_items hide_item rest
326+
#endif
327+
318328
#if OCAML_VERSION < (4,3,0)
319329
| { str_desc = Tstr_value (_, vbs ); _} :: rest ->
320330
#else
@@ -387,8 +397,7 @@ let rec extract_structure_tree_items : bool -> Typedtree.structure_item list ->
387397
#endif
388398
| { str_desc = Tstr_primitive {val_id; _}; str_loc; _ } :: rest ->
389399
[`Value (val_id, false, Some str_loc)] @ extract_structure_tree_items hide_item rest
390-
| { str_desc = Tstr_eval _; _} :: rest
391-
| { str_desc = Tstr_typext _; _} :: rest -> extract_structure_tree_items hide_item rest
400+
| { str_desc = Tstr_eval _; _} :: rest -> extract_structure_tree_items hide_item rest
392401
| [] -> []
393402

394403

@@ -400,6 +409,7 @@ let flatten_extracted : items list -> item list = fun items ->
400409
| `Value _
401410
| `Class _
402411
| `Exception _
412+
| `Extension _
403413
| `ClassType _ as x -> [x]
404414
| `Include xs -> xs) items |> List.flatten
405415

@@ -443,6 +453,12 @@ let env_of_items : Id.Signature.t -> item list -> t -> t = fun parent items env
443453
(match loc with | Some l -> LocHashtbl.add env.loc_to_ident l (identifier :> Id.any) | _ -> ());
444454
inner rest env
445455

456+
| `Extension (t, loc) :: rest ->
457+
let name = Ident.name t in
458+
let identifier = Mk.extension(parent, ExtensionName.make_std name) in
459+
(match loc with | Some l -> LocHashtbl.add env.loc_to_ident l (identifier :> Id.any) | _ -> ());
460+
inner rest env
461+
446462
| `Value (t, is_hidden_item, loc) :: rest ->
447463
let name = Ident.name t in
448464
let is_hidden = is_hidden_item || value_name_exists name rest in

src/loader/ident_env.cppo.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type item =
2626
| `Class of
2727
Ident.t * Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
2828
| `Exception of Ident.t * Warnings.loc option
29+
| `Extension of Ident.t * Warnings.loc option
2930
| `ClassType of
3031
Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option ]
3132

test/sources/lookup_def.t/run.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ Show the locations:
2222
[{"`Value":[{"`Root":["None","A"]},"a"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"value-a"]}}]
2323
[{"`Exception":[{"`Root":["None","A"]},"Exn"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"exception-Exn"]}}]
2424
[{"`Type":[{"`Root":["None","A"]},"ext"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"type-ext"]}}]
25-
[{"`Extension":[{"`Root":["None","A"]},"Ext"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"def_11"]}}]
25+
[{"`Extension":[{"`Root":["None","A"]},"Ext"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"extension-Ext"]}}]
2626
[{"`Class":[{"`Root":["None","A"]},"cls"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"class-cls"]}}]
2727
[{"`ClassType":[{"`Root":["None","A"]},"clst"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"class_type-clst"]}}]

test/sources/source.t/a.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
type t = string
22

3+
type truc = A | B
4+
35
let x = 2
46
let y = x + 1
57
let z a = if x = 1 || true then x + y else 0
@@ -11,7 +13,7 @@ module type T = sig end
1113
module type U = T
1214

1315
type ext = ..
14-
type ext += Foo
16+
type ext += Foo | Bar
1517

1618
exception Exn
1719

test/sources/source.t/run.t

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Files containing some values:
33
$ cat a.ml
44
type t = string
55

6+
type truc = A | B
7+
68
let x = 2
79
let y = x + 1
810
let z a = if x = 1 || true then x + y else 0
@@ -14,7 +16,7 @@ Files containing some values:
1416
module type U = T
1517

1618
type ext = ..
17-
type ext += Foo
19+
type ext += Foo | Bar
1820

1921
exception Exn
2022

@@ -67,6 +69,10 @@ Source links generated in the documentation:
6769
<div class="spec type anchored" id="type-t">
6870
<a href="#type-t" class="anchor"></a>
6971
<a href="../root/source/a.ml.html#type-t" class="source_link">Source</a>
72+
--
73+
<div class="spec type anchored" id="type-truc">
74+
<a href="#type-truc" class="anchor"></a>
75+
<a href="../root/source/a.ml.html#type-truc" class="source_link">Source
7076
--
7177
<div class="spec value anchored" id="val-y">
7278
<a href="#val-y" class="anchor"></a>
@@ -98,7 +104,7 @@ Source links generated in the documentation:
98104
--
99105
<div class="spec type extension anchored" id="extension-decl-Foo">
100106
<a href="#extension-decl-Foo" class="anchor"></a>
101-
<a href="../root/source/a.ml.html#def_10" class="source_link">Source</a>
107+
<a href="../root/source/a.ml.html#extension-Foo" class="source_link">
102108
--
103109
<div class="spec exception anchored" id="exception-Exn">
104110
<a href="#exception-Exn" class="anchor"></a>
@@ -146,23 +152,23 @@ Ids generated in the source code:
146152
id="L21"
147153
id="L22"
148154
id="L23"
155+
id="L24"
156+
id="L25"
149157
id="type-t"
158+
id="type-truc"
150159
id="value-{x}2"
151160
id="value-y"
152161
id="value-z"
153-
id="local_a_47"
162+
id="local_a_66"
154163
id="module-A"
155164
id="module-B"
156165
id="module_type-T"
157166
id="module_type-U"
158167
id="type-ext"
159-
id="def_10"
168+
id="extension-Foo"
169+
id="extension-Bar"
160170
id="exception-Exn"
161171
id="class-cls"
162172
id="class-cls'"
163173
id="class_type-ct"
164174
id="value-x"
165-
166-
$ firefox html/root/source/a.ml.html
167-
Gtk-Message: 12:16:26.688: Failed to load module "xapp-gtk3-module"
168-
Gtk-Message: 12:16:26.689: Not loading module "atk-bridge": The functionality is provided by GTK natively. Please try to not load it.

0 commit comments

Comments
 (0)