Skip to content

Commit

Permalink
Source rendering: Anchor counter should increase
Browse files Browse the repository at this point in the history
So that adding some content at the end of the file does not modify
anchors that are above.

Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd committed Sep 15, 2023
1 parent 652931c commit ae5bc8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/loader/implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ let of_cmt (source_id : Odoc_model.Paths.Identifier.SourcePage.t)
Analysis.structure (env, uid_to_loc)
(id :> Odoc_model.Paths.Identifier.Signature.t)
[] structure
|> List.rev
(* Information are accumulated in a list. We need to have the
first info first in the list, to assign anchors with increasing
numbers, so that adding some content at the end of a file does
not modify the anchors for existing anchors. *)
in
let uid_to_loc_map = Shape.Uid.Tbl.to_map uid_to_loc in
let uid_to_id : Odoc_model.Paths.Identifier.SourceLocation.t Shape.Uid.Map.t =
Expand Down
1 change: 1 addition & 0 deletions test/sources/source.t/a.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let segr = Yoyo.Aa
let x = 2
let y = x + 1
let z a = if x = 1 || true then x + y else a
let z' a = if x = 1 || true then x + y else a

module A = struct end
module B = A
Expand Down
8 changes: 8 additions & 0 deletions test/sources/source.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Files containing some values:
let x = 2
let y = x + 1
let z a = if x = 1 || true then x + y else a
let z' a = if x = 1 || true then x + y else a

module A = struct end
module B = A
Expand Down Expand Up @@ -128,6 +129,10 @@ Source links generated in the documentation:
<div class="spec value anchored" id="val-z">
<a href="#val-z" class="anchor"></a>
<a href="../root/source/a.ml.html#val-z" class="source_link">Source</a>
--
<div class="spec value anchored" id="val-z'">
<a href="#val-z'" class="anchor"></a>
<a href="../root/source/a.ml.html#val-z'" class="source_link">Source</a>
--
<div class="spec module anchored" id="module-A">
<a href="#module-A" class="anchor"></a>
Expand Down Expand Up @@ -264,6 +269,7 @@ Ids generated in the source code:
id="L58"
id="L59"
id="L60"
id="L61"
id="type-t"
id="type-truc"
id="val-xazaz"
Expand All @@ -274,6 +280,8 @@ Ids generated in the source code:
id="val-y"
id="val-z"
id="local_a_2"
id="val-z'"
id="local_a_3"
id="module-A"
id="module-B"
id="module-type-T"
Expand Down

0 comments on commit ae5bc8b

Please sign in to comment.