Permalink
Browse files

Reimplement previous commit with sytnax based solution

Added a minimalistic sytnax file that can detect strings and comments
so the searchpair() calls can use synID names for skipping.
Special thanks to @sandermarechal for the idea.

Related to: #49
  • Loading branch information...
1 parent 356804c commit d477a92496d134e34b1401baaf151d74a6f1f60d @complex857 complex857 committed Aug 27, 2014
Showing with 85 additions and 6 deletions.
  1. +9 −6 autoload/phpcomplete.vim
  2. +76 −0 syntax/phpcompletetempbuffer.vim
@@ -178,9 +178,9 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
" Check if we are inside of PHP markup
let pos = getpos('.')
let phpbegin = searchpairpos('<?', '', '?>', 'bWn',
- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"')
+ \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
let phpend = searchpairpos('<?', '', '?>', 'Wn',
- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"')
+ \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
if phpbegin == [0,0] && phpend == [0,0]
" We are outside of any PHP markup. Complete HTML
@@ -1004,9 +1004,9 @@ function! phpcomplete#GetCurrentSymbolWithContext() " {{{
" Check if we are inside of PHP markup
let pos = getpos('.')
let phpbegin = searchpairpos('<?', '', '?>', 'bWn',
- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"')
+ \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
let phpend = searchpairpos('<?', '', '?>', 'Wn',
- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"')
+ \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
if (phpbegin == [0, 0] && phpend == [0, 0])
return ['', '', '', '']
@@ -1125,6 +1125,7 @@ function! s:readfileToTmpbuffer(file) " {{{
let cfile = join(readfile(a:file), "\n")
silent! below 1new
silent! 0put =cfile
+ silent! exec "set ft=phpcompletetempbuffer"
return [bufnr('$'), bufname('%')]
endfunction " }}}
@@ -2197,6 +2198,8 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam
silent! below 1new
silent! 0put =cfile
+ silent! exec "set ft=phpcompletetempbuffer"
+
call search('\(class\|interface\)\_s\+'.a:class_name.'\(\>\|$\)')
let cfline = line('.')
call search('{')
@@ -2209,7 +2212,7 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam
else
let extends_class = ''
endif
- call searchpair('{','', '}', 'W', 'getline(".") =~? "\\v[\"'."\\'".'].*\\}"')
+ call searchpair('{', '', '}', 'W', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
let classcontent = join(getline(cfline, line('.')), "\n")
silent! bw! %
let [current_namespace, imports] = phpcomplete#GetCurrentNameSpace(a:file_lines[0:cfline])
@@ -2637,7 +2640,7 @@ function! phpcomplete#GetCurrentFunctionBoundaries() " {{{
call search('\cfunction\_.\{-}(\_.\{-})\_.\{-}{', 'Wce')
" get the position of the function block's closing "}"
- let func_end_pos = searchpairpos('{', '', '}', 'W')
+ let func_end_pos = searchpairpos('{', '', '}', 'W', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
if func_end_pos == [0, 0]
" there is a function start but no end found, assume that we are in a
" function but the user did not typed the closing "}" yet and the
@@ -0,0 +1,76 @@
+" Vim syntax file
+" Language: PHP - only with strings and comments for the autocomplete plugin
+" Maintainer: Dávid Szabó ( complex857 AT gmail DOT com )
+" URL: https://github.com/shawncplus/phpcomplete.vim
+" Thanks: Paul Garvin <paul@paulgarvin.net>
+" Whos php.vim project where I've got all the code from.
+
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn match phpSpecialChar +\\"+ contained display
+syn match phpSpecialChar "\\\$" contained display
+syn match phpStrEsc "\\\\" contained display
+syn match phpStrEsc "\\'" contained display
+
+" Comment
+syn region phpComment start="/\*" end="\*/" contained extend
+
+syn match phpComment "#.\{-}\(?>\|$\)\@=" contained
+syn match phpComment "//.\{-}\(?>\|$\)\@=" contained
+
+syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=phpSpecialChar,phpStrEsc contained extend keepend
+syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+ contains=phpSpecialChar,phpStrEsc contained extend keepend
+syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=phpStrEsc contained keepend extend
+
+" HereDoc
+syn case match
+syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)\@<=\z(\I\i*\)$" end="^\z1\(;\=$\)\@=" contained contains=phpSpecialChar,phpStrEsc keepend extend
+syn region phpHereDoc matchgroup=Delimiter start=+\(<<<\)\@<="\z(\I\i*\)"$+ end="^\z1\(;\=$\)\@=" contained contains=phpSpecialChar,phpStrEsc keepend extend
+" including HTML,JavaScript,SQL even if not enabled via options
+syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)\@<=\z(\(\I\i*\)\=\(html\)\c\(\i*\)\)$" end="^\z1\(;\=$\)\@=" contained contains=phpSpecialChar,phpStrEsc keepend extend
+syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)\@<=\z(\(\I\i*\)\=\(sql\)\c\(\i*\)\)$" end="^\z1\(;\=$\)\@=" contained contains=phpSpecialChar,phpStrEsc keepend extend
+syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)\@<=\z(\(\I\i*\)\=\(javascript\)\c\(\i*\)\)$" end="^\z1\(;\=$\)\@=" contained contains=phpSpecialChar,phpStrEsc keepend extend
+syn case ignore
+
+" NowDoc
+syn region phpNowDoc matchgroup=Delimiter start=+\(<<<\)\@<='\z(\I\i*\)'$+ end="^\z1\(;\=$\)\@=" contained keepend extend
+
+" Clusters
+syn cluster phpClConst contains=phpStringSingle,phpStringDouble,phpBacktick
+syn cluster phpClInside contains=@phpClConst,phpComment,phpDocComment,phpHereDoc,phpNowDoc
+
+syn region phpRegion matchgroup=Delimiter start="<?\(php\)\=" end="?>" contains=@phpClInside keepend
+
+" Sync
+if php_sync_method==-1
+ syn sync match phpRegionSync grouphere phpRegion "^\s*<?\(php\)\=\s*$"
+ syn sync match phpRegionSync grouphere NONE "^\s*?>\s*$"
+ syn sync match phpRegionSync grouphere NONE "^\s*%>\s*$"
+ syn sync match phpRegionSync grouphere phpRegion "function\s.*(.*\$"
+elseif php_sync_method>0
+ exec "syn sync minlines=" . php_sync_method
+else
+ exec "syn sync fromstart"
+endif
+
+" Define the default highlighting.
+" For version 5.8 and later: only when an item doesn't have highlighting yet
+if !exists("did_php_syn_inits")
+
+ hi def link phpComment Comment
+ hi def link phpDocComment Comment
+ hi def link phpCommentStar Comment
+ hi def link phpStringSingle String
+ hi def link phpStringDouble String
+ hi def link phpBacktick String
+ hi def link phpStringDelimiter String
+ hi def link phpHereDoc String
+ hi def link phpNowDoc String
+ hi def link phpSpecialChar String
+
+endif
+
+let b:current_syntax = "phpcompletetempbuffer"

0 comments on commit d477a92

Please sign in to comment.