Skip to content

Commit

Permalink
fix: avoid using -1 as a column
Browse files Browse the repository at this point in the history
Fixes #456
  • Loading branch information
lewis6991 committed Jul 5, 2024
1 parent 0734ffb commit 8198ad4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ end
local context_range = cache.memoize(function(node, query)
local bufnr = api.nvim_get_current_buf()
local range = { node:range() } --- @type Range4
range[3] = range[1]
range[4] = -1
range[3] = range[1] + 1
range[4] = 0

-- max_start_depth depth is only supported in nvim 0.10. It is ignored on
-- versions 0.9 or less. It is only needed to improve performance
Expand Down Expand Up @@ -133,8 +133,8 @@ local function trim_contexts(context_ranges, context_lines, trim, top)
table.remove(context_ranges, idx)
table.remove(context_lines, idx)
else
context_to_trim[3] = context_to_trim[3] - trim
context_to_trim[4] = -1
context_to_trim[3] = context_to_trim[3] - trim + (context_to_trim[4] == 0 and 0 or 1)
context_to_trim[4] = 0
local context_lines_to_trim = context_lines[idx]
for _ = 1, trim do
context_lines_to_trim[#context_lines_to_trim] = nil
Expand Down Expand Up @@ -167,7 +167,12 @@ local function get_text_for_range(range)
end_row = end_row - 1
end

return { start_row, 0, end_row, -1 }, lines
if end_col == -1 then
end_col = 0
end_row = end_row + 1
end

return { start_row, 0, end_row, end_col }, lines
end

local M = {}
Expand Down
2 changes: 1 addition & 1 deletion lua/treesitter-context/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ local function highlight_contexts(bufnr, ctx_bufnr, contexts)
local range = vim.treesitter.get_range(node, bufnr, metadata[capture])
local nsrow, nscol, nerow, necol = range[1], range[2], range[4], range[5]

if nerow > end_row or (nerow == end_row and necol > end_col and end_col ~= -1) then
if nerow > end_row or (nerow == end_row and necol > end_col) then
break
end

Expand Down

0 comments on commit 8198ad4

Please sign in to comment.