mirror of
https://github.com/neovim/neovim.git
synced 2025-11-17 15:51:32 +00:00
feat(treesitter)!: don't parse tree in get_parser() or start()
**Problem:** `vim.treesitter.get_parser()` and `vim.treesitter.start()` both parse the tree before returning it. This is problematic because if this is a sync parse, it will stall the editor on large files. If it is an async parse, the functions return stale trees. **Solution:** Remove this parsing side effect and leave it to the user to parse the returned trees, either synchronously or asynchronously.
This commit is contained in:
@@ -117,6 +117,7 @@ describe('treesitter language API', function()
|
||||
'<node translation_unit>',
|
||||
exec_lua(function()
|
||||
local langtree = vim.treesitter.get_parser(0, 'c')
|
||||
langtree:parse()
|
||||
local tree = langtree:tree_for_range({ 1, 3, 1, 3 })
|
||||
return tostring(tree:root())
|
||||
end)
|
||||
@@ -133,6 +134,7 @@ describe('treesitter language API', function()
|
||||
'<node translation_unit>',
|
||||
exec_lua(function()
|
||||
local langtree = vim.treesitter.get_parser(0, 'c')
|
||||
langtree:parse()
|
||||
local tree = langtree:tree_for_range({ 10, 10, 10, 10 })
|
||||
return tostring(tree:root())
|
||||
end)
|
||||
@@ -149,6 +151,7 @@ describe('treesitter language API', function()
|
||||
'<node primitive_type>',
|
||||
exec_lua(function()
|
||||
local langtree = vim.treesitter.get_parser(0, 'c')
|
||||
langtree:parse()
|
||||
local node = langtree:named_node_for_range({ 1, 3, 1, 3 })
|
||||
return tostring(node)
|
||||
end)
|
||||
@@ -160,6 +163,7 @@ describe('treesitter language API', function()
|
||||
|
||||
exec_lua(function()
|
||||
_G.langtree = vim.treesitter.get_parser(0, 'lua')
|
||||
_G.langtree:parse()
|
||||
_G.node = _G.langtree:node_for_range({ 0, 3, 0, 3 })
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user