From 652931cd98767ed1b6877ffba268f67f7fb519e2 Mon Sep 17 00:00:00 2001 From: Paul-Elliot Date: Fri, 15 Sep 2023 11:24:53 +0200 Subject: [PATCH] Source rendering: anchors do not depend on locations Signed-off-by: Paul-Elliot --- src/loader/implementation.ml | 13 +++++++++---- test/sources/source.t/a.ml | 2 +- test/sources/source.t/run.t | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/loader/implementation.ml b/src/loader/implementation.ml index edbed059b9..4660b8d7ee 100644 --- a/src/loader/implementation.ml +++ b/src/loader/implementation.ml @@ -9,6 +9,12 @@ type annotations = | LocalValue of Ident.t | DefJmp of Shape.Uid.t +let counter = + let c = ref 0 in + fun () -> + incr c; + !c + module Analysis = struct open Typedtree open Odoc_model.Paths @@ -331,10 +337,10 @@ let postprocess_poses source_id poses uid_to_id uid_to_loc = let local_def_anchors = List.filter_map (function - | LocalDefinition id, (start, _) -> + | LocalDefinition id, _ -> let name = Odoc_model.Names.LocalName.make_std - (Printf.sprintf "local_%s_%d" (Ident.name id) start) + (Printf.sprintf "local_%s_%d" (Ident.name id) (counter ())) in let identifier = Odoc_model.Paths.Identifier.Mk.source_location_int @@ -476,8 +482,7 @@ let of_cmt (source_id : Odoc_model.Paths.Identifier.SourcePage.t) | Item _ -> let name = Odoc_model.Names.DefName.make_std - (Printf.sprintf "def_%d_%d" loc.loc_start.pos_cnum - loc.loc_end.pos_cnum) + (Printf.sprintf "def_%d" (counter ())) in Some name | _ -> None) diff --git a/test/sources/source.t/a.ml b/test/sources/source.t/a.ml index 0229992bce..8e755f3bee 100644 --- a/test/sources/source.t/a.ml +++ b/test/sources/source.t/a.ml @@ -12,7 +12,7 @@ let segr = Yoyo.Aa let x = 2 let y = x + 1 -let z a = if x = 1 || true then x + y else 0 +let z a = if x = 1 || true then x + y else a module A = struct end module B = A diff --git a/test/sources/source.t/run.t b/test/sources/source.t/run.t index 4613ede1e1..1a5f6f21b9 100644 --- a/test/sources/source.t/run.t +++ b/test/sources/source.t/run.t @@ -15,7 +15,7 @@ Files containing some values: let x = 2 let y = x + 1 - let z a = if x = 1 || true then x + y else 0 + let z a = if x = 1 || true then x + y else a module A = struct end module B = A @@ -273,7 +273,7 @@ Ids generated in the source code: id="val-{x}2" id="val-y" id="val-z" - id="local_a_148" + id="local_a_2" id="module-A" id="module-B" id="module-type-T" @@ -295,7 +295,7 @@ Ids generated in the source code: id="module-F.argument-1-M.module-A" id="module-F.module-B" id="module-FM" - id="def_591_612" + id="def_1" id="module-FF" id="module-FF2" id="module-FF2.argument-1-A.module-E"