Skip to content

Commit

Permalink
Add support for line-line docblock typehints for properties
Browse files Browse the repository at this point in the history
Adds support for the following style:
    /* @var ClassB */
    private $classb;

Fixes #65
  • Loading branch information
dudu committed May 15, 2015
1 parent 12d56a3 commit 0e5cfcf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions autoload/phpcomplete.vim
Expand Up @@ -1655,8 +1655,8 @@ function! phpcomplete#GetCallChainReturnType(classname_candidate, class_candidat
" Get Structured information of all classes and subclasses including namespace and includes
" try to find the method's return type in docblock comment
for classstructure in classcontents
let doclock_target_pattern = 'function\s\+&\?'.method.'\|\(public\|private\|protected\|var\).\+\$'.method
let doc_str = phpcomplete#GetDocBlock(split(classstructure.content, '\n'), doclock_target_pattern)
let docblock_target_pattern = 'function\s\+&\?'.method.'\|\(public\|private\|protected\|var\).\+\$'.method
let doc_str = phpcomplete#GetDocBlock(split(classstructure.content, '\n'), docblock_target_pattern)
if doc_str != ''
break
endif
Expand Down Expand Up @@ -2482,8 +2482,11 @@ function! phpcomplete#GetDocBlock(sccontent, search) " {{{
" start backward serch for the comment block
while l != 0
let line = a:sccontent[l]
" if comment end found save line position and end search
if line =~? '^\s*\*/'
" if it's a one line docblock like comment and we can just return it right away
if line =~? '^\s*\/\*\*.\+\*\/\s*$'
return substitute(line, '\v^\s*(\/\*\*\s*)|(\s*\*\/)\s*$', '', 'g')
"... or if comment end found save line position and end search
elseif line =~? '^\s*\*/'
let comment_end = l
break
" ... or the line doesn't blank (only whitespace or nothing) end search
Expand All @@ -2505,6 +2508,7 @@ function! phpcomplete#GetDocBlock(sccontent, search) " {{{
endif
let l -= 1
endwhile

" no docblock comment start found
if comment_start == -1
return ''
Expand Down
9 changes: 9 additions & 0 deletions tests/GetDocBlock_test.vim
Expand Up @@ -27,4 +27,13 @@ fun! TestCase_returns_the_comment_block_without_last_and_first_line_and_without_
\ ret)
endf

fun! TestCase_recognizes_a_oneline_comment_block_for_properties()
call SetUp()

let ret = phpcomplete#GetDocBlock(g:fixture_class_content, ' public $onliner;')
call VUAssertEquals(
\ "@var Bar",
\ ret)
endf

" vim: foldmethod=marker:expandtab:ts=4:sts=4
3 changes: 3 additions & 0 deletions tests/fixtures/DocBlock/foo.class.php
Expand Up @@ -45,4 +45,7 @@ public function not_commented() {
*/
public function minimally_commented() {
}

/** @var Bar */
public $onliner;
}

1 comment on commit 0e5cfcf

@vbjordan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, thanks for the fix.

Please sign in to comment.