diff --git a/autoload/exception.vim b/autoload/exception.vim index bffd7e2..d194691 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 @@ -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