feat(dynamic-views): unified branch foundations (types & parser) - Clean PR#1
feat(dynamic-views): unified branch foundations (types & parser) - Clean PR#1Jrakru wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces the foundational types and parser for a unified branch abstraction in LikeC4 dynamic views, establishing the groundwork for supporting both parallel AND alternate execution paths. The implementation is feature-flagged (disabled by default) to ensure backward compatibility while enabling incremental delivery of the full branching experience.
Key changes:
- Unified branch type system with
DynamicBranchCollectionsupporting parallel/alternate paths - Parser extensions to handle named paths with backward compatibility for anonymous parallel syntax
- Feature flag infrastructure to control rollout
- Type guards and helper functions for branch operations
Reviewed Changes
Copilot reviewed 47 out of 47 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
packages/core/src/types/view-parsed.dynamic.ts |
Adds unified branch types (DynamicBranchCollection, DynamicBranchPath) with legacy compatibility |
packages/language-server/src/like-c4.langium |
Extends grammar to support branch collections and named paths |
packages/language-server/src/model/parser/ViewsParser.ts |
Implements parser for branch collections with legacy parallel conversion |
packages/core/src/config/featureFlags.ts |
Feature flag system for controlling branch collection behavior |
packages/core/src/compute-view/dynamic-view/compute.ts |
Updates compute traversal for branch collections while maintaining backward compatibility |
packages/core/src/types/__tests__/dynamic-branch.spec.ts |
Type guard and helper function tests |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Remove duplicate label property from DynamicAlternateBranch (Comment #4) - Remove path keyword from metadata grammar to avoid ambiguity (Comment #1) - Performance optimization deferred (Comment #2) - Code duplication addressed in PR likec4#2332 (Comment #3)
971041e to
1a6acd7
Compare
Introduces foundational types and grammar for parallel and alternate branch paths in dynamic views. New Types: - DynamicBranchCollection: Union of parallel/alternate branches - DynamicBranchPath: Named or anonymous execution paths - DynamicParallelBranch: Concurrent execution paths - DynamicAlternateBranch: Mutually exclusive paths Grammar Updates: - DynamicViewBranchCollection: parallel|par|alternate|alt keywords - DynamicViewBranchPath: Named paths with optional titles - Backward compatible via feature flag (defaults OFF) Changes: - Add feature flag system (LIKEC4_UNIFIED_BRANCHES) - Add type guards and helpers (isDynamicBranchCollection, toLegacyParallel) - Update compute logic to handle branch collections - Add test coverage for new types Breaking: None (feature flag defaults to false) Feature: Enables structured branch syntax for future PRs
1a6acd7 to
7ac8ddb
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Extract kind mapping to helper function for maintainability - Simplify nested ternary for __parallel assignment using if/else - Remove type casts by using proper type narrowing - Add documentation for feature flag dual env var support - Add JSDoc for toLegacyParallel function behavior - Improve isDynamicStep boolean logic clarity - Better handling of nested branch collections in compute/utils
✅ All Copilot Review Comments AddressedThanks for the thorough review! I've addressed all feedback in commit Fixed Issues:
Intentional Design Choices:
All 679 core tests and 609 language-server tests passing ✅ |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jrakru <Jrakru@users.noreply.github.com>
- Use direct property check ('paths' in step) instead of function call for better performance in isDynamicStep
- Extract parseValidSteps() helper to eliminate code duplication in parser
- Update parseDynamicBranchPath to use new helper function
|
Closing in favor of consolidated feature branch PR |
Create modular, testable components for parallel & alternate branches: ## New Modules ### Core Modules (packages/core/src/compute-view/dynamic-view/) 1. **types.ts** - Shared type definitions - BranchStackEntry, BranchCollectionAccumulator, ComputedStep - Centralized types for reuse across modules 2. **StepIdGenerator.ts** - Step ID generation logic (~80 LOC) - buildStepId() - Hierarchical IDs for nested branches - buildLegacyParallelStepId() - Legacy format support - Isolated, testable, single responsibility 3. **BranchStackManager.ts** - Branch state management (~220 LOC) - Stack operations: push(), pop(), getStack() - Edge registration: registerStep() - Trail building: buildTrail() - Finalization: finalize() -> ComputedBranchCollection[] - Encapsulates all branch tracking logic 4. **StepVisitor.ts** - Visitor pattern for step flattening (~140 LOC) - StepFlattener class with visit methods - Handles: single steps, series, branches, legacy parallel - Type-safe traversal, reusable for other operations ## Validation Fixes (3 Critical Edge Cases) ### packages/language-server/src/validation/dynamic-view.ts **Edge Case #1: Empty Path Validation** (10 LOC) - Error if path has zero steps - Code: LIKEC4-EMPTY-PATH - Prevents: Data integrity issues, rendering crashes **Edge Case #2: Nesting Depth Validation** (40 LOC) - calculateBranchDepth() - Recursive depth calculation - Warning at 4+ levels (LIKEC4-DEEP-NESTING) - Error at 6+ levels (LIKEC4-MAX-DEPTH) - Prevents: Unwieldy step IDs, rendering issues **Edge Case #3: Mixed Path Style Hint** (10 LOC) - Hint when mixing named paths + anonymous steps - Code: LIKEC4-MIXED-PATH-STYLE - Improves: Code consistency, readability ## Benefits - **Testability**: Each module <250 LOC, easy to unit test - **Maintainability**: Clear separation of concerns - **Extensibility**: Easy to add new step types (loop, break) - **Readability**: Self-documenting with comprehensive JSDoc ## Next Steps - Update utils.ts to use new StepVisitor - Refactor compute.ts to use StepIdGenerator & BranchStackManager - Add test cases for new modules - Add tests for validation edge cases References: EDGE_CASE_ANALYSIS.md, EDGE_CASES_WALKTHROUGH.md
Rationale
Dynamic views currently support only anonymous parallel steps with limited expressiveness. Users cannot:
This PR establishes the type system and parser foundations for a unified branch abstraction that will eventually support both parallel AND alternate execution paths in dynamic views, enabling richer scenario modeling.
What This Changes
Type System (packages/core)
DynamicBranchCollectionunion type (parallel | alternate)DynamicBranchPathfor named, described execution pathsDynamicParallelBranchwith legacy__parallelcompatibilityDynamicAlternateBranchfor conditional flowsisDynamicBranchCollection,isDynamicBranchPathtoLegacyParallel()helper for backward compatibilitydynamicBranchCollections(defaults: OFF)Grammar & Parser (packages/language-server)
DynamicViewBranchCollectionparallel/par/alternate/alt{ path name { steps } }__parallelformatTests
packages/core/src/types/__tests__/dynamic-branch.spec.ts)Fixes Applied
This PR addresses potential review concerns:
✅ Removed
pathfrom metadata keys - Reservespathkeyword exclusively for branch path syntax, preventing parsing ambiguity✅ Removed duplicate
labelproperty -DynamicAlternateBranchnow properly inheritslabelfromDynamicBranchCollectionBaseBackward Compatibility
__paralleltoLegacyParallel()helper maintains compute compatibilityFuture Work
This unlocks:
Technical Notes
Quality Gates
Note: This is a clean resubmission of the unified branch foundations feature. Once this passes review in our fork, we'll submit it upstream to likec4/likec4.