irongit

My nvim configuration

fix(claude): highlight only shows on current quickfix list and buffer scrolls on submit

huncholanehuncholaneauthored
parent db74a46commit 8a682bdcd7251512e7c2e8d16c4008b8b5ddb9a4Browse files

3 files changed, +71 -39

+22-13claude-nvim/lua/claude/highlights.lua
@@ -1,6 +1,5 @@
11 local M = {}
22
3-local store = require("claude.store")
43 local ns = vim.api.nvim_create_namespace("claude_changes")
54 local cfg = { highlight = true, blame = true }
65
@@ -12,26 +11,36 @@ function M.setup(opts)
1211 vim.api.nvim_set_hl(0, "ClaudeChangeSign", { default = true, fg = "#e07b00" })
1312 vim.api.nvim_set_hl(0, "ClaudeBlame", { default = true, fg = "#7f5a2a", italic = true })
1413
15- vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost" }, {
14+ vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "BufEnter" }, {
1615 callback = function(args)
1716 M.apply_to_buf(args.buf)
1817 end,
1918 })
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
2031 end
2132
2233 local function collect_for_path(abs_path)
2334 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 "" })
3544 end
3645 end
3746 end
+1-0claude-nvim/lua/claude/pickers.lua
@@ -27,6 +27,7 @@ function M.set_qf_from_prompt(p)
2727 items = items,
2828 })
2929 vim.cmd("copen")
30+ pcall(function() require("claude.highlights").refresh_all() end)
3031 end
3132
3233 function M.qf_last()
+48-26claude-nvim/lua/claude/ui.lua
@@ -9,53 +9,72 @@ local panel = {
99
1010 local spinner = {
1111 timer = nil,
12- line = nil,
1312 frame = 1,
1413 frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" },
14+ active = false,
15+ row = nil,
1516 }
1617
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+
1745 local function spinner_render()
46+ if not spinner.active then return end
1847 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…"
2048 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() })
2451 else
2552 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
2955 end
3056 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()
3558 end
3659
3760 local function spinner_stop()
61+ spinner.active = false
3862 if spinner.timer then
3963 spinner.timer:stop()
4064 if not spinner.timer:is_closing() then spinner.timer:close() end
4165 spinner.timer = nil
4266 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()
5168 end
5269
5370 local function spinner_start()
5471 spinner_stop()
72+ spinner.active = true
5573 spinner.frame = 1
5674 spinner_render()
5775 spinner.timer = vim.uv.new_timer()
5876 spinner.timer:start(90, 90, vim.schedule_wrap(function()
77+ if not spinner.active then return end
5978 spinner.frame = (spinner.frame % #spinner.frames) + 1
6079 spinner_render()
6180 end))
@@ -84,24 +103,24 @@ local function ensure_buf()
84103 end
85104
86105 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()
91107 end
92108
93109 local function append_lines(lines)
94110 local buf = panel.buf
95111 if not buf or not vim.api.nvim_buf_is_valid(buf) then return end
112+ spinner_remove_if_present()
96113 vim.bo[buf].modifiable = true
97114 vim.api.nvim_buf_set_lines(buf, -1, -1, false, lines)
98115 vim.bo[buf].modifiable = false
116+ spinner_render()
99117 scroll_to_bottom()
100118 end
101119
102120 local function append_text_streaming(text)
103121 local buf = panel.buf
104122 if not buf or not vim.api.nvim_buf_is_valid(buf) then return end
123+ spinner_remove_if_present()
105124 vim.bo[buf].modifiable = true
106125 local lc = vim.api.nvim_buf_line_count(buf)
107126 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)
109128 parts[1] = last .. parts[1]
110129 vim.api.nvim_buf_set_lines(buf, lc - 1, lc, false, parts)
111130 vim.bo[buf].modifiable = false
131+ spinner_render()
112132 scroll_to_bottom()
113133 end
114134
115135 local function clear_buf()
116136 local buf = panel.buf
117137 if not buf or not vim.api.nvim_buf_is_valid(buf) then return end
138+ spinner.row = nil
118139 vim.bo[buf].modifiable = true
119140 vim.api.nvim_buf_set_lines(buf, 0, -1, false, {})
120141 vim.bo[buf].modifiable = false
@@ -479,22 +500,23 @@ function M.append_user_prompt(sid, text)
479500 table.insert(lines, "")
480501 append_lines(lines)
481502 spinner_start()
503+ scroll_to_bottom()
482504 pcall(vim.cmd, "redraw!")
483505 end
484506
485507 function M.append_assistant_text(sid, text)
486508 if sid ~= panel.sid then return end
487509 vim.schedule(function()
488- spinner_stop()
489510 append_text_streaming(text)
511+ spinner_render()
490512 end)
491513 end
492514
493515 function M.append_tool_use(sid, name, path)
494516 if sid ~= panel.sid then return end
495517 vim.schedule(function()
496- spinner_stop()
497518 append_lines({ "", "> **" .. name .. "** `" .. path .. "`", "" })
519+ spinner_render()
498520 end)
499521 end
500522