junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code
https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer
MIT License
355 stars 43 forks source link

Wrong working Path #145

Open marcohald opened 3 years ago

marcohald commented 3 years ago

I use this Plugin in Version v0.1.158 with the integrated php-cs-fixer.phar on Windows with this PHP version:

PHP 8.0.3 (cli) (built: Mar 2 2021 23:34:05) ( ZTS Visual C++ 2019 x64 ) Copyright (c) The PHP Group Zend Engine v4.0.3, Copyright (c) Zend Technologies

I'd like to Fix my code for the Repository https://github.com/nextcloud/server The error i receive is

In .php_cs.dist line 5:

require_once(./lib/composer/autoload.php): Failed to open stream: No such file or directory

So i think this is a issue with the working path or the When i change the Path to an absolute I get this Error:

Fatal error: Uncaught Error: Class "Nextcloud\CodingStandard\Config" not found in C:\Users\user\Documents\GitHub\server.php_cs.dist:9

junstyle commented 3 years ago

Nextcloud\CodingStandard\Config

    "require-dev": {
        "nextcloud/coding-standard": "^0.5.0",
        "vimeo/psalm": "^4.0"
    },

did you have exec composer require-dev

marcohald commented 3 years ago

No I did not :( After running composer install and changig the path in .php_cs.dist to an absolute it is working. With the relative Path the error is still the same

In .php_cs.dist line 5:

require_once(./lib/composer/autoload.php): Failed to open stream: No such file or directory

junstyle commented 3 years ago

require_once(./lib/composer/autoload.php) to absolute path:

require_once(__DIR__ . '/lib/composer/autoload.php')

because php-cs-fixer execute in itself path, the relative path is to php-cs-fixer path.

marcohald commented 3 years ago

This works for me too. Is it probably the better way to pass the workspace path as cwd option to the child_process.spawn ? https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options So there is no need to change it on the nextcloud project. I don't know how other Projects handle this.

junstyle commented 3 years ago

i see what you want to do, you can format your code on your local pc, after format the code, restore the config file: .php_cs.dist and then pull the PR, your code can review successfully.

in this extension, cwd has passed to child_process.spawn yet.

marcohald commented 3 years ago

That would work, but I think maybe other users have the same issue as me, so a code fix would be the best way. Oh okay now i have seen the code for it. I set the "PHP-cs-fixer: Executable Path Windows" to a batch script which basically contains this: echo %cd% The result was the path where the File is stored and not the workspace path. Do you think it is a good idea to change the cwd option to the actual workspace ? I found this https://stackoverflow.com/a/64726585 to get the path of the actual workspace. But I'm not sure whats the best way to handle multiple workspaces.