zbirenbaum / copilot-cmp

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

No suggestions appearing #1

Closed kozer closed 2 years ago

kozer commented 2 years ago

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)>
zbirenbaum commented 2 years ago

No suggestions from cmp at all? Or no suggestions from copilot?

kozer commented 2 years ago

No suggestions from copilot. cmp work as expected. As a side note, ~/.config/copilot files are there.

zbirenbaum commented 2 years ago

Are you on neovim .6 or .7? I am looking into making some debug functions but doing so for .7 is much, much easier.

kozer commented 2 years ago

As I said in my original post, I'm on 0.6.1

zbirenbaum commented 2 years ago

As I said in my original post, I'm on 0.6.1

Apologies, I missed that. I think I know the issue, there will be a patch out soon. It's a part of copilot.lua actually

kozer commented 2 years ago

Thank you for that! :)

zbirenbaum commented 2 years ago

I just pushed an update, can you test it out?

kozer commented 2 years ago

Yes, I tested it but still, no luck... I'll try to update to the new version (0.7) and see how it goes. (Although I don't see any package on arch for 0.7)

zbirenbaum commented 2 years ago

I am on arch myself. I personally build from source often, but you can always use the nightly app images posted on the neovim github.

Also, there is an aur pkgbuild for it https://aur.archlinux.org/packages/neovim-nightly-bin. Apparently it refreshes the link it uses to the source based on the date, so even though it says .6 it should be .7

I find building from source best/easiest but the other two options are there.

Just make a script with something like the following if you don't want to install globally:

make CMAKE_BUILD_TYPE=RelWithDebInfo make CMAKE_INSTALL_PREFIX="~/progfiles/neovim-git" make install

and then in the Makefile change CMAKE_EXTRA_FLAGS to something like this

-DCMAKE_INSTALL_PREFIX=/home/zach/progfiles/neovim-git

kozer commented 2 years ago

I installed 0.7 but the problem remains. Actually, it happens something strange: I get results on the root level of the file. If I'm inside a function, I get nothing...

Frydac commented 2 years ago

Somewhat similar experience, I'm on Manjaro. After updating to arch nvim nightly 0.7.0 dev+1400 package I see some suggestions. How it works, seems to depend on the language, in lua and especially C I get a bunch of suggestions while just writing code, but in C++ (which I used most) I get very few suggestions if at all. However, If I look at some video about copilot C++ (in vscode) and type the same, i.e. write a specific comment and then wait for suggestions I seem to get similar suggestions as well, and it seems more userfriendly with cmp where it shows the complete suggestion in the extra popup (or maybe the video was dated already), I guess I'll have to learn more about copilot.

At least as far as I can evaluate the nvim/cmp plugins work, cool, thx!

zbirenbaum commented 2 years ago

Copilot, by virtue of what it is, gives more results for some languages than others. @kozer I have found that longer files with more context tend to give far more results than others, but in some files I get similar results to yours.

I have a couple ideas on how to address this. As I said in a different post, the original copilot.vim sent a request on every insertchange with no debounce. I also recall it having a sleep time for awaiting/waiting on the response of 1ms. This is likely the reason for many of the performance issues associated with copilot.vim, but also for its 'responsiveness'. I plan to implement a configuration option using uv loops which will do a similar process, albeit hopefully slightly more efficient since it will be lua and not vimscript, which users can opt for.

Another idea I am considering as a configuration option in copilot.lua, is sending recursive context configurable by depth from things like import, require, or #include within the files. Doing this based on workspace would also probably work, but either option would have dramatic performance implications.

I will be testing out .6 locally myself to confirm that it is working for me later today. Once I have done so, and confirmed it works, I'll be moving on to drawing up some ideas for preemptively sending requests for completions to increase responsiveness, but this is not a trivial feature.

zbirenbaum commented 2 years ago

Should be fixed via my most recent commit.

I just pushed a sizable fix. Apparently, due to the incredibly strange way copilot returns start and endpoints for its completions, and the fact that if those are incorrect, cmp will just ignore them, @kozer 's observation was correct. The offset for completions outside of the root level was causing them not to appear.

This should be resolved now. Initially, the implementation caused a large delay in all completions appearing, but I changed it so that normal completions should appear quickly, while copilot completions may take a short moment to pop in, as the copilot completions do take longer. Please let me know if you notice any performance issues.

I am going to tentatively close this, as I strongly believe the issue has been addressed, but do not hesitate to reopen it or create a new one if you still are not receiving completions after packer sync'ing