From 4dc3bddb11ac02427c85c7395be4c10c8b6da3f5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 5 Dec 2024 15:24:46 +0800 Subject: [PATCH] feat(diagnostic): Allow hovers to be entered if command is run twice 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. --- lua/rustaceanvim/commands/diagnostic.lua | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/lua/rustaceanvim/commands/diagnostic.lua b/lua/rustaceanvim/commands/diagnostic.lua index fe409a04..dd9ceb48 100644 --- a/lua/rustaceanvim/commands/diagnostic.lua +++ b/lua/rustaceanvim/commands/diagnostic.lua @@ -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), @@ -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 @@ -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 @@ -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', { @@ -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),