From 2c85e6283d0045f1f62c6b0865f1bcb07ae20c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 7 Jun 2026 20:44:39 +0900 Subject: [PATCH] runtime: Apply similar constant query improvements to c/cpp --- runtime/queries/c/highlights.scm | 5 ++++- runtime/queries/cpp/highlights.scm | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 -- 2.51.2