bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.61k stars 94 forks source link

Rename breaks if directory does not have a slash at the end in the "autoload" setting #2797

Closed rejmann closed 3 months ago

rejmann commented 7 months ago

If we have a class with its namespace "Intelephense\VsCode\Rename\Test" than its respective directory "src/Intelephense/VsCode/Rename/Test" and when renaming it to a new namespace called "Intelephense\VsCode\Rename\Test\NewNamespace" a new directory is being created with the first backslash "src/IntelephenseVsCode/Rename/Test/NewNamespace" escaping, meaning Intelephense and VsCode are concatenated.

To reproduce, simply rename a namespace in your project and look at its first directory.

A new directory must not be created by concatenating the beginning of the namespaces

v1.10.2 (premium) Windows 11 + WSL Ubuntu 22.04 LTS e Pop!_OS 22.04 LTS

bmewburn commented 7 months ago

I'm unable to reproduce the error using the steps provided. Is there any further info you can provide to help debug this? Screenshot from 2024-03-06 14-17-35

rejmann commented 5 months ago

Sorry for the delay @bmewburn, I ended up not seeing the notification of this issue!

Below is a quick video demonstrating the bug found, it is worth noting that the new directory is created as stated and the old one is left without the created class.

Hugs.

Gravação de tela de 2024-04-10 16-17-18.webm

bmewburn commented 5 months ago

Thanks @rejmann , can you also post the autoload section of your composer.json for this example if there is one?

rejmann commented 5 months ago

For sure @bmewburn! I only ran composer init and nothing else.

{
    "name": "php/test",
    "description": "test intelephense",
    "autoload": {
        "psr-4": {
            "Php\\Test\\": "src/"
        }
    },
    "authors": [
        {
            "name": "rejman"
        }
    ],
    "require": {}
}
victordev13 commented 4 months ago

Some update here?

bmewburn commented 4 months ago

I still cant reproduce the original issue of incorrect directories being created. To me this seems more like a feature request to delete empty directories after a rename.

rejmann commented 4 months ago

Oops @bmewburn , I ended up noticing that there really wasn't a problem in the video. My apologies!

But we identified that, if composer.json has a namespace without the slash at the end of the directory:

Slash added at the end of "src"

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

It concatenates App with the first subdirectory creating a namespace App\SubdirectoryName...

Perhaps making a regex to consider the slash at the end if it is not specified should help resolve the bug.

victordev13 commented 3 months ago

yep