vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Renaming the namespace creates an incorrect directory.

Open rejmann opened this issue 1 year ago • 4 comments

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

rejmann avatar Feb 15 '24 11:02 rejmann

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

bmewburn avatar Mar 06 '24 03:03 bmewburn

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

rejmann avatar Apr 10 '24 19:04 rejmann

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

bmewburn avatar Apr 10 '24 22:04 bmewburn

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": {}
}

rejmann avatar Apr 10 '24 23:04 rejmann

Some update here?

victordev13 avatar May 28 '24 12:05 victordev13

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.

bmewburn avatar May 31 '24 04:05 bmewburn

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.

rejmann avatar Jun 03 '24 13:06 rejmann

yep

victordev13 avatar Jun 07 '24 19:06 victordev13