diff options
author | Mahmoud Al-Qudsi <mqudsi@neosmart.net> | 2022-10-17 04:37:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 10:37:44 +0100 |
commit | 39911d76be560c998cc7dee51c5d94f811164f66 (patch) | |
tree | 626cc4a1317cdae822887cbc8b21fc1174dc6516 /runtime/lua/man.lua | |
parent | 190019dd79aa66d9be9003b0249473634dd854eb (diff) | |
download | rneovim-39911d76be560c998cc7dee51c5d94f811164f66.tar.gz rneovim-39911d76be560c998cc7dee51c5d94f811164f66.tar.bz2 rneovim-39911d76be560c998cc7dee51c5d94f811164f66.zip |
fix(man): handle absolute paths as `:Man` targets (#20624)
* fix(man): handle absolute paths as :Man targets
Previously, attempting to provide `:Man` with an absolute path as the name would
cause neovim to return the following error:
```
Error detected while processing command line:
/usr/local/share/nvim/runtime/lua/man.lua:690: /usr/local/share/nvim/runtime/lua/man.lua:683: Vim:E426: tag not found: nil(nil)
Press ENTER or type command to continue
```
..because it would try to validate the existence of a man page for the provided
name by executing `man -w /some/path` which (on at least some Linux machines
[0]) returns `/some/path` instead of the path to the nroff files that would be
formatted to satisfy the man(1) lookup.
While man pages are not normally named after absolute paths, users shouldn't be
blamed for trying. Given such a name/path, neovim would **not** complain that
the path didn't have a corresponding man file but would error out when trying
to call the tag function for the null-propagated name-and-section `nil(nil)`.
(The same underlying error existed before this function was ported to lua, but
did not exhibit the lua-specific `nil(nil)` name; instead a tag lookup for `()`
would fail and error out.)
With this patch, we detect the case where `man -w ...` returns the same value as
the provided name to not only prevent invoking the tag function for a
non-existent/malformed name+sect but also to properly report the non-existence
of a man page for the provided lookup (the absolute path).
While man(1) can be used to directly read an nroff-formatted document via `man
/path/to/nroff.doc`, `:Man /path/to/nroff.doc` never supported this behavior so
no functionality is lost in case the provided path _was_ an nroff file.
[0]: `man -w /absolute/path` returning `/absolute/path` observed on an Ubuntu
18.04 installation.
* test: add regression test for #20624
Add a functional test to `man_spec.lua` to check for a regression for #20624 by
first obtaining an absolute path to a random file and materializing it to disk,
then attempting to query `:Man` for an entry by that same name/path.
The test passes if nvim correctly reports that there is no man page
correspending to the provided name/path and fails if any other error (or no
error) is shown.
Diffstat (limited to 'runtime/lua/man.lua')
-rw-r--r-- | runtime/lua/man.lua | 8 |
1 files changed, 8 insertions, 0 deletions
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) |