summaryrefslogtreecommitdiff
path: root/runtime/autoload/rubycomplete.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/rubycomplete.vim')
-rw-r--r--runtime/autoload/rubycomplete.vim36
1 files changed, 32 insertions, 4 deletions
diff --git a/runtime/autoload/rubycomplete.vim b/runtime/autoload/rubycomplete.vim
index e1064c8a5..440dfd42e 100644
--- a/runtime/autoload/rubycomplete.vim
+++ b/runtime/autoload/rubycomplete.vim
@@ -93,7 +93,7 @@ function! s:GetBufferRubyEntity( name, type, ... )
let stopline = 1
- let crex = '^\s*\<' . a:type . '\>\s*\<' . a:name . '\>\s*\(<\s*.*\s*\)\?'
+ let crex = '^\s*\<' . a:type . '\>\s*\<' . escape(a:name, '*') . '\>\s*\(<\s*.*\s*\)\?'
let [lnum,lcol] = searchpos( crex, 'w' )
"let [lnum,lcol] = searchpairpos( crex . '\zs', '', '\(end\|}\)', 'w' )
@@ -149,7 +149,7 @@ function! s:GetRubyVarType(v)
let ctors = ctors.'\)'
let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
- let sstr = ''.a:v.'\>\s*[+\-*/]*'.fstr
+ let sstr = ''.escape(a:v, '*').'\>\s*[+\-*/]*'.fstr
let [lnum,lcol] = searchpos(sstr,'nb',stopline)
if lnum != 0 && lcol != 0
let str = matchstr(getline(lnum),fstr,lcol)
@@ -266,6 +266,28 @@ class VimRubyCompletion
end
end
+ def load_gems
+ fpath = VIM::evaluate("get(g:, 'rubycomplete_gemfile_path', 'Gemfile')")
+ return unless File.file?(fpath) && File.readable?(fpath)
+ want_bundler = VIM::evaluate("get(g:, 'rubycomplete_use_bundler')")
+ parse_file = !want_bundler
+ begin
+ require 'bundler'
+ Bundler.setup
+ Bundler.require
+ rescue Exception
+ parse_file = true
+ end
+ if parse_file
+ File.new(fpath).each_line do |line|
+ begin
+ require $1 if /\s*gem\s*['"]([^'"]+)/.match(line)
+ rescue Exception
+ end
+ end
+ end
+ end
+
def load_buffer_class(name)
dprint "load_buffer_class(%s) START" % name
classdef = get_buffer_entity(name, 's:GetBufferRubyClass("%s")')
@@ -588,6 +610,10 @@ class VimRubyCompletion
load_rails
end
+ want_gems = VIM::evaluate("get(g:, 'rubycomplete_load_gemfile')")
+ load_gems unless want_gems.to_i.zero?
+
+
input = VIM::Buffer.current.line
cpos = VIM::Window.current.cursor[1] - 1
input = input[0..cpos]
@@ -678,7 +704,9 @@ class VimRubyCompletion
cv = eval("self.class.constants")
vartype = get_var_type( receiver )
dprint "vartype: %s" % vartype
- if vartype != ''
+
+ invalid_vartype = ['', "gets"]
+ if !invalid_vartype.include?(vartype)
load_buffer_class( vartype )
begin
@@ -706,7 +734,7 @@ class VimRubyCompletion
methods.concat m.instance_methods(false)
}
end
- variables += add_rails_columns( "#{vartype}" ) if vartype && vartype.length > 0
+ variables += add_rails_columns( "#{vartype}" ) if vartype && !invalid_vartype.include?(vartype)
when /^\(?\s*[A-Za-z0-9:^@.%\/+*\(\)]+\.\.\.?[A-Za-z0-9:^@.%\/+*\(\)]+\s*\)?\.([^.]*)/
message = $1