Skip to content

Commit 0e41ad1

Browse files
panglesdjonludlam
authored andcommitted
Source rendering: anchors do not depend on locations
Signed-off-by: Paul-Elliot <[email protected]>
1 parent 481dd46 commit 0e41ad1

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/loader/implementation.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ type annotations =
99
| LocalValue of Ident.t
1010
| DefJmp of Shape.Uid.t
1111

12+
let counter =
13+
let c = ref 0 in
14+
fun () ->
15+
incr c;
16+
!c
17+
1218
module Analysis = struct
1319
open Typedtree
1420
open Odoc_model.Paths
@@ -331,10 +337,10 @@ let postprocess_poses source_id poses uid_to_id uid_to_loc =
331337
let local_def_anchors =
332338
List.filter_map
333339
(function
334-
| LocalDefinition id, (start, _) ->
340+
| LocalDefinition id, _ ->
335341
let name =
336342
Odoc_model.Names.LocalName.make_std
337-
(Printf.sprintf "local_%s_%d" (Ident.name id) start)
343+
(Printf.sprintf "local_%s_%d" (Ident.name id) (counter ()))
338344
in
339345
let identifier =
340346
Odoc_model.Paths.Identifier.Mk.source_location_int
@@ -476,8 +482,7 @@ let of_cmt (source_id : Odoc_model.Paths.Identifier.SourcePage.t)
476482
| Item _ ->
477483
let name =
478484
Odoc_model.Names.DefName.make_std
479-
(Printf.sprintf "def_%d_%d" loc.loc_start.pos_cnum
480-
loc.loc_end.pos_cnum)
485+
(Printf.sprintf "def_%d" (counter ()))
481486
in
482487
Some name
483488
| _ -> None)

test/sources/source.t/a.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let segr = Yoyo.Aa
1212

1313
let x = 2
1414
let y = x + 1
15-
let z a = if x = 1 || true then x + y else 0
15+
let z a = if x = 1 || true then x + y else a
1616

1717
module A = struct end
1818
module B = A

test/sources/source.t/run.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Files containing some values:
1515

1616
let x = 2
1717
let y = x + 1
18-
let z a = if x = 1 || true then x + y else 0
18+
let z a = if x = 1 || true then x + y else a
1919

2020
module A = struct end
2121
module B = A
@@ -273,7 +273,7 @@ Ids generated in the source code:
273273
id="val-{x}2"
274274
id="val-y"
275275
id="val-z"
276-
id="local_a_148"
276+
id="local_a_2"
277277
id="module-A"
278278
id="module-B"
279279
id="module-type-T"
@@ -295,7 +295,7 @@ Ids generated in the source code:
295295
id="module-F.argument-1-M.module-A"
296296
id="module-F.module-B"
297297
id="module-FM"
298-
id="def_591_612"
298+
id="def_1"
299299
id="module-FF"
300300
id="module-FF2"
301301
id="module-FF2.argument-1-A.module-E"

0 commit comments

Comments
 (0)