Skip to content

fix(language-server): allow group metadata key#2948

Merged
davydkov merged 1 commit into
mainfrom
cgk/fix-2932-metadata-group
May 18, 2026
Merged

fix(language-server): allow group metadata key#2948
davydkov merged 1 commit into
mainfrom
cgk/fix-2932-metadata-group

Conversation

@ckeller42

Copy link
Copy Markdown
Collaborator

Fixes #2932

Summary:

  • allow metadata keys to use the existing LikeC4 Id rule
  • add regression coverage for metadata.group

Checks:

  • pnpm generate
  • vitest run --no-isolate packages/language-server/src/model/__tests__/model-builder.spec.ts -t "group metadata key"
  • vitest run --no-isolate packages/language-server/src
  • pnpm --filter @likec4/language-server run typecheck
  • pnpm --filter @likec4/language-server run lint

@changeset-bot

changeset-bot Bot commented May 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 18c6ac5

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/vite-plugin Patch
likec4-vscode 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

@ckeller42

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 11, 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: cfbd97bb-d3d3-427e-aed1-c467d2f05b57

📥 Commits

Reviewing files that changed from the base of the PR and between 2f60bfa and 18c6ac5.

📒 Files selected for processing (3)
  • .changeset/fix-metadata-group-key.md
  • packages/language-server/src/like-c4.langium
  • packages/language-server/src/model/__tests__/model-builder.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-metadata-group-key.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/language-server/src/like-c4.langium
  • packages/language-server/src/model/tests/model-builder.spec.ts

📝 Walkthrough

Walkthrough

This PR fixes issue #2932 by updating the Langium grammar to accept reserved keywords like group as metadata attribute keys (switching key=IdTerminal to key=Id). A new test verifies model building preserves group and _group metadata keys, and a changeset documents the patch release.

Changes

Allow Reserved Keywords as Metadata Keys

Layer / File(s) Summary
Grammar Rule Update
packages/language-server/src/like-c4.langium
MetadataAttribute rule changes key=IdTerminal to key=Id, allowing reserved keywords such as group to be parsed as valid metadata keys.
License Header
packages/language-server/src/like-c4.langium
SPDX-License-Identifier and copyright header are added to the grammar file.
Test Validation
packages/language-server/src/model/__tests__/model-builder.spec.ts
New test case verifies metadata with group, _group, team, and other keys is preserved during model building and correctly filtered by where metadata.group is 'group name' query.
Release Documentation
.changeset/fix-metadata-group-key.md
Changeset entry documents patch release for @likec4/language-server fixing issue #2932.

Sequence Diagram(s)

sequenceDiagram
  participant Parser
  participant ModelBuilder
  participant ViewFilter
  Parser->>ModelBuilder: parse element with metadata keys (team, _group, group, other)
  ModelBuilder->>ModelBuilder: build model preserving all metadata keys
  ViewFilter->>ModelBuilder: query where metadata.group is 'group name'
  ModelBuilder->>ViewFilter: return matching element(s)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • likec4/likec4#2845: Updates identifier token regex in the same grammar file to allow underscore+digit prefixes, complementary to this PR's reserved keyword handling.

Suggested reviewers

  • davydkov
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly identifies the main fix: allowing 'group' to be used as a metadata key, which directly addresses the primary objective.
Description check ✅ Passed The PR description is mostly complete with a clear summary, issue reference, and comprehensive verification checks listed. However, it does not explicitly check all checklist items from the template.
Linked Issues check ✅ Passed The PR changes fully address issue #2932 by modifying the grammar rule to allow 'group' as a metadata key and adding regression test coverage for the metadata.group scenario.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the metadata key parsing issue: grammar rule update, changeset entry, and test coverage. No out-of-scope changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cgk/fix-2932-metadata-group

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/language-server/src/model/__tests__/model-builder.spec.ts (1)

246-266: ⚡ Quick win

Assert the where metadata.group filter outcome explicitly.

Right now this test proves parse/build success, but it doesn’t verify that the view predicate actually filters as intended. Add a view assertion so the regression catches semantic breaks too.

Proposed test assertion
     const model = await buildModel()
     expect(model).toBeDefined()
     expect(model.elements).toMatchObject({
       test: {
         kind: 'system',
         metadata: {
           team: 'team name',
           _group: '_group name',
           group: 'group name',
           other: 'other name',
         },
       },
     })
+    expect(model.views).toHaveProperty('index')
+    expect(model.views['index' as ViewId]!.nodes.map(n => n.id)).toContain('test')

As per coding guidelines: “Aim to cover new features with relevant tests; keep test names descriptive”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/language-server/src/model/__tests__/model-builder.spec.ts` around
lines 246 - 266, The test currently builds the model with a view filter but
doesn't assert the view's actual contents; add an assertion after buildModel()
that checks the view named "index" (from the "views { view index { include *
where metadata.group is 'group name' } }" snippet) yields only the expected
element(s) — e.g. confirm model.views['index'] (or model.views.index) contains
the "test" element and excludes others — so the predicate is validated; use
buildModel(), model.elements and the view identifier "index" to locate where to
insert the new expectation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/language-server/src/model/__tests__/model-builder.spec.ts`:
- Around line 246-266: The test currently builds the model with a view filter
but doesn't assert the view's actual contents; add an assertion after
buildModel() that checks the view named "index" (from the "views { view index {
include * where metadata.group is 'group name' } }" snippet) yields only the
expected element(s) — e.g. confirm model.views['index'] (or model.views.index)
contains the "test" element and excludes others — so the predicate is validated;
use buildModel(), model.elements and the view identifier "index" to locate where
to insert the new expectation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 30ce3262-214e-415b-bdb7-c7ff6d31845a

📥 Commits

Reviewing files that changed from the base of the PR and between 87aabdb and 2f60bfa.

📒 Files selected for processing (3)
  • .changeset/fix-metadata-group-key.md
  • packages/language-server/src/like-c4.langium
  • packages/language-server/src/model/__tests__/model-builder.spec.ts

@ckeller42 ckeller42 marked this pull request as ready for review May 11, 2026 09:14
@ckeller42 ckeller42 requested a review from davydkov May 11, 2026 09:14
@ckeller42 ckeller42 force-pushed the cgk/fix-2932-metadata-group branch from 2f60bfa to 18c6ac5 Compare May 11, 2026 09:21
Comment thread packages/language-server/src/model/__tests__/model-builder.spec.ts
@davydkov davydkov merged commit 9637876 into main May 18, 2026
18 checks passed
@davydkov davydkov deleted the cgk/fix-2932-metadata-group branch May 18, 2026 07:08
@likec4-ci likec4-ci Bot mentioned this pull request May 18, 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.

Element metadata with key group breaks parser

3 participants