From 6bcde37316064f3020dc6f9c0b49720304956a66 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Thu, 14 Sep 2023 18:07:44 +0100 Subject: [PATCH] Apply suggestions from PR review Suggested by @panglesd. --- src/odoc/bin/main.ml | 13 +++++++------ src/odoc/html_page.ml | 18 +++++++++++------- src/odoc/html_page.mli | 8 ++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/odoc/bin/main.ml b/src/odoc/bin/main.ml index 7a402c36b3..c88d531292 100644 --- a/src/odoc/bin/main.ml +++ b/src/odoc/bin/main.ml @@ -41,17 +41,17 @@ let convert_fpath = let convert_src_fpath = let parse inp = match Arg.(conv_parser file) inp with - | Ok s -> Result.Ok (Html_page.File (Fs.File.of_string s)) + | Ok s -> Result.Ok (Html_page.Source.File (Fs.File.of_string s)) | Error _ as e -> e - and print = Html_page.pp in + and print = Html_page.Source.pp in Arg.conv (parse, print) let convert_src_dir = let parse inp = match Arg.(conv_parser dir) inp with - | Ok s -> Result.Ok (Html_page.Root (Fs.File.of_string s)) + | Ok s -> Result.Ok (Html_page.Source.Root (Fs.File.of_string s)) | Error _ as e -> e - and print = Html_page.pp in + and print = Html_page.Source.pp in Arg.conv (parse, print) (** On top of the conversion 'string', split into segs. *) @@ -732,8 +732,9 @@ module Odoc_html_args = struct let source_root = let doc = - "Source code root for the compilation unit. It must have been compiled \ - with --source-parent passed." + "Source code root for the compilation unit. Used to find the source file \ + from the value of --source-name it was compiled with. Incompatible with \ + --source-file." in Arg.( value diff --git a/src/odoc/html_page.ml b/src/odoc/html_page.ml index a133f04432..566cb81b2a 100644 --- a/src/odoc/html_page.ml +++ b/src/odoc/html_page.ml @@ -16,13 +16,17 @@ open Odoc_model -type source = File of Fpath.t | Root of Fpath.t +module Source = struct + type t = File of Fpath.t | Root of Fpath.t -let pp fmt = function - | File f -> Format.fprintf fmt "File: %a" Fpath.pp f - | Root f -> Format.fprintf fmt "File: %a" Fpath.pp f + let pp fmt = function + | File f -> Format.fprintf fmt "File: %a" Fpath.pp f + | Root f -> Format.fprintf fmt "File: %a" Fpath.pp f -let to_string f = Format.asprintf "%a" pp f + let to_string f = Format.asprintf "%a" pp f +end + +type source = Source.t type args = { html_config : Odoc_html.Config.t; @@ -38,7 +42,7 @@ let source_documents source_info source ~syntax = | Some { Lang.Source_info.id; infos }, Some src -> ( let file = match src with - | File f -> f + | Source.File f -> f | Root f -> let open Odoc_model.Paths.Identifier in let rec get_path_dir : SourceDir.t -> Fpath.t = function @@ -76,7 +80,7 @@ let source_documents source_info source ~syntax = (Error.filename_only "--source argument is invalid on compilation unit that were not \ compiled with --source-parent and --source-name" - (to_string src)); + (Source.to_string src)); [] | None, None -> [] diff --git a/src/odoc/html_page.mli b/src/odoc/html_page.mli index faa34e5e79..579acd3a3c 100644 --- a/src/odoc/html_page.mli +++ b/src/odoc/html_page.mli @@ -16,9 +16,13 @@ open Odoc_document -type source = File of Fpath.t | Root of Fpath.t +module Source : sig + type t = File of Fpath.t | Root of Fpath.t -val pp : Format.formatter -> source -> unit + val pp : Format.formatter -> t -> unit +end + +type source = Source.t type args = { html_config : Odoc_html.Config.t;