Skip to content

Commit d0cec19

Browse files
author
Marc Jakobi
committed
fix(renderDiagnostic): hover closes immediately if auto_focus disabled
1 parent d433164 commit d0cec19

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [4.0.3] - 2024-01-28
10+
11+
### Fixed
12+
13+
- `renderDiagnostic`: Window closes immediately if `auto_focus`
14+
is disabled [[#193](https://github.com/mrcjkb/rustaceanvim/issues/193)].
15+
- `explainError`/`renderDiagnostic`: Fall back to first
16+
detected diagnostic if none is found close to the cursor.
17+
918
## [4.0.2] - 2024-01-27
1019

1120
### Fixed

lua/rustaceanvim/commands/diagnostic.lua

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ function M.explain_error()
9696
local searched_all = pos_map[pos_id] ~= nil
9797
until diagnostic == nil or found or searched_all
9898
if not found then
99+
-- Fall back to first diagnostic
100+
diagnostic = diagnostics[1]
101+
local pos = { diagnostic.lnum, diagnostic.col }
102+
opts.cursor_position = pos
99103
return
100104
end
101105

@@ -181,7 +185,9 @@ function M.render_diagnostic()
181185
local searched_all = pos_map[pos_id] ~= nil
182186
until diagnostic == nil or rendered_diagnostic ~= nil or searched_all
183187
if not rendered_diagnostic then
184-
return
188+
-- No diagnostics found. Fall back to first result from filter,
189+
rendered_diagnostic = get_rendered_diagnostic(diagnostics[1])
190+
---@cast rendered_diagnostic string
185191
end
186192

187193
-- Save position in the window's jumplist
@@ -194,22 +200,25 @@ function M.render_diagnostic()
194200
local float_preview_lines = vim.deepcopy(markdown_lines)
195201
table.insert(float_preview_lines, 1, '---')
196202
table.insert(float_preview_lines, 1, '1. Open in split')
197-
close_hover()
198-
local bufnr, winnr = vim.lsp.util.open_floating_preview(
199-
float_preview_lines,
200-
'markdown',
201-
vim.tbl_extend('keep', config.tools.float_win_config, {
202-
focus = false,
203-
focusable = true,
204-
focus_id = 'ra-render-diagnostic',
205-
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
206-
})
207-
)
208-
_window_state.winnr = winnr
209-
set_open_split_keymap(bufnr, winnr, markdown_lines)
210-
if config.tools.float_win_config.auto_focus then
211-
vim.api.nvim_set_current_win(winnr)
212-
end
203+
vim.schedule(function()
204+
close_hover()
205+
local bufnr, winnr = vim.lsp.util.open_floating_preview(
206+
float_preview_lines,
207+
'markdown',
208+
vim.tbl_extend('keep', config.tools.float_win_config, {
209+
focus = false,
210+
focusable = true,
211+
focus_id = 'ra-render-diagnostic',
212+
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
213+
})
214+
)
215+
_window_state.float_winnr = winnr
216+
set_close_keymaps(bufnr)
217+
set_open_split_keymap(bufnr, winnr, markdown_lines)
218+
if config.tools.float_win_config.auto_focus then
219+
vim.api.nvim_set_current_win(winnr)
220+
end
221+
end)
213222
end
214223

215224
return M

0 commit comments

Comments
 (0)