My nvim configuration
refactor(highlights): extract qf-line-highlights from claude-nvim
Move highlight module out of claude-nvim into top-level extensions so any qflist source (telescope, LSP, etc.) gets line highlights. Drop claude-specific highlight/blame config and prompt text tracking. Add changedtick polling to catch qflist changes from non-cmd sources.
6 files changed, +36 -34
+1-1claude-nvim/lua/claude/find.lua
| @@ -105,7 +105,7 @@ function M.find() | ||
| 105 | 105 | vim.fn.setqflist({}, " ", { title = query, items = items }) |
| 106 | 106 | vim.cmd("copen") |
| 107 | 107 | pcall(vim.cmd, "cc 2") |
| 108 | - pcall(function() require("claude.highlights").refresh_all() end) | |
| 108 | + pcall(function() require("extensions.qf-line-highlights").refresh_all() end) | |
| 109 | 109 | end)) |
| 110 | 110 | end) |
| 111 | 111 | end |
+0-6claude-nvim/lua/claude/init.lua
| @@ -2,7 +2,6 @@ local M = {} | ||
| 2 | 2 | |
| 3 | 3 | local ui = require("claude.ui") |
| 4 | 4 | local runner = require("claude.runner") |
| 5 | -local highlights = require("claude.highlights") | |
| 6 | 5 | local pickers = require("claude.pickers") |
| 7 | 6 | local edit = require("claude.edit") |
| 8 | 7 | local timetravel = require("claude.timetravel") |
| @@ -15,10 +14,6 @@ local defaults = { | ||
| 15 | 14 | width = 80, |
| 16 | 15 | --- Add --dangerously-skip-permissions flag to all claude commands (default: false) |
| 17 | 16 | skip_permissions = false, |
| 18 | - --- Highlight claude-changed lines like gitsigns (default: true) | |
| 19 | - highlight = true, | |
| 20 | - --- Inline blame: show prompt text on changed lines (default: true) | |
| 21 | - blame = true, | |
| 22 | 17 | --- Write raw stream events + cmd + exit codes to <data>/claude-nvim/debug.log |
| 23 | 18 | debug = false, |
| 24 | 19 | } |
| @@ -29,7 +24,6 @@ function M.setup(opts) | ||
| 29 | 24 | opts = vim.tbl_deep_extend("force", defaults, opts or {}) |
| 30 | 25 | ui.setup(opts) |
| 31 | 26 | runner.setup(opts) |
| 32 | - highlights.setup(opts) | |
| 33 | 27 | edit.setup(opts) |
| 34 | 28 | commit.setup(opts) |
| 35 | 29 | find.setup(opts) |
+1-1claude-nvim/lua/claude/pickers.lua
| @@ -34,7 +34,7 @@ function M.set_qf_from_prompt(p) | ||
| 34 | 34 | table.insert(items, 1, { text = "▌ " .. title, valid = 0 }) |
| 35 | 35 | vim.fn.setqflist({}, " ", { title = title, items = items }) |
| 36 | 36 | vim.cmd("copen") |
| 37 | - pcall(function() require("claude.highlights").refresh_all() end) | |
| 37 | + pcall(function() require("extensions.qf-line-highlights").refresh_all() end) | |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | function M.qf_last() |
+1-1claude-nvim/lua/claude/runner.lua
| @@ -96,7 +96,7 @@ local function flush_prompt(sid) | ||
| 96 | 96 | table.insert(st.session.prompts, p) |
| 97 | 97 | store.save(st.session) |
| 98 | 98 | vim.schedule(function() |
| 99 | - local ok_h, hl = pcall(require, "claude.highlights") | |
| 99 | + local ok_h, hl = pcall(require, "extensions.qf-line-highlights") | |
| 100 | 100 | if ok_h then hl.refresh_all() end |
| 101 | 101 | local ok_t, tt = pcall(require, "claude.timetravel") |
| 102 | 102 | if ok_t then tt.bump() end |
+1-0init.lua
| @@ -3,3 +3,4 @@ require("options") | ||
| 3 | 3 | require("functions") |
| 4 | 4 | require("commands") |
| 5 | 5 | require("keymaps") |
| 6 | +require("extensions.qf-line-highlights").setup() |
+32-25claude-nvim/lua/claude/highlights.lua → lua/extensions/qf-line-highlights.lua
| @@ -1,23 +1,7 @@ | ||
| 1 | 1 | local M = {} |
| 2 | 2 | |
| 3 | -local ns = vim.api.nvim_create_namespace("claude_changes") | |
| 4 | -local cfg = { highlight = true } | |
| 5 | - | |
| 6 | -function M.setup(opts) | |
| 7 | - cfg.highlight = opts.highlight ~= false | |
| 8 | - | |
| 9 | - vim.api.nvim_set_hl(0, "ClaudeChange", { default = true, bg = "#3a2410" }) | |
| 10 | - | |
| 11 | - vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "BufEnter" }, { | |
| 12 | - callback = function(args) | |
| 13 | - M.apply_to_buf(args.buf) | |
| 14 | - end, | |
| 15 | - }) | |
| 16 | - | |
| 17 | - vim.api.nvim_create_autocmd({ "QuickFixCmdPost" }, { | |
| 18 | - callback = function() M.refresh_all() end, | |
| 19 | - }) | |
| 20 | -end | |
| 3 | +local ns = vim.api.nvim_create_namespace("qf_line_highlights") | |
| 4 | +local cfg = { hl_group = "QfLineHl" } | |
| 21 | 5 | |
| 22 | 6 | local function qf_item_path(item) |
| 23 | 7 | if item.filename and item.filename ~= "" then return item.filename end |
| @@ -29,15 +13,14 @@ end | ||
| 29 | 13 | |
| 30 | 14 | local function collect_for_path(abs_path) |
| 31 | 15 | local out = {} |
| 32 | - local items = vim.fn.getqflist() | |
| 33 | - for _, item in ipairs(items) do | |
| 16 | + for _, item in ipairs(vim.fn.getqflist()) do | |
| 34 | 17 | local fname = qf_item_path(item) |
| 35 | 18 | if fname and fname ~= "" then |
| 36 | 19 | local p = vim.fn.fnamemodify(fname, ":p") |
| 37 | 20 | if p == abs_path and item.lnum and item.lnum > 0 then |
| 38 | 21 | local s = item.lnum |
| 39 | 22 | local e = (item.end_lnum and item.end_lnum > 0) and item.end_lnum or s |
| 40 | - table.insert(out, { start = s, finish = e, prompt = item.text or "" }) | |
| 23 | + table.insert(out, { start = s, finish = e }) | |
| 41 | 24 | end |
| 42 | 25 | end |
| 43 | 26 | end |
| @@ -46,7 +29,6 @@ end | ||
| 46 | 29 | |
| 47 | 30 | function M.apply_to_buf(buf) |
| 48 | 31 | if not vim.api.nvim_buf_is_valid(buf) then return end |
| 49 | - if not cfg.highlight then return end | |
| 50 | 32 | local name = vim.api.nvim_buf_get_name(buf) |
| 51 | 33 | if name == "" then return end |
| 52 | 34 | if vim.bo[buf].buftype ~= "" then return end |
| @@ -60,9 +42,7 @@ function M.apply_to_buf(buf) | ||
| 60 | 42 | local e = math.min(lc - 1, (h.finish or h.start or 1) - 1) |
| 61 | 43 | if e < s then e = s end |
| 62 | 44 | for ln = s, e do |
| 63 | - if cfg.highlight then | |
| 64 | - pcall(vim.api.nvim_buf_set_extmark, buf, ns, ln, 0, { line_hl_group = "ClaudeChange" }) | |
| 65 | - end | |
| 45 | + pcall(vim.api.nvim_buf_set_extmark, buf, ns, ln, 0, { line_hl_group = cfg.hl_group }) | |
| 66 | 46 | end |
| 67 | 47 | end |
| 68 | 48 | end |
| @@ -75,4 +55,31 @@ function M.refresh_all() | ||
| 75 | 55 | end |
| 76 | 56 | end |
| 77 | 57 | |
| 58 | +function M.setup(opts) | |
| 59 | + opts = opts or {} | |
| 60 | + if opts.hl_group then cfg.hl_group = opts.hl_group end | |
| 61 | + | |
| 62 | + vim.api.nvim_set_hl(0, "QfLineHl", { default = true, bg = "#3a2410" }) | |
| 63 | + | |
| 64 | + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "BufEnter" }, { | |
| 65 | + callback = function(args) M.apply_to_buf(args.buf) end, | |
| 66 | + }) | |
| 67 | + | |
| 68 | + vim.api.nvim_create_autocmd({ "QuickFixCmdPost" }, { | |
| 69 | + callback = function() M.refresh_all() end, | |
| 70 | + }) | |
| 71 | + | |
| 72 | + -- Detect qflist changes from any source (Lua setqflist by telescope/LSP/etc.). | |
| 73 | + local last_tick = -1 | |
| 74 | + vim.api.nvim_create_autocmd({ "CursorHold", "WinEnter", "BufWinEnter", "FocusGained" }, { | |
| 75 | + callback = function() | |
| 76 | + local tick = (vim.fn.getqflist({ changedtick = 0 }) or {}).changedtick or 0 | |
| 77 | + if tick ~= last_tick then | |
| 78 | + last_tick = tick | |
| 79 | + M.refresh_all() | |
| 80 | + end | |
| 81 | + end, | |
| 82 | + }) | |
| 83 | +end | |
| 84 | + | |
| 78 | 85 | return M |