feat(dynamic-views): add unified branch foundations (types & parser)#2331
feat(dynamic-views): add unified branch foundations (types & parser)#2331Jrakru wants to merge 6 commits into
Conversation
## Rationale
Dynamic views currently support only anonymous parallel steps with limited
expressiveness. Users cannot:
- Name or describe different execution paths
- Model alternate/conditional flows (success vs error paths)
- Provide contextual information for different branches
- Support complex scenarios like retry logic or fallback paths
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)
- Add DynamicBranchCollection union type (parallel | alternate)
- Add DynamicBranchPath for named, described execution paths
- Add DynamicParallelBranch with legacy __parallel compatibility
- Add DynamicAlternateBranch for conditional flows
- Add type guards: isDynamicBranchCollection, isDynamicBranchPath
- Add toLegacyParallel() helper for backward compatibility
- Add feature flag system with dynamicBranchCollections (defaults: OFF)
### Grammar & Parser (packages/language-server)
- Extend Langium grammar with DynamicViewBranchCollection
- Support syntax: parallel/par/alternate/alt { path name { steps } }
- Parse anonymous steps into legacy __parallel format
- Emit unified branch nodes with metadata for future stages
- Update formatter to handle new branch syntax
### Tests
- Add type guard tests (packages/core/src/types/__tests__/dynamic-branch.spec.ts)
- Add parser tests for named paths, alternate branches, chained steps
- All existing tests pass (609 tests, backward compatible)
## Backward Compatibility
- Feature flag defaults to OFF (no behavior changes)
- Legacy anonymous parallel syntax continues to work
- Parser converts old syntax to new internal structures via __parallel
- toLegacyParallel() helper maintains compute compatibility
## Future Work
This unlocks:
- PR02: Compute traversal for branch collections
- PR03: Sequence diagram layout for branches
- PR04: Walkthrough UI with branch navigation
- PR05: UI polish for branch selection experience
## Technical Notes
- No changes to compute logic (deferred to PR02)
- No UI changes (deferred to PR04/PR05)
- Type-safe implementation (all TypeScript checks pass)
- Comprehensive test coverage for new types and parser logic
There was a problem hiding this comment.
Pull Request Overview
This PR establishes type system and parser foundations for a unified branch abstraction in dynamic views, enabling support for both parallel and alternate execution paths. The feature is gated behind a feature flag (defaulting to OFF) to ensure backward compatibility.
Key Changes:
- Introduced
DynamicBranchCollectionunion type supporting parallel and alternate branches with named paths - Extended Langium grammar to parse
parallel/alternatesyntax with path definitions - Added feature flag system to control unified branch behavior (defaults to OFF)
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/types/view-parsed.dynamic.ts | Added branch collection types, type guards, and legacy compatibility helpers |
| packages/core/src/types/tests/dynamic-branch.spec.ts | Added comprehensive tests for new type guards and helpers |
| packages/core/src/config/featureFlags.ts | Implemented feature flag system for dynamic branch collections |
| packages/core/src/index.ts | Exported feature flags module |
| packages/language-server/src/like-c4.langium | Extended grammar with branch collection and path syntax |
| packages/language-server/src/model/parser/ViewsParser.ts | Implemented parser for branch collections with legacy support |
| packages/language-server/src/model/tests/model-parser-dynamic-views.spec.ts | Added parser tests for named paths and alternate branches |
| packages/language-server/src/validation/index.ts | Updated validation to handle new AST node types |
| packages/language-server/src/formatting/LikeC4Formatter.ts | Updated formatter to support branch collection syntax |
| packages/language-server/src/tests/views-dynamic.spec.ts | Updated test expectations for valid nested parallel steps |
| packages/core/src/compute-view/dynamic-view/utils.ts | Extended flattenSteps to handle branch collections |
| packages/core/src/compute-view/dynamic-view/compute.ts | Updated compute logic to traverse branch collections |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| readonly label?: string | ||
| } | ||
|
|
There was a problem hiding this comment.
The label property is duplicated in both DynamicBranchCollectionBase (line 68) and DynamicAlternateBranch (line 82). Remove the duplicate declaration from DynamicAlternateBranch since it's already inherited from the base interface.
| readonly label?: string | |
| } | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jrakru <Jrakru@users.noreply.github.com>
- Remove duplicate 'label' property from DynamicAlternateBranch interface (already inherited from DynamicBranchCollectionBase) - Remove 'path' from metadata attribute keys to avoid keyword conflict with new branch path syntax Addresses Copilot review comments #1 and #4 from PR likec4#2331
Addressed Copilot Review CommentsI've pushed a commit that addresses the following review comments: ✅ Fixed: Comment #1 - Remove
|
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.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jrakru <Jrakru@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jrakru <Jrakru@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jrakru <Jrakru@users.noreply.github.com>
|
Closing this PR in favor of a cleaner resubmission. Issue: This PR had accumulated many unrelated commits from merging an outdated base branch, making review difficult. Solution: Created a clean PR with only the relevant changes:
The clean version is ready for review and will be submitted upstream once approved. Changes preserved:
|
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)
Grammar & Parser (packages/language-server)
Tests
Backward Compatibility
Future Work
This unlocks:
Technical Notes
Quality Gates