From 1df3f5ec6aca24cbe7b78ead5c37ad06a65c84e8 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 23 Feb 2023 17:05:20 +0000 Subject: feat(treesitter): upstream foldexpr from nvim-treesitter --- runtime/queries/c/folds.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 runtime/queries/c/folds.scm (limited to 'runtime/queries/c') diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm new file mode 100644 index 0000000000..80c3039b6b --- /dev/null +++ b/runtime/queries/c/folds.scm @@ -0,0 +1,19 @@ +[ + (for_statement) + (if_statement) + (while_statement) + (switch_statement) + (case_statement) + (function_definition) + (struct_specifier) + (enum_specifier) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (initializer_list) +] @fold + + (compound_statement + (compound_statement) @fold) -- cgit From ddd257f75301a50c177fc24a693d39a45b47a689 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 8 Mar 2023 11:03:11 +0000 Subject: feat(treesitter): use upstream format for injection queries --- runtime/queries/c/injections.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime/queries/c') diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 7e9e73449d..84ae33683e 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,3 +1,5 @@ -(preproc_arg) @c +((preproc_arg) @injection.content + (#set! injection.language "c")) -; (comment) @comment +; ((comment) @injection.content +; (#set! injection.language "comment")) -- cgit From 2a298f2e48eb081f2e3b58068af589b82fe76a18 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 31 Mar 2023 16:11:17 +0200 Subject: fix(treesitter): update queries from nvim-treesitter remove self-injection for C preprocessor macros (can be very slow) --- runtime/queries/c/highlights.scm | 115 +++++++++++++++++++++++++-------------- runtime/queries/c/injections.scm | 4 +- 2 files changed, 76 insertions(+), 43 deletions(-) (limited to 'runtime/queries/c') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 33e6df74ab..dee70f9cc7 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,22 +1,19 @@ -(identifier) @variable +; Lower priority to prefer @parameter when identifier appears in parameter_declaration. +((identifier) @variable (#set! "priority" 95)) [ - "const" "default" "enum" - "extern" - "inline" - "return" - "sizeof" - "static" "struct" "typedef" "union" - "volatile" "goto" - "register" ] @keyword +"sizeof" @keyword.operator + +"return" @keyword.return + [ "while" "for" @@ -32,7 +29,6 @@ "switch" ] @conditional -"#define" @constant.macro [ "#if" "#ifdef" @@ -41,10 +37,18 @@ "#elif" "#endif" (preproc_directive) -] @keyword +] @preproc + +"#define" @define "#include" @include +[ ";" ":" "," ] @punctuation.delimiter + +"..." @punctuation.special + +[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket + [ "=" @@ -62,6 +66,7 @@ ">>" "->" + "." "<" "<=" @@ -88,35 +93,25 @@ "++" ] @operator +;; Make sure the comma operator is given a highlight group after the comma +;; punctuator so the operator is highlighted properly. +(comma_expression [ "," ] @operator) + [ (true) (false) ] @boolean -[ "." ";" ":" "," ] @punctuation.delimiter - -(conditional_expression [ "?" ":" ] @conditional) - - -[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket +(conditional_expression [ "?" ":" ] @conditional.ternary) (string_literal) @string -(string_literal) @spell (system_lib_string) @string +(escape_sequence) @string.escape (null) @constant.builtin (number_literal) @number -(char_literal) @number +(char_literal) @character -(call_expression - function: (identifier) @function) -(call_expression - function: (field_expression - field: (field_identifier) @function)) -(function_declarator - declarator: (identifier) @function) -(preproc_function_def - name: (identifier) @function.macro) [ (preproc_arg) (preproc_defined) @@ -126,18 +121,32 @@ (statement_identifier) @label [ -(type_identifier) -(primitive_type) -(sized_type_specifier) -(type_descriptor) - ] @type + (type_identifier) + (sized_type_specifier) + (type_descriptor) +] @type + +(storage_class_specifier) @storageclass + +(type_qualifier) @type.qualifier + +(linkage_specification + "extern" @storageclass) -(declaration (type_qualifier) @type) -(cast_expression type: (type_descriptor) @type) -(sizeof_expression value: (parenthesized_expression (identifier) @type)) +(type_definition + declarator: (type_identifier) @type.definition) + +(primitive_type) @type.builtin ((identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]+$")) + (#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")) ;; Preproc def / undef (preproc_def @@ -147,9 +156,20 @@ argument: (_) @constant (#eq? @_u "#undef")) +(call_expression + function: (identifier) @function.call) +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) +(function_declarator + declarator: (identifier) @function) +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell -(comment) @comment -(comment) @spell +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) ;; Parameters (parameter_declaration @@ -158,7 +178,20 @@ (parameter_declaration declarator: (pointer_declarator) @parameter) -(preproc_params - (identifier)) @parameter +(preproc_params (identifier) @parameter) + +[ + "__attribute__" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + "_unaligned" + "__unaligned" + "__declspec" + (attribute_declaration) +] @attribute (ERROR) @error diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 84ae33683e..3b99c7a444 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,5 +1,5 @@ -((preproc_arg) @injection.content - (#set! injection.language "c")) +; ((preproc_arg) @injection.content +; (#set! injection.language "c")) ; ((comment) @injection.content ; (#set! injection.language "comment")) -- cgit From 9ff59517cbf309d31f979a49b7dc82b237ecfcc4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 13 May 2023 12:56:21 +0200 Subject: fix(treesitter): update c queries --- runtime/queries/c/highlights.scm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'runtime/queries/c') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index dee70f9cc7..523a792403 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -117,12 +117,19 @@ (preproc_defined) ] @function.macro -(field_identifier) @property +(((field_expression + (field_identifier) @property)) @_parent + (#not-has-parent? @_parent template_method function_declarator call_expression)) + +(field_designator) @property +(((field_identifier) @property) + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) + (statement_identifier) @label [ (type_identifier) - (sized_type_specifier) (type_descriptor) ] @type @@ -138,6 +145,8 @@ (primitive_type) @type.builtin +(sized_type_specifier _ @type.builtin type: _?) + ((identifier) @constant (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) (enumerator @@ -163,6 +172,10 @@ field: (field_identifier) @function.call)) (function_declarator declarator: (identifier) @function) +(function_declarator + declarator: (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) (preproc_function_def name: (identifier) @function.macro) -- cgit From 41cefe513054edd1c12f235125220dbc6b4d9451 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 27 Jul 2023 12:45:08 +0200 Subject: build(deps): bump tree-sitter-c to v0.20.4 (#24495) --- runtime/queries/c/folds.scm | 3 ++- runtime/queries/c/highlights.scm | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'runtime/queries/c') diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm index 80c3039b6b..5a35334a24 100644 --- a/runtime/queries/c/folds.scm +++ b/runtime/queries/c/folds.scm @@ -13,7 +13,8 @@ (preproc_else) (preproc_ifdef) (initializer_list) + (gnu_asm_expression) ] @fold - (compound_statement +(compound_statement (compound_statement) @fold) diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 523a792403..ef70a7103c 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -8,9 +8,14 @@ "typedef" "union" "goto" + "asm" + "__asm__" ] @keyword -"sizeof" @keyword.operator +[ + "sizeof" + "offsetof" +] @keyword.operator "return" @keyword.return @@ -36,6 +41,8 @@ "#else" "#elif" "#endif" + "#elifdef" + "#elifndef" (preproc_directive) ] @preproc @@ -43,7 +50,7 @@ "#include" @include -[ ";" ":" "," ] @punctuation.delimiter +[ ";" ":" "," "::" ] @punctuation.delimiter "..." @punctuation.special @@ -98,8 +105,8 @@ (comma_expression [ "," ] @operator) [ - (true) - (false) + (true) + (false) ] @boolean (conditional_expression [ "?" ":" ] @conditional.ternary) @@ -112,10 +119,8 @@ (number_literal) @number (char_literal) @character -[ - (preproc_arg) - (preproc_defined) -] @function.macro +((preproc_arg) @function.macro (#set! "priority" 90)) +(preproc_defined) @function.macro (((field_expression (field_identifier) @property)) @_parent @@ -135,7 +140,10 @@ (storage_class_specifier) @storageclass -(type_qualifier) @type.qualifier +[ + (type_qualifier) + (gnu_asm_qualifier) +] @type.qualifier (linkage_specification "extern" @storageclass) @@ -195,15 +203,15 @@ [ "__attribute__" + "__declspec" + "__based" "__cdecl" "__clrcall" "__stdcall" "__fastcall" "__thiscall" "__vectorcall" - "_unaligned" - "__unaligned" - "__declspec" + (ms_pointer_modifier) (attribute_declaration) ] @attribute -- cgit From 3836eeb90182cc610ea15bf6bd83cbc720bb7c64 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 12 Aug 2023 18:12:49 +0200 Subject: feat(treesitter): update C queries from upstream --- runtime/queries/c/highlights.scm | 49 ++++++++++++++++++++++++++++++++++++++-- runtime/queries/c/injections.scm | 20 ++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) (limited to 'runtime/queries/c') 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 @@ -196,6 +238,9 @@ (parameter_declaration declarator: (identifier) @parameter) +(parameter_declaration + declarator: (array_declarator) @parameter) + (parameter_declaration declarator: (pointer_declarator) @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")) -- cgit