Skip to content

Add embedded language syntax highlighting support - #1180

Open
angelozerr wants to merge 1 commit into
redhat-developer:mainfrom
angelozerr:tm4e-semantic-tokens-support
Open

angelozerr wants to merge 1 commit into
redhat-developer:mainfrom
angelozerr:tm4e-semantic-tokens-support

Conversation

@angelozerr

@angelozerr angelozerr commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This PR requires eclipse-lemminx/lemminx#1881

Add xml.embeddedLanguages setting and TextMate grammar resolution for embedded language syntax highlighting in XML files.

  • Add xml.embeddedLanguages setting with DocumentMatcher + expressions
  • Add xml.textMateGrammar command to resolve grammar paths from installed VS Code extensions (e.g., built-in Groovy, Java, SQL)
  • Add settings enrichment to inject grammarPath before sending to lemminx
  • Expressions use xpath + languageId; grammarPath resolved automatically
  • Add documentation for embedded languages and semantic tokens features

Add xml.embeddedLanguages setting and TextMate grammar resolution for
embedded language syntax highlighting in XML files.

- Add xml.embeddedLanguages setting with DocumentMatcher + expressions
- Add xml.textMateGrammar command to resolve grammar paths from
  installed VS Code extensions (e.g., built-in Groovy, Java, SQL)
- Add settings enrichment to inject grammarPath before sending to
lemminx
- Expressions use xpath + languageId; grammarPath resolved automatically
- Add documentation for embedded languages and semantic tokens features

Signed-off-by: azerr <azerr@redhat.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f742282-b6b9-4fbe-ba99-74d57a017256
📥 Commits

Reviewing files that changed from the base of the PR and between 028e8a9 and 99a5049.

📒 Files selected for processing: 7
  • docs/Features.md
  • docs/Features/XMLEmbeddedLanguagesFeatures.md
  • docs/Features/XMLFeatures.md
  • gulpfile.js
  • package.json
  • src/commands/clientCommandConstants.ts
  • src/commands/registerCommands.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Added configurable highlighting for embedded languages in XML text and CDATA, using XPath rules to select content and grammars from installed VS Code extensions.
    • Added support for document-matching criteria and optional grammar paths when a language’s grammar is not available through an extension.
  • Documentation
    • Added examples for highlighting Groovy, SQL, JavaScript, and CSS in XML documents.
    • Expanded XML highlighting guidance and added the embedded-language features page to the feature index.

The pull request adds an xml.embeddedLanguages setting and a client command that resolves TextMate grammars from installed extensions. It documents the setting and XML highlighting examples. Both server build tasks now source the JAR from the uber module.

Changes: XML Embedded Languages

Layer / File(s) Summary
Embedded-language configuration and grammar lookup
package.json, src/commands/clientCommandConstants.ts, src/commands/registerCommands.ts
The setting schema defines document-matching criteria and XPath-language rules. The registered client command searches installed extensions for a grammar matching the requested language ID and returns its resolved path and scope name, or null.
Embedded-language examples and highlighting details
docs/Features.md, docs/Features/XMLEmbeddedLanguagesFeatures.md, docs/Features/XMLFeatures.md
The feature index links to documentation with configuration examples, document-matcher properties, grammar resolution details, and semantic-token scope mappings.

Server Build JAR Source

Layer / File(s) Summary
Server build JAR source
gulpfile.js
Both server build tasks source the JAR from the uber module. The native build task retains its binary glob.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: datho7561

Merge Risk: ⚪ Minimal · up to 99a50

The XHTML highlighting example works with the server’s XPath matching behavior. No actionable merge-blocking issue is established.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (4 skipped: 4 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the main change: support for embedded-language syntax highlighting in XML files.
Description check Passed The description directly covers the new setting, grammar-resolution command, configuration enrichment, expressions, and documentation changes.

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

@MeherSru

MeherSru commented Oct 16, 2026 •

Copy link
Copy Markdown

Hi Angelo, a few small things about the doc:

@angelozerr

Copy link
Copy Markdown
Contributor Author

Thanks @MeherSru

To be honest with you, it is just a POC.

Thanks for your feedback, I need to check your feedback.

@datho7561

Copy link
Copy Markdown
Contributor

Tried it out with a fake xhtml document. I used this for my settings:

  "xml.embeddedLanguages": [
    {
      "pattern": "**/*.xml",
      "expressions": [
        {
          "languageId": "javascript",
          "xpath": "/html/script/text()"
        }
      ]
    }
  ]

I get the highlighting, but noticed that the colours are different from a standard JavaScript file. I think this is because semantic token colours are highlighted differently than their regular TextMate scope counterparts. I don't think there's much we can do about this, since we can only set the token type and don't have control over what the theme chooses to colour those tokens.

image

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants