@@ -241,19 +241,26 @@ local function generate_on_attach_function(list, unmapped_keys, remove_defaults)
241
241
for _ , m in ipairs (M .on_attach .list ) do
242
242
local keys = type (m .key ) == " table" and m .key or { m .key }
243
243
for _ , k in ipairs (keys ) do
244
- if LEGACY_MAPPINGS [m .action ] then
245
- -- straight action
244
+ local legacy_mapping = LEGACY_MAPPINGS [m .action ] or LEGACY_MAPPINGS [m .cb ]
245
+ if legacy_mapping then
246
+ -- straight action or cb, which generated an action string at setup time
246
247
vim .keymap .set (
247
248
m .mode or " n" ,
248
249
k ,
249
- LEGACY_MAPPINGS [ m . action ] .fn ,
250
- { desc = m .action , buffer = bufnr , noremap = true , silent = true , nowait = true }
250
+ legacy_mapping .fn ,
251
+ { desc = m .cb or m . action , buffer = bufnr , noremap = true , silent = true , nowait = true }
251
252
)
252
253
elseif type (m .action_cb ) == " function" then
253
254
-- action_cb
254
255
vim .keymap .set (m .mode or " n" , k , function ()
255
256
m .action_cb (api .tree .get_node_under_cursor ())
256
- end , { desc = m .action , buffer = bufnr , noremap = true , silent = true , nowait = true })
257
+ end , {
258
+ desc = m .action or " no description" ,
259
+ buffer = bufnr ,
260
+ noremap = true ,
261
+ silent = true ,
262
+ nowait = true ,
263
+ })
257
264
end
258
265
end
259
266
end
@@ -285,21 +292,22 @@ local function generate_on_attach_lua(list, unmapped_keys, remove_defaults)
285
292
for _ , m in ipairs (list ) do
286
293
local keys = type (m .key ) == " table" and m .key or { m .key }
287
294
for _ , k in ipairs (keys ) do
288
- if LEGACY_MAPPINGS [m .action ] then
295
+ local legacy_mapping = LEGACY_MAPPINGS [m .action ] or LEGACY_MAPPINGS [m .cb ]
296
+ if legacy_mapping then
289
297
lua = lua
290
298
.. string.format (
291
299
[[ vim.keymap.set('%s', '%s', %s, opts('%s'))]] ,
292
300
m .mode or " n" ,
293
301
k ,
294
- LEGACY_MAPPINGS [ m . action ] .n ,
295
- LEGACY_MAPPINGS [ m . action ] .desc
302
+ legacy_mapping .n ,
303
+ legacy_mapping .desc
296
304
)
297
305
.. " \n "
298
306
elseif type (m .action_cb ) == " function" then
299
307
lua = lua .. string.format ([[ vim.keymap.set('%s', '%s', function()]] , m .mode or " n" , k ) .. " \n "
300
308
lua = lua .. [[ local node = api.tree.get_node_under_cursor()]] .. " \n "
301
309
lua = lua .. [[ -- your code goes here]] .. " \n "
302
- lua = lua .. string.format ([[ end, opts('%s'))]] , m .action ) .. " \n\n "
310
+ lua = lua .. string.format ([[ end, opts('%s'))]] , m .action or " no description " ) .. " \n\n "
303
311
end
304
312
end
305
313
end
0 commit comments