@@ -2437,6 +2437,20 @@ function! rails#sprockets_cfile(...) abort
24372437 endif
24382438endfunction
24392439
2440+ function ! s: file_for_nested_constant (const ) abort
2441+ let file = rails#underscore (a: const , 1 ) . ' .rb'
2442+ if file = ~# ' /'
2443+ let absolute = s: find_file (file )
2444+ if empty (absolute)
2445+ let parent = substitute (file , ' /[^/]*\.rb$' , ' .rb' , ' ' )
2446+ if len (s: find_file (parent))
2447+ return parent
2448+ endif
2449+ endif
2450+ endif
2451+ return file
2452+ endfunction
2453+
24402454function ! s: ruby_cfile () abort
24412455 let buffer = rails#buffer ()
24422456
@@ -2453,14 +2467,14 @@ function! s:ruby_cfile() abort
24532467 if len (res )|return s: simplify (res )|endif
24542468
24552469 let res = s: match_it (' \v\s*<%(include|extend)\(=\s*<([[:alnum:]_:]+)>' ,' \1' )
2456- if len (res )|return rails#underscore (res , 1 ). " .rb " |endif
2470+ if len (res )|return s: file_for_nested_constant (res ) |endif
24572471
24582472 let res = s: match_method (' require' )
24592473 if len (res )|return res .(res !~ ' \.[^\/.]\+$' ? ' .rb' : ' ' )|endif
24602474
24612475 if ! empty (s: match_method (' \w\+' ))
24622476 let class = s: match_it (' ^[^;#]*,\s*\%(:class_name\s*=>\|class_name:\)\s*["'' :]\=\([[:alnum:]_:]\+\)' ,' \1' )
2463- if len (class )|return rails#underscore (class , 1 ). " .rb " |endif
2477+ if len (class )|return s: file_for_nested_constant (class ) |endif
24642478 endif
24652479
24662480 let res = s: match_method (' belongs_to\|has_one\|embedded_in\|embeds_one\|composed_of\|validates_associated\|scaffold' )
@@ -2631,7 +2645,7 @@ function! s:ruby_cfile() abort
26312645 if cfile = ~# ' ^\l\w*#\w\+$'
26322646 let cfile = s: sub (cfile , ' #' , ' _controller.rb#' )
26332647 elseif cfile = ~# ' \u'
2634- let cfile = rails#underscore (cfile , 1 ) . ' .rb '
2648+ let cfile = s: file_for_nested_constant (cfile )
26352649 elseif cfile = ~# ' ^\w*_\%(path\|url\)$' && synid != hlID (' rubyString' )
26362650 let route = s: gsub (cfile , ' ^hash_for_|_%(path|url)$' , ' ' )
26372651 let cfile = s: active () ? rails#app ().named_route_file (route) : ' '
0 commit comments