junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code

Home Page:https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using relative paths in config does not work

hoermannklaus opened this issue · comments

I try to use relative paths in the workspace configuration to set the settings for the following two values
"settings": { "php-cs-fixer.executablePath": "./typo3/vendor/bin/php-cs-fixer", "php-cs-fixer.config": ".php_cs" ....
When I use the full path it works. But as this project may be checked out to various folders it is not possible to enter the full path. I also tried to use "${workspaceFolder}" but it does not work.

Any hints why this doesnt work, or how to achieve this?
Thanks

Hi,

You could use the ${workspaceRoot} to get the absolute path to your root project then go into your vendor.

In my case I used : ${workspaceRoot}/vendor/bin/php-cs-fixer

I'm wondering why this is not the recommended way to do it. Because when we are working on multiple projects, the version can be different in every project.

In addition, since I used https://github.com/kubawerlos/php-cs-fixer-custom-fixers I need to be in the context of my project because otherwise ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers()) could not be resolved.

Thanks for your answer. I tried this, and I works. Kind of...

A little bit more about my scenario:
I use a VSC workspace, in which I define the settings for the php-cs-fixer plugin. For the "executablePath" I now use ${workspaceRoot}/typo3/vendor/bin/php-cs-fixer which points to the executable for php-cs-fixer. So far so good. Everything works fine.

My project has a subfolder in the tree which contains a extension, on which I need to work often. Therefore I do not want to navigate the whole tree in order to access the folder. So I added the subfolder "test_ext" into the workspace folders. It looks like that.

{
    "folders": [
        {
            "name": "PROJECT: test",
            "path": "."
        },
        {
            "name": "EXT: test_ext",
            "path": "typo3/public/typo3conf/ext/test_ext/"
        }
       ]
}

Now I can directly jump into this folder from the VSC explorer entry "EXT: test_ext". Great. But now the "php-cs-fixer" does not work anymore for files in the "test_ext" subfolder.

I think there is some mixing up of paths now. But that is just my guess. Or maybe I do not understand how to achieve this, or misuse the feature in a way not ment to.

Thanks

I figured out, that when I use the "folders" section in my workspace file, VSC sees each of these folders as "root" and therefore the paths do not line up anymore. I may stop using the "folders" section in order to use the plugin again.

as you said, it's deprecated, but it can be used.

'''          
const pattern = /^${workspace(Root|Folder)}/;
'''
https://github.com/junstyle/vscode-php-cs-fixer/blob/master/extension.js#L76

workspaceRoot and workspaceFolder are the same value