Skip to content

Commit 702b6cc

Browse files
ChickenkeeperShekhinah Memmel
authored andcommitted
Fix C++ syntax highlighting, and improve C & WGSL highlighting (helix-editor#4079)
1 parent 7298f73 commit 702b6cc

File tree

4 files changed

+274
-175
lines changed

4 files changed

+274
-175
lines changed

languages.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
184184

185185
[[grammar]]
186186
name = "c"
187-
source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "f05e279aedde06a25801c3f2b2cc8ac17fac52ae" }
187+
source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "7175a6dd5fc1cee660dce6fe23f6043d75af424a" }
188188

189189
[[language]]
190190
name = "cpp"
@@ -221,7 +221,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
221221

222222
[[grammar]]
223223
name = "cpp"
224-
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "e8dcc9d2b404c542fd236ea5f7208f90be8a6e89" }
224+
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "d5e90fba898f320db48d81ddedd78d52c67c1fed" }
225225

226226
[[language]]
227227
name = "c-sharp"

runtime/queries/c/highlights.scm

Lines changed: 105 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,104 @@
1-
(storage_class_specifier) @keyword.storage
2-
3-
"goto" @keyword
4-
"register" @keyword
5-
"break" @keyword
6-
"case" @keyword
7-
"continue" @keyword
8-
"default" @keyword
9-
"do" @keyword
10-
"else" @keyword
11-
"enum" @keyword
12-
"extern" @keyword
13-
"for" @keyword
14-
"if" @keyword
15-
"inline" @keyword
16-
"return" @keyword
171
"sizeof" @keyword
18-
"struct" @keyword
19-
"switch" @keyword
20-
"typedef" @keyword
21-
"union" @keyword
22-
"volatile" @keyword
23-
"while" @keyword
24-
"const" @keyword
252

263
[
27-
"#define"
28-
"#elif"
29-
"#else"
30-
"#endif"
31-
"#if"
32-
"#ifdef"
33-
"#ifndef"
34-
"#include"
35-
(preproc_directive)
4+
"enum"
5+
"struct"
6+
"typedef"
7+
"union"
8+
] @keyword.storage.type
9+
10+
[
11+
"const"
12+
"extern"
13+
"inline"
14+
"register"
15+
"volatile"
16+
(storage_class_specifier)
17+
] @keyword.storage.modifier
18+
19+
[
20+
"goto"
21+
"break"
22+
"continue"
23+
] @keyword.control
24+
25+
[
26+
"do"
27+
"for"
28+
"while"
29+
] @keyword.control.repeat
30+
31+
[
32+
"if"
33+
"else"
34+
"switch"
35+
"case"
36+
"default"
37+
] @keyword.control.conditional
38+
39+
"return" @keyword.control.return
40+
41+
[
42+
"defined"
43+
"#define"
44+
"#elif"
45+
"#else"
46+
"#endif"
47+
"#if"
48+
"#ifdef"
49+
"#ifndef"
50+
"#include"
51+
(preproc_directive)
3652
] @keyword.directive
3753

38-
"--" @operator
39-
"-" @operator
40-
"-=" @operator
41-
"->" @operator
42-
"=" @operator
43-
"!=" @operator
44-
"*" @operator
45-
"&" @operator
46-
"&&" @operator
47-
"+" @operator
48-
"++" @operator
49-
"+=" @operator
50-
"<" @operator
51-
"==" @operator
52-
">" @operator
53-
"||" @operator
54-
">=" @operator
55-
"<=" @operator
56-
57-
"." @punctuation.delimiter
58-
";" @punctuation.delimiter
54+
[
55+
"+"
56+
"-"
57+
"*"
58+
"/"
59+
"++"
60+
"--"
61+
"%"
62+
"=="
63+
"!="
64+
">"
65+
"<"
66+
">="
67+
"<="
68+
"&&"
69+
"||"
70+
"!"
71+
"&"
72+
"|"
73+
"^"
74+
"~"
75+
"<<"
76+
">>"
77+
"="
78+
"+="
79+
"-="
80+
"*="
81+
"/="
82+
"%="
83+
"<<="
84+
">>="
85+
"&="
86+
"^="
87+
"|="
88+
"?"
89+
] @operator
90+
91+
(conditional_expression ":" @operator)
92+
93+
"..." @punctuation
94+
95+
["," "." ":" ";" "->" "::"] @punctuation.delimiter
96+
97+
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
5998

6099
[(true) (false)] @constant.builtin.boolean
61100

62-
(enumerator) @type.enum.variant
101+
(enumerator name: (identifier) @type.enum.variant)
63102

64103
(string_literal) @string
65104
(system_lib_string) @string
@@ -73,19 +112,28 @@
73112
(call_expression
74113
function: (field_expression
75114
field: (field_identifier) @function))
115+
(call_expression (argument_list (identifier) @variable))
76116
(function_declarator
77-
declarator: (identifier) @function)
117+
declarator: [(identifier) (field_identifier)] @function)
118+
(parameter_declaration
119+
declarator: (identifier) @variable.parameter)
120+
(parameter_declaration
121+
(pointer_declarator
122+
declarator: (identifier) @variable.parameter))
78123
(preproc_function_def
79124
name: (identifier) @function.special)
80125

126+
(attribute
127+
name: (identifier) @attribute)
128+
81129
(field_identifier) @variable.other.member
82130
(statement_identifier) @label
83131
(type_identifier) @type
84-
(primitive_type) @type
132+
(primitive_type) @type.builtin
85133
(sized_type_specifier) @type
86134

87135
((identifier) @constant
88-
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
136+
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
89137

90138
(identifier) @variable
91139

runtime/queries/cpp/highlights.scm

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
; inherits: c
2-
31
; Functions
42

53
(call_expression
@@ -12,56 +10,106 @@
1210
(template_method
1311
name: (field_identifier) @function)
1412

15-
(template_function
16-
name: (identifier) @function)
17-
1813
(function_declarator
1914
declarator: (qualified_identifier
2015
name: (identifier) @function))
2116

2217
(function_declarator
2318
declarator: (qualified_identifier
24-
name: (identifier) @function))
19+
name: (qualified_identifier
20+
name: (identifier) @function)))
2521

2622
(function_declarator
2723
declarator: (field_identifier) @function)
2824

2925
; Types
3026

31-
((namespace_identifier) @type
32-
(#match? @type "^[A-Z]"))
27+
(using_declaration ("using" "namespace" (identifier) @namespace))
28+
(using_declaration ("using" "namespace" (qualified_identifier name: (identifier) @namespace)))
29+
(namespace_definition name: (identifier) @namespace)
30+
(namespace_identifier) @namespace
31+
32+
(qualified_identifier name: (identifier) @type.enum.variant)
3333

3434
(auto) @type
35+
"decltype" @type
3536

3637
; Constants
3738

3839
(this) @variable.builtin
39-
(nullptr) @constant
40+
(nullptr) @constant.builtin
4041

4142
; Keywords
4243

43-
"catch" @keyword
44-
"class" @keyword
45-
"constexpr" @keyword
46-
"delete" @keyword
47-
"explicit" @keyword
48-
"final" @keyword
49-
"friend" @keyword
50-
"mutable" @keyword
51-
"namespace" @keyword
52-
"noexcept" @keyword
53-
"new" @keyword
54-
"override" @keyword
55-
"private" @keyword
56-
"protected" @keyword
57-
"public" @keyword
58-
"template" @keyword
59-
"throw" @keyword
60-
"try" @keyword
61-
"typename" @keyword
62-
"using" @keyword
63-
"virtual" @keyword
44+
(template_argument_list (["<" ">"] @punctuation.bracket))
45+
(template_parameter_list (["<" ">"] @punctuation.bracket))
46+
(default_method_clause "default" @keyword)
47+
48+
"static_assert" @function.special
49+
50+
[
51+
"<=>"
52+
"[]"
53+
"()"
54+
] @operator
55+
56+
[
57+
"co_await"
58+
"co_return"
59+
"co_yield"
60+
"concept"
61+
"delete"
62+
"final"
63+
"new"
64+
"operator"
65+
"requires"
66+
"using"
67+
] @keyword
68+
69+
[
70+
"catch"
71+
"noexcept"
72+
"throw"
73+
"try"
74+
] @keyword.control.exception
75+
76+
77+
[
78+
"and"
79+
"and_eq"
80+
"bitor"
81+
"bitand"
82+
"not"
83+
"not_eq"
84+
"or"
85+
"or_eq"
86+
"xor"
87+
"xor_eq"
88+
] @keyword.operator
89+
90+
[
91+
"class"
92+
"namespace"
93+
"typename"
94+
] @keyword.storage.type
95+
96+
[
97+
"constexpr"
98+
"constinit"
99+
"consteval"
100+
"explicit"
101+
"friend"
102+
"mutable"
103+
"private"
104+
"protected"
105+
"public"
106+
"override"
107+
"template"
108+
"virtual"
109+
] @keyword.storage.modifier
64110

65111
; Strings
66112

67113
(raw_string_literal) @string
114+
115+
; inherits: c

0 commit comments

Comments
 (0)