From ace75de758f6c374cc9e54a192c6b947f8be9379 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 11 Jun 2023 21:37:17 +0300 Subject: [PATCH 1/2] Fix error regex --- autoload/exception.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/exception.vim b/autoload/exception.vim index bffd7e2..df1ea7b 100644 --- a/autoload/exception.vim +++ b/autoload/exception.vim @@ -56,7 +56,7 @@ function! exception#trace() abort continue endif - let src = fnamemodify(matchstr(verb[1], 'Last set from \zs.\+'), ':p') + let src = fnamemodify(matchstr(verb[1], 'Last set from \zs.\+\ze\%( line \d\+\)'), ':p') if !filereadable(src) continue endif From 2cf02607500137fc37b40c5d843d4a482304d10e Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 11 Jun 2023 21:38:32 +0300 Subject: [PATCH 2/2] Find the error line's body and show it in the quickfix window --- autoload/exception.vim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autoload/exception.vim b/autoload/exception.vim index df1ea7b..d194691 100644 --- a/autoload/exception.vim +++ b/autoload/exception.vim @@ -68,9 +68,21 @@ function! exception#trace() abort endif let pat .= func.'\>' - for line in readfile(src) - let lnum += 1 + let function_offset = 0 + let function_found = 0 + let line_body = '' + + for [index, line] in items(readfile(src)) + if !function_found + let function_offset += 1 + endif + if line =~# pat + let function_found = 1 + endif + + if lnum + function_offset == index + 1 + let line_body = trim(line) break endif endfor @@ -78,9 +90,9 @@ function! exception#trace() abort if !empty(src) && !empty(func) let fname = fnamemodify(src, ':.') call add(errlist, { - \ 'text': printf('%*s. %s', nw, '#'.i, t), + \ 'text': printf('%*s. %s: %s', nw, '#'.i, t, line_body), \ 'filename': fname, - \ 'lnum': lnum, + \ 'lnum': function_offset + lnum, \ 'type': 'I', \ }) endif