My nvim configuration
fix(claude): highlight only shows on current quickfix list and buffer scrolls on submit
3 files changed, +71 -39
+22-13claude-nvim/lua/claude/highlights.lua
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | local M = {} |
| 2 | 2 | |
| 3 | -local store = require("claude.store") | |
| 4 | 3 | local ns = vim.api.nvim_create_namespace("claude_changes") |
| 5 | 4 | local cfg = { highlight = true, blame = true } |
| 6 | 5 | |
| @@ -12,26 +11,36 @@ function M.setup(opts) | ||
| 12 | 11 | vim.api.nvim_set_hl(0, "ClaudeChangeSign", { default = true, fg = "#e07b00" }) |
| 13 | 12 | vim.api.nvim_set_hl(0, "ClaudeBlame", { default = true, fg = "#7f5a2a", italic = true }) |
| 14 | 13 | |
| 15 | - vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost" }, { | |
| 14 | + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "BufEnter" }, { | |
| 16 | 15 | callback = function(args) |
| 17 | 16 | M.apply_to_buf(args.buf) |
| 18 | 17 | end, |
| 19 | 18 | }) |
| 19 | + | |
| 20 | + vim.api.nvim_create_autocmd({ "QuickFixCmdPost" }, { | |
| 21 | + callback = function() M.refresh_all() end, | |
| 22 | + }) | |
| 23 | +end | |
| 24 | + | |
| 25 | +local function qf_item_path(item) | |
| 26 | + if item.filename and item.filename ~= "" then return item.filename end | |
| 27 | + if item.bufnr and item.bufnr > 0 and vim.api.nvim_buf_is_valid(item.bufnr) then | |
| 28 | + return vim.api.nvim_buf_get_name(item.bufnr) | |
| 29 | + end | |
| 30 | + return nil | |
| 20 | 31 | end |
| 21 | 32 | |
| 22 | 33 | local function collect_for_path(abs_path) |
| 23 | 34 | local out = {} |
| 24 | - for _, p in ipairs(store.all_prompts()) do | |
| 25 | - for _, f in ipairs(p.files or {}) do | |
| 26 | - if f.path == abs_path then | |
| 27 | - for _, h in ipairs(f.hunks or {}) do | |
| 28 | - table.insert(out, { | |
| 29 | - start = h.start, | |
| 30 | - finish = h.finish, | |
| 31 | - prompt = p.text or "", | |
| 32 | - ts = p.ts or 0, | |
| 33 | - }) | |
| 34 | - end | |
| 35 | + local items = vim.fn.getqflist() | |
| 36 | + for _, item in ipairs(items) do | |
| 37 | + local fname = qf_item_path(item) | |
| 38 | + if fname and fname ~= "" then | |
| 39 | + local p = vim.fn.fnamemodify(fname, ":p") | |
| 40 | + if p == abs_path and item.lnum and item.lnum > 0 then | |
| 41 | + local s = item.lnum | |
| 42 | + local e = (item.end_lnum and item.end_lnum > 0) and item.end_lnum or s | |
| 43 | + table.insert(out, { start = s, finish = e, prompt = item.text or "" }) | |
| 35 | 44 | end |
| 36 | 45 | end |
| 37 | 46 | end |
+1-0claude-nvim/lua/claude/pickers.lua
| @@ -27,6 +27,7 @@ function M.set_qf_from_prompt(p) | ||
| 27 | 27 | items = items, |
| 28 | 28 | }) |
| 29 | 29 | vim.cmd("copen") |
| 30 | + pcall(function() require("claude.highlights").refresh_all() end) | |
| 30 | 31 | end |
| 31 | 32 | |
| 32 | 33 | function M.qf_last() |
+48-26claude-nvim/lua/claude/ui.lua
| @@ -9,53 +9,72 @@ local panel = { | ||
| 9 | 9 | |
| 10 | 10 | local spinner = { |
| 11 | 11 | timer = nil, |
| 12 | - line = nil, | |
| 13 | 12 | frame = 1, |
| 14 | 13 | frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }, |
| 14 | + active = false, | |
| 15 | + row = nil, | |
| 15 | 16 | } |
| 16 | 17 | |
| 18 | +local function spinner_text() | |
| 19 | + return spinner.frames[spinner.frame] .. " thinking…" | |
| 20 | +end | |
| 21 | + | |
| 22 | +local function scroll_to_bottom_now() | |
| 23 | + if panel.win and vim.api.nvim_win_is_valid(panel.win) then | |
| 24 | + pcall(vim.api.nvim_win_call, panel.win, function() | |
| 25 | + vim.cmd("normal! G") | |
| 26 | + end) | |
| 27 | + end | |
| 28 | +end | |
| 29 | + | |
| 30 | +local function spinner_remove_if_present() | |
| 31 | + if spinner.row == nil then return end | |
| 32 | + if not panel.buf or not vim.api.nvim_buf_is_valid(panel.buf) then | |
| 33 | + spinner.row = nil | |
| 34 | + return | |
| 35 | + end | |
| 36 | + local lc = vim.api.nvim_buf_line_count(panel.buf) | |
| 37 | + if spinner.row < lc then | |
| 38 | + vim.bo[panel.buf].modifiable = true | |
| 39 | + pcall(vim.api.nvim_buf_set_lines, panel.buf, spinner.row, spinner.row + 1, false, {}) | |
| 40 | + vim.bo[panel.buf].modifiable = false | |
| 41 | + end | |
| 42 | + spinner.row = nil | |
| 43 | +end | |
| 44 | + | |
| 17 | 45 | local function spinner_render() |
| 46 | + if not spinner.active then return end | |
| 18 | 47 | if not panel.buf or not vim.api.nvim_buf_is_valid(panel.buf) then return end |
| 19 | - local txt = spinner.frames[spinner.frame] .. " thinking…" | |
| 20 | 48 | vim.bo[panel.buf].modifiable = true |
| 21 | - local appended = false | |
| 22 | - if spinner.line ~= nil and spinner.line < vim.api.nvim_buf_line_count(panel.buf) then | |
| 23 | - pcall(vim.api.nvim_buf_set_lines, panel.buf, spinner.line, spinner.line + 1, false, { txt }) | |
| 49 | + if spinner.row ~= nil and spinner.row < vim.api.nvim_buf_line_count(panel.buf) then | |
| 50 | + pcall(vim.api.nvim_buf_set_lines, panel.buf, spinner.row, spinner.row + 1, false, { spinner_text() }) | |
| 24 | 51 | else |
| 25 | 52 | local lc = vim.api.nvim_buf_line_count(panel.buf) |
| 26 | - pcall(vim.api.nvim_buf_set_lines, panel.buf, lc, lc, false, { txt }) | |
| 27 | - spinner.line = lc | |
| 28 | - appended = true | |
| 53 | + pcall(vim.api.nvim_buf_set_lines, panel.buf, lc, lc, false, { spinner_text() }) | |
| 54 | + spinner.row = lc | |
| 29 | 55 | end |
| 30 | 56 | vim.bo[panel.buf].modifiable = false |
| 31 | - if appended and panel.win and vim.api.nvim_win_is_valid(panel.win) then | |
| 32 | - local lc = vim.api.nvim_buf_line_count(panel.buf) | |
| 33 | - pcall(vim.api.nvim_win_set_cursor, panel.win, { lc, 0 }) | |
| 34 | - end | |
| 57 | + scroll_to_bottom_now() | |
| 35 | 58 | end |
| 36 | 59 | |
| 37 | 60 | local function spinner_stop() |
| 61 | + spinner.active = false | |
| 38 | 62 | if spinner.timer then |
| 39 | 63 | spinner.timer:stop() |
| 40 | 64 | if not spinner.timer:is_closing() then spinner.timer:close() end |
| 41 | 65 | spinner.timer = nil |
| 42 | 66 | end |
| 43 | - if spinner.line ~= nil and panel.buf and vim.api.nvim_buf_is_valid(panel.buf) then | |
| 44 | - if spinner.line < vim.api.nvim_buf_line_count(panel.buf) then | |
| 45 | - vim.bo[panel.buf].modifiable = true | |
| 46 | - pcall(vim.api.nvim_buf_set_lines, panel.buf, spinner.line, spinner.line + 1, false, {}) | |
| 47 | - vim.bo[panel.buf].modifiable = false | |
| 48 | - end | |
| 49 | - end | |
| 50 | - spinner.line = nil | |
| 67 | + spinner_remove_if_present() | |
| 51 | 68 | end |
| 52 | 69 | |
| 53 | 70 | local function spinner_start() |
| 54 | 71 | spinner_stop() |
| 72 | + spinner.active = true | |
| 55 | 73 | spinner.frame = 1 |
| 56 | 74 | spinner_render() |
| 57 | 75 | spinner.timer = vim.uv.new_timer() |
| 58 | 76 | spinner.timer:start(90, 90, vim.schedule_wrap(function() |
| 77 | + if not spinner.active then return end | |
| 59 | 78 | spinner.frame = (spinner.frame % #spinner.frames) + 1 |
| 60 | 79 | spinner_render() |
| 61 | 80 | end)) |
| @@ -84,24 +103,24 @@ local function ensure_buf() | ||
| 84 | 103 | end |
| 85 | 104 | |
| 86 | 105 | local function scroll_to_bottom() |
| 87 | - if panel.win and vim.api.nvim_win_is_valid(panel.win) then | |
| 88 | - local lc = vim.api.nvim_buf_line_count(panel.buf) | |
| 89 | - pcall(vim.api.nvim_win_set_cursor, panel.win, { lc, 0 }) | |
| 90 | - end | |
| 106 | + scroll_to_bottom_now() | |
| 91 | 107 | end |
| 92 | 108 | |
| 93 | 109 | local function append_lines(lines) |
| 94 | 110 | local buf = panel.buf |
| 95 | 111 | if not buf or not vim.api.nvim_buf_is_valid(buf) then return end |
| 112 | + spinner_remove_if_present() | |
| 96 | 113 | vim.bo[buf].modifiable = true |
| 97 | 114 | vim.api.nvim_buf_set_lines(buf, -1, -1, false, lines) |
| 98 | 115 | vim.bo[buf].modifiable = false |
| 116 | + spinner_render() | |
| 99 | 117 | scroll_to_bottom() |
| 100 | 118 | end |
| 101 | 119 | |
| 102 | 120 | local function append_text_streaming(text) |
| 103 | 121 | local buf = panel.buf |
| 104 | 122 | if not buf or not vim.api.nvim_buf_is_valid(buf) then return end |
| 123 | + spinner_remove_if_present() | |
| 105 | 124 | vim.bo[buf].modifiable = true |
| 106 | 125 | local lc = vim.api.nvim_buf_line_count(buf) |
| 107 | 126 | local last = vim.api.nvim_buf_get_lines(buf, lc - 1, lc, false)[1] or "" |
| @@ -109,12 +128,14 @@ local function append_text_streaming(text) | ||
| 109 | 128 | parts[1] = last .. parts[1] |
| 110 | 129 | vim.api.nvim_buf_set_lines(buf, lc - 1, lc, false, parts) |
| 111 | 130 | vim.bo[buf].modifiable = false |
| 131 | + spinner_render() | |
| 112 | 132 | scroll_to_bottom() |
| 113 | 133 | end |
| 114 | 134 | |
| 115 | 135 | local function clear_buf() |
| 116 | 136 | local buf = panel.buf |
| 117 | 137 | if not buf or not vim.api.nvim_buf_is_valid(buf) then return end |
| 138 | + spinner.row = nil | |
| 118 | 139 | vim.bo[buf].modifiable = true |
| 119 | 140 | vim.api.nvim_buf_set_lines(buf, 0, -1, false, {}) |
| 120 | 141 | vim.bo[buf].modifiable = false |
| @@ -479,22 +500,23 @@ function M.append_user_prompt(sid, text) | ||
| 479 | 500 | table.insert(lines, "") |
| 480 | 501 | append_lines(lines) |
| 481 | 502 | spinner_start() |
| 503 | + scroll_to_bottom() | |
| 482 | 504 | pcall(vim.cmd, "redraw!") |
| 483 | 505 | end |
| 484 | 506 | |
| 485 | 507 | function M.append_assistant_text(sid, text) |
| 486 | 508 | if sid ~= panel.sid then return end |
| 487 | 509 | vim.schedule(function() |
| 488 | - spinner_stop() | |
| 489 | 510 | append_text_streaming(text) |
| 511 | + spinner_render() | |
| 490 | 512 | end) |
| 491 | 513 | end |
| 492 | 514 | |
| 493 | 515 | function M.append_tool_use(sid, name, path) |
| 494 | 516 | if sid ~= panel.sid then return end |
| 495 | 517 | vim.schedule(function() |
| 496 | - spinner_stop() | |
| 497 | 518 | append_lines({ "", "> **" .. name .. "** `" .. path .. "`", "" }) |
| 519 | + spinner_render() | |
| 498 | 520 | end) |
| 499 | 521 | end |
| 500 | 522 |