How to refresh tree-sitter parser after vim.opt.rtp
has changed and new queries are now available?
#28708
Unanswered
DanilaMihailov
asked this question in
Q&A
Replies: 1 comment
-
found a way to do this, but it requires use of private field local parser = vim.treesitter.get_parser()
parser._injection_query = vim.treesitter.query.get("lua", "injections")
parser:invalidate(true)
parser:parse(true) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'am adding tree-sitter queries to a plugin. Into directory
after/queries/lua/injections.scm
. Everything works great only if plugin is not loaded lazily.I'am using lazy.nvim, but in any way it basically does
vim.opt.rtp:append("path/to/plugin")
. The problem is - before plugin loaded lazily, I already have tree-sitter parser running for buffer (filetype plugin already run and calledvim.treesitter.run()
). And tree-sitter reads query files once per "parser" (vim.treesitter.LanguageTree
), but my plugin is not loaded yet, sovim.opt.rtp
does not contain path to my plugin.The only way I found to trigger reloading parser is by doing
:edit
, which drops parser for current buffer and creates new one. New parser now sees updatedruntimepath
and loads my queries.I tried doing something like this
but
parser:destroy()
actually does nothing. And calls toget_parser
return cached parser for current buffer. The only way parser is removed is by an eventnvim_buf_detach_event[{buf}]
(:h nvim_buf_detach_event
). Which is triggered when buffer is closed or reloaded with:edit
.Is there a better way to refresh parser? Or another way to add queries via plugin that is lazily loaded?
Beta Was this translation helpful? Give feedback.
All reactions