annotate runtime/autoload/rubycomplete.vim @ 49:000769ce6c9d default tip

Added tag v7-3-618 for changeset 67300faee616
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 01 Aug 2012 18:08:37 +0900
parents c16898406ff2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
1 " Vim completion script
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
2 " Language: Ruby
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
3 " Maintainer: Mark Guzman <segfault@hasno.info>
39
c16898406ff2 synchorinize version 7.3.081
one@zeus.cr.ie.u-ryukyu.ac.jp
parents: 34
diff changeset
4 " Last Change: 2009 Sep 28
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
5 " URL: http://vim-ruby.rubyforge.org
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
6 " Anon CVS: See above site
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
39
c16898406ff2 synchorinize version 7.3.081
one@zeus.cr.ie.u-ryukyu.ac.jp
parents: 34
diff changeset
8 " Maintainer Version: 0.8.1
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
9 " ----------------------------------------------------------------------------
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
10 "
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
11 " Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
12 " ----------------------------------------------------------------------------
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
13
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
14 " {{{ requirement checks
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
15 if !has('ruby')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
16 s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
17 s:ErrMsg( "Error: falling back to syntax completion" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
18 " lets fall back to syntax completion
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
19 setlocal omnifunc=syntaxcomplete#Complete
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
20 finish
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
21 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
22
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
23 if version < 700
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
24 s:ErrMsg( "Error: Required vim >= 7.0" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
25 finish
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
26 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
27 " }}} requirement checks
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
28
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
29 " {{{ configuration failsafe initialization
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
30 if !exists("g:rubycomplete_rails")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
31 let g:rubycomplete_rails = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
32 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
33
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
34 if !exists("g:rubycomplete_classes_in_global")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
35 let g:rubycomplete_classes_in_global = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
36 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
37
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
38 if !exists("g:rubycomplete_buffer_loading")
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
39 let g:rubycomplete_buffer_loading = 0
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
40 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
41
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
42 if !exists("g:rubycomplete_include_object")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
43 let g:rubycomplete_include_object = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
44 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
45
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
46 if !exists("g:rubycomplete_include_objectspace")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
47 let g:rubycomplete_include_objectspace = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
48 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
49 " }}} configuration failsafe initialization
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
50
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
51 " {{{ vim-side support functions
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
52 let s:rubycomplete_debug = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
53
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
54 function! s:ErrMsg(msg)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
55 echohl ErrorMsg
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
56 echo a:msg
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
57 echohl None
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
58 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
59
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
60 function! s:dprint(msg)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
61 if s:rubycomplete_debug == 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
62 echom a:msg
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
63 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
64 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
65
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
66 function! s:GetBufferRubyModule(name, ...)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
67 if a:0 == 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
68 let [snum,enum] = s:GetBufferRubyEntity(a:name, "module", a:1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
69 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
70 let [snum,enum] = s:GetBufferRubyEntity(a:name, "module")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
71 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
72 return snum . '..' . enum
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
73 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
74
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
75 function! s:GetBufferRubyClass(name, ...)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
76 if a:0 >= 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
77 let [snum,enum] = s:GetBufferRubyEntity(a:name, "class", a:1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
78 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
79 let [snum,enum] = s:GetBufferRubyEntity(a:name, "class")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
80 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
81 return snum . '..' . enum
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
82 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
83
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
84 function! s:GetBufferRubySingletonMethods(name)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
85 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
86
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
87 function! s:GetBufferRubyEntity( name, type, ... )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
88 let lastpos = getpos(".")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
89 let lastline = lastpos
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
90 if (a:0 >= 1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
91 let lastline = [ 0, a:1, 0, 0 ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
92 call cursor( a:1, 0 )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
93 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
94
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
95 let stopline = 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
96
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
97 let crex = '^\s*\<' . a:type . '\>\s*\<' . a:name . '\>\s*\(<\s*.*\s*\)\?'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
98 let [lnum,lcol] = searchpos( crex, 'w' )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
99 "let [lnum,lcol] = searchpairpos( crex . '\zs', '', '\(end\|}\)', 'w' )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
100
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
101 if lnum == 0 && lcol == 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
102 call cursor(lastpos[1], lastpos[2])
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
103 return [0,0]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
104 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
105
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
106 let curpos = getpos(".")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
107 let [enum,ecol] = searchpairpos( crex, '', '\(end\|}\)', 'wr' )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
108 call cursor(lastpos[1], lastpos[2])
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
109
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
110 if lnum > enum
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
111 return [0,0]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
112 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
113 " we found a the class def
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
114 return [lnum,enum]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
115 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
116
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
117 function! s:IsInClassDef()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
118 return s:IsPosInClassDef( line('.') )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
119 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
120
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
121 function! s:IsPosInClassDef(pos)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
122 let [snum,enum] = s:GetBufferRubyEntity( '.*', "class" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
123 let ret = 'nil'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
124
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
125 if snum < a:pos && a:pos < enum
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
126 let ret = snum . '..' . enum
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
127 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
128
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
129 return ret
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
130 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
131
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
132 function! s:GetRubyVarType(v)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
133 let stopline = 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
134 let vtp = ''
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
135 let pos = getpos('.')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
136 let sstr = '^\s*#\s*@var\s*'.a:v.'\>\s\+[^ \t]\+\s*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
137 let [lnum,lcol] = searchpos(sstr,'nb',stopline)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
138 if lnum != 0 && lcol != 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
139 call setpos('.',pos)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
140 let str = getline(lnum)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
141 let vtp = substitute(str,sstr,'\1','')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
142 return vtp
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
143 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
144 call setpos('.',pos)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
145 let ctors = '\(now\|new\|open\|get_instance'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
146 if exists('g:rubycomplete_rails') && g:rubycomplete_rails == 1 && s:rubycomplete_rails_loaded == 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
147 let ctors = ctors.'\|find\|create'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
148 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
149 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
150 let ctors = ctors.'\)'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
151
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
152 let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
153 let sstr = ''.a:v.'\>\s*[+\-*/]*'.fstr
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
154 let [lnum,lcol] = searchpos(sstr,'nb',stopline)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
155 if lnum != 0 && lcol != 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
156 let str = matchstr(getline(lnum),fstr,lcol)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
157 let str = substitute(str,'^=\s*','','')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
158
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
159 call setpos('.',pos)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
160 if str == '"' || str == '''' || stridx(tolower(str), '%q[') != -1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
161 return 'String'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
162 elseif str == '[' || stridx(str, '%w[') != -1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
163 return 'Array'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
164 elseif str == '{'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
165 return 'Hash'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
166 elseif str == '/' || str == '%r{'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
167 return 'Regexp'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
168 elseif strlen(str) >= 4 && stridx(str,'..') != -1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
169 return 'Range'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
170 elseif stridx(str, 'lambda') != -1 || str == '&'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
171 return 'Proc'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
172 elseif strlen(str) > 4
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
173 let l = stridx(str,'.')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
174 return str[0:l-1]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
175 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
176 return ''
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
177 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
178 call setpos('.',pos)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
179 return ''
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
180 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
181
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
182 "}}} vim-side support functions
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
183
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
184 "{{{ vim-side completion function
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
185 function! rubycomplete#Init()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
186 execute "ruby VimRubyCompletion.preload_rails"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
187 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
188
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
189 function! rubycomplete#Complete(findstart, base)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
190 "findstart = 1 when we need to get the text length
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
191 if a:findstart
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
192 let line = getline('.')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
193 let idx = col('.')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
194 while idx > 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
195 let idx -= 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
196 let c = line[idx-1]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
197 if c =~ '\w'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
198 continue
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
199 elseif ! c =~ '\.'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
200 idx = -1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
201 break
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
202 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
203 break
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
204 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
205 endwhile
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
206
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
207 return idx
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
208 "findstart = 0 when we need to return the list of completions
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
209 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
210 let g:rubycomplete_completions = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
211 execute "ruby VimRubyCompletion.get_completions('" . a:base . "')"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
212 return g:rubycomplete_completions
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
213 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
214 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
215 "}}} vim-side completion function
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
216
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
217 "{{{ ruby-side code
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
218 function! s:DefRuby()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
219 ruby << RUBYEOF
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
220 # {{{ ruby completion
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
221
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
222 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
223 require 'rubygems' # let's assume this is safe...?
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
224 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
225 #ignore?
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
226 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
227 class VimRubyCompletion
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
228 # {{{ constants
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
229 @@debug = false
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
230 @@ReservedWords = [
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
231 "BEGIN", "END",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
232 "alias", "and",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
233 "begin", "break",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
234 "case", "class",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
235 "def", "defined", "do",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
236 "else", "elsif", "end", "ensure",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
237 "false", "for",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
238 "if", "in",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
239 "module",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
240 "next", "nil", "not",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
241 "or",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
242 "redo", "rescue", "retry", "return",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
243 "self", "super",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
244 "then", "true",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
245 "undef", "unless", "until",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
246 "when", "while",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
247 "yield",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
248 ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
249
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
250 @@Operators = [ "%", "&", "*", "**", "+", "-", "/",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
251 "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
252 "[]", "[]=", "^", ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
253 # }}} constants
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
254
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
255 # {{{ buffer analysis magic
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
256 def load_requires
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
257 buf = VIM::Buffer.current
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
258 enum = buf.line_number
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
259 nums = Range.new( 1, enum )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
260 nums.each do |x|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
261 ln = buf[x]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
262 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
263 eval( "require %s" % $1 ) if /.*require\s*(.*)$/.match( ln )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
264 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
265 #ignore?
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
266 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
267 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
268 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
269
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
270 def load_buffer_class(name)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
271 dprint "load_buffer_class(%s) START" % name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
272 classdef = get_buffer_entity(name, 's:GetBufferRubyClass("%s")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
273 return if classdef == nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
274
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
275 pare = /^\s*class\s*(.*)\s*<\s*(.*)\s*\n/.match( classdef )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
276 load_buffer_class( $2 ) if pare != nil && $2 != name # load parent class if needed
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
277
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
278 mixre = /.*\n\s*include\s*(.*)\s*\n/.match( classdef )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
279 load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
280
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
281 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
282 eval classdef
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
283 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
284 VIM::evaluate( "s:ErrMsg( 'Problem loading class \"%s\", was it already completed?' )" % name )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
285 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
286 dprint "load_buffer_class(%s) END" % name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
287 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
288
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
289 def load_buffer_module(name)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
290 dprint "load_buffer_module(%s) START" % name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
291 classdef = get_buffer_entity(name, 's:GetBufferRubyModule("%s")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
292 return if classdef == nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
293
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
294 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
295 eval classdef
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
296 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
297 VIM::evaluate( "s:ErrMsg( 'Problem loading module \"%s\", was it already completed?' )" % name )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
298 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
299 dprint "load_buffer_module(%s) END" % name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
300 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
301
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
302 def get_buffer_entity(name, vimfun)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
303 loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
304 return nil if loading_allowed.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
305 return nil if /(\"|\')+/.match( name )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
306 buf = VIM::Buffer.current
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
307 nums = eval( VIM::evaluate( vimfun % name ) )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
308 return nil if nums == nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
309 return nil if nums.min == nums.max && nums.min == 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
310
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
311 dprint "get_buffer_entity START"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
312 visited = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
313 clscnt = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
314 bufname = VIM::Buffer.current.name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
315 classdef = ""
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
316 cur_line = VIM::Buffer.current.line_number
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
317 while (nums != nil && !(nums.min == 0 && nums.max == 0) )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
318 dprint "visited: %s" % visited.to_s
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
319 break if visited.index( nums )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
320 visited << nums
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
321
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
322 nums.each do |x|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
323 if x != cur_line
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
324 next if x == 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
325 ln = buf[x]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
326 if /^\s*(module|class|def|include)\s+/.match(ln)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
327 clscnt += 1 if $1 == "class"
39
c16898406ff2 synchorinize version 7.3.081
one@zeus.cr.ie.u-ryukyu.ac.jp
parents: 34
diff changeset
328 #dprint "\$1$1
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
329 classdef += "%s\n" % ln
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
330 classdef += "end\n" if /def\s+/.match(ln)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
331 dprint ln
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
332 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
333 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
334 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
335
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
336 nm = "%s(::.*)*\", %s, \"" % [ name, nums.last ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
337 nums = eval( VIM::evaluate( vimfun % nm ) )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
338 dprint "nm: \"%s\"" % nm
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
339 dprint "vimfun: %s" % (vimfun % nm)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
340 dprint "got nums: %s" % nums.to_s
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
341 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
342 if classdef.length > 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
343 classdef += "end\n"*clscnt
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
344 # classdef = "class %s\n%s\nend\n" % [ bufname.gsub( /\/|\\/, "_" ), classdef ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
345 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
346
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
347 dprint "get_buffer_entity END"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
348 dprint "classdef====start"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
349 lns = classdef.split( "\n" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
350 lns.each { |x| dprint x }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
351 dprint "classdef====end"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
352 return classdef
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
353 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
354
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
355 def get_var_type( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
356 if /(\"|\')+/.match( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
357 "String"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
358 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
359 VIM::evaluate("s:GetRubyVarType('%s')" % receiver)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
360 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
361 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
362
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
363 def dprint( txt )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
364 print txt if @@debug
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
365 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
366
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
367 def get_buffer_entity_list( type )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
368 # this will be a little expensive.
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
369 loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
370 allow_aggressive_load = VIM::evaluate("exists('g:rubycomplete_classes_in_global') && g:rubycomplete_classes_in_global")
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
371 return [] if allow_aggressive_load.to_i.zero? || loading_allowed.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
372
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
373 buf = VIM::Buffer.current
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
374 eob = buf.length
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
375 ret = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
376 rg = 1..eob
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
377 re = eval( "/^\s*%s\s*([A-Za-z0-9_:-]*)(\s*<\s*([A-Za-z0-9_:-]*))?\s*/" % type )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
378
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
379 rg.each do |x|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
380 if re.match( buf[x] )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
381 next if type == "def" && eval( VIM::evaluate("s:IsPosInClassDef(%s)" % x) ) != nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
382 ret.push $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
383 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
384 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
385
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
386 return ret
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
387 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
388
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
389 def get_buffer_modules
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
390 return get_buffer_entity_list( "modules" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
391 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
392
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
393 def get_buffer_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
394 return get_buffer_entity_list( "def" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
395 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
396
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
397 def get_buffer_classes
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
398 return get_buffer_entity_list( "class" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
399 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
400
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
401
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
402 def load_rails
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
403 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
404 return if allow_rails.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
405
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
406 buf_path = VIM::evaluate('expand("%:p")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
407 file_name = VIM::evaluate('expand("%:t")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
408 vim_dir = VIM::evaluate('getcwd()')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
409 file_dir = buf_path.gsub( file_name, '' )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
410 file_dir.gsub!( /\\/, "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
411 vim_dir.gsub!( /\\/, "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
412 vim_dir << "/"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
413 dirs = [ vim_dir, file_dir ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
414 sdirs = [ "", "./", "../", "../../", "../../../", "../../../../" ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
415 rails_base = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
416
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
417 dirs.each do |dir|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
418 sdirs.each do |sub|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
419 trail = "%s%s" % [ dir, sub ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
420 tcfg = "%sconfig" % trail
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
421
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
422 if File.exists?( tcfg )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
423 rails_base = trail
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
424 break
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
425 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
426 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
427 break if rails_base
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
428 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
429
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
430 return if rails_base == nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
431 $:.push rails_base unless $:.index( rails_base )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
432
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
433 rails_config = rails_base + "config/"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
434 rails_lib = rails_base + "lib/"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
435 $:.push rails_config unless $:.index( rails_config )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
436 $:.push rails_lib unless $:.index( rails_lib )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
437
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
438 bootfile = rails_config + "boot.rb"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
439 envfile = rails_config + "environment.rb"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
440 if File.exists?( bootfile ) && File.exists?( envfile )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
441 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
442 require bootfile
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
443 require envfile
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
444 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
445 require 'console_app'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
446 require 'console_with_helpers'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
447 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
448 dprint "Rails 1.1+ Error %s" % $!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
449 # assume 1.0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
450 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
451 #eval( "Rails::Initializer.run" ) #not necessary?
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
452 VIM::command('let s:rubycomplete_rails_loaded = 1')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
453 dprint "rails loaded"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
454 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
455 dprint "Rails Error %s" % $!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
456 VIM::evaluate( "s:ErrMsg('Error loading rails environment')" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
457 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
458 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
459 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
460
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
461 def get_rails_helpers
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
462 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
463 rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
464 return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
465
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
466 buf_path = VIM::evaluate('expand("%:p")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
467 buf_path.gsub!( /\\/, "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
468 path_elm = buf_path.split( "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
469 dprint "buf_path: %s" % buf_path
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
470 types = [ "app", "db", "lib", "test", "components", "script" ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
471
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
472 i = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
473 ret = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
474 type = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
475 types.each do |t|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
476 i = path_elm.index( t )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
477 break if i
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
478 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
479 type = path_elm[i]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
480 type.downcase!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
481
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
482 dprint "type: %s" % type
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
483 case type
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
484 when "app"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
485 i += 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
486 subtype = path_elm[i]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
487 subtype.downcase!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
488
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
489 dprint "subtype: %s" % subtype
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
490 case subtype
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
491 when "views"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
492 ret += ActionView::Base.instance_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
493 ret += ActionView::Base.methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
494 when "controllers"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
495 ret += ActionController::Base.instance_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
496 ret += ActionController::Base.methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
497 when "models"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
498 ret += ActiveRecord::Base.instance_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
499 ret += ActiveRecord::Base.methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
500 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
501
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
502 when "db"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
503 ret += ActiveRecord::ConnectionAdapters::SchemaStatements.instance_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
504 ret += ActiveRecord::ConnectionAdapters::SchemaStatements.methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
505 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
506
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
507
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
508 return ret
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
509 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
510
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
511 def add_rails_columns( cls )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
512 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
513 rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
514 return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
515
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
516 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
517 eval( "#{cls}.establish_connection" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
518 return [] unless eval( "#{cls}.ancestors.include?(ActiveRecord::Base).to_s" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
519 col = eval( "#{cls}.column_names" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
520 return col if col
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
521 rescue
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
522 dprint "add_rails_columns err: (cls: %s) %s" % [ cls, $! ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
523 return []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
524 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
525 return []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
526 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
527
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
528 def clean_sel(sel, msg)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
529 sel.delete_if { |x| x == nil }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
530 sel.uniq!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
531 sel.grep(/^#{Regexp.quote(msg)}/) if msg != nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
532 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
533
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
534 def get_rails_view_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
535 allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
536 rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
537 return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
538
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
539 buf_path = VIM::evaluate('expand("%:p")')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
540 buf_path.gsub!( /\\/, "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
541 pelm = buf_path.split( "/" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
542 idx = pelm.index( "views" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
543
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
544 return [] unless idx
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
545 idx += 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
546
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
547 clspl = pelm[idx].camelize.pluralize
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
548 cls = clspl.singularize
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
549
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
550 ret = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
551 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
552 ret += eval( "#{cls}.instance_methods" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
553 ret += eval( "#{clspl}Helper.instance_methods" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
554 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
555 dprint "Error: Unable to load rails view helpers for %s: %s" % [ cls, $! ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
556 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
557
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
558 return ret
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
559 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
560 # }}} buffer analysis magic
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
561
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
562 # {{{ main completion code
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
563 def self.preload_rails
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
564 a = VimRubyCompletion.new
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
565 require 'Thread'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
566 Thread.new(a) do |b|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
567 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
568 b.load_rails
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
569 rescue
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
570 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
571 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
572 a.load_rails
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
573 rescue
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
574 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
575
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
576 def self.get_completions(base)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
577 b = VimRubyCompletion.new
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
578 b.get_completions base
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
579 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
580
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
581 def get_completions(base)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
582 loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
9
6a13985590e6 *** empty log message ***
axmo
parents: 0
diff changeset
583 if loading_allowed.to_i == 1
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
584 load_requires
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
585 load_rails
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
586 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
587
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
588 input = VIM::Buffer.current.line
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
589 cpos = VIM::Window.current.cursor[1] - 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
590 input = input[0..cpos]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
591 input += base
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
592 input.sub!(/.*[ \t\n\"\\'`><=;|&{(]/, '') # Readline.basic_word_break_characters
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
593 input.sub!(/self\./, '')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
594 input.sub!(/.*((\.\.[\[(]?)|([\[(]))/, '')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
595
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
596 dprint 'input %s' % input
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
597 message = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
598 receiver = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
599 methods = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
600 variables = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
601 classes = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
602 constants = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
603
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
604 case input
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
605 when /^(\/[^\/]*\/)\.([^.]*)$/ # Regexp
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
606 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
607 message = Regexp.quote($2)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
608 methods = Regexp.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
609
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
610 when /^([^\]]*\])\.([^.]*)$/ # Array
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
611 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
612 message = Regexp.quote($2)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
613 methods = Array.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
614
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
615 when /^([^\}]*\})\.([^.]*)$/ # Proc or Hash
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
616 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
617 message = Regexp.quote($2)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
618 methods = Proc.instance_methods(true) | Hash.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
619
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
620 when /^(:[^:.]*)$/ # Symbol
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
621 dprint "symbol"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
622 if Symbol.respond_to?(:all_symbols)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
623 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
624 message = $1.sub( /:/, '' )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
625 methods = Symbol.all_symbols.collect{|s| s.id2name}
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
626 methods.delete_if { |c| c.match( /'/ ) }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
627 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
628
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
629 when /^::([A-Z][^:\.\(]*)$/ # Absolute Constant or class methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
630 dprint "const or cls"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
631 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
632 methods = Object.constants
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
633 methods.grep(/^#{receiver}/).collect{|e| "::" + e}
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
634
39
c16898406ff2 synchorinize version 7.3.081
one@zeus.cr.ie.u-ryukyu.ac.jp
parents: 34
diff changeset
635 when /^(((::)?[A-Z][^:.\(]*)+?)::?([^:.]*)$/ # Constant or class methods
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
636 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
637 message = Regexp.quote($4)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
638 dprint "const or cls 2 [recv: \'%s\', msg: \'%s\']" % [ receiver, message ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
639 load_buffer_class( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
640 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
641 classes = eval("#{receiver}.constants")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
642 #methods = eval("#{receiver}.methods")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
643 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
644 dprint "exception: %s" % $!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
645 methods = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
646 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
647 methods.grep(/^#{message}/).collect{|e| receiver + "::" + e}
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
648
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
649 when /^(:[^:.]+)\.([^.]*)$/ # Symbol
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
650 dprint "symbol"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
651 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
652 message = Regexp.quote($2)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
653 methods = Symbol.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
654
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
655 when /^([0-9_]+(\.[0-9_]+)?(e[0-9]+)?)\.([^.]*)$/ # Numeric
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
656 dprint "numeric"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
657 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
658 message = Regexp.quote($4)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
659 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
660 methods = eval(receiver).methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
661 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
662 methods = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
663 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
664
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
665 when /^(\$[^.]*)$/ #global
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
666 dprint "global"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
667 methods = global_variables.grep(Regexp.new(Regexp.quote($1)))
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
668
39
c16898406ff2 synchorinize version 7.3.081
one@zeus.cr.ie.u-ryukyu.ac.jp
parents: 34
diff changeset
669 when /^((\.?[^.]+)+?)\.([^.]*)$/ # variable
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
670 dprint "variable"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
671 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
672 message = Regexp.quote($3)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
673 load_buffer_class( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
674
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
675 cv = eval("self.class.constants")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
676 vartype = get_var_type( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
677 dprint "vartype: %s" % vartype
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
678 if vartype != ''
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
679 load_buffer_class( vartype )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
680
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
681 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
682 methods = eval("#{vartype}.instance_methods")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
683 variables = eval("#{vartype}.instance_variables")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
684 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
685 dprint "load_buffer_class err: %s" % $!
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
686 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
687 elsif (cv).include?(receiver)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
688 # foo.func and foo is local var.
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
689 methods = eval("#{receiver}.methods")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
690 vartype = receiver
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
691 elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
692 vartype = receiver
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
693 # Foo::Bar.func
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
694 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
695 methods = eval("#{receiver}.methods")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
696 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
697 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
698 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
699 # func1.func2
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
700 ObjectSpace.each_object(Module){|m|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
701 next if m.name != "IRB::Context" and
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
702 /^(IRB|SLex|RubyLex|RubyToken)/ =~ m.name
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
703 methods.concat m.instance_methods(false)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
704 }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
705 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
706 variables += add_rails_columns( "#{vartype}" ) if vartype && vartype.length > 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
707
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
708 when /^\(?\s*[A-Za-z0-9:^@.%\/+*\(\)]+\.\.\.?[A-Za-z0-9:^@.%\/+*\(\)]+\s*\)?\.([^.]*)/
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
709 message = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
710 methods = Range.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
711
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
712 when /^\.([^.]*)$/ # unknown(maybe String)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
713 message = Regexp.quote($1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
714 methods = String.instance_methods(true)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
715
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
716 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
717 dprint "default/other"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
718 inclass = eval( VIM::evaluate("s:IsInClassDef()") )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
719
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
720 if inclass != nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
721 dprint "inclass"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
722 classdef = "%s\n" % VIM::Buffer.current[ inclass.min ]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
723 found = /^\s*class\s*([A-Za-z0-9_-]*)(\s*<\s*([A-Za-z0-9_:-]*))?\s*\n$/.match( classdef )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
724
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
725 if found != nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
726 receiver = $1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
727 message = input
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
728 load_buffer_class( receiver )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
729 begin
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
730 methods = eval( "#{receiver}.instance_methods" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
731 variables += add_rails_columns( "#{receiver}" )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
732 rescue Exception
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
733 found = nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
734 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
735 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
736 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
737
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
738 if inclass == nil || found == nil
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
739 dprint "inclass == nil"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
740 methods = get_buffer_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
741 methods += get_rails_view_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
742
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
743 cls_const = Class.constants
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
744 constants = cls_const.select { |c| /^[A-Z_-]+$/.match( c ) }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
745 classes = eval("self.class.constants") - constants
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
746 classes += get_buffer_classes
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
747 classes += get_buffer_modules
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
748
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
749 include_objectspace = VIM::evaluate("exists('g:rubycomplete_include_objectspace') && g:rubycomplete_include_objectspace")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
750 ObjectSpace.each_object(Class) { |cls| classes << cls.to_s } if include_objectspace == "1"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
751 message = receiver = input
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
752 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
753
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
754 methods += get_rails_helpers
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
755 methods += Kernel.public_methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
756 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
757
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
758
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
759 include_object = VIM::evaluate("exists('g:rubycomplete_include_object') && g:rubycomplete_include_object")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
760 methods = clean_sel( methods, message )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
761 methods = (methods-Object.instance_methods) if include_object == "0"
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
762 rbcmeth = (VimRubyCompletion.instance_methods-Object.instance_methods) # lets remove those rubycomplete methods
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
763 methods = (methods-rbcmeth)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
764
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
765 variables = clean_sel( variables, message )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
766 classes = clean_sel( classes, message ) - ["VimRubyCompletion"]
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
767 constants = clean_sel( constants, message )
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
768
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
769 valid = []
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
770 valid += methods.collect { |m| { :name => m, :type => 'm' } }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
771 valid += variables.collect { |v| { :name => v, :type => 'v' } }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
772 valid += classes.collect { |c| { :name => c, :type => 't' } }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
773 valid += constants.collect { |d| { :name => d, :type => 'd' } }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
774 valid.sort! { |x,y| x[:name] <=> y[:name] }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
775
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
776 outp = ""
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
777
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
778 rg = 0..valid.length
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
779 rg.step(150) do |x|
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
780 stpos = 0+x
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
781 enpos = 150+x
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
782 valid[stpos..enpos].each { |c| outp += "{'word':'%s','item':'%s','kind':'%s'}," % [ c[:name], c[:name], c[:type] ] }
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
783 outp.sub!(/,$/, '')
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
784
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
785 VIM::command("call extend(g:rubycomplete_completions, [%s])" % outp)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
786 outp = ""
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
787 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
788 end
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
789 # }}} main completion code
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
790
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
791 end # VimRubyCompletion
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
792 # }}} ruby completion
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
793 RUBYEOF
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
794 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
795
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
796 let s:rubycomplete_rails_loaded = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
797
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
798 call s:DefRuby()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
799 "}}} ruby-side code
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
800
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
801
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
802 " vim:tw=78:sw=4:ts=8:et:fdm=marker:ft=vim:norl: