Skip to content

Commit

Permalink
added variable type detection for Ranges
Browse files Browse the repository at this point in the history
added handlers for string completion: "test".<C-x><C-o>
  • Loading branch information
segfault committed Apr 27, 2006
1 parent 6d64561 commit f9956ad
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions autoload/rubycomplete.vim
Expand Up @@ -96,9 +96,9 @@ function! GetRubyVarType(v)
let ctors = '\(now\|new\|open\|get_instance\)'
endif

let [lnum,lcol] = searchpos(''.a:v.'\>\s*[+\-*/]*=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%r{\)','nb',stopline)
let [lnum,lcol] = searchpos(''.a:v.'\>\s*[+\-*/]*=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%r{\|[A-Za-z0-9@:\-()]\+...\?\)','nb',stopline)
if lnum != 0 && lcol != 0
let str = matchstr(getline(lnum),'=\s*\([^ \t]\+.' . ctors . '\>\|[\[{"''/]\|%r{\)',lcol)
let str = matchstr(getline(lnum),'=\s*\([^ \t]\+.' . ctors . '\>\|[\[{"''/]\|%r{\|[A-Za-z0-9@:\-()]\+...\?\)',lcol)
let str = substitute(str,'^=\s*','','')
call setpos('.',pos)
if str == '"' || str == ''''
Expand All @@ -109,6 +109,8 @@ function! GetRubyVarType(v)
return 'Hash'
elseif str == '/' || str == '%r{'
return 'Regexp'
elseif strlen(str) >= 4 && stridx(str,'..') != -1
return 'Range'
elseif strlen(str) > 4
let l = stridx(str,'.')
return str[0:l-1]
Expand Down Expand Up @@ -217,7 +219,7 @@ def load_buffer_module(name)
end

def get_buffer_entity(name, vimfun)
return nil if name == '""'
return nil if /(\"|\')+/.match( name )
buf = VIM::Buffer.current
nums = eval( VIM::evaluate( vimfun % name ) )
return nil if nums == nil
Expand All @@ -235,6 +237,14 @@ def get_buffer_entity(name, vimfun)
return classdef
end

def get_var_type( receiver )
if /(\"|\')+/.match( receiver )
"String"
else
VIM::evaluate("GetRubyVarType('%s')" % receiver)
end
end

def get_buffer_classes()
# this will be a little expensive.
allow_aggressive_load = VIM::evaluate('g:rubycomplete_classes_in_global')
Expand Down Expand Up @@ -383,8 +393,8 @@ def get_completions(base)
load_buffer_class( receiver )

cv = eval("self.class.constants")

vartype = VIM::evaluate("GetRubyVarType('%s')" % receiver)
vartype = get_var_type( receiver )
print "vartype: %s receiver: %s" % [ vartype, receiver ]
if vartype != ''
load_buffer_class( vartype )

Expand Down

0 comments on commit f9956ad

Please sign in to comment.