zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.45k stars 67 forks source link

Copilot doesn't work #180

Closed cxzhou35 closed 1 year ago

cxzhou35 commented 1 year ago

I have viewed the similar issues in this repo, but none of them worked, so I raise a new issue to ask for help.

I have setup both copilot.lua and copilot-cmp plugins, the config is below(based on LazyVim):

return {

  -- copilot
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    build = ":Copilot auth",
    opts = {
      suggestion = { enabled = false },
      panel = { enabled = false },
      filetypes = {
        markdown = true,
        help = true,
      },
    },
  },
  {
    "nvim-lualine/lualine.nvim",
    optional = true,
    event = "VeryLazy",
    opts = function(_, opts)
      local Util = require("lazyvim.util")
      local colors = {
        [""] = Util.fg("Special"),
        ["Normal"] = Util.fg("Special"),
        ["Warning"] = Util.fg("DiagnosticError"),
        ["InProgress"] = Util.fg("DiagnosticWarn"),
      }
      table.insert(opts.sections.lualine_x, 2, {
        function()
          local icon = require("lazyvim.config").icons.kinds.Copilot
          local status = require("copilot.api").status.data
          return icon .. (status.message or "")
        end,
        cond = function()
          local ok, clients = pcall(vim.lsp.get_active_clients, { name = "copilot", bufnr = 0 })
          return ok and #clients > 0
        end,
        color = function()
          if not package.loaded["copilot"] then
            return
          end
          local status = require("copilot.api").status.data
          return colors[status.status] or colors[""]
        end,
      })
    end,
  },

  -- copilot cmp source
  {
    "nvim-cmp",
    dependencies = {
      {
        "zbirenbaum/copilot-cmp",
        dependencies = "copilot.lua",
        opts = {},
        config = function(_, opts)
          local copilot_cmp = require("copilot_cmp")
          copilot_cmp.setup(opts)
          -- attach cmp source whenever copilot attaches
          -- fixes lazy-loading issues with the copilot cmp source
          require("lazyvim.util").on_attach(function(client)
            if client.name == "copilot" then
              copilot_cmp._on_insert_enter({})
            end
          end)
        end,
      },
    },
    ---@param opts cmp.ConfigSchema
    opts = function(_, opts)
      local cmp = require("cmp")

      table.insert(opts.sources, 1, { name = "copilot", group_index = 2 })

      opts.sorting = {
        priority_weight = 2,
        comparators = {
          require("copilot_cmp.comparators").prioritize,

          -- Below is the default comparitor list and order for nvim-cmp
          cmp.config.compare.offset,
          -- cmp.config.compare.scopes, --this is commented in nvim-cmp too
          cmp.config.compare.exact,
          cmp.config.compare.score,
          cmp.config.compare.recently_used,
          cmp.config.compare.locality,
          cmp.config.compare.kind,
          cmp.config.compare.sort_text,
          cmp.config.compare.length,
          cmp.config.compare.order,
        },
      }
    end,
  },
}

How to reproduce:

  1. Setup LazyVim and install the copilot.lua and copilot-cmp plugins
  2. Auth the github account to use the copilot.
  3. Edit anyone file with neovim.
  4. Copilot doesn't work.

LspInfo result:

image

Lualine Status(The copilot status is online):

image

Anyone can provide the solutions for me? Thanks a lot. :)

MunifTanjim commented 1 year ago

Looks like an issue for https://github.com/zbirenbaum/copilot-cmp/issues

You're not using any features of copilot.lua directly.

If :Copilot status output looks okay, copilot.lua is working as expected.

cxzhou35 commented 1 year ago

Looks like an issue for https://github.com/zbirenbaum/copilot-cmp/issues

You're not using any features of copilot.lua directly.

If :Copilot status output looks okay, copilot.lua is working as expected.

Thanks for your reply, I will raise this issue to the copilot-cmp repo and close this issue.

But if copilot.lua is working as expected, some texts will appear in the context of my code?

I still can't see any code suggestions provided by copilot.lua without the nvim-cmp popup window.

MunifTanjim commented 1 year ago

I still can't see any code suggestions provided by copilot.lua

You've set:

      suggestion = { enabled = false },
      panel = { enabled = false },

that would be the reason.

MunifTanjim commented 1 year ago

Check this for the guide: https://github.com/zbirenbaum/copilot.lua/discussions/99#discussioncomment-4483942

cxzhou35 commented 1 year ago

Now I changed my config according to the guide, here is the result:

:Copilot auth:

image

:Copilot status:

image image

Sad, still no suggestions..

MunifTanjim commented 1 year ago

Did you enable auto trigger? You'll need to either enable auto trigger, or trigger manually.

Also try writing some characters (e.g. func) and see if copilot completes it. Sometimes copilot doesn't suggest anything for empty lines.

What does :Copilot version output?

MunifTanjim commented 1 year ago

If nothing works, you can try two last things:

zbirenbaum commented 1 year ago

But if copilot.lua is working as expected, some texts will appear in the context of my code?

I still can't see any code suggestions provided by copilot.lua without the nvim-cmp popup window.

Copilot.vim/copilot.lua style inline text suggestions are mutually exclusive with copilot-cmp. This is a limitation brought on by nvim-cmp's ghost text which doesn't support multiline suggestions.

cxzhou35 commented 1 year ago

If nothing works, you can try two last things:

  • :Copilot auth signout and :Copilot auth signin again.
  • If that doesn't work... Try out the official https://github.com/github/copilot.vim plugin to see if it works. Could be that your account (or IP address) is blocked from using Copilot for some reason.

I'm sorry for the late reply due to my final exam, now my config is below:

  -- copilot
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    build = ":Copilot auth",
    opts = {
      suggestion = {
        enabled = true,
        auto_trigger = true,
      },
      panel = {
        enabled = true,
        auto_refresh = false,
      },
    },
  }

That works, thank you for your quick reply.

However, my copilot-cmp plugin still not work at all, in its repo I found this hint:

image

If I change the config to this one, the copilot will not work, here is my copilot config with the cmp integration:


return {
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    build = ":Copilot auth",
    module = "copilot",
    opts = {
      suggestion = { enabled = false },
      panel = { enabled = false },
      filetypes = {
        yaml = false,
        markdown = false,
        help = false,
        gitcommit = false,
        gitrebase = false,
        hgcommit = false,
        svn = false,
        cvs = false,
      },
    },
  },
  {
    "zbirenbaum/copilot-cmp",
    dependencies = "copilot.lua",
    event = { "InsertEnter", "LspAttach" },
    fix_pairs = true,
    config = function(_, opts)
      local copilot_cmp = require("copilot_cmp")
      copilot_cmp.setup(opts)
      -- attach cmp source whenever copilot attaches
      -- fixes lazy-loading issues with the copilot cmp source
      require("lazyvim.util").on_attach(function(client)
        if client.name == "copilot" then
          copilot_cmp._on_insert_enter({})
        end
      end)
    end,
  },
}