Skip to content

Commit 4ce00db

Browse files
committed
fix: add fallback to local find/grep for failed remote live actions
When remote 'live_find' or 'live_grep' actions fail (e.g., connection not found, or the live action itself fails), the system now gracefully falls back to performing a local 'find' or 'grep' operation. This enhances robustness and user experience by ensuring that a search or find operation is always attempted, even if the remote live action encounters an issue.
1 parent ba11f96 commit 4ce00db

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lua/sshfs/api.lua

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ Api.live_grep = function(path)
194194
return
195195
end
196196

197+
local function fallback_to_local_grep(connection)
198+
local Picker = require("sshfs.ui.picker")
199+
Picker.grep_remote_files(nil, { dir = connection.mount_path })
200+
end
201+
197202
local function execute_live_grep(connection)
198203
local Picker = require("sshfs.ui.picker")
199204
local config = Config.get()
@@ -204,9 +209,10 @@ Api.live_grep = function(path)
204209

205210
if not success then
206211
vim.notify(
207-
"Live grep not available: " .. picker_name .. ". Install telescope or fzf-lua.",
208-
vim.log.levels.ERROR
212+
"Live grep not available: " .. picker_name .. ". Falling back to local grep on mounted path.",
213+
vim.log.levels.WARN
209214
)
215+
return fallback_to_local_grep(connection)
210216
end
211217
end
212218

@@ -236,6 +242,22 @@ Api.live_find = function(path)
236242
return
237243
end
238244

245+
local function fallback_to_local_find(connection)
246+
local Picker = require("sshfs.ui.picker")
247+
local config = Config.get()
248+
local ok, picker_name = Picker.open_file_picker(connection.mount_path, config, false)
249+
if not ok then
250+
vim.notify(
251+
"Fallback file picker failed for "
252+
.. connection.mount_path
253+
.. " ("
254+
.. picker_name
255+
.. "). Install a supported picker.",
256+
vim.log.levels.ERROR
257+
)
258+
end
259+
end
260+
239261
local function execute_live_find(connection)
240262
local Picker = require("sshfs.ui.picker")
241263
local config = Config.get()
@@ -246,9 +268,10 @@ Api.live_find = function(path)
246268

247269
if not success then
248270
vim.notify(
249-
"Live find not available: " .. picker_name .. ". Install telescope or fzf-lua.",
250-
vim.log.levels.ERROR
271+
"Live find not available: " .. picker_name .. ". Falling back to local find on mounted path.",
272+
vim.log.levels.WARN
251273
)
274+
return fallback_to_local_find(connection)
252275
end
253276
end
254277

lua/sshfs/ui/hooks.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ local function run_preset_action(preset, mount_dir, config)
7373
if preset == "live_grep" or preset == "live_find" then
7474
local conn = find_connection_by_mount(mount_dir)
7575
if not conn then
76-
vim.notify("No connection found for on_mount action: " .. mount_dir, vim.log.levels.WARN)
77-
return
76+
vim.notify("No connection found for on_mount action: " .. mount_dir .. " – falling back to local " .. (preset == "live_grep" and "grep" or "find"), vim.log.levels.WARN)
77+
return run_preset_action(preset == "live_grep" and "grep" or "find", mount_dir, config)
7878
end
7979
local Picker = require("sshfs.ui.picker")
8080
local fn = preset == "live_grep" and Picker.open_live_remote_grep or Picker.open_live_remote_find
8181
local ok, picker_name = fn(conn.host, conn.mount_path, conn.remote_path or ".", config)
8282
if not ok then
83-
vim.notify("Live action failed: " .. picker_name, vim.log.levels.ERROR)
83+
vim.notify("Live action failed: " .. picker_name .. " – falling back to local " .. (preset == "live_grep" and "grep" or "find"), vim.log.levels.WARN)
84+
return run_preset_action(preset == "live_grep" and "grep" or "find", mount_dir, config)
8485
end
8586
return
8687
end

0 commit comments

Comments
 (0)