Skip to content

Commit 5a4c1eb

Browse files
committed
refactor: clean up unnecessary mini.files handling in selection.lua
- Remove complex mini.files detection logic from selection module - Remove range-based selection function (not needed) - Remove unnecessary test file - Keep only essential path extraction fixes in get_visual_selection, get_cursor_position, get_range_selection The existing command handler already properly uses integrations.get_selected_files_from_tree() first, so we don't need duplicate logic in the selection module.
1 parent b2a71c6 commit 5a4c1eb

File tree

3 files changed

+0
-347
lines changed

3 files changed

+0
-347
lines changed

lua/claudecode/integrations.lua

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -268,41 +268,6 @@ end
268268
--- Reference: mini.files API MiniFiles.get_fs_entry()
269269
--- @return table files List of file paths
270270
--- @return string|nil error Error message if operation failed
271-
-- Helper function to get mini.files selection using explicit range
272-
function M._get_mini_files_selection_with_range(start_line, end_line)
273-
local success, mini_files = pcall(require, "mini.files")
274-
if not success then
275-
return {}, "mini.files not available"
276-
end
277-
278-
local files = {}
279-
local bufnr = vim.api.nvim_get_current_buf()
280-
281-
-- Process each line in the range
282-
for line = start_line, end_line do
283-
local entry_ok, entry = pcall(mini_files.get_fs_entry, bufnr, line)
284-
285-
if entry_ok and entry and entry.path and entry.path ~= "" then
286-
-- Extract real filesystem path from mini.files buffer path
287-
local real_path = entry.path
288-
-- Remove mini.files buffer protocol prefix if present
289-
if real_path:match("^minifiles://") then
290-
real_path = real_path:gsub("^minifiles://[^/]*/", "")
291-
end
292-
293-
-- Validate that the path exists
294-
if vim.fn.filereadable(real_path) == 1 or vim.fn.isdirectory(real_path) == 1 then
295-
table.insert(files, real_path)
296-
end
297-
end
298-
end
299-
300-
if #files > 0 then
301-
return files, nil
302-
else
303-
return {}, "No file found under cursor"
304-
end
305-
end
306271

307272
function M._get_mini_files_selection()
308273
local success, mini_files = pcall(require, "mini.files")

lua/claudecode/selection.lua

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -659,81 +659,6 @@ function M.send_at_mention_for_visual_selection(line1, line2)
659659
return false
660660
end
661661

662-
-- Special handling for mini.files: use integrations module instead of selection system
663-
local current_ft = vim.bo.filetype
664-
local current_buf_name = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf())
665-
666-
if current_ft == "minifiles" or current_buf_name:match("^minifiles://") then
667-
local integrations = require("claudecode.integrations")
668-
local files, err
669-
670-
if line1 and line2 then
671-
-- Range-based selection, get files directly using the range
672-
files, err = integrations._get_mini_files_selection_with_range(line1, line2)
673-
else
674-
-- No range provided, try to get last visual selection range
675-
local last_visual_start = vim.fn.line("'<")
676-
local last_visual_end = vim.fn.line("'>")
677-
678-
if last_visual_start > 0 and last_visual_end > 0 and last_visual_start <= last_visual_end then
679-
files, err = integrations._get_mini_files_selection_with_range(last_visual_start, last_visual_end)
680-
else
681-
-- Fall back to current mode detection
682-
files, err = integrations.get_selected_files_from_tree()
683-
end
684-
end
685-
686-
if err then
687-
logger.error("selection", "Failed to get mini.files selection: " .. err)
688-
return false
689-
end
690-
691-
if not files or #files == 0 then
692-
logger.warn("selection", "No files selected in mini.files.")
693-
return false
694-
end
695-
696-
-- Send files sequentially with proper delays
697-
local success_count = 0
698-
local total_count = #files
699-
700-
local function send_next_file(index)
701-
if index > total_count then
702-
-- All files processed, show summary
703-
if success_count > 0 then
704-
local message = success_count == 1 and "Added 1 file from mini.files"
705-
or string.format("Added %d files from mini.files", success_count)
706-
logger.info("selection", message)
707-
else
708-
logger.error("selection", "Failed to send any mini.files selections.")
709-
end
710-
return
711-
end
712-
713-
local file_path = files[index]
714-
local success, error_msg = claudecode_main.send_at_mention(file_path, nil, nil, "ClaudeCodeSend")
715-
if success then
716-
success_count = success_count + 1
717-
logger.debug("selection", "Sent mini.files selection: " .. file_path)
718-
else
719-
logger.error("selection", "Failed to send mini.files selection " .. file_path .. ": " .. (error_msg or "unknown error"))
720-
end
721-
722-
-- Send next file after a small delay
723-
if index < total_count then
724-
vim.defer_fn(function()
725-
send_next_file(index + 1)
726-
end, 200) -- 200ms delay between files
727-
else
728-
send_next_file(index + 1) -- Process final summary
729-
end
730-
end
731-
732-
-- Start sending files
733-
send_next_file(1)
734-
return true -- Return immediately, files are sent asynchronously
735-
end
736-
737662
local sel_to_send
738663

739664
-- If range parameters are provided, use them (for :'<,'> commands)

tests/unit/mini_files_selection_spec.lua

Lines changed: 0 additions & 237 deletions
This file was deleted.

0 commit comments

Comments
 (0)