|
269 | 269 | --- @return table files List of file paths
|
270 | 270 | --- @return string|nil error Error message if operation failed
|
271 | 271 |
|
| 272 | +-- Helper function to get mini.files selection using explicit range |
| 273 | +function M._get_mini_files_selection_with_range(start_line, end_line) |
| 274 | + local success, mini_files = pcall(require, "mini.files") |
| 275 | + if not success then |
| 276 | + return {}, "mini.files not available" |
| 277 | + end |
| 278 | + |
| 279 | + local files = {} |
| 280 | + local bufnr = vim.api.nvim_get_current_buf() |
| 281 | + |
| 282 | + local logger = require("claudecode.logger") |
| 283 | + logger.debug("integrations", "mini.files range selection: " .. start_line .. " to " .. end_line) |
| 284 | + |
| 285 | + -- Process each line in the range |
| 286 | + for line = start_line, end_line do |
| 287 | + local entry_ok, entry = pcall(mini_files.get_fs_entry, bufnr, line) |
| 288 | + |
| 289 | + if entry_ok and entry and entry.path and entry.path ~= "" then |
| 290 | + -- Extract real filesystem path from mini.files buffer path |
| 291 | + local real_path = entry.path |
| 292 | + -- Remove mini.files buffer protocol prefix if present |
| 293 | + if real_path:match("^minifiles://") then |
| 294 | + real_path = real_path:gsub("^minifiles://[^/]*/", "") |
| 295 | + end |
| 296 | + |
| 297 | + -- Validate that the path exists |
| 298 | + if vim.fn.filereadable(real_path) == 1 or vim.fn.isdirectory(real_path) == 1 then |
| 299 | + table.insert(files, real_path) |
| 300 | + logger.debug("integrations", " added: " .. real_path) |
| 301 | + end |
| 302 | + end |
| 303 | + end |
| 304 | + |
| 305 | + logger.debug("integrations", "Range selection found " .. #files .. " files") |
| 306 | + |
| 307 | + if #files > 0 then |
| 308 | + return files, nil |
| 309 | + else |
| 310 | + return {}, "No files found in range" |
| 311 | + end |
| 312 | +end |
| 313 | + |
272 | 314 | function M._get_mini_files_selection()
|
273 | 315 | local success, mini_files = pcall(require, "mini.files")
|
274 | 316 | if not success then
|
|
0 commit comments