Skip to content

Documentation inheritance issue with included extension modules #355

@johnhaley81

Description

@johnhaley81

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 checking
  • contains, containsBy - membership testing
  • length, size, count - counting
  • find, findWithIndex - searching
  • forEach, forEachWithIndex - iteration
  • min, max, minBy, maxBy - extrema
  • toList, 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

  1. Build documentation: make docs
  2. Open _build/default/_doc/_html/relude/Relude/List/index.html
  3. Search for id="val-all" - you'll find the function signature but no <div class="spec-doc"> section
  4. Compare with _build/default/_doc/_html/relude/Relude/Extensions/Foldable/FoldableExtensions/index.html where the documentation is complete

Root Cause Analysis

This is a fundamental limitation of ReasonML/OCaml's module system:

  1. Module functors like FoldableExtensions(F) define documentation at the functor level
  2. Include statements (include Relude_Extensions_Foldable.FoldableExtensions(Foldable)) copy function implementations but not odoc comments
  3. Generated documentation only sees the final module signature, not the source of included functions
  4. 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:

  1. Immediate fix: Can be implemented as part of the documentation generation pipeline
  2. Automation: No ongoing maintenance burden once implemented
  3. Context7 compatibility: Generates properly documented HTML/markdown that Context7 can crawl
  4. Reversible: Can be removed if upstream solutions emerge

Implementation Plan

  1. Create scripts/copy-extension-docs.js that:
    • Parses extension module .re files for documentation comments
    • Identifies where those functions are included in collection modules
    • Copies documentation to a temporary location before odoc generation
  2. Integrate into documentation generation workflow (make docs)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions