Skip to content

Commit 4079a18

Browse files
fix(ui/renderDiagnostics): seemingly empty float window (#766)
1 parent 3567efc commit 4079a18

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lua/rustaceanvim/commands/diagnostic.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,22 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
246246
table.insert(float_preview_lines, 1, '---')
247247
table.insert(float_preview_lines, 1, '1. Open in split')
248248
vim.schedule(function()
249+
-- Create preview buffer with plain text content for setting the right dimensions
249250
local bufnr, winnr = vim.lsp.util.open_floating_preview(
250251
float_preview_lines,
251252
'plaintext',
252253
vim.tbl_extend('keep', config.tools.float_win_config, {
253254
focus_id = 'ra-render-diagnostic',
254255
})
255256
)
257+
-- Clear content of preview buffer
258+
vim.bo[bufnr].modifiable = true
259+
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {})
260+
vim.bo[bufnr].modifiable = false
261+
-- Send content with ansi color codes to preview buffer
262+
local chanid = vim.api.nvim_open_term(bufnr, {})
263+
vim.api.nvim_chan_send(chanid, vim.trim('1. Open in split\r\n' .. '---\r\n' .. rendered_diagnostic))
264+
256265
vim.api.nvim_create_autocmd('WinEnter', {
257266
callback = function()
258267
vim.api.nvim_feedkeys(
@@ -268,10 +277,6 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
268277
end,
269278
buffer = bufnr,
270279
})
271-
272-
local chanid = vim.api.nvim_open_term(bufnr, {})
273-
vim.api.nvim_chan_send(chanid, vim.trim('1. Open in split\r\n' .. '---\r\n' .. rendered_diagnostic))
274-
275280
_window_state.float_winnr = winnr
276281
set_close_keymaps(bufnr)
277282
set_split_open_keymap(bufnr, winnr, function()

0 commit comments

Comments
 (0)