Skip to content

Commit 8908f18

Browse files
committed
vital: detect script line number
1 parent 4d291dc commit 8908f18

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

autoload/vital/vital.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ function! s:_format_throwpoint(throwpoint) abort
177177
endif
178178
let info = s:_get_func_info(name)
179179
if !empty(info)
180-
call add(funcs, printf('function %s(...) %s Line:%d (%s)',
181-
\ info.funcname, join(info.attrs, ' '), lnum, info.filename))
180+
let attrs = empty(info.attrs) ? '' : join([''] + info.attrs)
181+
let flnum = info.lnum == 0 ? '' : printf(' Line:%d', info.lnum + lnum)
182+
call add(funcs, printf('function %s(...)%s Line:%d (%s%s)',
183+
\ info.funcname, attrs, lnum, info.filename, flnum))
182184
continue
183185
endif
184186
endif
@@ -197,9 +199,11 @@ function! s:_get_func_info(name) abort
197199
let body = execute(printf('verbose function %s', name))
198200
let lines = split(body, "\n")
199201
let signature = matchstr(lines[0], '^\s*\zs.*')
200-
let file = matchstr(lines[1], '^\t\%(Last set from\|.\{-}:\)\s*\zs.*$')
202+
let [_, file, lnum; __] = matchlist(lines[1],
203+
\ '^\t\%(Last set from\|.\{-}:\)\s*\zs\(.\{-}\)\%( \S\+ \(\d\+\)\)\?$')
201204
return {
202205
\ 'filename': substitute(file, '[/\\]\+', '/', 'g'),
206+
\ 'lnum': 0 + lnum,
203207
\ 'funcname': a:name,
204208
\ 'arguments': split(matchstr(signature, '(\zs.*\ze)'), '\s*,\s*'),
205209
\ 'attrs': filter(['dict', 'abort', 'range', 'closure'], 'signature =~# (").*" . v:val)'),

test/vital.vimspec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ Describe vital
222222

223223
It can handle error stack in s:_vital_loaded(V)
224224
let errorpat = '/^vital: fail to call \._vital_loaded(): FOO from:\_.*\n'
225-
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim.*)\n'
226-
\ . 'function \d\+(\.\.\.) dict abort Line:1 (.*\/ErrorSelfmodule\.vim.*)\n'
227-
\ . 'function \S*_throwFOO(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim.*)$/'
225+
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
226+
\ . 'function \d\+(\.\.\.) dict abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
227+
\ . 'function \S*_throwFOO(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)$/'
228228
execute 'Throws' errorpat ':call V.import("ErrorSelfmodule")'
229229
End
230230

@@ -308,9 +308,9 @@ Describe vital
308308
It can handle error stack in s:_vital_loaded(V)
309309
let V = vital#{g:testplugin_name}#new()
310310
let errorpat = '/^vital: fail to call \._vital_loaded(): FOO from:\_.*\n'
311-
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim.*)\n'
312-
\ . 'function \d\+(\.\.\.) dict abort Line:1 (.*\/ErrorSelfmodule\.vim.*)\n'
313-
\ . 'function \S*_throwFOO(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim.*)$/'
311+
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
312+
\ . 'function \d\+(\.\.\.) dict abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
313+
\ . 'function \S*_throwFOO(\.\.\.) abort Line:1 (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)$/'
314314
execute 'Throws' errorpat ':call V.load("ErrorSelfmodule")'
315315
End
316316

0 commit comments

Comments
 (0)