complete another file namespace class function.
Closed this issue · 5 comments
classtest.php:
<?php
namespace Test;
class MyClass {
function test() {
echo 'Hello';
}
}1.php
<?php
require_once 'classtest.php';
$app = new Test\MyClass();
// $app = new MyClass();
$app->test();2.php
<?php
$app->I tried complete in 2.php doesn't work.
I put some code in autoload\phpcomplete.php line 165:
if classname =~ '\'
" split the last \ segment as a classname, everything else is the namespace
echom classnameoutput:
Test\\MyClass
execute :echo split('Test\\MyClass', '\')
output:
['Test', '', 'MyClass']
so:
join(classname_parts[0:-2], '\') equal Test\
patch:
diff -urN a/bundle/phpcomplete.vim/autoload/phpcomplete.vim b/bundle/phpcomplete.vim/autoload/phpcomplete.vim
--- a/bundle/phpcomplete.vim/autoload/phpcomplete.vim 2015-07-04 05:02:02.000000000 +0800
+++ b/bundle/phpcomplete.vim/autoload/phpcomplete.vim 2015-10-24 17:01:40.491649900 +0800
@@ -248,7 +248,7 @@
if classname != ''
if classname =~ '\'
" split the last \ segment as a classname, everything else is the namespace
- let classname_parts = split(classname, '\')
+ let classname_parts = split(classname, '\\\{1,\}')
let namespace = join(classname_parts[0:-2], '\')
let classname = classname_parts[-1]
elseThank you for the report! If i understand your explanation correctly the problem seems to be that there's an extra \ separator in the classname variable.
However I'm having trouble reproducing the behaviour. The 2.php file doesn't have anything that the plugin could figure out the class of the $app variable's class from.
If i put the $app = new Test\MyClass(); or a // @var $app Test\MyClass before it then the problem won't manifest. Is this really the full contents of 2.php?
Yeah. I generate tags file and set g:phpcomplete_search_tags_for_variables is 1.
Ah, i see! That's because the info is taken from an ex command and that needs to escape the \ to search it for a literal \.
I've pushed a commit that should resolve the issue, please give it a try.
I've opted to unescape the result at the place it's extracted from a tags file instead of changing the split pattern.
It's worked, thanks.