From 64d2f305d30cec13938aa99f8f13bd84c502e020 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Wed, 24 May 2023 22:29:20 -0700 Subject: [PATCH] fix: catch errors opening preview window (#113) --- lua/oil/mutator/preview.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/oil/mutator/preview.lua b/lua/oil/mutator/preview.lua index 073e4b1..07a0993 100644 --- a/lua/oil/mutator/preview.lua +++ b/lua/oil/mutator/preview.lua @@ -90,7 +90,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb) -- Create the floating window local width, height = layout.calculate_dims(max_line_width, #lines + 1, config.preview) - local winid = vim.api.nvim_open_win(bufnr, true, { + local ok, winid = pcall(vim.api.nvim_open_win, bufnr, true, { relative = "editor", width = width, height = height, @@ -100,6 +100,10 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb) style = "minimal", border = config.preview.border, }) + if not ok then + vim.notify(string.format("Error showing oil preview window: %s", winid), vim.log.levels.ERROR) + cb(false) + end vim.bo[bufnr].filetype = "oil_preview" vim.bo[bufnr].syntax = "oil_preview" for k, v in pairs(config.preview.win_options) do