Skip to content

Commit 05eb01a

Browse files
committed
feat: auto-focus terminal after sending selection and optimize test performance
Change-Id: Iacfd6193a2d87da88df1679994a740f0d12e9c8f Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 2004b32 commit 05eb01a

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

lua/claudecode/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ function M._create_commands()
275275
if sent_successfully then
276276
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
277277
logger.debug("command", "ClaudeCodeSend: Exited visual mode after successful send.")
278+
279+
-- Focus the Claude Code terminal after sending selection
280+
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
281+
if terminal_ok then
282+
terminal.open({}) -- Open/focus the terminal
283+
logger.debug("command", "ClaudeCodeSend: Focused Claude Code terminal after selection send.")
284+
else
285+
logger.warn("command", "ClaudeCodeSend: Failed to load terminal module for focusing.")
286+
end
278287
end
279288
else
280289
logger.error("command", "ClaudeCodeSend: Failed to load selection module.")

lua/claudecode/terminal.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function M.open(opts_override)
357357
managed_snacks_terminal:focus()
358358
local term_buf_id = managed_snacks_terminal.buf
359359
if term_buf_id and vim.api.nvim_buf_get_option(term_buf_id, "buftype") == "terminal" then
360-
vim.api.nvim_win_call(managed_snacks_terminal.winid, function()
360+
vim.api.nvim_win_call(managed_snacks_terminal.win, function()
361361
vim.cmd("startinsert")
362362
end)
363363
end

tests/mocks/vim.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,19 @@ local vim = {
438438

439439
-- Additional missing vim functions
440440
wait = function(timeout, condition, interval, fast_only)
441-
-- Mock implementation that immediately returns true if condition is met
442-
-- For tests, we'll assume the condition is met quickly
441+
-- Optimized mock implementation for faster test execution
443442
local start_time = os.clock()
444-
interval = interval or 200
443+
interval = interval or 10 -- Reduced from 200ms to 10ms for faster polling
445444
timeout = timeout or 1000
446445

447446
while (os.clock() - start_time) * 1000 < timeout do
448447
if condition and condition() then
449448
return true
450449
end
451-
-- In a real implementation this would yield, but for tests we'll just continue
450+
-- Add a small sleep to prevent busy-waiting and reduce CPU usage
451+
os.execute("sleep 0.001") -- 1ms sleep
452452
end
453+
453454
return false
454455
end,
455456

tests/unit/diff_mcp_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("MCP-compliant diff operations", function()
4949
end)
5050

5151
-- Wait for resolution
52-
vim.wait(1000, function()
52+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
5353
return coroutine.status(co) == "dead"
5454
end)
5555

@@ -78,7 +78,7 @@ describe("MCP-compliant diff operations", function()
7878
end)
7979

8080
-- Wait for resolution
81-
vim.wait(1000, function()
81+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
8282
return coroutine.status(co) == "dead"
8383
end)
8484

@@ -125,7 +125,7 @@ describe("MCP-compliant diff operations", function()
125125
diff._resolve_diff_as_rejected(test_tab_name)
126126
end)
127127

128-
vim.wait(1000, function()
128+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
129129
return coroutine.status(co2) == "dead"
130130
end)
131131
end)
@@ -225,7 +225,7 @@ describe("MCP-compliant diff operations", function()
225225
diff._resolve_diff_as_rejected(tab_name_2)
226226
end)
227227

228-
vim.wait(1000, function()
228+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
229229
return coroutine.status(co1) == "dead" and coroutine.status(co2) == "dead"
230230
end)
231231
end)

tests/unit/tools/open_diff_mcp_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe("openDiff tool MCP compliance", function()
127127
end)
128128

129129
-- Wait for resolution
130-
vim.wait(1000, function()
130+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
131131
return coroutine.status(co) == "dead"
132132
end)
133133

@@ -164,7 +164,7 @@ describe("openDiff tool MCP compliance", function()
164164
end)
165165

166166
-- Wait for resolution
167-
vim.wait(1000, function()
167+
vim.wait(100, function() -- Reduced from 1000ms to 100ms
168168
return coroutine.status(co) == "dead"
169169
end)
170170

0 commit comments

Comments
 (0)