From f84377ed9dc9dc8027f494046e0c409537e4565c Mon Sep 17 00:00:00 2001 From: taylrfnt Date: Mon, 5 Jan 2026 18:37:34 -0600 Subject: [PATCH 1/2] attempt fix of treesitter rewrite --- lua/codewindow/highlight.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/codewindow/highlight.lua b/lua/codewindow/highlight.lua index 535b43d..d9b7402 100644 --- a/lua/codewindow/highlight.lua +++ b/lua/codewindow/highlight.lua @@ -3,7 +3,6 @@ local M = {} local config = require("codewindow.config").get() local utils = require("codewindow.utils") local highlighter -local ts_utils local hl_namespace local screenbounds_namespace @@ -99,8 +98,11 @@ local function extract_highlighting(buffer, lines) if hl then local c = query._query.captures[capture] if c ~= nil then - local start_row, start_col, end_row, end_col = - ts_utils.get_vim_range({ vim.treesitter.get_node_range(node) }, buffer) + -- vim.treesitter.get_node_range returns 0-indexed rows and columns + -- Convert to 1-indexed for vim ranges + local start_row, start_col, end_row, end_col = vim.treesitter.get_node_range(node) + start_row = start_row + 1 + end_row = end_row + 1 for y = start_row, end_row do for x = start_col, math.min(end_col, minimap_char_width) do @@ -124,7 +126,6 @@ end if config.use_treesitter then highlighter = require("vim.treesitter.highlighter") - ts_utils = require("nvim-treesitter.ts_utils") M.extract_highlighting = extract_highlighting else M.extract_highlighting = function() end From 215b427db8bafaf7b5589c8b4ed5f5f84be476aa Mon Sep 17 00:00:00 2001 From: taylrfnt Date: Sat, 17 Jan 2026 11:57:55 -0600 Subject: [PATCH 2/2] bounds checking improvements & 1-index start col --- lua/codewindow/highlight.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/codewindow/highlight.lua b/lua/codewindow/highlight.lua index d9b7402..ef7f75b 100644 --- a/lua/codewindow/highlight.lua +++ b/lua/codewindow/highlight.lua @@ -99,15 +99,21 @@ local function extract_highlighting(buffer, lines) local c = query._query.captures[capture] if c ~= nil then -- vim.treesitter.get_node_range returns 0-indexed rows and columns - -- Convert to 1-indexed for vim ranges + -- Rows: 0-indexed inclusive -> 1-indexed inclusive + -- Cols: 0-indexed with end exclusive [start_col, end_col) -> 1-indexed inclusive local start_row, start_col, end_row, end_col = vim.treesitter.get_node_range(node) start_row = start_row + 1 end_row = end_row + 1 + start_col = start_col + 1 + -- end_col is already "one past" in 0-based; in 1-based it's the inclusive end for y = start_row, end_row do for x = start_col, math.min(end_col, minimap_char_width) do local minimap_x, minimap_y = utils.buf_to_minimap(x, y) - highlights[minimap_y][minimap_x][c] = (highlights[minimap_y][minimap_x][c] or 0) + 1 + if minimap_y >= 1 and minimap_y <= minimap_height + and minimap_x >= 1 and minimap_x <= minimap_width then + highlights[minimap_y][minimap_x][c] = (highlights[minimap_y][minimap_x][c] or 0) + 1 + end end end end