Skip to content

Commit c00c4d6

Browse files
committed
Occurrence: refactor typedtree traverse and source_info type
An occurrence contains information for its documentation and its implementation. The manual traverse is made only to compute the environment, the compiler traverse is used to find occurrences. Signed-off-by: Paul-Elliot <[email protected]>
1 parent 46820f7 commit c00c4d6

File tree

10 files changed

+415
-526
lines changed

10 files changed

+415
-526
lines changed

src/document/generator.ml

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -252,52 +252,43 @@ module Make (Syntax : SYNTAX) = struct
252252
let path id = Url.Path.from_identifier id
253253
let url id = Url.from_path (path id)
254254

255+
let to_link documentation implementation =
256+
let documentation =
257+
let open Paths.Path.Resolved in
258+
match documentation with
259+
| Some (`Resolved p) when not (is_hidden (p :> t)) -> (
260+
let id = identifier (p :> t) in
261+
match Url.from_identifier ~stop_before:false id with
262+
| Ok link -> Some link
263+
| _ -> None)
264+
| _ -> None
265+
in
266+
let implementation =
267+
match implementation with
268+
| None -> None
269+
| Some id -> (
270+
match Url.Anchor.from_identifier (id :> Paths.Identifier.t) with
271+
| Ok url -> Some url
272+
| Error _ -> None)
273+
in
274+
Some (Source_page.Link { implementation; documentation })
275+
255276
let info_of_info : Lang.Source_info.annotation -> Source_page.info option =
256277
function
257-
| Value id -> (
258-
match Url.Anchor.from_identifier (id :> Paths.Identifier.t) with
259-
| Ok url -> Some (Link url)
260-
| Error _ -> None)
261278
| Definition id -> (
262279
match id.iv with
263280
| `SourceLocation (_, def) -> Some (Anchor (DefName.to_string def))
264281
| `SourceLocationInternal (_, local) ->
265282
Some (Anchor (LocalName.to_string local))
266283
| _ -> None)
267-
| ModulePath (`Resolved p)
268-
when not (Paths.Path.Resolved.is_hidden (p :> Paths.Path.Resolved.t))
269-
-> (
270-
let id = Paths.Path.Resolved.(identifier (p :> t)) in
271-
match Url.from_identifier ~stop_before:false id with
272-
| Ok link -> Some (Link link)
273-
| _ -> None)
274-
| TypePath (`Resolved p)
275-
when not (Paths.Path.Resolved.is_hidden (p :> Paths.Path.Resolved.t))
276-
-> (
277-
let id = Paths.Path.Resolved.(identifier (p :> t)) in
278-
match Url.from_identifier ~stop_before:false id with
279-
| Ok link -> Some (Link link)
280-
| _ -> None)
281-
| ValuePath (`Resolved p)
282-
when not (Paths.Path.Resolved.is_hidden (p :> Paths.Path.Resolved.t))
283-
-> (
284-
let id = Paths.Path.Resolved.(identifier (p :> t)) in
285-
match Url.from_identifier ~stop_before:false id with
286-
| Ok link -> Some (Link link)
287-
| _ -> None)
288-
| ConstructorPath (`Resolved p)
289-
when not (Paths.Path.Resolved.is_hidden (p :> Paths.Path.Resolved.t))
290-
-> (
291-
let id = Paths.Path.Resolved.(identifier (p :> t)) in
292-
match Url.from_identifier ~stop_before:false id with
293-
| Ok link -> Some (Link link)
294-
| _ -> None)
295-
| ModulePath _ -> None
296-
| ClassPath _ -> None
297-
| TypePath _ -> None
298-
| MtyPath _ -> None
299-
| ValuePath _ -> None
300-
| ConstructorPath _ -> None
284+
| Module { documentation; _ } -> to_link documentation None
285+
| ModuleType { documentation; _ } -> to_link documentation None
286+
| Type { documentation; _ } -> to_link documentation None
287+
| Class { documentation; _ } -> to_link documentation None
288+
| Value { documentation; implementation } ->
289+
to_link documentation implementation
290+
| Constructor { documentation; _ } -> to_link documentation None
291+
301292

302293
let source id syntax_info infos source_code =
303294
let url = path id in

src/document/types.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ end =
183183
Page
184184

185185
and Source_page : sig
186-
type info = Syntax of string | Anchor of string | Link of Url.Anchor.t
186+
187+
type target = { documentation : Url.Anchor.t option ; implementation : Url.Anchor.t option}
188+
type info = Syntax of string | Anchor of string | Link of target
187189

188190
type code = span list
189191
and span = Tagged_code of info * code | Plain_code of string

src/html/html_source.ml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,24 @@ let html_of_doc ~config ~resolve docs =
2424
let children = List.concat @@ List.map (doc_to_html ~is_in_a) docs in
2525
match info with
2626
| Syntax tok -> [ span ~a:[ a_class [ tok ] ] children ]
27-
| Link anchor ->
28-
let href = Link.href ~config ~resolve anchor in
29-
[ a ~a:[ a_href href ] children ]
27+
| Link { documentation; implementation } -> (
28+
let href_implementation =
29+
Option.map (Link.href ~config ~resolve) implementation
30+
in
31+
let href_documentation =
32+
Option.map (Link.href ~config ~resolve) documentation
33+
in
34+
let body =
35+
match href_implementation with
36+
| Some href -> [ a ~a:[ a_href href ] children ]
37+
| None -> children
38+
in
39+
match href_documentation with
40+
| None -> body
41+
| Some href ->
42+
[
43+
span ~a:[] [ span ~a:[] body; a ~a:[ a_href href ] [txt "Jump to documentation"] ];
44+
])
3045
| Anchor lbl -> [ span ~a:[ a_id lbl ] children ])
3146
in
3247
span ~a:[] @@ List.concat @@ List.map (doc_to_html ~is_in_a:false) docs

0 commit comments

Comments
 (0)