Skip to content

Commit

Permalink
feat(diagnostic): Allow hovers to be entered if command is run twice
Browse files Browse the repository at this point in the history
According to neovim's documentation for
vim.lsp.util.open_floating_preview:

> If `true`, and if {focusable} is also `true`, focus an existing floating
> window with the same {focus_id}
> (default: `true`)
> @field focus? boolean

Removing the focus=false, and removing call to close_hover enable users
to enter the hover.
  • Loading branch information
rywng committed Dec 6, 2024
1 parent bf3d8c7 commit 7569b42
Showing 1 changed file with 3 additions and 13 deletions.
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

0 comments on commit 7569b42

Please sign in to comment.