Skip to content

feat: add show_terminal_on_at_mention configuration option #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).

-- Selection Tracking
track_selection = true,
show_terminal_on_at_mention = true, -- Whether to show terminal when sending @ mentions
visual_demotion_delay_ms = 50,

-- Terminal Configuration
Expand Down
3 changes: 3 additions & 0 deletions lua/claudecode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ M.defaults = {
env = {}, -- Custom environment variables for Claude terminal
log_level = "info",
track_selection = true,
show_terminal_on_at_mention = true, -- Whether to show terminal when sending @ mentions
visual_demotion_delay_ms = 50, -- Milliseconds to wait before demoting a visual selection
connection_wait_delay = 200, -- Milliseconds to wait after connection before sending queued @ mentions
connection_timeout = 10000, -- Maximum time to wait for Claude Code to connect (milliseconds)
Expand Down Expand Up @@ -56,6 +57,8 @@ function M.validate(config)

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

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")

assert(
type(config.visual_demotion_delay_ms) == "number" and config.visual_demotion_delay_ms >= 0,
"visual_demotion_delay_ms must be a non-negative number"
Expand Down
24 changes: 19 additions & 5 deletions lua/claudecode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ M.version = {
--- @field env table<string,string> Custom environment variables for Claude terminal.
--- @field log_level "trace"|"debug"|"info"|"warn"|"error" Log level.
--- @field track_selection boolean Enable sending selection updates to Claude.
--- @field show_terminal_on_at_mention boolean Whether to show terminal when sending @ mentions.
--- @field visual_demotion_delay_ms number Milliseconds to wait before demoting a visual selection.
--- @field connection_wait_delay number Milliseconds to wait after connection before sending queued @ mentions.
--- @field connection_timeout number Maximum time to wait for Claude Code to connect (milliseconds).
Expand Down Expand Up @@ -316,6 +317,7 @@ end
---@return string|nil error Error message if failed
function M.send_at_mention(file_path, start_line, end_line, context)
context = context or "command"
local show_terminal = M.state.config.show_terminal_on_at_mention

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

-- Check if Claude Code is connected
if M.is_claude_connected() then
-- Claude is connected, send immediately and ensure terminal is visible
-- Claude is connected, send immediately and optionally ensure terminal is visible
local success, error_msg = M._broadcast_at_mention(file_path, start_line, end_line)
if success then
if success and show_terminal then
local terminal = require("claudecode.terminal")
terminal.ensure_visible()
end
Expand All @@ -335,9 +337,21 @@ function M.send_at_mention(file_path, start_line, end_line, context)
-- Claude not connected, queue the mention and launch terminal
queue_mention(file_path, start_line, end_line)

-- Launch terminal with Claude Code
local terminal = require("claudecode.terminal")
terminal.open()
-- Claude not connected, queue the mention and optionally launch terminal
local mention_data = {
file_path = file_path,
start_line = start_line,
end_line = end_line,
context = context,
}

queue_at_mention(mention_data)

if show_terminal then
-- Launch terminal with Claude Code
local terminal = require("claudecode.terminal")
terminal.open()
end

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

Expand Down
27 changes: 27 additions & 0 deletions tests/unit/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ describe("Configuration", function()
expect(success).to_be_false()
end)

it("should reject invalid show_terminal_on_at_mention type", function()
local invalid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
log_level = "debug",
track_selection = false,
show_terminal_on_at_mention = "invalid", -- Should be boolean
visual_demotion_delay_ms = 50,
diff_opts = {
auto_close_on_accept = true,
show_diff_stats = true,
vertical_split = true,
open_in_current_tab = true,
},
models = {
{ name = "Test Model", value = "test-model" },
},
}

local success, _ = pcall(function()
config.validate(invalid_config)
end)

expect(success).to_be_false()
end)

it("should merge user config with defaults", function()
local user_config = {
auto_start = true,
Expand All @@ -133,6 +159,7 @@ describe("Configuration", function()
expect(merged_config.log_level).to_be("debug")
expect(merged_config.port_range.min).to_be(config.defaults.port_range.min)
expect(merged_config.track_selection).to_be(config.defaults.track_selection)
expect(merged_config.show_terminal_on_at_mention).to_be(config.defaults.show_terminal_on_at_mention)
expect(merged_config.models).to_be_table()
end)

Expand Down
Loading