Skip to content

feat(language-server): clear diagnostic for nested parallel blocks#2985

Merged
davydkov merged 1 commit into
likec4:mainfrom
farhan523:feat/lsp-nested-parallel-diagnostic
Jun 2, 2026
Merged

feat(language-server): clear diagnostic for nested parallel blocks#2985
davydkov merged 1 commit into
likec4:mainfrom
farhan523:feat/lsp-nested-parallel-diagnostic

Conversation

@farhan523

Copy link
Copy Markdown
Collaborator

Checklist

  • I've thoroughly read the latest contribution guidelines.
  • I've rebased my branch onto main before creating this PR.
  • I've added tests to cover my changes (if applicable).
  • I've verified pnpm typecheck and pnpm test.
  • I've added changesets.
  • My change requires documentation updates. (no — internal grammar/validator change, no public DSL semantics shift)
  • I've updated the documentation accordingly. (N/A)

Summary

Resolves #988 (originally from @susliko in discussion #816).

Today parallel { parallel { ... } } in a dynamic view produces a cryptic parser error like Expecting token of type --> RightCurly <-- but found --> 'parallel' <--. The grammar simply forbids the nested form structurally, so users get the raw parser error.

This PR:

  1. Loosens the grammar so a DynamicViewParallelSteps can appear as a step inside another DynamicViewParallelSteps. The parser accepts the form now, instead of rejecting it.
  2. Adds a dynamicViewParallelSteps validator that walks steps and emits a clear error — Nested parallel blocks are not allowed — on any nested DynamicViewParallelSteps. The diagnostic is attached to the inner block so the squiggle lines up with the offending parallel/par keyword.

Net behaviour: same outcome (the model is rejected), much better message.

Files

  • Grammarlike-c4.langium: (steps+=(DynamicViewParallelSteps | DynamicViewStep))*.
  • Validatorvalidation/dynamic-view.ts: new dynamicViewParallelSteps check.
  • Registrationvalidation/index.ts: wired under the DynamicViewParallelSteps key.
  • Parsermodel/parser/ViewsParser.ts: parseDynamicParallelSteps now filters out nested ParallelSteps before calling parseDynamicStep (the validator has already errored on them; this keeps the c4-model side narrow and avoids a confusing internal type error).

Test plan

New tests in dynamic-view.spec.ts:

  • A single, non-nested parallel block — no errors.
  • parallel { parallel { ... } } — reports Nested parallel blocks are not allowed.
  • par { par { ... } } (the par alias) — same diagnostic.

Local: pnpm test packages/language-server/src/validation/dynamic-view.spec.ts → 12/12 passing, pnpm --filter @likec4/language-server typecheck → clean, pnpm lint:errors-only → 0 errors.

Generated parser artifacts (packages/language-server/src/generated/) are git-ignored, so CI's pnpm generate step will produce the updated parser from the new grammar.

Nested `parallel { parallel { ... } }` in dynamic views previously`produced a cryptic parser error because the grammar rejected the form`outright. The grammar now accepts `DynamicViewParallelSteps` as a step`inside another `DynamicViewParallelSteps`, and a new validator emits`a clear `Nested parallel blocks are not allowed` error on the inner`block.

`ViewsParser` filters nested ParallelSteps when building the c4 model`(the validator already errors on them) to keep the parser side narrow.

Resolves likec4#988
@changeset-bot

changeset-bot Bot commented May 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e98fbe1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@likec4/language-server Patch
@likec4/playground Patch
@likec4/language-services Patch
likec4 Patch
@likec4/lsp Patch
@likec4/mcp Patch
likec4-vscode Patch
@likec4/vite-plugin Patch
@likec4/spa Patch
@likec4/docs-astro Patch
@likec4/style-preset Patch
@likec4/styles Patch
@likec4/config Patch
@likec4/core Patch
@likec4/diagram Patch
@likec4/generators Patch
@likec4/layouts Patch
@likec4/leanix-bridge Patch
@likec4/log Patch
@likec4/react Patch
@likec4/tsconfig Patch
@likec4/vscode-preview Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 544f9654-0131-461f-97c5-9a04e00ea548

📥 Commits

Reviewing files that changed from the base of the PR and between c18fa00 and e98fbe1.

📒 Files selected for processing (6)
  • .changeset/lsp-nested-parallel-diagnostic.md
  • packages/language-server/src/like-c4.langium
  • packages/language-server/src/model/parser/ViewsParser.ts
  • packages/language-server/src/validation/dynamic-view.spec.ts
  • packages/language-server/src/validation/dynamic-view.ts
  • packages/language-server/src/validation/index.ts

📝 Walkthrough

Walkthrough

This PR improves error reporting for nested parallel blocks in LikeC4 dynamic views by loosening the grammar to allow parsing nested structures, adding a validation check that detects and reports them as errors, and adjusting the parser to filter them before processing.

Changes

Nested Parallel Block Detection

Layer / File(s) Summary
Grammar and validation infrastructure
packages/language-server/src/like-c4.langium, packages/language-server/src/validation/dynamic-view.ts, packages/language-server/src/validation/index.ts
DynamicViewParallelSteps grammar rule is updated to parse nested parallel blocks alongside steps. New validation check dynamicViewParallelSteps detects and reports nested blocks as errors. Validation check is registered in the core registry.
Parser filtering of nested blocks
packages/language-server/src/model/parser/ViewsParser.ts
parseDynamicParallelSteps filters out nested DynamicViewParallelSteps blocks before mapping steps, preventing internal parsing errors for structures already flagged by validation.
Tests and documentation
packages/language-server/src/validation/dynamic-view.spec.ts, .changeset/lsp-nested-parallel-diagnostic.md
Test suite covers acceptance of non-nested parallel blocks, rejection of nested blocks with the diagnostic "Nested parallel blocks are not allowed", and rejection via the par alias. Changeset documents the patch release.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a clear diagnostic message for nested parallel blocks in the language server.
Description check ✅ Passed The description is comprehensive and complete, covering all checklist items, explaining the problem and solution clearly, detailing file changes, and documenting test coverage and verification steps.
Linked Issues check ✅ Passed The PR fully addresses issue #988 by implementing the requested feature: providing a clear diagnostic for nested parallel blocks instead of cryptic parser errors.
Out of Scope Changes check ✅ Passed All changes are directly related to resolving issue #988: grammar loosening, validator implementation, parser filtering, test coverage, and validation registration are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@davydkov davydkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thank you!

@davydkov davydkov enabled auto-merge (squash) June 2, 2026 20:39
@davydkov davydkov merged commit e2ad89e into likec4:main Jun 2, 2026
14 checks passed
@likec4-ci likec4-ci Bot mentioned this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve error-reporting capabilities for parallel steps

2 participants