mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
Merge pull request #17365 from kevinhwang91/fix-ts-empty-lines
fix(query.lua): check empty table for lines
This commit is contained in:
@@ -199,11 +199,13 @@ function M.get_node_text(node, source)
|
|||||||
lines = a.nvim_buf_get_lines(source, start_row, end_row + 1, true)
|
lines = a.nvim_buf_get_lines(source, start_row, end_row + 1, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
if #lines == 1 then
|
if #lines > 0 then
|
||||||
lines[1] = string.sub(lines[1], start_col+1, end_col)
|
if #lines == 1 then
|
||||||
else
|
lines[1] = string.sub(lines[1], start_col+1, end_col)
|
||||||
lines[1] = string.sub(lines[1], start_col+1)
|
else
|
||||||
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
lines[1] = string.sub(lines[1], start_col+1)
|
||||||
|
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(lines, "\n")
|
return table.concat(lines, "\n")
|
||||||
|
@@ -285,6 +285,25 @@ end]]
|
|||||||
eq(true, result)
|
eq(true, result)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('support getting empty text if node range is zero width', function()
|
||||||
|
local text = [[
|
||||||
|
```lua
|
||||||
|
{}
|
||||||
|
```]]
|
||||||
|
insert(text)
|
||||||
|
local result = exec_lua([[
|
||||||
|
local fake_node = {}
|
||||||
|
function fake_node:start()
|
||||||
|
return 1, 0, 7
|
||||||
|
end
|
||||||
|
function fake_node:end_()
|
||||||
|
return 1, 0, 7
|
||||||
|
end
|
||||||
|
return vim.treesitter.get_node_text(fake_node, 0) == ''
|
||||||
|
]])
|
||||||
|
eq(true, result)
|
||||||
|
end)
|
||||||
|
|
||||||
it('can match special regex characters like \\ * + ( with `vim-match?`', function()
|
it('can match special regex characters like \\ * + ( with `vim-match?`', function()
|
||||||
insert('char* astring = "\\n"; (1 + 1) * 2 != 2;')
|
insert('char* astring = "\\n"; (1 + 1) * 2 != 2;')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user