Skip to content

Commit cb97739

Browse files
committed
Restore support for projections inside gems
This reverts commit 5c0c19a.
1 parent 2c92a7a commit cb97739

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

autoload/rails.vim

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,6 +4601,7 @@ let s:has_projections = {
46014601
\ }
46024602
\}
46034603

4604+
let s:projections_for_gems = {}
46044605
function! s:app_projections() dict abort
46054606
let dict = s:combine_projections({}, s:default_projections)
46064607
for [k, v] in items(s:has_projections)
@@ -4610,28 +4611,43 @@ function! s:app_projections() dict abort
46104611
endfor
46114612
call s:combine_projections(dict, self.smart_projections())
46124613
call s:combine_projections(dict, get(g:, 'rails_projections', ''))
4613-
for gem in keys(get(g:, 'rails_gem_projections', {}))
4614+
for [gem, data] in items(get(g:, 'rails_gem_projections', {}))
46144615
if self.has_gem(gem)
46154616
try
4616-
if type(g:rails_gem_projections[gem]) ==# v:t_string
4617-
let file = g:rails_gem_projections[gem]
4618-
if file !~# '^\a\+:\|^/'
4617+
if type(data) ==# v:t_string && data isnot# 'lib/projections.json' && data isnot# 'lib/rails/projections.json'
4618+
if data !~# '^\a\+:\|^/\|^$'
46194619
if !has_key(self.gems(), gem)
46204620
continue
46214621
endif
4622-
let file = self.gems()[gem] . '/' . file
4622+
let data = self.gems()[gem] . '/' . data
46234623
endif
4624-
if file =~# '/$'
4625-
let file .= 'projections.json'
4624+
if data =~# '/$'
4625+
let data .= 'projections.json'
46264626
endif
4627-
call s:combine_projections(dict, rails#json_parse(s:readfile(file)))
4628-
else
4629-
call s:combine_projections(dict, g:rails_gem_projections[gem])
4627+
call s:combine_projections(dict, rails#json_parse(s:readfile(data)))
4628+
elseif type(data) ==# v:t_dict
4629+
call s:combine_projections(dict, data)
46304630
endif
46314631
catch
46324632
endtry
46334633
endif
46344634
endfor
4635+
let gem_path = escape(join(values(self.gems()),','), ' ')
4636+
if get(g:, 'rails_projections_inside_gems', 1) && !empty(gem_path)
4637+
if !has_key(s:projections_for_gems, gem_path)
4638+
let gem_projections = {}
4639+
for path in ['lib/', 'lib/rails/']
4640+
for file in findfile(path.'projections.json', gem_path, -1)
4641+
try
4642+
call s:combine_projections(gem_projections, rails#json_parse(s:readfile(self.path(file))))
4643+
catch
4644+
endtry
4645+
endfor
4646+
endfor
4647+
let s:projections_for_gems[gem_path] = gem_projections
4648+
endif
4649+
call s:combine_projections(dict, s:projections_for_gems[gem_path])
4650+
endif
46354651
if self.cache.needs('projections')
46364652
call self.cache.set('projections', {})
46374653

0 commit comments

Comments
 (0)