Skip to content

Commit 8f903c7

Browse files
committed
Compatibility with Odoc 3
Several changes: - Entries are now defined in the `odoc_index` library, - Entries can have new kinds (pages, source, ...) - Indexes have the form of "skeletons of entries", that can be folded. - Indexes can be created by odoc with the `odoc compile-index` command, and then consumed by sherlodoc. These changes come from: - ocaml/odoc#1228 - ocaml/odoc#1232 - ocaml/odoc#1233 - ocaml/odoc#1244 - ocaml/odoc#1250 - ocaml/odoc#1251
1 parent 358dc49 commit 8f903c7

File tree

9 files changed

+46
-36
lines changed

9 files changed

+46
-36
lines changed

cli/search.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ let string_of_kind =
1717
| Constructor _ -> "cons"
1818
| Field _ -> "field"
1919
| Val _ -> "val"
20+
| Page -> "page"
21+
| Impl -> "source"
2022

2123
let print_result ~print_cost ~print_docstring ~no_rhs (elt : Db.Entry.t) =
2224
let cost = if print_cost then string_of_int elt.cost ^ " " else "" in

db/entry.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ let non_empty_string s =
66

77
module Kind = struct
88
type t =
9-
| Doc
9+
| Doc (** Standalone doc comment *)
10+
| Page (** Mld page *)
11+
| Impl (** Source page *)
1012
| Module
1113
| Module_type
1214
| Class
@@ -26,7 +28,7 @@ module Kind = struct
2628
match t with
2729
| Val typ | Extension_constructor typ | Exception typ | Constructor typ | Field typ ->
2830
Some typ
29-
| Doc | Module | Module_type | Class | Class_type | Method | Type_decl _
31+
| Doc | Page | Impl | Module | Module_type | Class | Class_type | Method | Type_decl _
3032
| Type_extension ->
3133
None
3234
end

db/entry.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Kind : sig
22
type t =
3-
| Doc
3+
| Doc (** Standalone doc comment *)
4+
| Page (** Mld page *)
5+
| Impl (** Source page *)
46
| Module
57
| Module_type
68
| Class

index/index.ml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ let index_file register filename =
33
| Error (`Msg msg) -> Format.printf "FILE ERROR %s: %s@." filename msg
44
| Ok file ->
55
let open Odoc_model in
6-
let page p =
7-
let id = p.Lang.Page.name in
8-
Fold.page ~f:(register (id :> Paths.Identifier.t)) () p
9-
in
10-
let unit u =
11-
let id = u.Lang.Compilation_unit.id in
12-
Fold.unit ~f:(register (id :> Paths.Identifier.t)) () u
13-
in
14-
(match Odoc_odoc.Indexing.handle_file ~page ~unit file with
6+
let page p = register [ Odoc_index.Skeleton.from_page p ] in
7+
let unit u = register [ Odoc_index.Skeleton.from_unit u ] in
8+
let occ o = register o in
9+
(match Odoc_odoc.Indexing.handle_file ~page ~unit ~occ file with
1510
| Ok result -> result
16-
| Error (`Msg msg) -> Format.printf "Odoc warning or error %s: %s@." filename msg)
11+
| Error (`Msg msg) ->
12+
Format.printf "Odoc warning or error %a: %s@." Fpath.pp file msg)
1713

1814
let main
1915
files
@@ -29,17 +25,18 @@ let main
2925
let module Storage = (val Db_store.storage_module db_format) in
3026
let db = Db_writer.make () in
3127
let no_pkg = Db.Entry.Package.v ~name:"" ~version:"" in
32-
let register ~pkg ~favourite id () item =
28+
let register ~pkg ~favourite =
3329
List.iter
34-
(Load_doc.register_entry
35-
~db
36-
~index_docstring
37-
~index_name
38-
~type_search
39-
~favourite
40-
~favoured_prefixes
41-
~pkg)
42-
(Odoc_search.Entry.entries_of_item id item)
30+
@@ Odoc_utils.Tree.iter
31+
~f:
32+
(Load_doc.register_entry
33+
~db
34+
~index_docstring
35+
~index_name
36+
~type_search
37+
~favourite
38+
~favoured_prefixes
39+
~pkg)
4340
in
4441
let files =
4542
match file_list with
@@ -109,7 +106,7 @@ let odoc_favourite_file =
109106
Arg.(value & opt_all file [] & info [ "favoured" ] ~doc)
110107

111108
let odoc_files =
112-
let doc = "Path to a .odocl file" in
109+
let doc = "Path to a .odocl file or a .odoc-index file" in
113110
Arg.(value & (pos_all file [] @@ info ~doc ~docv:"ODOCL_FILE" []))
114111

115112
let term =

index/load_doc.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let searchable_type_of_constructor args res =
9999
let searchable_type_of_record parent_type type_ =
100100
Odoc_model.Lang.TypeExpr.Arrow (None, parent_type, type_)
101101

102-
let convert_kind ~db (Odoc_search.Entry.{ kind; _ } as entry) =
102+
let convert_kind ~db (Odoc_index.Entry.{ kind; _ } as entry) =
103103
match kind with
104104
| TypeDecl _ -> Entry.Kind.Type_decl (Odoc_search.Html.typedecl_params_of_entry entry)
105105
| Value { value = _; type_ } ->
@@ -121,13 +121,16 @@ let convert_kind ~db (Odoc_search.Entry.{ kind; _ } as entry) =
121121
let typ = searchable_type_of_record parent_type type_ in
122122
let typ = Db_writer.type_of_odoc ~db typ in
123123
Entry.Kind.Field typ
124-
| Doc _ -> Doc
124+
| Doc -> Doc
125+
| Dir -> Doc
126+
| Page _ -> Doc
125127
| Class_type _ -> Class_type
126128
| Method _ -> Method
127129
| Class _ -> Class
128130
| TypeExtension _ -> Type_extension
129-
| Module -> Entry.Kind.Module
130-
| ModuleType -> Module_type
131+
| Module _ -> Entry.Kind.Module
132+
| ModuleType _ -> Module_type
133+
| Impl -> Doc
131134

132135
let register_type_expr ~db elt typ =
133136
let type_polarities = Db.Type_polarity.of_typ ~any_is_poly:true typ in
@@ -150,11 +153,11 @@ let rec categorize id =
150153
| `ExtensionDecl _ | `Module _ ) as x ->
151154
let parent = Identifier.label_parent { id with iv = x } in
152155
categorize (parent :> Identifier.Any.t)
153-
| `AssetFile _ | `SourceDir _ | `SourceLocationMod _ | `SourceLocation _ | `SourcePage _
156+
| `AssetFile _ | `SourceLocationMod _ | `SourceLocation _ | `SourcePage _
154157
| `SourceLocationInternal _ ->
155158
`ignore (* unclear what to do with those *)
156159

157-
let categorize Odoc_search.Entry.{ id; _ } =
160+
let categorize Odoc_index.Entry.{ id; _ } =
158161
match id.iv with
159162
| `ModuleType (parent, _) ->
160163
(* A module type itself is not *from* a module type, but it might be if one
@@ -171,7 +174,7 @@ let register_entry
171174
~favoured_prefixes
172175
~pkg
173176
~cat
174-
(Odoc_search.Entry.{ id; doc; kind } as entry)
177+
(Odoc_index.Entry.{ id; doc; kind } as entry)
175178
=
176179
let module Sherlodoc_entry = Entry in
177180
let open Odoc_search in
@@ -199,15 +202,15 @@ let register_entry
199202
~favourite
200203
~favoured_prefixes
201204
~pkg
202-
(Odoc_search.Entry.{ id; kind; _ } as entry)
205+
(Odoc_index.Entry.{ id; kind; _ } as entry)
203206
=
204207
let cat = categorize entry in
205208
let is_pure_documentation =
206209
match kind with
207-
| Doc _ -> true
210+
| Doc | Page _ | Dir | Impl -> true
208211
| _ -> false
209212
in
210-
if is_pure_documentation || cat = `ignore || Odoc_model.Paths.Identifier.is_internal id
213+
if is_pure_documentation || cat = `ignore || Odoc_model.Paths.Identifier.is_hidden id
211214
then ()
212215
else
213216
register_entry

index/load_doc.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ val register_entry
66
-> favourite:bool
77
-> favoured_prefixes:string list
88
-> pkg:Db.Entry.Package.t
9-
-> Odoc_search.Entry.t
9+
-> Odoc_index.Entry.t
1010
-> unit
1111
(** [register_entry ~db ~index_name ~type_search ~index_docstring e] register
1212
the entry [e] in [db]. *)

jsoo/main.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ let string_of_kind =
8181
let open Odoc_html_frontend in
8282
function
8383
| Db.Entry.Kind.Doc -> kind_doc
84+
| Page -> kind_doc
85+
| Impl -> kind_impl
8486
| Type_decl _ -> kind_typedecl
8587
| Module -> kind_module
8688
| Exception _ -> kind_exception

jsoo/odoc_html_frontend.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ let kind_constructor = "cons"
4949
let kind_field = "field"
5050
let kind_value = "val"
5151
let kind_extension = "ext"
52+
let kind_impl = "source"

test/cram/cli.t/run.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
$ odoc compile -I . page.mld
44
$ odoc link -I . main.odoc
55
$ odoc link -I . page-page.odoc
6+
$ odoc compile-index -o index.odoc-index --root ./
67
$ export SHERLODOC_DB=db.bin
78
$ export SHERLODOC_FORMAT=marshal
8-
$ sherlodoc index $(find . -name '*.odocl')
9+
$ sherlodoc index index.odoc-index
910
$ sherlodoc search "unique_name"
1011
val Main.unique_name : foo
1112
$ sherlodoc search "multiple_hit"

0 commit comments

Comments
 (0)