Skip to content

Commit 66f18f9

Browse files
blink-so[bot]ThomasK33
andcommitted
fix: enhance ClaudeCodeSend to handle tree multi-selection properly
- Add tree buffer detection to ClaudeCodeSend command - Delegate to tree integration when in nvim-tree or neo-tree buffers - Fixes issue where visual selection in tree sent line ranges instead of files - Now properly sends each selected file as individual at_mentions - Simplify keybinding configuration - single command handles both contexts - Update documentation to reflect enhanced functionality Resolves multi-file selection issue in neotree/nvim-tree Co-authored-by: ThomasK33 <[email protected]>
1 parent cd6b4a9 commit 66f18f9

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
5151
keys = {
5252
{ "<leader>ac", "<cmd>ClaudeCode<cr>", desc = "Toggle Claude" },
5353
{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v", desc = "Send to Claude" },
54-
-- Add file from nvim-tree or neo-tree
55-
{ "<leader>as", "<cmd>ClaudeCodeTreeAdd<cr>", desc = "Add file to Claude context", ft = { "NvimTree", "neo-tree" } },
54+
-- Tree integration works automatically with the same keybinding
55+
{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", desc = "Add file to Claude context", ft = { "NvimTree", "neo-tree" } },
5656
},
5757
}
5858
```
@@ -74,8 +74,8 @@ That's it! For more configuration options, see [Advanced Setup](#advanced-setup)
7474
## Commands
7575

7676
- `:ClaudeCode` - Toggle the Claude Code terminal window
77-
- `:ClaudeCodeSend` - Send current visual selection to Claude
78-
- `:ClaudeCodeTreeAdd` - Add selected file(s) from tree explorer to Claude context
77+
- `:ClaudeCodeSend` - Send current visual selection to Claude, or add files from tree explorer
78+
- `:ClaudeCodeTreeAdd` - Add selected file(s) from tree explorer to Claude context (also available via ClaudeCodeSend)
7979

8080
### Tree Integration
8181

lua/claudecode/init.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,58 @@ function M._create_commands()
251251
vim.notify("Claude Code integration is not running", vim.log.levels.ERROR)
252252
return
253253
end
254+
255+
-- Check if we're in a tree buffer - if so, delegate to tree integration
256+
local current_ft = vim.bo.filetype
257+
if current_ft == "NvimTree" or current_ft == "neo-tree" then
258+
logger.debug("command", "ClaudeCodeSend: Detected tree buffer, delegating to tree integration")
259+
260+
local integrations = require("claudecode.integrations")
261+
local files, error = integrations.get_selected_files_from_tree()
262+
263+
if error then
264+
logger.warn("command", "ClaudeCodeSend->TreeAdd: " .. error)
265+
vim.notify(error, vim.log.levels.WARN, { title = "ClaudeCode" })
266+
return
267+
end
268+
269+
if not files or #files == 0 then
270+
logger.warn("command", "ClaudeCodeSend->TreeAdd: No files selected")
271+
vim.notify("No files selected", vim.log.levels.WARN, { title = "ClaudeCode" })
272+
return
273+
end
274+
275+
-- Send each file as an at_mention (full file, no line numbers)
276+
local success_count = 0
277+
for _, file_path in ipairs(files) do
278+
local params = {
279+
filePath = file_path,
280+
lineStart = nil, -- No line numbers for full file
281+
lineEnd = nil, -- No line numbers for full file
282+
}
283+
284+
local broadcast_success = M.state.server.broadcast("at_mentioned", params)
285+
if broadcast_success then
286+
success_count = success_count + 1
287+
logger.debug("command", "ClaudeCodeSend->TreeAdd: Added file " .. file_path)
288+
else
289+
logger.error("command", "ClaudeCodeSend->TreeAdd: Failed to add file " .. file_path)
290+
end
291+
end
292+
293+
if success_count > 0 then
294+
local message = success_count == 1 and "Added 1 file to Claude context"
295+
or string.format("Added %d files to Claude context", success_count)
296+
logger.debug("command", message) -- Use debug level to avoid popup
297+
else
298+
vim.notify("Failed to add any files", vim.log.levels.ERROR, { title = "ClaudeCode" })
299+
end
300+
301+
-- Exit visual mode if we were in it
302+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
303+
return
304+
end
305+
254306
logger.debug(
255307
"command",
256308
"ClaudeCodeSend (new logic) invoked. Mode: "

0 commit comments

Comments
 (0)