Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lua/codewindow/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,13 +98,22 @@ 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
-- 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
Expand All @@ -124,7 +132,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
Expand Down