avante.nvim
avante.nvim copied to clipboard
bug: Can't control height in horizontal layout, and width of input window
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%:
I noticed that it does work correctly when no file is opened:
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
nvim -u repro.lua(see bottom of the issue)- Open a file
- Open Avante with
\aa
Expected behavior
- Bug:
windows.heightshould always work correctly - Feature request:
windows.input.widthoption
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,
},
},
}
},
})
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.
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_widthon 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
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 😀
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 thanks! I pushed https://github.com/yetone/avante.nvim/pull/1590
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.
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...