|
| 1 | +-- Minimal repro config for claudecode.nvim issues. |
| 2 | +-- |
| 3 | +-- This fixture intentionally avoids a plugin manager so it's easy to run and reason about. |
| 4 | +-- |
| 5 | +-- Usage (from repo root): |
| 6 | +-- source fixtures/nvim-aliases.sh |
| 7 | +-- repro |
| 8 | +-- |
| 9 | +-- To edit this config: |
| 10 | +-- vve repro |
| 11 | + |
| 12 | +-- Ensure this repo is on the runtimepath so `plugin/claudecode.lua` is loaded. |
| 13 | +local config_dir = vim.fn.stdpath("config") |
| 14 | +local repo_root = vim.fn.fnamemodify(config_dir, ":h:h") |
| 15 | + |
| 16 | +vim.opt.rtp:prepend(repo_root) |
| 17 | + |
| 18 | +-- Basic editor settings |
| 19 | +vim.g.mapleader = " " |
| 20 | +vim.g.maplocalleader = "\\" |
| 21 | + |
| 22 | +local ok, claudecode = pcall(require, "claudecode") |
| 23 | +assert(ok, "Failed to load claudecode.nvim from repo root: " .. tostring(claudecode)) |
| 24 | + |
| 25 | +claudecode.setup({ |
| 26 | + auto_start = false, -- avoid noisy startup + make restarts deterministic |
| 27 | + log_level = "debug", |
| 28 | + terminal = { |
| 29 | + provider = "native", |
| 30 | + auto_close = false, |
| 31 | + }, |
| 32 | + diff_opts = { |
| 33 | + layout = "vertical", |
| 34 | + open_in_new_tab = false, |
| 35 | + keep_terminal_focus = false, |
| 36 | + }, |
| 37 | +}) |
| 38 | + |
| 39 | +local function ensure_claudecode_started() |
| 40 | + local ok_start, started_or_err, port_or_err = pcall(function() |
| 41 | + return claudecode.start(false) |
| 42 | + end) |
| 43 | + |
| 44 | + if not ok_start then |
| 45 | + vim.notify("ClaudeCode start crashed: " .. tostring(started_or_err), vim.log.levels.ERROR) |
| 46 | + return false |
| 47 | + end |
| 48 | + |
| 49 | + local started = started_or_err |
| 50 | + if started then |
| 51 | + return true |
| 52 | + end |
| 53 | + |
| 54 | + -- start() returns false + "Already running" when running. |
| 55 | + if port_or_err == "Already running" then |
| 56 | + return true |
| 57 | + end |
| 58 | + |
| 59 | + vim.notify("ClaudeCode failed to start: " .. tostring(port_or_err), vim.log.levels.ERROR) |
| 60 | + return false |
| 61 | +end |
| 62 | + |
| 63 | +-- Keymaps (kept small on purpose) |
| 64 | +vim.keymap.set("n", "<leader>ac", function() |
| 65 | + if ensure_claudecode_started() then |
| 66 | + local terminal = require("claudecode.terminal") |
| 67 | + terminal.simple_toggle({}, nil) |
| 68 | + end |
| 69 | +end, { desc = "Toggle Claude" }) |
| 70 | + |
| 71 | +vim.keymap.set("n", "<leader>af", function() |
| 72 | + if ensure_claudecode_started() then |
| 73 | + local terminal = require("claudecode.terminal") |
| 74 | + terminal.focus_toggle({}, nil) |
| 75 | + end |
| 76 | +end, { desc = "Focus Claude" }) |
| 77 | + |
| 78 | +vim.keymap.set("n", "<leader>aa", "<cmd>ClaudeCodeDiffAccept<cr>", { desc = "Accept diff" }) |
| 79 | +vim.keymap.set("n", "<leader>ad", "<cmd>ClaudeCodeDiffDeny<cr>", { desc = "Deny diff" }) |
| 80 | + |
| 81 | +-- Convenience helpers for iterating on this fixture. |
| 82 | +vim.api.nvim_create_user_command("ReproEditConfig", function() |
| 83 | + local config_path = vim.fn.stdpath("config") .. "/init.lua" |
| 84 | + |
| 85 | + -- Open the config file without `:edit` / `vim.cmd(...)` so we don't trigger |
| 86 | + -- Treesitter "vim" language injections (which can be noisy if parsers/queries mismatch). |
| 87 | + local bufnr = vim.fn.bufadd(config_path) |
| 88 | + vim.fn.bufload(bufnr) |
| 89 | + vim.api.nvim_set_current_buf(bufnr) |
| 90 | +end, { desc = "Edit the repro Neovim config" }) |
| 91 | + |
| 92 | +vim.keymap.set("n", "<leader>ae", "<cmd>ReproEditConfig<cr>", { desc = "Edit repro config" }) |
| 93 | +vim.keymap.set("n", "<leader>aw", function() |
| 94 | + vim.notify(("windows in tab: %d"):format(vim.fn.winnr("$"))) |
| 95 | +end, { desc = "Claude: show window count" }) |
0 commit comments