Repository navigation
fix(doc_cli): include module and class members in the HTML search index - #1476
Conversation
There was a problem hiding this comment.
Code Review
.github/workflows/coverage.yml
1. concurrency.group collision risk (minor)
The group uses coverage-${{ github.workflow }}-${{ github.ref }}. github.workflow is already Coverage, so github.ref is the discriminator. This is fine, but ${{ github.workflow }} is redundant. Not a bug.
2. Fork-PR skip means missing PR coverage comment (design note)
For fork PRs the upload is skipped, so Coveralls won't report on those PRs. That's an explicit trade-off documented in the comment — acceptable, but worth confirming that's the desired UX (e.g. continue-on-error: true on the upload step might be preferable so non-fork failures still surface but don't fail the build).
3. fetch-depth: 0 on every run
Full history is only needed by coveralls for base-commit diffs. Combined with cancel-in-progress on PRs this is usually fine, but it slows clone time noticeably. Consider fetch-depth: 0 only on the pull_request/push events that need it (all of them here, so low priority).
4. Missing --locked
cargo llvm-cov --workspace --all-features will update Cargo.lock if it's stale. In CI you typically want --locked to fail fast on a dirty lockfile. Same applies if a Cargo.lock isn't committed.
crates/emmylua_doc_cli/src/html_generator/mod.rs
5. &mut pages iteration + later &pages borrow (correct, but note)
for (filename, doc) in &mut pages then write_search_index(&output, &index_doc.nav, &pages) — this is fine because the mutable borrow ends with the loop, but it's slightly fragile if anyone later moves a &pages use inside the loop. Not a defect.
6. Potential duplicate search entries from methods.chain(fields)
If a name appears in both doc.methods and doc.fields (e.g. overloaded / re-declared member, or a field that's also emitted as a method by the doc resolver), the search index will contain two entries with the same name and href. The tests use find_entry which asserts len == 1, so a fixture triggering this would fail — but the production code has no dedup. Consider using a HashSet or asserting/no-op on duplicates. At minimum, a duplicate silently produces duplicate search results.
7. Anchor generation assumption is untested by the helper
format!("{href}#{}", member.name) assumes the member's DOM id is exactly member.name. The tests validate this for the given fixtures (assert_member_anchors_exist), but there's no guard in production code. If HtmlDoc member name ever differs from the anchor id (e.g. HTML-escaping for names with <, &, or Unicode that gets escaped differently), search links will silently 404 the anchor. Worth a comment or a shared constant/function that both the template and the index use to derive the anchor id.
8. HTML-unsafe anchors
member.name is inserted into a JSON href verbatim. serde_json::to_string escapes for JS string context, so search-index.js itself is safe. However, if main.js sets location.hash from a name containing #, ?, spaces, or non-ASCII, the browser may misparse the anchor. If Lua identifiers are guaranteed ASCII [A-Za-z0-9_.], ignore; otherwise percent-encoding the fragment is safer.
9. pages type coupling
Changing write_search_index to take &[(String, HtmlDoc)] couples it to the concrete page tuple. A small struct PageRef<'a> { href: &'a str, doc: &'a HtmlDoc } or just impl Iterator<Item = (&str, &HtmlDoc)> would be cleaner and avoid the &pages shape leaking. Not blocking.
crates/emmylua_doc_cli/tests/common/mod.rs
10. Brittle string strip
strip_prefix("window.SEARCH_INDEX = ") / strip_suffix(';') will break the moment the emitter is wrapped in a function, minified, or gains a trailing newline (the suffix ; alone requires no trailing whitespace — actually strip_suffix(';') does not tolerate a trailing \n). The current writer emits window.SEARCH_INDEX = {json};, matching, but this is fragile. If/when the generator changes, every test breaks with a confusing "unexpected search index format" panic. Consider asserting the exact prefix/suffix in the generator test, or reading via a lightweight extraction that trims first.
crates/emmylua_doc_cli/tests/html_search_index.rs
11. Test gaps
- No test covers a duplicate member name across methods/fields (see item 6).
- No test covers a member whose name collides with a page-level entry name (e.g. global
gvs the fieldg, or a classWidgetvs. a member namedWidget).find_entryrequiring exactly one match would catch page-level collisions, but there is no explicit case. - No test for an empty fixture / no pages — trivially fine, but a guard against a panic-on-empty regression is cheap.
assert_member_anchors_existskips non-member kinds, so a regression that emitted members under a differentkindlabel (e.g."function"instead of"method") would slip through the anchor check (though the explicitassert_eq!(method["kind"], "method")per test covers it).
12. find_entry panics with the full entries dump on failure
For large fixtures this is noisy but acceptable in tests. Fine.
13. common module is shared
html_search_index.rs declares mod common; — if common/mod.rs was previously only used by another test file, adding a second consumer is fine (each integration test compiles its own copy), but unused-fn warnings can appear per test binary. Since read_search_index is used here, no warning. OK.
Summary
| Severity | Issue |
|---|---|
| Medium | Possible duplicate search entries when a name is both method and field (item 6) |
| Medium | Anchor id derived independently of template; no production-side guard (item 7) |
| Low | strip_suffix(';') brittle to trailing whitespace (item 10) |
| Low | Missing --locked in cargo llvm-cov (item 4) |
| Low | Duplicate/collision test coverage gaps (item 11) |
| Nit | Redundant github.workflow in concurrency group; &mut pages iteration fragility |
4780618 to
f44f980
Compare
Include module, class, enum and global members in static/search-index.js with their page anchors so searching for a member name finds it. Fixes EmmyLuaLs#1475
f44f980 to
cf0c5bc
Compare
Deduplicate identical member entries, share member anchors between the templates and the index, and make search-index parsing in tests resilient to whitespace. Expand coverage for globals, enums, private members, namespaced anchors, empty docs and duplicate entries Follows up EmmyLuaLs#1475
cf0c5bc to
2ba0e41
Compare
Addressed5.
|
|
@CppCXY Can we fix this? It would make searching much more convenient. |
Fixes #1475