Skip to content

Commit fe35544

Browse files
committed
Skip comments when determing completion types
E.g., x was being completed as an Array x = "42" # x = [42] x.
1 parent eec4d89 commit fe35544

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

autoload/rubycomplete.vim

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,28 @@ function! s:IsPosInClassDef(pos)
144144
return ret
145145
endfunction
146146

147+
function! s:IsInComment(pos)
148+
let stack = synstack(a:pos[0], a:pos[1])
149+
if !empty(stack)
150+
return synIDattr(stack[0], 'name') =~ 'ruby\%(.*Comment\|Documentation\)'
151+
else
152+
return 0
153+
endif
154+
endfunction
155+
147156
function! s:GetRubyVarType(v)
148157
let stopline = 1
149158
let vtp = ''
150-
let pos = getpos('.')
159+
let curpos = getpos('.')
151160
let sstr = '^\s*#\s*@var\s*'.escape(a:v, '*').'\>\s\+[^ \t]\+\s*$'
152161
let [lnum,lcol] = searchpos(sstr,'nb',stopline)
153162
if lnum != 0 && lcol != 0
154-
call setpos('.',pos)
163+
call setpos('.',curpos)
155164
let str = getline(lnum)
156165
let vtp = substitute(str,sstr,'\1','')
157166
return vtp
158167
endif
159-
call setpos('.',pos)
168+
call setpos('.',curpos)
160169
let ctors = '\(now\|new\|open\|get_instance'
161170
if exists('g:rubycomplete_rails') && g:rubycomplete_rails == 1 && s:rubycomplete_rails_loaded == 1
162171
let ctors = ctors.'\|find\|create'
@@ -166,9 +175,13 @@ function! s:GetRubyVarType(v)
166175

167176
let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
168177
let sstr = ''.escape(a:v, '*').'\>\s*[+\-*/]*'.fstr
169-
let [lnum,lcol] = searchpos(sstr,'nb',stopline)
170-
if lnum != 0 && lcol != 0
171-
let str = matchstr(getline(lnum),fstr,lcol)
178+
let pos = searchpos(sstr,'bW')
179+
while pos != [0,0] && s:IsInComment(pos)
180+
let pos = searchpos(sstr,'bW')
181+
endwhile
182+
if pos != [0,0]
183+
let [lnum, col] = pos
184+
let str = matchstr(getline(lnum),fstr,col)
172185
let str = substitute(str,'^=\s*','','')
173186

174187
call setpos('.',pos)
@@ -190,7 +203,7 @@ function! s:GetRubyVarType(v)
190203
end
191204
return ''
192205
endif
193-
call setpos('.',pos)
206+
call setpos('.',curpos)
194207
return ''
195208
endfunction
196209

0 commit comments

Comments
 (0)