-
Notifications
You must be signed in to change notification settings - Fork 32
Navigation Refactor: Generic Type System, O(1) Re-homing, and improved assembly routines #1995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Introduced draft documentation for all CLI commands under `docs/cli`. - Updated `_docset.yml` to include new CLI documentation. - Adjusted navigation order and reinstated missing migration files.
Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>
… url is dynamic based on parent toc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! Lots of changes. I guess this will enable interesting things in the future, like unified nav menus or accessing nav metadata for other features without having to reconstruct it from other bits.
My only pressing question: Does this break any existing nav definition, including crosslinks?
it doesn't now :) @theletterf |
This PR fundamentally rewrites the navigation system to solve long-standing maintainability issues and enable future extensibility.
The Problem
The original navigation implementation had four critical issues:
INavigationItem<INavigationModel, INavigationItem>, forcing runtime type checks and casts throughout the codebase to access model-specific propertiesMarkdownFileitself, creating tight coupling between navigation logic and a single model implementation tied to HTML renderingThese issues blocked API documentation integration, made the assembler process opaque, and created a brittle system where navigation concerns leaked into model classes.
The Solution
1. Generic Type System with Covariance
Before:
After:
Made all navigation classes generic over
TModel where TModel : IDocumentationFile. Enables:2. Navigation as Single Source of Truth
Before: URLs, paths, and navigation properties duplicated on
MarkdownFile:After: Navigation owns all navigational concerns:
Why this matters:
3. Dedicated Navigation Assembly
Created
Elastic.Documentation.Navigationas standalone assembly:IDocumentationFileimplementation4. Two-Phase Loading (Configuration → Navigation)
Phase 1: Configuration resolution - Parse YAML, resolve paths, validate files
Phase 2: Navigation construction - Build tree, calculate URLs, set relationships
Why this matters:
5. Home Provider Architecture: O(1) Re-homing
The assembler must combine repositories with custom URL prefixes. Naive approach requires O(n) tree traversal.
Our solution: Provider pattern with indirection.
Time complexity: O(1) - Single reference assignment, regardless of subtree size. URLs lazy-calculated on-demand from provider. This is what makes the assembler practical at scale.
What Changed
Core Navigation (
src/Elastic.Documentation.Navigation/)DocumentationSetNavigation<TModel>Configuration (
src/Elastic.Documentation.Configuration/)Assembler (
src/Elastic.Documentation.Assembler/)AssemblerBuildflag controls scope creationModels (Breaking Change)
Documentation (
docs/development/navigation/)10 comprehensive documents with progressive learning path:
Why This Was Necessary
Enabling Future Work
This refactor was extensive because we needed to:
What This Enables
ApiDocFilemodelBackward Compatibility
All 111 tests pass. Breaking change: Models no longer have navigation properties - access through navigation tree instead.
Testing