aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Seitz <sseitz@nvidia.com>2021-12-20 14:50:59 +0100
committerStephan Seitz <stephan.seitz@fau.de>2022-01-29 13:11:56 +0100
commite4675bc410ebf7889e63a691f59d5760aec4e0e9 (patch)
tree1c42d2a0adb51a35014ec94ed721f7d7b86e63ac
parenthighlights(c): highlight enum variants as `@constant` (diff)
downloadnvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar.gz
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar.bz2
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar.lz
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar.xz
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.tar.zst
nvim-treesitter-e4675bc410ebf7889e63a691f59d5760aec4e0e9.zip
highlights(c/cpp): highlight case labels as constants
-rw-r--r--queries/c/highlights.scm2
-rw-r--r--queries/cpp/highlights.scm2
-rw-r--r--tests/query/highlights/c/enums-as-constants.c21
-rw-r--r--tests/query/highlights/cpp/enums-as-constants.cpp25
4 files changed, 50 insertions, 0 deletions
diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm
index 019522c3b..2ea07a74a 100644
--- a/queries/c/highlights.scm
+++ b/queries/c/highlights.scm
@@ -139,6 +139,8 @@
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(enumerator
name: (identifier) @constant)
+(case_statement
+ value: (identifier) @constant)
;; Preproc def / undef
(preproc_def
diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm
index 46ce27bb2..e3139c7be 100644
--- a/queries/cpp/highlights.scm
+++ b/queries/cpp/highlights.scm
@@ -38,6 +38,8 @@
(#lua-match? @type "^[A-Z]"))
((namespace_identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
+(case_statement
+ value: (qualified_identifier (identifier) @constant))
(namespace_definition
name: (identifier) @namespace)
diff --git a/tests/query/highlights/c/enums-as-constants.c b/tests/query/highlights/c/enums-as-constants.c
new file mode 100644
index 000000000..8e6474466
--- /dev/null
+++ b/tests/query/highlights/c/enums-as-constants.c
@@ -0,0 +1,21 @@
+enum Foo{
+ a,
+// ^ @constant
+ aa,
+// ^ @constant
+ C,
+};
+
+void foo(enum Foo f){
+ switch ( f ) {
+ case a:
+ // ^ @constant
+ break;
+ case aa:
+ // ^ @constant
+ break;
+ case C:
+ break;
+ default:
+ }
+}
diff --git a/tests/query/highlights/cpp/enums-as-constants.cpp b/tests/query/highlights/cpp/enums-as-constants.cpp
new file mode 100644
index 000000000..ae773e8d3
--- /dev/null
+++ b/tests/query/highlights/cpp/enums-as-constants.cpp
@@ -0,0 +1,25 @@
+enum class Foo{
+ a,
+// ^ @constant
+ aa,
+// ^ @constant
+ C,
+// ^ @constant
+};
+
+void foo(Foo f){
+ switch ( f ) {
+ case Foo::a:
+ // ^ @type
+ // ^ @namespace
+ // ^ @constant
+ break;
+ case Foo::aa:
+ // ^ @constant
+ break;
+ case Foo::C:
+ // ^ @constant
+ break;
+ default:
+ }
+}