@@ -210,6 +210,11 @@ function! s:IsRequireEvent(event) abort
210210 return a: event = ~# " require('.*')"
211211endfunction
212212
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+
213218function ! s: Profile (onfinish, onprogress, options , tries, file , items ) abort
214219 if ! a: onprogress (a: tries )
215220 return
@@ -589,8 +594,23 @@ function! startuptime#GotoFile() abort
589594 if l: item .type == # s: sourcing_event_type
590595 let l: file = ' '
591596 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 '
594614 let l: file = substitute (l: item .event , ' ^sourcing ' , ' ' , ' ' )
595615 endif
596616 if ! empty (l: file ) && filereadable (l: file )
@@ -784,8 +804,7 @@ function! s:Tabulate(items, startup) abort
784804 let l: event = l: item .event
785805 if l: item .type == # s: sourcing_event_type
786806 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 )
789808 else
790809 let l: event = substitute (l: event , ' ^sourcing ' , ' ' , ' ' )
791810 let l: event = fnamemodify (l: event , ' :t' )
0 commit comments