yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
6.66k stars 240 forks source link

bug: Using Copilot for Auto Suggestions #571

Closed LessComplexity closed 1 month ago

LessComplexity commented 1 month ago

Describe the bug

Editing a file after enabling suggestions I get the following error every time it tries to suggest: ^I...al/share/nvim/lazy/avante.nvim/lua/avante/utils/init.lua:507: in function <...al/share/nvim/lazy/avante.nvim/lua/avante/utils/init.lua:506>

Seems like this error is related to the suggest() function, as I'm unfamiliar with the code and architecture it's hard for me to pinpoint more specifically where the error originates more than this. I've install Copilot using LazyExtras, if I don't do this I get an error from the avante suggestions implying that the copilot.setup function was not called, this might be a related issue with the fact that I'm using LazyVim (probably). Love the Avante project BTW as someone who doesn't want to leave neovim just because of some simple but powerful AI helper tools :)

To reproduce

Using lazyvim I have the following 'avante.lua' file inside my plugins folder:

return {
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
  dependencies = {
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    --- The below dependencies are optional,
    "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
    "zbirenbaum/copilot.lua",
    {
      -- support for image pasting
      "HakonHarnes/img-clip.nvim",
      event = "VeryLazy",
      opts = {
        -- recommended settings
        default = {
          embed_image_as_base64 = false,
          prompt_for_file_name = false,
          drag_and_drop = {
            insert_mode = true,
          },
          -- required for Windows users
          use_absolute_path = true,
        },
      },
    },
    {
      -- Make sure to set this up properly if you have lazy=true
      "MeanderingProgrammer/render-markdown.nvim",
      opts = {
        file_types = { "markdown", "Avante" },
      },
      ft = { "markdown", "Avante" },
    },
  },
  opts = {
    -- add any opts here
  },
  init = function()
    local config = require("avante.config")
    config.auto_suggestions_provider = "copilot"
    -- vim.notify("Avante initialization complete", vim.log.levels.INFO)
  end,
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make",
}

Pretty much similar to the README file.

Expected behavior

Suggestions will work seamlessly.

Environment

holaguz commented 1 month ago

Seems like the setup function for the copilot provider is never getting called.

For a dirty fix, add the following two lines in copilot.lua before the last line:

M.setup()
vim.delay(500)
holaguz commented 1 month ago

FYI, while debugging this issue I got the following email from GitHub, probably because I requested a lot of tokens.


On behalf of the GitHub Security team, I want to first extend our gratitude for your continued use of GitHub and for being a valued member of the GitHub community.

Recent activity on your account caught the attention of our abuse-detection systems. This activity included use of Copilot that was indicative of scripted interactions or of an otherwise deliberately unusual or strenuous nature. While we have not yet restricted Copilot access for your account, further anomalous activity could result in a temporary suspension of your Copilot access.

While I’m unable to share specifics on rate limits, we prohibit all use of our servers for any form of excessive automated bulk activity, as well as any activity that places undue burden on our servers through automated means. Please refer to our Acceptable Use Policies on this topic: https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github.

Please also refer to our Terms for Additional Products and Features for GitHub Copilot for specific terms: https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot.

Sincerely, GitHub Security