feat(treesitter): add injections

This commit is contained in:
Christian Clason 2022-09-04 16:37:24 +02:00
parent e85b8aa768
commit 64cc78c9f3
4 changed files with 54 additions and 3 deletions

View File

@ -0,0 +1,3 @@
(preproc_arg) @c
; (comment) @comment

View File

@ -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

View File

@ -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

View File

@ -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:~ }|