Permalink
Browse files

update syntax php.vim and phpcomplete.vim as well.

  • Loading branch information...
1 parent 43b8bf8 commit 86b178dfc6671605ec8a298d50ad8253921501c1 @kenguest committed Mar 16, 2013
Showing with 631 additions and 3,491 deletions.
  1. +151 −46 autoload/phpcomplete.vim
  2. +480 −3,445 syntax/php.vim
@@ -1,11 +1,9 @@
" Vim completion script
" Language: PHP
" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
-" Last Change: 2006 May 9
+" Maintainer: Shawn Biddle ( shawn AT shawnbiddle DOT com )
"
" TODO:
-" - Class aware completion:
-" a) caching?
" - Switching to HTML (XML?) completion (SQL) inside of phpStrings
" - allow also for XML completion <- better do html_flavor for HTML
" completion
@@ -134,7 +132,7 @@ function! phpcomplete#CompletePHP(findstart, base)
" few not so subtle differences as not appending of $ and addition
" of 'kind' tag (not necessary in regular completion)
- if scontext =~ '->$' && scontext !~ '\$this->$'
+ if scontext =~ '->$' || scontext =~ '::'
" Get name of the class
let classname = phpcomplete#GetClassName(scontext)
@@ -166,18 +164,17 @@ function! phpcomplete#CompletePHP(findstart, base)
let classcontent = ''
let classcontent .= "\n".phpcomplete#GetClassContents(classfile, classname)
let sccontent = split(classcontent, "\n")
+ let classAccess = expand('%:p') == fnamemodify(classlocation, ':p') ? '\\(public\\|private\\|protected\\)' : 'public'
+
+ " limit based on context to static or normal public methods
+ if scontext =~ '::'
+ let functions = filter(deepcopy(sccontent),
+ \ 'v:val =~ "^\\s*\\(\\(' . classAccess . '\\s\\+static\\|static\\)\\s\\+\\)*function"')
+ elseif scontext =~ '->$'
+ let functions = filter(deepcopy(sccontent),
+ \ 'v:val =~ "^\\s*\\(' . classAccess . '\\s\\+\\)*function"')
+ endif
- " YES, YES, YES! - we have whole content including extends!
- " Now we need to get two elements: public functions and public
- " vars
- " NO, NO, NO! - third separate filtering looking for content
- " :(, but all of them have differences. To squeeze them into
- " one implementation would require many additional arguments
- " and ifs. No good solution
- " Functions declared with public keyword or without any
- " keyword are public
- let functions = filter(deepcopy(sccontent),
- \ 'v:val =~ "^\\s*\\(static\\s\\+\\|public\\s\\+\\)*function"')
let jfuncs = join(functions, ' ')
let sfuncs = split(jfuncs, 'function\s\+')
let c_functions = {}
@@ -193,7 +190,7 @@ function! phpcomplete#CompletePHP(findstart, base)
" Variables declared with var or with public keyword are
" public
let variables = filter(deepcopy(sccontent),
- \ 'v:val =~ "^\\s*\\(public\\|var\\)\\s\\+\\$"')
+ \ 'v:val =~ "^\\s*\\(' . classAccess . '\\|var\\)\\s\\+\\$"')
let jvars = join(variables, ' ')
let svars = split(jvars, '\$')
let c_variables = {}
@@ -205,9 +202,26 @@ function! phpcomplete#CompletePHP(findstart, base)
endif
endfor
+
+ let constants = filter(deepcopy(sccontent),
+ \ 'v:val =~ "^\\s*const\\s\\+"')
+
+ let jcons = join(constants, ' ')
+ let scons = split(jcons, 'const')
+
+ let c_constants = {}
+ for i in scons
+ let c_con = matchstr(i,
+ \ '^\s*\zs[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\ze')
+ if c_con != ''
+ let c_constants[c_con] = ''
+ endif
+ endfor
+
let all_values = {}
call extend(all_values, c_functions)
call extend(all_values, c_variables)
+ call extend(all_values, c_constants)
for m in sort(keys(all_values))
if m =~ '^'.a:base && m !~ '::'
@@ -572,36 +586,93 @@ function! phpcomplete#GetClassName(scontext) " {{{
" line above
" or line in tags file
- let object = matchstr(a:scontext, '\zs[a-zA-Z_0-9\x7f-\xff]\+\ze->')
- let i = 1
- while i < line('.')
- let line = getline(line('.')-i)
- if line =~ '^\s*\*\/\?\s*$'
- let i += 1
- continue
- else
- if line =~ '@var\s\+\$'.object.'\s\+[a-zA-Z_0-9\x7f-\xff]\+'
- let classname = matchstr(line, '@var\s\+\$'.object.'\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+')
+ if a:scontext =~ '\$this->' || a:scontext =~ '\(self\|static\)::'
+ let i = 1
+ while i < line('.')
+ let line = getline(line('.')-i)
+
+ " Don't complete self:: or $this if outside of a class
+ " (assumes correct indenting)
+ if line =~ '^}'
+ return ''
+ endif
+
+ if line =~ '^abstract\s*class'
+ let classname = matchstr(line, '^abstract\s*class \zs[a-zA-Z]\w\+\ze\(\s*\|$\)')
+ return classname
+ elseif line =~ '^class'
+ let classname = matchstr(line, '^class \zs[a-zA-Z]\w\+\ze\(\s*\|$\)')
+ return classname
+ else
+ let i += 1
+ continue
+ endif
+ endwhile
+ else
+ let object = matchstr(a:scontext, '\zs[a-zA-Z_0-9\x7f-\xff]\+\ze->')
+ let i = 1
+ while i < line('.')
+ let line = getline(line('.')-i)
+ if line =~ '^\s*\*\/\?\s*$'
+ let i += 1
+ continue
+ else
+ if line =~ '@var\s\+\$'.object.'\s\+[a-zA-Z_0-9\x7f-\xff]\+'
+ let classname = matchstr(line, '@var\s\+\$'.object.'\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+')
+ return classname
+ else
+ break
+ endif
+ endif
+ endwhile
+
+ " do in-file lookup of $var = new Class
+ let i = 1
+ while i < line('.')
+ let line = getline(line('.')-i)
+ if line =~ '^\s*\$'.object.'\s*=\s*new\s\+[a-zA-Z_0-9\x7f-\xff]\+'
+
+ let classname = matchstr(line, '\$'.object.'\s*=\s*new \zs[a-zA-Z_0-9\x7f-\xff]\+')
+ return classname
+ else
+ let i += 1
+ continue
+ endif
+ endwhile
+
+ " do in-file lookup for Class::getInstance()
+ let i = 1
+ while i < line('.')
+ let line = getline(line('.')-i)
+ if line =~ '^\s*\$'.object.'\s*=&\?\s*\s\+[a-zA-Z_0-9\x7f-\xff]\+::getInstance\+'
+
+ let classname = matchstr(line, '\$'.object.'\s*=&\?\s*\zs[a-zA-Z_0-9\x7f-\xff]\+\ze::getInstance\+')
return classname
else
- break
+ let i += 1
+ continue
endif
+ endwhile
+
+ " check Constant lookup
+ let constant_object = matchstr(a:scontext, '\zs[a-zA-Z_0-9\x7f-\xff]\+\ze::')
+ if constant_object != ''
+ return constant_object
endif
- endwhile
- " OK, first way failed, now check tags file(s)
- let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")'))
- exe 'silent! vimgrep /^'.object.'.*\$'.object.'.*=\s*new\s\+.*\tv\(\t\|$\)/j '.fnames
- let qflist = getqflist()
- if len(qflist) == 0
- return ''
- else
- " In all properly managed projects it should be one item list, even if it
- " *is* longer we cannot solve conflicts, assume it is first element
- let classname = matchstr(qflist[0]['text'], '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze')
- return classname
+ " OK, first way failed, now check tags file(s)
+ let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")'))
+ exe 'silent! vimgrep /^'.object.'.*\$'.object.'.*=\s*new\s\+.*\tv\(\t\|$\)/j '.fnames
+ let qflist = getqflist()
+ if len(qflist) == 0
+ return ''
+ else
+ " In all properly managed projects it should be one item list, even if it
+ " *is* longer we cannot solve conflicts, assume it is first element
+ let classname = matchstr(qflist[0]['text'], '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze')
+ return classname
+ endif
endif
-
endfunction
" }}}
function! phpcomplete#GetClassLocation(classname) " {{{
@@ -616,6 +687,19 @@ function! phpcomplete#GetClassLocation(classname) " {{{
return 'VIMPHP_BUILTINOBJECT'
endif
+
+ " do in-file lookup for class definition
+ let i = 1
+ while i < line('.')
+ let line = getline(line('.')-i)
+ if line =~ '^\s*class ' . a:classname . '\(\s\+\|$\)'
+ return expand('%:p')
+ else
+ let i += 1
+ continue
+ endif
+ endwhile
+
" Get class location
for fname in tagfiles()
let fhead = fnamemodify(fname, ":h")
@@ -634,7 +718,9 @@ function! phpcomplete#GetClassLocation(classname) " {{{
endif
" And only one class location
if classlocation != ''
- let classlocation = fhead.classlocation
+ if matchstr(classlocation,'^/') != '/'
+ let classlocation = fhead.classlocation
+ endif
return classlocation
else
return ''
@@ -652,19 +738,20 @@ function! phpcomplete#GetClassContents(file, name) " {{{
" matching {}
below 1new
0put =cfile
+ let endline = search('{')
call search('class\s\+'.a:name)
let cfline = line('.')
+ let content = join(getline(cfline, endline),"\n")
" Catch extends
- if getline('.') =~ 'extends'
- let extends_class = matchstr(getline('.'),
- \ 'class\s\+'.a:name.'\s\+extends\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze')
+ if content =~ 'extends'
+ let extends_class = matchstr(content, 'class\_s\+'.a:name.'\_s\+extends\_s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze')
else
let extends_class = ''
endif
call search('{')
normal! %
- let classc = getline(cfline, ".")
- let classcontent = join(classc, "\n")
+
+ let classcontent = cfile
bw! %
if extends_class != ''
@@ -1008,6 +1095,24 @@ let g:php_keywords = {
\ 'LOG_NDELAY': '',
\ 'LOG_NOWAIT': '',
\ 'LOG_PERROR': '',
+\ 'FILTER_VALIDATE_INT': '',
+\ 'FILTER_VALIDATE_FLOAT': '',
+\ 'FILTER_VALIDATE_BOOLEAN': '',
+\ 'FILTER_VALIDATE_REGEXP': '',
+\ 'FILTER_VALIDATE_URL': '',
+\ 'FILTER_VALIDATE_EMAIL': '',
+\ 'FILTER_VALIDATE_IP': '',
+\ 'FILTER_SANITIZE_STRING': '',
+\ 'FILTER_SANITIZE_STRIPPED': '',
+\ 'FILTER_SANITIZE_ENCODED': '',
+\ 'FILTER_SANITIZE_SPECIAL_CHARS': '',
+\ 'FILTER_SANITIZE_EMAIL': '',
+\ 'FILTER_SANITIZE_URL': '',
+\ 'FILTER_SANITIZE_NUMBER_INT': '',
+\ 'FILTER_SANITIZE_NUMBER_FLOAT': '',
+\ 'FILTER_SANITIZE_MAGIC_QUOTES': '',
+\ 'FILTER_SANITIZE_UNSAFE_RAW': '',
+\ 'FILTER_SANITIZE_CALLBACK': '',
\ }
" }}}
" PHP builtin functions {{{
Oops, something went wrong.

0 comments on commit 86b178d

Please sign in to comment.