Skip to content

refactor(ui): one Velocity grammar for every Monaco editor (#37965) - #37969

Open
fmontes wants to merge 1 commit into
mainfrom
issue-37965-shared-velocity-grammar
Open

fmontes wants to merge 1 commit into
mainfrom
issue-37965-shared-velocity-grammar

Conversation

@fmontes

@fmontes fmontes commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Proposed Changes

  • One Velocity grammar for every Monaco editor, in @dotcms/ui (ui/src/lib/monaco/velocity-language.ts). The Velocity Playground, the content editor's code fields and its file editor all register it with ensureDotVelocityLanguageRegistered().
  • It merges the two grammars that existed: the content editor's, which knew HTML (tags, attributes, <script> and <style>), and the playground's, which coloured strings, numbers, operators and method calls.
  • Velocity is coloured in text, inside tags and inside attribute values. Strings, numbers and operators are coloured only inside Velocity expressions (directive and method arguments), so an apostrophe in prose no longer starts a string. Multi-line #* *# comments are coloured too.
  • Same language id: it keeps velocity, the id the content editor already stores and detects. The playground's id changes from velocity-playground to velocity.
  • edit-content's own grammar (custom-languages/) is removed. Its HTML rules move to ui/src/lib/monaco/velocity-html-tokenizer.ts.
  • The shared monacoMock gains getLanguages, which real Monaco has.

Checklist

  • Tests
  • Translations (none needed)
  • Security Implications Contemplated (highlighting only; no data or requests change)

Additional Info

  • First of three stacked PRs for Ease edit code #37965 (Edit Source). Next: refactor(edit-content): share side-panel behaviour across panels (#37965) #37970.
  • A spec checks that every state the grammar moves to exists, since Monaco only reports a missing state when it reaches it at runtime.
  • Checked in the browser with monaco.editor.tokenize on a sample template: comments, Velocity inside tags and attribute values, expressions, ${…} references and #dotParse paths are coloured; apostrophes in prose, $5 and #hashtag stay plain text.

Refs #37965

🤖 Generated with Claude Code

The Velocity Playground's grammar moves to @dotcms/ui and merges with the content editor's HTML-aware one, so the playground, the content editor's code fields and its file editor highlight Velocity the same way. Velocity is coloured in text, tags and attribute values; strings, numbers and operators only inside Velocity expressions, so an apostrophe in prose no longer starts a string. Multi-line #* *# comments are coloured too.

The language keeps the velocity id the content editor already stores, and edit-content's own grammar is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fmontes
fmontes added this pull request to stack #37971 October 9, 2026 16:59
@github-actions github-actions Bot mentioned this pull request Oct 9, 2026
3 tasks
@github-actions github-actions Bot added the Area : Frontend PR changes Angular/TypeScript frontend code label Oct 9, 2026
@claude

claude Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @fmontes's task in 2m 12s —— View job


Claude's Review — one Velocity grammar for every Monaco editor

  • Read the PR diff against origin/main
  • Trace the new shared grammar and its consumers
  • Verify no leftover references to the deleted modules
  • Check test coverage and spec updates
  • Post review

This is a clean consolidation: three divergent Velocity grammars (edit-content's velocity-monaco-language.ts, the playground's register-velocity.ts, and the inline registrations in two components) collapse into one shared @dotcms/ui grammar registered through ensureDotVelocityLanguageRegistered(). I verified the wiring holds up:

  • No dangling references — velocity-monaco-language, register-velocity, ensureVelocityLanguageRegistered, VELOCITY_LANGUAGE_ID, and dotVelocityLanguageDefinition are gone everywhere (grep across libs returns none).
  • The language id stays 'velocity' (DOT_VELOCITY_LANGUAGE_ID), which matches AvailableLanguageMonaco.Velocity = 'velocity' in dot-edit-content-field.constant.ts:47, so the content editor's stored/detected languages keep resolving to the registered grammar.
  • Removed imports (AvailableLanguageMonaco, the old grammar) are no longer referenced in the files they were removed from; AvailableLanguageMonaco is still correctly imported where it's still used.
  • monaco-editor.mock.ts gains getLanguages: () => [], which is what the new registration path needs, and the two edit-content specs were updated to match (the file-editor spec dropped its now-redundant local getLanguages shim).
  • Good new test coverage in velocity-language.spec.ts, including the getLanguages-based idempotency check and the state-reference integrity test that catches a typo'd @state name — a real risk with Monarch grammars.

New Issues

  • 🟡 Medium: core-web/libs/portlets/dot-velocity-playground/src/lib/dot-velocity-playground-page/dot-velocity-playground-page.component.ts:105 — The playground switches from its own velocity-playground grammar to the shared velocity grammar. The old playground grammar colored strings/numbers/operators anywhere at the top level; the shared grammar only colors those inside a Velocity expression context (directive args, [...] index, {...} map) — in plain template text a bare "string", number, or operator now falls through as uncolored text. The shared grammar is intentionally richer (full HTML + embedded JS/CSS), and bare literals in a VTL template are arguably output text that shouldn't be colored, so this may be the desired result.
    Assumption: this highlighting change in the playground is intended as part of the unification.
    What to verify: open a representative template in the Velocity Playground and confirm the highlighting is acceptable (the PR body's "Updated" screenshot slot is still a placeholder — a before/after there would settle this). Fix this →

No blocking issues found — the Medium above is a behavior check, not a defect. The console.warn("Monaco is not available globally") that DotEditContentMonacoEditorControlComponent.registerVelocityLanguage used to emit is now silently swallowed by the early return in ensureDotVelocityLanguageRegistered; that's a reasonable trade since the function is deliberately called repeatedly and before Monaco loads.
· branch issue-37965-shared-velocity-grammar

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant