Skip to content

Commit

Permalink
nvim: let's try copilot-cmp finally
Browse files Browse the repository at this point in the history
a fork of copilot-cmp can now show results on empty lines

zbirenbaum/copilot-cmp#5 (comment)
  • Loading branch information
andreykaipov committed Apr 25, 2024
1 parent 334eae4 commit d280076
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 29 deletions.
3 changes: 2 additions & 1 deletion home/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"bufferline.nvim": { "branch": "main", "commit": "64e2c5def50dfd6b6f14d96a45fa3d815a4a1eef" },
"catppuccin": { "branch": "main", "commit": "045e3499d9ec8d84635fb08877ae44fd33f6a38d" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-copilot": { "branch": "master", "commit": "351fc8cc439234f78bd208bee62449ed966ec5a6" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"conform.nvim": { "branch": "master", "commit": "c92e265eb94a78bf0033a54f1f734fd7d69f48b9" },
"copilot.vim": { "branch": "release", "commit": "3b39e786d865df9ba77fe61624d6ee646528a809" },
"copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" },
"dashboard-nvim": { "branch": "master", "commit": "413442b12d85315fc626c44a0ce4929b213ef604" },
"dressing.nvim": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" },
"friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" },
Expand Down
1 change: 1 addition & 0 deletions home/nvim/lua/config/lazy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local config = {
{ import = "lazyvim.plugins.extras.lang.tex" },
{ import = "lazyvim.plugins.extras.lang.typescript" },
{ import = "lazyvim.plugins.extras.lang.yaml" },
-- { import = "lazyvim.plugins.extras.coding.copilot" },
{ import = "plugins" },
defaults = {
autocmds = true,
Expand Down
101 changes: 73 additions & 28 deletions home/nvim/lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
return {
{
"github/copilot.vim",
event = { "InsertEnter", "VeryLazy" },
-- priority = 200,
-- cmd = "Copilot",
-- build = ":Copilot auth",
config = function()
vim.keymap.set("i", "<s-tab>", "<plug>(copilot-suggest)")
vim.keymap.set("i", "<c-e>", "<plug>(copilot-accept-line)")
vim.keymap.set("i", "<c-w>", "<plug>(copilot-next)")

-- vim.keymap.set("i", "<c-j>", 'copilot#accept("\\<cr>")', {
-- expr = true,
-- replace_keycodes = false,
-- })
-- vim.g.copilot_no_tab_map = true
-- vim.keymap.set('i', '<c-i>', '<plug>(copilot-previous)')
-- vim.keymap.set("i", "<c-l>", "<plug>(copilot-accept-word)")
end,
},
-- {
-- "github/copilot.vim",
-- event = { "InsertEnter", "VeryLazy" },
-- -- priority = 200,
-- -- cmd = "Copilot",
-- -- build = ":Copilot auth",
-- config = function()
-- vim.keymap.set("i", "<s-tab>", "<plug>(copilot-suggest)")
-- vim.keymap.set("i", "<c-e>", "<plug>(copilot-accept-line)")
-- vim.keymap.set("i", "<c-w>", "<plug>(copilot-next)")
--
-- -- vim.keymap.set("i", "<c-j>", 'copilot#accept("\\<cr>")', {
-- -- expr = true,
-- -- replace_keycodes = false,
-- -- })
-- -- vim.g.copilot_no_tab_map = true
-- -- vim.keymap.set('i', '<c-i>', '<plug>(copilot-previous)')
-- -- vim.keymap.set("i", "<c-l>", "<plug>(copilot-accept-word)")
-- end,
-- },
{
"L3MON4D3/LuaSnip",
event = { "InsertEnter", "VeryLazy" },
Expand All @@ -29,6 +29,39 @@ return {
-- use ^j and ^k instead
keys = false,
},
-- have to do this all manually instead of using
-- lazyvim.plugins.extras.coding.copilot because i'm using a fork of
-- copilot-cmp (see https://github.com/zbirenbaum/copilot-cmp/issues/5)
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
build = ":Copilot auth",
opts = {
suggestion = { enabled = false },
panel = { enabled = false },
filetypes = {
markdown = true,
help = true,
},
},
},
{
"JosefLitos/cmp-copilot",
event = { "InsertEnter", "VeryLazy" },
dependencies = "copilot.lua",
opts = {},
config = function(_, opts)
local copilot_cmp = require("cmp_copilot")
copilot_cmp.setup(opts)
-- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source
require("lazyvim.util").lsp.on_attach(function(client)
if client.name == "copilot" then
copilot_cmp._on_insert_enter({})

This comment has been minimized.

Copy link
@litoj

litoj Apr 25, 2024

Are you sure you need this entire config function? I've never had issues with this myself, but I've noticed some funky code in the plugin that might have been related.

Should be all fixed now, making this unnecessary.

end
end)
end,
},
{
"hrsh7th/nvim-cmp",
event = { "InsertEnter", "VeryLazy" },
Expand All @@ -38,7 +71,7 @@ return {

-- ref: https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/config/default.lua
-- ghost text is off for cmp since we use copilot.vim, i like it more than copilot.lua
opts.experimental.ghost_text = false
opts.experimental.ghost_text = true
opts.window = { completion = {}, documentation = {} }
opts.window.completion.border = "solid"
opts.window.documentation.border = "solid"
Expand All @@ -55,6 +88,17 @@ return {
cmp.TriggerEvent.InsertEnter,
}

opts.sources = cmp.config.sources({
-- Copilot Source
{ name = "copilot", group_index = 2, priority = 100 },
-- Other Sources
{ name = "nvim_lsp", group_index = 2 },
{ name = "path", group_index = 2 },
{ name = "luasnip", group_index = 2 },
}, {
{ name = "buffer" },
})

local has_words_before = function()
cmp.unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
Expand Down Expand Up @@ -132,6 +176,14 @@ return {
fallback()
end
end),
["<S-CR>"] = function(fallback)
if cmp.visible() then
-- force carriage return if we ever want to insert newline without confirming completion
cmp.abort()
fallback()
end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<CR>", true, false, true), "i", true)
end,
["<CR>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() then
Expand Down Expand Up @@ -163,13 +215,6 @@ return {
end
end,
}),
["<C-CR>"] = function()
if cmp.visible() then
-- force carriage return if we ever want to insert newline without confirming completion
cmp.abort()
end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<CR>", true, false, true), "i", true)
end,
})
cmp.setup(opts)
end,
Expand Down

0 comments on commit d280076

Please sign in to comment.