aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-08-13 18:19:01 +0200
committerGitHub <noreply@github.com>2023-08-13 18:19:01 +0200
commit11590543ebad593b9f6d1434b71f019d042cb5d5 (patch)
treed04f3ab913d8ef5c1fe5082fda8b5654ed7b777d
parent017ff93b020e1915d03d9a2dd9a895613148f181 (diff)
parent3836eeb90182cc610ea15bf6bd83cbc720bb7c64 (diff)
downloadrneovim-11590543ebad593b9f6d1434b71f019d042cb5d5.tar.gz
rneovim-11590543ebad593b9f6d1434b71f019d042cb5d5.tar.bz2
rneovim-11590543ebad593b9f6d1434b71f019d042cb5d5.zip
Merge pull request #24681 from clason/update-c
feat(treesitter): update C parser and queries
-rw-r--r--cmake.deps/deps.txt4
-rw-r--r--runtime/queries/c/highlights.scm49
-rw-r--r--runtime/queries/c/injections.scm20
-rw-r--r--test/functional/treesitter/highlight_spec.lua6
4 files changed, 70 insertions, 9 deletions
diff --git a/cmake.deps/deps.txt b/cmake.deps/deps.txt
index 3260a9cb97..7430b258be 100644
--- a/cmake.deps/deps.txt
+++ b/cmake.deps/deps.txt
@@ -44,8 +44,8 @@ GETTEXT_SHA256 66415634c6e8c3fa8b71362879ec7575e27da43da562c798a8a2f223e6e47f5c
LIBICONV_URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178
-TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.4.tar.gz
-TREESITTER_C_SHA256 393a4208803de81c968dfc02c666aeb934971666e565345dff7445c6e0f06f8d
+TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.5.tar.gz
+TREESITTER_C_SHA256 694a5408246ee45d535df9df025febecdb50bee764df64a94346b9805a5f349b
TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.18.tar.gz
TREESITTER_LUA_SHA256 659beef871a7fa1d9a02c23f5ebf55019aa3adce6d7f5441947781e128845256
TREESITTER_VIM_URL https://github.com/neovim/tree-sitter-vim/archive/v0.3.0.tar.gz
diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm
index ef70a7103c..29fb5747ca 100644
--- a/runtime/queries/c/highlights.scm
+++ b/runtime/queries/c/highlights.scm
@@ -1,5 +1,6 @@
; Lower priority to prefer @parameter when identifier appears in parameter_declaration.
((identifier) @variable (#set! "priority" 95))
+(preproc_def (preproc_arg) @variable)
[
"default"
@@ -16,6 +17,7 @@
"sizeof"
"offsetof"
] @keyword.operator
+(alignof_expression . _ @keyword.operator)
"return" @keyword.return
@@ -141,8 +143,9 @@
(storage_class_specifier) @storageclass
[
- (type_qualifier)
+ (type_qualifier)
(gnu_asm_qualifier)
+ "__extension__"
] @type.qualifier
(linkage_specification
@@ -157,13 +160,52 @@
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
+(preproc_def (preproc_arg) @constant
+ (#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(enumerator
name: (identifier) @constant)
(case_statement
value: (identifier) @constant)
((identifier) @constant.builtin
- (#any-of? @constant.builtin "stderr" "stdin" "stdout"))
+ (#any-of? @constant.builtin
+ "stderr" "stdin" "stdout"
+ "__FILE__" "__LINE__" "__DATE__" "__TIME__"
+ "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
+ "__cplusplus" "__OBJC__" "__ASSEMBLER__"
+ "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
+ "__TIMESTAMP__" "__clang__" "__clang_major__"
+ "__clang_minor__" "__clang_patchlevel__"
+ "__clang_version__" "__clang_literal_encoding__"
+ "__clang_wide_literal_encoding__"
+ "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
+ "__VA_ARGS__" "__VA_OPT__"))
+(preproc_def (preproc_arg) @constant.builtin
+ (#any-of? @constant.builtin
+ "stderr" "stdin" "stdout"
+ "__FILE__" "__LINE__" "__DATE__" "__TIME__"
+ "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
+ "__cplusplus" "__OBJC__" "__ASSEMBLER__"
+ "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
+ "__TIMESTAMP__" "__clang__" "__clang_major__"
+ "__clang_minor__" "__clang_patchlevel__"
+ "__clang_version__" "__clang_literal_encoding__"
+ "__clang_wide_literal_encoding__"
+ "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
+ "__VA_ARGS__" "__VA_OPT__"))
+
+(attribute_specifier
+ (argument_list (identifier) @variable.builtin))
+((attribute_specifier
+ (argument_list (call_expression
+ function: (identifier) @variable.builtin))))
+
+((call_expression
+ function: (identifier) @function.builtin)
+ (#lua-match? @function.builtin "^__builtin_"))
+((call_expression
+ function: (identifier) @function.builtin)
+ (#has-ancestor? @function.builtin attribute_specifier))
;; Preproc def / undef
(preproc_def
@@ -197,6 +239,9 @@
declarator: (identifier) @parameter)
(parameter_declaration
+ declarator: (array_declarator) @parameter)
+
+(parameter_declaration
declarator: (pointer_declarator) @parameter)
(preproc_params (identifier) @parameter)
diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm
index 3b99c7a444..5a49e20df5 100644
--- a/runtime/queries/c/injections.scm
+++ b/runtime/queries/c/injections.scm
@@ -1,5 +1,21 @@
-; ((preproc_arg) @injection.content
-; (#set! injection.language "c"))
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "c"))
+
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "c"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "c"))
; ((comment) @injection.content
; (#set! injection.language "comment"))
+
+; TODO: add when asm is added
+; (gnu_asm_expression assembly_code: (string_literal) @injection.content
+; (#set! injection.language "asm"))
+; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
+; (#set! injection.language "asm"))
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index dc303c564f..c88c5cd3e5 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -580,9 +580,9 @@ describe('treesitter highlighting (C)', function()
-- expect everything to have Constant highlight
screen:expect{grid=[[
{12:int}{8: x = INT_MAX;} |
- {8:#define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))} |
- {8:#define foo void main() { \} |
- {8: return 42; \} |
+ {8:#define READ_STRING(x, y) (}{12:char}{8: *)read_string((x), (}{12:size_t}{8:)(y))} |
+ {8:#define foo }{12:void}{8: main() { \} |
+ {8: }{12:return}{8: 42; \} |
{8: }} |
^ |
{1:~ }|