11" Vim completion script
22" Language: Ruby
33" Maintainer: Mark Guzman <[email protected] >4- " Last Change: 2009 Sep 28
5- " URL: http://vim-ruby.rubyforge.org
6- " Anon CVS: See above site
4+ " URL: https://github.com/vim-ruby/vim-ruby
75" Release Coordinator: Doug Kearns <[email protected] >86" Maintainer Version: 0.8.1
97" ----------------------------------------------------------------------------
1210" ----------------------------------------------------------------------------
1311
1412" {{{ requirement checks
13+
14+ function ! s: ErrMsg (msg)
15+ echohl ErrorMsg
16+ echo a: msg
17+ echohl None
18+ endfunction
19+
1520if ! has (' ruby' )
16- s: ErrMsg ( " Error: Rubycomplete requires vim compiled with +ruby" )
17- s: ErrMsg ( " Error: falling back to syntax completion" )
21+ call s: ErrMsg ( " Error: Rubycomplete requires vim compiled with +ruby" )
22+ call s: ErrMsg ( " Error: falling back to syntax completion" )
1823 " lets fall back to syntax completion
1924 setlocal omnifunc = syntaxcomplete#Complete
2025 finish
2126endif
2227
2328if version < 700
24- s: ErrMsg ( " Error: Required vim >= 7.0" )
29+ call s: ErrMsg ( " Error: Required vim >= 7.0" )
2530 finish
2631endif
2732" }}} requirement checks
5156" {{{ vim-side support functions
5257let s: rubycomplete_debug = 0
5358
54- function ! s: ErrMsg (msg)
55- echohl ErrorMsg
56- echo a: msg
57- echohl None
58- endfunction
59-
6059function ! s: dprint (msg)
6160 if s: rubycomplete_debug == 1
6261 echom a: msg
@@ -133,7 +132,7 @@ function! s:GetRubyVarType(v)
133132 let stopline = 1
134133 let vtp = ' '
135134 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*$'
137136 let [lnum,lcol] = searchpos (sstr,' nb' ,stopline)
138137 if lnum != 0 && lcol != 0
139138 call setpos (' .' ,pos)
@@ -275,7 +274,7 @@ class VimRubyCompletion
275274 pare = /^\s*class\s*(.*)\s*<\s*(.*)\s*\n/ .match ( classdef )
276275 load_buffer_class ( $2 ) if pare != nil && $2 != name # load parent class if needed
277276
278- mixre = /.*\n\s*include\s*(.*)\s*\n/ .match ( classdef )
277+ mixre = /.*\n\s*( include|prepend) \s*(.*)\s*\n/ .match ( classdef )
279278 load_buffer_module ( $2 ) if mixre != nil && $2 != name # load mixins if needed
280279
281280 begin
@@ -364,6 +363,10 @@ class VimRubyCompletion
364363 print txt if @ @d ebug
365364 end
366365
366+ def escape_vim_singlequote_string (str)
367+ str.to_s.gsub (/'/ ," \\ '" )
368+ end
369+
367370 def get_buffer_entity_list ( type )
368371 # this will be a little expensive.
369372 loading_allowed = VIM:: evaluate (" exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading" )
@@ -526,9 +529,9 @@ class VimRubyCompletion
526529 end
527530
528531 def clean_sel (sel , msg)
529- sel .delete_if { |x | x == nil }
530- sel . uniq !
531- sel . grep ( /^#{Regexp.quote(msg)}/ ) if msg != nil
532+ ret = sel .reject{ |x |x . nil?}. uniq
533+ ret = ret . grep ( /^#{Regexp.quote(msg)}/ ) if msg != nil
534+ ret
532535 end
533536
534537 def get_rails_view_methods
@@ -767,10 +770,10 @@ class VimRubyCompletion
767770 constants = clean_sel ( constants, message )
768771
769772 valid = []
770- valid += methods.collect { |m | { :name = > m , :type = > ' m' } }
771- valid += variables.collect { |v | { :name = > v , :type = > ' v' } }
772- valid += classes.collect { |c | { :name = > c , :type = > ' t' } }
773- valid += constants.collect { |d | { :name = > d , :type = > ' d' } }
773+ valid += methods.collect { |m | { :name = > m .to_s , :type = > ' m' } }
774+ valid += variables.collect { |v | { :name = > v .to_s , :type = > ' v' } }
775+ valid += classes.collect { |c | { :name = > c .to_s , :type = > ' t' } }
776+ valid += constants.collect { |d | { :name = > d .to_s , :type = > ' d' } }
774777 valid.sort ! { |x ,y | x [:name] <= > y [:name] }
775778
776779 outp = " "
@@ -779,7 +782,7 @@ class VimRubyCompletion
779782 rg.step (150 ) do |x |
780783 stpos = 0 + x
781784 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)} }
783786 outp.sub! (/,$/ , ' ' )
784787
785788 VIM:: command (" call extend(g:rubycomplete_completions, [%s])" % outp)
0 commit comments