Skip to content

Commit 8ff91d2

Browse files
authored
Merge pull request #888 from sim642/raise-ref
Treat raise tag value as reference
2 parents 5a741da + 9700c17 commit 8ff91d2

File tree

16 files changed

+105
-38
lines changed

16 files changed

+105
-38
lines changed

src/document/comment.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,11 @@ let tag : Comment.tag -> Description.one =
274274
let sp = inline (Text " ") in
275275
let item ?value ~tag definition =
276276
let tag_name = inline ~attr:[ "at-tag" ] (Text tag) in
277-
let tag_value =
278-
match value with
279-
| None -> []
280-
| Some t -> [ sp; inline ~attr:[ "value" ] t ]
281-
in
277+
let tag_value = match value with None -> [] | Some t -> sp :: t in
282278
let key = tag_name :: tag_value in
283279
{ Description.attr = [ tag ]; key; definition }
284280
in
281+
let mk_value desc = [ inline ~attr:[ "value" ] desc ] in
285282
let text_def s = [ block (Block.Inline [ inline @@ Text s ]) ] in
286283
let content_to_inline ?(prefix = []) content =
287284
match content with
@@ -293,23 +290,23 @@ let tag : Comment.tag -> Description.one =
293290
| `Deprecated content ->
294291
item ~tag:"deprecated" (nestable_block_element_list content)
295292
| `Param (name, content) ->
296-
let value = Inline.Text name in
293+
let value = mk_value (Inline.Text name) in
297294
item ~tag:"parameter" ~value (nestable_block_element_list content)
298-
| `Raise (name, content) ->
299-
let value = Inline.Text name in
295+
| `Raise (kind, content) ->
296+
let value = inline_element (kind :> Comment.inline_element) in
300297
item ~tag:"raises" ~value (nestable_block_element_list content)
301298
| `Return content -> item ~tag:"returns" (nestable_block_element_list content)
302299
| `See (kind, target, content) ->
303300
let value =
304301
match kind with
305-
| `Url -> Inline.Link (target, [ inline @@ Text target ])
306-
| `File -> Inline.Source (source_of_code target)
307-
| `Document -> Inline.Text target
302+
| `Url -> mk_value (Inline.Link (target, [ inline @@ Text target ]))
303+
| `File -> mk_value (Inline.Source (source_of_code target))
304+
| `Document -> mk_value (Inline.Text target)
308305
in
309306
item ~tag:"see" ~value (nestable_block_element_list content)
310307
| `Since s -> item ~tag:"since" (text_def s)
311308
| `Before (version, content) ->
312-
let value = Inline.Text version in
309+
let value = mk_value (Inline.Text version) in
313310
item ~tag:"before" ~value (nestable_block_element_list content)
314311
| `Version s -> item ~tag:"version" (text_def s)
315312
| `Alert ("deprecated", content) ->

src/html_support_files/odoc.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ tt, code, pre {
408408
padding: 0 0.3ex;
409409
}
410410

411-
p a > code {
411+
p a > code, li a > code {
412412
color: var(--link-color);
413413
}
414414

src/html_support_files/odoc_html_support_files.ml

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

src/model/comment.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ type non_link_inline_element =
2424
cross-referencer. *)
2525
type link_content = non_link_inline_element with_location list
2626

27+
type reference_element = [ `Reference of Reference.t * link_content ]
28+
2729
type inline_element =
2830
[ leaf_inline_element
2931
| `Styled of style * inline_element with_location list
30-
| `Reference of Reference.t * link_content
32+
| reference_element
3133
| `Link of string * link_content ]
3234

3335
type paragraph = inline_element with_location list
@@ -53,7 +55,9 @@ type tag =
5355
[ `Author of string
5456
| `Deprecated of nestable_block_element with_location list
5557
| `Param of string * nestable_block_element with_location list
56-
| `Raise of string * nestable_block_element with_location list
58+
| `Raise of
59+
[ `Code_span of string | reference_element ]
60+
* nestable_block_element with_location list
5761
| `Return of nestable_block_element with_location list
5862
| `See of
5963
[ `Url | `File | `Document ]

src/model/semantics.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,17 @@ let tag :
271271
ok (`Deprecated (nestable_block_elements status content))
272272
| `Param (name, content) ->
273273
ok (`Param (name, nestable_block_elements status content))
274-
| `Raise (name, content) ->
275-
ok (`Raise (name, nestable_block_elements status content))
274+
| `Raise (name, content) -> (
275+
match Error.raise_warnings (Reference.parse location name) with
276+
(* TODO: location for just name *)
277+
| Result.Ok target ->
278+
ok
279+
(`Raise
280+
(`Reference (target, []), nestable_block_elements status content))
281+
| Result.Error error ->
282+
Error.raise_warning error;
283+
let placeholder = `Code_span name in
284+
ok (`Raise (placeholder, nestable_block_elements status content)))
276285
| `Return content -> ok (`Return (nestable_block_elements status content))
277286
| `See (kind, target, content) ->
278287
ok (`See (kind, target, nestable_block_elements status content))

src/model_desc/comment_desc.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ and general_tag =
3333
[ `Author of string
3434
| `Deprecated of general_docs
3535
| `Param of string * general_docs
36-
| `Raise of string * general_docs
36+
| `Raise of
37+
[ `Code_span of string
38+
| `Reference of Paths.Reference.t * general_link_content ]
39+
* general_docs
3740
| `Return of general_docs
3841
| `See of [ `Url | `File | `Document ] * string * general_docs
3942
| `Since of string
@@ -124,7 +127,11 @@ and tag : general_tag t =
124127
| `Author x -> C ("`Author", x, string)
125128
| `Deprecated x -> C ("`Deprecated", x, docs)
126129
| `Param (x1, x2) -> C ("`Param", (x1, x2), Pair (string, docs))
127-
| `Raise (x1, x2) -> C ("`Raise", (x1, x2), Pair (string, docs))
130+
| `Raise (x1, x2) ->
131+
C
132+
( "`Raise",
133+
((x1 :> general_inline_element), x2),
134+
Pair (inline_element, docs) )
128135
| `Return x -> C ("`Return", x, docs)
129136
| `See (x1, x2, x3) ->
130137
C ("`See", (x1, x2, x3), Triple (url_kind, string, docs))

src/ocamlary/ocamlary.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ val fun_maybe : ?yes:unit -> unit -> int
226226
val not_found : unit -> unit
227227
(** @raise Not_found That's all it does *)
228228

229+
val kaboom : unit -> unit
230+
(** @raise Kaboom That's all it does *)
231+
229232
val ocaml_org : string
230233
(** @see <http://ocaml.org/> The OCaml Web site *)
231234

src/xref2/link.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,18 @@ and comment_tag env parent ~loc:_ (x : Comment.tag) =
278278
`Deprecated (comment_nestable_block_element_list env parent content)
279279
| `Param (name, content) ->
280280
`Param (name, comment_nestable_block_element_list env parent content)
281-
| `Raise (name, content) ->
282-
`Raise (name, comment_nestable_block_element_list env parent content)
281+
| `Raise ((`Reference (r, reference_content) as orig), content) -> (
282+
match Ref_tools.resolve_reference env r |> Error.raise_warnings with
283+
| Ok x ->
284+
`Raise
285+
( `Reference (`Resolved x, reference_content),
286+
comment_nestable_block_element_list env parent content )
287+
| Error e ->
288+
Errors.report ~what:(`Reference r) ~tools_error:(`Reference e)
289+
`Resolve;
290+
`Raise (orig, comment_nestable_block_element_list env parent content))
291+
| `Raise ((`Code_span _ as orig), content) ->
292+
`Raise (orig, comment_nestable_block_element_list env parent content)
283293
| `Return content ->
284294
`Return (comment_nestable_block_element_list env parent content)
285295
| `See (kind, target, content) ->

test/generators/html/Markup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ <h2 id="math"><a href="#math" class="anchor"></a>Math</h2>
240240
</ul>
241241
<ul class="at-tags">
242242
<li class="raises"><span class="at-tag">raises</span>
243-
<span class="value">Failure</span> <p>always</p>
243+
<code>Failure</code> <p>always</p>
244244
</li>
245245
</ul>
246246
<ul class="at-tags">

test/generators/html/Ocamlary.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,25 @@ <h4 id="basic-type-and-value-stuff-with-advanced-doc-comments">
447447
<div class="spec-doc">
448448
<ul class="at-tags">
449449
<li class="raises"><span class="at-tag">raises</span>
450-
<span class="value">Not_found</span> <p>That's all it does</p>
450+
<code>Not_found</code> <p>That's all it does</p>
451+
</li>
452+
</ul>
453+
</div>
454+
</div>
455+
<div class="odoc-spec">
456+
<div class="spec value anchored" id="val-kaboom">
457+
<a href="#val-kaboom" class="anchor"></a>
458+
<code>
459+
<span><span class="keyword">val</span> kaboom :
460+
<span>unit <span class="arrow">&#45;&gt;</span></span> unit
461+
</span>
462+
</code>
463+
</div>
464+
<div class="spec-doc">
465+
<ul class="at-tags">
466+
<li class="raises"><span class="at-tag">raises</span>
467+
<a href="#exception-Kaboom"><code>Kaboom</code></a>
468+
<p>That's all it does</p>
451469
</li>
452470
</ul>
453471
</div>

0 commit comments

Comments
 (0)