feat: Enhance highlight for C++20 keywords

This commit is contained in:
Caio Piccirillo 2025-08-23 15:58:38 -03:00
parent d49409caba
commit ad505e6568
3 changed files with 71 additions and 20 deletions

3
Cargo.lock generated
View file

@ -17182,8 +17182,7 @@ dependencies = [
[[package]] [[package]]
name = "tree-sitter-cpp" name = "tree-sitter-cpp"
version = "0.23.4" version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/tree-sitter/tree-sitter-cpp?rev=5cb9b693cfd7bfacab1d9ff4acac1a4150700609#5cb9b693cfd7bfacab1d9ff4acac1a4150700609"
checksum = "df2196ea9d47b4ab4a31b9297eaa5a5d19a0b121dceb9f118f6790ad0ab94743"
dependencies = [ dependencies = [
"cc", "cc",
"tree-sitter-language", "tree-sitter-language",

View file

@ -624,7 +624,7 @@ tower-http = "0.4.4"
tree-sitter = { version = "0.25.6", features = ["wasm"] } tree-sitter = { version = "0.25.6", features = ["wasm"] }
tree-sitter-bash = "0.25.0" tree-sitter-bash = "0.25.0"
tree-sitter-c = "0.23" 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-css = "0.23"
tree-sitter-diff = "0.1.0" tree-sitter-diff = "0.1.0"
tree-sitter-elixir = "0.3" tree-sitter-elixir = "0.3"

View file

@ -3,8 +3,36 @@
(namespace_identifier) @namespace (namespace_identifier) @namespace
(concept_definition (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)))
(co_await_expression
operator: "co_await" @keyword.operator)
(co_return_statement
"co_return" @keyword.operator)
(co_yield_statement
"co_yield" @keyword.operator)
(call_expression (call_expression
function: (qualified_identifier function: (qualified_identifier
@ -61,6 +89,9 @@
(operator_name (operator_name
(identifier)? @operator) @function (identifier)? @operator) @function
(operator_name
"<=>" @operator.spaceship)
(destructor_name (identifier) @function) (destructor_name (identifier) @function)
((namespace_identifier) @type ((namespace_identifier) @type
@ -68,21 +99,17 @@
(auto) @type (auto) @type
(type_identifier) @type (type_identifier) @type
type :(primitive_type) @type.primitive type: (primitive_type) @type.builtin
(sized_type_specifier) @type.primitive (sized_type_specifier) @type.builtin
(requires_clause
constraint: (template_type
name: (type_identifier) @concept))
(attribute (attribute
name: (identifier) @keyword) name: (identifier) @attribute)
((identifier) @constant ((identifier) @constant.builtin
(#match? @constant "^_*[A-Z][A-Z\\d_]*$")) (#match? @constant.builtin "^_*[A-Z][A-Z\\d_]*$"))
(statement_identifier) @label (statement_identifier) @label
(this) @variable.special (this) @variable.builtin
("static_assert") @function.builtin ("static_assert") @function.builtin
[ [
@ -92,11 +119,10 @@ type :(primitive_type) @type.primitive
"case" "case"
"catch" "catch"
"class" "class"
"co_await"
"co_return"
"co_yield"
"concept" "concept"
"consteval"
"constexpr" "constexpr"
"constinit"
"continue" "continue"
"decltype" "decltype"
"default" "default"
@ -105,15 +131,20 @@ type :(primitive_type) @type.primitive
"else" "else"
"enum" "enum"
"explicit" "explicit"
"export"
"extern" "extern"
"final" "final"
"for" "for"
"friend" "friend"
"goto"
"if" "if"
"import"
"inline" "inline"
"module"
"namespace" "namespace"
"new" "new"
"noexcept" "noexcept"
"operator"
"override" "override"
"private" "private"
"protected" "protected"
@ -124,6 +155,7 @@ type :(primitive_type) @type.primitive
"struct" "struct"
"switch" "switch"
"template" "template"
"thread_local"
"throw" "throw"
"try" "try"
"typedef" "typedef"
@ -136,6 +168,12 @@ type :(primitive_type) @type.primitive
(type_qualifier) (type_qualifier)
] @keyword ] @keyword
[
"co_await"
"co_return"
"co_yield"
] @keyword.operator
[ [
"#define" "#define"
"#elif" "#elif"
@ -146,7 +184,7 @@ type :(primitive_type) @type.primitive
"#ifndef" "#ifndef"
"#include" "#include"
(preproc_directive) (preproc_directive)
] @keyword ] @keyword.directive
(comment) @comment (comment) @comment
@ -224,10 +262,24 @@ type :(primitive_type) @type.primitive
">" ">"
"<=" "<="
">=" ">="
"<=>"
"||"
"?" "?"
"and"
"and_eq"
"bitand"
"bitor"
"compl"
"not"
"not_eq"
"or"
"or_eq"
"xor"
"xor_eq"
] @operator ] @operator
"<=>" @operator.spaceship
(binary_expression
operator: "<=>" @operator.spaceship)
(conditional_expression ":" @operator) (conditional_expression ":" @operator)
(user_defined_literal (literal_suffix) @operator) (user_defined_literal (literal_suffix) @operator)