Skip to content

Commit

Permalink
feat(keys): add mapping rhs as description for temporary lazy mappings
Browse files Browse the repository at this point in the history
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>
```
  • Loading branch information
staticssleever668 committed Dec 10, 2024
1 parent b97ee16 commit 6bd07d0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/lazy/core/handler/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bd07d0

Please sign in to comment.