@@ -2322,7 +2322,7 @@ function! s:findasset(path, dir) abort
23222322 let path = expand (' %:p:h:h' ) . ' /' . path [3 :-1 ]
23232323 endif
23242324 let suffixes = s: suffixes (a: dir )
2325- let asset = s: resolve_asset (rails#app (). asset_path (), path , suffixes )
2325+ let asset = s: resolve_asset (path , suffixes )
23262326 if len (asset)
23272327 return asset
23282328 endif
@@ -2381,12 +2381,6 @@ endfunction
23812381
23822382function ! s: sprockets_cfile () abort
23832383 let dir = ' '
2384- if s: active ()
2385- let path = rails#app ().asset_path ()
2386- else
2387- let parent = matchstr (expand (' %:p' ), ' .*\ze[\/]assets[\/]' )
2388- let path = len (parent) ? [parent . ' /*' ] : []
2389- endif
23902384
23912385 if &sua = ~# ' \.js\>'
23922386 let dir = ' javascripts'
@@ -2397,15 +2391,15 @@ function! s:sprockets_cfile() abort
23972391 let sssuf = s: suffixes (' stylesheets' )
23982392 let res = s: match_it (' \%(^\s*[[:alnum:]-]\+:\s\+\)\=\<[[:alnum:]-]\+-\%(path\|url\)(["'' ]\=\([^"'' () ]*\)' , ' \1' )
23992393 if ! empty (res )
2400- let asset = s: resolve_asset (path , res )
2394+ let asset = s: resolve_asset (res )
24012395 endif
24022396 let res = s: match_it (' \%(^\s*[[:alnum:]-]\+:\s\+\)\=\<stylesheet-\%(path\|url\)(["'' ]\=\([^"'' () ]*\)' , ' \1' )
24032397 if ! empty (res )
2404- let asset = s: resolve_asset (path , res , sssuf)
2398+ let asset = s: resolve_asset (res , sssuf)
24052399 endif
24062400 let res = s: match_it (' \%(^\s*[[:alnum:]-]\+:\s\+\)\=\<javascript-\%(path\|url\)(["'' ]\=\([^"'' () ]*\)' , ' \1' )
24072401 if ! empty (res )
2408- let asset = s: resolve_asset (path , res , s: suffixes (' javascripts' ))
2402+ let asset = s: resolve_asset (res , s: suffixes (' javascripts' ))
24092403 endif
24102404 if ! empty (asset)
24112405 return asset
@@ -2422,17 +2416,17 @@ function! s:sprockets_cfile() abort
24222416 endif
24232417 endfor
24242418 endfor
2425- let asset = s: resolve_asset (path , res , sssuf)
2419+ let asset = s: resolve_asset (res , sssuf)
24262420 if empty (asset) && expand (' %:e' ) = ~# ' ^s[ac]ss$'
2427- let asset = s: resolve_asset (path , rel, sssuf)
2421+ let asset = s: resolve_asset (rel, sssuf)
24282422 endif
24292423 return empty (asset) ? ' app/assets/stylesheets/' .res : asset
24302424 endif
24312425 endif
24322426
24332427 let res = s: match_it (' ^\s*\%(//\|[*#]\)=\s*\%(link\|require\|depend_on\|stub\)\w*\s*["'' ]\=\([^"'' ]*\)' , ' \1' )
24342428 if ! empty (res ) && exists (' l:dir' )
2435- let asset = s: resolve_asset (path , res , dir )
2429+ let asset = s: resolve_asset (res , dir )
24362430 return empty (asset) ? res : asset
24372431 endif
24382432 return ' '
@@ -3123,27 +3117,55 @@ function! s:readable_resolve_layout(name, ...) dict abort
31233117 return view
31243118endfunction
31253119
3126- function ! s: app_asset_path () dict abort
3127- let gems = self .gems ()
3128- if self .cache.needs (' gem_assets' , gems)
3129- let path = []
3130- let gempath = escape (join (values (gems),' ,' ), ' ' )
3131- if ! empty (gempath)
3132- call extend (path , finddir (' app/assets/' , gempath, -1 ))
3133- call extend (path , finddir (' lib/assets/' , gempath, -1 ))
3134- call extend (path , finddir (' vendor/assets/' , gempath, -1 ))
3135- call extend (path , finddir (' assets/' , gempath, -1 ))
3136- call map (path , ' v:val . "*"' )
3137- call sort (path )
3120+ let s: gem_subdirs = {}
3121+ function ! s: gem_subdirs (... ) abort
3122+ let gems = []
3123+ let project = exists (' *bundler#project' ) ? bundler#project () : {}
3124+ if has_key (project, ' sorted' )
3125+ let gems = bundler#project ().sorted ()
3126+ elseif has_key (project, ' paths' )
3127+ let gems = values (bundler#project ().paths ())
3128+ endif
3129+ let gempath = escape (join (gems,' ,' ), ' ' )
3130+ if empty (gempath)
3131+ return []
3132+ endif
3133+ let key = gempath . " \n " . join (a: 000 , ' ,' )
3134+ if ! has_key (s: gem_subdirs , key )
3135+ if len (s: gem_subdirs ) > 512
3136+ let s: gem_subdirs = {}
31383137 endif
3139- call self .cache.set (' gem_assets' , path , gems)
3138+ let path = []
3139+ for subdir in a: 000
3140+ call extend (path , finddir (subdir, gempath, -1 ))
3141+ endfor
3142+ call map (path , ' fnamemodify(v:val . "/*", ":p")' )
3143+ call sort (path )
3144+ let s: gem_subdirs [key ] = path
31403145 endif
3141- return extend ([self .path (' app/assets/*' ), self .path (' lib/assets/*' ), self .path (' vendor/assets/*' ), self .path (' node_modules' )],
3142- \ self .cache.get (' gem_assets' ))
3146+ return copy (s: gem_subdirs [key ])
31433147endfunction
31443148
3145- function ! s: resolve_asset (path , name, ... ) abort
3146- let path = type (a: path ) == type ([]) ? join (map (copy (a: path ), ' escape(v:val, " ,")' ), ' ,' ) : a: path
3149+ function ! s: asset_path () abort
3150+ let path = []
3151+ let root = ' '
3152+ let parent = matchstr (expand (' %:p' ), ' .*\ze[\/]assets[\/]' )
3153+ if parent = ~# ' [\/]\%(app\|lib\|vendor\)$'
3154+ let root = substitute (parent, ' [\/]\%(app\|lib\|vendor\)$' , ' ' , ' ' )
3155+ elseif ! empty (s: glob (parent.' /*.gemspec' ))
3156+ let root = parent
3157+ call add (path , parent . ' /assets/*' )
3158+ endif
3159+ if len (root)
3160+ call extend (path , map ([' app/assets/*' , ' lib/assets/*' , ' vendor/assets/*' , ' node_modules' ], ' root . "/" . v:val' ))
3161+ endif
3162+ return path
3163+ endfunction
3164+
3165+ function ! s: resolve_asset (name, ... ) abort
3166+ let paths = s: asset_path ()
3167+ call extend (paths, s: gem_subdirs (' app/assets' , ' lib/assets' , ' vendor/assets' , ' assets' ))
3168+ let path = join (map (paths, ' escape(v:val, " ,")' ), ' ,' )
31473169 let suffixesadd = &l: suffixesadd
31483170 let exact = s: find_file (a: name , path , a: 0 ? (type (a: 1 ) == # type ([]) ? a: 1 : s: suffixes (a: 1 )) : [])
31493171 if ! empty (exact)
@@ -3165,7 +3187,6 @@ function! rails#pack_suffixes(type) abort
31653187endfunction
31663188
31673189call s: add_methods (' readable' , [' resolve_view' , ' resolve_layout' ])
3168- call s: add_methods (' app' , [' asset_path' ])
31693190
31703191function ! s: findview (name) abort
31713192 let view = s: active () ? rails#buffer ().resolve_view (a: name , line (' .' )) : ' '
@@ -4466,19 +4487,6 @@ function! s:app_has_gem(gem) dict abort
44664487 endif
44674488endfunction
44684489
4469- function ! s: app_engines () dict abort
4470- let gems = self .gems ()
4471- if self .cache.needs (' engines' , gems)
4472- let gempath = escape (join (values (gems),' ,' ), ' ' )
4473- if empty (gempath)
4474- call self .cache.set (' engines' , [], gems)
4475- else
4476- call self .cache.set (' engines' , sort (map (finddir (' app' , gempath, -1 ), ' fnamemodify(v:val, ":h")' )), gems)
4477- endif
4478- endif
4479- return self .cache.get (' engines' )
4480- endfunction
4481-
44824490function ! s: app_smart_projections () dict abort
44834491 let ts = s: getftime (self .path (' app/' ))
44844492 if self .cache.needs (' smart_projections' , ts )
@@ -4845,7 +4853,7 @@ function! s:app_projections() dict abort
48454853 return dict
48464854endfunction
48474855
4848- call s: add_methods (' app' , [' gems' , ' has_gem' , ' engines ' , ' smart_projections' , ' projections' ])
4856+ call s: add_methods (' app' , [' gems' , ' has_gem' , ' smart_projections' , ' projections' ])
48494857
48504858let s: transformations = {}
48514859
@@ -5023,15 +5031,11 @@ function! rails#sprockets_setup(type) abort
50235031 return
50245032 endif
50255033
5026- if ! exists (' *RailsDetect' ) || ! RailsDetect ()
5027- let parent = matchstr (expand (' %:p' ), ' .*\ze[\/]assets[\/]' )
5028- if parent !~# ' \<\%(app\|lib\|vendor\)$' && empty (s: glob (parent.' /*.gemspec' ))
5029- return
5030- endif
5031- call rails#update_path ([parent . ' /assets/*' ], [])
5032- else
5033- call rails#update_path (rails#app ().asset_path (), [])
5034+ let path = s: asset_path ()
5035+ if empty (path )
5036+ return
50345037 endif
5038+ call rails#update_path (path , s: gem_subdirs (' app/assets' , ' lib/assets' , ' vendor/assets' , ' assets' ))
50355039
50365040 let &l: include .= (empty (&l: include ) ? ' ' : ' \|' ) .
50375041 \ ' ^\s*[[:punct:]]\+=\s*\%(link\|require\|depend_on\|stub\)\w*'
@@ -5119,7 +5123,7 @@ function! rails#ruby_setup() abort
51195123 endif
51205124 call add (path , rails#app ().path ())
51215125
5122- let engine_paths = map ( copy ( rails#app (). engines ()), ' v:val . "/ app/*" ' )
5126+ let engine_paths = s: gem_subdirs ( ' app' )
51235127 call rails#update_path (path , engine_paths)
51245128
51255129 let b: undo_ftplugin = get (b: , ' undo_ftplugin' , ' exe' ) . ' |setlocal pa= sua= inc='
0 commit comments