refactor(treesitter): use scratch buffer for string parser #35988

This commit changes `languagetree.lua` so that it creates a scratch
buffer under the hood when dealing with string parsers. This will make
it much easier to just use extmarks whenever we need to track injection
trees in `languagetree.lua`. This also allows us to remove the
`treesitter.c` code for parsing a string directly.

Note that the string parser's scratch buffer has `set noeol nofixeol` so
that the parsed source exactly matches the passed in string.
This commit is contained in:
Riley Bruins
2025-10-02 15:33:18 -07:00
committed by GitHub
parent 8eb0964537
commit ac15b384a6
5 changed files with 66 additions and 62 deletions

View File

@@ -1264,6 +1264,12 @@ print()
parser:for_each_tree(function(tstree, tree)
ranges[tree:lang()] = { tstree:root():range(true) }
end)
-- Scratch buffer should get cleaned up
assert(vim.api.nvim_buf_is_loaded(parser:source()))
parser:destroy()
assert(not vim.api.nvim_buf_is_loaded(parser:source()))
return ranges
end)