Skip to content

Commit 643a9e2

Browse files
caiopiccirillotidely
authored andcommitted
Enhance syntax highlight for C++20 keywords (zed-industries#36817)
Closes zed-industries#36439 and zed-industries#32999 ## C++20 modules: Before (Zed Preview v0.201.3): <img width="1048" height="704" alt="image" src="https://github.com/user-attachments/assets/8eaaf77f-4e27-4a5a-9e87-4e5ba7293990" /> After: <img width="1048" height="704" alt="image" src="https://github.com/user-attachments/assets/df8d0b2c-f2d0-4b0e-9a52-495e6be5a8c0" /> ## C++20 coroutines: Before (Zed Preview v0.201.3): <img width="1048" height="704" alt="image" src="https://github.com/user-attachments/assets/652191ec-a653-444d-a239-da3e4e4b661e" /> After: <img width="1048" height="704" alt="image" src="https://github.com/user-attachments/assets/36947eb5-8997-483a-b36c-8af84872b158" /> ## Logical operators: Before (Zed Preview v0.201.3): <img width="511" height="102" alt="image" src="https://github.com/user-attachments/assets/9bf95bac-b076-4edd-a1f3-c3dfee98c2fd" /> After: <img width="511" height="102" alt="image" src="https://github.com/user-attachments/assets/82c7564d-b94d-41f5-9c48-e39fe3ba3b3e" /> ## Operator keyword: Before (Zed Preview v0.201.3): <img width="591" height="381" alt="image" src="https://github.com/user-attachments/assets/1d9dad05-2d86-4566-97f4-aff440dcd1df" /> After: <img width="591" height="381" alt="image" src="https://github.com/user-attachments/assets/a1ca289a-8a5d-4ffd-96db-0d511405da4b" /> ## Goto: Before (Zed Preview v0.201.3): <img width="610" height="430" alt="image" src="https://github.com/user-attachments/assets/2d00382b-d1ad-4e36-a3ee-88e06ec528ed" /> After: <img width="610" height="430" alt="image" src="https://github.com/user-attachments/assets/de887b21-66f0-4a70-9ed2-e18dbb3c81c9" /> Release Notes: - Enhance keyword highlighting for C++
1 parent 4112792 commit 643a9e2

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ tower-http = "0.4.4"
624624
tree-sitter = { version = "0.25.6", features = ["wasm"] }
625625
tree-sitter-bash = "0.25.0"
626626
tree-sitter-c = "0.23"
627-
tree-sitter-cpp = "0.23"
627+
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "5cb9b693cfd7bfacab1d9ff4acac1a4150700609" }
628628
tree-sitter-css = "0.23"
629629
tree-sitter-diff = "0.1.0"
630630
tree-sitter-elixir = "0.3"

crates/languages/src/cpp/highlights.scm

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
(namespace_identifier) @namespace
44

55
(concept_definition
6-
(identifier) @concept)
6+
name: (identifier) @concept)
77

8+
(requires_clause
9+
constraint: (template_type
10+
name: (type_identifier) @concept))
11+
12+
(module_name
13+
(identifier) @module)
14+
15+
(module_declaration
16+
name: (module_name
17+
(identifier) @module))
18+
19+
(import_declaration
20+
name: (module_name
21+
(identifier) @module))
22+
23+
(import_declaration
24+
partition: (module_partition
25+
(module_name
26+
(identifier) @module)))
827

928
(call_expression
1029
function: (qualified_identifier
@@ -61,28 +80,27 @@
6180
(operator_name
6281
(identifier)? @operator) @function
6382

83+
(operator_name
84+
"<=>" @operator.spaceship)
85+
6486
(destructor_name (identifier) @function)
6587

6688
((namespace_identifier) @type
6789
(#match? @type "^[A-Z]"))
6890

6991
(auto) @type
7092
(type_identifier) @type
71-
type :(primitive_type) @type.primitive
72-
(sized_type_specifier) @type.primitive
73-
74-
(requires_clause
75-
constraint: (template_type
76-
name: (type_identifier) @concept))
93+
type: (primitive_type) @type.builtin
94+
(sized_type_specifier) @type.builtin
7795

7896
(attribute
79-
name: (identifier) @keyword)
97+
name: (identifier) @attribute)
8098

81-
((identifier) @constant
82-
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
99+
((identifier) @constant.builtin
100+
(#match? @constant.builtin "^_*[A-Z][A-Z\\d_]*$"))
83101

84102
(statement_identifier) @label
85-
(this) @variable.special
103+
(this) @variable.builtin
86104
("static_assert") @function.builtin
87105

88106
[
@@ -96,7 +114,9 @@ type :(primitive_type) @type.primitive
96114
"co_return"
97115
"co_yield"
98116
"concept"
117+
"consteval"
99118
"constexpr"
119+
"constinit"
100120
"continue"
101121
"decltype"
102122
"default"
@@ -105,15 +125,20 @@ type :(primitive_type) @type.primitive
105125
"else"
106126
"enum"
107127
"explicit"
128+
"export"
108129
"extern"
109130
"final"
110131
"for"
111132
"friend"
133+
"goto"
112134
"if"
135+
"import"
113136
"inline"
137+
"module"
114138
"namespace"
115139
"new"
116140
"noexcept"
141+
"operator"
117142
"override"
118143
"private"
119144
"protected"
@@ -124,6 +149,7 @@ type :(primitive_type) @type.primitive
124149
"struct"
125150
"switch"
126151
"template"
152+
"thread_local"
127153
"throw"
128154
"try"
129155
"typedef"
@@ -146,7 +172,7 @@ type :(primitive_type) @type.primitive
146172
"#ifndef"
147173
"#include"
148174
(preproc_directive)
149-
] @keyword
175+
] @keyword.directive
150176

151177
(comment) @comment
152178

@@ -224,10 +250,24 @@ type :(primitive_type) @type.primitive
224250
">"
225251
"<="
226252
">="
227-
"<=>"
228-
"||"
229253
"?"
254+
"and"
255+
"and_eq"
256+
"bitand"
257+
"bitor"
258+
"compl"
259+
"not"
260+
"not_eq"
261+
"or"
262+
"or_eq"
263+
"xor"
264+
"xor_eq"
230265
] @operator
231266

267+
"<=>" @operator.spaceship
268+
269+
(binary_expression
270+
operator: "<=>" @operator.spaceship)
271+
232272
(conditional_expression ":" @operator)
233273
(user_defined_literal (literal_suffix) @operator)

0 commit comments

Comments
 (0)