Skip to content

Commit 65b8cbd

Browse files
committed
Simpler app detector
1 parent 92d55a0 commit 65b8cbd

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

plugin/rails.vim

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,15 @@ function! RailsDetect(...) abort
2525
if exists('b:rails_root')
2626
return 1
2727
endif
28-
let fn = substitute(fnamemodify(a:0 ? a:1 : expand('%'), ":p"),'\c^file://','','')
29-
let sep = exists('+shellslash') && !&shellslash ? '\\' : '/'
30-
if isdirectory(fn)
31-
let fn = fnamemodify(fn,':s?[\/]$??')
32-
else
33-
let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
34-
if !isdirectory(fn)
35-
return 0
36-
endif
28+
let fn = fnamemodify(a:0 ? a:1 : expand('%'), ':p')
29+
if !isdirectory(fn)
30+
let fn = fnamemodify(fn, ':h')
31+
endif
32+
let file = findfile('config/environment.rb', escape(fn, ', ').';')
33+
if !empty(file)
34+
let b:rails_root = fnamemodify(file, ':p:h:h')
35+
return 1
3736
endif
38-
let ofn = ""
39-
let fns = []
40-
while fn != ofn && fn !=# '/' && fn !=# '.'
41-
call add(fns, fn)
42-
if filereadable(fn . "/config/environment.rb")
43-
let b:rails_root = resolve(fn)
44-
return 1
45-
endif
46-
let ofn = fn
47-
let fn = fnamemodify(ofn,':h')
48-
endwhile
49-
return 0
5037
endfunction
5138

5239
" }}}1

0 commit comments

Comments
 (0)