Skip to content

Improve CMake syntax highlighting: extend variable recognition with compiler/toolchain families and add scoped property command colorization - #4527

Merged
Hannia Valera (hanniavalera) merged 3 commits into
microsoft:mainfrom
pboettch:syntax-highlighting-textmate-proposal
Apr 8, 2026
Merged

Hannia Valera (hanniavalera) merged 3 commits into
microsoft:mainfrom
pboettch:syntax-highlighting-textmate-proposal

Conversation

@pboettch

@pboettch Patrick Boettcher (pboettch) commented Jul 29, 2025 •

Copy link
Copy Markdown
Contributor

I upgraded my grammar-generation script I use to generate the vim-syntax-highlighting-rules to put out a TextMate-grammer.

The script can be found here: https://github.com/pboettch/vim-cmake-syntax/tree/textmate-grammer-generation

This change might address item #4508

This changes visible behavior

The following changes are proposed:

  • Improved syntax highlighting grammar
  • Fine grained keyword/command
  • Builtin-variables vs user-variables
  • Properties only in property-commands

Other Notes/Information

This is a proposal for discussion. I learnt TextMate-grammar just recently and I'm relatively new to vsCode. There is
a lot of space for improvements. Modules are not at all handled, as an example.

Here is a screenshot of a CMake-Files using the Monokai Dimmed-theme

image image

Final Version Description:
This pull request improves the CMake syntax highlighting in the extension by extending variable recognition and adding better colorization for property commands and their arguments. The changes update the grammar to recognize more CMake variables, especially those related to compiler and toolchain families, and introduce scoped highlighting for commands like set_property, get_property, and related property commands. Test coverage is expanded to ensure these new highlighting features work as expected.

Syntax highlighting improvements:

  • Extended the list of recognized CMake variables in knownVariables to include compiler/toolchain family variables and other recently added CMake variables, improving detection and highlighting in the editor.
  • Improved variable reference matching to allow for nested and more complex variable names, and delegated recognition to the expanded knownVariables rule.

Property command highlighting:

  • Added a new scopedPropertyCommand grammar rule to highlight property-related commands (set_property, get_property, etc.), their scope keywords (like GLOBAL, TARGET), and well-known property names with distinct colors. [1] [2]

Test coverage:

  • Expanded the syntax test file test/visual-syntax-test/CMakeLists.txt with a comprehensive set of examples covering the new variable recognition and property command highlighting, ensuring the changes are tested and validated.

Documentation:

  • Updated the CHANGELOG.md to document the improved CMake syntax highlighting and the extension of variable and property command recognition.
@pboettch
Patrick Boettcher (pboettch) force-pushed the syntax-highlighting-textmate-proposal branch from dcd59b4 to f195395 Compare July 29, 2025 21:29
@pboettch
Patrick Boettcher (pboettch) force-pushed the syntax-highlighting-textmate-proposal branch 3 times, most recently from d55fce6 to 38e87ab Compare July 31, 2025 15:59
I upgraded my grammar-generation script I use to
generate the vim-syntax-highlighting-rules to put
out a TextMate-grammer.

The script can be found here: https://github.com/pboettch/vim-cmake-syntax/tree/textmate-grammer-generation
@hanniavalera
Hannia Valera (hanniavalera) force-pushed the syntax-highlighting-textmate-proposal branch from 38e87ab to 41320ca Compare April 7, 2026 21:27
@hanniavalera

Copy link
Copy Markdown
Contributor

Hi Patrick Boettcher (@pboettch), thank you for this PR, and for the time you put into researching the vim syntax as a reference! The ideas here are genuinely useful and several of them are being brought in.

Our grammar has evolved toward a regex-generalized architecture rather than exhaustive keyword enumeration, meaning we prefer patterns like CMAKE_\w+_COMPILER_VERSION over listing every language variant individually.

This keeps the file maintainable as CMake grows and avoids false-positives. The tradeoff is that it doesn't match the structure of a vim syntax file very directly, so the translation isn't one-to-one.

The improvements from this PR are being incorporated in a rebased form that layers your ideas on top of the current grammar's design, preserving the scoped-command architecture, the existing scope names and regex families, and the fixes already present in main.

You'll be credited in the changelog for the inspiration. Thanks again for the contribution!

@hanniavalera Hannia Valera (hanniavalera) changed the title Update TextMate grammar based on vim-syntax Apr 7, 2026
@hanniavalera Hannia Valera (hanniavalera) changed the title Improve CMake syntax highlighting: extend variable recognition with compiler/toolchain families and add scoped property command colorization for set_property, get_property, set_target_properties, and related commands. Apr 7, 2026
@pboettch

Copy link
Copy Markdown
Contributor Author

Don't worry, I didn't do this PR for the glory. I just know from the past that finding something generic regarding CMake syntax is hard to impossible and also CMake does not provide anything in their source tree which would make a syntax-tree design easier - except the documentation.

@hanniavalera
Hannia Valera (hanniavalera) merged commit 2d772e9 into microsoft:main Apr 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants