Skip to content

Commit ebf1a3a

Browse files
panglesdjonludlam
authored andcommitted
Render source code: Add jump to implementation for modules
Signed-off-by: Paul-Elliot <[email protected]>
1 parent 5f8e28e commit ebf1a3a

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/xref2/link.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ let rec unit env t =
462462
| Module v ->
463463
Module
464464
(jump_to v
465-
(fun _ -> None)
465+
(Shape_tools.lookup_module_path env)
466466
(module_path ~report_errors:false env))
467467
| ModuleType v ->
468468
ModuleType

src/xref2/shape_tools.cppo.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ let rec shape_of_id env :
5656
let rec shape_of_module_path env : _ -> Shape.t option =
5757
let proj parent kind name =
5858
let item = Shape.Item.make name kind in
59-
match shape_of_module_path env (parent :> Odoc_model.Paths.Path.t) with
59+
match shape_of_module_path env (parent :> Odoc_model.Paths.Path.Module.t) with
6060
| Some shape -> Some (Shape.proj shape item)
6161
| None -> None
6262
in
63-
fun (path : Odoc_model.Paths.Path.t) ->
63+
fun (path : Odoc_model.Paths.Path.Module.t) ->
6464
match path with
6565
| `Resolved _ -> None
6666
| `Root name -> (
@@ -72,11 +72,11 @@ let rec shape_of_module_path env : _ -> Shape.t option =
7272
| _ -> None)
7373
| `Forward _ -> None
7474
| `Dot (parent, name) ->
75-
proj (parent :> Odoc_model.Paths.Path.t) Kind.Module name
75+
proj (parent :> Odoc_model.Paths.Path.Module.t) Kind.Module name
7676
| `Apply (parent, arg) ->
77-
shape_of_module_path env (parent :> Odoc_model.Paths.Path.t)
77+
shape_of_module_path env (parent :> Odoc_model.Paths.Path.Module.t)
7878
>>= fun parent ->
79-
shape_of_module_path env (arg :> Odoc_model.Paths.Path.t) >>= fun arg ->
79+
shape_of_module_path env (arg :> Odoc_model.Paths.Path.Module.t) >>= fun arg ->
8080
Some (Shape.app parent ~arg)
8181
| `Identifier (id, _) ->
8282
shape_of_id env (id :> Odoc_model.Paths.Identifier.NonSrc.t)
@@ -85,14 +85,14 @@ let shape_of_value_path env :
8585
Odoc_model.Paths.Path.Value.t -> Shape.t option =
8686
let proj parent kind name =
8787
let item = Shape.Item.make name kind in
88-
match shape_of_module_path env (parent :> Odoc_model.Paths.Path.t) with
88+
match shape_of_module_path env parent with
8989
| Some shape -> Some (Shape.proj shape item)
9090
| None -> None
9191
in
9292
fun (path : Odoc_model.Paths.Path.Value.t) ->
9393
match path with
9494
| `Resolved _ -> None
95-
| `Dot (parent, name) -> proj (parent :> Odoc_model.Paths.Path.t) Kind.Value name
95+
| `Dot (parent, name) -> proj parent Kind.Value name
9696
| `Identifier (id, _) -> shape_of_id env (id :> Odoc_model.Paths.Identifier.NonSrc.t)
9797

9898

@@ -160,6 +160,16 @@ let lookup_value_path :
160160
| None -> None
161161
| Some query -> lookup_shape env query
162162

163+
164+
let lookup_module_path :
165+
Env.t ->
166+
Path.Module.t ->
167+
Identifier.SourceLocation.t option
168+
= fun env path ->
169+
match shape_of_module_path env path with
170+
| None -> None
171+
| Some query -> lookup_shape env query
172+
163173
#else
164174

165175
type t = unit

src/xref2/shape_tools.cppo.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ val lookup_value_path :
1818
Env.t ->
1919
Path.Value.t ->
2020
Identifier.SourceLocation.t option
21+
22+
val lookup_module_path :
23+
Env.t ->
24+
Path.Module.t ->
25+
Identifier.SourceLocation.t option

test/sources/source.t/run.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ Ids generated in the source code:
307307
id="module-F.argument-1-M.module-A"
308308
id="module-F.module-B"
309309
id="module-FM"
310-
id="def_3"
310+
id="local_A_3"
311311
id="module-FF"
312312
id="module-FF2"
313313
id="module-FF2.argument-1-A.module-E"

0 commit comments

Comments
 (0)