The Vue tree-sitter parser sets the injection language depending on how the is used:
https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/vue/injections.scm
; <script lang="ts">
((script_element
(start_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value (attribute_value) @_ts)))
(raw_text) @injection.content)
(#eq? @_lang "lang")
(#eq? @_ts "ts")
(#set! injection.language "typescript"))
This works great for highlighting, folds, etc. But when using treesitter-textobjects (https://github.com/nvim-treesitter/nvim-treesitter-textobjects) I cannot jump to any of the text objects that I can for the language that is being set by (#set! injection.language "typescript")
in the Vue tree-sitter injection.
Is there any way I can write a query that can match something like (function_declaration) @function
after the injection language is set? The vue treesitter parser (https://github.com/ikatyang/tree-sitter-vue) seems to only support the template nodes.
I tried something like:
(script_element
(start_tag
(tag_name
) @tag
((attribute
(attribute_name) @lang_key (#match? @lang_key "lang")
(quoted_attribute_value) @_lang (#match? @_lang "ts")
) @attr
)
) @start
(raw_text) @raw
(#set! injection.language "javascript")
(function_identifier) @func
)
Which results in the following error:
/usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:248: Query error at 13:4. Invalid node type "function_identifier":
(function_identifier) @_func
^
Thanks for your time.