Skip to content

Fix docgen source links for modules in nested directories - #6703

Open
leonitousconforti wants to merge 2 commits into
Effect-TS:mainfrom
leonitousconforti:fix/docgen-nested-source-links
Open

Fix docgen source links for modules in nested directories#6703
leonitousconforti wants to merge 2 commits into
Effect-TS:mainfrom
leonitousconforti:fix/docgen-nested-source-links

Conversation

@leonitousconforti

@leonitousconforti leonitousconforti commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

[Source](...) links in docgen's generated markdown are built from only the file's base name:

const name = source.sourceFile.getBaseName()
return `\n\n[Source](${config.srcLink}${name}#L${position.line})`

For modules in subdirectories of srcDir (e.g. src/frida/FridaRpcClient.ts), the link drops the subdirectory and points one level too high (<srcLink>/FridaRpcClient.ts instead of <srcLink>/frida/FridaRpcClient.ts), producing 404s.

This changes the printer to use the module's path relative to srcDir (source.path.slice(1).join("/")), which is the same convention getModuleMarkdownOutputPath already uses for the generated markdown file layout. Links for modules directly under srcDir are unchanged.

Notes

  • The makeSource test helper previously modeled Source.path as [basename], which doesn't match production (file.path.split(path.sep) including the srcDir prefix). It now derives the path from the source file's actual file path with a src prefix, matching what parseFile produces.
  • Added a regression test covering a module in a nested directory.

Noticed while adopting @effect/docgen@4.0.0-beta.102 in a project with nested modules: leonitousconforti/efffrida#158

Summary by CodeRabbit

  • Bug Fixes

    • Fixed generated documentation Source links for modules in nested directories.
    • Source links now display and resolve the correct relative folder path and line reference instead of targeting the wrong directory level.
  • Tests

    • Updated and expanded parser/docgen test coverage to ensure nested in-memory source files produce correctly formed Source links.

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7cc035a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@effect/docgen Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ab0c938-13f7-49be-a798-4f4bced11ef3

📥 Commits

Reviewing files that changed from the base of the PR and between 8d2d808 and 7cc035a.

📒 Files selected for processing (1)
  • packages/tools/docgen/test/Parser.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/tools/docgen/test/Parser.test.ts

📝 Walkthrough

Walkthrough

Docgen source links now retain nested source-directory paths instead of using only file names. Parser tests construct full source paths and verify generated markdown for a nested module.

Changes

Docgen source-link path handling

Layer / File(s) Summary
Preserve nested source paths
packages/tools/docgen/src/Printer.ts, .changeset/*
Source-link labels are derived from the module path, and the changeset records the nested-directory fix.
Validate nested source links
packages/tools/docgen/test/Parser.test.ts
Test helpers support full source-file paths, and coverage verifies markdown links for nested/test.ts.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/tools/docgen/test/Parser.test.ts (1)

154-195: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Retain coverage for modules directly under srcDir.

This updated case exercises only src/nested/test.ts, so the unchanged src/test.ts link behavior is no longer asserted. Add a second case or parameterize the test for both direct and nested modules.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/docgen/test/Parser.test.ts` around lines 154 - 195, Extend the
source-link coverage in the test around Parser.parseModule and expectMarkdown to
also parse a module directly under project.srcDir, such as src/test.ts, and
assert its generated link uses the correct root-relative path. Preserve the
existing nested src/nested/test.ts assertion and expected link.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/tools/docgen/test/Parser.test.ts`:
- Around line 154-195: Extend the source-link coverage in the test around
Parser.parseModule and expectMarkdown to also parse a module directly under
project.srcDir, such as src/test.ts, and assert its generated link uses the
correct root-relative path. Preserve the existing nested src/nested/test.ts
assertion and expected link.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 212de654-d5c3-4bd0-b308-d604672bb196

📥 Commits

Reviewing files that changed from the base of the PR and between d48506d and 8d2d808.

📒 Files selected for processing (3)
  • .changeset/fix-docgen-nested-source-links.md
  • packages/tools/docgen/src/Printer.ts
  • packages/tools/docgen/test/Parser.test.ts

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.29 KB 6.29 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.89 KB 19.90 KB -0.02 KB (-0.08%)
differ.ts 19.06 KB 19.07 KB -0.02 KB (-0.10%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.45 KB 7.45 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.84 KB 18.86 KB -0.02 KB (-0.12%)
schema-fromJsonSchemaDocument.ts 28.75 KB 28.77 KB -0.01 KB (-0.04%)
schema-representation-roundtrip.ts 25.05 KB 25.07 KB -0.01 KB (-0.06%)
schema-string-transformation.ts 12.96 KB 12.96 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.62 KB 21.64 KB -0.02 KB (-0.09%)
schema-toCodeDocument.ts 24.07 KB 24.09 KB -0.01 KB (-0.06%)
schema-toCodecJson.ts 18.97 KB 18.99 KB -0.02 KB (-0.11%)
schema-toEquivalence.ts 18.69 KB 18.71 KB -0.02 KB (-0.10%)
schema-toFormatter.ts 18.56 KB 18.58 KB -0.02 KB (-0.10%)
schema-toJsonSchemaDocument.ts 22.19 KB 22.21 KB -0.02 KB (-0.09%)
schema-toRepresentation.ts 19.23 KB 19.25 KB -0.02 KB (-0.10%)
schema.ts 18.10 KB 18.12 KB -0.02 KB (-0.10%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants