-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove all nvim-cmp related plugins and switch to blink-cmp.
- Loading branch information
1 parent
e99ee6b
commit 8d75afa
Showing
6 changed files
with
140 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,78 @@ | ||
-- Link CmpGhostText to Comment | ||
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) | ||
|
||
local cmp = require("cmp") | ||
local defaults = require("cmp.config.default")() | ||
local suggestion = require("copilot.suggestion") | ||
|
||
local opts = { | ||
enabled = function() | ||
-- disable completion in comments | ||
local context = require("cmp.config.context") | ||
-- keep command mode completion enabled when cursor is in a comment | ||
if vim.api.nvim_get_mode().mode == "c" then | ||
return true | ||
else | ||
return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") | ||
end | ||
end, | ||
performance = { | ||
debounce = 120, | ||
require("blink.cmp").setup({ | ||
keymap = { | ||
preset = "enter", | ||
["<C-y>"] = { "select_and_accept" }, | ||
["<C-e>"] = { | ||
function(cmp) | ||
suggestion.dismiss() -- Dismiss copilot suggestions | ||
return cmp.cancel() | ||
end, | ||
"fallback", | ||
}, | ||
["<Tab>"] = { | ||
"snippet_forward", | ||
function(cmp) | ||
if suggestion.is_visible() then | ||
return cmp.hide() | ||
end | ||
end, | ||
"fallback", | ||
}, | ||
}, | ||
auto_brackets = {}, -- configure any filetype to auto add brackets | ||
completion = { | ||
completeopt = "menu,menuone,noinsert,noselect", | ||
keyword_length = 3, | ||
appearance = { | ||
use_nvim_cmp_as_default = true, | ||
nerd_font_variant = "mono", | ||
kind_icons = require("icons").kinds, | ||
}, | ||
preselect = cmp.PreselectMode.Item, | ||
snippet = { | ||
expand = function(args) | ||
vim.snippet.expand(args.body) | ||
end, | ||
signature = { enabled = true }, | ||
sources = { | ||
default = { "lsp", "path", "snippets", "buffer", "emoji" }, | ||
cmdline = {}, | ||
providers = { | ||
lsp = { | ||
min_keyword_length = function(ctx) | ||
-- Always show this provider when trigger is manual | ||
-- i.e. <C-space> is pressed. | ||
return ctx.trigger.kind == "manual" and 0 or 1 | ||
end, | ||
score_offset = 0, | ||
}, | ||
path = { | ||
min_keyword_length = 0, | ||
}, | ||
snippets = { | ||
min_keyword_length = 2, | ||
}, | ||
buffer = { | ||
min_keyword_length = 5, | ||
max_items = 5, | ||
}, | ||
emoji = { | ||
module = "blink-emoji", | ||
name = "Emoji", | ||
score_offset = 15, -- Tune by preference | ||
opts = { insert = true }, -- Insert emoji (default) or complete its name | ||
}, | ||
}, | ||
}, | ||
mapping = cmp.mapping.preset.insert({ | ||
["<Tab>"] = cmp.mapping(function(fallback) | ||
if vim.snippet.active({ direction = 1 }) then | ||
vim.schedule(function() | ||
vim.snippet.jump(1) | ||
end) | ||
elseif suggestion.is_visible() and cmp.visible() then | ||
cmp.close() | ||
elseif suggestion.is_visible() then | ||
-- Ignore TextChanged events to prevent triggering | ||
-- completion again after accepting a suggestion | ||
local origin = vim.o.eventignore | ||
vim.o.eventignore = "TextChangedI,TextChangedP" | ||
suggestion.accept() | ||
vim.defer_fn(function() | ||
vim.o.eventignore = origin | ||
end, 10) | ||
-- vim.schedule(function() | ||
-- -- We need to schedule this to close the completion menu after accepting the suggestion | ||
-- cmp.abort() | ||
-- end) | ||
else | ||
fallback() | ||
end | ||
end, { "i", "s" }), | ||
|
||
["<S-Tab>"] = cmp.mapping(function(fallback) | ||
if vim.snippet.active({ direction = -1 }) then | ||
vim.schedule(function() | ||
vim.snippet.jump(-1) | ||
end) | ||
else | ||
fallback() | ||
end | ||
end, { "i", "s" }), | ||
|
||
-- Show next Copilot suggestion | ||
["<C-k>"] = cmp.mapping(function() | ||
suggestion.next() | ||
end, { "i" }), | ||
|
||
-- Show prev Copilot suggestion | ||
["<C-j>"] = cmp.mapping(function() | ||
suggestion.prev() | ||
end, { "i" }), | ||
|
||
-- Accept next word | ||
["<C-l>"] = cmp.mapping(function(fallback) | ||
if suggestion.is_visible() then | ||
suggestion.accept_word() | ||
else | ||
fallback() | ||
end | ||
end, { "i" }), | ||
completion = { | ||
accept = { auto_brackets = { enabled = true } }, | ||
|
||
-- Accept line | ||
["<C-S-l>"] = cmp.mapping(function(fallback) | ||
if suggestion.is_visible() then | ||
suggestion.accept_line() | ||
else | ||
fallback() | ||
end | ||
end, { "i" }), | ||
documentation = { | ||
auto_show = true, | ||
auto_show_delay_ms = 250, | ||
treesitter_highlighting = true, | ||
}, | ||
|
||
["<C-y>"] = cmp.mapping.confirm({ | ||
behavior = cmp.ConfirmBehavior.Replace, | ||
select = true, | ||
}, { "i", "c" }), | ||
["<C-n>"] = cmp.mapping.select_next_item(), | ||
["<C-p>"] = cmp.mapping.select_prev_item(), | ||
["<C-b>"] = cmp.mapping.scroll_docs(-4), | ||
["<C-f>"] = cmp.mapping.scroll_docs(4), | ||
["<C-Space>"] = cmp.mapping.complete(), | ||
["<C-e>"] = cmp.mapping(function() | ||
-- Dismiss Copilot | ||
suggestion.dismiss() | ||
cmp.abort() | ||
end, { "i" }), | ||
["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert }), | ||
["<S-CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace }), | ||
}), | ||
sources = cmp.config.sources({ | ||
{ name = "nvim_lsp_signature_help", keyword_length = 1 }, | ||
{ name = "nvim_lsp", keyword_length = 1 }, | ||
-- { name = "copilot", keyword_length = 3 }, | ||
{ | ||
name = "snippets", | ||
keyword_length = 2, | ||
priority = 99, | ||
menu = { | ||
draw = { | ||
columns = { | ||
{ "kind_icon", "label", gap = 1 }, | ||
{ "kind" }, | ||
}, | ||
}, | ||
}, | ||
{ name = "path" }, | ||
}, { | ||
{ name = "buffer", keyword_length = 3 }, | ||
}, { | ||
{ name = "emoji", priority = 999 }, | ||
}), | ||
formatting = { | ||
format = function(_, item) | ||
local icons = require("icons").kinds | ||
if icons[item.kind] then | ||
item.kind = icons[item.kind] .. item.kind | ||
end | ||
return item | ||
end, | ||
}, | ||
experimental = { | ||
ghost_text = false, -- { hl_group = "CmpGhostText" }, | ||
}, | ||
sorting = defaults.sorting, | ||
} | ||
|
||
for _, source in ipairs(opts.sources) do | ||
source.group_index = source.group_index or 1 | ||
end | ||
|
||
-- clangd extensions | ||
table.insert(opts.sorting.comparators, 1, require("clangd_extensions.cmp_scores")) | ||
|
||
cmp.setup(opts) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters