Skip to content

Commit 9210fe5

Browse files
committed
Attempt to deduce require(...) file path.
1 parent 8354891 commit 9210fe5

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

autoload/startuptime.vim

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ function! s:IsRequireEvent(event) abort
210210
return a:event =~# "require('.*')"
211211
endfunction
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+
213218
function! 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')

doc/startuptime.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ column since events can overlap. The reported percents are taken relative to
186186
the `startup` time, and thus don't necessarily sum to 100%.
187187

188188
The require(...) events added in Neovim PR #19267 are treated as if they are
189-
sourcing events, currently without the ability to jump to the corresponding
190-
file.
189+
sourcing events. The full path to the underlying file is not provided, but an
190+
attempt to deduce this path is made when fulfilling a request to open the file
191+
in a new split.
191192

192193
============================================================================
193194
vim:tw=78:ts=4:ft=help:norl:

0 commit comments

Comments
 (0)