Comments (17)
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.
I have confirmed that phpcbf
works correctly in my environment with coc-diagnostic "v0.20.0". (add "ignoreExitCode": [1]
)
from coc-diagnostic.
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.
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.
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.
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:
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.
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.
from coc-diagnostic.
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.
seems like phpcbf
just modify the file instead of output the format file to stdout.
from coc-diagnostic.
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.
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.
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.
I found doesWriteToFile under 'formatters field' at https://github.com/iamcco/diagnostic-languageserver
ohhhhhhh my fault.
from coc-diagnostic.
@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 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.
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.
@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.
Confirmed working here, as well. Thanks!
from coc-diagnostic.
Related Issues (20)
- Lint errors should be removed on file write HOT 1
- How to enable _all_ supported filetypes? HOT 1
- Cannot make PHP-CS-Fixer work. HOT 3
- Could you support messageDelay about virtualtext? HOT 1
- Some linters do not mark any columns
- 警告信息全都高亮 HOT 1
- [sh] diagnostic handle fail: [shellcheck] Unexpected end of JSON input HOT 3
- [question] how to make default security be warning not error HOT 1
- Question: How to Set languageserver Options ? HOT 1
- Wrong working directory (phpcs) HOT 1
- [advice] how about use json to restore config.ts? HOT 2
- alex configuration not working HOT 2
- Floating error message not displaying with source code that uses tabs instead of spaces HOT 1
- golang 1.21 built-in function max and min cannot be recognized HOT 1
- Format on save HOT 5
- When multiple PHPStan and PHP_CodeSniffer errors are on the same line, they are not all displayed HOT 9
- High cpu usage with pylint HOT 2
- 请问可以设置linter的来源吗,我想要用flake8来检查,但是却无法去掉pyright HOT 2
- Adapting the color scheme for severity levels? HOT 1
- Diagnostic language service not running automatically HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coc-diagnostic.