phpactor
phpactor copied to clipboard
Force running php-cs-fixer in sequential mode
Hello,
PHP-CS-Fixer has recently introduced a way to run in parallel, which boost the performance drastically.
Unfortunately, when enabling this mode, its integration through phpactor crashes.
I've been advised to run php-cs-fixer using the --sequential option, when used through phpactor, because it only asks on a single file anyway.
However I don't see any way to do that with phpactor integration (other than providing a separate config file and configure it through language_server_php_cs_fixer.config) which I'd see as suboptimal, as other developers of my team might not be using phpactor, thus won't need this second config file.
After a quick analysis, Phpactor\Extension\LanguageServerPhpCsFixer\LspCommand\FormatCommand seems to be the best candidate to have this option passed to php-cs-fixer (however, I'm wondering how the version of php-cs-fixer could be detected?).
I can take care of the fix, as soon as the solution feels less blury to me :)
hm, we should ensure that Phpactor only runs cs fixer with a single process, but with a (new) command line flag we also need to detect the version, which isn't trivial at least.
Disabling it with an env var would be safest but not sure if it's possible to disable it:
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/d61006b658e21190f47b67cf89501fdc4c17072c/src/Config.php#L80-L84
maybe @keradus or @Wirone could advise?
@dantleech the code you pointed is only for default config. By default Fixer uses sequential runner, unless "future mode" is enabled or PHP_CS_FIXER_PARALLEL env var is set. If Fixer's config enables parallel runner, then the only way to fallback to sequential mode is using --sequential flag.
I don't know how PHPActor is configured, but instead of detecting Fixer's version I would rather require explicit config flag / env var for PHPActor integration that would enforce usage of --sequential.
FYI: for formatting a single file there would be 2 processes (main process + 1 worker), so not a big deal, but it's sub-optimal to spawn TCP server and additional process for that. Especially that it causes problems in this case 🙂.
It seems like PHP-CS-Fixer/PHP-CS-Fixer#8154 can fix this, as we could fallback to sequential runner automatically if amount of files to analyse is lower or equal to chunk size. This can be considered as generic optimisation, not only for PHPActor 🙂.
config flag / env var for PHPActor integration that would enforce usage of --sequential
yeah, the simple option would be to allow options to be configured (as we do for phpstan and phpcs). I didn't realise sequential was the default, so that makes sense 👍