Peekmo / atom-autocomplete-php

Autocomplete for PHP in atom editor
MIT License
136 stars 34 forks source link

atom-autocomplete-php:namespace command does not work #213

Closed umpirsky closed 8 years ago

umpirsky commented 8 years ago

I used import_namespace in sublime, and I really miss it.

It would be nice if we can add this feature.

Peekmo commented 8 years ago

Hello,

The feature already exists, you can press "ctrl - alt - n" or use command "atom autocomplete php : namespace"

Note : it only works if you are in a composer project.

umpirsky commented 8 years ago

@Peekmo Thanks for the quick response, really appreciate it!

I tried both, keyboard shortcut and command in several projects. In one it failed with https://github.com/Peekmo/atom-autocomplete-php/issues/23, but that's ok since composer.json is not in the root dir. But for others just nothing happens.

I would be happy to debug if you instruct me what I can do to provide more information.

Peekmo commented 8 years ago

Can you copy/past your "autoload" sectin of your composer.json and the location of your php files in your project pls ?

umpirsky commented 8 years ago

@Peekmo Let's test it on https://github.com/sylius/sylius/ project as an example. I just did - didn't work.

I opened app/AppKernel.php and typed:

$product = new Product();

Positioned cursor on Product and pressed ctrl-alt-n. Nothing changed.

Autoload is in https://github.com/Sylius/Sylius/blob/master/composer.json#L191-L193.

Thanks.

umpirsky commented 8 years ago

@Peekmo Any news on this?

Peekmo commented 8 years ago

Everything works well for me with Sylius.

The problem you can have is that it will not work in app/AppKernel.php ('cause app/ folder is not in composer's autoloader). But every file in "src" folder should work.

umpirsky commented 8 years ago

@Peekmo OK, I tried it and it did't work as I expected, see https://github.com/umpirsky/Sylius/commit/faaa271a2a0d05e1640069a4e98a406ae230ffb1:

Thanks.

Peekmo commented 8 years ago

Sorry, but everything is ok with your example :

Peekmo commented 8 years ago

As a side note, Sylius components have a different composer.json for each bundle (see https://github.com/umpirsky/Sylius/blob/master/src/Sylius/Bundle/AddressingBundle/composer.json) that's why their namespace doesn't have a "Sylius\" prefix.

The plugin only look at a composer.json to the root directory of the project.

I think that it's an Sylius issue if their root composer.json autoload section does not match the bundle's namespaces.

umpirsky commented 8 years ago

@Peekmo Ah, true, you are right.

But I must disagree that it is a Sylius issue, this is perfectly valid and common in many projects that split across components, like Symfony for example.

However, it is noted in README that it will work only with composer.json in root, so ok.

But, I guess it is not hard to find first composer.json by going up to directory tree, right? And it would do the job. Maybe I will submit PR when I get some time.

Thanks.

Peekmo commented 8 years ago

No, there is a Sylius issue because the autoloader section of the root composer is not right with component's autoloaders.

Of course, component specific autoloaders is not an issue, but in this case, namespaces from different composers MUST match.

In Symfony2, it matches so there's no issue (https://github.com/symfony/symfony/blob/master/composer.json#L91).

umpirsky commented 8 years ago

@Peekmo How do you explain auto loader working then if it is a Sylius issue. All classes are autoloaded without any problem. I work on this project for several years and autoloader always worked. So I think it is not a Sylius issue. :)

Peekmo commented 8 years ago

It works because of composer.json in each folders. It doesn't break the code, but the autoload from root composer.json is inconsistent, that's all ^^