p00f/nvim-ts-rainbow

Cache parsers per buffer

Closed this issue · 1 comments

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

Sure, go ahead!