mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
treesitter: test newly added set_included_ranges
This commit is contained in:
@@ -447,8 +447,9 @@ static int parser_set_ranges(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: For sure that's wrong, try to find a way to get the byte offset directly
|
// TODO: For sure that's wrong, try to find a way to get the byte offset directly
|
||||||
uint32_t start_byte = ml_find_line_or_offset(buf, start_row, NULL, false) + start_col;
|
// Lines are 0 based for consistency
|
||||||
uint32_t stop_byte = ml_find_line_or_offset(buf, stop_row, NULL, false) + stop_col;
|
uint32_t start_byte = ml_find_line_or_offset(buf, start_row + 1, NULL, false) + start_col;
|
||||||
|
uint32_t stop_byte = ml_find_line_or_offset(buf, stop_row + 1, NULL, false) + stop_col;
|
||||||
|
|
||||||
ranges[index] = (TSRange) {
|
ranges[index] = (TSRange) {
|
||||||
.start_point = (TSPoint) {
|
.start_point = (TSPoint) {
|
||||||
|
@@ -404,4 +404,44 @@ static int nlua_schedule(lua_State *const lstate)
|
|||||||
end
|
end
|
||||||
eq({true,true}, {has_named,has_anonymous})
|
eq({true,true}, {has_named,has_anonymous})
|
||||||
end)
|
end)
|
||||||
|
it('allows to set ranges', function()
|
||||||
|
if not check_parser() then return end
|
||||||
|
|
||||||
|
insert(test_text)
|
||||||
|
|
||||||
|
local res = exec_lua([[
|
||||||
|
parser = vim.treesitter.get_parser(0, "c")
|
||||||
|
return { parser:parse():root():range() }
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({0, 0, 19, 0}, res)
|
||||||
|
|
||||||
|
local res = exec_lua([[
|
||||||
|
parser:set_included_ranges({{0, 0, 1, 0}})
|
||||||
|
parser.valid = false
|
||||||
|
return { parser:parse():root():range() }
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({0, 0, 1, 0}, res)
|
||||||
|
|
||||||
|
-- Pick random samples
|
||||||
|
local res = exec_lua([[
|
||||||
|
parser:set_included_ranges({{8, 0, 9, 0}, {12, 0, 13 ,0}})
|
||||||
|
local root = parser:parse():root()
|
||||||
|
return {{root:child(0):range()}, {root:child(1):range()}}
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({{
|
||||||
|
8,
|
||||||
|
2,
|
||||||
|
8,
|
||||||
|
33
|
||||||
|
},
|
||||||
|
{
|
||||||
|
12,
|
||||||
|
4,
|
||||||
|
12,
|
||||||
|
37
|
||||||
|
}}, res)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user