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: avante input buffer not deleting when quit sidebar #1042

Open
nfwyst opened this issue Jan 6, 2025 · 1 comment
Open

bug: avante input buffer not deleting when quit sidebar #1042

nfwyst opened this issue Jan 6, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@nfwyst
Copy link

nfwyst commented Jan 6, 2025

Describe the bug

empty buffer left when quit avante

To reproduce

produce step

  1. install lazyvim
  2. enable buffers components in tabline for lualine
  3. open snacks dashboard then open avante sidebar
  4. input something in avante input
  5. press tab focus on avante chat view
  6. press q to close avante sidebar
  7. [No Name] buffer show in lualine buffers

Expected behavior

avante input buffer should delete or keep alive after close/toggle sidebar

Installation method

Use 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)
nvim 0.10.3

@nfwyst nfwyst added the bug Something isn't working label Jan 6, 2025
@nfwyst nfwyst changed the title bug: avante inout buffer not deleting when quit sidebar bug: avante input buffer not deleting when quit sidebar Jan 6, 2025
@DaniBedz
Copy link

DaniBedz commented Jan 6, 2025

I'm finding the same.

A couple of 'Scratch' tabs still showing after closing avante:
2025-01-06 150919

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

2 participants