From abd6009b41595713de847e641bf78e9e46051909 Mon Sep 17 00:00:00 2001
From: Caio Piccirillo <34453935+caiopiccirillo@users.noreply.github.com>
Date: Wed, 27 Aug 2025 01:31:57 -0300
Subject: [PATCH] Enhance syntax highlight for C++20 keywords (#36817)
Closes #36439 and #32999
## C++20 modules:
Before (Zed Preview v0.201.3):
After:
## C++20 coroutines:
Before (Zed Preview v0.201.3):
After:
## Logical operators:
Before (Zed Preview v0.201.3):
After:
## Operator keyword:
Before (Zed Preview v0.201.3):
After:
## Goto:
Before (Zed Preview v0.201.3):
After:
Release Notes:
- Enhance keyword highlighting for C++
---
Cargo.lock | 3 +-
Cargo.toml | 2 +-
crates/languages/src/cpp/highlights.scm | 68 ++++++++++++++++++++-----
3 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 6ece2bb6bf9442a4af81a2928ef47209fd6f00df..4325addc392214614a6654563d88041331f2ded9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -17185,8 +17185,7 @@ dependencies = [
[[package]]
name = "tree-sitter-cpp"
version = "0.23.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df2196ea9d47b4ab4a31b9297eaa5a5d19a0b121dceb9f118f6790ad0ab94743"
+source = "git+https://github.com/tree-sitter/tree-sitter-cpp?rev=5cb9b693cfd7bfacab1d9ff4acac1a4150700609#5cb9b693cfd7bfacab1d9ff4acac1a4150700609"
dependencies = [
"cc",
"tree-sitter-language",
diff --git a/Cargo.toml b/Cargo.toml
index 6ec243a9b9de4d2ab322e0466e804fa542a1ed35..209c312aec4061c97d547a6157dece5ed5402cf8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -624,7 +624,7 @@ tower-http = "0.4.4"
tree-sitter = { version = "0.25.6", features = ["wasm"] }
tree-sitter-bash = "0.25.0"
tree-sitter-c = "0.23"
-tree-sitter-cpp = "0.23"
+tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "5cb9b693cfd7bfacab1d9ff4acac1a4150700609" }
tree-sitter-css = "0.23"
tree-sitter-diff = "0.1.0"
tree-sitter-elixir = "0.3"
diff --git a/crates/languages/src/cpp/highlights.scm b/crates/languages/src/cpp/highlights.scm
index 6fa8bd7b0858d3a1844ce2d322564ce9c39babea..bd988445bb155e8851ffa8bc3771bdd235fc7dff 100644
--- a/crates/languages/src/cpp/highlights.scm
+++ b/crates/languages/src/cpp/highlights.scm
@@ -3,8 +3,27 @@
(namespace_identifier) @namespace
(concept_definition
- (identifier) @concept)
+ name: (identifier) @concept)
+(requires_clause
+ constraint: (template_type
+ name: (type_identifier) @concept))
+
+(module_name
+ (identifier) @module)
+
+(module_declaration
+ name: (module_name
+ (identifier) @module))
+
+(import_declaration
+ name: (module_name
+ (identifier) @module))
+
+(import_declaration
+ partition: (module_partition
+ (module_name
+ (identifier) @module)))
(call_expression
function: (qualified_identifier
@@ -61,6 +80,9 @@
(operator_name
(identifier)? @operator) @function
+(operator_name
+ "<=>" @operator.spaceship)
+
(destructor_name (identifier) @function)
((namespace_identifier) @type
@@ -68,21 +90,17 @@
(auto) @type
(type_identifier) @type
-type :(primitive_type) @type.primitive
-(sized_type_specifier) @type.primitive
-
-(requires_clause
- constraint: (template_type
- name: (type_identifier) @concept))
+type: (primitive_type) @type.builtin
+(sized_type_specifier) @type.builtin
(attribute
- name: (identifier) @keyword)
+ name: (identifier) @attribute)
-((identifier) @constant
- (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
+((identifier) @constant.builtin
+ (#match? @constant.builtin "^_*[A-Z][A-Z\\d_]*$"))
(statement_identifier) @label
-(this) @variable.special
+(this) @variable.builtin
("static_assert") @function.builtin
[
@@ -96,7 +114,9 @@ type :(primitive_type) @type.primitive
"co_return"
"co_yield"
"concept"
+ "consteval"
"constexpr"
+ "constinit"
"continue"
"decltype"
"default"
@@ -105,15 +125,20 @@ type :(primitive_type) @type.primitive
"else"
"enum"
"explicit"
+ "export"
"extern"
"final"
"for"
"friend"
+ "goto"
"if"
+ "import"
"inline"
+ "module"
"namespace"
"new"
"noexcept"
+ "operator"
"override"
"private"
"protected"
@@ -124,6 +149,7 @@ type :(primitive_type) @type.primitive
"struct"
"switch"
"template"
+ "thread_local"
"throw"
"try"
"typedef"
@@ -146,7 +172,7 @@ type :(primitive_type) @type.primitive
"#ifndef"
"#include"
(preproc_directive)
-] @keyword
+] @keyword.directive
(comment) @comment
@@ -224,10 +250,24 @@ type :(primitive_type) @type.primitive
">"
"<="
">="
- "<=>"
- "||"
"?"
+ "and"
+ "and_eq"
+ "bitand"
+ "bitor"
+ "compl"
+ "not"
+ "not_eq"
+ "or"
+ "or_eq"
+ "xor"
+ "xor_eq"
] @operator
+"<=>" @operator.spaceship
+
+(binary_expression
+ operator: "<=>" @operator.spaceship)
+
(conditional_expression ":" @operator)
(user_defined_literal (literal_suffix) @operator)