Closed umpirsky closed 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.
@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.
Can you copy/past your "autoload" sectin of your composer.json and the location of your php files in your project pls ?
@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.
@Peekmo Any news on this?
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.
@Peekmo OK, I tried it and it did't work as I expected, see https://github.com/umpirsky/Sylius/commit/faaa271a2a0d05e1640069a4e98a406ae230ffb1:
Sylius\Sylius\Bundle\AddressingBundle
namespace Sylius\Bundle\AddressingBundle
expected. Thanks.
Sorry, but everything is ok with your example :
"psr-0": { "Sylius\\": "src/" }
so everything under src is on Sylius namespace, then, you have Sylius, Bundle, AdressingBundle folder, so, The namespace is Sylius
(from composer) + Sylius\Bundle\AddressingBundle
(from folders) = Sylius\Sylius\Bundle\AddressingBundle
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.
@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.
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).
@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. :)
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 ^^
I used import_namespace in sublime, and I really miss it.
It would be nice if we can add this feature.