@@ -93,7 +93,7 @@ function! s:GetBufferRubyEntity( name, type, ... )
9393
9494 let stopline = 1
9595
96- let crex = ' ^\s*\<' . a: type . ' \>\s*\<' . a: name . ' \>\s*\(<\s*.*\s*\)\?'
96+ let crex = ' ^\s*\<' . a: type . ' \>\s*\<' . escape ( a: name, ' * ' ) . ' \>\s*\(<\s*.*\s*\)\?'
9797 let [lnum,lcol] = searchpos ( crex, ' w' )
9898 " let [lnum,lcol] = searchpairpos( crex . '\zs', '', '\(end\|}\)', 'w' )
9999
@@ -149,7 +149,7 @@ function! s:GetRubyVarType(v)
149149 let ctors = ctors.' \)'
150150
151151 let fstr = ' =\s*\([^ \t]\+.' . ctors .' \>\|[\[{"'' /]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
152- let sstr = ' ' .a: v .' \>\s*[+\-*/]*' .fstr
152+ let sstr = ' ' .escape ( a: v, ' * ' ) .' \>\s*[+\-*/]*' .fstr
153153 let [lnum,lcol] = searchpos (sstr,' nb' ,stopline)
154154 if lnum != 0 && lcol != 0
155155 let str = matchstr (getline (lnum),fstr,lcol)
@@ -266,6 +266,28 @@ class VimRubyCompletion
266266 end
267267 end
268268
269+ def load_gems
270+ fpath = VIM:: evaluate (" get(g:, 'rubycomplete_gemfile_path', 'Gemfile')" )
271+ return unless File.file ?(fpath) && File.readable?(fpath)
272+ want_bundler = VIM:: evaluate (" get(g:, 'rubycomplete_use_bundler')" )
273+ parse_file = ! want_bundler
274+ begin
275+ require ' bundler'
276+ Bundler.setup
277+ Bundler.require
278+ rescue Exception
279+ parse_file = true
280+ end
281+ if parse_file
282+ File.new (fpath).each_line do |line |
283+ begin
284+ require $1 if /\s*gem\s*['"]([^'"]+)/ .match (line )
285+ rescue Exception
286+ end
287+ end
288+ end
289+ end
290+
269291 def load_buffer_class (name)
270292 dprint " load_buffer_class(%s) START" % name
271293 classdef = get_buffer_entity (name, ' s:GetBufferRubyClass("%s")' )
@@ -588,6 +610,10 @@ class VimRubyCompletion
588610 load_rails
589611 end
590612
613+ want_gems = VIM:: evaluate (" get(g:, 'rubycomplete_load_gemfile')" )
614+ load_gems unless want_gems.to_i.zero?
615+
616+
591617 input = VIM::Buffer.current.line
592618 cpos = VIM::Window.current.cursor [1 ] - 1
593619 input = input [0 ..cpos]
@@ -678,7 +704,9 @@ class VimRubyCompletion
678704 cv = eval (" self.class.constants" )
679705 vartype = get_var_type ( receiver )
680706 dprint " vartype: %s" % vartype
681- if vartype != ' '
707+
708+ invalid_vartype = [' ' , " gets" ]
709+ if ! invalid_vartype.include ?(vartype)
682710 load_buffer_class ( vartype )
683711
684712 begin
@@ -706,7 +734,7 @@ class VimRubyCompletion
706734 methods.concat m .instance_methods (false)
707735 }
708736 end
709- variables += add_rails_columns ( " #{vartype}" ) if vartype && vartype.length > 0
737+ variables += add_rails_columns ( " #{vartype}" ) if vartype && ! invalid_vartype. include ?(vartype)
710738
711739 when /^\(?\s*[A-Za-z0-9:^@.%\/+*\(\)]+\.\.\.?[A-Za-z0-9:^@.%\/+*\(\)]+\s*\)?\.([^.]*)/
712740 message = $1
0 commit comments