From 9342e94f22a2635bc8d3ddec86ecd3fe23b49dd0 Mon Sep 17 00:00:00 2001 From: Daniel-De-Dev Date: Tue, 25 Nov 2025 17:47:48 +0000 Subject: [PATCH 1/5] feat(keymaps): implemented more detailed descriptions By default all keymaps got the description `blink.cmp` for someone new to the keymaps (like me) it's very helpful to with a tool like Telescope be able to quickly look up what keymaps do. Hence the description is very important to provide the detail. Logic has been added to generate a description in the format: ``` Blink: command_1, command_2, ... (mode) ``` This is just a very quick solution implemented which is good enough for me, as far as im aware this change is self contained and affects essentially nothing other than the descriptions. --- lua/blink/cmp/keymap/apply.lua | 71 ++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/lua/blink/cmp/keymap/apply.lua b/lua/blink/cmp/keymap/apply.lua index 156ef70f..ac68ecff 100644 --- a/lua/blink/cmp/keymap/apply.lua +++ b/lua/blink/cmp/keymap/apply.lua @@ -2,17 +2,60 @@ local apply = {} local snippet_commands = { 'snippet_forward', 'snippet_backward', 'show_signature', 'hide_signature' } +local readable_names = { + ['show'] = "Show", + ['hide'] = "Hide", + ['accept'] = "Accept", + ['select_prev'] = "Select Prev", + ['select_next'] = "Select Next", + ['show_documentation'] = "Show Docs", + ['hide_documentation'] = "Hide Docs", + ['scroll_documentation_up'] = "Scroll Docs Up", + ['scroll_documentation_down'] = "Scroll Docs Down", + ['snippet_forward'] = "Snippet Forward", + ['snippet_backward'] = "Snippet Backward", +} + +-- Generates descriptions for the commands +local function get_desc(commands, mode_label) + local suffix = mode_label and (" " .. mode_label) or "" + + if type(commands) ~= 'table' then + return "Blink: " .. tostring(commands) .. suffix + end + + local parts = {} + for _, cmd in ipairs(commands) do + -- Filter out "fallback" + if cmd ~= 'fallback' and cmd ~= 'fallback_to_mappings' then + if type(cmd) == 'string' then + table.insert(parts, readable_names[cmd] or cmd) + elseif type(cmd) == 'function' then + table.insert(parts, "Custom") + end + end + end + + -- If the list is empty (Only Fallback) + if #parts == 0 then + return "Blink: Default Behavior" .. suffix + end + + return "Blink: " .. table.concat(parts, ", ") .. suffix +end + --- Applies the keymaps to the current buffer --- @param keys_to_commands table function apply.keymap_to_current_buffer(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(0, 'i')) do - if mapping.desc == 'blink.cmp' then return end + if mapping.desc and mapping.desc:find('^Blink:') then return end end -- insert mode: uses both snippet and insert commands for key, commands in pairs(keys_to_commands) do local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) + local desc = get_desc(commands, "(insert)") apply.set('i', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -32,7 +75,7 @@ function apply.keymap_to_current_buffer(keys_to_commands) return end end - end) + end, desc) end -- snippet mode: uses only snippet commands @@ -40,6 +83,8 @@ function apply.keymap_to_current_buffer(keys_to_commands) if not apply.has_snippet_commands(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('s', key) + local desc = get_desc(commands, "(snippet)") + apply.set('s', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -58,7 +103,7 @@ function apply.keymap_to_current_buffer(keys_to_commands) if did_run then return end end end - end) + end, desc) ::continue:: end @@ -81,7 +126,7 @@ end function apply.term_keymaps(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(0, 't')) do - if mapping.desc == 'blink.cmp' then return end + if mapping.desc and mapping.desc:find('^Blink:') then return end end -- terminal mode: uses insert commands only @@ -89,6 +134,8 @@ function apply.term_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) + local desc = get_desc(commands, "(terminal)") + apply.set('t', key, function() for _, command in ipairs(commands) do -- special case for fallback @@ -104,7 +151,7 @@ function apply.term_keymaps(keys_to_commands) return end end - end) + end, desc) ::continue:: end @@ -113,7 +160,7 @@ end function apply.cmdline_keymaps(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_get_keymap('c')) do - if mapping.desc == 'blink.cmp' then return end + if mapping.desc and mapping.desc:find('^Blink:') then return end end -- cmdline mode: uses only insert commands @@ -121,9 +168,10 @@ function apply.cmdline_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('c', key) + local desc = get_desc(commands, "(cmdline)") + apply.set('c', key, function() for _, command in ipairs(commands) do - -- special case for fallback if command == 'fallback' or command == 'fallback_to_mappings' then return fallback(command == 'fallback_to_mappings') @@ -137,7 +185,7 @@ function apply.cmdline_keymaps(keys_to_commands) if did_run then return end end end - end) + end, desc) ::continue:: end @@ -146,7 +194,8 @@ end --- @param mode string --- @param key string --- @param callback fun(): string | nil -function apply.set(mode, key, callback) +--- @param desc string|nil +function apply.set(mode, key, callback, desc) if mode == 'c' or mode == 't' then vim.api.nvim_set_keymap(mode, key, '', { callback = callback, @@ -156,7 +205,7 @@ function apply.set(mode, key, callback) silent = false, noremap = true, replace_keycodes = false, - desc = 'blink.cmp', + desc = desc or 'blink.cmp', }) else vim.api.nvim_buf_set_keymap(0, mode, key, '', { @@ -165,7 +214,7 @@ function apply.set(mode, key, callback) silent = true, noremap = true, replace_keycodes = false, - desc = 'blink.cmp', + desc = desc or 'blink.cmp', }) end end From 894fbcd66998c97501e664e451398902123e45cb Mon Sep 17 00:00:00 2001 From: Daniel-De-Dev Date: Tue, 25 Nov 2025 18:48:54 +0000 Subject: [PATCH 2/5] style: format lua/blink/cmp/keymap/apply.lua This is to pass the stylua check --- lua/blink/cmp/keymap/apply.lua | 44 ++++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lua/blink/cmp/keymap/apply.lua b/lua/blink/cmp/keymap/apply.lua index ac68ecff..9fc0883b 100644 --- a/lua/blink/cmp/keymap/apply.lua +++ b/lua/blink/cmp/keymap/apply.lua @@ -3,26 +3,24 @@ local apply = {} local snippet_commands = { 'snippet_forward', 'snippet_backward', 'show_signature', 'hide_signature' } local readable_names = { - ['show'] = "Show", - ['hide'] = "Hide", - ['accept'] = "Accept", - ['select_prev'] = "Select Prev", - ['select_next'] = "Select Next", - ['show_documentation'] = "Show Docs", - ['hide_documentation'] = "Hide Docs", - ['scroll_documentation_up'] = "Scroll Docs Up", - ['scroll_documentation_down'] = "Scroll Docs Down", - ['snippet_forward'] = "Snippet Forward", - ['snippet_backward'] = "Snippet Backward", + ['show'] = 'Show', + ['hide'] = 'Hide', + ['accept'] = 'Accept', + ['select_prev'] = 'Select Prev', + ['select_next'] = 'Select Next', + ['show_documentation'] = 'Show Docs', + ['hide_documentation'] = 'Hide Docs', + ['scroll_documentation_up'] = 'Scroll Docs Up', + ['scroll_documentation_down'] = 'Scroll Docs Down', + ['snippet_forward'] = 'Snippet Forward', + ['snippet_backward'] = 'Snippet Backward', } -- Generates descriptions for the commands local function get_desc(commands, mode_label) - local suffix = mode_label and (" " .. mode_label) or "" + local suffix = mode_label and (' ' .. mode_label) or '' - if type(commands) ~= 'table' then - return "Blink: " .. tostring(commands) .. suffix - end + if type(commands) ~= 'table' then return 'Blink: ' .. tostring(commands) .. suffix end local parts = {} for _, cmd in ipairs(commands) do @@ -31,17 +29,15 @@ local function get_desc(commands, mode_label) if type(cmd) == 'string' then table.insert(parts, readable_names[cmd] or cmd) elseif type(cmd) == 'function' then - table.insert(parts, "Custom") + table.insert(parts, 'Custom') end end end -- If the list is empty (Only Fallback) - if #parts == 0 then - return "Blink: Default Behavior" .. suffix - end + if #parts == 0 then return 'Blink: Default Behavior' .. suffix end - return "Blink: " .. table.concat(parts, ", ") .. suffix + return 'Blink: ' .. table.concat(parts, ', ') .. suffix end --- Applies the keymaps to the current buffer @@ -55,7 +51,7 @@ function apply.keymap_to_current_buffer(keys_to_commands) -- insert mode: uses both snippet and insert commands for key, commands in pairs(keys_to_commands) do local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) - local desc = get_desc(commands, "(insert)") + local desc = get_desc(commands, '(insert)') apply.set('i', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -83,7 +79,7 @@ function apply.keymap_to_current_buffer(keys_to_commands) if not apply.has_snippet_commands(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('s', key) - local desc = get_desc(commands, "(snippet)") + local desc = get_desc(commands, '(snippet)') apply.set('s', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -134,7 +130,7 @@ function apply.term_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) - local desc = get_desc(commands, "(terminal)") + local desc = get_desc(commands, '(terminal)') apply.set('t', key, function() for _, command in ipairs(commands) do @@ -168,7 +164,7 @@ function apply.cmdline_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('c', key) - local desc = get_desc(commands, "(cmdline)") + local desc = get_desc(commands, '(cmdline)') apply.set('c', key, function() for _, command in ipairs(commands) do From fce85eb3d69a8b8f1c56118dc558e22500ba3e2c Mon Sep 17 00:00:00 2001 From: Daniel-De-Dev Date: Wed, 26 Nov 2025 02:52:41 +0000 Subject: [PATCH 3/5] refactor: simplified description generation - Instead if using a predefined table, the readable names are instead generated by simply substituting '_' with space, then captilize the first letter of each token. - Changed prefix to instead be `blink.cmp: ` - Removed mode subfix --- lua/blink/cmp/keymap/apply.lua | 55 ++++++++++++++-------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/lua/blink/cmp/keymap/apply.lua b/lua/blink/cmp/keymap/apply.lua index 9fc0883b..37f9650f 100644 --- a/lua/blink/cmp/keymap/apply.lua +++ b/lua/blink/cmp/keymap/apply.lua @@ -2,42 +2,31 @@ local apply = {} local snippet_commands = { 'snippet_forward', 'snippet_backward', 'show_signature', 'hide_signature' } -local readable_names = { - ['show'] = 'Show', - ['hide'] = 'Hide', - ['accept'] = 'Accept', - ['select_prev'] = 'Select Prev', - ['select_next'] = 'Select Next', - ['show_documentation'] = 'Show Docs', - ['hide_documentation'] = 'Hide Docs', - ['scroll_documentation_up'] = 'Scroll Docs Up', - ['scroll_documentation_down'] = 'Scroll Docs Down', - ['snippet_forward'] = 'Snippet Forward', - ['snippet_backward'] = 'Snippet Backward', -} - --- Generates descriptions for the commands -local function get_desc(commands, mode_label) - local suffix = mode_label and (' ' .. mode_label) or '' - - if type(commands) ~= 'table' then return 'Blink: ' .. tostring(commands) .. suffix end +-- The prefix each description begins with +local prefix = 'blink.cmp: ' +-- Generates description based on commands +--- @param commands blink.cmp.KeymapCommand[] +--- @return string +local function get_desc(commands) local parts = {} for _, cmd in ipairs(commands) do - -- Filter out "fallback" + -- Filter out "fallback" & "fallback_to_mappings" if cmd ~= 'fallback' and cmd ~= 'fallback_to_mappings' then if type(cmd) == 'string' then - table.insert(parts, readable_names[cmd] or cmd) + -- Substitute all '_' with space, then captilize seperated token + local readable_cmd = cmd:gsub('_', ' ') + readable_cmd = readable_cmd:gsub('(%a)(%w*)', function(first, rest) return first:upper() .. rest end) + table.insert(parts, readable_cmd) elseif type(cmd) == 'function' then - table.insert(parts, 'Custom') + table.insert(parts, '') end end end - -- If the list is empty (Only Fallback) - if #parts == 0 then return 'Blink: Default Behavior' .. suffix end - - return 'Blink: ' .. table.concat(parts, ', ') .. suffix + -- In case the list consisted of only fallbacks + if #parts == 0 then return prefix .. 'Default Behavior' end + return prefix .. table.concat(parts, ', ') end --- Applies the keymaps to the current buffer @@ -45,13 +34,13 @@ end function apply.keymap_to_current_buffer(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(0, 'i')) do - if mapping.desc and mapping.desc:find('^Blink:') then return end + if mapping.desc and mapping.desc:find('^' .. prefix) then return end end -- insert mode: uses both snippet and insert commands for key, commands in pairs(keys_to_commands) do local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) - local desc = get_desc(commands, '(insert)') + local desc = get_desc(commands) apply.set('i', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -79,7 +68,7 @@ function apply.keymap_to_current_buffer(keys_to_commands) if not apply.has_snippet_commands(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('s', key) - local desc = get_desc(commands, '(snippet)') + local desc = get_desc(commands) apply.set('s', key, function() if not require('blink.cmp.config').enabled() then return fallback() end @@ -122,7 +111,7 @@ end function apply.term_keymaps(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(0, 't')) do - if mapping.desc and mapping.desc:find('^Blink:') then return end + if mapping.desc and mapping.desc:find('^' .. prefix) then return end end -- terminal mode: uses insert commands only @@ -130,7 +119,7 @@ function apply.term_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('i', key) - local desc = get_desc(commands, '(terminal)') + local desc = get_desc(commands) apply.set('t', key, function() for _, command in ipairs(commands) do @@ -156,7 +145,7 @@ end function apply.cmdline_keymaps(keys_to_commands) -- skip if we've already applied the keymaps for _, mapping in ipairs(vim.api.nvim_get_keymap('c')) do - if mapping.desc and mapping.desc:find('^Blink:') then return end + if mapping.desc and mapping.desc:find('^' .. prefix) then return end end -- cmdline mode: uses only insert commands @@ -164,7 +153,7 @@ function apply.cmdline_keymaps(keys_to_commands) if not apply.has_insert_command(commands) then goto continue end local fallback = require('blink.cmp.keymap.fallback').wrap('c', key) - local desc = get_desc(commands, '(cmdline)') + local desc = get_desc(commands) apply.set('c', key, function() for _, command in ipairs(commands) do From 2695c0426091da7d93bfccb3bd902a48bf091024 Mon Sep 17 00:00:00 2001 From: Daniel-De-Dev Date: Wed, 26 Nov 2025 03:07:13 +0000 Subject: [PATCH 4/5] spell: Corrected spelling --- lua/blink/cmp/keymap/apply.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/blink/cmp/keymap/apply.lua b/lua/blink/cmp/keymap/apply.lua index 37f9650f..85a76b4b 100644 --- a/lua/blink/cmp/keymap/apply.lua +++ b/lua/blink/cmp/keymap/apply.lua @@ -14,7 +14,7 @@ local function get_desc(commands) -- Filter out "fallback" & "fallback_to_mappings" if cmd ~= 'fallback' and cmd ~= 'fallback_to_mappings' then if type(cmd) == 'string' then - -- Substitute all '_' with space, then captilize seperated token + -- Substitute all '_' with space, then captilize separated token local readable_cmd = cmd:gsub('_', ' ') readable_cmd = readable_cmd:gsub('(%a)(%w*)', function(first, rest) return first:upper() .. rest end) table.insert(parts, readable_cmd) From c2b9eb7aa695cb5f29a28a6a3a93e65099312b81 Mon Sep 17 00:00:00 2001 From: Daniel-De-Dev Date: Wed, 26 Nov 2025 05:19:45 +0000 Subject: [PATCH 5/5] refactor: abbreviate custom function description - Update comment for clarity - Abbreviate '' to '' to save UI space --- lua/blink/cmp/keymap/apply.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/blink/cmp/keymap/apply.lua b/lua/blink/cmp/keymap/apply.lua index 85a76b4b..8d9d7927 100644 --- a/lua/blink/cmp/keymap/apply.lua +++ b/lua/blink/cmp/keymap/apply.lua @@ -14,18 +14,19 @@ local function get_desc(commands) -- Filter out "fallback" & "fallback_to_mappings" if cmd ~= 'fallback' and cmd ~= 'fallback_to_mappings' then if type(cmd) == 'string' then - -- Substitute all '_' with space, then captilize separated token + -- Separate on '_', then captilize each token local readable_cmd = cmd:gsub('_', ' ') readable_cmd = readable_cmd:gsub('(%a)(%w*)', function(first, rest) return first:upper() .. rest end) table.insert(parts, readable_cmd) elseif type(cmd) == 'function' then - table.insert(parts, '') + table.insert(parts, '') end end end -- In case the list consisted of only fallbacks if #parts == 0 then return prefix .. 'Default Behavior' end + return prefix .. table.concat(parts, ', ') end