Skip to content

Commit 13e0ce1

Browse files
committed
fix: implement proper sequential file sending for mini.files
- Use asynchronous sequential sending with 200ms delays - Ensure proper auto-open behavior by using send_at_mention directly - Add proper logging and summary messages - Fix issue where only last file was showing and Claude didn't auto-open This should now properly send all files with delays and trigger Claude Code opening.
1 parent 948ab9c commit 13e0ce1

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

lua/claudecode/selection.lua

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -675,20 +675,45 @@ function M.send_at_mention_for_visual_selection(line1, line2)
675675
return false
676676
end
677677

678-
-- Use the standard file adding function with delay to properly handle multiple files
679-
local success_count, total_count = claudecode_main._add_paths_to_claude(files, {
680-
delay = 100, -- 100ms delay between files
681-
show_summary = true,
682-
context = "mini.files visual selection"
683-
})
678+
-- Send files sequentially with proper delays
679+
local success_count = 0
680+
local total_count = #files
684681

685-
if success_count > 0 then
686-
logger.debug("selection", "Successfully sent " .. success_count .. "/" .. total_count .. " mini.files selections.")
687-
return true
688-
else
689-
logger.error("selection", "Failed to send any mini.files selections.")
690-
return false
682+
local function send_next_file(index)
683+
if index > total_count then
684+
-- All files processed, show summary
685+
if success_count > 0 then
686+
local message = success_count == 1 and "Added 1 file from mini.files"
687+
or string.format("Added %d files from mini.files", success_count)
688+
logger.info("selection", message)
689+
else
690+
logger.error("selection", "Failed to send any mini.files selections.")
691+
end
692+
return
693+
end
694+
695+
local file_path = files[index]
696+
local success, error_msg = claudecode_main.send_at_mention(file_path, nil, nil, "ClaudeCodeSend")
697+
if success then
698+
success_count = success_count + 1
699+
logger.debug("selection", "Sent mini.files selection: " .. file_path)
700+
else
701+
logger.error("selection", "Failed to send mini.files selection " .. file_path .. ": " .. (error_msg or "unknown error"))
702+
end
703+
704+
-- Send next file after a small delay
705+
if index < total_count then
706+
vim.defer_fn(function()
707+
send_next_file(index + 1)
708+
end, 200) -- 200ms delay between files
709+
else
710+
send_next_file(index + 1) -- Process final summary
711+
end
691712
end
713+
714+
-- Start sending files
715+
send_next_file(1)
716+
return true -- Return immediately, files are sent asynchronously
692717
end
693718

694719
local sel_to_send

0 commit comments

Comments
 (0)