Giter Site home page Giter Site logo

copilot-cmp's Introduction

copilot-cmp's People

Contributors

algmyr avatar dklymenk avatar glyphack avatar imzhongqi avatar knpwrs avatar muniftanjim avatar sitiom avatar svilupp avatar techcaotri avatar xfo-0 avatar zbirenbaum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

copilot-cmp's Issues

Suggestions for empty line.

Common use case of copilot is
1 write a comment
2 go to next line
3 accept suggestion

This is not working, even when I force trigger cmp (cmp.mapping.complete()) then also it does not show any completion from copilot, but has other sources like buffer.
If I write a character copilot suggestion works, but not on empty line.

Support for manually requesting new suggestions

Thank you so much for this awesome plugin, it works great and it is a really valuable addition to workflows. I would like to request some ability to add a keymap to erase the current copilot suggestion and trigger a new one. I have tried with copilot.lua options, but they don't seem to translate to this plugins' suggestions inside cmp. Right now the easiest way to do this is to change surrounding code or add a comment until it starts suggesting again.

yesterday's commit introduced a bug

Error detected while processing TextChangedI Autocommands for "*":
Error executing lua callback: .../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:325: attempt to call method 'com
plete' (a nil value)
stack traceback:
.../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:325: in function 'complete'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:289: in function 'complete'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:169: in function 'callback'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:219: in function 'autoindent'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:161: in function 'on_change'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/init.lua:313: in function 'callback'
...ite/pack/packer/start/nvim-cmp/lua/cmp/utils/autocmd.lua:49: in function 'emit'
...ite/pack/packer/start/nvim-cmp/lua/cmp/utils/autocmd.lua:23: in function <...ite/pack/packer/start/nvim-cmp/lua
/cmp/utils/autocmd.lua:22>

Error Attempt to call method 'complete' (a nil value)

Hello :)
I recently updated my plugins and after I did I was met with the following error
image

I did some investigating in the code and found the bug and I have a fix for it:
In source.lua line 57 opts.method gives the value getCompletionCycling and not getCompletionsCycling (The difference is the singular Completion vs Completions). Then when it's passed down to completion_functions.init in line 88, completion_functions don't have the method getCompletionCycling so everything returns back nil which causes the mentioned error above when trying to call the complete function from source

I would love to create a pull request for the fix myself but if that's not possible I can provide snippets for the fix :)

Thank you for making an amazing plugin, I use it everyday โญ ๐Ÿ˜

Insert the first word or the first line only

When I type I want a b, assume the first completion item is beautiful dog. If I press Enter, I will accept that as a whole and I will have I want a beautiful dog.

What I want is another mapping, say <C-w> to accept only the first space separated word, i.e. when I press <C-w>, I want to have I want a beautiful. Then I can type cat and I will have I want a beautiful cat.

So basically I want to intercept the completion text, split it by space or by newline and insert the splitted first word or first line into the buffer instead of the whole completion text.

After inserting the first word or newline, the completion suggestions will be updated and hopefully better ones.

Copilot suggestion goes to the beginning of the line on enter

When I use enter to accept a suggestion from copilot it always puts it at the beginning of the line, ignoring any tabulation or the position of the cursor. This happens with all the languages.

Does this happen to someone else?
I need to do a minimal config error, but I wanted to ask because it might be something known.

Here is an example:

Screen.Recording.2022-04-30.at.12.22.34.mov

Error when trying to complete an empty line

copilot-cmp is making suggestions for empty lines, but when I try to accept them using tab I get the following error:

E5108: Error executing lua ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:154: Vim:E5108: Error executing lua [string "v:lua"]:1: attempt to call global 'tab_complete' (a nil value)
stack traceback:
        [string "v:lua"]:1: in main chunk
        [C]: in function 'nvim_eval'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:154: in function 'solve'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:133: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:132>
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:248: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:247>
stack traceback:
        [C]: in function 'nvim_eval'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:154: in function 'solve'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:133: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:132>
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:248: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:247>

cmp config is pretty much just from the docs:

      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
      return {
        snippet = {
          expand = function(args)
            luasnip.lsp_expand(args.body) -- For `luasnip` users.
          end,
        },
        completeopt = "menu,menuone,noinsert",
        mapping = {
          ["<CR>"] = cmp.mapping.confirm({
            behavior = cmp.ConfirmBehavior.Replace,
            select = false,
          }),
          ["<Tab>"] = vim.schedule_wrap(function(fallback)
            if cmp.visible() and has_words_before() then
              cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
            else
              fallback()
            end
          end, { "i", "s" }),
          ["<S-Tab>"] = vim.schedule_wrap(function(fallback)
            if cmp.visible() and has_words_before() then
              cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
            else
              fallback()
            end
          end, { "i", "s" }),
        },
[...]
keymap("i", "<tab>", "v:lua.tab_complete()", {expr = true, noremap = true})

no longer seeing suggestions

I'm no longer seeing any copilot suggestions, can you recommend a way to debug?

I have made some changes to my configs, however, I am still seeing suggestions from all other cmp sources.

Constant format.lua errors

I seem to get this when I'm just typing but it comes on and off randomly hard to duplicate.

NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Error executing vim.schedule lua callback: ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/format.lua:61: Index out of bounds
stack traceback:
	[C]: in function 'nvim_buf_get_text'
	...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/format.lua:61: in function 'get_line_text'
	...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/format.lua:76: in function 'format_fn'
	...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/format.lua:97: in function 'insert_text'
	...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:7: in function <...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:6>
	vim/shared.lua: in function 'tbl_map'
	...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:39: in function 'format_completions'
	...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:61: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

copilot source registered multiple times.

Running :CmpStatus shows:

# ready source names
- dictionary
- nvim_lsp_document_symbol
- nvim_lsp_signature_help
- nvim_lua
- buffer
- path
- luasnip
- nvim_lsp:null-ls
- copilot
- copilot
- nvim_lsp:sumneko_lua
- copilot
- copilot

It appears any time an InsertEnter event occurs, the source is added. Perhaps using once would address the issue.

double prompt

When I hit Enter to select the candidate, it confirms the selection, but it prompts a cmp list again.
CleanShot 2022-07-01 at 21 07 54

Toggle completion source

Hey,
I'm currently trying to toggle the completion from copilot on or off, but it seems, that even when toggling to off the completion from copilot.lua, cmp still uses copilot as a source.
Is there any way to toggle the source on or off?

Slow Performance?

Using cmp-copilot, I usually get the suggestion almost immediately, while for this plugin I sometimes have to wait for around 5 seconds.

module 'copilot.util' not found

Hi i get the following issue.

Error detected while processing InsertEnter Autocommands for "*":                                                                                                                                                                                                                                                             
Error executing lua callback: ...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:2: module 'copilot.util' not found:                                                                                                                                                                                                 
        no field package.preload['copilot.util']                                                                                                                                                                                                                                                                              
        no file './copilot/util.lua'                                                                                                                                                                                                                                                                                          
        no file '/usr/share/luajit-2.1.0-beta3/copilot/util.lua'                                                                                                                                                                                                                                                              
        no file '/usr/local/share/lua/5.1/copilot/util.lua'                                                                                                                                                                                                                                                                   
        no file '/usr/local/share/lua/5.1/copilot/util/init.lua'                                                                                                                                                                                                                                                              
        no file '/usr/share/lua/5.1/copilot/util.lua'                                                                                                                                                                                                                                                                         
        no file '/usr/share/lua/5.1/copilot/util/init.lua'                                                                                                                                                                                                                                                                    
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/copilot/util.lua'                                                                                                                                                                                                                      
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/copilot/util/init.lua'                                                                                                                                                                                                                 
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/copilot/util.lua'                                                                                                                                                                                                             
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/copilot/util/init.lua'                                                                                                                                                                                                        
        no file './copilot/util.so'                                                                                                                                                                                                                                                                                           
        no file '/usr/local/lib/lua/5.1/copilot/util.so'                                                                                                                                                                                                                                                                      
        no file '/usr/lib64/lua/5.1/copilot/util.so'                                                                                                                                                                                                                                                                          
        no file '/usr/local/lib/lua/5.1/loadall.so'                                                                                                                                                                                                                                                                           
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/copilot/util.so'                                                                                                                                                                                                                         
        no file './copilot.so'                                                                                                                                                                                                                                                                                                
        no file '/usr/local/lib/lua/5.1/copilot.so'                                                                                                                                                                                                                                                                           
        no file '/usr/lib64/lua/5.1/copilot.so'                                                                                                                                                                                                                                                                               
        no file '/usr/local/lib/lua/5.1/loadall.so'                                                                                                                                                                                                                                                                           
        no file '~/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/copilot.so'                                                                                                                                                                                                                              
stack traceback:                                                                                                                                                                                                                                                                                                              
        [C]: in function 'require'                                                                                                                                                                                                                                                                                            
        ...opt/copilot-cmp/lua/copilot_cmp/completion_functions.lua:2: in main chunk                                                                                                                                                                                                                                          
        [C]: in function 'require'                                                                                                                                                                                                                                                                                            
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:60: in function 'new'                                                                                                                                                                                                                                     
        ...ite/pack/packer/opt/copilot-cmp/lua/copilot_cmp/init.lua:46: in function <...ite/pack/packer/opt/copilot-cmp/lua/copilot_cmp/init.lua:42>

This is sometimes/mostly happening when i use these two lines in my cmp config file:
What am i missing?

sorting = {
  comparators = {
    ..
    require("copilot_cmp.comparators").prioritize,
    require("copilot_cmp.comparators").score,
    ..
  }
}

my plugins.lua

...
use {
	"zbirenbaum/copilot.lua",
	cmd = "Copilot",
	event = "InsertEnter",
	config = function()
		require("copilot").setup({
			suggestion = { enabled = false },
			panel = { enabled = false },
		})
	end,
}
use {
	"zbirenbaum/copilot-cmp",
	module = "copilot_cmp",
	after = { "copilot.lua", "nvim-cmp" },
	config = function()
		require("copilot_cmp").setup()
	end
}

use({
	"hrsh7th/nvim-cmp",
	requires = {
		"hrsh7th/cmp-nvim-lsp",
		"hrsh7th/cmp-nvim-lsp-signature-help",
		"L3MON4D3/LuaSnip",
		"saadparwaiz1/cmp_luasnip",
		"amarakon/nvim-cmp-buffer-lines",
		"tzachar/cmp-fuzzy-buffer",
		"tzachar/fuzzy.nvim",
		"petertriho/cmp-git"
	},
	config = function()
		require("config/nvim-cmp")
	end,
})
...

my config/nvim-cmp

local has_words_before = function()
	unpack = unpack or table.unpack
	local line, col = 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

local cmp = require("cmp")
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local luasnip = require("luasnip")
local compare = require "cmp.config.compare"

local function border(hl_name)
	return {
		{ "โ•ญ", hl_name },
		{ "โ”€", hl_name },
		{ "โ•ฎ", hl_name },
		{ "โ”‚", hl_name },
		{ "โ•ฏ", hl_name },
		{ "โ”€", hl_name },
		{ "โ•ฐ", hl_name },
		{ "โ”‚", hl_name },
	}
end

vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })

cmp.event:on(
	'confirm_done',
	cmp_autopairs.on_confirm_done()
)
cmp.setup({
	window = {
		completion = {
			border = border "CmpBorder",
			-- winhighlight = "CursorLine:PmenuSel,Search:None",
			winhighlight = "NormalFloat:Pmenu,NormalFloat:Pmenu,CursorLine:PmenuSel,Search:None",
		},
		documentation = true,
	},
	snippet = {
		expand = function(args)
			luasnip.lsp_expand(args.body) -- For `luasnip` users.
		end,
	},
	-- experimental = {
	-- 	ghost_text = true,
	-- },
	view = {
		entries = { name = 'custom', selection_order = 'near_cursor' }
	},
	mapping = cmp.mapping.preset.insert({
		["<C-d>"] = cmp.mapping.scroll_docs(-4),
		["<C-f>"] = cmp.mapping.scroll_docs(4),
		["<C-Space>"] = cmp.mapping.complete(),
		["<CR>"] = cmp.mapping.confirm({ select = true }),
		["<C-e>"] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close() }),
		["<Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
				-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
				-- they way you will only jump inside the snippet region
			elseif luasnip.expand_or_jumpable() then
				luasnip.expand_or_jump()
			elseif has_words_before() then
				cmp.complete()
			else
				fallback()
			end
		end, { "i", "s" }),
		["<S-Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_prev_item()
			elseif luasnip.jumpable(-1) then
				luasnip.jump(-1)
			else
				fallback()
			end
		end, { "i", "s" }),
	}),
	sources = {
		{
			name = 'nvim_lsp',
			group_index = 2
		},
		{
			name = 'luasnip',
			group_index = 2,
			entry_filter = function(entry, ctx)
				return cmp.lsp.CompletionItemKind.Text ~= entry:get_kind()
			end
		},
		{
			name = 'buffer',
			group_index = 2
		},
		{
			name = 'buffer-lines',
			group_index = 2
		},
		{
			name = 'git',
			group_index = 2
		},
		{
			name = 'nvim_lua',
			group_index = 2
		},
		{
			name = "copilot",
			group_index = 2
		},
	},
	confirm_opts = {
		behavior = cmp.ConfirmBehavior.Replace,
		select = true,
	},
	sorting = {
		priority_weight = 2,
		comparators = {
			compare.exact,
			require("copilot_cmp.comparators").prioritize,
			require("copilot_cmp.comparators").score,
			compare.offset,
			compare.scopes,
			compare.score,
			compare.recently_used,
			compare.locality,
			compare.kind,
			compare.sort_text,
			compare.length,
			compare.order,
		},
	},
	formatting = {
		fields = { "kind", "abbr", "menu" },
		format = function(entry, vim_item)
			if entry.source.name == "copilot" then
				vim_item.kind_hl_group = "CmpItemKindCopilot"
			end

			-- NOTE: order matters
			vim_item.menu = ({
				nvim_lsp = "",
				nvim_lua = "",
				luasnip = "",
				buffer = "",
				path = "",
				emoji = "",
			})[entry.source.name]
			return vim_item
		end,
	},
	-- formatters = {
	-- 	label = require("copilot_cmp.format").format_label_text,
	-- 	insert_text = require("copilot_cmp.format").remove_existing,
	-- 	preview = require("copilot_cmp.format").deindent,
	-- },
})

require "cmp".setup.cmdline({ "/", "?" }, {
	mapping = require "cmp".mapping.preset.cmdline(),
	sources = {
		{
			name = "buffer",
			option = { keyword_pattern = [[\k\+]] }
		},
		{ name = "buffer-lines" }
	}
})

require("cmp_git").setup({
	-- As above
	sorting = {
		comparators = {
			cmp.config.compare.offset,
			cmp.config.compare.exact,
			cmp.config.compare.sort_text,
			cmp.config.compare.score,
			cmp.config.compare.recently_used,
			cmp.config.compare.kind,
			cmp.config.compare.length,
			cmp.config.compare.order,
		},
	},
})

get result with error index on the first line

echo &cindent is 1
echo &autoindent is 1
echo &indentexpr is v:lua.require'nvim-yati.indent'.indentexpr()


i use a treesitter indent plugin nvim-yati, but i have try to disable the plugin, to make indentexpr empty. the error indent on the first line still show

2023-01-29-23-34-53.mp4

Extra brackets when using copilots completion

How to avoid extra brackets when accept suggestion from copilot-cmp? It is not constantly but sometimes quite annoying.

my config:

		-- {
		-- 	"github/copilot.vim"
		-- },
		{ "zbirenbaum/copilot.lua",
			event = "VimEnter",
			config = function()
				vim.defer_fn(function()
					require("copilot").setup()
				end, 100)
			end,
		},

		{ "zbirenbaum/copilot-cmp",
			after = { "copilot.lua" },
			config = function()
				require("copilot_cmp").setup()
			end
		},

Got something like this when accepting suggestions:
Screenshot 2022-12-06 at 7 27 51 PM

packer.nvim: Error running config for copilot-cmp

Hi,
thanks for the plugin, seems like exactly what I wanted. But I have a problem:
packer.nvim: Error running config for copilot-cmp: ...re/nvim/site/pack/packer/opt/nvim-cmp/lua/cmp/config.lua:224: attempt to index local 's' (a string value)

Could you help me out?

not getting any sources on cmp from copilot.lua

This is a repost of an issue on copilot.lua: zbirenbaum/copilot.lua#24

I can't get the source on cmp for copilot.lua, I debugged the sources that arrive at the cmp setup and there is no source input coming from copilot.lua.

copilot.vim works and the user auth works correctly.

I tried to create a minimal config, but I can't get it to work, here is the minimal config:

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match "Windows"

local function join_paths(...)
	local path_sep = on_windows and "\\" or "/"
	local result = table.concat({ ... }, path_sep)
	return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir
if on_windows then
	temp_dir = vim.loop.os_getenv "TEMP"
else
	temp_dir = "/tmp"
end

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local function load_plugins()
	-- only add other plugins if they are necessary to reproduce the issue
	require("packer").startup {
		{
			"wbthomason/packer.nvim",
			{ "neovim/nvim-lspconfig" },
			{ "neovim/nvim-lsp" },
			{ "hrsh7th/nvim-cmp" },
			{ "hrsh7th/cmp-nvim-lsp" },
			{ "github/copilot.vim" }, -- needed for the auth
			{
				"zbirenbaum/copilot.lua",
				event = "VimEnter",
				config = function()
					vim.defer_fn(function()
						require("copilot").setup {}
					end, 100)
				end,
			},
			{
				"zbirenbaum/copilot-cmp",
				after = { "copilot.lua", "nvim-cmp" },
			},
			{ "williamboman/nvim-lsp-installer" },
		},
		config = {
			package_root = package_root,
			compile_path = compile_path,
		},
	}
end

if vim.fn.isdirectory(install_path) == 0 then
	vim.fn.system {
		"git",
		"clone",
		"https://github.com/wbthomason/packer.nvim",
		install_path,
	}
	load_plugins()
	require("packer").sync()
else
	load_plugins()
	require("packer").sync()
end

vim.keymap.set("n", "<Space>w", ":w<cr>")
vim.keymap.set("n", "<Space>q", ":q<cr>")

require "lspconfig"

local cmp = require "cmp"
local kind = cmp.lsp.CompletionItemKind

-- vim.o.completeopt = "menu,menuone,noselect"
vim.opt.completeopt = { "menu", "menuone", "noselect" }

vim.cmd "set shortmess+=c"
vim.cmd "let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy', 'all']"

cmp.setup {
	mapping = {
		["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
		["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
		["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
		["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
		["<C-e>"] = cmp.mapping {
			i = cmp.mapping.abort(),
			c = cmp.mapping.close(),
		},
		["<CR>"] = cmp.mapping.confirm {
			select = true,
			behavior = cmp.ConfirmBehavior.Replace,
		},
	},
	experimental = { ghost_text = true },
	sources = {
		{ name = "copilot" },
		{ name = "nvim_lsp", max_item_count = 5 },
	},
}

require("nvim-lsp-installer").setup {}

In my configuration, cmp works with all the other sources without any problem.

How can I get suggestions without ending the word?

I'm only getting suggestions when I press space or some other character like ( or { that ends the word.

I'd like to get suggestions when I pause in the middle of a word or something similar.

Is this configurable?

Suggestion does not show for some language

After setup this plugin. Copilot works properly in one of my machines. But in WLS2 of windows system. Copilot dose not output any suggestions for some of the languages (python, perl, etc.), while other language works properly.

asciicast

Full code snippet appears on nvim-cmp window but I can only accept the first line

**EDIT: I SOLVED IT AND IT WAS REALLY DUMB ** : I just figured it out when posting the cmd.lua configs here. There is a specific key to accept the suggestion entry and only when that key is pressed the entire suggestion is accepted, otherwise just the first line is inserted.

This is a different issue than the similar one we have there. That guy was having only the first line of code appearing in the nvim-cmp window. In my case the code appears entirely and without any issues in the window:

image

But pressing tab to accept it only writes out the first line on the file:
image

Here are my relevant configurations:

on plugins.lua (file where I install plugins using packer):

   use({
   	"zbirenbaum/copilot.lua",
   	event = { "vimenter" },
   	config = function()
   		vim.defer_fn(function()
   			require("user.copilot").setup()
   		end, 100)
   	end,
   })
	-- copilot integration with nvim-cmp
	use({
		"zbirenbaum/copilot-cmp",
		after = { "copilot.lua" },
		config = function()
			require("copilot_cmp").setup({
				method = "getcompletionscycling",
			})
		end,
	})

on my copilot.lua file (config file required by init.lua where I configure the copilot.lua plugin):

local M = {}

function M.setup()
	require("copilot").setup({
		filetypes = { "lua", "c", "javascript", "typescript", "rust", "python" },
		suggestion = { enabled = false},
		panel = { enabled = false },
		plugin_manager_path = vim.call("stdpath", "data"),
	})
end

return M

cmp.lua (configuration file for nvim-cmp):

local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
	return
end

-- Define a highlight group for the Copilot icon
vim.cmd('highlight MyCopilotIcon guifg=#ffa500')

local check_backspace = function()
	local col = vim.fn.col(".") - 1
	return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end

local kind_icons = {
	Text = "๏พ",
	Method = "๏šฆ",
	Function = "๏šฆ",
	Constructor = "๏šฆ",
	Field = "๎œ–",
	Variable = "๎œ–",
	Class = "๏ –",
	Interface = "๏ƒจ",
	Module = "๏™จ",
	Property = "๏‚ญ",
	Unit = "๎ˆŸ",
	Value = "๏ขŸ",
	Enum = "๏…",
	Keyword = "๏ง",
	Snippet = "๏—",
	Color = "๏ฃ—",
	File = "๏œ˜",
	Reference = "๏’",
	Folder = "๏Š",
	EnumMember = "๏…",
	Constant = "๏›ผ",
	Struct = "๏†ณ",
	Event = "๏ƒง",
	Operator = "๏š”",
	TypeParameter = "๏žƒ",
	Copilot = vim.fn.nr2char(0xe708)
}

cmp.setup({
	snippet = {
		expand = function() end,
	},
	mapping = cmp.mapping.preset.insert({
		["<C-k>"] = cmp.mapping.select_prev_item(),
		["<C-j>"] = cmp.mapping.select_next_item(),
		["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
		["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
		["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
		["<C-e>"] = cmp.mapping({
			i = cmp.mapping.abort(),
			c = cmp.mapping.close(),
		}),
		["<space>"] = cmp.mapping.confirm({ select = false }),
		["<Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_next_item()
			elseif check_backspace() then
				fallback()
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
		["<S-Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_prev_item()
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
	}),
	formatting = {
		fields = { "kind", "abbr", "menu" },
		format = function(entry, vim_item)
			vim_item.kind = kind_icons[vim_item.kind]
			vim_item.menu = ({
				nvim_lsp = "",
				nvim_lua = "",
				buffer = "",
				path = "",
				emoji = "",
			})[entry.source.name]
			return vim_item
		end,
	},
	sources = {
		{ name = "nvim_lsp" },
		{ name = "nvim_lua" },
		{ name = "buffer" },
		{ name = "path" },
		{ name = "copilot", priority = 100 },
	},
	confirm_opts = {
		behavior = cmp.ConfirmBehavior.Replace,
		select = false,
	},
	window = {
		completion = cmp.config.window.bordered(),
		documentation = cmp.config.window.bordered(),
	},
	experimental = {
		ghost_text = true,
	},
})

That's all folks.

Important Announcement: Please Read Before Posting

I've pushed a number of sizable improvements and bug fixes to both copilot-cmp and copilot.lua. I've tentatively closed many of the issues in both repos regarding completions not showing in some locations, or showing inconsistently, as there were many that appeared to be duplicates and keeping track of what problems are outstanding was becoming difficult. I've tried to keep open the ones that look like they have causes which were not addressed by the changes. With that said, please regard the following:

Before anything else: Platform should no longer be a problem. I downloaded a 0.6 appimage to test and both copilot plugins functioned fine for me. If you have any issues, they should now be version independent. I apologize for the problems with attaching on 0.6, they were due to a problem I thought I had pushed the fix for days ago, and discovered I had not.

  1. If you have an open issue and the behavior of the problem has in no way changed, naturally please keep it open.
  2. If you had an issue closed and still run into the exact same problems, please re-open it.
  3. If you have an issue open which appears to be addressed, please close it
  4. If you have an issue (closed or open) and still are having problems after downloading the updates, but the nature of your problem seems to have changed, please do the following depending on your circumstance:
    4a. If you have an open issue: Close the current issue and open a new one with revised info
    4b. If you have a closed issue: Even if the behavior seems related, if it has changed in nature at all, please open a new issue and link the closed one as related.
  5. Before reopening any closed issue, or opening a new one, please check both copilot.lua and copilot-cmp for the same issue I understand if you cannot tell if someone is having the same problem as you, and in such cases, feel free to post, but taking a moment to do this will help a lot with organization

I promise if you have an existing problem I will work on it, but please try to adhere to the above for now.

`copilot` is an unknown source name

I installed according to the instructions. (~/.config/githubcopilot exists)

{ 'zbirenbaum/copilot.lua',
    config = function()
      require("copilot").setup()
    end, },
  { 'zbirenbaum/copilot-cmp',
    after = { "copilot.lua", "nvim-cmp" },
  },

...

lvim.builtin.cmp.sources = {
  { name = "copilot", group_index = 2 },
  { name = "nvim_lsp", group_index = 2 },
  { name = "path", group_index = 2 },
  { name = "luasnip", group_index = 2 },
}

Both plugins seem to be installed, but :CmpInfo produces

# ready source names                                                                                                                                                                                                                  
- path
- luasnip
- nvim_lsp:sumneko_lua

# unused source names
- buffer

# unknown source names
- copilot

It would be nice, if the two plugins copilot.lua and copilot-cmp would list steps to verify installation, as I am not even sure where to file this issue.

How to sort copilot lower than lsp?

I tried to follow your code snippet on the readme to rank copilot lower than exact match, but it does not work.

sorting = {
        priority_weight = 2,
        comparators = {
          require("copilot_cmp.comparators").prioritize,
          require("copilot_cmp.comparators").score,
          compare.offset,
          compare.exact,
          compare.score,
          compare.recently_used,
          compare.kind,
          compare.sort_text,
          compare.length,
          compare.order,
        },
      }

Screenshot 2023-01-17 at 18 43 54

But in the text you said copilot should be put lower, so I tried this:

      sorting = {
        priority_weight = 2,
        comparators = {
          compare.offset,
          compare.exact,
          compare.score,
          compare.recently_used,
          compare.kind,
          compare.sort_text,
          compare.length,
          compare.order,
          require("copilot_cmp.comparators").prioritize,
          require("copilot_cmp.comparators").score,
        },
      },

Screenshot 2023-01-17 at 18 46 59

I tried remove the sorting config and use cmp's default but copilot is stilled ranked highest.
Screenshot 2023-01-17 at 18 48 24

Do you have any idea? Thank you.

Suggestions appearing only randomly

Hello, so the suggestions always properly appear in the buffer (in grey) but are only very randomly suggested in the popup window in insert mode:

Screenshot 2022-04-06 at 12 04 13

This is happening more often than not, not sure to what it's related. Any suggestions on how to debug it?

Also, LspInfo is giving me this state on copilot.lua:

Screenshot 2022-04-06 at 12 09 17

It seems it's not being attached to the buffers all the time?

Neovim version: 0.6.1
nvim-cmp config:

local default = {
   snippet = {
      expand = function(args)
         require("luasnip").lsp_expand(args.body)
      end,
   },
   formatting = {
      format = function(entry, vim_item)
         local icons = require "plugins.configs.lspkind_icons"
         vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)

         vim_item.menu = ({
            nvim_lsp = "[LSP]",
            nvim_lua = "[Lua]",
            buffer = "[BUF]",
         })[entry.source.name]

         return vim_item
      end,
   },
   mapping = {
      ["<C-p>"] = cmp.mapping.select_prev_item(),
      ["<C-n>"] = cmp.mapping.select_next_item(),
      ["<C-d>"] = cmp.mapping.scroll_docs(-4),
      ["<C-f>"] = cmp.mapping.scroll_docs(4),
      ["<C-Space>"] = cmp.mapping.complete(),
      ["<C-e>"] = cmp.mapping.close(),
      ["<CR>"] = cmp.mapping.confirm {
         behavior = cmp.ConfirmBehavior.Replace,
         select = true,
      },
      ["<Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_next_item()
         elseif require("luasnip").expand_or_jumpable() then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
      ["<S-Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_prev_item()
         elseif require("luasnip").jumpable(-1) then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
   },
   sources = {
      { name = "copilot" },
      { name = "nvim_lsp" },
      -- { name = "luasnip" },
      -- { name = "buffer" },
      -- { name = "nvim_lua" },
      -- { name = "path" },
   },
}

Packer config:

     {
         "zbirenbaum/copilot.lua",
         event = "InsertEnter",
         config = function()
            vim.schedule(function()
               require("copilot").setup()
            end)
         end,
      },
      {
         "zbirenbaum/copilot-cmp",
         after = { "copilot.lua", "nvim-cmp" },
      },

Using cmp replace behaviour does not fix trailing character

I saw issue #22 and have similar problems, I have the following mapping setup in cmp (this fixed the indent issue #45)

    ["<Tab>"] = cmp.mapping(function(fallback)
        if cmp.visible() then
            cmp.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace })
        else
            fallback()
        end
    end, { "i", "c" }),
obs.mp4

Is format.remove_existing ever coming back?

I am having trouble with autotags leaving extra end parens and brackets when using cmp completion. Seems like remove_existing was designed to solve that problem but it is currently disabled in format.lua. Can we expect to see this return or is it fully deprecated? If so I would recommend removing it from the readme file.

Do you know of an alternate method to solve this issue?

Can't get this working with LSP-Zero

The copilot suggestions don't appear in the LSP options or as ghost text.

I am using the lsp-zero setup (which I admittedly don't understand very well). I'm somewhat new to nvim.

It seems I may need to add copilot as a source to cmp but I'm not sure what variable that is, or what package it comes from.

Here is my ~ packer.lua

-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(
  function(use)
    -- Packer can manage itself
    use 'wbthomason/packer.nvim'
    use 'vim-test/vim-test'
    use( 'nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'} )

    -- utils

    -- use 'dkarter/bullets.vim'
    use "lukas-reineke/indent-blankline.nvim" -- shows indent levels
    use "WhoIsSethDaniel/toggle-lsp-diagnostics.nvim"

    use 'nvim-tree/nvim-web-devicons'
    use 'glacambre/firenvim'
    -- use 'github/copilot.vim' # no lsp

    -- colorschemes
    -- use 'nyoom-engineering/oxocarbon.nvim'
    -- use { "bluz71/vim-moonfly-colors", as = "moonfly" }
    use 'folke/tokyonight.nvim'
    use { 'nvim-lualine/lualine.nvim', requires = {
          'kyazdani42/nvim-web-devicons', opt = true
      }
    }

    use {
      'VonHeikemen/lsp-zero.nvim',
      branch = 'v1.x',
      requires = {
        -- LSP Support
        {'neovim/nvim-lspconfig'},             -- Required
        {'williamboman/mason.nvim'},           -- Optional
        {'williamboman/mason-lspconfig.nvim'}, -- Optional

        -- Autocompletion
        {'hrsh7th/nvim-cmp'},         -- Required
        {'hrsh7th/cmp-nvim-lsp'},     -- Required
        {'hrsh7th/cmp-buffer'},       -- Optional
        {'hrsh7th/cmp-path'},         -- Optional
        {'saadparwaiz1/cmp_luasnip'}, -- Optional
        {'hrsh7th/cmp-nvim-lua'},     -- Optional

        -- for spelling and grammar, look into 
        -- ltex-ls

        -- Snippets
        {'L3MON4D3/LuaSnip'},             -- Required
        {'rafamadriz/friendly-snippets'}, -- Optional
      }
    }

    { -- copilot functions
      'zbirenbaum/copilot.lua',
      cmd = 'Copilot',
      event = 'InsertEnter',
      suggestion = { enabled = false },
      panel = { enabled = false },
      config = function()
        require('copilot').setup({})
      end,
    }

    { -- integrate copilot completion
      "zbirenbaum/copilot-cmp",
      after = { "copilot.lua" },
      config = function ()
        require("copilot_cmp").setup()
      end
    }

  end
)

Please help, I spent my whole morning on this!

Errors in insert mode when typing since update

Since updating to 00aa1ad I'm seeing this error during typing:

Error executing vim.schedule lua callback: ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:29: attempt to get length of local 'str_to_remove' (a nil value)
stack traceback:                                                                                                                                                                                                                          
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:29: in function 'remove_string_from_end'                                                                                                                                   
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:41: in function 'clean_insertion'                                                                                                                                          
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:54: in function 'format_and_clean_insertion'                                                                                                                               
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:104: in function 'func'                                                                                                                                                    
        vim/shared.lua:191: in function 'tbl_map'                                                                                                                                                                                              
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:98: in function 'format_completions'                                                                                                                                       
        ...e/pack/packer/opt/copilot-cmp/lua/copilot_cmp/source.lua:122: in function 'handler'  

Accepting copilot suggestion puts it at the beginning of line (no indentation)

Screen.Recording.2023-01-31.at.15.45.52.mov

Packer:

  use({
    "zbirenbaum/copilot-cmp",
    after = { "copilot.lua" },
    config = function()
      require("copilot_cmp").setup()
    end,
  })
  use({
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    config = function()
      require("copilot").setup({
        suggestion = { enabled = false },
        panel = { enabled = false },
      })
    end,
  })

CMP config:

local cmp = require("cmp")
local luasnip = require("luasnip")

local check_backspace = function()
  local col = vim.fn.col(".") - 1
  return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end

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

cmp.setup({
  snippet = {
    expand = function(args)
      luasnip.lsp_expand(args.body) -- For `luasnip` users.
    end,
  },
  mapping = {
    ["<C-Space>"] = cmp.mapping.complete(),
      -- config = { sources = { { name = "copilot", keyword_length = 0 } } },
    -- }),
    ["<C-e>"] = cmp.mapping({
      i = cmp.mapping.abort(),
      c = cmp.mapping.close(),
    }),
    -- Accept currently selected item. If none selected, `select` first item.
    -- Set `select` to `false` to only confirm explicitly selected items.
    ["<CR>"] = cmp.mapping.confirm({ select = true }),
    ["<Tab>"] = vim.schedule_wrap(function(fallback)
      if cmp.visible() and has_words_before() then
        cmp.select_next_item({ behavior = cmp.SelectBehavior })
      else
        fallback()
      end
    end),
    ["<S-Tab>"] = vim.schedule_wrap(function(fallback)
      if cmp.visible() and has_words_before() then
        cmp.select_prev_item({ behavior = cmp.SelectBehavior })
      else
        fallback()
      end
    end),
  },
  sources = {
    { name = "copilot", keyword_length = 0 },
    { name = "luasnip" },
    { name = "nvim_lsp" },
    { name = "nvim_lua" },
    { name = "buffer" },
    { name = "path" },
  },
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- `/` cmdline setup.
cmp.setup.cmdline("/", {
  mapping = cmp.mapping.preset.cmdline(),
  sources = {
    { name = "buffer" },
  },
})
-- `:` cmdline setup.
cmp.setup.cmdline(":", {
  mapping = cmp.mapping.preset.cmdline(),
  sources = cmp.config.sources({
    { name = "path" },
  }, {
    { name = "cmdline" },
  }),
})

Copilot is unknown source

Copilot is installed and running. What am I doing wrong?

Screen Shot 2022-09-13 at 7 47 05 pm

Screen Shot 2022-09-13 at 7 49 05 pm

		use({
			'zbirenbaum/copilot.lua',
			event = { 'VimEnter' },
			config = function()
				vim.defer_fn(function()
					require('copilot').setup({})
				end, 100)
			end,
		})

		use({
			'zbirenbaum/copilot-cmp',
			after = {
				'copilot.lua',
				'nvim-cmp',
			},
			config = function()
				require('copilot_cmp').setup()
			end,
		})
	sources = {
		{
			name = 'copilot',
			-- keyword_length = 0,
			max_item_count = 3,
			},
			...

Pressing tab is causing the auto complete to automatically show suggestions

So sometimes when I'm indenting something the simple fact of pressing tab in the blank causes suggestions to popup which can be quite annoying...

Would be nice to be able to disable this behavior. My cmp triggers automatically when I start typing something, so that would be the intended behavior for me

multiple virtual lines (ghost_text) possible?

I'm so impressed with copilot and this plugin has made it super easy to get it working nicely with neovim.

The only issue I have is that Copilot likes to suggest multiple lines, and sometimes quite a lot of them.

In VS Code, if there are multiple lines they are printed as virtual lines (and the rest of the lines are moved down). With copilot-cmp I'm not seeing any indication that Copilot is suggesting more than one line, and I can't see any indication that the suggestion is a multi-line suggestion, and if I undo the suggestion after it has been inserted into the buffer, it actually undoes the last 2 completions, rather than just one.

EDIT: Actually, I can see the whole suggestion in the menu, I think enabling view.entries fixed this(?):

image

However, ideal solution would be multi-line ghost text.

module 'copilot_cmp.comparators' not found

I'm trying the snippet suggested in https://github.com/zbirenbaum/copilot-cmp#comparators

cmp.setup {
  ...
  sorting = {
    priority_weight = 2,
    comparators = {
      require("copilot_cmp.comparators").prioritize,
      require("copilot_cmp.comparators").score,

And get this:

Error detected while processing /Users/josh.nichols/workspace/pickled-nvim/init.lua:
E5113: Error while calling lua chunk: ...chols/.config/nvim/lua/pickled-nvim/language-support.lua:144: module 'copilot_cmp.comparators' not found:
        no field package.preload['copilot_cmp.comparators']
        no file './copilot_cmp/comparators.lua'
        no file '/opt/homebrew/share/luajit-2.1.0-beta3/copilot_cmp/comparators.lua'
        no file '/usr/local/share/lua/5.1/copilot_cmp/comparators.lua'
        no file '/usr/local/share/lua/5.1/copilot_cmp/comparators/init.lua'
        no file '/opt/homebrew/share/lua/5.1/copilot_cmp/comparators.lua'
        no file '/opt/homebrew/share/lua/5.1/copilot_cmp/comparators/init.lua'
        no file './copilot_cmp/comparators.so'
        no file '/usr/local/lib/lua/5.1/copilot_cmp/comparators.so'
        no file '/opt/homebrew/lib/lua/5.1/copilot_cmp/comparators.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './copilot_cmp.so'
        no file '/usr/local/lib/lua/5.1/copilot_cmp.so'
        no file '/opt/homebrew/lib/lua/5.1/copilot_cmp.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        ...chols/.config/nvim/lua/pickled-nvim/language-support.lua:144: in main chunk
        [C]: in function 'require'
        /Users/josh.nichols/workspace/pickled-nvim/init.lua:25: in main chunk

I wonder if it has to do with using a vim.defer_fn for copilot.lua and `after = { 'copilot.lua'} for copilot-cmp?

	use {
		'zbirenbaum/copilot.lua',
		event = 'VimEnter',
		config = function()
			vim.defer_fn(function()
				require("copilot").setup({
					ft_disable = vim.g.filetype_plugin_config.copilot.disable,

					-- suggested to disable these when using with cmp
					suggestion = { enabled = false },
					panel = { enabled = false },
				})
			end, 100)
		end,
	}

	use {
		'zbirenbaum/copilot-cmp',
		after = {'copilot.lua'},
		config = function ()
			require("copilot_cmp").setup {
				method = "getCompletionsCycling",
				formatters = {
					label = require("copilot_cmp.format").format_label_text,
					insert_text = require("copilot_cmp.format").format_insert_text,
					preview = require("copilot_cmp.format").deindent,
				},
			}
		end
	}

my config for reference: https://github.com/technicalpickles/pickled-nvim

line is cleared on confirm

Hi, I'm having this issue since recently, where using <CR> to confirm a suggestion clears the entire line, in the sense that no matter what was on the line and cursor position I end up with a blank line and cursor at column 1. This seems to happen only for single-line suggestions, multiline snippets get inserted correctly.

EDIT: behaviour seems related to clear_after_cursor option, as setting it to false does not clear the entire line, although suggestion is inserted with super f'd up indenting. force_autofmt seems to do nothing.

I am not sure if this is an interaction problem with other plugins, load-order hell or a bug in copilot-cmp. These are some bits of configuration. Removing all lazy loading does not change anything.

copilot config:

    use({
        "zbirenbaum/copilot.lua",
        event = { "VimEnter" },
        config = function()
            vim.defer_fn(function()
                require("copilot").setup({
                    ft_disable = { "julia", "dap-repl" },
                    suggestion = {
                        keymap = {
                            accept = "<M-CR>",
                            next = "<M-n>",
                            prev = "<M-p>",
                            dismiss = "<M-]>",
                        },
                    },
                })
            end, 1000)
        end,
    })
    use({
        "zbirenbaum/copilot-cmp",
        after = { "copilot.lua", "nvim-cmp" },
        config = function()
            require("copilot_cmp").setup()
        end,
    })

relevant cmp config:

    use({
        "hrsh7th/nvim-cmp",
        event = { "InsertEnter", "CmdLineEnter" },
        after = "ultisnips",
        config = function()
            require("plugins.cmp")
        end,
    })
        ["<CR>"] = cmp.mapping({
            i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
            c = function(fallback)
                if cmp.visible() and cmp.get_selected_entry() then
                    cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
                else
                    fallback()
                end
            end,
        }

relevant autopairs config:

    use({
        "windwp/nvim-autopairs",
        after = { "nvim-cmp" },
        config = function()
            require("plugins.autopairs")
        end,
    })
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp = require("cmp")
cmp.event:on(
    "confirm_done",
    cmp_autopairs.on_confirm_done({
        map_char = {
            tex = "",
        },
    })
)

Can no longer update from repo

Hey, I recently tried to update (Packer Sync), and the packer update failed repeatedly.

After some digging, it seems like there was maybe a rebase of the main branch, which packer did not like. So, I went to the repo directory in packer, and tried to do `git pull --allow-unrelated-histories, so I could update from the main branch.

However, the auto merge failes

Auto-merging lua/copilot_cmp/init.lua
CONFLICT (add/add): Merge conflict in lua/copilot_cmp/init.lua
Auto-merging lua/copilot_cmp/source.lua
CONFLICT (add/add): Merge conflict in lua/copilot_cmp/source.lua
Automatic merge failed; fix conflicts and then commit the result.

Do I just need to uninstall and reinstall this plugin?

Snippet only on one line

Hello again!

First a little follow-up on #3, it seems it's working much better now, I'm now using 0.7 and I have the latest version of your plugins.

I'm now facing another issue, but I'm not certain it's related to your plugin specifically. What happens is that the snippets suggested only cover one line:
Screenshot 2022-04-21 at 15 35 13

This suggestion from copilot is not displaying more than one line, and I'm sure it's not supposed to be that short, and it doesn't matter if I select it, it remains short.

In comparison, here is a snippet related to typescript in this case:
Screenshot 2022-04-21 at 15 36 29

This one generates the expected snippet on multiple lines.

My config is the following:

Packer:

      {
         "zbirenbaum/copilot.lua",
         event = { "VimEnter" },
         config = function()
            vim.defer_fn(function()
               require("copilot").setup()
            end, 100)
         end,
      },
      {
         "zbirenbaum/copilot-cmp",
         after = { "copilot.lua", "nvim-cmp" },
      },

nvim-cmp:

   snippet = {
      expand = function(args)
         require("luasnip").lsp_expand(args.body)
      end,
   },
   formatting = {
      format = function(entry, vim_item)
         local icons = require "plugins.configs.lspkind_icons"
         vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)

         vim_item.menu = ({
            nvim_lsp = "[LSP]",
            nvim_lua = "[Lua]",
            buffer = "[BUF]",
         })[entry.source.name]

         return vim_item
      end,
   },
   mapping = {
      ["<C-p>"] = cmp.mapping.select_prev_item(),
      ["<C-n>"] = cmp.mapping.select_next_item(),
      ["<C-d>"] = cmp.mapping.scroll_docs(-4),
      ["<C-f>"] = cmp.mapping.scroll_docs(4),
      ["<C-Space>"] = cmp.mapping.complete(),
      ["<C-e>"] = cmp.mapping.close(),
      ["<CR>"] = cmp.mapping.confirm {
         behavior = cmp.ConfirmBehavior.Replace,
         select = true,
      },
      ["<Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_next_item()
         elseif require("luasnip").expand_or_jumpable() then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
      ["<S-Tab>"] = cmp.mapping(function(fallback)
         if cmp.visible() then
            cmp.select_prev_item()
         elseif require("luasnip").jumpable(-1) then
            vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
         else
            fallback()
         end
      end, { "i", "s" }),
   },
   sources = {
      { name = "copilot" },
      { name = "nvim_lsp" },
      { name = "luasnip" },
      { name = "buffer" },
      { name = "nvim_lua" },
      { name = "path" },
   },

Copilot-cmp joins current line with previous line unexpectedly

When I select the entry from copilot in the completion menu, copilot-cmp will sometimes join the current line with the previous line.

Minimal nvim-cmp config:

local cmp = require('cmp')

cmp.setup({
  mapping = {
    ['<C-n>'] = cmp.mapping(function(fallback)
      if vim.fn.mode() == 'i' then
        if cmp.visible() then
          cmp.select_next_item()
        else
          cmp.complete()
        end
      elseif vim.fn.mode() == 'c' then
        if cmp.visible() then
          cmp.select_next_item()
        else
          fallback()
        end
      end
    end, { 'i', 'c' }),
  },
  sources = {
    { name = 'copilot' },
  },
})

Copilot-cmp config:

require('copilot_cmp').setup({
  formatters = {
    label = function(item) return item.text:gsub('^%s*', '') end,
    insert_text = require('copilot_cmp.format').remove_existing
  },
})

Copilot.lua config:

vim.defer_fn(function()
  if vim.g.loaded_coplilot then
    return
  end
  vim.g.loaded_coplilot = true
  require('copilot').setup({
    suggestion = { enabled = false },
    panel = { enabled = false },
  })
end, 100)

Screen recording:

simplescreenrecorder-2023-03-20_13.40.11.mp4

No suggestions appearing

I'm currently on neovim 0.6.1.
My config is the following:

local cmp = require 'cmp'
local luasnip = require('luasnip')
local lspkind = require('lspkind')

require("luasnip/loaders/from_vscode").lazy_load()
vim.cmd [[ set pumheight=6 ]]

cmp.setup({
    snippet = {expand = function(args) luasnip.lsp_expand(args.body) end},
    mapping = {
        ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
        ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
        ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), {'i', 'c'}),
        ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
        ['<C-e>'] = cmp.mapping({
            i = cmp.mapping.abort(),
            c = cmp.mapping.close()
        }),
        ['<CR>'] = cmp.mapping.confirm({select = true}), -- Accep
        ['<Tab>'] = cmp.mapping(function(fallback)
            if luasnip.expand_or_jumpable() then
                return luasnip.expand_or_jump()
            end
            return fallback()
        end, {"i", "s"}),
        ['<S-Tab>'] = cmp.mapping(function(fallback)
            if luasnip.jumpable(-1) then return luasnip.jump(-1) end
            return fallback()
        end, {"i", "s"})
    },
    experimental = {native_menu = false, ghost_text = true},
    sorting = {
        comparators = {
            cmp.config.compare.recently_used, cmp.config.compare.offset,
            cmp.config.compare.score, cmp.config.compare.sort_text,
            cmp.config.compare.length, cmp.config.compare.order
        }
    },
    preselect = cmp.PreselectMode.Item,
    format = lspkind.cmp_format({with_text = false, maxwidth = 50}),

    formatting = {
        fields = {"kind", "abbr", "menu"},
        format = function(entry, vim_item)
            -- fancy icons and a name of kind
            vim_item.kind = require('lspkind').presets.default[vim_item.kind] ..
                                ' ' .. vim_item.kind

            -- set a name for each source
            vim_item.menu = entry.source.name
            return vim_item
        end
    },
    sources = {
        {name = "copilot", group_index = 2},
        {name = "luasnip", group_index = 2},
        {name = "nvim_lsp", group_index = 2}, {name = "path", group_index = 2},
        {name = "buffer", group_index = 2}, {name = "nvim_lua", group_index = 2}
    }
})

-- you need setup cmp first put this after cmp.setup()
require('nvim-autopairs').setup {}

vim.g.completion_trigger_character = {'>'}
cmp.event:on('confirm_done',
             require("nvim-autopairs.completion.cmp").on_confirm_done({
    map_char = {tex = ''}
}))

And in packer I have:

    use {"zbirenbaum/copilot-cmp", after = {"copilot.lua", "nvim-cmp"}}
    use {
        "zbirenbaum/copilot.lua",
        event = "InsertEnter",
        config = function()
            vim.schedule(function() require("copilot") end)
        end
    }

When I write code, I get no suggestions, although with copilot.vim, everything worked as expected.
Any ideas on why is that?
Thanks!

PS:
When I run :LspInfo I get:

1 active client(s) not attached to this buffer: 
 
 Client: copilot (id: 1, pid: 838276, bufnr: [6])
 	filetypes:       
 	autostart:       true
 	root directory:  <root dir>
 	cmd:             <cmd (index.js)>

Duplicate text after insertion

I have a slight issue that I've only been able to track to this plugin, however it might still be in my cmp config.

For example if I have

import numpy
numpy.array(|)

The cursor being the | character, the copilot suggestion is numpy.array([1, 2, 3]), however when I insert this suggestion, I obtain:

import numpy
bumpy.array([1, 2, 3]))

It duplicates the closing parentheses, this is both with Insert and Replace behaviour in cmp.

Indentation wrong on first line of mutli-line and all single line completions

I'm not sure if this is something with my cmp config, but i'm only seeing it with this source.

I'm being offered a multi-line copilot completion
image

and once selected
image

everything shows up properly except the first line which becomes un-indented. I see this on all my copilot completions and single line completions are always un-indented.

my cmp setup is here: https://github.com/cwebster2/vim/blob/nvim-lua/lua/cwebster/completion/cmp.lua
my copilot-cmp setup is here: https://github.com/cwebster2/vim/blob/05a6fac5fe6a433c19fbb488f4dcb12972521bbf/lua/cwebster/copilot.lua#L12

Copilot is working but the completions do not appear in cmp menu

I have installed copilot.lua and copilot-cmp. When I am trying to get suggestions from the copilot, I am getting suggestions in form of ghost texts instead of cmp-menu.
I want them to be displayed in the cmp menu instead of ghost text

My configuration:
user/plugins.lua

user/copilot.lua

user/cmp.lua

Breaking Changes:

Copilot-cmp's setup function will no longer be executed by copilot.lua in order to keep the codebase consistent and reduce complexity in light of the new formatter function overrides. Review the README for updated setup instructions.

Copilot crashing the language server

First of all, thank you for the amazing plugin!

Is Copilot meant to co-exist with other language servers in the same buffer? I suspect that it clashes with a language server.

Expected behaviour: When I open a julia language file, Copilot and Julia LanguageServer would be both loaded and contribute with suggestions to cmp.

Current behaviour: Julia LanguageServer crashes within minutes because CMP(?) tries to call a method "getCompletionsCycling" from Julia LS, which is undefined, so it crashes. I cannot find any option to change to prevent that and it's not listed in any server capabilities or so. I suspect it has to do with the copilot-cmp internals.

Stacktrace:
"ERROR: "
"LoadError: "
"Unknown method getCompletionsCycling.\nStacktrace:\n [1] "
(the rest is just JSON rpc calls and deeper in Julia stack)

System:

  • MacOS 12.5.1 (Apple M-series chip)
  • nvim 0.7.2
  • Packer used for pkg management
  • Copilot.lua and copilot-cmp refreshed today / latest version installed
    (and Copilot is working)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.