Skip to content

Commit

Permalink
Improve context detection around interfaces in class declarations
Browse files Browse the repository at this point in the history
Made GetCurrentInstruction return the class declaration as a whole even
if theres a `,` in it (list of implemented interfaces)
Made the only completion for the second word after an extended class to be
`implements`
  • Loading branch information
dudu committed Mar 20, 2014
1 parent b5a015b commit a137e60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions autoload/phpcomplete.vim
Expand Up @@ -274,6 +274,8 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{
" }}}
elseif context =~? 'implements'
return phpcomplete#CompleteClassName(a:base, ['i'], current_namespace, imports)
elseif context =~? 'extends\s\+.\+$'
return ['implements']
elseif context =~? 'extends'
let kinds = context =~? 'class\s' ? ['c'] : ['i']
return phpcomplete#CompleteClassName(a:base, kinds, current_namespace, imports)
Expand Down Expand Up @@ -1208,7 +1210,7 @@ function! phpcomplete#GetCurrentInstruction(line_number, col_number, phpbegin) "
\ '!', '@', '%', '^', '&',
\ '*', '/', '-', '+', '=',
\ ':', '>', '<', '.', '?',
\ ';', '(', '|', '['
\ ';', '(', '|', '['
\ ]

let phpbegin_length = len(matchstr(getline(a:phpbegin[0]), '\zs<?\(php\)\?\ze'))
Expand Down Expand Up @@ -1317,8 +1319,8 @@ function! phpcomplete#GetCurrentInstruction(line_number, col_number, phpbegin) "

" there were a "naked" coma in the instruction
if first_coma_break_pos != -1
if instruction !~? '^use' " use ... statements should not be broken up
let pos = -1 * first_coma_break_pos + 1
if instruction !~? '^use' && instruction !~? '^class' " use ... statements and class delcarations should not be broken up by comas
let pos = (-1 * first_coma_break_pos) + 1
let instruction = instruction[pos :]
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion tests/CompleteClassName_test.vim
Expand Up @@ -125,7 +125,7 @@ fun! TestCase_complete_classes_from_built_in_classes()
\ 'name': 'FindMeFoo'
\ },
\}
" the completion should give the value of the 'name' property regardeless
" the completion should give the value of the 'name' property regardless
" of the outer dictionary keys
let res = phpcomplete#CompleteClassName('tra', ['i'], '\', {})
call VUAssertEquals([
Expand Down
6 changes: 6 additions & 0 deletions tests/GetCurrentInstruction_test.vim
Expand Up @@ -139,5 +139,11 @@ fun! TestCase_returns_instuction_string()
call VUAssertEquals(
\ '$foo->',
\ res)
call cursor(96, 48)
let res = phpcomplete#GetCurrentInstruction(96, 48, [1, 1])
call VUAssertEquals(
\ 'class Foo extends Bar implements ArrayAccess, It',
\ res)

silent! bw! %
endf
2 changes: 2 additions & 0 deletions tests/fixtures/GetCurrentInstruction/instructions.php
Expand Up @@ -92,3 +92,5 @@ public function bar()
;
return $foo-> // cursor here
;

class Foo extends Bar implements ArrayAccess, It

0 comments on commit a137e60

Please sign in to comment.