@@ -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 )
213222end
214223
215224return M
0 commit comments