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 -(declaration (type_qualifier) @type) -(cast_expression type: (type_descriptor) @type) -(sizeof_expression value: (parenthesized_expression (identifier) @type)) +(storage_class_specifier) @storageclass + +(type_qualifier) @type.qualifier + +(linkage_specification + "extern" @storageclass) + +(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 -(comment) @spell +(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")) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 2c0dc5447a..5fbf8a1833 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -8,8 +8,6 @@ "local" ] @keyword -(label_statement) @label - (break_statement) @keyword (do_statement @@ -109,6 +107,7 @@ [ ";" ":" + "::" "," "." ] @punctuation.delimiter @@ -129,12 +128,21 @@ (identifier) @variable ((identifier) @variable.builtin - (#eq? @variable.builtin "self")) + (#any-of? @variable.builtin "_G" "_VERSION" "debug" "io" "jit" "math" "os" "package" "self" "string" "table" "utf8")) + +((identifier) @keyword.coroutine + (#eq? @keyword.coroutine "coroutine")) (variable_list - attribute: (attribute - (["<" ">"] @punctuation.bracket - (identifier) @attribute))) + attribute: (attribute + (["<" ">"] @punctuation.bracket + (identifier) @attribute))) + +;; Labels + +(label_statement (identifier) @label) + +(goto_statement (identifier) @label) ;; Constants @@ -172,7 +180,7 @@ (function_call name: (dot_index_expression field: (identifier) @function.call)) (function_declaration name: (dot_index_expression field: (identifier) @function)) -(method_index_expression method: (identifier) @method) +(method_index_expression method: (identifier) @method.call) (function_call (identifier) @function.builtin @@ -180,20 +188,27 @@ ;; built-in functions in Lua 5.1 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" - "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable" - "tonumber" "tostring" "type" "unpack" "xpcall")) + "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setfenv" "setmetatable" + "tonumber" "tostring" "type" "unpack" "xpcall" + "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" + "__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" + "__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm")) ;; Others -(comment) @comment -(comment) @spell +(comment) @comment @spell -(hash_bang_line) @comment +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-][-]")) + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-](%s?)@")) + +(hash_bang_line) @preproc (number) @number -(string) @string -(string) @spell +(string) @string @spell ;; Error (ERROR) @error diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 10eb4c4054..1c7bdaf951 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -11,18 +11,18 @@ name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content))) (#set! injection.language "vim") - (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd")) ((function_call name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content) .)) (#set! injection.language "query") - (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) + (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse")) -; ;; highlight string as query if starts with `;; query` -; ((string ("string_content") @injection.content) -; (#set! injection.language "query") -; (#lua-match? @injection.content "^%s*;+%s?query")) +;; highlight string as query if starts with `;; query` +((string ("string_content") @injection.content) + (#set! injection.language "query") + (#lua-match? @injection.content "^%s*;+%s?query")) ; ((comment) @injection.content ; (#set! injection.language "comment")) diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index 239b0a0b37..ce25b13b9f 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -271,7 +271,7 @@ ":" ] @punctuation.delimiter -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) ; Options ((set_value) @number