feat(dynamic-views): unified branch foundations (types & parser)#2333
Closed
Jrakru wants to merge 4 commits into
Closed
feat(dynamic-views): unified branch foundations (types & parser)#2333Jrakru wants to merge 4 commits into
Jrakru wants to merge 4 commits into
Conversation
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
- 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
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR establishes the foundational type system and parser for a unified branch abstraction in dynamic views, enabling support for both parallel and alternate execution paths while maintaining backward compatibility with the existing anonymous parallel syntax.
Key Changes:
- Added
DynamicBranchCollectionunion type system with support forparallelandalternatebranch kinds - Extended Langium grammar to parse named branch paths with
parallel/par/alternate/altsyntax - Introduced feature flag system (
dynamicBranchCollections) that defaults to OFF, ensuring no behavioral changes
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/types/view-parsed.dynamic.ts | Defines new branch collection types, type guards, and legacy compatibility helpers |
| packages/core/src/types/tests/dynamic-branch.spec.ts | Adds comprehensive test coverage for new type guards and helper functions |
| packages/core/src/config/featureFlags.ts | Implements feature flag system for controlled rollout of branch collections |
| packages/core/src/index.ts | Exports feature flag configuration |
| packages/language-server/src/like-c4.langium | Extends grammar with branch collection and branch path syntax |
| packages/language-server/src/model/parser/ViewsParser.ts | Implements parser logic to convert AST to new branch collection types with legacy fallback |
| packages/language-server/src/model/tests/model-parser-dynamic-views.spec.ts | Adds parser tests for named paths and alternate branches |
| packages/language-server/src/validation/index.ts | Updates validation to recognize new AST node types |
| packages/language-server/src/formatting/LikeC4Formatter.ts | Updates formatter to handle branch collection nodes |
| packages/language-server/src/tests/views-dynamic.spec.ts | Updates test expectations for nested parallel validation |
| packages/core/src/compute-view/dynamic-view/utils.ts | Updates flattenSteps to handle new branch collection structures |
| packages/core/src/compute-view/dynamic-view/compute.ts | Extends compute logic to traverse branch collections while maintaining legacy parallel support |
💡 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)Code Quality
This PR has been reviewed by GitHub Copilot and addresses all actionable feedback:
✅ Refactoring Applied:
getBranchKind()helper function for maintainabilitytoLegacyParallel()functionisDynamicStep()boolean logic clarityBackward Compatibility
__paralleltoLegacyParallel()helper maintains compute compatibilityFuture Work
This unlocks:
Technical Notes
Quality Gates
Related: This is the foundational PR for the unified branch system outlined in #2282. This PR focuses on types and parser only, with subsequent PRs handling compute, layout, and UI.