Skip to content

Commit 8c6e322

Browse files
committed
stop rendering dead links
Signed-off-by: lubegasimon <lubegasimon73@gmail.com>
1 parent 2f687bc commit 8c6e322

File tree

17 files changed

+527
-218
lines changed

17 files changed

+527
-218
lines changed

src/compat/odoc_compat.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(**
2-
Compatibility module reexporting ~equivalent functions based on the current
3-
OCaml version
4-
*)
2+
Compatibility module reexporting ~equivalent functions based on the current
3+
OCaml version
4+
*)
55
module String =
66
struct
77
include String

src/document/generator.ml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,27 @@ module Make (Syntax : SYNTAX) = struct
459459
O.documentedSrc (cstr ++ O.txt " " ++ O.keyword "of" ++ O.txt " ")
460460
@ record fields
461461

462+
let rec read_typ_exp typ_expr =
463+
let open Lang.TypeExpr in
464+
let open Paths.Path in
465+
match typ_expr with
466+
| Constr (p, ts) ->
467+
is_hidden (p :> Paths.Path.t)
468+
|| List.exists (fun t -> read_typ_exp t) ts
469+
| Poly (_, t) | Alias (t, _) -> read_typ_exp t
470+
| Arrow (_, t, t2) -> read_typ_exp t || read_typ_exp t2
471+
| Tuple ts | Class (_, ts) -> List.exists (fun t -> read_typ_exp t) ts
472+
| _ -> false
473+
474+
let internal_cstr_arg t =
475+
let open Lang.TypeDecl.Constructor in
476+
let open Lang.TypeDecl.Field in
477+
match t.args with
478+
| Tuple type_exprs ->
479+
List.exists (fun type_expr -> read_typ_exp type_expr) type_exprs
480+
| Record fields ->
481+
List.exists (fun field -> read_typ_exp field.type_) fields
482+
462483
let variant cstrs : DocumentedSrc.t =
463484
let constructor id args res =
464485
match Url.from_identifier ~stop_before:true id with
@@ -476,6 +497,7 @@ module Make (Syntax : SYNTAX) = struct
476497
| _ :: _ ->
477498
let rows =
478499
cstrs
500+
|> List.filter (fun cstr -> not (internal_cstr_arg cstr))
479501
|> List.map (fun cstr ->
480502
let open Odoc_model.Lang.TypeDecl.Constructor in
481503
let url, attrs, code =
@@ -693,13 +715,15 @@ module Make (Syntax : SYNTAX) = struct
693715
| Variant cstrs -> variant cstrs
694716
| Record fields -> record fields
695717
in
696-
O.documentedSrc
697-
( O.txt " = "
698-
++
699-
if need_private then
700-
O.keyword Syntax.Type.private_keyword ++ O.txt " "
701-
else O.noop )
702-
@ content
718+
if List.length content > 0 then
719+
O.documentedSrc
720+
( O.txt " = "
721+
++
722+
if need_private then
723+
O.keyword Syntax.Type.private_keyword ++ O.txt " "
724+
else O.noop )
725+
@ content
726+
else []
703727
in
704728
let tconstr =
705729
match t.equation.params with

src/loader/cmi.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ open Odoc_model.Paths
2323
open Odoc_model.Lang
2424
open Odoc_model.Names
2525

26-
module Env = Odoc_model.Ident_env
26+
module Env = Ident_env
2727
module Paths = Odoc_model.Paths
28-
module Ident_env = Odoc_model.Ident_env
2928

3029
let opt_map f = function
3130
| None -> None

src/loader/cmi.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818

1919
module Paths = Odoc_model.Paths
20-
module Ident_env = Odoc_model.Ident_env
21-
2220

2321

2422
val read_interface: Odoc_model.Paths.Identifier.ContainerPage.t -> string -> Odoc_model.Compat.signature ->

src/loader/cmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module OCamlPath = Path
2323
open Odoc_model.Paths
2424
open Odoc_model.Lang
2525

26-
module Env = Odoc_model.Ident_env
26+
module Env = Ident_env
2727

2828

2929
let read_core_type env ctyp =

src/loader/cmti.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ open Odoc_model.Paths
2323
open Odoc_model.Lang
2424
open Odoc_model.Names
2525

26-
module Env = Odoc_model.Ident_env
26+
module Env = Ident_env
2727
module Paths = Odoc_model.Paths
28-
module Ident_env = Odoc_model.Ident_env
2928

3029
let read_module_expr : (Ident_env.t -> Identifier.Signature.t -> Identifier.LabelParent.t -> Typedtree.module_expr -> ModuleType.expr) ref = ref (fun _ _ _ _ -> failwith "unset")
3130

src/loader/cmti.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*)
1616

1717
module Paths = Odoc_model.Paths
18-
module Ident_env = Odoc_model.Ident_env
1918

2019
val read_module_expr : (Ident_env.t -> Paths.Identifier.Signature.t -> Paths.Identifier.LabelParent.t -> Typedtree.module_expr -> Odoc_model.Lang.ModuleType.expr) ref
2120
val read_interface :

src/loader/doc_attr.ml

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let empty : Odoc_model.Comment.docs = empty_body
2828

2929

3030

31-
let load_payload : Parsetree.payload -> (string * Location.t) option = function
31+
let load_payload : Parsetree.payload -> string * Location.t = function
3232
| PStr [{pstr_desc =
3333
Pstr_eval ({pexp_desc =
3434
#if OCAML_MAJOR = 4 && OCAML_MINOR = 02
@@ -39,9 +39,21 @@ let load_payload : Parsetree.payload -> (string * Location.t) option = function
3939
Pexp_constant (Pconst_string (text, _, _))
4040
#endif
4141
; pexp_loc = loc; _}, _); _}] ->
42-
Some (text, loc)
43-
| _ ->
44-
None
42+
(text, loc)
43+
| _ -> assert false
44+
45+
46+
let parse_attribute : Parsetree.attribute -> (string * Location.t) option = function
47+
#if OCAML_MAJOR = 4 && OCAML_MINOR >= 08
48+
| { attr_name = { Location.txt =
49+
("text" | "ocaml.text"); loc = _loc}; attr_payload; _ } -> begin
50+
#else
51+
| ({Location.txt =
52+
("text" | "ocaml.text"); loc = _loc}, attr_payload) -> begin
53+
#endif
54+
Some (load_payload attr_payload)
55+
end
56+
| _ -> None
4557

4658
let attached parent attrs =
4759
let ocaml_deprecated = ref None in
@@ -56,7 +68,7 @@ let attached parent attrs =
5668
("doc" | "ocaml.doc"); loc = _loc}, attr_payload) :: rest -> begin
5769
#endif
5870
match load_payload attr_payload with
59-
| Some (str, loc) -> begin
71+
| (str, loc) -> begin
6072
let start_pos = loc.Location.loc_start in
6173
let start_pos =
6274
{start_pos with pos_cnum = start_pos.pos_cnum + 3} in
@@ -70,7 +82,6 @@ let attached parent attrs =
7082
in
7183
loop false 0 (acc @ parsed) rest
7284
end
73-
| None -> (* TODO *) assert false
7485
end
7586
| _ :: rest -> loop first nb_deprecated acc rest
7687
| [] -> begin
@@ -96,32 +107,15 @@ let read_string parent loc str : Odoc_model.Comment.docs_or_stop =
96107

97108
let page = read_string
98109

99-
let standalone parent
100-
: Parsetree.attribute -> Odoc_model.Comment.docs_or_stop option =
101-
102-
function
103-
#if OCAML_MAJOR = 4 && OCAML_MINOR >= 08
104-
| { attr_name = { Location.txt =
105-
("text" | "ocaml.text"); loc = _loc}; attr_payload; _ } -> begin
106-
#else
107-
| ({Location.txt =
108-
("text" | "ocaml.text"); loc = _loc}, attr_payload) -> begin
109-
#endif
110-
match load_payload attr_payload with
111-
| Some ("/*", _loc) -> Some `Stop
112-
| Some (str, loc) ->
113-
let loc' =
114-
{ loc with
115-
loc_start = { loc.loc_start with pos_cnum = loc.loc_start.pos_cnum + 3 } }
116-
in
117-
Some (read_string parent loc' str)
118-
| None ->
119-
(* TODO *)
120-
assert false
121-
(* let doc : Odoc_model.Comment.t =
122-
Error (invalid_attribute_error parent loc) in
123-
Some (Documentation doc) *)
124-
end
110+
let standalone parent(attr : Parsetree.attribute): Odoc_model.Comment.docs_or_stop option =
111+
match parse_attribute attr with
112+
| Some ("/*", _loc) -> Some `Stop
113+
| Some (str, loc) ->
114+
let loc' =
115+
{ loc with
116+
loc_start = { loc.loc_start with pos_cnum = loc.loc_start.pos_cnum + 3 } }
117+
in
118+
Some (read_string parent loc' str)
125119
| _ -> None
126120

127121
let standalone_multiple parent attrs =

src/loader/doc_attr.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module Paths = Odoc_model.Paths
2222

2323
val empty : Odoc_model.Comment.docs
2424

25+
val parse_attribute : Parsetree.attribute -> (string * Location.t) option
26+
2527
val attached :
2628
Paths.Identifier.LabelParent.t ->
2729
Parsetree.attributes ->

src/loader/dune

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
(rule
2+
(targets ident_env.ml)
3+
(deps
4+
(:x ident_env.cppo.ml))
5+
(action
6+
(chdir
7+
%{workspace_root}
8+
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))
9+
10+
(rule
11+
(targets ident_env.mli)
12+
(deps
13+
(:x ident_env.cppo.mli))
14+
(action
15+
(chdir
16+
%{workspace_root}
17+
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))
18+
119
(library
220
(name odoc_loader)
321
(public_name odoc.loader)

0 commit comments

Comments
 (0)