Skip to content

Ignore shadowed bindings when generating doc output #7497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# 12.0.0-alpha.14 (Unreleased)

#### :bug: Bug fix

- `rescript-tools doc` no longer includes shadowed bindings in its output. https://github.com/rescript-lang/rescript/pull/7497

# 12.0.0-alpha.13

#### :boom: Breaking Change
Expand Down
16 changes: 15 additions & 1 deletion tools/src/tools.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
open Analysis

module StringSet = Set.Make (String)

type fieldDoc = {
fieldName: string;
docstrings: string list;
Expand Down Expand Up @@ -458,6 +460,7 @@ let extractDocs ~entryPointFile ~debug =
let env = QueryEnv.fromFile file in
let rec extractDocsForModule ?(modulePath = [env.file.moduleName])
(structure : Module.structure) =
let valuesSeen = ref StringSet.empty in
{
id = modulePath |> List.rev |> ident;
docstring = structure.docstring |> List.map String.trim;
Expand Down Expand Up @@ -611,7 +614,18 @@ let extractDocs ~entryPointFile ~debug =
(makeId ~identifier:(Path.name p)
moduleTypeIdPath);
})
| _ -> None);
| _ -> None)
(* Filter out shadowed bindings by keeping only the last value associated with an id *)
|> List.rev
|> List.filter_map (fun (docItem : docItem) ->
match docItem with
| Value {id} ->
if StringSet.mem id !valuesSeen then None
else (
valuesSeen := StringSet.add id !valuesSeen;
Some docItem)
| _ -> Some docItem)
|> List.rev;
}
in
let docs = extractDocsForModule structure in
Expand Down