@@ -85,14 +85,15 @@ function M.explain_error(cycle_diagnostic)
8585 end
8686
8787 local diagnostics = vim
88- .iter (vim .diagnostic .get (0 , {}))
89- --- @param diagnostic vim.Diagnostic
90- :filter (function (diagnostic )
91- return diagnostic .code ~= nil
92- and diagnostic .source == ' rustc'
93- and diagnostic .severity == vim .diagnostic .severity .ERROR
94- end )
95- :totable ()
88+ .iter (vim .diagnostic .get (0 , {}))
89+ :filter (
90+ --- @param diagnostic vim.Diagnostic
91+ function (diagnostic )
92+ return diagnostic .code ~= nil
93+ and diagnostic .source == ' rustc'
94+ and diagnostic .severity == vim .diagnostic .severity .ERROR
95+ end )
96+ :totable ()
9697 if # diagnostics == 0 then
9798 vim .notify (' No explainable errors found.' , vim .log .levels .INFO )
9899 return
@@ -185,15 +186,15 @@ function M.explain_error_current_line()
185186
186187 -- get matching diagnostics from current line
187188 local diagnostics = vim
188- .iter (vim .diagnostic .get (0 , {
189- lnum = cursor_position [1 ] - 1 ,
190- }))
191- :filter (function (diagnostic )
192- return diagnostic .code ~= nil
193- and diagnostic .source == ' rustc'
194- and diagnostic .severity == vim .diagnostic .severity .ERROR
195- end )
196- :totable ()
189+ .iter (vim .diagnostic .get (0 , {
190+ lnum = cursor_position [1 ] - 1 ,
191+ }))
192+ :filter (function (diagnostic )
193+ return diagnostic .code ~= nil
194+ and diagnostic .source == ' rustc'
195+ and diagnostic .severity == vim .diagnostic .severity .ERROR
196+ end )
197+ :totable ()
197198
198199 -- no matching diagnostics on current line
199200 if # diagnostics == 0 then
246247local function render_ansi_code_diagnostic (rendered_diagnostic )
247248 -- adopted from https://stackoverflow.com/questions/48948630/lua-ansi-escapes-pattern
248249 local lines =
249- vim .split (rendered_diagnostic :gsub (' [\27\155 ][][()#;?%d]*[A-PRZcf-ntqry=><~]' , ' ' ), ' \n ' , { trimempty = true })
250+ vim .split (rendered_diagnostic :gsub (' [\27\155 ][][()#;?%d]*[A-PRZcf-ntqry=><~]' , ' ' ), ' \n ' , { trimempty = true })
250251 local float_preview_lines = vim .deepcopy (lines )
251252 table.insert (float_preview_lines , 1 , ' ---' )
252253 table.insert (float_preview_lines , 1 , ' 1. Open in split' )
@@ -298,12 +299,12 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
298299 vim .api .nvim_feedkeys (
299300 vim .api .nvim_replace_termcodes (
300301 ' <cmd>lua vim.api.nvim_set_current_win('
301- .. winnr
302- .. ' )<CR>'
303- .. [[ <c-\><c-n>]]
304- .. ' <cmd>lua vim.api.nvim_win_set_cursor('
305- .. winnr
306- .. ' ,{1,0})<CR>' ,
302+ .. winnr
303+ .. ' )<CR>'
304+ .. [[ <c-\><c-n>]]
305+ .. ' <cmd>lua vim.api.nvim_win_set_cursor('
306+ .. winnr
307+ .. ' ,{1,0})<CR>' ,
307308 true ,
308309 false ,
309310 true
@@ -318,12 +319,13 @@ end
318319--- @param cycle_diagnostic (fun ( opts ?: vim.diagnostic.JumpOpts ): vim.Diagnostic ?)
319320function M .render_diagnostic (cycle_diagnostic )
320321 local diagnostics = vim
321- .iter (vim .diagnostic .get (0 , {}))
322- --- @param diagnostic vim.Diagnostic
323- :filter (function (diagnostic )
324- return get_rendered_diagnostic (diagnostic ) ~= nil
325- end )
326- :totable ()
322+ .iter (vim .diagnostic .get (0 , {}))
323+ :filter (
324+ --- @param diagnostic vim.Diagnostic
325+ function (diagnostic )
326+ return get_rendered_diagnostic (diagnostic ) ~= nil
327+ end )
328+ :totable ()
327329 if # diagnostics == 0 then
328330 vim .notify (' No renderable diagnostics found.' , vim .log .levels .INFO )
329331 return
@@ -401,12 +403,13 @@ function M.render_diagnostic_current_line()
401403 -- get rendered diagnostics from current line
402404 --- @type string[]
403405 local rendered_diagnostics = vim
404- .iter (get_diagnostics_current_line ())
405- --- @param diagnostic vim.Diagnostic
406- :map (function (diagnostic )
407- return get_rendered_diagnostic (diagnostic )
408- end )
409- :totable ()
406+ .iter (get_diagnostics_current_line ())
407+ :map (
408+ --- @param diagnostic vim.Diagnostic
409+ function (diagnostic )
410+ return get_rendered_diagnostic (diagnostic )
411+ end )
412+ :totable ()
410413
411414 -- if no renderable diagnostics on current line
412415 if # rendered_diagnostics == 0 then
@@ -430,17 +433,18 @@ function M.related_diagnostics()
430433 end
431434 --- @type lsp.Location[]
432435 local locations = vim
433- .iter (get_diagnostics_at_cursor ())
434- --- @param diagnostic vim.Diagnostic
435- :map (function (diagnostic )
436- return vim .tbl_get (diagnostic , ' user_data' , ' lsp' , ' relatedInformation' )
437- end )
438- :flatten ()
439- --- @param related_info rustaceanvim.diagnostic.RelatedInfo
440- :map (function (related_info )
441- return related_info .location
442- end )
443- :totable ()
436+ .iter (get_diagnostics_at_cursor ())
437+ :map (
438+ --- @param diagnostic vim.Diagnostic
439+ function (diagnostic )
440+ return vim .tbl_get (diagnostic , ' user_data' , ' lsp' , ' relatedInformation' )
441+ end )
442+ :flatten ()
443+ --- @param related_info rustaceanvim.diagnostic.RelatedInfo
444+ :map (function (related_info )
445+ return related_info .location
446+ end )
447+ :totable ()
444448 if # locations == 0 then
445449 vim .notify (' No related diagnostics found.' , vim .log .levels .INFO )
446450 return
0 commit comments