diff options
author | Riley Bruins <ribru17@hotmail.com> | 2025-01-28 09:59:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-28 18:59:04 +0100 |
commit | b88874d33c15bb0fd7a421230f8bf819056d7665 (patch) | |
tree | 97b21d11ad7fd8b3fc8a1df828212a84a3bf4798 | |
parent | a119dab40f939121d5e5a0c622f19911c9c9ce03 (diff) | |
download | rneovim-b88874d33c15bb0fd7a421230f8bf819056d7665.tar.gz rneovim-b88874d33c15bb0fd7a421230f8bf819056d7665.tar.bz2 rneovim-b88874d33c15bb0fd7a421230f8bf819056d7665.zip |
fix(treesitter): empty queries can disable injections (#31748)
**Problem:** Currently, if users want to efficiently disable injections,
they have to delete the injection query files at their runtime path.
This is because we only check for existence of the files before running
the query over the entire buffer.
**Solution:** Check for existence of query files, *and* that those files
actually have captures. This will allow users to just comment out
existing queries (or better yet, just add their own injection query to
`~/.config/nvim` which contains only comments) to disable running the
query over the entire buffer (a potentially slow operation)
-rw-r--r-- | runtime/doc/treesitter.txt | 4 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/languagetree.lua | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 6286924f10..d87439a1e0 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -572,6 +572,10 @@ associated with patterns: • `injection.parent` - indicates that the captured node’s text should be parsed with the same language as the node's parent LanguageTree. +Injection queries are currently run over the entire buffer, which can be slow +for large buffers. To disable injections for, e.g., `c`, just place an +empty `queries/c/injections.scm` file in your 'runtimepath'. + ============================================================================== VIM.TREESITTER *lua-treesitter* diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index ecace67419..5e1156fa68 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -953,7 +953,7 @@ end --- @private --- @return table<string, Range6[][]> function LanguageTree:_get_injections() - if not self._injection_query then + if not self._injection_query or #self._injection_query.captures == 0 then return {} end |