Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sherlodoc on .odoc-index file for odoc 3 compat #42

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(synopsis "Search engine for OCaml documentation")
(depends
(ocaml (>= 4.0.8))
(odoc (>= 2.4.0))
odoc
(base64 (>= 3.5.1))
(bigstringaf (>= 0.9.1))
(js_of_ocaml (>= 5.6.0))
Expand Down
39 changes: 34 additions & 5 deletions index/index.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let index_file register filename =
let index_odocl_file register filename =
match Fpath.of_string filename with
| Error (`Msg msg) -> Format.printf "FILE ERROR %s: %s@." filename msg
| Ok file ->
Expand All @@ -11,10 +11,19 @@ let index_file register filename =
let id = u.Lang.Compilation_unit.id in
Fold.unit ~f:(register (id :> Paths.Identifier.t)) () u
in
(match Odoc_odoc.Indexing.handle_file ~page ~unit file with
let occ _o = () in
(match Odoc_odoc.Indexing.handle_file ~page ~unit ~occ file with
| Ok result -> result
| Error (`Msg msg) -> Format.printf "Odoc warning or error %s: %s@." filename msg)

let index_odoc_index_file register filename =
match Fpath.of_string filename with
| Error (`Msg msg) -> Format.printf "FILE ERROR %s: %s@." filename msg
| Ok file ->
(match Odoc_odoc.Odoc_file.load_index file with
| Ok entries -> Odoc_model.Paths.Identifier.Hashtbl.Any.iter register (snd entries)
| Error (`Msg msg) -> Format.printf "Odoc warning or error %s: %s@." filename msg)

let main
files
favourite_files
Expand All @@ -39,7 +48,7 @@ let main
~favourite
~favoured_prefixes
~pkg)
(Odoc_search.Entry.entries_of_item id item)
(Odoc_search.Entry.entries_of_item item)
in
let files =
match file_list with
Expand Down Expand Up @@ -68,7 +77,27 @@ let main
| [ name; version; filename ] -> Db.Entry.Package.v ~name ~version, filename
| _ -> failwith ("invalid line: " ^ odoc)
in
index_file (register ~pkg ~favourite) odoc ;
let file = Fpath.v odoc in
(match Fpath.(get_ext file) with
| ".odocl" -> index_odocl_file (register ~pkg ~favourite) odoc
| ".odoc-index" ->
index_odoc_index_file
(fun _id entry ->
Load_doc.register_entry
~db
~index_docstring
~index_name
~type_search
~favourite
~favoured_prefixes
~pkg
entry)
odoc
| _ ->
Format.eprintf
"ERROR: %a is not a .odocl file, nor a .odoc-index file.@."
Fpath.pp
file) ;
if db_format = `ancient && Db_writer.load db > 1_000_000 then flush ()
in
List.iter (loop ~favourite:false) files ;
Expand Down Expand Up @@ -109,7 +138,7 @@ let odoc_favourite_file =
Arg.(value & opt_all file [] & info [ "favoured" ] ~doc)

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

let term =
Expand Down
6 changes: 3 additions & 3 deletions index/load_doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ let rec categorize id =
| `ExtensionDecl _ | `Module _ ) as x ->
let parent = Identifier.label_parent { id with iv = x } in
categorize (parent :> Identifier.Any.t)
| `AssetFile _ | `SourceDir _ | `SourceLocationMod _ | `SourceLocation _ | `SourcePage _
| `AssetFile _ | `SourceLocationMod _ | `SourceLocation _ | `SourcePage _
| `SourceLocationInternal _ ->
`ignore (* unclear what to do with those *)

Expand Down Expand Up @@ -185,7 +185,7 @@ let register_entry
let rhs = Html.rhs_of_kind kind in
let kind = convert_kind ~db entry in
let cost = cost ~name ~kind ~doc_html ~rhs ~cat ~favourite ~favoured_prefixes in
let url = Result.get_ok (Html.url id) in
let url = Result.get_ok (Html.url entry) in
let elt = Sherlodoc_entry.v ~name ~kind ~rhs ~doc_html ~cost ~url ~pkg () in
if index_docstring then register_doc ~db elt doc_txt ;
if index_name && kind <> Doc then register_full_name ~db elt ;
Expand All @@ -207,7 +207,7 @@ let register_entry
| Doc _ -> true
| _ -> false
in
if is_pure_documentation || cat = `ignore || Odoc_model.Paths.Identifier.is_internal id
if is_pure_documentation || cat = `ignore || Odoc_model.Paths.Identifier.is_hidden id
then ()
else
register_entry
Expand Down
16 changes: 13 additions & 3 deletions index/typename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ and show_signature h sig_ =
| `ModuleType (_, p) ->
Format.fprintf h "%s" (Odoc_model.Names.ModuleTypeName.to_string p)

let show_type_name_verbose h : Path.Type.t -> _ = function
let rec show_type_name_verbose h : Path.Type.t -> _ = function
| `Resolved t ->
Format.fprintf h "%a" show_ident_long Path.Resolved.(identifier (t :> t))
| `Identifier (path, _hidden) ->
let name = String.concat "." @@ Identifier.fullname path in
Format.fprintf h "%s" name
| `Dot (mdl, x) ->
Format.fprintf h "%s.%s" (Odoc_document.Url.render_path (mdl :> Path.t)) x
| `SubstitutedT t -> show_type_name_verbose h t
| `DotT (mdl, x) ->
Format.fprintf
h
"%s.%s"
(Odoc_document.Url.render_path (mdl :> Path.t))
(Odoc_model.Names.TypeName.to_string_unsafe x)

let to_string t = Format.asprintf "%a" show_type_name_verbose t

type t =
| Hidden of string
| Shadowed of string * int * string
| Std of string
6 changes: 5 additions & 1 deletion sherlodoc.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bug-reports: "https://github.com/art-w/sherlodoc/issues"
depends: [
"dune" {>= "3.5"}
"ocaml" {>= "4.0.8"}
"odoc" {>= "2.4.0"}
"odoc"
"base64" {>= "3.5.1"}
"bigstringaf" {>= "0.9.1"}
"js_of_ocaml" {>= "5.6.0"}
Expand Down Expand Up @@ -46,3 +46,7 @@ build: [
]
]
dev-repo: "git+https://github.com/art-w/sherlodoc.git"
pin-depends: [
[ "odoc.dev" "git+https://github.com/ocaml/odoc#f3b0823d90cfeb6583925a1cf90c82e3e52da268"]
[ "odoc-parser.dev" "git+https://github.com/ocaml/odoc#f3b0823d90cfeb6583925a1cf90c82e3e52da268"]
]
4 changes: 4 additions & 0 deletions sherlodoc.opam.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pin-depends: [
[ "odoc.dev" "git+https://github.com/ocaml/odoc#f3b0823d90cfeb6583925a1cf90c82e3e52da268"]
[ "odoc-parser.dev" "git+https://github.com/ocaml/odoc#f3b0823d90cfeb6583925a1cf90c82e3e52da268"]
]
3 changes: 2 additions & 1 deletion test/cram/cli.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
$ odoc compile -I . page.mld
$ odoc link -I . main.odoc
$ odoc link -I . page-page.odoc
$ odoc compile-index -o index.odoc-index -L '':.
$ export SHERLODOC_DB=db.bin
$ export SHERLODOC_FORMAT=marshal
$ sherlodoc index $(find . -name '*.odocl')
$ sherlodoc index index.odoc-index
$ sherlodoc search "unique_name"
val Main.unique_name : foo
$ sherlodoc search "multiple_hit"
Expand Down