Skip to content

Commit

Permalink
Enable copilot_cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
semanser committed Jan 18, 2024
1 parent 05669a7 commit 23fa77a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
19 changes: 11 additions & 8 deletions nvim/.config/nvim/lua/plugins/coding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ return {
config = function()
require("copilot").setup({
suggestion = {
auto_trigger = true,
debounce = 100,
keymap = {
accept = "<C-l>",
},
enabled = false,
},
panel = {
enabled = false,
},
filetypes = {
typescriptreact = true,
Expand All @@ -41,8 +40,12 @@ return {
server_opts_overrides = {},
})
end,
dependencies = {
"zbirenbaum/copilot-cmp",
},
},
{
"zbirenbaum/copilot-cmp",
after = { "copilot.lua" },
config = function()
require("copilot_cmp").setup()
end,
},
}
29 changes: 24 additions & 5 deletions nvim/.config/nvim/lua/plugins/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,44 @@ return {
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
-- https://github.com/zbirenbaum/copilot-cmp?tab=readme-ov-file#tab-completion-configuration-highly-recommended
["<Tab>"] = vim.schedule_wrap(function(fallback)
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0
and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$")
== nil
end

if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
fallback()
end
end),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
sources = {
{ name = "copilot", group_index = 2 },
{ name = "nvim_lsp" },
{ name = "buffer" },
}),
{ name = "nvim_lsp", group_index = 2 },
{ name = "buffer", group_index = 2 },
},
formatting = {
format = lspkind.cmp_format({
mode = "text_symbol", -- show only symbol annotations
mode = "symbol_text", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
-- can also be a function to dynamically calculate max width such as
-- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
show_labelDetails = true, -- show labelDetails in menu. Disabled by default
symbol_map = { Copilot = "" },

-- The function below will be called before any actual modifications from lspkind
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
Expand Down

0 comments on commit 23fa77a

Please sign in to comment.