Skip to content

Commit ac64e51

Browse files
panglesdjonludlam
authored andcommitted
Source rendering: Anchor counter should increase
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]>
1 parent 0e41ad1 commit ac64e51

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/loader/implementation.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ let of_cmt (source_id : Odoc_model.Paths.Identifier.SourcePage.t)
463463
Analysis.structure (env, uid_to_loc)
464464
(id :> Odoc_model.Paths.Identifier.Signature.t)
465465
[] structure
466+
|> List.rev
467+
(* Information are accumulated in a list. We need to have the
468+
first info first in the list, to assign anchors with increasing
469+
numbers, so that adding some content at the end of a file does
470+
not modify the anchors for existing anchors. *)
466471
in
467472
let uid_to_loc_map = Shape.Uid.Tbl.to_map uid_to_loc in
468473
let uid_to_id : Odoc_model.Paths.Identifier.SourceLocation.t Shape.Uid.Map.t =

test/sources/source.t/a.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let segr = Yoyo.Aa
1313
let x = 2
1414
let y = x + 1
1515
let z a = if x = 1 || true then x + y else a
16+
let z' a = if x = 1 || true then x + y else a
1617

1718
module A = struct end
1819
module B = A

test/sources/source.t/run.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Files containing some values:
1616
let x = 2
1717
let y = x + 1
1818
let z a = if x = 1 || true then x + y else a
19+
let z' a = if x = 1 || true then x + y else a
1920

2021
module A = struct end
2122
module B = A
@@ -128,6 +129,10 @@ Source links generated in the documentation:
128129
<div class="spec value anchored" id="val-z">
129130
<a href="#val-z" class="anchor"></a>
130131
<a href="../root/source/a.ml.html#val-z" class="source_link">Source</a>
132+
--
133+
<div class="spec value anchored" id="val-z'">
134+
<a href="#val-z'" class="anchor"></a>
135+
<a href="../root/source/a.ml.html#val-z'" class="source_link">Source</a>
131136
--
132137
<div class="spec module anchored" id="module-A">
133138
<a href="#module-A" class="anchor"></a>
@@ -264,6 +269,7 @@ Ids generated in the source code:
264269
id="L58"
265270
id="L59"
266271
id="L60"
272+
id="L61"
267273
id="type-t"
268274
id="type-truc"
269275
id="val-xazaz"
@@ -274,6 +280,8 @@ Ids generated in the source code:
274280
id="val-y"
275281
id="val-z"
276282
id="local_a_2"
283+
id="val-z'"
284+
id="local_a_3"
277285
id="module-A"
278286
id="module-B"
279287
id="module-type-T"

0 commit comments

Comments
 (0)