change completion plugin
this was done to support dynamically enabling AI autosuggestion and is disabled by default
This commit is contained in:
parent
ec750a0e89
commit
6e2a88508c
7 changed files with 114 additions and 126 deletions
|
|
@ -12,8 +12,15 @@ return {
|
|||
config = function()
|
||||
require("copilot").setup({
|
||||
suggestion = { enabled = false },
|
||||
panel = { enabled = true, auto_refresh = true },
|
||||
panel = { enabled = false },
|
||||
})
|
||||
|
||||
vim.g.copilot_autocomplete_enabled = false
|
||||
|
||||
vim.api.nvim_create_user_command("CopilotToggleAutocomplete", function()
|
||||
vim.g.copilot_autocomplete_enabled = not vim.g.copilot_autocomplete_enabled
|
||||
print("Copilot autocompletion: " .. tostring(vim.g.copilot_autocomplete_enabled))
|
||||
end, { desc = "Toggle Copilot autocompletion" })
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
|
@ -62,6 +69,7 @@ return {
|
|||
},
|
||||
}
|
||||
end,
|
||||
|
||||
keys = {
|
||||
{
|
||||
"<leader>at",
|
||||
|
|
|
|||
|
|
@ -1,120 +1,107 @@
|
|||
---@diagnostic disable: missing-fields
|
||||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
version = false, -- last release is way too old
|
||||
event = "InsertEnter",
|
||||
"saghen/blink.cmp",
|
||||
lazy = false,
|
||||
version = "*",
|
||||
dependencies = {
|
||||
"L3MON4D3/LuaSnip",
|
||||
"davidsierradz/cmp-conventionalcommits",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-path",
|
||||
"petertriho/cmp-git",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"windwp/nvim-autopairs",
|
||||
{
|
||||
"zbirenbaum/copilot-cmp",
|
||||
config = function()
|
||||
require("copilot_cmp").setup()
|
||||
end
|
||||
},
|
||||
"rafamadriz/friendly-snippets",
|
||||
"giuxtaposition/blink-cmp-copilot",
|
||||
"folke/lazydev.nvim",
|
||||
{ "saghen/blink.compat", version = "*", },
|
||||
},
|
||||
config = function()
|
||||
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
|
||||
local cmp = require("cmp")
|
||||
|
||||
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
|
||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
||||
|
||||
local defaults = require("cmp.config.default")()
|
||||
local window_opts = {
|
||||
opts = function()
|
||||
local window_options = {
|
||||
border = "rounded",
|
||||
side_padding = 1,
|
||||
-- fix colors for catppuccin colorscheme
|
||||
winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None",
|
||||
winblend = vim.o.pumblend,
|
||||
}
|
||||
local opts = {
|
||||
visible_docs = false,
|
||||
completion = {
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
|
||||
---@module 'blink.cmp'
|
||||
---@type blink.cmp.Config
|
||||
return {
|
||||
sources = {
|
||||
providers = {
|
||||
dadbod = { name = "Dadbod", module = "vim_dadbod_completion.blink" },
|
||||
lazydev = { name = "LazyDev", module = "lazydev.integrations.blink" },
|
||||
copilot = {
|
||||
name = "copilot",
|
||||
module = "blink-cmp-copilot",
|
||||
score_offset = 5,
|
||||
enabled = function()
|
||||
if vim.g.copilot_autocomplete_enabled == nil then
|
||||
return false
|
||||
end
|
||||
return vim.g.copilot_autocomplete_enabled
|
||||
end,
|
||||
},
|
||||
luasnip = {
|
||||
name = 'luasnip',
|
||||
module = 'blink.compat.source',
|
||||
score_offset = -3,
|
||||
opts = {
|
||||
use_show_condition = false,
|
||||
show_autosnippets = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
-- nvim-cmp sources
|
||||
compat = {},
|
||||
completion = {
|
||||
enabled_providers = {
|
||||
"copilot",
|
||||
"lsp",
|
||||
"path",
|
||||
"snippets",
|
||||
"buffer",
|
||||
"dadbod",
|
||||
"lazydev",
|
||||
},
|
||||
},
|
||||
},
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
accept = {
|
||||
auto_brackets = { enabled = true },
|
||||
expand_snippet = function(snippet) require('luasnip').lsp_expand(snippet) end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-o>"] = function()
|
||||
if cmp.visible_docs() then
|
||||
cmp.close_docs()
|
||||
else
|
||||
cmp.open_docs()
|
||||
end
|
||||
end,
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<BR>"] = cmp.mapping.abort(),
|
||||
["<C-CR>"] = cmp.mapping.confirm({ select = false }), -- Confirm only if selected an item
|
||||
["<CR>"] = cmp.mapping.confirm({
|
||||
-- Auto confirms first item
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
trigger = { signature_help = { enabled = true } },
|
||||
keymap = {
|
||||
preset = "enter",
|
||||
["<C-u>"] = { 'scroll_documentation_up', 'fallback' },
|
||||
["<C-d>"] = { 'scroll_documentation_down', 'fallback' },
|
||||
},
|
||||
highlight = {
|
||||
-- sets the fallback highlight groups to nvim-cmp's highlight groups
|
||||
-- useful for when your theme doesn't support blink.cmp
|
||||
-- will be removed in a future release, assuming themes add support
|
||||
use_nvim_cmp_as_default = false,
|
||||
},
|
||||
-- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
|
||||
-- adjusts spacing to ensure icons are aligned
|
||||
nerd_font_variant = "mono",
|
||||
windows = {
|
||||
autocomplete = vim.tbl_extend("force", window_options, {
|
||||
selection = "manual",
|
||||
---@type blink.cmp.Draw
|
||||
draw = {
|
||||
components = {
|
||||
kind_icon = {
|
||||
text = function(ctx)
|
||||
if ctx.item.source_name == "copilot" then
|
||||
ctx.kind_icon = require("aleidk.constants").icons.kinds.Copilot
|
||||
end
|
||||
|
||||
return ctx.kind_icon .. ctx.icon_gap
|
||||
end,
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
documentation = vim.tbl_extend("force", window_options, {
|
||||
auto_show = true,
|
||||
winblend = 0,
|
||||
}),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "conventionalcommits" },
|
||||
{ name = "copilot" },
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
formatting = {
|
||||
fields = { "kind", "abbr", "menu" },
|
||||
format = function(_, item)
|
||||
local icons = require("aleidk.constants").icons.kinds
|
||||
if icons[item.kind] then
|
||||
item.kind = icons[item.kind] .. item.kind
|
||||
end
|
||||
return item
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(window_opts),
|
||||
documentation = cmp.config.window.bordered(window_opts),
|
||||
},
|
||||
experimental = {
|
||||
ghost_text = {
|
||||
hl_group = "CmpGhostText",
|
||||
},
|
||||
},
|
||||
sorting = {
|
||||
priority_weight = 2,
|
||||
comparators = {
|
||||
require("copilot_cmp.comparators").prioritize,
|
||||
|
||||
-- Below is the default comparitor list and order for nvim-cmp
|
||||
cmp.config.compare.offset,
|
||||
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
|
||||
cmp.config.compare.exact,
|
||||
cmp.config.compare.score,
|
||||
cmp.config.compare.recently_used,
|
||||
cmp.config.compare.locality,
|
||||
cmp.config.compare.kind,
|
||||
cmp.config.compare.sort_text,
|
||||
cmp.config.compare.length,
|
||||
cmp.config.compare.order,
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
kind_icons = require("aleidk.constants").icons.kinds,
|
||||
}
|
||||
|
||||
cmp.setup(opts)
|
||||
end,
|
||||
end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ return {
|
|||
-- Automatically install LSPs to stdpath for neovim
|
||||
{ "williamboman/mason.nvim", config = true },
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
{ 'saghen/blink.cmp' } -- autocompletion
|
||||
},
|
||||
|
||||
config = function()
|
||||
|
|
@ -146,7 +147,7 @@ return {
|
|||
|
||||
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
||||
capabilities = require("blink.cmp").get_lsp_capabilities(capabilities)
|
||||
|
||||
-- Ensure the servers above are installed
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue