annotate runtime/autoload/rubycomplete.vim @ 19584:3aaaa407d308

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