Skip to content

Commit

Permalink
fix(blink-cmp): update keymaps and add lazydev support
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Nov 7, 2024
1 parent 95cfc4c commit 580686c
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions lua/astrocommunity/completion/blink-cmp/init.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
local function has_words_before()
local line, col = (unpack or table.unpack)(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end

return {
"Saghen/blink.cmp",
event = "InsertEnter",
version = "v0.*",
version = "*",
dependencies = { "rafamadriz/friendly-snippets" },
opts_extend = { "sources.completion.enabled_providers" },
opts = {
-- remember to enable your providers here
sources = { completion = { enabled_providers = { "lsp", "path", "snippets", "buffer" } } },
-- experimental auto-brackets support
accept = { auto_brackets = { enabled = true } },
keymap = {
show = { "<C-Space>", "<C-N>", "<C-P>" },
accept = { "<Tab>", "<CR>" },
select_prev = { "<Up>", "<C-P>", "<C-K>" },
select_next = { "<Down>", "<C-N>", "<C-J>" },
scroll_documentation_up = "<C-D>",
scroll_documentation_down = "<C-U>",
["<C-Space>"] = { "show", "show_documentation", "hide_documentation" },
["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" },
["<C-N>"] = { "select_next", "show" },
["<C-P>"] = { "select_prev", "show" },
["<C-J>"] = { "select_next", "fallback" },
["<C-K>"] = { "select_prev", "fallback" },
["<C-U>"] = { "scroll_documentation_up", "fallback" },
["<C-D>"] = { "scroll_documentation_down", "fallback" },
["<C-e>"] = { "hide", "fallback" },
["<CR>"] = { "accept", "fallback" },
["<Tab>"] = {
function(cmp)
if cmp.windows.autocomplete.win:is_open() then
return cmp.select_next()
elseif cmp.is_in_snippet() then
return cmp.snippet_forward()
elseif has_words_before() then
return cmp.show()
end
end,
"fallback",
},
["<S-Tab>"] = {
function(cmp)
if cmp.windows.autocomplete.win:is_open() then
return cmp.select_prev()
elseif cmp.is_in_snippet() then
return cmp.snippet_backward()
end
end,
"fallback",
},
},
windows = {
autocomplete = {
Expand All @@ -29,6 +66,26 @@ return {
},
},
specs = {
{
"folke/lazydev.nvim",
optional = true,
specs = {
{
"Saghen/blink.cmp",
opts = {
sources = {
-- add lazydev to your completion providers
completion = { enabled_providers = { "lazydev" } },
providers = {
-- dont show LuaLS require statements when lazydev has items
lsp = { fallback_for = { "lazydev" } },
lazydev = { name = "LazyDev", module = "lazydev.integrations.blink" },
},
},
},
},
},
},
-- disable built in completion plugins
{ "hrsh7th/nvim-cmp", enabled = false },
{ "rcarriga/cmp-dap", enabled = false },
Expand Down

0 comments on commit 580686c

Please sign in to comment.