Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(diagnostics): focus preview window when invoking commands again with current argument #607

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions lua/rustaceanvim/commands/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function M.explain_error()
vim.notify('No explainable errors found.', vim.log.levels.INFO)
return
end
close_hover()
local win_id = vim.api.nvim_get_current_win()
local opts = {
cursor_position = vim.api.nvim_win_get_cursor(win_id),
Expand Down Expand Up @@ -128,15 +129,11 @@ function M.explain_error()
table.insert(float_preview_lines, 1, '---')
table.insert(float_preview_lines, 1, '1. Open in split')
vim.schedule(function()
close_hover()
local bufnr, winnr = vim.lsp.util.open_floating_preview(
float_preview_lines,
'markdown',
vim.tbl_extend('keep', config.tools.float_win_config, {
focus = false,
focusable = true,
focus_id = 'rustc-explain-error',
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
})
)
_window_state.float_winnr = winnr
Expand Down Expand Up @@ -203,15 +200,11 @@ function M.explain_error_current_line()
table.insert(float_preview_lines, 1, '---')
table.insert(float_preview_lines, 1, '1. Open in split')
vim.schedule(function()
close_hover()
local bufnr, winnr = vim.lsp.util.open_floating_preview(
float_preview_lines,
'markdown',
vim.tbl_extend('keep', config.tools.float_win_config, {
focus = false,
focusable = true,
focus_id = 'rustc-explain-error',
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
})
)
_window_state.float_winnr = winnr
Expand Down Expand Up @@ -252,15 +245,11 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
table.insert(float_preview_lines, 1, '---')
table.insert(float_preview_lines, 1, '1. Open in split')
vim.schedule(function()
close_hover()
local bufnr, winnr = vim.lsp.util.open_floating_preview(
float_preview_lines,
'',
'plaintext',
vim.tbl_extend('keep', config.tools.float_win_config, {
focus = false,
focusable = true,
focus_id = 'ra-render-diagnostic',
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
})
)
vim.api.nvim_create_autocmd('WinEnter', {
Expand Down Expand Up @@ -322,6 +311,7 @@ function M.render_diagnostic()
vim.notify('No renderable diagnostics found.', vim.log.levels.INFO)
return
end
close_hover()
local win_id = vim.api.nvim_get_current_win()
local opts = {
cursor_position = vim.api.nvim_win_get_cursor(win_id),
Expand Down
Loading