Config for placement of diagnostics float
Feature description
I have a function for lsp-diagnostics, whihc place the diagnostic float in the lower left corner:
local _, winnr = vim.diagnostic.open_float({ source = true })
if winnr then
local width = vim.api.nvim_get_option("columns")
local height = vim.api.nvim_get_option("lines")
local config = {
anchor = 'SW',
relative = 'editor',
row = height - 2,
col = 1,
}
vim.api.nvim_win_set_config(winnr, config)
end
Because rusteceanvim does not show hints and info diagnostic levels, I have a function to fall back to lsp diagnostics in `ftplugin/rust.lua:
local bufnr = vim.api.nvim_get_current_buf()
local opts = { silent = true, buffer = bufnr }
vim.keymap.set("n", "<localleader>e", function()
local output = vim.fn.execute('RustLsp renderDiagnostic current')
if output:match("No renderable diagnostics found.") then
vim.cmd('lua _G.show_diagnostics()')
end
end, opts)
But now the diagnostic float placement is inconsistent between native diagnostics and rustaceanvim.
Can I modify the window placement for RustLsp renderDiagnostic current dynamically?
Hey 👋
You can configure rustaceanvim's floating windows with vim.g.rustaceanvim.tools.float_win_config.
See :h rustaceanvim.config.
If that doesn't provide what you're looking for, PRs are welcome 😀.
@mrcjkb Is this config lazily evaluated on creation of a float?
@mrcjkb Is this config lazily evaluated on creation of a float?
No.
Is there a way to modify the width/height of the floating windows? When I execute the debuggables command, the hover window is too horizontally small to display the entire names of the debuggables.
@retarpt You can globally override the floating preview config:
local border = { '▗', '▄', '▖', '▌', '▘', '▀', '▝', '▐' };
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview;
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {};
opts.border = border;
opts.max_width = opts.max_width or 100;
opts.wrap = opts.wrap or true;
return orig_util_open_floating_preview(contents, syntax, opts, ...);
end;
Thank you very much!
@mrcjkb Is this config lazily evaluated on creation of a float?
With regards to this point, does this mean relative positioning to the right of the window is not possible, because we have to get the width of the window at runtime, and not when configuring the global Rustaceanvim float config?
As of now, the only way to do that would be by overriding vim.lsp.util.open_floating_preview, I suppose.
As of now, the only way to do that would be by overriding
vim.lsp.util.open_floating_preview, I suppose.
I did think about that, but because opening the float happens asynchronously, I don't believe I can dynamically change the float preview config for a single rustaceanvim call? E.g. this won't work?
-- override vim.lsp.util.open_floating_preview
vim.cmd.RustLsp({ "renderDiagnostic", "current" }) -- calls `open_floating_preview` in a scheduled task
-- revert to old vim.lsp.util.open_floating_preview
Or perhaps this will work? I'll have to experiment with it.
No, but you could override it globally and change the behaviour based on the focus_id, which is 'rust-analyzer-hover-actions'. It's a hacky solution, but it should work.