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

bug: Can't control height in horizontal layout, and width of input window

Open toupeira opened this issue 8 months ago • 5 comments

Describe the bug

I'd like to use the horizontal layout with position = 'bottom' or position = 'smart', but can't seem to control the height. It always opens at 50-60%:

Image

I noticed that it does work correctly when no file is opened:

Image

The width setting also works fine for the vertical layout.

I'd also like to make the input window wider, I see there's a setting windows.input.height but no .width

To reproduce

  1. nvim -u repro.lua (see bottom of the issue)
  2. Open a file
  3. Open Avante with \aa

Expected behavior

  1. Bug: windows.height should always work correctly
  2. Feature request: windows.input.width option

Installation method

Using lazy.nvim and latest commit 931a364

Environment

nvim -v:

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

uname -a:

Linux ocelot 6.12.17-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.17-1 (2025-03-01) x86_64 GNU/Linux

Distribution: Debian sid

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    {
      'yetone/avante.nvim',
      event = 'VeryLazy',
      build = 'make',

      dependencies = {
        'nvim-treesitter/nvim-treesitter',
        'stevearc/dressing.nvim',
        'nvim-lua/plenary.nvim',
        'MunifTanjim/nui.nvim',
      },

      opts = {
        windows = {
          position = 'bottom',
          height = 20,
        },
      },
    }
  },
})

toupeira avatar Mar 13 '25 09:03 toupeira

Updated the issue with a proper repro.lua, I noticed it does work correctly when no file is opened so I wanted to check if another plugin is interfering, but I can reproduce it with the minimal config too.

I tried debugging the code but didn't find the problem yet. I traced all the calls to nvim_win_set_height like so:

orig = vim.api.nvim_win_set_height
vim.api.nvim_win_set_height = function(...)
  vim.print(...)
  return orig(...)
end

...but the correct values seem to get passed, for example 8 lines both with/without a file opened.

toupeira avatar Mar 13 '25 21:03 toupeira

Ok I found the culprits:

  • The window layout gets overwritten by the call to wincmd = at https://github.com/yetone/avante.nvim/blob/f60f150a21e2a32f1b0ee194abd7f2be3bab92db/lua/avante/sidebar.lua#L130

    • If I remove it the size is as expected.
    • There's another call at https://github.com/yetone/avante.nvim/blob/f60f150a21e2a32f1b0ee194abd7f2be3bab92db/lua/avante/sidebar.lua#L148 which seems suspect as well. I think the plugin should just close its windows and leave others alone?
  • The input window width defaults to 40% which would be perfectly fine for me (so no setting needed), but it gets displaced by the call to nvim_win_set_width on the results window at https://github.com/yetone/avante.nvim/blob/f60f150a21e2a32f1b0ee194abd7f2be3bab92db/lua/avante/sidebar.lua#L2977

    • If I remove it the input window size is as expected, and I don't notice any immediate problems in both horizontal and vertical layouts.

I'd be happy to submit a PR to just remove these 3 calls, although Sidebar:adjust_result_container_layout() might need some more consideration.

/cc @yetone

toupeira avatar Mar 14 '25 14:03 toupeira

PRs that added the wincmd = calls don't have any context: https://github.com/yetone/avante.nvim/pull/160, https://github.com/yetone/avante.nvim/pull/198

@aarnphm do you remember what problems these fixed, and can you check if removing them breaks anything for you? I don't really see the sense in doing wincmd = when the plugin has explicit settings for width/height 😀

toupeira avatar Mar 14 '25 21:03 toupeira

The reason for wincmd = is mainly for windows being relocated, and we need to balance the buffer.

But that is before all of the logics we have td. Feel free to open the PR, (the codebase have changed quite a bit since the last time I worked on this 😃, but can def review)

aarnphm avatar Mar 15 '25 03:03 aarnphm

@aarnphm thanks! I pushed https://github.com/yetone/avante.nvim/pull/1590

toupeira avatar Mar 15 '25 12:03 toupeira

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 15 '25 02:04 github-actions[bot]

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.

bumping...

toupeira avatar Apr 15 '25 06:04 toupeira