From 64cc78c9f39b3066b74f01ec7e3f50fd316416e4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 16:37:24 +0200 Subject: [PATCH] feat(treesitter): add injections --- runtime/queries/c/injections.scm | 3 +++ runtime/queries/lua/injections.scm | 22 ++++++++++++++++ runtime/queries/vim/injections.scm | 26 +++++++++++++++++++ test/functional/treesitter/highlight_spec.lua | 6 ++--- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 runtime/queries/c/injections.scm create mode 100644 runtime/queries/lua/injections.scm create mode 100644 runtime/queries/vim/injections.scm diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm new file mode 100644 index 0000000000..7e9e73449d --- /dev/null +++ b/runtime/queries/c/injections.scm @@ -0,0 +1,3 @@ +(preproc_arg) @c + +; (comment) @comment diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm new file mode 100644 index 0000000000..0e67329139 --- /dev/null +++ b/runtime/queries/lua/injections.scm @@ -0,0 +1,22 @@ +((function_call + name: [ + (identifier) @_cdef_identifier + (_ _ (identifier) @_cdef_identifier) + ] + arguments: (arguments (string content: _ @c))) + (#eq? @_cdef_identifier "cdef")) + +((function_call + name: (_) @_vimcmd_identifier + arguments: (arguments (string content: _ @vim))) + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) + +; ((function_call +; name: (_) @_vimcmd_identifier +; arguments: (arguments (string content: _ @query) .)) +; (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) + +; ;; highlight string as query if starts with `;; query` +; ((string ("string_content") @query) (#lua-match? @query "^%s*;+%s?query")) + +; (comment) @comment diff --git a/runtime/queries/vim/injections.scm b/runtime/queries/vim/injections.scm new file mode 100644 index 0000000000..e2dea8fe75 --- /dev/null +++ b/runtime/queries/vim/injections.scm @@ -0,0 +1,26 @@ +(lua_statement (script (body) @lua)) +(lua_statement (chunk) @lua) +; (ruby_statement (script (body) @ruby)) +; (ruby_statement (chunk) @ruby) +; (python_statement (script (body) @python)) +; (python_statement (chunk) @python) +;; (perl_statement (script (body) @perl)) +;; (perl_statement (chunk) @perl) + +; (autocmd_statement (pattern) @regex) + +((set_item + option: (option_name) @_option + value: (set_value) @vim) + (#any-of? @_option + "includeexpr" "inex" + "printexpr" "pexpr" + "formatexpr" "fex" + "indentexpr" "inde" + "foldtext" "fdt" + "foldexpr" "fde" + "diffexpr" "dex" + "patchexpr" "pex" + "charconvert" "ccv")) + +; (comment) @comment diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 5a1081592e..5e38a8c2df 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -579,9 +579,9 @@ describe('treesitter highlighting', function() -- expect everything to have Error highlight screen:expect{grid=[[ {12:int}{8: x = INT_MAX;} | - {8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}| - {8:#define foo void main() { \} | - {8: return 42; \} | + {8:#define READ_STRING(x, y) (}{12:char_u}{8: *)read_string((x), (}{12:size_t}{8:)(y))}| + {8:#define foo }{12:void}{8: main() { \} | + {8: }{12:return}{8: 42; \} | {8: }} | ^ | {1:~ }|