1111local M = {}
1212
1313--- @package
14+ --- @param file_name string
1415--- @param output string
1516--- @return vim.Diagnostic[]
1617--- @diagnostic disable-next-line : inject-field
17- M .parse_diagnostics = function (output )
18+ M .parse_diagnostics = function (file_name , output )
19+ output = output :gsub (' \r\n ' , ' \n ' )
20+ local lines = vim .split (output , ' \n ' )
1821 --- @type vim.Diagnostic[]
1922 local diagnostics = {}
20- for line , col , message in output :gmatch (" thread '[^']+' panicked at [^:]+:(%d+):(%d+):\n ([^\n ]*)" ) do
21- diagnostics [# diagnostics + 1 ] = {
22- lnum = tonumber (line ) - 1 ,
23- col = tonumber (col ) or 0 ,
24- message = message ,
25- source = ' rustaceanvim' ,
26- severity = vim .diagnostic .severity .ERROR ,
27- }
28- end
29- if # diagnostics == 0 then
30- --- Fall back to old format
31- for message , line , col in output :gmatch (" thread '[^']+' panicked at '([^']+)', [^:]+:(%d+):(%d+)" ) do
32- diagnostics [# diagnostics + 1 ] = {
33- lnum = tonumber (line ) - 1 ,
23+ for i , line in ipairs (lines ) do
24+ local message = ' '
25+ local file , lnum , col = line :match (" thread '[^']+' panicked at ([^:]+):(%d+):(%d+):" )
26+ if lnum and col and message and vim .endswith (file_name , file ) then
27+ local next_i = i + 1
28+ while # lines >= next_i and lines [next_i ] ~= ' ' do
29+ message = message .. lines [next_i ] .. ' \n '
30+ next_i = next_i + 1
31+ end
32+ local diagnostic = {
33+ lnum = tonumber (lnum ) - 1 ,
3434 col = tonumber (col ) or 0 ,
3535 message = message ,
3636 source = ' rustaceanvim' ,
3737 severity = vim .diagnostic .severity .ERROR ,
3838 }
39+ table.insert (diagnostics , diagnostic )
40+ end
41+ end
42+ if # diagnostics == 0 then
43+ --- Fall back to old format
44+ for message , file , lnum , col in output :gmatch (" thread '[^']+' panicked at '([^']+)', ([^:]+):(%d+):(%d+)" ) do
45+ if vim .endswith (file_name , file ) then
46+ local diagnostic = {
47+ lnum = tonumber (lnum ) - 1 ,
48+ col = tonumber (col ) or 0 ,
49+ message = message ,
50+ source = ' rustaceanvim' ,
51+ severity = vim .diagnostic .severity .ERROR ,
52+ }
53+ table.insert (diagnostics , diagnostic )
54+ end
3955 end
4056 end
4157 return diagnostics
@@ -56,6 +72,7 @@ M.execute_command = function(command, args, cwd, opts)
5672 local notify_prefix = (is_single_test and ' test ' or ' tests ' )
5773 local compat = require (' rustaceanvim.compat' )
5874 local cmd = vim .list_extend ({ command }, args )
75+ local fname = vim .api .nvim_buf_get_name (opts .bufnr )
5976 compat .system (cmd , { cwd = cwd }, function (sc )
6077 --- @cast sc vim.SystemCompleted
6178 if sc .code == 0 then
@@ -65,8 +82,8 @@ M.execute_command = function(command, args, cwd, opts)
6582 end )
6683 return
6784 end
68- local output = sc .stderr or ' '
69- local diagnostics = M .parse_diagnostics (output )
85+ local output = ( sc .stderr or ' ' ) .. ' \n ' .. ( sc . stdout or ' ' )
86+ local diagnostics = M .parse_diagnostics (fname , output )
7087 local summary = get_test_summary (sc .stdout or ' ' )
7188 vim .schedule (function ()
7289 vim .diagnostic .set (diag_namespace , opts .bufnr , diagnostics )
0 commit comments