@@ -347,27 +347,34 @@ endfunction
347347
348348function ! RubyCursorFile () abort
349349 let cfile = expand (' <cfile>' )
350- let ext = getline (' .' ) = ~# ' ^\s*load\>' ? ' ' : ' .rb'
351- if getline (' .' ) = ~# ' ^\s*require_relative\s*\(["'' ]\).*\1\s*$'
352- return expand (' %:p:h' ) . ' /' . matchstr (getline (' .' ),' \(["'' ]\)\zs.\{-\}\ze\1' ) . ' .rb'
353- elseif getline (' .' ) = ~# ' ^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'' ]\)\.\./.*\1,\s*__FILE__)\s*$'
354- let target = matchstr (getline (' .' ),' \(["'' ]\)\.\./\zs.\{-\}\ze\1' )
355- return expand (' %:p:h' ) . ' /' . target . ext
356- elseif getline (' .' ) = ~# ' ^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'' ]\).*\1\s*$'
357- return matchstr (getline (' .' ),' \(["'' ]\)\zs.\{-\}\ze\1' ) . ext
358- elseif s: synname () == # ' rubyConstant'
359- let cfile = substitute (cfile ,' \.\w\+$' ,' ' ,' ' )
350+ let pre = matchstr (strpart (getline (' .' ), 0 , col (' .' )-1 ), ' .*\f\@<!' )
351+ let post = matchstr (strpart (getline (' .' ), col (' .' )), ' \f\@!.*' )
352+ let ext = getline (' .' ) = ~# ' ^\s*\%(require\|autoload\)\>' ? ' .rb' : ' '
353+ if s: synname () == # ' rubyConstant'
354+ let cfile = substitute (cfile ,' \.\w\+[?!=]\=$' ,' ' ,' ' )
360355 let cfile = substitute (cfile ,' ::' ,' /' ,' g' )
361356 let cfile = substitute (cfile ,' \(\u\+\)\(\u\l\)' ,' \1_\2' , ' g' )
362357 let cfile = substitute (cfile ,' \(\l\|\d\)\(\u\)' ,' \1_\2' , ' g' )
363358 return tolower (cfile ) . ' .rb'
359+ elseif getline (' .' ) = ~# ' ^\s*require_relative\s*\(["'' ]\).*\1\s*$'
360+ let cfile = expand (' %:p:h' ) . ' /' . matchstr (getline (' .' ),' \(["'' ]\)\zs.\{-\}\ze\1' ) . ' .rb'
361+ elseif getline (' .' ) = ~# ' ^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'' ]\)\.\./.*\1,\s*__FILE__)\s*$'
362+ let target = matchstr (getline (' .' ),' \(["'' ]\)\.\.\zs/.\{-\}\ze\1' )
363+ let cfile = expand (' %:p:h' ) . target . ext
364+ elseif getline (' .' ) = ~# ' ^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'' ]\).*\1\s*$'
365+ return fnameescape (matchstr (getline (' .' ),' \(["'' ]\)\zs.\{-\}\ze\1' ) . ext)
366+ elseif pre .post = ~# ' \<File.expand_path[( ].*['' "]\{2\}, *__FILE__\>' && cfile = ~# ' ^\.\.'
367+ let cfile = expand (' %:p:h' ) . strpart (cfile , 2 )
364368 else
365369 return cfile
366370 endif
371+ let cwdpat = ' ^\M' . substitute (getcwd (), ' [\/]' , ' \\[\\/]' , ' g' ).' \ze\[\/]'
372+ let cfile = substitute (cfile , cwdpat, ' .' , ' ' )
373+ return fnameescape (cfile )
367374endfunction
368375
369376function ! s: gf (count ,map ,edit) abort
370- let target = RubyCursorFile ()
377+ let target = expand ( RubyCursorFile () )
371378 if target = ~# ' /$'
372379 let found = finddir (target, &path , a: count )
373380 else
0 commit comments