Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: duplicated input container window and confusing window sizes #1055

Open
nfwyst opened this issue Jan 8, 2025 · 0 comments
Open

bug: duplicated input container window and confusing window sizes #1055

nfwyst opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@nfwyst
Copy link

nfwyst commented Jan 8, 2025

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 nfwyst added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant