-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Documentation inheritance issue with included extension modules
Problem Description
Functions defined in extension modules (like FoldableExtensions) lose their documentation when included in user-facing modules like List and Array. This creates a significant gap in the generated API documentation where core utility functions appear completely undocumented.
Concrete Example
The all function is defined in src/extensions/Relude_Extensions_Foldable.re with comprehensive documentation:
/**
Indicates if all items in the foldable satisfy the given predicate.
*/
let all: 'a. ('a => bool, F.t('a)) => bool =
(f, xs) => F.fold_left((v, x) => v && f(x), true, xs);However, when users access this via List.all or Array.all (through the include statement in *_Instances.re files), the generated HTML documentation shows the function signature but no documentation text.
Affected Functions
All functions from FoldableExtensions that users interact with through collection modules:
all,any- predicate checkingcontains,containsBy- membership testinglength,size,count- countingfind,findWithIndex- searchingforEach,forEachWithIndex- iterationmin,max,minBy,maxBy- extrematoList,toArray- conversions- Plus functions from other extension modules (MonoidExtensions, EqExtensions, etc.)
Estimated impact: ~20+ core utility functions per collection type appear undocumented.
How to Verify the Issue
- Build documentation:
make docs - Open
_build/default/_doc/_html/relude/Relude/List/index.html - Search for
id="val-all"- you'll find the function signature but no<div class="spec-doc">section - Compare with
_build/default/_doc/_html/relude/Relude/Extensions/Foldable/FoldableExtensions/index.htmlwhere the documentation is complete
Root Cause Analysis
This is a fundamental limitation of ReasonML/OCaml's module system:
- Module functors like
FoldableExtensions(F)define documentation at the functor level - Include statements (
include Relude_Extensions_Foldable.FoldableExtensions(Foldable)) copy function implementations but not odoc comments - Generated documentation only sees the final module signature, not the source of included functions
- IDE tooling and Context7-style documentation crawlers see functions without their original documentation
Impact on Context7 Integration
This directly affects issue #353's goal of Context7 integration because:
- Context7 crawls the generated documentation (HTML/markdown)
- Missing documentation means core utility functions appear as undocumented in AI/LLM contexts
- Users get incomplete API information when using Claude Code or similar tools
- Significantly reduces the value of Relude in AI-assisted development
Potential Solutions
Option 1: Manual Documentation Duplication
Approach: Copy documentation comments to each inclusion site
Pros: Guaranteed to work with current tooling
Cons: Maintenance burden, documentation drift risk, violates DRY principle
Option 2: Preprocessing Script Solution
Approach: Build-time script that copies documentation from extension modules to included locations
Pros: Automated, maintains single source of truth
Cons: Complex build process, needs custom tooling
Option 3: odoc Attribute Workarounds
Approach: Use [@@@ocaml.doc] attributes or similar odoc directives
Pros: Works within existing system
Cons: Limited effectiveness for included modules, still experimental
Option 4: Upstream Tooling Improvements
Approach: Contribute to odoc to support documentation inheritance
Pros: Benefits entire OCaml ecosystem
Cons: Long-term solution, no immediate fix
Recommended Approach for Context7
For the Context7 integration effort, I recommend Option 2 (preprocessing script) because:
- Immediate fix: Can be implemented as part of the documentation generation pipeline
- Automation: No ongoing maintenance burden once implemented
- Context7 compatibility: Generates properly documented HTML/markdown that Context7 can crawl
- Reversible: Can be removed if upstream solutions emerge
Implementation Plan
- Create
scripts/copy-extension-docs.jsthat:- Parses extension module
.refiles for documentation comments - Identifies where those functions are included in collection modules
- Copies documentation to a temporary location before odoc generation
- Parses extension module
- Integrate into documentation generation workflow (
make docs) - Test with Context7 submission to verify improved documentation quality
Success Criteria
- All ~20+ affected functions show proper documentation in generated HTML
- Context7 can successfully index comprehensive Relude API documentation
- Zero documentation gaps for core utility functions accessed through List/Array/etc.
- Automated solution requires no manual maintenance
This issue represents a significant barrier to AI/LLM accessibility of the Relude library and should be prioritized for the Context7 integration effort.