nvim-ufo
nvim-ufo copied to clipboard
refactor(treesitter): remove nvim-treesitter dependencies
Replace all the use of nvim-treesitter APIs with core vim.treesitter APIs. No more nvim-treesitter dependency, just core neovim is enough.
This fix makes ufo work without the nvim-treesitter plugin as an
additional dependency. In fact, nvim-treesitter v1.0 deprecates and
removes some APIs that have been migrated to the core neovim APIs
vim.treesitter
, which makes ufo's previous treesitter provider
implementation incompatible.
Note that this commit does not change the minimum neovim version requirement, should work fine with neovim 0.7.x.
Implementation note:
There are four APIs that need to be migrated:
-
nvim-treesitter.parsers.get_parser()
: The difference to the core APIvim.treesitter.get_parser()
is whether to throw errors when a parser is not available (has_parser
). We simply mimic the previous behavior by catching errors. -
nvim-treesitter.query.get_query()
: The difference to core APIvim.treesitter.query.get()
is whether the query file is cached or not. This may have a small performance impact; in neovim 0.10.x, this function is memoized and thus very fast, but in neovim <= 0.9.x it might be slightly slow due to the lack of cache.Note: One can consider as well automatically falling back to the old nvim-treesitter (v0.9.x) if available, for neovim < 0.10.
-
nvim-treesitter.query.has_folds()
(i.e.,has_query_files()
): can be easily replaced withvim.treesitter.query.get_files
. Also there might be a subtle performance difference of whether cache is being used (in the old nvim-treesitter implementations) or not. -
nvim-treesitter.tsrange
: TheTSRange
API has gone. Note that this is used only to implement the#make-range!
directive; it suffices to havenode:range()
only for where it's used. Therefore,TSRange.from_nodes()
is the only API we'll need, which can be easily backported into the existingMetaNode
implementation.