comparison runtime/autoload/rubycomplete.vim @ 4869:a5352e73dc00

Update runtime files.
author Bram Moolenaar <bram@vim.org>
date Wed, 12 Jun 2013 21:29:15 +0200
parents dd5c1983e355
children 43efa4f5a8ea
comparison
equal deleted inserted replaced
4868:f2f15e432db6 4869:a5352e73dc00
1 " Vim completion script 1 " Vim completion script
2 " Language: Ruby 2 " Language: Ruby
3 " Maintainer: Mark Guzman <segfault@hasno.info> 3 " Maintainer: Mark Guzman <segfault@hasno.info>
4 " Last Change: 2009 Sep 28 4 " URL: https://github.com/vim-ruby/vim-ruby
5 " URL: http://vim-ruby.rubyforge.org
6 " Anon CVS: See above site
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com> 5 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
8 " Maintainer Version: 0.8.1 6 " Maintainer Version: 0.8.1
9 " ---------------------------------------------------------------------------- 7 " ----------------------------------------------------------------------------
10 " 8 "
11 " Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com) 9 " Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
12 " ---------------------------------------------------------------------------- 10 " ----------------------------------------------------------------------------
13 11
14 " {{{ requirement checks 12 " {{{ requirement checks
13
14 function! s:ErrMsg(msg)
15 echohl ErrorMsg
16 echo a:msg
17 echohl None
18 endfunction
19
15 if !has('ruby') 20 if !has('ruby')
16 s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" ) 21 call s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" )
17 s:ErrMsg( "Error: falling back to syntax completion" ) 22 call s:ErrMsg( "Error: falling back to syntax completion" )
18 " lets fall back to syntax completion 23 " lets fall back to syntax completion
19 setlocal omnifunc=syntaxcomplete#Complete 24 setlocal omnifunc=syntaxcomplete#Complete
20 finish 25 finish
21 endif 26 endif
22 27
23 if version < 700 28 if version < 700
24 s:ErrMsg( "Error: Required vim >= 7.0" ) 29 call s:ErrMsg( "Error: Required vim >= 7.0" )
25 finish 30 finish
26 endif 31 endif
27 " }}} requirement checks 32 " }}} requirement checks
28 33
29 " {{{ configuration failsafe initialization 34 " {{{ configuration failsafe initialization
48 endif 53 endif
49 " }}} configuration failsafe initialization 54 " }}} configuration failsafe initialization
50 55
51 " {{{ vim-side support functions 56 " {{{ vim-side support functions
52 let s:rubycomplete_debug = 0 57 let s:rubycomplete_debug = 0
53
54 function! s:ErrMsg(msg)
55 echohl ErrorMsg
56 echo a:msg
57 echohl None
58 endfunction
59 58
60 function! s:dprint(msg) 59 function! s:dprint(msg)
61 if s:rubycomplete_debug == 1 60 if s:rubycomplete_debug == 1
62 echom a:msg 61 echom a:msg
63 endif 62 endif
131 130
132 function! s:GetRubyVarType(v) 131 function! s:GetRubyVarType(v)
133 let stopline = 1 132 let stopline = 1
134 let vtp = '' 133 let vtp = ''
135 let pos = getpos('.') 134 let pos = getpos('.')
136 let sstr = '^\s*#\s*@var\s*'.a:v.'\>\s\+[^ \t]\+\s*$' 135 let sstr = '^\s*#\s*@var\s*'.escape(a:v, '*').'\>\s\+[^ \t]\+\s*$'
137 let [lnum,lcol] = searchpos(sstr,'nb',stopline) 136 let [lnum,lcol] = searchpos(sstr,'nb',stopline)
138 if lnum != 0 && lcol != 0 137 if lnum != 0 && lcol != 0
139 call setpos('.',pos) 138 call setpos('.',pos)
140 let str = getline(lnum) 139 let str = getline(lnum)
141 let vtp = substitute(str,sstr,'\1','') 140 let vtp = substitute(str,sstr,'\1','')
273 return if classdef == nil 272 return if classdef == nil
274 273
275 pare = /^\s*class\s*(.*)\s*<\s*(.*)\s*\n/.match( classdef ) 274 pare = /^\s*class\s*(.*)\s*<\s*(.*)\s*\n/.match( classdef )
276 load_buffer_class( $2 ) if pare != nil && $2 != name # load parent class if needed 275 load_buffer_class( $2 ) if pare != nil && $2 != name # load parent class if needed
277 276
278 mixre = /.*\n\s*include\s*(.*)\s*\n/.match( classdef ) 277 mixre = /.*\n\s*(include|prepend)\s*(.*)\s*\n/.match( classdef )
279 load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed 278 load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed
280 279
281 begin 280 begin
282 eval classdef 281 eval classdef
283 rescue Exception 282 rescue Exception
360 end 359 end
361 end 360 end
362 361
363 def dprint( txt ) 362 def dprint( txt )
364 print txt if @@debug 363 print txt if @@debug
364 end
365
366 def escape_vim_singlequote_string(str)
367 str.to_s.gsub(/'/,"\\'")
365 end 368 end
366 369
367 def get_buffer_entity_list( type ) 370 def get_buffer_entity_list( type )
368 # this will be a little expensive. 371 # this will be a little expensive.
369 loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading") 372 loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
524 end 527 end
525 return [] 528 return []
526 end 529 end
527 530
528 def clean_sel(sel, msg) 531 def clean_sel(sel, msg)
529 sel.delete_if { |x| x == nil } 532 ret = sel.reject{|x|x.nil?}.uniq
530 sel.uniq! 533 ret = ret.grep(/^#{Regexp.quote(msg)}/) if msg != nil
531 sel.grep(/^#{Regexp.quote(msg)}/) if msg != nil 534 ret
532 end 535 end
533 536
534 def get_rails_view_methods 537 def get_rails_view_methods
535 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails") 538 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
536 rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded') 539 rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
765 variables = clean_sel( variables, message ) 768 variables = clean_sel( variables, message )
766 classes = clean_sel( classes, message ) - ["VimRubyCompletion"] 769 classes = clean_sel( classes, message ) - ["VimRubyCompletion"]
767 constants = clean_sel( constants, message ) 770 constants = clean_sel( constants, message )
768 771
769 valid = [] 772 valid = []
770 valid += methods.collect { |m| { :name => m, :type => 'm' } } 773 valid += methods.collect { |m| { :name => m.to_s, :type => 'm' } }
771 valid += variables.collect { |v| { :name => v, :type => 'v' } } 774 valid += variables.collect { |v| { :name => v.to_s, :type => 'v' } }
772 valid += classes.collect { |c| { :name => c, :type => 't' } } 775 valid += classes.collect { |c| { :name => c.to_s, :type => 't' } }
773 valid += constants.collect { |d| { :name => d, :type => 'd' } } 776 valid += constants.collect { |d| { :name => d.to_s, :type => 'd' } }
774 valid.sort! { |x,y| x[:name] <=> y[:name] } 777 valid.sort! { |x,y| x[:name] <=> y[:name] }
775 778
776 outp = "" 779 outp = ""
777 780
778 rg = 0..valid.length 781 rg = 0..valid.length
779 rg.step(150) do |x| 782 rg.step(150) do |x|
780 stpos = 0+x 783 stpos = 0+x
781 enpos = 150+x 784 enpos = 150+x
782 valid[stpos..enpos].each { |c| outp += "{'word':'%s','item':'%s','kind':'%s'}," % [ c[:name], c[:name], c[:type] ] } 785 valid[stpos..enpos].each { |c| outp += "{'word':'%s','item':'%s','kind':'%s'}," % [ c[:name], c[:name], c[:type] ].map{|x|escape_vim_singlequote_string(x)} }
783 outp.sub!(/,$/, '') 786 outp.sub!(/,$/, '')
784 787
785 VIM::command("call extend(g:rubycomplete_completions, [%s])" % outp) 788 VIM::command("call extend(g:rubycomplete_completions, [%s])" % outp)
786 outp = "" 789 outp = ""
787 end 790 end