From 4fd06401503fd1ad952d4258a04ae54322def114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Wed, 21 May 2025 14:39:30 +0100 Subject: [PATCH 1/2] Ignore shadowed bindings when generating doc output --- tools/src/tools.ml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/src/tools.ml b/tools/src/tools.ml index e0bdc28c37..2db1be7e6a 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -1,5 +1,7 @@ open Analysis +module StringSet = Set.Make (String) + type fieldDoc = { fieldName: string; docstrings: string list; @@ -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; @@ -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 From 581337edbe112f1eee0fa03470192f46ea6bc90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Wed, 21 May 2025 14:42:16 +0100 Subject: [PATCH 2/2] Add CHANGELOG entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae5700ade..ed93f9f578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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