Files
zed/crates/languages/src/cpp/highlights.scm
T
ozacodandozacod 61e575547c languages: Change syntax highlighting for C/C++ preprocessor directives (#48109)
This changes the highlight capture for preprocessor directives from
`@keyword.directive` to `@preproc` in both C and C++.

PR #44043 changed C from `@keyword` to `@keyword.directive` for
consistency with C++, but `@keyword.directive` is still semantically
wrong. Preprocessor directives are not language keywords — they are
instructions to a separate preprocessing phase that runs before
compilation.

Using `@preproc` reflects this distinction and allows themes to style
them independently from actual language keywords like `const`,
`struct`,`if`, etc. This is consistent with how editors like CLion
handle preprocessor directives.

Before:
<img width="710" height="653" alt="before"
src="https://github.com/user-attachments/assets/5c02fc06-bc19-4112-ae53-ad72eb8044e3"
/>

After:
<img width="710" height="653" alt="after"
src="https://github.com/user-attachments/assets/2490e796-7286-4fbb-81b0-387f551cde8f"
/>

Release Notes:

- C/C++: Syntax highlighting for preprocessor directives can now be
tweaked with @preproc capture group.

Co-authored-by: ozacod <ozacod@users.noreply.github.com>
2026-02-10 12:44:23 +01:00

290 lines
4.1 KiB
Scheme

(identifier) @variable
(field_identifier) @property
(namespace_identifier) @namespace
(concept_definition
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
name: (identifier) @function))
(call_expression
(qualified_identifier
(identifier) @function.call))
(call_expression
(qualified_identifier
(qualified_identifier
(identifier) @function.call)))
(call_expression
(qualified_identifier
(qualified_identifier
(qualified_identifier
(identifier) @function.call))))
((qualified_identifier
(qualified_identifier
(qualified_identifier
(qualified_identifier
(identifier) @function.call)))) @_parent
(#has-ancestor? @_parent call_expression))
(call_expression
function: (identifier) @function)
(call_expression
function: (field_expression
field: (field_identifier) @function))
(preproc_function_def
name: (identifier) @function.special)
(template_function
name: (identifier) @function)
(template_method
name: (field_identifier) @function)
(function_declarator
declarator: (identifier) @function)
(function_declarator
declarator: (qualified_identifier
name: (identifier) @function))
(function_declarator
declarator: (field_identifier) @function)
(operator_name
(identifier)? @operator) @function
(operator_name
"<=>" @operator.spaceship)
(destructor_name (identifier) @function)
((namespace_identifier) @type
(#match? @type "^[A-Z]"))
(auto) @type
(type_identifier) @type
type: (primitive_type) @type.builtin
(sized_type_specifier) @type.builtin
; GNU __attribute__
(attribute_specifier) @attribute
(attribute_specifier
(argument_list
(identifier) @attribute))
; C++11 [[attributes]]
(attribute
prefix: (identifier) @attribute)
(attribute
name: (identifier) @attribute)
((identifier) @constant.builtin
(#match? @constant.builtin "^_*[A-Z][A-Z\\d_]*$"))
(statement_identifier) @label
(this) @variable.builtin
("static_assert") @function.builtin
[
"alignas"
"alignof"
"class"
"concept"
"consteval"
"constexpr"
"constinit"
"decltype"
"delete"
"enum"
"explicit"
"export"
"extern"
"final"
"friend"
"import"
"inline"
"module"
"namespace"
"new"
"noexcept"
"operator"
"override"
"private"
"protected"
"public"
"requires"
"sizeof"
"struct"
"template"
"thread_local"
"typedef"
"typename"
"union"
"using"
"virtual"
(storage_class_specifier)
(type_qualifier)
] @keyword
[
"break"
"case"
"catch"
"co_await"
"co_return"
"co_yield"
"continue"
"default"
"do"
"else"
"for"
"goto"
"if"
"return"
"switch"
"throw"
"try"
"while"
] @keyword.control
[
"#define"
"#elif"
"#elifdef"
"#elifndef"
"#else"
"#endif"
"#if"
"#ifdef"
"#ifndef"
"#include"
(preproc_directive)
] @preproc
(comment) @comment
[
(true)
(false)
] @boolean
[
(null)
("nullptr")
] @constant.builtin
(number_literal) @number
[
(string_literal)
(system_lib_string)
(char_literal)
(raw_string_literal)
] @string
(escape_sequence) @string.escape
[
","
":"
"::"
";"
(raw_string_delimiter)
] @punctuation.delimiter
[
"{"
"}"
"("
")"
"["
"]"
] @punctuation.bracket
[
"."
".*"
"->*"
"~"
"-"
"--"
"-="
"->"
"="
"!"
"!="
"|"
"|="
"||"
"^"
"^="
"&"
"&="
"&&"
"+"
"++"
"+="
"*"
"*="
"/"
"/="
"%"
"%="
"<<"
"<<="
">>"
">>="
"<"
"=="
">"
"<="
">="
"?"
"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)