zbirenbaum / copilot-cmp

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

not getting any sources on cmp from copilot.lua #12

Closed marcelarie closed 2 years ago

marcelarie commented 2 years ago

This is a repost of an issue on copilot.lua: https://github.com/zbirenbaum/copilot.lua/issues/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.

marcelarie commented 2 years ago

I got this error on startup:

Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:142: Vim(source):E484: Can'
t open file /home/marcel/.local/share/nvim/site/pack/packer/opt/copilot-cmp/after/plugin/copilot_cmp.lua
Please check your config for correctness
zbirenbaum commented 2 years ago

I got this error on startup:


Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:142: Vim(source):E484: Can'

t open file /home/marcel/.local/share/nvim/site/pack/packer/opt/copilot-cmp/after/plugin/copilot_cmp.lua

Please check your config for correctness

I can't seem to reproduce this, but since I haven't changed anything recently having been super busy, it's probably a breaking change somewhere in nvim-cmp. I'll take a look and see what I can figure out.

marcelarie commented 2 years ago

thanks!

zbirenbaum commented 2 years ago

closed via zbirenbaum/copilot.lua#25

marcelarie commented 2 years ago

amazing thank you!