diff --git a/lua/blink/cmp/completion/accept/init.lua b/lua/blink/cmp/completion/accept/init.lua index a057c369..533d4b5e 100644 --- a/lua/blink/cmp/completion/accept/init.lua +++ b/lua/blink/cmp/completion/accept/init.lua @@ -50,7 +50,7 @@ local function accept(ctx, item, callback) text_edits_lib.apply(all_text_edits) -- Expand the snippet - require('blink.cmp.config').accept.expand_snippet(item.textEdit.newText) + require('blink.cmp.config').snippets.expand(item.textEdit.newText) -- OR Normal: Apply the text edit and move the cursor else diff --git a/lua/blink/cmp/completion/list.lua b/lua/blink/cmp/completion/list.lua index cdce55c7..bcdda8ca 100644 --- a/lua/blink/cmp/completion/list.lua +++ b/lua/blink/cmp/completion/list.lua @@ -57,26 +57,24 @@ local list = { ---------- State ---------- function list.show(context, items) + -- reset state for new context local is_new_context = not list.context or list.context.id ~= context.id + if is_new_context then list.preview_undo_text_edit = nil end + list.context = context list.items = list.fuzzy(context, items or list.items) - vim.print(#list.items) if #list.items == 0 then list.hide_emitter:emit({ context = context }) else - vim.print('emitting') list.show_emitter:emit({ items = list.items, context = context }) end - -- reset state for new context - if not is_new_context then return end + -- todo: some logic to maintain the selection if the user moved the cursor? list.select(list.config.selection == 'preselect' and 1 or nil) - list.preview_undo_text_edit = nil end function list.fuzzy(context, items) - vim.print(#items) local fuzzy = require('blink.cmp.fuzzy') local sources = require('blink.cmp.sources.lib') @@ -91,15 +89,13 @@ function list.hide() list.hide_emitter:emit({ context = list.context }) end function list.get_selected_item() return list.items[list.selected_item_idx] end function list.select(idx) - if idx ~= nil and not list.items[idx] then - error('Invalid index while selecting from the completion list. ' .. idx) - end + local item = list.items[idx] list.undo_preview() - if list.config.selection == 'auto_insert' then list.apply_preview(list.items[idx]) end + if list.config.selection == 'auto_insert' and item then list.apply_preview(item) end list.selected_item_idx = idx - list.select_emitter:emit({ idx = idx, item = list.items[idx], items = list.items, context = list.context }) + list.select_emitter:emit({ idx = idx, item = item, items = list.items, context = list.context }) end function list.select_next() diff --git a/lua/blink/cmp/completion/windows/menu.lua b/lua/blink/cmp/completion/windows/menu.lua index d74718f7..32af8d35 100644 --- a/lua/blink/cmp/completion/windows/menu.lua +++ b/lua/blink/cmp/completion/windows/menu.lua @@ -58,9 +58,6 @@ function menu.open_with_items(context, items) -- it's possible for the window to close after updating the position -- if there was nowhere to place the window if not menu.win:is_open() then return end - - -- todo: some logic to maintain the selection if the user moved the cursor? - vim.api.nvim_win_set_cursor(menu.win:get_win(), { 1, 0 }) end function menu.open() @@ -82,11 +79,9 @@ function menu.close() end function menu.set_selected_item_idx(idx) - if idx == nil then menu.win:set_option_value('cursorline', false) end - menu.win:set_option_value('cursorline', true) - + menu.win:set_option_value('cursorline', idx ~= nil) menu.selected_item_idx = idx - if menu.win:is_open() then vim.api.nvim_win_set_cursor(menu.win:get_win(), { idx, 0 }) end + if menu.win:is_open() then vim.api.nvim_win_set_cursor(menu.win:get_win(), { idx or 1, 0 }) end end --- TODO: Don't switch directions if the context is the same diff --git a/lua/blink/cmp/highlights.lua b/lua/blink/cmp/highlights.lua index ad7b09cf..1956ff70 100644 --- a/lua/blink/cmp/highlights.lua +++ b/lua/blink/cmp/highlights.lua @@ -8,9 +8,12 @@ function highlights.setup() vim.api.nvim_set_hl(0, hl_group, opts) end - set_hl('BlinkCmpLabel', { link = use_nvim_cmp and 'CmpItemAbbr' or 'Pmenu' }) + if use_nvim_cmp then + set_hl('BlinkCmpLabel', { link = 'CmpItemAbbr' }) + set_hl('BlinkCmpLabelMatch', { link = 'CmpItemAbbrMatch' }) + end + set_hl('BlinkCmpLabelDeprecated', { link = use_nvim_cmp and 'CmpItemAbbrDeprecated' or 'NonText' }) - set_hl('BlinkCmpLabelMatch', { link = use_nvim_cmp and 'CmpItemAbbrMatch' or 'Pmenu' }) set_hl('BlinkCmpLabelDetail', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' }) set_hl('BlinkCmpLabelDescription', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' }) set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' }) diff --git a/lua/blink/cmp/init.lua b/lua/blink/cmp/init.lua index 999a495a..5e900d7c 100644 --- a/lua/blink/cmp/init.lua +++ b/lua/blink/cmp/init.lua @@ -81,7 +81,7 @@ end function cmp.show_documentation() local menu = require('blink.cmp.completion.windows.menu') - local documentation = require('blink.cmp.windows.documentation') + local documentation = require('blink.cmp.completion.windows.documentation') if documentation.win:is_open() or not menu.win:is_open() then return end local item = require('blink.cmp.completion.list').get_selected_item() @@ -92,7 +92,7 @@ function cmp.show_documentation() end function cmp.hide_documentation() - local documentation = require('blink.cmp.windows.documentation') + local documentation = require('blink.cmp.completion.windows.documentation') if not documentation.win:is_open() then return end vim.schedule(function() documentation.win:close() end) @@ -101,7 +101,7 @@ end --- @param count? number function cmp.scroll_documentation_up(count) - local documentation = require('blink.cmp.windows.documentation') + local documentation = require('blink.cmp.completion.windows.documentation') if not documentation.win:is_open() then return end vim.schedule(function() documentation.scroll_up(count or 4) end) @@ -110,7 +110,7 @@ end --- @param count? number function cmp.scroll_documentation_down(count) - local documentation = require('blink.cmp.windows.documentation') + local documentation = require('blink.cmp.completion.windows.documentation') if not documentation.win:is_open() then return end vim.schedule(function() documentation.scroll_down(count or 4) end)