Giter Site home page Giter Site logo

Comments (17)

iamcco avatar iamcco commented on July 20, 2024 3

I add ignoreExitCode options support for formatter. it can be true ignore all exit code > 0 or number[] for exit codes you want to ignore. and below config works for me.

  "diagnostic-languageserver.formatters": {
    "phpcbf": {
      "command": "phpcbf",
      "rootPatterns": ["composer.lock", "vendor", ".git"],
      "args": [],
      "isStdout": true,
      "isStderr": false,
      "doesWriteToFile": false,
      "ignoreExitCode": [1]
    }
  },

from coc-diagnostic.

yaegassy avatar yaegassy commented on July 20, 2024 3

I have confirmed that phpcbf works correctly in my environment with coc-diagnostic "v0.20.0". (add "ignoreExitCode": [1])

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024 1

https://github.com/iamcco/diagnostic-languageserver/blob/master/src/handles/handleFormat.ts#L50

seems like I know what happen. need to fix it.

from coc-diagnostic.

yaegassy avatar yaegassy commented on July 20, 2024 1

I changed the diagnostic-languageserver to verify this.

phpcbf seems to return 1 for "code". :(

$ cat sample.php | phpcbf
<?php

declare(strict_types=1);

function dummy()
{
    return "dummy";
}
$ echo $?
1

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024

I do not use phpcbf so I don't know how to do that. Maybe you can add args or something to tell phpcbf to use your local configuration.

from coc-diagnostic.

marioy47 avatar marioy47 commented on July 20, 2024

I think I made some progress, but still no solution.

I added "intelephense.format.enable": false, to coc-settings.json and changed the phpcbf formater config to

  "diagnostic-languageserver.formatters": {
    "phpcbf": {
      "command": "./vendor/bin/phpcbf",
      "rootPatterns": ["composer.json", "composer.lock", "vendor", ".git"],
      "args": ["%file"],
      "isStdout": false,
      "doesWriteToFile": true
    }
  }

And now the files get formated but no loaded in the buffer.

The breaktrough is that I get the following error:
vim-error

So it looks like the phpcbf fixer is takes longer that normal.

is there a way to increment the timeout so I can verify this?

from coc-diagnostic.

mkindred avatar mkindred commented on July 20, 2024

I'm having the same issue. phpcs works great, and phpcbf is making the corrections, but the saved file isn't loaded to the buffer.

210524_coc_phpcbf_issues

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024

I'm having the same issue. phpcs works great, and phpcbf is making the corrections, but the saved file isn't loaded to the buffer.

210524_coc_phpcbf_issues

seems like phpcbf just modify the file instead of output the format file to stdout.

from coc-diagnostic.

mkindred avatar mkindred commented on July 20, 2024

I've tried several combinations of isStdout and doesWriteToFile, and I can't quite get there. Here is my coc-settings.json file:

{
  "coc.preferences.formatOnSaveFiletypes": [
    "javascript",
    "javascriptreact",
    "javascriptreact.html",
    "html",
    "json",
    "php",
    "yaml"
  ],
  "intelephense.format.enable": false,
  "diagnostic-languageserver.filetypes": {
    "php": "phpcs"
  },
  "diagnostic-languageserver.linters": {
    "phpcs": {
      "command": "phpcs",
      "debounce": 300,
      "rootPatterns": ["composer.lock", "vendor", ".git"],
      "args": ["--report=emacs", "-s", "-"],
      "offsetLine": 0,
      "offsetColumn": 0,
      "sourceName": "phpcs",
      "formatLines": 1,
      "formatPattern": [
        "^.*:(\\d+):(\\d+):\\s+(.*)\\s+-\\s+(.*)(\\r|\\n)*$",
        {
          "line": 1,
          "column": 2,
          "message": 4,
          "security": 3
        }
      ],
      "securities": {
        "error": "error",
        "warning": "warning"
      }
    }
  },
  "diagnostic-languageserver.formatFiletypes": {
    "php": "phpcbf"
  },
  "diagnostic-languageserver.formatters": {
    "phpcbf": {
      "command": "phpcbf",
      "rootPatterns": ["composer.lock", "vendor", ".git"],
      "args": ["--standard=./phpcs.xml", "%file"],
      "isStdout": false,
      "isStderr": false,
      "doesWriteToFile": true
    }
  },
  "git.enableGutters": false,
  "prettier.singleQuote": true
}

With the above, I get the option to re-load the corrected file.

But if I use the following, nothing happens.

  "diagnostic-languageserver.formatFiletypes": {
    "php": "phpcbf"
  },
  "diagnostic-languageserver.formatters": {
    "phpcbf": {
      "command": "phpcbf",
      "rootPatterns": ["composer.lock", "vendor", ".git"],
      "args": ["--standard=./phpcs.xml"],
      "isStdout": true,
      "isStderr": false,
      "doesWriteToFile": false
    }
  },

I confirmed that running phpcbf test.php from the command line does work, and it correctly picks up the appropriate phpcs.xml.

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024

what's doesWriteToFile options? coc-diagnostic doesn't support such option.

you have to make sure phpcbf command does not write change to disk and output format content to stdout or stderr. then set the isStdout or isStderr to true.

from coc-diagnostic.

mkindred avatar mkindred commented on July 20, 2024

I found doesWriteToFile under 'formatters field' at https://github.com/iamcco/diagnostic-languageserver

Yes, I'm trying to learn how to direct phpcbf output to stdout.

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024

I found doesWriteToFile under 'formatters field' at https://github.com/iamcco/diagnostic-languageserver

ohhhhhhh my fault.

from coc-diagnostic.

yaegassy avatar yaegassy commented on July 20, 2024

@iamcco Is it possible to pass stdin in diagnostic-langserver's "formatter"?

If you can pass it as stdin, this problem may be solved.

$ cat sample.php
<?php

declare(strict_types=1);

function dummy() {
    return "dummy";
}
$ cat sample.php | phpcbf
<?php

declare(strict_types=1);

function dummy()
{
    return "dummy";
}

from coc-diagnostic.

iamcco avatar iamcco commented on July 20, 2024

@iamcco Is it possible to pass stdin in diagnostic-langserver's "formatter"?

If you can pass it as stdin, this problem may be solved.

$ cat sample.php
<?php

declare(strict_types=1);

function dummy() {
    return "dummy";
}
$ cat sample.php | phpcbf
<?php

declare(strict_types=1);

function dummy()
{
    return "dummy";
}

Yep, by default it use the stdin.

so it maybe works change the %file to %filepath:

"diagnostic-languageserver.formatters": {
    "phpcbf": {
      "command": "phpcbf",
      "rootPatterns": ["composer.lock", "vendor", ".git"],
      "args": ["--standard=./phpcs.xml", "%filepath"],
      "isStdout": true,
      "isStderr": false,
      "doesWriteToFile": false
    }
  },

PS. it will not use stdin when use %file, it's note in the README of https://github.com/iamcco/diagnostic-languageserver#args-additional-syntax

from coc-diagnostic.

yaegassy avatar yaegassy commented on July 20, 2024

I used %filepath and ran it in the same file as this comment. #38 (comment)

Unfortunately, there seems to be no change in "newText" :(

linter run args: ["/Users/yaegassy/_Dev/php/slim4php8/sample.php"]
[Trace - 17:09:43] Received response 'textDocument/formatting - (4)' in 81ms.
Result: [
    {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 9,
                "character": 0
            }
        },
        "newText": "<?php\n\ndeclare(strict_types=1);\n\nfunction dummy() {\n    return \"dummy\";\n}\n"
    }
]

from coc-diagnostic.

yaegassy avatar yaegassy commented on July 20, 2024

@iamcco I tried to skip that control part in diagnostic-languageserver and it was formatted correctly in phpcbf

setting

// ...snip
    "phpcbf": {
      "command": "phpcbf",
      "rootPatterns": ["composer.json", "composer.lock", "vendor", ".git"],
      "isStdout": true,
      "isStderr": false
    }
// ..snip

log(OK)

linter run args: []
[Trace - 18:13:24] Received response 'textDocument/formatting - (3)' in 84ms.
Result: [
    {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 9,
                "character": 0
            }
        },
        "newText": "<?php\n\ndeclare(strict_types=1);\n\nfunction dummy()\n{\n    return \"dummy\";\n}\n"
    }
]

from coc-diagnostic.

mkindred avatar mkindred commented on July 20, 2024

Confirmed working here, as well. Thanks!

from coc-diagnostic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.