avante.nvim icon indicating copy to clipboard operation
avante.nvim copied to clipboard

bug: duplicated input container window and confusing window sizes

Open nfwyst opened this issue 11 months ago • 5 comments

Describe the bug

There is duplicated input container window created after splitting vertical terminal panel. and the sidebar width and the window layout messed up.

To reproduce

  1. open neovim editor and open avante sidebar
  2. focus on avante input container
  3. add vertical panel for terminal(for example use zellij) which lead to vim resized 截屏2025-01-08 23 06 46 截屏2025-01-08 23 07 24

Expected behavior

  1. the height of input container and selected file container, response container should recovery its original height
  2. the width of sidebar should recovery its original width after closing vertical terminal panel
  3. the token count should not overflow

Installation method

Use lazy.nvim/lazyvim:

local function switch_prompt(config)
  return function()
    local default_prompt = "你是一位出色的编程专家。"
    local prompt = default_prompt
    local msg = "prompt set to default"
    if config.options.system_prompt == default_prompt then
      msg = "prompt set to expert"
      prompt = PROMPT
    else
      prompt = default_prompt
    end
    config.override({ system_prompt = prompt })
    NOTIFY(msg, levels.INFO)
  end
end

local function init(config)
  CMD("TogglePrompt", switch_prompt(config), { desc = "Toggle Prompt" })
  config.override({ system_prompt = PROMPT })
end

local mode = { "n", "v" }

return {
  "yetone/avante.nvim",
  cond = HAS_AI_KEY,
  build = "make BUILD_FROM_SOURCE=true",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
  },
  keys = {
    { "<leader>a", "", desc = "+ai", mode = mode },
    {
      "<leader>aa",
      function()
        GET_USER_INPUT("question", function(question)
          cmd("AvanteAsk " .. question)
        end)
      end,
      desc = "AvanteAsk",
    },
    { "<leader>aB", "<cmd>AvanteBuild<cr>", desc = "AvanteBuild" },
    { "<leader>ac", "<cmd>AvanteChat<cr>", desc = "AvanteChat" },
    { "<leader>aH", "<cmd>AvanteClear history<cr>", desc = "AvanteClear" },
    { "<leader>aM", "<cmd>AvanteClear memory<cr>", desc = "AvanteClear memory" },
    { "<leader>aC", "<cmd>AvanteClear cache<cr>", desc = "AvanteClear cache" },
    { "<leader>ae", "<cmd>AvanteEdit<cr>", desc = "AvanteEdit", mode = mode },
    { "<leader>ar", "<cmd>AvanteRefresh<cr>", desc = "AvanteRefresh" },
    { "<leader>aR", "<cmd>AvanteShowRepoMap<cr>", desc = "AvanteShowRepoMap" },
    { "<leader>aP", "<cmd>AvanteSwitchFileSelectorProvider<cr>", desc = "AvanteSwitchFileSelectorProvider" },
    { "<leader>ap", "<cmd>AvanteSwitchProvider<cr>", desc = "AvanteSwitchProvider" },
    { "<leader>at", "<cmd>AvanteToggle<cr>", desc = "AvanteToggle" },
    {
      "<leader>ah",
      function()
        require("avante").toggle.hint()
      end,
      desc = "Avante: Toggle Hint",
    },
    {
      "<leader>ad",
      function()
        require("avante").toggle.debug()
      end,
      desc = "Avante: Toggle Debug",
    },
    {
      "<leader>as",
      function()
        require("avante").toggle.suggestion()
      end,
      desc = "Avante: Toggle Suggestion",
    },
    {
      "<leader>aT",
      "<cmd>TogglePrompt<cr>",
      desc = "TogglePrompt",
    },
  },
  config = function()
    -- hide left columns for avante sidebar
    AUCMD("FileType", {
      group = GROUP("hide_left_columns_for_avante", { clear = true }),
      pattern = { "Avante", "AvanteInput" },
      callback = function(event)
        local bufnr = event.buf
        defer(function()
          local win = fn.bufwinid(bufnr)
          local opts = COLUMN_OPTS(false)
          local is_input = event.match == "AvanteInput"
          if is_input then
            opts.signcolumn = "yes"
            pcall(keymap.del, "i", "<tab>", { buffer = bufnr })
          end
          SET_OPTS(opts, wo[win])
        end, 30)
      end,
    })

    local config = require("avante.config")
    local providers = require("avante.providers")
    local api_key_name = "DEEPSEEK_API_KEY"
    local token = os.getenv(api_key_name) or ""

    require("avante").setup({
      provider = "openai",
      openai = {
        endpoint = "https://api.deepseek.com/beta",
        model = "deepseek-chat",
        timeout = 30000,
        api_key_name = api_key_name,
        temperature = 0.1,
        max_tokens = 8192,
        allow_insecure = false,
      },
      vendors = {
        deepseek = {
          endpoint = "https://api.deepseek.com/beta/chat/completions",
          model = "deepseek-chat",
          api_key_name = api_key_name,
          parse_curl_args = function(opts, code_opts)
            return {
              url = opts.endpoint,
              headers = {
                ["Accept"] = "application/json",
                ["Content-Type"] = "application/json",
                ["Authorization"] = "Bearer " .. token,
              },
              body = {
                model = opts.model,
                messages = providers.openai.parse_messages(code_opts),
                temperature = 0.1,
                max_tokens = 8192,
                stream = true,
              },
            }
          end,
          parse_response_data = function(...)
            return providers.openai.parse_response(...)
          end,
        },
      },
      behaviour = {
        auto_suggestions = false,
        auto_set_highlight_group = true,
        auto_apply_diff_after_generation = false,
        auto_set_keymaps = false,
        support_paste_from_clipboard = false,
        minimize_diff = true,
      },
      windows = {
        height = 100,
        input = { prefix = "➜ " },
        sidebar_header = {
          enabled = false,
        },
        ask = {
          start_insert = false,
        },
      },
      mappings = {
        files = {
          add_current = "<leader>ab",
        },
      },
      hints = {
        enabled = false,
      },
      repo_map = {
        ignore_patterns = {
          "%.git",
          "%.worktree",
          "__pycache__",
          "node_modules",
          "__tests__",
          "e2e-tests",
          "%.github",
          "%.husky",
          "%.vscode",
          "fonts",
          "%.ttf",
          "images",
          "img",
          "%.png",
          "%.gif",
          "%.zip",
          "%.jar",
          "%.min.js",
          "%.svg",
          "%lock.json",
          "docker",
          "%.platform",
          "%.htaccess",
          "%.storybook",
          "dist",
          "%.lock",
          "locales",
        },
      },
      file_selector = {
        provider = "fzf",
        provider_opts = {},
      },
    })
    init(config)
  end,
}

Environment

macos: 15.2 (24C101) neovim: 0.10.3

nfwyst avatar Jan 08 '25 15:01 nfwyst

I can reproduce your issue, here some screenshot with the duplicates

Image

after resizing (twice, focusing on input and on output window)

Image

basically the focused window will duplicate after a resize.

McKean avatar Feb 11 '25 11:02 McKean

Is there a workaround for this?

xeon826 avatar Feb 13 '25 20:02 xeon826

I had a similar problem any time I opened the avante sidebar after version 0.9

I'm not 100% sure why this works but in lua/avante/sidebar.lua if I comment out the line for winfixbuf = true from within the base_win_options, it seems to work.

jrhoads avatar Feb 19 '25 09:02 jrhoads

i think Maybe you use VimResized command "wincmd ="

autocmd("VimResized", {
  pattern = "*",
  command = "tabdo wincmd =",
})

Solution

autocmd("VimResized", {
  pattern = "*",
  callback = function()
    local ft = vim.bo.filetype

    if not string.find(ft, "Avante") then
      vim.cmd("tabdo wincmd =")
    end
  end,
})

Yanguk avatar Mar 06 '25 10:03 Yanguk

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 06 '25 02:04 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Apr 12 '25 02:04 github-actions[bot]