Skip to content

Commit 5f8e28e

Browse files
panglesdjonludlam
authored andcommitted
Occurrence: collect local module definitions
Signed-off-by: Paul-Elliot <[email protected]>
1 parent c8e806e commit 5f8e28e

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

src/loader/typedtree_traverse.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ module Analysis = struct
5656
()
5757
| _ -> ()
5858

59-
(* Add module_binding equivalent of pat *)
60-
59+
let module_binding env poses = function
60+
| { Typedtree.mb_id = Some id; mb_loc; _ } when not mb_loc.loc_ghost -> (
61+
match Ident_env.identifier_of_loc env mb_loc with
62+
| None -> poses := (LocalDefinition id, mb_loc) :: !poses
63+
| Some _ -> ())
64+
| _ -> ()
6165

6266
let module_expr poses mod_expr =
6367
match mod_expr with
@@ -114,6 +118,10 @@ let of_cmt env structure =
114118
Analysis.class_type poses cl_type;
115119
Tast_iterator.default_iterator.class_type iterator cl_type
116120
in
121+
let module_binding iterator mb =
122+
Analysis.module_binding env poses mb;
123+
Tast_iterator.default_iterator.module_binding iterator mb
124+
in
117125
let iterator =
118126
{
119127
Tast_iterator.default_iterator with
@@ -123,6 +131,7 @@ let of_cmt env structure =
123131
typ;
124132
module_type;
125133
class_type;
134+
module_binding;
126135
}
127136
in
128137
iterator.structure iterator structure;

src/odoc/occurrences.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ end = struct
7777
| `Value (parent, _) -> do_ parent
7878
| `ClassType (parent, _) -> do_ parent
7979
| `Root _ -> incr tbl id
80-
| `SourcePage _ | `Page _ | `LeafPage _ | `SourceLocation _
80+
| `SourcePage _ | `Page _ | `LeafPage _ | `SourceLocation _
8181
| `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _
8282
| `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ ->
8383
assert false

src/xref2/link.ml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,20 @@ let constructor_path :
185185
(* else *)
186186
if not (should_resolve_constructor p) then p
187187
else
188-
let cp = Component.Of_Lang.(constructor_path (empty ()) p) in
189-
match cp with
190-
| `Resolved p ->
191-
let result = Tools.reresolve_constructor env p in
192-
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
193-
| _ -> (
194-
match Tools.resolve_constructor_path env cp with
195-
| Ok p' ->
196-
let result = Tools.reresolve_constructor env p' in
197-
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
198-
| Error e ->
199-
if report_errors then
200-
Errors.report ~what:(`Constructor_path cp) ~tools_error:e `Lookup;
201-
p)
188+
let cp = Component.Of_Lang.(constructor_path (empty ()) p) in
189+
match cp with
190+
| `Resolved p ->
191+
let result = Tools.reresolve_constructor env p in
192+
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
193+
| _ -> (
194+
match Tools.resolve_constructor_path env cp with
195+
| Ok p' ->
196+
let result = Tools.reresolve_constructor env p' in
197+
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
198+
| Error e ->
199+
if report_errors then
200+
Errors.report ~what:(`Constructor_path cp) ~tools_error:e `Lookup;
201+
p)
202202

203203
let class_type_path :
204204
?report_errors:bool ->
@@ -427,6 +427,11 @@ let rec unit env t =
427427
| Pack _ as p -> p
428428
in
429429
let source_info =
430+
let env =
431+
match t.content with
432+
| Module sg -> Env.open_signature sg env |> Env.add_docs sg.doc
433+
| Pack _ -> env
434+
in
430435
let open Source_info in
431436
match t.source_info with
432437
| Some inf ->
@@ -455,14 +460,25 @@ let rec unit env t =
455460
(Shape_tools.lookup_value_path env)
456461
(value_path ~report_errors:false env))
457462
| Module v ->
458-
Module (jump_to v (fun _ -> None) (module_path ~report_errors:false env))
463+
Module
464+
(jump_to v
465+
(fun _ -> None)
466+
(module_path ~report_errors:false env))
459467
| ModuleType v ->
460468
ModuleType
461-
(jump_to v (fun _ -> None) (module_type_path ~report_errors:false env))
462-
| Type v -> Type (jump_to v (fun _ -> None) (type_path ~report_errors:false env))
469+
(jump_to v
470+
(fun _ -> None)
471+
(module_type_path ~report_errors:false env))
472+
| Type v ->
473+
Type
474+
(jump_to v
475+
(fun _ -> None)
476+
(type_path ~report_errors:false env))
463477
| Constructor v ->
464478
Constructor
465-
(jump_to v (fun _ -> None) (constructor_path ~report_errors:false env))
479+
(jump_to v
480+
(fun _ -> None)
481+
(constructor_path ~report_errors:false env))
466482
| i -> i
467483
in
468484
(info, pos))

0 commit comments

Comments
 (0)