Skip to content

Commit dd014cc

Browse files
authored
fix: suppress non-critical errors on opening file (e.g E325) (#217)
1 parent a75b1bf commit dd014cc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lua/neo-tree/utils.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ M.open_file = function(state, path, open_cmd)
307307
if M.truthy(path) then
308308
local escaped_path = vim.fn.fnameescape(path)
309309
local events = require("neo-tree.events")
310+
local result = true
311+
local err = nil
310312
local event_result = events.fire_event(events.FILE_OPEN_REQUESTED, {
311313
state = state,
312314
path = path,
@@ -317,7 +319,7 @@ M.open_file = function(state, path, open_cmd)
317319
return
318320
end
319321
if state.current_position == "current" then
320-
vim.cmd(open_cmd .. " " .. escaped_path)
322+
result, err = pcall(vim.cmd, open_cmd .. " " .. escaped_path)
321323
else
322324
-- use last window if possible
323325
local suitable_window_found = false
@@ -349,13 +351,17 @@ M.open_file = function(state, path, open_cmd)
349351
-- Neo-tree must be the only window, restore it's status as a sidebar
350352
local winid = vim.api.nvim_get_current_win()
351353
local width = M.get_value(state, "window.width", 40)
352-
vim.cmd("vsplit " .. escaped_path)
354+
result, err = pcall(vim.cmd, "vsplit " .. escaped_path)
353355
vim.api.nvim_win_set_width(winid, width)
354356
else
355-
vim.cmd(open_cmd .. " " .. escaped_path)
357+
result, err = pcall(vim.cmd, open_cmd .. " " .. escaped_path)
356358
end
357359
end
358-
events.fire_event(events.FILE_OPENED, path)
360+
if (result or err == "Vim(edit):E325: ATTENTION") then
361+
events.fire_event(events.FILE_OPENED, path)
362+
else
363+
log.error("Error opening file:", err)
364+
end
359365
end
360366
end
361367

0 commit comments

Comments
 (0)