coc-diagnostic icon indicating copy to clipboard operation
coc-diagnostic copied to clipboard

Cannot make PHP-CS-Fixer work.

Open xbot opened this issue 4 years ago • 3 comments

The following command works under my project root:

./vendor/bin/php-cs-fixer fix --ansi

But nothing happened after executing :call CocAction('format').

The related settings in coc-settings.json are:

    "diagnostic-languageserver.filetypes": {
        "php": ["phpcs", "phpstan"]
    },
    "diagnostic-languageserver.formatters": {
        "php-cs-fixer": {
            "command": "./vendor/bin/php-cs-fixer",
            "args": ["fix", "--ansi"]
        }
    },
    "diagnostic-languageserver.formatFiletypes": {
        "php": ["php-cs-fixer"],
        "python": ["black"]
    },

xbot avatar Jun 28 '21 07:06 xbot

Maybe you should setting rootPatterns option.

iamcco avatar Jul 23 '21 03:07 iamcco

By default linters and formatters take the stdout output but php-cs-fixer does not print the results in stdout then it does not work.

To make it work you have to deactivate the isStdout option and activate the doesWriteToFile option

This is my configuration for php-cs-fixer

"php-cs-fixer": {
    command: "./vendor/bin/php-cs-fixer",
    args: ["fix", "--using-cache=no", "--no-interaction", "%file"],
    isStdout: false,
    doesWriteToFile: true,
}

The %file arg is the full path of the current file, this is used when doesWriteTofile is set to true

dsolay avatar Jul 24 '21 16:07 dsolay

@iamcco @dsolay Still not working. The settings now are:

    "diagnostic-languageserver.filetypes": {
        "php": ["phpstan"]
    },
    "diagnostic-languageserver.formatters": {
        "php-cs-fixer": {
            "command": "./vendor/bin/php-cs-fixer",
            "args": ["fix", "--ansi", "%file"],
            "rootPatterns": [".git"],
            "isStdout": false,
            "doesWriteToFile": true
        }
    },
    "diagnostic-languageserver.formatFiletypes": {
        "php": ["php-cs-fixer"],
        "python": ["black"]
    },

xbot avatar Jul 27 '21 03:07 xbot