diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 18d08ad1a8..6eebee6376 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -283,6 +283,14 @@ local function get_path(sect, name, silent) return end + -- `man -w /some/path` will return `/some/path` for any existent file, which + -- stops us from actually determining if a path has a corresponding man file. + -- Since `:Man /some/path/to/man/file` isn't supported anyway, we should just + -- error out here if we detect this is the case. + if sect == '' and #results == 1 and results[1] == name then + return + end + -- find any that match the specified name local namematches = vim.tbl_filter(function(v) return fn.fnamemodify(v, ':t'):match(name) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 3e63c5df9a..203424c855 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -6,6 +6,8 @@ local exec_lua = helpers.exec_lua local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local matches = helpers.matches +local write_file = helpers.write_file +local tmpname = helpers.tmpname clear() if funcs.executable('man') == 0 then @@ -156,4 +158,16 @@ describe(':Man', function() local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'} matches('quit works!!', funcs.system(args, {'manpage contents'})) end) + + it('reports non-existent man pages for absolute paths', function() + local actual_file = tmpname() + -- actual_file must be an absolute path to an existent file for us to test against it + matches('^/.+', actual_file) + write_file(actual_file, '') + local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'} + matches(('Error detected while processing command line:\r\n' .. + 'man.lua: "no manual entry for %s"'):format(actual_file), + funcs.system(args, {''})) + os.remove(actual_file) + end) end)