feat(keys): add mapping rhs as description for temporary lazy mappings

Fixes `:map` not showing what the mapping does until the plugin is loaded.

With lazy mapping `{ "<Leader>f", "<Cmd>FzfLua files<CR>" },` `:map` now
shows:

```
n  <Space>f    * <Lua 79: ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/keys.lua:126>
                 <Cmd>FzfLua files<CR>
```

How `:map` looks after the plugin is loaded:
```
n  <Space>f    * <Cmd>FzfLua files<CR>
```
This commit is contained in:
Yaroslav Chvanov 2024-12-11 01:28:56 +03:00
commit 6bd07d0b71
No known key found for this signature in database
GPG key ID: CCF75EB2BBF8F69C

View file

@ -112,6 +112,11 @@ function M:_add(keys)
local lhs = keys.lhs
local opts = M.opts(keys)
local rhs = keys.rhs -- Work-around lua-language-server type inference.
-- Pass string rhs to desc to make it visible before loading the plugin, or we will only see file path to closure
-- below.
opts.desc = opts.desc or type(rhs) == "string" and rhs or nil
---@param buf? number
local function add(buf)
if M.is_nop(keys) then