Closed wookayin closed 3 months ago
@kevinhwang91 You may want to test and make sure there is no performance regression on old neovim versions that are supported by nvim-ufo (0.7, 0.8, and 0.9). I wasn't sure how I can test the performance, so I will leave this part to you.
@kevinhwang91 What do you think?
ufo should be compatible with older nvim version, and nightly is not a stable version, should wait for the official release. FYI: https://launchpad.net/~neovim-ppa/+archive/ubuntu/stable
This change also works compatible with older nvim versions.
I just noticed nightly neovim crashes with ufo when treesitter is used to figure out folding. I wonder if all this could be related (didn't investigate yet)...?
I just noticed nightly neovim crashes with ufo when treesitter is used to figure out folding. I wonder if all this could be related (didn't investigate yet)...?
https://github.com/kevinhwang91/nvim-ufo/commit/e29dbf5b2d76ea43f4e585e3deeb6510488eee3f
@kevinhwang91 Is there anything else you'd like me to address for this PR?
Thanks!
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.