mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(treesitter): use tree range instead of tree root node range
This commit is contained in:
parent
81fc27124b
commit
00e6651880
@ -1100,7 +1100,14 @@ end
|
|||||||
---@param range Range
|
---@param range Range
|
||||||
---@return boolean
|
---@return boolean
|
||||||
local function tree_contains(tree, range)
|
local function tree_contains(tree, range)
|
||||||
return Range.contains({ tree:root():range() }, range)
|
local tree_ranges = tree:included_ranges(false)
|
||||||
|
|
||||||
|
return Range.contains({
|
||||||
|
tree_ranges[1][1],
|
||||||
|
tree_ranges[1][2],
|
||||||
|
tree_ranges[#tree_ranges][3],
|
||||||
|
tree_ranges[#tree_ranges][4],
|
||||||
|
}, range)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Determines whether {range} is contained in the |LanguageTree|.
|
--- Determines whether {range} is contained in the |LanguageTree|.
|
||||||
|
@ -495,22 +495,21 @@ describe('commenting', function()
|
|||||||
it("recomputes local 'commentstring' based on cursor position", function()
|
it("recomputes local 'commentstring' based on cursor position", function()
|
||||||
setup_treesitter()
|
setup_treesitter()
|
||||||
local lines = {
|
local lines = {
|
||||||
|
' print(1)',
|
||||||
'lua << EOF',
|
'lua << EOF',
|
||||||
' print(1)',
|
' print(1)',
|
||||||
'EOF',
|
'EOF',
|
||||||
}
|
}
|
||||||
set_lines(lines)
|
set_lines(lines)
|
||||||
|
|
||||||
-- Vimscript's tree-sitter grammar is (currently) written in a way that Lua's
|
set_cursor(1, 1)
|
||||||
-- injection really starts at the first non-blank character
|
|
||||||
set_cursor(2, 1)
|
|
||||||
feed('gc_')
|
feed('gc_')
|
||||||
eq(get_lines()[2], ' "print(1)')
|
eq(get_lines()[1], ' "print(1)')
|
||||||
|
|
||||||
set_lines(lines)
|
set_lines(lines)
|
||||||
set_cursor(2, 2)
|
set_cursor(3, 2)
|
||||||
feed('.')
|
feed('.')
|
||||||
eq(get_lines()[2], ' -- print(1)')
|
eq(get_lines()[3], ' -- print(1)')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('preserves marks', function()
|
it('preserves marks', function()
|
||||||
|
@ -120,6 +120,20 @@ describe('treesitter language API', function()
|
|||||||
eq('<node translation_unit>', exec_lua('return tostring(tree:root())'))
|
eq('<node translation_unit>', exec_lua('return tostring(tree:root())'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('retrieve the tree given a range when range is out of bounds relative to buffer', function()
|
||||||
|
insert([[
|
||||||
|
int main() {
|
||||||
|
int x = 3;
|
||||||
|
}]])
|
||||||
|
|
||||||
|
exec_lua([[
|
||||||
|
langtree = vim.treesitter.get_parser(0, "c")
|
||||||
|
tree = langtree:tree_for_range({10, 10, 10, 10})
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq('<node translation_unit>', exec_lua('return tostring(tree:root())'))
|
||||||
|
end)
|
||||||
|
|
||||||
it('retrieve the node given a range', function()
|
it('retrieve the node given a range', function()
|
||||||
insert([[
|
insert([[
|
||||||
int main() {
|
int main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user