p00f / nvim-ts-rainbow

Rainbow parentheses for neovim using tree-sitter. Use https://sr.ht/~p00f/nvim-ts-rainbow instead
Apache License 2.0
869 stars 67 forks source link

Cache parsers per buffer #106

Closed HiPhish closed 2 years ago

HiPhish commented 2 years ago

Currently the plugin relies on the fact that vim.treesitter.get_parser retains the same parser instance over the lifetime of the buffer. The function is not called directly, instead get_parser from nvim-treesitter gets called, which is a wrapper around the standard function.

The Neovim documentation states the following:

Currently, the parser will be retained for the lifetime of a buffer but this is subject to change. A plugin should keep a reference to the parser object as long as it wants incremental updates.

See :h treesitter-parsers

We should maintain a table that maps a buffer ID to a parser instance. This will keep the parser alive instead of letting it become garbage. The reference needs to be deleted when a buffer is detached again.

If you agree I would like to give this a try myself, I think it makes a good first issue.

p00f commented 2 years ago

Sure, go ahead!