zbirenbaum / copilot-cmp

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

Can't get this working with LSP-Zero #55

Closed benlieb closed 1 year ago

benlieb commented 1 year ago

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!

EngoDev commented 1 year ago

This is from the README:

cmp.setup {
  ...
  sources = {
    -- Copilot Source
    { name = "copilot", group_index = 2 },
    -- Other Sources
    { name = "nvim_lsp", group_index = 2 },
    { name = "path", group_index = 2 },
    { name = "luasnip", group_index = 2 },
  },
  ...
}

Go to where nvim-cmp is configured, look for a keyword named sources and add the copilot line to it. I recommend you follow the README Setup section to get the basic configuration up and running.

And welcome to the nvim community ;)

benlieb commented 1 year ago

Thank you. I did finally figure it out.

The first issue was to realize that

cmp.setup {

probably meant

local cmp = require('nvim-cmp')
cmp.setup {

This might be obvious to others, but wasn't to me. Once I figured that out I found out how lsp-zero configures nvim-cmp

lsp.setup_nvim_cmp({
  sources = {
    { name = "copilot", group_index = 2 },
    { name = 'path'},
    { name = 'nvim_lsp'},
    { name = 'buffer', keyword_length = 3},
    { name = 'luasnip', keyword_length = 2},
  }
})

Thanks again!

EngoDev commented 1 year ago

No problem :)