Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete another file namespace class function. #78

Closed
bstaint opened this issue Oct 24, 2015 · 5 comments
Closed

complete another file namespace class function. #78

bstaint opened this issue Oct 24, 2015 · 5 comments

Comments

@bstaint
Copy link

bstaint commented Oct 24, 2015

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 classname

output:
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]
                else
@complex857
Copy link
Collaborator

Thank 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?

@bstaint
Copy link
Author

bstaint commented Oct 25, 2015

Yeah. I generate tags file and set g:phpcomplete_search_tags_for_variables is 1.

@complex857
Copy link
Collaborator

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 \.

@complex857
Copy link
Collaborator

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.

@bstaint
Copy link
Author

bstaint commented Oct 25, 2015

It's worked, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants