@@ -81,35 +81,34 @@ function utils.map_selections(prompt_bufnr, f)
8181 end
8282end
8383
84- local findnth = function (str , nth )
85- local array = {}
86- for i in string.gmatch (str , " %d+" ) do
87- table.insert (array , tonumber (i ))
88- end
89- return array [nth ]
90- end
91-
9284--- Utility to collect mappings of prompt buffer in array of `{mode, keybind, name}`.
9385--- @param prompt_bufnr number : The prompt bufnr
9486function utils .get_registered_mappings (prompt_bufnr )
9587 local ret = {}
9688 for _ , mode in ipairs { " n" , " i" } do
97- local mode_mappings = vim .api .nvim_buf_get_keymap (prompt_bufnr , mode )
98- for _ , mapping in ipairs (mode_mappings ) do
89+ for _ , mapping in ipairs (vim .api .nvim_buf_get_keymap (prompt_bufnr , mode )) do
9990 -- ensure only telescope mappings
100- if mapping .rhs and string.find (mapping .rhs , [[ require%('telescope.mappings'%).execute_keymap]] ) then
101- local funcid = findnth (mapping .rhs , 2 )
102- table.insert (ret , { mode = mode , keybind = mapping .lhs , func = __TelescopeKeymapStore [prompt_bufnr ][funcid ] })
91+ if mapping .desc then
92+ if mapping .desc :sub (1 , 10 ) == " telescope|" then
93+ table.insert (ret , { mode = mode , keybind = mapping .lhs , desc = mapping .desc :sub (11 ) })
94+ elseif mapping .desc :sub (1 , 11 ) == " telescopej|" then
95+ local fname = utils ._get_anon_function_name (vim .json .decode (mapping .desc :sub (12 )))
96+ fname = fname :lower () == mapping .lhs :lower () and " <anonymous>" or fname
97+ table.insert (ret , {
98+ mode = mode ,
99+ keybind = mapping .lhs ,
100+ desc = fname ,
101+ })
102+ end
103103 end
104104 end
105105 end
106106 return ret
107107end
108108
109109-- Best effort to infer function names for actions.which_key
110- function utils ._get_anon_function_name (func_ref )
110+ function utils ._get_anon_function_name (info )
111111 local Path = require " plenary.path"
112- local info = debug.getinfo (func_ref )
113112 local fname
114113 -- if fn defined in string (ie loadstring) source is string
115114 -- if fn defined in file, source is file name prefixed with a `@´
0 commit comments