zbirenbaum / copilot-cmp

Lua plugin to turn github copilot into a cmp source
MIT License
1.07k stars 38 forks source link

Moves cmp popup to beginning of suggestion #89

Open EricDriussi opened 10 months ago

EricDriussi commented 10 months ago

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?

crzdg commented 8 months ago

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.

xzbdmw commented 3 months ago

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
alwaysamer commented 3 weeks ago

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

image

xzbdmw commented 3 weeks ago

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

alwaysamer commented 3 weeks ago

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 ?

xzbdmw commented 3 weeks ago

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

alwaysamer commented 3 weeks ago

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...

xzbdmw commented 3 weeks ago

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

alwaysamer commented 3 weeks ago

Awesome. That seems to have done it as well!