iamcco / coc-diagnostic

diagnostic-languageserver extension for coc.nvim
245 stars 22 forks source link

Cannot make PHP-CS-Fixer work. #104

Closed xbot closed 1 year ago

xbot commented 3 years ago

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"]
    },
iamcco commented 3 years ago

Maybe you should setting rootPatterns option.

dsolay commented 3 years ago

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

xbot commented 3 years ago

@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"]
    },