@@ -210,6 +210,11 @@ function! s:IsRequireEvent(event) abort
210
210
return a: event = ~# " require('.*')"
211
211
endfunction
212
212
213
+ " E.g., convert "require('vim.filetype')" to "vim.filetype"
214
+ function ! s: ExtractRequireArg (event ) abort
215
+ return a: event [9 :-3 ]
216
+ endfunction
217
+
213
218
function ! s: Profile (onfinish, onprogress, options , tries, file , items ) abort
214
219
if ! a: onprogress (a: tries )
215
220
return
@@ -589,8 +594,23 @@ function! startuptime#GotoFile() abort
589
594
if l: item .type == # s: sourcing_event_type
590
595
let l: file = ' '
591
596
if s: IsRequireEvent (l: item .event )
592
- " TODO: attempt to deduce file path
593
- else
597
+ " Attempt to deduce the file path.
598
+ let l: arg = s: ExtractRequireArg (l: item .event )
599
+ let l: part = substitute (l: arg , ' \.' , ' /' , ' g' )
600
+ for l: base in globpath (&runtimepath , ' ' , 1 , 1 )
601
+ let l: candidates = [
602
+ \ l: base .. ' lua/' .. l: part .. ' .lua' ,
603
+ \ l: base .. ' lua/' .. l: part .. ' /init.lua'
604
+ \ ]
605
+ for l: candidate in l: candidates
606
+ if filereadable (l: candidate )
607
+ let l: file = l: candidate
608
+ break
609
+ endif
610
+ endfor
611
+ if ! empty (l: file ) | break | endif
612
+ endfor
613
+ elseif l: item .event = ~# ' ^sourcing '
594
614
let l: file = substitute (l: item .event , ' ^sourcing ' , ' ' , ' ' )
595
615
endif
596
616
if ! empty (l: file ) && filereadable (l: file )
@@ -784,8 +804,7 @@ function! s:Tabulate(items, startup) abort
784
804
let l: event = l: item .event
785
805
if l: item .type == # s: sourcing_event_type
786
806
if s: IsRequireEvent (l: event )
787
- " E.g., convert "require('vim.filetype')" to "vim.filetype"
788
- let l: event = l: event [9 :-3 ]
807
+ let l: event = s: ExtractRequireArg (l: event )
789
808
else
790
809
let l: event = substitute (l: event , ' ^sourcing ' , ' ' , ' ' )
791
810
let l: event = fnamemodify (l: event , ' :t' )
0 commit comments