|
268 | 268 | --- Reference: mini.files API MiniFiles.get_fs_entry() |
269 | 269 | --- @return table files List of file paths |
270 | 270 | --- @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 | + local logger = require("claudecode.logger") |
| 282 | + logger.debug("integrations", "mini.files range selection:") |
| 283 | + logger.debug("integrations", " start_line: " .. tostring(start_line)) |
| 284 | + logger.debug("integrations", " end_line: " .. tostring(end_line)) |
| 285 | + |
| 286 | + -- Process each line in the range |
| 287 | + for line = start_line, end_line do |
| 288 | + logger.debug("integrations", " processing line " .. tostring(line)) |
| 289 | + local entry_ok, entry = pcall(mini_files.get_fs_entry, bufnr, line) |
| 290 | + |
| 291 | + if entry_ok and entry then |
| 292 | + logger.debug("integrations", " entry found: " .. tostring(entry.path)) |
| 293 | + if entry.path and entry.path ~= "" then |
| 294 | + -- Extract real filesystem path from mini.files buffer path |
| 295 | + local real_path = entry.path |
| 296 | + -- Remove mini.files buffer protocol prefix if present |
| 297 | + if real_path:match("^minifiles://") then |
| 298 | + real_path = real_path:gsub("^minifiles://[^/]*/", "") |
| 299 | + end |
| 300 | + |
| 301 | + logger.debug("integrations", " real_path: " .. tostring(real_path)) |
| 302 | + |
| 303 | + -- Validate that the path exists |
| 304 | + if vim.fn.filereadable(real_path) == 1 or vim.fn.isdirectory(real_path) == 1 then |
| 305 | + logger.debug("integrations", " adding to files: " .. real_path) |
| 306 | + table.insert(files, real_path) |
| 307 | + else |
| 308 | + logger.debug("integrations", " path not readable/directory: " .. real_path) |
| 309 | + end |
| 310 | + else |
| 311 | + logger.debug("integrations", " entry has no path or empty path") |
| 312 | + end |
| 313 | + else |
| 314 | + logger.debug("integrations", " no entry or pcall failed for line " .. tostring(line)) |
| 315 | + end |
| 316 | + end |
| 317 | + |
| 318 | + logger.debug("integrations", "mini.files range selection result: " .. #files .. " files found") |
| 319 | + for i, file in ipairs(files) do |
| 320 | + logger.debug("integrations", " file " .. i .. ": " .. file) |
| 321 | + end |
| 322 | + |
| 323 | + if #files > 0 then |
| 324 | + return files, nil |
| 325 | + else |
| 326 | + return {}, "No file found under cursor" |
| 327 | + end |
| 328 | +end |
| 329 | + |
271 | 330 | function M._get_mini_files_selection() |
272 | 331 | local success, mini_files = pcall(require, "mini.files") |
273 | 332 | if not success then |
|
0 commit comments