Skip to content

Commit 30d8be7

Browse files
committed
Fix CodeRabbit review comments
- Remove whitespace-only lines throughout codebase - Add nil-safe buffer validity checks - Add guard for instances table access - Add buffer cleanup logic to prune invalid entries
1 parent a373afb commit 30d8be7

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

lua/claude-code/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ local function validate_config(config)
174174
if type(config.git.use_git_root) ~= 'boolean' then
175175
return false, 'git.use_git_root must be a boolean'
176176
end
177-
177+
178178
if type(config.git.multi_instance) ~= 'boolean' then
179179
return false, 'git.multi_instance must be a boolean'
180180
end

lua/claude-code/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ end
4949
local function get_current_buffer_number()
5050
-- Get current instance from the instances table
5151
local current_instance = M.claude_code.current_instance
52-
if current_instance then
52+
if current_instance and type(M.claude_code.instances) == 'table' then
5353
return M.claude_code.instances[current_instance]
5454
end
5555
return nil

lua/claude-code/terminal.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,19 @@ end
6565
--- @param config table The plugin configuration
6666
function M.force_insert_mode(claude_code, config)
6767
local current_bufnr = vim.fn.bufnr('%')
68-
68+
6969
-- Check if current buffer is any of our Claude instances
7070
local is_claude_instance = false
7171
for _, bufnr in pairs(claude_code.claude_code.instances) do
72-
if bufnr == current_bufnr and vim.api.nvim_buf_is_valid(bufnr) then
72+
if bufnr
73+
and bufnr == current_bufnr
74+
and vim.api.nvim_buf_is_valid(bufnr)
75+
then
7376
is_claude_instance = true
7477
break
7578
end
7679
end
77-
80+
7881
if is_claude_instance then
7982
-- Only enter insert mode if we're in the terminal buffer and not already in insert mode
8083
-- and not configured to stay in normal mode
@@ -106,9 +109,9 @@ function M.toggle(claude_code, config, git)
106109
-- Use a fixed ID for single instance mode
107110
instance_id = "global"
108111
end
109-
112+
110113
claude_code.claude_code.current_instance = instance_id
111-
114+
112115
-- Check if this Claude Code instance is already running
113116
local bufnr = claude_code.claude_code.instances[instance_id]
114117
if bufnr and vim.api.nvim_buf_is_valid(bufnr) then
@@ -130,6 +133,10 @@ function M.toggle(claude_code, config, git)
130133
end
131134
end
132135
else
136+
-- Prune invalid buffer entries
137+
if bufnr and not vim.api.nvim_buf_is_valid(bufnr) then
138+
claude_code.claude_code.instances[instance_id] = nil
139+
end
133140
-- This Claude Code instance is not running, start it in a new split
134141
create_split(config.window.position, config)
135142

@@ -145,7 +152,7 @@ function M.toggle(claude_code, config, git)
145152

146153
vim.cmd(cmd)
147154
vim.cmd 'setlocal bufhidden=hide'
148-
155+
149156
-- Create a unique buffer name (or a standard one in single instance mode)
150157
local buffer_name
151158
if config.git.multi_instance then

0 commit comments

Comments
 (0)