@@ -149,7 +149,7 @@ function! s:_import(name) abort dict
149
149
call module._vital_created (module)
150
150
endif
151
151
let export_module = filter (copy (module), ' v:key =~# "^\\a"' )
152
- " Cache module before calling module.vital_loaded () to avoid cyclic
152
+ " Cache module before calling module._vital_loaded () to avoid cyclic
153
153
" dependences but remove the cache if module._vital_loaded() fails.
154
154
" let s:loaded[a:name] = export_module
155
155
let s: loaded [a: name ] = export_module
@@ -167,30 +167,51 @@ let s:Vital._import = function('s:_import')
167
167
168
168
function ! s: _format_throwpoint (throwpoint) abort
169
169
let funcs = []
170
- let stack = matchstr (a: throwpoint , ' ^function \zs.*\ze, line \d\+$' )
170
+ let stack = matchstr (a: throwpoint , ' ^function \zs.*, .\{-} \d\+$' )
171
171
for line in split (stack, ' \.\.' )
172
- let m = matchlist (line , ' ^\%(<SNR>\(\d\+\)_\)\?\(.\+\)\[\(\d\+\)\]$' )
173
- if empty (m )
174
- call add (funcs, line )
175
- continue
176
- endif
177
- let [sid , name, lnum] = m [1 :3 ]
178
- let attr = ' '
179
- if ! empty (sid )
180
- let name = printf (' <SNR>%d_%s' , sid , name)
172
+ let m = matchlist (line , ' ^\(.\+\)\%(\[\(\d\+\)\]\|, .\{-} \(\d\+\)\)$' )
173
+ if ! empty (m )
174
+ let [name, lnum, lnum2] = m [1 :3 ]
175
+ if empty (lnum)
176
+ let lnum = lnum2
177
+ endif
178
+ let info = s: _get_func_info (name)
179
+ if ! empty (info)
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))
184
+ continue
185
+ endif
181
186
endif
182
- let file = s: _get_file_by_func_name (name)
183
- call add (funcs, printf ( ' function %s(...)%s Line:%d (%s) ' , name, attr, lnum, file ) )
187
+ " fallback when function information cannot be detected
188
+ call add (funcs, line )
184
189
endfor
185
190
return join (funcs, " \n " )
186
191
endfunction
187
192
188
- function ! s: _get_file_by_func_name (name) abort
189
- let body = execute (printf (' verbose function %s' , a: name ))
193
+ function ! s: _get_func_info (name) abort
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
200
+ if ! exists (' *' . name)
201
+ return {}
202
+ endif
203
+ let body = execute (printf (' verbose function %s' , name))
190
204
let lines = split (body, " \n " )
191
205
let signature = matchstr (lines [0 ], ' ^\s*\zs.*' )
192
- let file = matchstr (lines [1 ], ' ^\t\%(Last set from\|.\{-}:\)\s*\zs.*$' )
193
- return substitute (file , ' [/\\]\+' , ' /' , ' g' )
206
+ let [_, file , lnum; __] = matchlist (lines [1 ],
207
+ \ ' ^\t\%(Last set from\|.\{-}:\)\s*\zs\(.\{-}\)\%( \S\+ \(\d\+\)\)\?$' )
208
+ return {
209
+ \ ' filename' : substitute (file , ' [/\\]\+' , ' /' , ' g' ),
210
+ \ ' lnum' : 0 + lnum,
211
+ \ ' funcname' : a: name ,
212
+ \ ' arguments' : split (matchstr (signature, ' (\zs.*\ze)' ), ' \s*,\s*' ),
213
+ \ ' attrs' : filter ([' dict' , ' abort' , ' range' , ' closure' ], ' signature =~# (").*" . v:val)' ),
214
+ \ }
194
215
endfunction
195
216
196
217
" s:_get_module() returns module object wihch has all script local functions.
0 commit comments