Skip to content

Commit a7bb78c

Browse files
authored
feat(diagnostics): focus preview window when invoking commands again with current argument (#607)
1 parent 87a7b0b commit a7bb78c

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

lua/rustaceanvim/commands/diagnostic.lua

+3-13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function M.explain_error()
7373
vim.notify('No explainable errors found.', vim.log.levels.INFO)
7474
return
7575
end
76+
close_hover()
7677
local win_id = vim.api.nvim_get_current_win()
7778
local opts = {
7879
cursor_position = vim.api.nvim_win_get_cursor(win_id),
@@ -128,15 +129,11 @@ function M.explain_error()
128129
table.insert(float_preview_lines, 1, '---')
129130
table.insert(float_preview_lines, 1, '1. Open in split')
130131
vim.schedule(function()
131-
close_hover()
132132
local bufnr, winnr = vim.lsp.util.open_floating_preview(
133133
float_preview_lines,
134134
'markdown',
135135
vim.tbl_extend('keep', config.tools.float_win_config, {
136-
focus = false,
137-
focusable = true,
138136
focus_id = 'rustc-explain-error',
139-
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
140137
})
141138
)
142139
_window_state.float_winnr = winnr
@@ -203,15 +200,11 @@ function M.explain_error_current_line()
203200
table.insert(float_preview_lines, 1, '---')
204201
table.insert(float_preview_lines, 1, '1. Open in split')
205202
vim.schedule(function()
206-
close_hover()
207203
local bufnr, winnr = vim.lsp.util.open_floating_preview(
208204
float_preview_lines,
209205
'markdown',
210206
vim.tbl_extend('keep', config.tools.float_win_config, {
211-
focus = false,
212-
focusable = true,
213207
focus_id = 'rustc-explain-error',
214-
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
215208
})
216209
)
217210
_window_state.float_winnr = winnr
@@ -252,15 +245,11 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
252245
table.insert(float_preview_lines, 1, '---')
253246
table.insert(float_preview_lines, 1, '1. Open in split')
254247
vim.schedule(function()
255-
close_hover()
256248
local bufnr, winnr = vim.lsp.util.open_floating_preview(
257249
float_preview_lines,
258-
'',
250+
'plaintext',
259251
vim.tbl_extend('keep', config.tools.float_win_config, {
260-
focus = false,
261-
focusable = true,
262252
focus_id = 'ra-render-diagnostic',
263-
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
264253
})
265254
)
266255
vim.api.nvim_create_autocmd('WinEnter', {
@@ -322,6 +311,7 @@ function M.render_diagnostic()
322311
vim.notify('No renderable diagnostics found.', vim.log.levels.INFO)
323312
return
324313
end
314+
close_hover()
325315
local win_id = vim.api.nvim_get_current_win()
326316
local opts = {
327317
cursor_position = vim.api.nvim_win_get_cursor(win_id),

0 commit comments

Comments
 (0)