Plugin does not work in files where treesitter is not enabled if treesitter is installed
bagohart opened this issue · comments
In contrast to my last issues (sorry for spamming your repo with issues xD ) I have treesitter installed currently.
Then I open a boring text file without file type, and when I now press ^X^L
with this configuration:
['<C-x><C-l>'] = cmp.mapping.complete({ -- manual ^X^L is broken,
config = {
sources = {
{ name = 'buffer-lines' },
option = {
words = false, -- include (true) or skip (false) lines that are a single word
comments = true, -- include (true) or strip (false) comments on insertion (probably only trailing comments? like `command --comment`)
leading_whitespace = true, -- show leading whitespace, is stripped on buffer insertion in any case.
max_size = 100000, -- kB
},
},
},
}),
I get the following error message:
E5108: Error executing lua: Failed to load parser: uv_dlopen: /home/bagohart/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/.: cannot read file data: Is a directory
stack traceback:
[C]: in function '_ts_add_language'
/usr/share/nvim/runtime/lua/vim/treesitter/language.lua:36: in function 'require_language'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:38: in function '_create_parser'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:96: in function 'get_parser'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:287: in function 'get_node_at_pos'
.../nvim-cmp-buffer-lines/lua/cmp-buffer-lines/complete.lua:31: in function 'rmcomments'
.../nvim-cmp-buffer-lines/lua/cmp-buffer-lines/complete.lua:110: in function 'generate'
.../nvim-cmp-buffer-lines/lua/cmp-buffer-lines/complete.lua:158: in function 'complete'
...re/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/source.lua:325: in function 'complete'
...hare/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/core.lua:289: in function 'complete'
...hare/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/init.lua:77: in function 'complete'
...site/pack/packer/opt/nvim-cmp/lua/cmp/config/mapping.lua:113: in function 'on_keymap'
...hare/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/core.lua:145: in function 'callback'
...m/site/pack/packer/opt/nvim-cmp/lua/cmp/utils/keymap.lua:133: in function <...m/site/pack/packer/opt/nvim-cmp/lua/cmp/utils/keymap.lua:127>
Looks like this plugin tries to use treesitter when it's installed even if it's not active for the current filetype.
An obvious workaround is to only enable this plugin for certain filetypes (the readme describes how) but I would expect it in this case to just not use treesitter.
I'm new to treesitter, so I have no idea if there's an easy way to query it if it's active in the current buffer, but I would assume there should be. Maybe like this?
https://neovim.discourse.group/t/check-if-treesitter-is-enabled-in-the-current-buffer/902
It should be fixed in the latest commit. Please test it.
I can't reproduce the error anymore, looks good! Nice!