From e25fb0f297f45491d0853dfe12f8ff32cbbad7ab Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 2 Feb 2026 14:04:24 -0500 Subject: [PATCH] fix(ci): typing --- lua/fugitive-ts/highlight.lua | 86 +++++++++++++++++------------------ lua/fugitive-ts/init.lua | 6 ++- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/lua/fugitive-ts/highlight.lua b/lua/fugitive-ts/highlight.lua index 3a16799..755c983 100644 --- a/lua/fugitive-ts/highlight.lua +++ b/lua/fugitive-ts/highlight.lua @@ -90,49 +90,6 @@ function M.highlight_hunk(bufnr, ns, hunk, opts) return end - ---@type string[] - local code_lines = {} - for _, line in ipairs(hunk.lines) do - table.insert(code_lines, line:sub(2)) - end - - local code = table.concat(code_lines, '\n') - if code == '' then - return - end - - local ok, parser_obj = pcall(vim.treesitter.get_string_parser, code, lang) - if not ok or not parser_obj then - dbg('failed to create parser for lang: %s', lang) - return - end - - local trees = parser_obj:parse() - if not trees or #trees == 0 then - dbg('parse returned no trees for lang: %s', lang) - return - end - - local query = vim.treesitter.query.get(lang, 'highlights') - if not query then - dbg('no highlights query for lang: %s', lang) - return - end - - if hunk.header_context and hunk.header_context_col then - local header_line = hunk.start_line - 1 - pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, header_line, hunk.header_context_col, { - end_col = hunk.header_context_col + #hunk.header_context, - hl_group = 'Normal', - priority = 199, - }) - local header_extmarks = - highlight_text(bufnr, ns, hunk, hunk.header_context_col, hunk.header_context, lang) - if header_extmarks > 0 then - dbg('header %s:%d applied %d extmarks', hunk.filename, hunk.start_line, header_extmarks) - end - end - for i, line in ipairs(hunk.lines) do local buf_line = hunk.start_line + i - 1 local line_len = #line @@ -176,6 +133,49 @@ function M.highlight_hunk(bufnr, ns, hunk, opts) return end + ---@type string[] + local code_lines = {} + for _, line in ipairs(hunk.lines) do + table.insert(code_lines, line:sub(2)) + end + + local code = table.concat(code_lines, '\n') + if code == '' then + return + end + + local ok, parser_obj = pcall(vim.treesitter.get_string_parser, code, lang) + if not ok or not parser_obj then + dbg('failed to create parser for lang: %s', lang) + return + end + + local trees = parser_obj:parse() + if not trees or #trees == 0 then + dbg('parse returned no trees for lang: %s', lang) + return + end + + local query = vim.treesitter.query.get(lang, 'highlights') + if not query then + dbg('no highlights query for lang: %s', lang) + return + end + + if hunk.header_context and hunk.header_context_col then + local header_line = hunk.start_line - 1 + pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, header_line, hunk.header_context_col, { + end_col = hunk.header_context_col + #hunk.header_context, + hl_group = 'Normal', + priority = 199, + }) + local header_extmarks = + highlight_text(bufnr, ns, hunk, hunk.header_context_col, hunk.header_context, lang) + if header_extmarks > 0 then + dbg('header %s:%d applied %d extmarks', hunk.filename, hunk.start_line, header_extmarks) + end + end + local extmark_count = 0 for id, node, _ in query:iter_captures(trees[1]:root(), code) do local capture_name = '@' .. query.captures[id] diff --git a/lua/fugitive-ts/init.lua b/lua/fugitive-ts/init.lua index 028275b..e57d817 100644 --- a/lua/fugitive-ts/init.lua +++ b/lua/fugitive-ts/init.lua @@ -25,6 +25,8 @@ local parser = require('fugitive-ts.parser') local ns = vim.api.nvim_create_namespace('fugitive_ts') +---@diagnostic disable: undefined-global + ---@param hex integer ---@param bg_hex integer ---@param alpha number @@ -45,8 +47,10 @@ local function blend_color(hex, bg_hex, alpha) return bit.bor(bit.lshift(blend_r, 16), bit.lshift(blend_g, 8), blend_b) end +---@diagnostic enable: undefined-global + ---@param name string ----@return vim.api.keyset.hl_info +---@return table local function resolve_hl(name) local hl = vim.api.nvim_get_hl(0, { name = name }) while hl.link do