Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7b66c13
Add test for omitting parent type in constructor reference (#447)
EmileTrotignon Feb 22, 2023
d318a5f
Allow signature to be parent in constructor references
EmileTrotignon Feb 27, 2023
be87d3a
move `class_signature_pv` from `parent` to `label_parent`
panglesd Feb 28, 2023
c280154
Force identifiers + resolved references to have a datatype as parent
panglesd Feb 28, 2023
bed9ef2
rename `parent` into `fragment_type_parent`
panglesd Mar 29, 2023
725d900
renaming fragment_type_parent to field_parent in resolved ref and id
panglesd Mar 29, 2023
c2228c0
invert type and datatype in Component
panglesd Mar 30, 2023
b637501
do not look for class when resolving a fragment_type_parent
panglesd Mar 30, 2023
c2c16a4
Improve test for omitted type in constructor parent
panglesd Dec 6, 2023
3c90fe0
Changelog entry for #933
panglesd Dec 6, 2023
5a054ff
Merge pull request #933 from panglesd/fix_447
Julow Dec 6, 2023
cea5c1b
Ident_env: Turn all maps into hashtbl
panglesd Oct 30, 2023
f0036f0
Collect occurrences info
panglesd May 23, 2023
b70e3f9
Occurrence: change datastructure to capture more information
panglesd Oct 19, 2023
e47ecad
Occurrences: add changelog
panglesd Oct 24, 2023
3af1d4c
remove duplicated function
panglesd Nov 2, 2023
ff735ea
Do not report resolution warning for occurrences
panglesd Nov 2, 2023
164cc19
Occurrences: Rename Definition to LocalDefinition when applicable
panglesd Nov 2, 2023
6229d9a
Occurrences: remove duplicated source infos
panglesd Nov 2, 2023
2f61d54
Occurrence: collect local module definitions
panglesd Nov 2, 2023
094eb94
Render source code: Add jump to implementation for modules
panglesd Nov 2, 2023
bca7259
Occurrences: style improvements
panglesd Nov 2, 2023
f42e58d
Occurrences: add a command to aggregate occurrence tables
panglesd Nov 2, 2023
0141cec
fmt
panglesd Nov 3, 2023
f1884c5
Occurrences: detection of hidden modules should be more efficient
panglesd Nov 3, 2023
00cb6b5
Occurrences: control which occurrences are counted
panglesd Nov 3, 2023
025f687
Occurrences: remove unused test
panglesd Nov 3, 2023
3224ef2
Occurrences: compatibility with different OCaml versions and fmt
panglesd Nov 3, 2023
213dcd1
fmt
panglesd Nov 3, 2023
b0da38a
Occurrences: change option from -include-persistent to -include-own
panglesd Nov 3, 2023
e098649
Occurrences: add shapes for other nodes, improve test
panglesd Nov 3, 2023
07c3dd9
loader compatibility code
panglesd Nov 3, 2023
cc6e2d7
Promote support files after rebase
panglesd Dec 5, 2023
ec233fe
occurrences: only count persistent one
panglesd Dec 6, 2023
0bc0fb0
Remove rendering of links to documentation
panglesd Dec 5, 2023
78d27ac
Only compute occurrences of odoc modules
panglesd Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Tags:
### Added
- Display 'private' keyword for private type extensions (@gpetiot, #1019)
- Add support for search (@panglesd, @EmileTrotignon, #972)
- Allow to omit parent type in constructor reference (@panglesd,
@EmileTrotignon, #933)
- Add jumps to documentation in rendered source code, and a `count-occurrences`
flag and command to count occurrences of every identifiers (@panglesd, #976)

### Fixed

Expand Down
18 changes: 15 additions & 3 deletions doc/driver.mld
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ Compiling a file with [odoc] requires a few arguments: the file to compile, an
optional parent, a list of include paths, a list of children for [.mld] files,
optional parent and name for source implementation, and an output path. Include
paths can be just ['.'], and we can calculate the output file from the input
because all of the files are going into the same directory.
because all of the files are going into the same directory. If we wish to count
occurrences of each identifier, we need to pass the [--count-occurrences] flag.

Linking a file with [odoc] requires the input file and a list of include paths. As
for compile, we will hard-code the include path.
Expand All @@ -148,6 +149,9 @@ Using the [--source] argument with an [.odocl] file that was not compiled with
[--source-parent-file] and [--source-name] will result in an error, as will omitting [--source] when generating HTML of an [odocl] that was
compiled with [--source-parent-file] and [--source-name].

To get the number of uses of each identifier, we can use the [count-occurrences]
command.

In all of these, we'll capture [stdout] and [stderr] so we can check it later.

{[
Expand Down Expand Up @@ -209,8 +213,9 @@ let add_prefixed_output cmd list prefix lines =
!list
@ Bos.Cmd.to_string cmd :: List.map (fun l -> prefix ^ ": " ^ l) lines

let compile file ?parent ?(output_dir = Fpath.v "./")
let compile file ?(count_occurrences = false) ?parent ?(output_dir = Fpath.v "./")
?(ignore_output = false) ?source_args children =
let count_occurrences = count_occurrences || (Option.is_some source_args) in
let output_basename =
let ext = Fpath.get_ext file in
let basename = Fpath.basename (Fpath.rem_ext file) in
Expand All @@ -237,8 +242,9 @@ let compile file ?parent ?(output_dir = Fpath.v "./")
| _ -> Cmd.empty
else Cmd.empty
in
let occ = if count_occurrences then Cmd.v "--count-occurrences" else Cmd.empty in
let cmd =
odoc % "compile" % Fpath.to_string file %% source_args %% cmt_arg
odoc % "compile" % Fpath.to_string file %% source_args %% occ %% cmt_arg
% "-I" % "." % "-o" % p output_file
|> List.fold_right (fun child cmd -> cmd % "--child" % child) children
in
Expand Down Expand Up @@ -289,6 +295,11 @@ let support_files () =
let open Cmd in
let cmd = odoc % "support-files" % "-o" % "html/odoc" in
run cmd

let count_occurrences output =
let open Cmd in
let cmd = odoc % "count-occurrences" % "-I" % "." % "-o" % p output in
run cmd
]}


Expand Down Expand Up @@ -750,6 +761,7 @@ let compiled = compile_all () in
let linked = link_all compiled in
let () = index_generate () in
let _ = js_index () in
let _ = count_occurrences (Fpath.v "occurrences.txt") in
generate_all linked
]}

Expand Down
35 changes: 29 additions & 6 deletions src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,41 @@ module Make (Syntax : SYNTAX) = struct
let path id = Url.Path.from_identifier id
let url id = Url.from_path (path id)

let to_link { Lang.Source_info.documentation; implementation } =
let documentation =
let open Paths.Path.Resolved in
match documentation with
| Some (`Resolved p) when not (is_hidden (p :> t)) -> (
let id = identifier (p :> t) in
match Url.from_identifier ~stop_before:false id with
| Ok link -> Some link
| _ -> None)
| _ -> None
in
let implementation =
match implementation with
| Some (Odoc_model.Lang.Source_info.Resolved id) -> (
match Url.Anchor.from_identifier (id :> Paths.Identifier.t) with
| Ok url -> Some url
| Error _ -> None)
| _ -> None
in
Some (Source_page.Link { implementation; documentation })

let info_of_info : Lang.Source_info.annotation -> Source_page.info option =
function
| Value id -> (
match Url.Anchor.from_identifier (id :> Paths.Identifier.t) with
| Ok url -> Some (Link url)
| Error _ -> None)
| Definition id -> (
match id.iv with
| `SourceLocation (_, def) -> Some (Anchor (DefName.to_string def))
| `SourceLocationInternal (_, local) ->
Some (Anchor (LocalName.to_string local))
| _ -> None)
| Module v -> to_link v
| ModuleType v -> to_link v
| Type v -> to_link v
| ClassType v -> to_link v
| Value v -> to_link v
| Constructor v -> to_link v

let source id syntax_info infos source_code =
let url = path id in
Expand Down Expand Up @@ -1784,8 +1807,8 @@ module Make (Syntax : SYNTAX) = struct
in
let source_anchor =
match t.source_info with
| Some src -> Some (Source_page.url src.id)
| None -> None
| Some { id = Some id; _ } -> Some (Source_page.url id)
| _ -> None
in
let page = make_expansion_page ~source_anchor url [ unit_doc ] items in
Document.Page page
Expand Down
6 changes: 5 additions & 1 deletion src/document/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ end =
Page

and Source_page : sig
type info = Syntax of string | Anchor of string | Link of Url.Anchor.t
type target = {
documentation : Url.Anchor.t option;
implementation : Url.Anchor.t option;
}
type info = Syntax of string | Anchor of string | Link of target

type code = span list
and span = Tagged_code of info * code | Plain_code of string
Expand Down
4 changes: 3 additions & 1 deletion src/html/html_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ let html_of_doc ~config ~resolve docs =
let children = List.concat @@ List.map (doc_to_html ~is_in_a) docs in
match info with
| Syntax tok -> [ span ~a:[ a_class [ tok ] ] children ]
| Link anchor ->
(* Currently, we do not render links to documentation *)
| Link { documentation = _; implementation = None } -> children
| Link { documentation = _; implementation = Some anchor } ->
let href = Link.href ~config ~resolve anchor in
[ a ~a:[ a_href href ] children ]
| Anchor lbl -> [ span ~a:[ a_id lbl ] children ])
Expand Down
2 changes: 1 addition & 1 deletion src/html_support_files/odoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1387,4 +1387,4 @@ td.def-doc *:first-child {
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*/
---------------------------------------------------------------------------*/
Loading