Skip to content

Commit

Permalink
Generate source links for extension constructors
Browse files Browse the repository at this point in the history
For consistency with regular variant, only one source link is generated
for a group of extension constructor, pointing to the first one.

Source link for exception was simply forgotten.

Co-authored-by: Paul-Elliot <peada@free.fr>
  • Loading branch information
2 people authored and jonludlam committed Mar 14, 2023
1 parent 016f5cb commit 5146b23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,14 @@ module Make (Syntax : SYNTAX) = struct
let attr = [ "type"; "extension" ] in
let anchor = Some (Url.Anchor.extension_decl t) in
let doc = Comment.to_ir t.doc in
Item.Declaration { attr; anchor; doc; content; source_anchor = None }
let source_anchor =
(* Take the anchor from the first constructor only for consistency with
regular variants. *)
match t.constructors with
| hd :: _ -> source_anchor hd.locs
| [] -> None
in
Item.Declaration { attr; anchor; doc; content; source_anchor }

let exn (t : Odoc_model.Lang.Exception.t) =
let cstr = constructor (t.id :> Paths.Identifier.t) t.args t.res in
Expand All @@ -641,7 +648,8 @@ module Make (Syntax : SYNTAX) = struct
let attr = [ "exception" ] in
let anchor = path_to_id t.id in
let doc = Comment.to_ir t.doc in
Item.Declaration { attr; anchor; doc; content; source_anchor = None }
let source_anchor = source_anchor t.locs in
Item.Declaration { attr; anchor; doc; content; source_anchor }

let polymorphic_variant ~type_ident
(t : Odoc_model.Lang.TypeExpr.Polymorphic_variant.t) =
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 @@ -70,6 +70,14 @@ Source links generated in the documentation:
<div class="spec type anchored" id="type-ext">
<a href="#type-ext" class="anchor"></a>
<a href="A.ml.html#def-A9" class="source_link">Source</a>
--
<div class="spec type extension anchored" id="extension-decl-Foo">
<a href="#extension-decl-Foo" class="anchor"></a>
<a href="A.ml.html#def-A10" class="source_link">Source</a>
--
<div class="spec exception anchored" id="exception-Exn">
<a href="#exception-Exn" class="anchor"></a>
<a href="A.ml.html#def-A11" class="source_link">Source</a>
--
<div class="spec class anchored" id="class-cls">
<a href="#class-cls" class="anchor"></a>
Expand Down

0 comments on commit 5146b23

Please sign in to comment.