|
3 | 3 | " Maintainer: Dávid Szabó ( complex857 AT gmail DOT com ) |
4 | 4 | " Previous Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) |
5 | 5 | " URL: https://github.com/shawncplus/phpcomplete.vim |
6 | | -" Last Change: 2016 Oct 10 |
| 6 | +" Last Change: 2018 Oct 10 |
7 | 7 | " |
8 | 8 | " OPTIONS: |
9 | 9 | " |
@@ -146,6 +146,8 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{ |
146 | 146 | end |
147 | 147 |
|
148 | 148 | try |
| 149 | + let eventignore = &eventignore |
| 150 | + let &eventignore = 'all' |
149 | 151 | let winheight = winheight(0) |
150 | 152 | let winnr = winnr() |
151 | 153 |
|
@@ -216,6 +218,7 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{ |
216 | 218 | endif |
217 | 219 | finally |
218 | 220 | silent! exec winnr.'resize '.winheight |
| 221 | + let &eventignore = eventignore |
219 | 222 | endtry |
220 | 223 | endfunction |
221 | 224 | " }}} |
@@ -1393,23 +1396,28 @@ function! phpcomplete#GetCallChainReturnType(classname_candidate, class_candidat |
1393 | 1396 | for classstructure in classcontents |
1394 | 1397 | let docblock_target_pattern = 'function\s\+&\?'.method.'\>\|\(public\|private\|protected\|var\).\+\$'.method.'\>\|@property.\+\$'.method.'\>' |
1395 | 1398 | let doc_str = phpcomplete#GetDocBlock(split(classstructure.content, '\n'), docblock_target_pattern) |
1396 | | - if doc_str != '' |
| 1399 | + let return_type_hint = phpcomplete#GetFunctionReturnTypeHint(split(classstructure.content, '\n'), 'function\s\+&\?'.method.'\>') |
| 1400 | + if doc_str != '' || return_type_hint != '' |
1397 | 1401 | break |
1398 | 1402 | endif |
1399 | 1403 | endfor |
1400 | | - if doc_str != '' |
| 1404 | + if doc_str != '' || return_type_hint != '' |
1401 | 1405 | let docblock = phpcomplete#ParseDocBlock(doc_str) |
1402 | | - if has_key(docblock.return, 'type') || has_key(docblock.var, 'type') || len(docblock.properties) > 0 |
1403 | | - let type = has_key(docblock.return, 'type') ? docblock.return.type : has_key(docblock.var, 'type') ? docblock.var.type : '' |
1404 | | - |
1405 | | - if type == '' |
1406 | | - for property in docblock.properties |
1407 | | - if property.description =~? method |
1408 | | - let type = property.type |
1409 | | - break |
1410 | | - endif |
1411 | | - endfor |
1412 | | - endif |
| 1406 | + if has_key(docblock.return, 'type') || has_key(docblock.var, 'type') || len(docblock.properties) > 0 || return_type_hint != '' |
| 1407 | + if return_type_hint == '' |
| 1408 | + let type = has_key(docblock.return, 'type') ? docblock.return.type : has_key(docblock.var, 'type') ? docblock.var.type : '' |
| 1409 | + |
| 1410 | + if type == '' |
| 1411 | + for property in docblock.properties |
| 1412 | + if property.description =~? method |
| 1413 | + let type = property.type |
| 1414 | + break |
| 1415 | + endif |
| 1416 | + endfor |
| 1417 | + endif |
| 1418 | + else |
| 1419 | + let type = return_type_hint |
| 1420 | + end |
1413 | 1421 |
|
1414 | 1422 | " there's a namespace in the type, threat the type as FQCN |
1415 | 1423 | if type =~ '\\' |
@@ -1483,7 +1491,7 @@ function! phpcomplete#GetMethodStack(line) " {{{ |
1483 | 1491 | continue |
1484 | 1492 | endif |
1485 | 1493 |
|
1486 | | - " if it's looks like a string |
| 1494 | + " if it looks like a string |
1487 | 1495 | if current_char == "'" || current_char == '"' |
1488 | 1496 | " and it is not escaped |
1489 | 1497 | if prev_char != '\' || (prev_char == '\' && prev_prev_char == '\') |
@@ -1587,9 +1595,11 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor |
1587 | 1595 | elseif function_file != '' && filereadable(function_file) |
1588 | 1596 | let file_lines = readfile(function_file) |
1589 | 1597 | let docblock_str = phpcomplete#GetDocBlock(file_lines, 'function\s*&\?\<'.function_name.'\>') |
| 1598 | + let return_type_hint = phpcomplete#GetFunctionReturnTypeHint(file_lines, 'function\s*&\?'.function_name.'\>') |
1590 | 1599 | let docblock = phpcomplete#ParseDocBlock(docblock_str) |
1591 | | - if has_key(docblock.return, 'type') |
1592 | | - let classname_candidate = docblock.return.type |
| 1600 | + let type = has_key(docblock.return, 'type') ? docblock.return.type : return_type_hint |
| 1601 | + if type != '' |
| 1602 | + let classname_candidate = type |
1593 | 1603 | let [class_candidate_namespace, function_imports] = phpcomplete#GetCurrentNameSpace(file_lines) |
1594 | 1604 | " try to expand the classname of the returned type with the context got from the function's source file |
1595 | 1605 |
|
@@ -1821,9 +1831,11 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor |
1821 | 1831 | elseif function_file != '' && filereadable(function_file) |
1822 | 1832 | let file_lines = readfile(function_file) |
1823 | 1833 | let docblock_str = phpcomplete#GetDocBlock(file_lines, 'function\s*&\?\<'.function_name.'\>') |
| 1834 | + let return_type_hint = phpcomplete#GetFunctionReturnTypeHint(file_lines, 'function\s*&\?'.function_name.'\>') |
1824 | 1835 | let docblock = phpcomplete#ParseDocBlock(docblock_str) |
1825 | | - if has_key(docblock.return, 'type') |
1826 | | - let classname_candidate = docblock.return.type |
| 1836 | + let type = has_key(docblock.return, 'type') ? docblock.return.type : return_type_hint |
| 1837 | + if type != '' |
| 1838 | + let classname_candidate = type |
1827 | 1839 | let [class_candidate_namespace, function_imports] = phpcomplete#GetCurrentNameSpace(file_lines) |
1828 | 1840 | " try to expand the classname of the returned type with the context got from the function's source file |
1829 | 1841 | let [classname_candidate, class_candidate_namespace] = phpcomplete#ExpandClassName(classname_candidate, class_candidate_namespace, function_imports) |
@@ -2413,6 +2425,44 @@ function! phpcomplete#ParseDocBlock(docblock) " {{{ |
2413 | 2425 | endfunction |
2414 | 2426 | " }}} |
2415 | 2427 |
|
| 2428 | +function! phpcomplete#GetFunctionReturnTypeHint(sccontent, search) |
| 2429 | + let i = 0 |
| 2430 | + let l = 0 |
| 2431 | + let function_line_start = -1 |
| 2432 | + let function_line_end = -1 |
| 2433 | + let sccontent_len = len(a:sccontent) |
| 2434 | + let return_type = '' |
| 2435 | + |
| 2436 | + while (i < sccontent_len) |
| 2437 | + let line = a:sccontent[i] |
| 2438 | + " search for a function declaration |
| 2439 | + if line =~? a:search |
| 2440 | + let l = i |
| 2441 | + let function_line_start = i |
| 2442 | + " now search for the first { where the function body starts |
| 2443 | + while l < sccontent_len |
| 2444 | + let line = a:sccontent[l] |
| 2445 | + if line =~? '\V{' |
| 2446 | + let function_line_end = l |
| 2447 | + break |
| 2448 | + endif |
| 2449 | + let l += 1 |
| 2450 | + endwhile |
| 2451 | + break |
| 2452 | + endif |
| 2453 | + let i += 1 |
| 2454 | + endwhile |
| 2455 | + |
| 2456 | + " now grab the lines that holds the function declaration line |
| 2457 | + if function_line_start != -1 && function_line_end != -1 |
| 2458 | + let function_line = join(a:sccontent[function_line_start :function_line_end], " ") |
| 2459 | + let class_name_pattern = '[a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*' |
| 2460 | + let return_type = matchstr(function_line, '\c\s*:\s*\zs'.class_name_pattern.'\ze\s*{') |
| 2461 | + endif |
| 2462 | + return return_type |
| 2463 | + |
| 2464 | +endfunction |
| 2465 | + |
2416 | 2466 | function! phpcomplete#GetTypeFromDocBlockParam(docblock_type) " {{{ |
2417 | 2467 | if a:docblock_type !~ '|' |
2418 | 2468 | return a:docblock_type |
@@ -2572,7 +2622,7 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{ |
2572 | 2622 | " find kind flags from tags or built in methods for the objects we extracted |
2573 | 2623 | " they can be either classes, interfaces or namespaces, no other thing is importable in php |
2574 | 2624 | for [key, import] in items(imports) |
2575 | | - " if theres a \ in the name we have it's definetly not a built in thing, look for tags |
| 2625 | + " if theres a \ in the name we have it's definitely not a built in thing, look for tags |
2576 | 2626 | if import.name =~ '\\' |
2577 | 2627 | let patched_ctags_detected = 0 |
2578 | 2628 | let [classname, namespace_for_classes] = phpcomplete#ExpandClassName(import.name, '\', {}) |
|
0 commit comments