diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 5101df0c..b716b67e 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -112,7 +112,10 @@ [(true) (false)] @constant.builtin.boolean -(enumerator name: (identifier) @type.enum.variant) +; C enumerators are integer constants; colour the definition the same as a use +; site (a SCREAMING_SNAKE reference resolves to @constant above), not as a +; distinct enum variant. C++ overrides this to keep @type.enum.variant. +(enumerator name: (identifier) @constant) (string_literal) @string (system_lib_string) @string diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm index da38e62e..95e9c1bc 100644 --- a/runtime/queries/cpp/highlights.scm +++ b/runtime/queries/cpp/highlights.scm @@ -9,7 +9,14 @@ (using_declaration ("using" "namespace" (identifier) @namespace)) (using_declaration ("using" "namespace" (qualified_identifier name: (identifier) @namespace))) -(qualified_identifier name: (identifier) @type.enum.variant) +; Only a Capitalised qualified leaf (`Color::Red`) is an enum variant; a +; lowercase one (`std::cout`) is a value/member and falls through to @variable. +((qualified_identifier name: (identifier) @type.enum.variant) + (#match? @type.enum.variant "^[A-Z]")) +; C colours enumerator definitions @constant (see c/highlights.scm); C++ resolves +; enum values through the qualified path above as @type.enum.variant, so keep the +; definition matching that. +(enumerator name: (identifier) @type.enum.variant) (namespace_definition name: (namespace_identifier) @namespace) (namespace_identifier) @namespace