diff options
| author | MDeiml <matthias@deiml.net> | 2022-01-08 01:37:18 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-01-08 13:27:25 +0100 |
| commit | 46b9916492910b3c008c815bb5884d3f8bdd469a (patch) | |
| tree | 9961220225077b7fddbd8163a7da51efe31e4d01 /lua/nvim-treesitter | |
| parent | 99d4d7e2d8c224089b30531592f9ae35a2313964 (diff) | |
Fix get_node_text
Diffstat (limited to 'lua/nvim-treesitter')
| -rw-r--r-- | lua/nvim-treesitter/ts_utils.lua | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 5733ce2b..b3261fd4 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -21,7 +21,10 @@ function M.get_node_text(node, bufnr) if start_row ~= end_row then local lines = api.nvim_buf_get_lines(bufnr, start_row, end_row + 1, false) lines[1] = string.sub(lines[1], start_col + 1) - lines[#lines] = string.sub(lines[#lines], 1, end_col) + -- end_row might be just after the last line. In this case the last line is not truncated. + if #lines == end_row - start_row then + lines[#lines] = string.sub(lines[#lines], 1, end_col) + end return lines else local line = api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1] |
