inline diffs are pretty good now
parent
91c24b34a6
commit
720778cd2c
@ -0,0 +1,57 @@
|
||||
local M = {}
|
||||
|
||||
-- Debug function to check inline diff state
|
||||
function M.debug_inline_diff()
|
||||
local inline_diff = require('nvim-claude.inline-diff')
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
vim.notify('=== Inline Diff Debug Info ===', vim.log.levels.INFO)
|
||||
|
||||
-- Check if inline diff is active for current buffer
|
||||
local diff_data = inline_diff.active_diffs[bufnr]
|
||||
if diff_data then
|
||||
vim.notify(string.format('✓ Inline diff ACTIVE for buffer %d', bufnr), vim.log.levels.INFO)
|
||||
vim.notify(string.format(' - Hunks: %d', #diff_data.hunks), vim.log.levels.INFO)
|
||||
vim.notify(string.format(' - Current hunk: %d', diff_data.current_hunk or 0), vim.log.levels.INFO)
|
||||
vim.notify(string.format(' - Original content length: %d', #(inline_diff.original_content[bufnr] or '')), vim.log.levels.INFO)
|
||||
vim.notify(string.format(' - New content length: %d', #(diff_data.new_content or '')), vim.log.levels.INFO)
|
||||
else
|
||||
vim.notify(string.format('✗ No inline diff for buffer %d', bufnr), vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
-- Check all active diffs
|
||||
local count = 0
|
||||
for buf, _ in pairs(inline_diff.active_diffs) do
|
||||
count = count + 1
|
||||
end
|
||||
vim.notify(string.format('Total active inline diffs: %d', count), vim.log.levels.INFO)
|
||||
|
||||
-- Check keymaps
|
||||
local keymaps = vim.api.nvim_buf_get_keymap(bufnr, 'n')
|
||||
local found_ir = false
|
||||
local leader = vim.g.mapleader or '\\'
|
||||
local ir_pattern = leader .. 'ir'
|
||||
|
||||
vim.notify(string.format('Looking for keymap: %s', ir_pattern), vim.log.levels.INFO)
|
||||
|
||||
for _, map in ipairs(keymaps) do
|
||||
if map.lhs == ir_pattern or map.lhs == '<leader>ir' then
|
||||
found_ir = true
|
||||
vim.notify(string.format('✓ Found keymap: %s -> %s', map.lhs, map.desc or 'no desc'), vim.log.levels.INFO)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not found_ir then
|
||||
vim.notify('✗ <leader>ir keymap not found', vim.log.levels.WARN)
|
||||
-- List all keymaps that start with leader
|
||||
vim.notify('Buffer keymaps starting with leader:', vim.log.levels.INFO)
|
||||
for _, map in ipairs(keymaps) do
|
||||
if map.lhs:match('^' .. vim.pesc(leader)) or map.lhs:match('^<leader>') then
|
||||
vim.notify(string.format(' %s -> %s', map.lhs, map.desc or 'no desc'), vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
@ -0,0 +1,112 @@
|
||||
local M = {}
|
||||
local utils = require('nvim-claude.utils')
|
||||
|
||||
-- Update Claude settings with current Neovim server address
|
||||
function M.update_claude_settings()
|
||||
local project_root = utils.get_project_root()
|
||||
if not project_root then
|
||||
return
|
||||
end
|
||||
|
||||
local settings_path = project_root .. '/.claude/settings.json'
|
||||
local settings_dir = project_root .. '/.claude'
|
||||
|
||||
-- Get current Neovim server address
|
||||
local server_addr = vim.v.servername
|
||||
if not server_addr or server_addr == '' then
|
||||
-- If no servername, we can't communicate
|
||||
return
|
||||
end
|
||||
|
||||
-- Ensure .claude directory exists
|
||||
if vim.fn.isdirectory(settings_dir) == 0 then
|
||||
vim.fn.mkdir(settings_dir, 'p')
|
||||
end
|
||||
|
||||
-- Read existing settings or create new
|
||||
local settings = {}
|
||||
if vim.fn.filereadable(settings_path) == 1 then
|
||||
local ok, content = pcall(vim.fn.readfile, settings_path)
|
||||
if ok and #content > 0 then
|
||||
local decode_ok, decoded = pcall(vim.json.decode, table.concat(content, '\n'))
|
||||
if decode_ok then
|
||||
settings = decoded
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Ensure hooks structure exists
|
||||
if not settings.hooks then
|
||||
settings.hooks = {}
|
||||
end
|
||||
if not settings.hooks.PreToolUse then
|
||||
settings.hooks.PreToolUse = {}
|
||||
end
|
||||
if not settings.hooks.PostToolUse then
|
||||
settings.hooks.PostToolUse = {}
|
||||
end
|
||||
|
||||
-- Update hook commands with current server address
|
||||
local pre_hook_cmd = string.format(
|
||||
'nvr --servername "%s" --remote-expr \'luaeval("require(\\"nvim-claude.hooks\\").pre_tool_use_hook()")\'',
|
||||
server_addr
|
||||
)
|
||||
|
||||
local post_hook_cmd = string.format(
|
||||
'nvr --servername "%s" --remote-send "<C-\\\\><C-N>:lua require(\'nvim-claude.hooks\').post_tool_use_hook()<CR>"',
|
||||
server_addr
|
||||
)
|
||||
|
||||
-- Update PreToolUse hooks
|
||||
local pre_hook_found = false
|
||||
for _, hook_group in ipairs(settings.hooks.PreToolUse) do
|
||||
if hook_group.matcher == "Edit|Write|MultiEdit" then
|
||||
hook_group.hooks = {{type = "command", command = pre_hook_cmd}}
|
||||
pre_hook_found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not pre_hook_found then
|
||||
table.insert(settings.hooks.PreToolUse, {
|
||||
matcher = "Edit|Write|MultiEdit",
|
||||
hooks = {{type = "command", command = pre_hook_cmd}}
|
||||
})
|
||||
end
|
||||
|
||||
-- Update PostToolUse hooks
|
||||
local post_hook_found = false
|
||||
for _, hook_group in ipairs(settings.hooks.PostToolUse) do
|
||||
if hook_group.matcher == "Edit|Write|MultiEdit" then
|
||||
hook_group.hooks = {{type = "command", command = post_hook_cmd}}
|
||||
post_hook_found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not post_hook_found then
|
||||
table.insert(settings.hooks.PostToolUse, {
|
||||
matcher = "Edit|Write|MultiEdit",
|
||||
hooks = {{type = "command", command = post_hook_cmd}}
|
||||
})
|
||||
end
|
||||
|
||||
-- Write updated settings
|
||||
local encoded = vim.json.encode(settings)
|
||||
vim.fn.writefile({encoded}, settings_path)
|
||||
end
|
||||
|
||||
-- Setup autocmds to update settings
|
||||
function M.setup()
|
||||
vim.api.nvim_create_autocmd({"VimEnter", "DirChanged"}, {
|
||||
group = vim.api.nvim_create_augroup("NvimClaudeSettingsUpdater", { clear = true }),
|
||||
callback = function()
|
||||
-- Defer to ensure servername is available
|
||||
vim.defer_fn(function()
|
||||
M.update_claude_settings()
|
||||
end, 100)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in New Issue