yetone / avante.nvim

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

bug: visual mode selection + pressing key 'c' is slow, if pressed twice error shows up #580

Closed av1155 closed 1 month ago

av1155 commented 1 month ago

Describe the bug

**E492: Not an editor command: '<,'>AvanteConflictChooseCursor**

Slow behavior:

  1. Create a random test.txt file
  2. Type anything into the file
  3. Highlight a word, or anything in the buffer, in visual mode
  4. Press the 'c' key to "change"
  5. Notice it takes a long time for the word, or selection, to get deleted
  6. Normal functionality resumes

Error shows up if:

  1. Create a random test.txt file
  2. Type anything into the file
  3. Highlight a word, or anything in the buffer, in visual mode
  4. Fast press the 'c' key to "change" more than 1 or 2 times,
  5. Error -> E492: Not an editor command: '<,'>AvanteConflictChooseCursor

To reproduce

E492: Not an editor command: '<,'>AvanteConflictChooseCursor

Slow behavior:

  1. Create a random test.txt file
  2. Type anything into the file
  3. Highlight a word, or anything in the buffer, in visual mode
  4. Press the 'c' key to "change"
  5. Notice it takes a long time for the word, or selection, to get deleted
  6. Normal functionality resumes

Error shows up if:

  1. Create a random test.txt file
  2. Type anything into the file
  3. Highlight a word, or anything in the buffer, in visual mode
  4. Fast press the 'c' key to "change" more than 1 or 2 times,
  5. Error -> E492: Not an editor command: '<,'>AvanteConflictChooseCursor

Expected behavior

No error when pressing 'c' key fast, and fast use of 'c' key in visual mode when Avante is installed.

Environment

NVIM v0.10.1 Build type: Release LuaJIT 2.1.1725453128 Run "nvim -V1 -v" for more info

Repro

No response

b0o commented 1 month ago

Hi there, I can't reproduce this. Can you please share your config?

b0o commented 1 month ago

Also, can you test to see if a similar error appears when you quickly hit ct or co?

will-lynas commented 1 month ago

I have this too. cc is very slow.

aarnphm commented 1 month ago

Are you using which-key by any chance? I can't reproduce this?

would be best if you can also provide a screen recording. Thanks

will-lynas commented 1 month ago

I am

aarnphm commented 1 month ago

can you provide a repro?

av1155 commented 1 month ago

https://github.com/user-attachments/assets/c9161e56-b868-4dbf-92b7-34abb25da401

cw is instant, vwc is slow, vwcc produces error (pressing c more than once on a highlighted string). Visual string highlight can be either with key stroke or mouse double click.

Obviously pressing c more than once on a highlighted string has no use, but sometimes we like to press keys many times, idk y.

I am using AstroNvim but I have had this config for around 1 year and a half now, I moved away from all IDE's. So I can safely say I understand how Neovim configuration works.

My avante config is the one provided by astrocommunity (https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/completion/avante-nvim), the only reason for me to have that lazy config is in case i want to modify any defaults, which I only modified it so that the side panel uses 40% of screen instead of 30%.

I am using which-key.

init.lua provided by astrocommunity:

return {
  "yetone/avante.nvim",
  build = ":AvanteBuild",
  cmd = {
    "AvanteAsk",
    "AvanteBuild",
    "AvanteConflictChooseAllTheirs",
    "AvanteConflictChooseBase",
    "AvanteConflictChooseBoth",
    "AvanteConflictChooseCursor",
    "AvanteConflictChooseNone",
    "AvanteConflictChooseOurs",
    "AvanteConflictChooseTheirs",
    "AvanteConflictListQf",
    "AvanteConflictNextConflict",
    "AvanteConflictPrevConflict",
    "AvanteEdit",
    "AvanteRefresh",
    "AvanteSwitchProvider",
  },
  dependencies = {
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    {
      "AstroNvim/astrocore",
      opts = function(_, opts)
        local maps = assert(opts.mappings)
        local prefix = "<Leader>a"

        maps.n[prefix] = { desc = "Avante functionalities" }

        maps.n[prefix .. "a"] = { function() require("avante.api").ask() end, desc = "Avante ask" }
        maps.v[prefix .. "a"] = { function() require("avante.api").ask() end, desc = "Avante ask" }

        maps.v[prefix .. "r"] = { function() require("avante.api").refresh() end, desc = "Avante refresh" }

        maps.n[prefix .. "e"] = { function() require("avante.api").edit() end, desc = "Avante edit" }
        maps.v[prefix .. "e"] = { function() require("avante.api").edit() end, desc = "Avante edit" }

        -- the following key bindings do not have an official api implementation
        maps.n.co = { ":AvanteConflictChooseOurs<CR>", desc = "Choose ours" }
        maps.v.co = { ":AvanteConflictChooseOurs<CR>", desc = "Choose ours" }

        maps.n.ct = { ":AvanteConflictChooseTheirs<CR>", desc = "Choose theirs" }
        maps.v.ct = { ":AvanteConflictChooseTheirs<CR>", desc = "Choose theirs" }

        maps.n.ca = { ":AvanteConflictChooseAllTheirs<CR>", desc = "Choose all theirs" }
        maps.v.ca = { ":AvanteConflictChooseAllTheirs<CR>", desc = "Choose all theirs" }

        maps.n.c0 = { ":AvanteConflictChooseNone<CR>", desc = "Choose none" }
        maps.v.c0 = { ":AvanteConflictChooseNone<CR>", desc = "Choose none" }

        maps.n.cb = { ":AvanteConflictChooseBoth<CR>", desc = "Choose both" }
        maps.v.cb = { ":AvanteConflictChooseBoth<CR>", desc = "Choose both" }

        maps.n.cc = { ":AvanteConflictChooseCursor<CR>", desc = "Choose cursor" }
        maps.v.cc = { ":AvanteConflictChooseCursor<CR>", desc = "Choose cursor" }

        maps.n["]x"] = { ":AvanteConflictPrevConflict<CR>", desc = "Move to previous conflict" }
        maps.v["]x"] = { ":AvanteConflictPrevConflict<CR>", desc = "Move to previous conflict" }

        maps.n["[x"] = { ":AvanteConflictNextConflict<CR>", desc = "Move to next conflict" }
        maps.x["[x"] = { ":AvanteConflictNextConflict<CR>", desc = "Move to next conflict" }
      end,
    },
  },
  opts = {},
  specs = { -- configure optional plugins
    { -- if copilot.lua is available, default to copilot provider
      "zbirenbaum/copilot.lua",
      optional = true,
      specs = {
        {
          "yetone/avante.nvim",
          opts = {
            provider = "copilot",
          },
        },
      },
    },
    {
      -- make sure `Avante` is added as a filetype
      "MeanderingProgrammer/render-markdown.nvim",
      optional = true,
      opts = function(_, opts)
        if not opts.file_types then opts.filetypes = { "markdown" } end
        opts.file_types = require("astrocore").list_insert_unique(opts.file_types, { "Avante" })
      end,
    },
    {
      -- make sure `Avante` is added as a filetype
      "OXY2DEV/markview.nvim",
      optional = true,
      opts = function(_, opts)
        if not opts.filetypes then opts.filetypes = { "markdown", "quarto", "rmd" } end
        opts.filetypes = require("astrocore").list_insert_unique(opts.filetypes, { "Avante" })
      end,
    },
  },
}
aarnphm commented 1 month ago

Oh ok these commands don't exist anymore

AvanteConflictChooseAllTheirs",
    "AvanteConflictChooseBase",
    "AvanteConflictChooseBoth",
    "AvanteConflictChooseCursor",
    "AvanteConflictChooseNone",
    "AvanteConflictChooseOurs",
    "AvanteConflictChooseTheirs",
    "AvanteConflictListQf",
    "AvanteConflictNextConflict",
    "AvanteConflictPrevConflict",

We now replaced all of those with <Plug>(Command) instead. Probably should update upstream with astronvim

aarnphm commented 1 month ago

Ok the astronvim config aside, https://github.com/AstroNvim/astrocommunity/pull/1210

av1155 commented 1 month ago

Thank you!