copilot-cmp icon indicating copy to clipboard operation
copilot-cmp copied to clipboard

Moves cmp popup to beginning of suggestion

Open EricDriussi opened this issue 2 years ago • 9 comments

Hi there! I'm noticing a strange behavior since a couple of days ago:

If the suggestion includes the content of current line, the popup window shows up at the beginning of the content instead of staying under the cursor.

Minimal config (using lazy.nvim):

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

local plugin_list = {
	{
		"hrsh7th/nvim-cmp",
		config = function()
			local cmp = require("cmp")
			cmp.setup({
				mapping = {
					["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
				},
				sources = {
					{ name = "copilot" },
				},
			})
		end,
	},
	{
		"zbirenbaum/copilot-cmp",
		config = true,
		dependencies = {
			"zbirenbaum/copilot.lua",
			opts = {
				suggestion = { enabled = false },
				panel = { enabled = false },
			},
		},
	},
}

require("lazy").setup(plugin_list, {})

Specific commits:

{
  "copilot-cmp": { "branch": "master", "commit": "11eb015fbf9f07ad1c72dbdc9d830ebac610b5cd" },
  "copilot.lua": { "branch": "master", "commit": "0fa30d6846aae1af1c94a9ead93fa7dcf8affbe6" },
  "lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" },
  "nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" }
}

Usual behavior:

image

Broken (?) behavior, notice the cursor position:

image

Mind you this is not due to the window size, the screenshot is just a portion of the window.

What makes this particularly annoying is that, since copilot takes longer to load than other cmp sources, once it does load it actually moves the window away from the cursor.

Am I missing something here?

EricDriussi avatar Sep 01 '23 19:09 EricDriussi

I also observe this behavior. My cmp window jumps around sometimes. But even worse, the plugin overwrites other cmp entries such as LSP. When I type the other suggestions are available, but only for a short time. So seems to be a second update happening, causing the overwrite, and certainly sometimes the jumping, I guess.

See my config here https://github.com/crzdg/dotfiles.

crzdg avatar Oct 20 '23 08:10 crzdg

https://github.com/hrsh7th/nvim-cmp/blob/ce16de5665c766f39c271705b17fff06f7bcb84f/lua/cmp/view.lua#L102

          for _, e in ipairs(s:get_entries(ctx)) do
            e.score = e.score + priority
            table.insert(group_entries, e)
            local is_copilot = e:get_completion_item().copilot
            if not is_copilot then
              offset = math.min(offset, e:get_offset())
            end
          end

xzbdmw avatar Apr 07 '24 20:04 xzbdmw

Any updates on this Issue ? I am encountering the same problem....

image

iamrx0 avatar Jun 09 '24 20:06 iamrx0

@alwaysamer have you tried my patch above, I’m afraid there is nothing to do by copilot here

xzbdmw avatar Jun 10 '24 01:06 xzbdmw

No I did not. Wasn't sure if that was the fix since the Issue is still open. Where exactly would I put that snippet ?

iamrx0 avatar Jun 10 '24 04:06 iamrx0

You need to modify cmp source code as the link points to.

xzbdmw avatar Jun 10 '24 04:06 xzbdmw

Okay I forked the repo and modified the Code. That seems to have fixed the Issue. So thanks @xzbdmw :) . It's going to be annoying to maintain the fork but I suppose there is no way around it...

iamrx0 avatar Jun 10 '24 04:06 iamrx0

@alwaysamer I think require("cmp").setup({ view = { entries = { follow_cursor = true } } }) this can be a workaround too, but maybe what you want

xzbdmw avatar Jun 10 '24 04:06 xzbdmw

Awesome. That seems to have done it as well!

iamrx0 avatar Jun 10 '24 05:06 iamrx0