Skip to content

Commit 4fd0640

Browse files
committed
Ignore shadowed bindings when generating doc output
1 parent e377444 commit 4fd0640

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tools/src/tools.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open Analysis
22

3+
module StringSet = Set.Make (String)
4+
35
type fieldDoc = {
46
fieldName: string;
57
docstrings: string list;
@@ -458,6 +460,7 @@ let extractDocs ~entryPointFile ~debug =
458460
let env = QueryEnv.fromFile file in
459461
let rec extractDocsForModule ?(modulePath = [env.file.moduleName])
460462
(structure : Module.structure) =
463+
let valuesSeen = ref StringSet.empty in
461464
{
462465
id = modulePath |> List.rev |> ident;
463466
docstring = structure.docstring |> List.map String.trim;
@@ -611,7 +614,18 @@ let extractDocs ~entryPointFile ~debug =
611614
(makeId ~identifier:(Path.name p)
612615
moduleTypeIdPath);
613616
})
614-
| _ -> None);
617+
| _ -> None)
618+
(* Filter out shadowed bindings by keeping only the last value associated with an id *)
619+
|> List.rev
620+
|> List.filter_map (fun (docItem : docItem) ->
621+
match docItem with
622+
| Value {id} ->
623+
if StringSet.mem id !valuesSeen then None
624+
else (
625+
valuesSeen := StringSet.add id !valuesSeen;
626+
Some docItem)
627+
| _ -> Some docItem)
628+
|> List.rev;
615629
}
616630
in
617631
let docs = extractDocsForModule structure in

0 commit comments

Comments
 (0)