@@ -25,25 +25,23 @@ function! RailsDetect(...) abort
2525 if exists (' b:rails_root' )
2626 return 1
2727 endif
28- let fn = fnamemodify (a: 0 ? a: 1 : expand (' %' ), ' :p' )
29- let ns = matchstr (fn, ' ^\a\a\+\ze:' )
30- if len (ns) && exists (' *' . ns . ' #filereadable' ) && exists (' *' . ns . ' #isdirectory' ) && ! get (g: , ' projectionist_ignore_' . ns)
31- let fn = substitute (fn, ' [^:\/#]*$' , ' ' , ' ' )
32- while fn = ~# ' ^\a\a\+:.'
33- if {ns}#filereadable (fn . ' config/environment.rb' ) && {ns}#isdirectory (fn . ' app' )
34- let b: rails_root = substitute (fn, ' [:\/#]$' , ' ' , ' ' )
28+ let path = a: 0 ? a: 1 : @%
29+ if exists (' *ProjectionistHas' )
30+ if path !~# ' ^/\|^\a\+:'
31+ let path = getcwd () . ' /' . path
32+ endif
33+ let previous = ' '
34+ while path !=# previous && path !~# ' ^\.\=$\|^[\/][\/][^\/]*$'
35+ if ProjectionistHas (' config/environment.rb&app/' , path )
36+ let b: rails_root = path
3537 return 1
3638 endif
37- let fn = substitute (fn, ' [^:\/#]*[:\/#][^:\/#]*$' , ' ' , ' ' )
39+ let previous = path
40+ let path = fnamemodify (path , ' :h' )
3841 endwhile
3942 return 0
40- elseif len (ns) || fn = ~# ' :[\/]\{2\}'
41- return 0
42- endif
43- if ! isdirectory (fn)
44- let fn = fnamemodify (fn, ' :h' )
4543 endif
46- let file = findfile (' config/environment.rb' , escape (fn , ' , ' ).' ;' )
44+ let file = findfile (' config/environment.rb' , escape (fnamemodify ( path , ' :p:h ' ) , ' , ' ).' ;' )
4745 if ! empty (file ) && isdirectory (fnamemodify (file , ' :p:h:h' ) . ' /app' )
4846 let b: rails_root = fnamemodify (file , ' :p:h:h' )
4947 return 1
@@ -83,7 +81,7 @@ augroup railsPluginDetect
8381 autocmd !
8482
8583 autocmd BufNewFile ,BufReadPost *
86- \ if RailsDetect (expand (" <afile>:p " )) && empty (&filetype ) |
84+ \ if RailsDetect (expand (" <afile>" )) && empty (&filetype ) |
8785 \ call rails#buffer_setup () |
8886 \ endif
8987 autocmd VimEnter *
0 commit comments