summaryrefslogtreecommitdiff
path: root/runtime/autoload/rubycomplete.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2006-04-22 22:33:57 +0000
committerBram Moolenaar <Bram@vim.org>2006-04-22 22:33:57 +0000
commiteb3593b38b7b6b658e93ad05d6caf76d58cc0c35 (patch)
tree39210f19a86e4db2914523b0fde4a5ff9d345c16 /runtime/autoload/rubycomplete.vim
parent57657d85c6c3d812e99b5e5d5161c07c66ac7dc7 (diff)
downloadvim-eb3593b38b7b6b658e93ad05d6caf76d58cc0c35.zip
updated for version 7.0e06
Diffstat (limited to 'runtime/autoload/rubycomplete.vim')
-rw-r--r--runtime/autoload/rubycomplete.vim71
1 files changed, 59 insertions, 12 deletions
diff --git a/runtime/autoload/rubycomplete.vim b/runtime/autoload/rubycomplete.vim
index 0a745b98c..d1c8a2653 100644
--- a/runtime/autoload/rubycomplete.vim
+++ b/runtime/autoload/rubycomplete.vim
@@ -10,6 +10,7 @@
" Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
" ----------------------------------------------------------------------------
+" {{{ requirement checks
if !has('ruby')
echohl ErrorMsg
echo "Error: Required vim compiled with +ruby"
@@ -23,8 +24,17 @@ if version < 700
echohl None
finish
endif
+" }}} requirement checks
+if !exists("g:rubycomplete_rails")
+ let g:rubycomplete_rails = 0
+endif
+
+if !exists("g:rubycomplete_classes_in_global")
+ let g:rubycomplete_classes_in_global = 0
+endif
+" {{{ vim-side support functions
function! GetBufferRubyModule(name)
let [snum,enum] = GetBufferRubyEntity(a:name, "module")
return snum . '..' . enum
@@ -103,6 +113,8 @@ function! GetRubyVarType(v)
return ''
endfunction
+"}}} vim-side support functions
+
function! rubycomplete#Complete(findstart, base)
"findstart = 1 when we need to get the text length
if a:findstart
@@ -133,6 +145,7 @@ endfunction
function! s:DefRuby()
ruby << RUBYEOF
+# {{{ ruby completion
RailsWords = [
"has_many", "has_one",
"belongs_to",
@@ -164,11 +177,11 @@ Operators = [ "%", "&", "*", "**", "+", "-", "/",
def load_requires
- @buf = VIM::Buffer.current
- enum = @buf.line_number
+ buf = VIM::Buffer.current
+ enum = buf.line_number
nums = Range.new( 1, enum )
nums.each do |x|
- ln = @buf[x]
+ ln = buf[x]
begin
eval( "require %s" % $1 ) if /.*require\s*(.*)$/.match( ln )
rescue Exception
@@ -198,7 +211,7 @@ def load_buffer_module(name)
end
def get_buffer_entity(name, vimfun)
- @buf = VIM::Buffer.current
+ buf = VIM::Buffer.current
nums = eval( VIM::evaluate( vimfun % name ) )
return nil if nums == nil
return nil if nums.min == nums.max && nums.min == 0
@@ -207,7 +220,7 @@ def get_buffer_entity(name, vimfun)
classdef = ""
nums.each do |x|
if x != cur_line
- ln = @buf[x]
+ ln = buf[x]
classdef += "%s\n" % ln
end
end
@@ -215,6 +228,25 @@ def get_buffer_entity(name, vimfun)
return classdef
end
+def get_buffer_classes()
+ # this will be a little expensive.
+ allow_aggressive_load = VIM::evaluate('g:rubycomplete_classes_in_global')
+ return [] if allow_aggressive_load != '1'
+
+ buf = VIM::Buffer.current
+ eob = buf.length
+ ret = []
+ rg = 1..eob
+
+ rg.each do |x|
+ if /^\s*class\s*([A-Za-z0-9_-]*)(\s*<\s*([A-Za-z0-9_:-]*))?\s*/.match( buf[x] )
+ ret.push $1
+ end
+ end
+
+ return ret
+end
+
def load_rails()
allow_rails = VIM::evaluate('g:rubycomplete_rails')
return if allow_rails != '1'
@@ -233,13 +265,19 @@ def load_rails()
break
end
end
+
+ return if pok == nil
bootfile = pok + "/boot.rb"
- require bootfile if pok != nil && File.exists?( bootfile )
+ if File.exists?( bootfile )
+ require bootfile
+ VIM::evaluate('let g:rubycomplete_rails_loaded = 1')
+ end
end
def get_rails_helpers
allow_rails = VIM::evaluate('g:rubycomplete_rails')
- return [] if allow_rails != '1'
+ rails_loaded = VIM::evaluate('g:rubycomplete_rails_loaded')
+ return [] if allow_rails != '1' || rails_loaded != '1'
return RailsWords
end
@@ -404,14 +442,21 @@ def get_completions(base)
receiver = $1
message = input
load_buffer_class( receiver )
- candidates = eval( "#{receiver}.instance_methods" )
- candidates += get_rails_helpers
- select_message(receiver, message, candidates)
+ begin
+ candidates = eval( "#{receiver}.instance_methods" )
+ candidates += get_rails_helpers
+ select_message(receiver, message, candidates)
+ rescue Exception
+ found = nil
+ end
end
end
if inclass == nil || found == nil
candidates = eval("self.class.constants")
+ candidates += get_buffer_classes
+ candidates.uniq!
+ candidates.sort!
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
end
end
@@ -459,10 +504,12 @@ def select_message(receiver, message, candidates)
candidates.uniq!
candidates.sort!
end
+
+# }}} ruby completion
RUBYEOF
endfunction
+let g:rubycomplete_rails_loaded = 0
-let g:rubycomplete_rails = 0
call s:DefRuby()
-" vim: set et ts=4:
+" vim:tw=78:sw=4:ts=8:ft=vim:norl: