Skip to content

Commit 4552c75

Browse files
authored
forc-doc: Preserve all doc links when merging parallel results (#7379)
## Description The sway-lib-std docs are broken and not showing all of the generated documentaiton. The root `index.html` was showing only one module while `all.html` listed only a subset of types. This started happening after the parallel processing was introduced in #7296. This PR fixes this as can be seen in the screenshots below. Also undoes the CI changes in #7362 & #7365 as they aren't necessary as this was the root cause. - Root cause: Using BTreeMap::extend to merge per-item results overwrote existing per-category vectors, so only the last chunk from parallel processing survived. - Fix: replace `.extend` merges with per-key append-and-dedup loops. Before: <img width="1608" height="1040" alt="before" src="https://github.com/user-attachments/assets/e433fcc2-cce6-4737-8ed3-c9e2a679de5a" /> After: <img width="1608" height="1040" alt="after" src="https://github.com/user-attachments/assets/c9e9c007-df6a-49b3-b864-e30d19f487f2" /> ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 3210f94 commit 4552c75

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

.github/workflows/gh-pages.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,12 @@ jobs:
5555
- name: Build Sway std library
5656
run: forc doc --path ./sway-lib-std
5757

58-
- name: Move assets into std directory
59-
run: |
60-
mv ./sway-lib-std/out/doc/static.files ./sway-lib-std/out/doc/std/
61-
mv ./sway-lib-std/out/doc/search.js ./sway-lib-std/out/doc/std/
62-
# Fix relative paths in HTML files
63-
find ./sway-lib-std/out/doc/std -name "*.html" -type f -exec sed -i 's|../static\.files/|static.files/|g' {} \;
64-
find ./sway-lib-std/out/doc/std -name "*.html" -type f -exec sed -i 's|../search\.js|search.js|g' {} \;
65-
6658
- name: Deploy master std
6759
uses: peaceiris/actions-gh-pages@v3
6860
with:
6961
github_token: ${{ secrets.GITHUB_TOKEN }}
70-
publish_dir: ./sway-lib-std/out/doc/std
71-
destination_dir: master/std
62+
publish_dir: ./sway-lib-std/out/doc
63+
destination_dir: master
7264
if: github.ref == 'refs/heads/master'
7365

7466
- name: Deploy master book
@@ -133,7 +125,7 @@ jobs:
133125
uses: peaceiris/actions-gh-pages@v3
134126
with:
135127
github_token: ${{ secrets.GITHUB_TOKEN }}
136-
publish_dir: ./sway-lib-std/out/doc
128+
publish_dir: ./sway-lib-std/out/doc/std
137129
destination_dir: ${{ steps.branch_name.outputs.BRANCH_NAME }}/std
138130
if: startsWith(github.ref, 'refs/tags')
139131

forc-plugins/forc-doc/src/render/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,29 @@ impl RenderedDocumentation {
120120
for (rendered_doc, local_module_map, local_all_docs) in rendered_results? {
121121
rendered_docs.0.push(rendered_doc);
122122

123+
// Merge module maps without overwriting existing categories; append and dedup links.
123124
for (key, value) in local_module_map {
124-
module_map.entry(key).or_default().extend(value);
125+
let entry = module_map.entry(key).or_default();
126+
for (block, mut links) in value {
127+
let list = entry.entry(block).or_default();
128+
// Append new links while avoiding duplicates.
129+
for link in links.drain(..) {
130+
if !list.contains(&link) {
131+
list.push(link);
132+
}
133+
}
134+
}
125135
}
126136

127-
all_docs.links.extend(local_all_docs.links);
137+
// Merge "all docs" links similarly, preserving existing items.
138+
for (block, mut links) in local_all_docs.links {
139+
let list = all_docs.links.entry(block).or_default();
140+
for link in links.drain(..) {
141+
if !list.contains(&link) {
142+
list.push(link);
143+
}
144+
}
145+
}
128146
}
129147

130148
// ProjectIndex

0 commit comments

Comments
 (0)