PHP-Namespace-Resolver icon indicating copy to clipboard operation
PHP-Namespace-Resolver copied to clipboard

Namespace incorrect with more than one autoload folder

Open JoeCianflone opened this issue 5 years ago • 5 comments

This was working fine prior to the last VSCode update.

I have two autoload-folders:

        "psr-4": {
            "App\\": "app/",
            "Domain\\": "src/"
        },

Namespace had no issue figuring out what folder I was in and using the right namespace, but now, it only takes whatever the first in the list is. So if I'm working in src/foo/bar the namespace should be Domain\Foo\Bar what I actually get is App\src\Foo\Bar

And to confirm, I changed the order of my psr-4 json there and if I change the order still gets it wrong, just now with the other name first.

Maybe I messed something up? I did run composer du too hoping that would help pick things up, but something seems to be amiss. Let me know if you need other information.

JoeCianflone avatar Jun 24 '19 18:06 JoeCianflone

Ok so on the off chance that this was something weird with my set up I created a totally new laravel project, I created one project with Laravel 5.8 and one with Laravel 5.9 I created a top-level src folder and I wanted to map that to Domain and I couldn't get the Namespace to be picked up. I did a composer du and I even disabled any plugin that worked with PHP in VSCode and it still got the Namespace incorrect. I've attached an image. Let me know if you need anything else. Screen Shot 2019-06-27 at 4 11 19 PM

JoeCianflone avatar Jun 27 '19 20:06 JoeCianflone

I'm having the same issue on a Laravel 8 project. The namespace of a class located in database/seeders resolves to App.

"autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },

ksidibe avatar Jan 05 '21 21:01 ksidibe

Same, I don't know why but this happens. It does not happen in any other Laravel project but this single one and I don't know why

neoighodaro avatar Jul 29 '21 07:07 neoighodaro

I just had the same issue. It always uses the first namespace in the autoload list in my composer file, no matter what root folder I generate the namespace in.

Is there any action or response on this? We're coming up on 3 years since it was first reported.

Note:
I just saw that the last commit in this repo was 3 years ago so I guess we can consider this plugin dead.

magnus-eriksson avatar Apr 11 '22 21:04 magnus-eriksson

@magnus-eriksson thanks for the recent response to this I ran into this issue again just the other day and I'd totally forgotten that it's a thing. My only stupid work-around was to NOT have a secondary namespace or to import my code as a package and then it works.

I was considering just forking this repo and fixing it myself but someone else has already gone through the trouble: https://github.com/ctf0/PHP-Namespace-Resolver (in the VSC marketplace: https://marketplace.visualstudio.com/items?itemName=ctf0.php-namespace-resolver) I am not affiliated with this, nor am I vouching for it, but I'm tired of this issue and I'm going to install this into my VSCode and see how it works. I suggest that anyone coming here do the same.

JoeCianflone avatar Apr 19 '22 15:04 JoeCianflone