fix(vim.ui.open): return (don't show) error message

Problem:
Showing an error via vim.notify() makes it awkward for callers such as
lsp/handlers.lua to avoid showing redundant errors.

Solution:
Return the message instead of showing it. Let the caller decide whether
and when to show the message.
This commit is contained in:
Justin M. Keyes
2023-07-04 23:33:23 +02:00
parent 67b2ed1004
commit e644e7ce0b
5 changed files with 38 additions and 23 deletions

View File

@@ -5,6 +5,7 @@ local exec_lua = helpers.exec_lua
local clear = helpers.clear
local feed = helpers.feed
local eval = helpers.eval
local is_os = helpers.is_os
local poke_eventloop = helpers.poke_eventloop
describe('vim.ui', function()
@@ -133,15 +134,17 @@ describe('vim.ui', function()
describe('open()', function()
it('validation', function()
exec_lua[[vim.ui.open('non-existent-file')]]
matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', eval('v:errmsg'))
if not is_os('bsd') then
matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }',
exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]])
end
exec_lua[[
vim.fn.has = function() return 0 end
vim.fn.executable = function() return 0 end
]]
exec_lua[[vim.ui.open('foo')]]
eq('vim.ui.open: no handler found (tried: wslview, xdg-open)', eval('v:errmsg'))
eq('vim.ui.open: no handler found (tried: wslview, xdg-open)',
exec_lua[[local _, err = vim.ui.open('foo') ; return err]])
end)
end)
end)