folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.11k stars 173 forks source link

bug: incorrect height of preview (type=main) #468

Closed aimuzov closed 1 month ago

aimuzov commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

MacOS 14.5

Describe the bug

There is an bug related to the winbar when calculating the window height. The window must be one line less in height, otherwise it overlaps with the win separator.

https://github.com/folke/trouble.nvim/assets/3313023/1b43e381-047a-4d0a-a58b-74ccaed31599

If I change the return value of the parent_size function then the problem goes away:

function M:parent_size()
  if self.opts.relative == "editor" or self.opts.relative == "cursor" then
    return { width = vim.o.columns, height = vim.o.lines }
  end

  return { 
        width = vim.api.nvim_win_get_width(self.opts.win), 
        height = vim.api.nvim_win_get_height(self.opts.win) - 1 -- << ???
        -- I don't know how to check that winbar exists in the parent window
    }
end

Fix solves this:

https://github.com/folke/trouble.nvim/assets/3313023/9f434873-148f-45ed-99bb-9cdde8ffecd6

Please tell me how I can find out the correct height required for the preview window?

Steps To Reproduce

  1. Setup winbar.
  2. Open diagnostic (trouble).
  3. Pay attention to the window separator.

Expected Behavior

The window divider should not be overlapped by the preview window.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/trouble.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
aimuzov commented 1 month ago

@b1nhack, can you check it for yourself?

b1nhack commented 1 month ago

I also have an issue with the window separator. When the preview window type is set to 'main' and a winbar is present, the size calculation for the preview window becomes problematic, causing it to overlap the window separator. When the type is 'main,' the preview maybe implemented as a fixed-size floating window, but the calculation for this window ignores the winbar, leading to the issue.

b1nhack commented 1 month ago

There's another issue: when the type is set to 'main', the floating window does not override the default winblend setting. The desired effect is for the preview window to be completely opaque, making it look like it is previewing in the original window.

aimuzov commented 1 month ago

ty :)

folke commented 1 month ago

@b1nhack just also changed the default winblend