Skip to content

Commit 3155f16

Browse files
John-Linclaude
andcommitted
feat: add show_terminal_on_at_mention configuration option
- Add new config option to control terminal visibility for @ mentions - Remove show_terminal parameter from send_at_mention function - Update config validation to include new boolean option - Simplify visual selection @ mention calls 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b8e5e54 commit 3155f16

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).
143143

144144
-- Selection Tracking
145145
track_selection = true,
146+
show_terminal_on_at_mention = true, -- Whether to show terminal when sending @ mentions
146147
visual_demotion_delay_ms = 50,
147148

148149
-- Terminal Configuration

lua/claudecode/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ M.defaults = {
99
env = {}, -- Custom environment variables for Claude terminal
1010
log_level = "info",
1111
track_selection = true,
12+
show_terminal_on_at_mention = true, -- Whether to show terminal when sending @ mentions
1213
visual_demotion_delay_ms = 50, -- Milliseconds to wait before demoting a visual selection
1314
connection_wait_delay = 200, -- Milliseconds to wait after connection before sending queued @ mentions
1415
connection_timeout = 10000, -- Maximum time to wait for Claude Code to connect (milliseconds)
@@ -56,6 +57,8 @@ function M.validate(config)
5657

5758
assert(type(config.track_selection) == "boolean", "track_selection must be a boolean")
5859

60+
assert(config.show_terminal_on_at_mention == nil or type(config.show_terminal_on_at_mention) == "boolean", "show_terminal_on_at_mention must be a boolean")
61+
5962
assert(
6063
type(config.visual_demotion_delay_ms) == "number" and config.visual_demotion_delay_ms >= 0,
6164
"visual_demotion_delay_ms must be a non-negative number"

lua/claudecode/init.lua

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ M.version = {
3939
--- @field env table<string,string> Custom environment variables for Claude terminal.
4040
--- @field log_level "trace"|"debug"|"info"|"warn"|"error" Log level.
4141
--- @field track_selection boolean Enable sending selection updates to Claude.
42+
--- @field show_terminal_on_at_mention boolean Whether to show terminal when sending @ mentions.
4243
--- @field visual_demotion_delay_ms number Milliseconds to wait before demoting a visual selection.
4344
--- @field connection_wait_delay number Milliseconds to wait after connection before sending queued @ mentions.
4445
--- @field connection_timeout number Maximum time to wait for Claude Code to connect (milliseconds).
@@ -316,6 +317,7 @@ end
316317
---@return string|nil error Error message if failed
317318
function M.send_at_mention(file_path, start_line, end_line, context)
318319
context = context or "command"
320+
local show_terminal = M.state.config.show_terminal_on_at_mention
319321

320322
if not M.state.server then
321323
logger.error(context, "Claude Code integration is not running")
@@ -324,9 +326,9 @@ function M.send_at_mention(file_path, start_line, end_line, context)
324326

325327
-- Check if Claude Code is connected
326328
if M.is_claude_connected() then
327-
-- Claude is connected, send immediately and ensure terminal is visible
329+
-- Claude is connected, send immediately and optionally ensure terminal is visible
328330
local success, error_msg = M._broadcast_at_mention(file_path, start_line, end_line)
329-
if success then
331+
if success and show_terminal then
330332
local terminal = require("claudecode.terminal")
331333
terminal.ensure_visible()
332334
end
@@ -335,9 +337,21 @@ function M.send_at_mention(file_path, start_line, end_line, context)
335337
-- Claude not connected, queue the mention and launch terminal
336338
queue_mention(file_path, start_line, end_line)
337339

338-
-- Launch terminal with Claude Code
339-
local terminal = require("claudecode.terminal")
340-
terminal.open()
340+
-- Claude not connected, queue the mention and optionally launch terminal
341+
local mention_data = {
342+
file_path = file_path,
343+
start_line = start_line,
344+
end_line = end_line,
345+
context = context,
346+
}
347+
348+
queue_at_mention(mention_data)
349+
350+
if show_terminal then
351+
-- Launch terminal with Claude Code
352+
local terminal = require("claudecode.terminal")
353+
terminal.open()
354+
end
341355

342356
logger.debug(context, "Queued @ mention and launched Claude Code: " .. file_path)
343357

tests/unit/config_spec.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,32 @@ describe("Configuration", function()
121121
expect(success).to_be_false()
122122
end)
123123

124+
it("should reject invalid show_terminal_on_at_mention type", function()
125+
local invalid_config = {
126+
port_range = { min = 10000, max = 65535 },
127+
auto_start = true,
128+
log_level = "debug",
129+
track_selection = false,
130+
show_terminal_on_at_mention = "invalid", -- Should be boolean
131+
visual_demotion_delay_ms = 50,
132+
diff_opts = {
133+
auto_close_on_accept = true,
134+
show_diff_stats = true,
135+
vertical_split = true,
136+
open_in_current_tab = true,
137+
},
138+
models = {
139+
{ name = "Test Model", value = "test-model" },
140+
},
141+
}
142+
143+
local success, _ = pcall(function()
144+
config.validate(invalid_config)
145+
end)
146+
147+
expect(success).to_be_false()
148+
end)
149+
124150
it("should merge user config with defaults", function()
125151
local user_config = {
126152
auto_start = true,
@@ -133,6 +159,7 @@ describe("Configuration", function()
133159
expect(merged_config.log_level).to_be("debug")
134160
expect(merged_config.port_range.min).to_be(config.defaults.port_range.min)
135161
expect(merged_config.track_selection).to_be(config.defaults.track_selection)
162+
expect(merged_config.show_terminal_on_at_mention).to_be(config.defaults.show_terminal_on_at_mention)
136163
expect(merged_config.models).to_be_table()
137164
end)
138165

0 commit comments

Comments
 (0)