Skip to content

Commit 59ce9bc

Browse files
committed
vital: detect lambda-function
1 parent 8908f18 commit 59ce9bc

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

autoload/vital/vital.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ function! s:_format_throwpoint(throwpoint) abort
191191
endfunction
192192

193193
function! s:_get_func_info(name) abort
194-
" If name is digits, it is anonymous-function
195-
let name = (a:name =~# '^\d\+$') ? printf('{%s}', a:name) : a:name
194+
let name = a:name
195+
if a:name =~# '^\d\+$' " is anonymous-function
196+
let name = printf('{%s}', a:name)
197+
elseif a:name =~# '^<lambda>\d\+$' " is lambda-function
198+
let name = printf("{'%s'}", a:name)
199+
endif
196200
if !exists('*' . name)
197201
return {}
198202
endif

test/_testdata/vital/testplugin/autoload/vital/__testplugin__/ErrorSelfmodule.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
let s:Obj = {}
2+
13
function! s:_vital_loaded(V) abort
2-
call s:Obj._anonymous_func()
4+
if exists('s:Lambda')
5+
call s:Lambda()
6+
else
7+
call s:Obj._anonymous_func()
8+
endif
39
endfunction
410

5-
let s:Obj = {}
11+
if has('lambda')
12+
let s:Lambda = {-> s:Obj._anonymous_func()}
13+
endif
14+
615
function! s:Obj._anonymous_func() dict abort
716
call s:_throwFOO()
817
endfunction

test/vital.vimspec

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ 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\( 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\+\)\?)$/'
225+
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
226+
\ . (has('lambda') ? 'function <lambda>\d\+(\.\.\.) Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n' : '')
227+
\ . 'function \d\+(\.\.\.) dict abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
228+
\ . 'function \S*_throwFOO(\.\.\.) abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)$/'
228229
execute 'Throws' errorpat ':call V.import("ErrorSelfmodule")'
229230
End
230231

@@ -308,9 +309,10 @@ Describe vital
308309
It can handle error stack in s:_vital_loaded(V)
309310
let V = vital#{g:testplugin_name}#new()
310311
let errorpat = '/^vital: fail to call \._vital_loaded(): FOO from:\_.*\n'
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\+\)\?)$/'
312+
\ . 'function \S*_vital_loaded(\.\.\.) abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
313+
\ . (has('lambda') ? 'function <lambda>\d\+(\.\.\.) Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n' : '')
314+
\ . 'function \d\+(\.\.\.) dict abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)\n'
315+
\ . 'function \S*_throwFOO(\.\.\.) abort Line:\d\+ (.*\/ErrorSelfmodule\.vim\( Line:\d\+\)\?)$/'
314316
execute 'Throws' errorpat ':call V.load("ErrorSelfmodule")'
315317
End
316318

0 commit comments

Comments
 (0)