yetone / avante.nvim

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

bug: Error on Apply action in Avante Ask: 'winfixbuf' is enabled #860

Open johnsaigle opened 6 hours ago

johnsaigle commented 6 hours ago

Describe the bug

When using Avante Ask, and hitting either a or A to apply changes, I got the following error.

Error executing vim.schedule lua callback: ...al/share/nvim/lazy/avante.nvim/lua/avante/utils/init.lua:712: E1513: Cannot switch buffer.
'winfixbuf' is enabled
stack traceback:
        [C]: in function 'nvim_set_current_buf'
        ...al/share/nvim/lazy/avante.nvim/lua/avante/utils/init.lua:712: in function 'get_or_create_buffer_with_filepath'
        ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:562: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I then ran :set nowinfixbuf in the LLM response window and Avante resumed operation there instead of in the main window. https://neovim.io/doc/user/message.html#E1513

Note that this option is probably incorrect: we don't want to modify the response buffer, but to switch to the main buffer and edit the code there. So, this is probably a bug in buffer selection.

To reproduce

No response

Expected behavior

No response

Installation method

return {
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  opts = {
    provider = "ollama",
    use_absolute_path = true,
    vendors = {
      ---@type AvanteProvider
      ollama = {
        ['local'] = true,
        endpoint = "http://localhost:11434/v1",
        model = "qwen2.5-coder:3b",
        parse_curl_args = function(opts, code_opts)
          return {
            url = opts.endpoint .. "/chat/completions",
            headers = {
              ["Accept"] = "application/json",
              ["Content-Type"] = "application/json",
              ['x-api-key'] = 'ollama',
            },
            body = {
              model = opts.model,
              messages = require("avante.providers").copilot.parse_messages(code_opts), -- you can make your own message, but this is very advanced
              max_tokens = 2048,
              stream = true,
            },
          }
        end,
        parse_response_data = function(data_stream, event_state, opts)
          require("avante.providers").openai.parse_response(data_stream, event_state, opts)
        end,
      },
    },
    behaviour = {
      auto_suggestions = false, -- Experimental stage
      auto_set_highlight_group = true,
      auto_set_keymaps = true,
      auto_apply_diff_after_generation = false,
      support_paste_from_clipboard = true,
    },
    mappings = {
      --- @class AvanteConflictMappings
      diff = {
        ours = 'co',
        theirs = 'ct',
        all_theirs = 'ca',
        both = 'cb',
        cursor = 'cc',
        next = ']x',
        prev = '[x',
      },
      suggestion = {
        accept = '<M-l>',
        next = '<M-]>',
        prev = '<M-[>',
        dismiss = '<C-]>',
      },
      jump = {
        next = ']]',
        prev = '[[',
      },
      submit = {
        normal = '<CR>',
        insert = '<C-s>',
      },
    },
    hints = { enabled = true },
    windows = {
      ---@type "right" | "left" | "top" | "bottom"
      position = 'right',   -- the position of the sidebar
      wrap = true,          -- similar to vim.o.wrap
      width = 30,           -- default % based on available width
      sidebar_header = {
        align = 'center', -- left, center, right for title
        rounded = true,
      },
    },
    highlights = {
      ---@type AvanteConflictHighlights
      diff = {
        current = 'DiffText',
        incoming = 'DiffAdd',
      },
    },
    --- @class AvanteConflictUserConfig
    diff = {
      autojump = true,
      ---@type string | fun(): any
      list_opener = 'copen',
    },
  },
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make BUILD_FROM_SOURCE=true",
  -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    --- The below dependencies are optional,
    "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
    {
      -- 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" },
    },
  },
  keys = {
    {
      "<leader>aa",
      function()
        require("avante.api").ask()
      end,
      desc = "avante: ask",
      mode = { "n", "v" },
    },
    {
      "<leader>ar",
      function()
        require("avante.api").refresh()
      end,
      desc = "avante: refresh",
    },
    {
      "<leader>ae",
      function()
        require("avante.api").edit()
      end,
      desc = "avante: edit",
      mode = "v",
    },
  },
}

Environment

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

Repro

No response

dieguscl commented 2 hours ago

Same issue here!