Skip to content

Commit 64624e2

Browse files
authored
Ignore shadowed bindings when generating doc output (#7497)
* Ignore shadowed bindings when generating doc output * Add CHANGELOG entry
1 parent e377444 commit 64624e2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.14 (Unreleased)
1414

15+
#### :bug: Bug fix
16+
17+
- `rescript-tools doc` no longer includes shadowed bindings in its output. https://github.com/rescript-lang/rescript/pull/7497
18+
1519
# 12.0.0-alpha.13
1620

1721
#### :boom: Breaking Change

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)