summaryrefslogtreecommitdiff
path: root/runtime/autoload
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-12-09 23:11:18 +0100
committerBram Moolenaar <Bram@vim.org>2019-12-09 23:11:18 +0100
commit2ed639abdc4000436115f378e28320b7bee38a6e (patch)
tree224e20482d2b67d1a680f5487b0515a7714097fa /runtime/autoload
parent661ed8b4b6da405c95ede88b0e45ac27adba3f71 (diff)
downloadvim-git-2ed639abdc4000436115f378e28320b7bee38a6e.tar.gz
Update a few runtime files.
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/rubycomplete.vim59
1 files changed, 44 insertions, 15 deletions
diff --git a/runtime/autoload/rubycomplete.vim b/runtime/autoload/rubycomplete.vim
index ea1847023..e8a187966 100644
--- a/runtime/autoload/rubycomplete.vim
+++ b/runtime/autoload/rubycomplete.vim
@@ -3,7 +3,7 @@
" Maintainer: Mark Guzman <segfault@hasno.info>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" Last Change: 2019 Jan 06
+" Last Change: 2019 Feb 25
" ----------------------------------------------------------------------------
"
" Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -53,6 +53,23 @@ if !exists("g:rubycomplete_include_objectspace")
endif
" }}} configuration failsafe initialization
+" {{{ regex patterns
+
+" Regex that defines the start-match for the 'end' keyword.
+let s:end_start_regex =
+ \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
+ \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' .
+ \ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
+ \ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>'
+
+" Regex that defines the middle-match for the 'end' keyword.
+let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|elsif\):\@!\>'
+
+" Regex that defines the end-match for the 'end' keyword.
+let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>'
+
+" }}} regex patterns
+
" {{{ vim-side support functions
let s:rubycomplete_debug = 0
@@ -103,7 +120,7 @@ function! s:GetBufferRubyEntity( name, type, ... )
endif
let curpos = getpos(".")
- let [enum,ecol] = searchpairpos( crex, '', '\(end\|}\)', 'W' )
+ let [enum,ecol] = searchpairpos( s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'W' )
call cursor(lastpos[1], lastpos[2])
if lnum > enum
@@ -128,19 +145,28 @@ function! s:IsPosInClassDef(pos)
return ret
endfunction
+function! s:IsInComment(pos)
+ let stack = synstack(a:pos[0], a:pos[1])
+ if !empty(stack)
+ return synIDattr(stack[0], 'name') =~ 'ruby\%(.*Comment\|Documentation\)'
+ else
+ return 0
+ endif
+endfunction
+
function! s:GetRubyVarType(v)
let stopline = 1
let vtp = ''
- let pos = getpos('.')
+ let curpos = getpos('.')
let sstr = '^\s*#\s*@var\s*'.escape(a:v, '*').'\>\s\+[^ \t]\+\s*$'
let [lnum,lcol] = searchpos(sstr,'nb',stopline)
if lnum != 0 && lcol != 0
- call setpos('.',pos)
+ call setpos('.',curpos)
let str = getline(lnum)
let vtp = substitute(str,sstr,'\1','')
return vtp
endif
- call setpos('.',pos)
+ call setpos('.',curpos)
let ctors = '\(now\|new\|open\|get_instance'
if exists('g:rubycomplete_rails') && g:rubycomplete_rails == 1 && s:rubycomplete_rails_loaded == 1
let ctors = ctors.'\|find\|create'
@@ -150,9 +176,13 @@ function! s:GetRubyVarType(v)
let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
let sstr = ''.escape(a:v, '*').'\>\s*[+\-*/]*'.fstr
- let [lnum,lcol] = searchpos(sstr,'nb',stopline)
- if lnum != 0 && lcol != 0
- let str = matchstr(getline(lnum),fstr,lcol)
+ let pos = searchpos(sstr,'bW')
+ while pos != [0,0] && s:IsInComment(pos)
+ let pos = searchpos(sstr,'bW')
+ endwhile
+ if pos != [0,0]
+ let [lnum, col] = pos
+ let str = matchstr(getline(lnum),fstr,col)
let str = substitute(str,'^=\s*','','')
call setpos('.',pos)
@@ -174,7 +204,7 @@ function! s:GetRubyVarType(v)
end
return ''
endif
- call setpos('.',pos)
+ call setpos('.',curpos)
return ''
endfunction
@@ -671,11 +701,10 @@ class VimRubyCompletion
methods.delete_if { |c| c.match( /'/ ) }
end
- when /^::([A-Z][^:\.\(]*)$/ # Absolute Constant or class methods
+ when /^::([A-Z][^:\.\(]*)?$/ # Absolute Constant or class methods
dprint "const or cls"
receiver = $1
- methods = Object.constants
- methods.grep(/^#{receiver}/).collect{|e| "::" + e}
+ methods = Object.constants.collect{ |c| c.to_s }.grep(/^#{receiver}/)
when /^(((::)?[A-Z][^:.\(]*)+?)::?([^:.]*)$/ # Constant or class methods
receiver = $1
@@ -684,13 +713,13 @@ class VimRubyCompletion
load_buffer_class( receiver )
load_buffer_module( receiver )
begin
- classes = eval("#{receiver}.constants")
- #methods = eval("#{receiver}.methods")
+ constants = eval("#{receiver}.constants").collect{ |c| c.to_s }.grep(/^#{message}/)
+ methods = eval("#{receiver}.methods").collect{ |m| m.to_s }.grep(/^#{message}/)
rescue Exception
dprint "exception: %s" % $!
+ constants = []
methods = []
end
- methods.grep(/^#{message}/).collect{|e| receiver + "::" + e}
when /^(:[^:.]+)\.([^.]*)$/ # Symbol
dprint "symbol"