Closed jrfoell closed 7 years ago
@jrfoell I just pushed some code on the development branch.
Can you check whether this issue persists in the development version as there are significant changes on how things are handled under the hood.
Thanks @ikappas - yes this seems to only lint active (open) files... much better!
I just pushed some major new features in develop
branch that need testing and include:
Your feedback is very welcome!
Hmmmm... phpcs is again linting every file in my project. This becomes problematic with 3rd party libraries that don't conform to the select code standard. Is there a way to specify to only lint files that are currently open in the editor?
@jrfoell you can set phpcs.ignorePatterns setting with glob patterns like so:
"phpcs.ignorePatterns": [
"*/ignored-file.php",
"*/ignored-dir/**"
]
@jrfoell can you please set "phpcs.trace.server": "messages"
setting and post back the output from Output > PHP Code Sniffer
Thanks, I added that and opened up a new folder which was cloned from https://github.com/WebDevStudios/custom-post-type-ui/
I first opened up custom-post-type-ui.php
(top two lines in Output). Then I switched to a stale branch (354-admin-ui-enhancements) which had a lot of changes.
My original report was me hoping for an option that would only lint files that are currently open - which is default behavior in PHPStorm. Actually to check all project files in a project in PHPStorm you have to enable "Batch Mode" which I think makes more sense for an application https://confluence.jetbrains.com/display/PhpStorm/PHP+Code+Sniffer+in+PhpStorm
This output would have been much larger had I chosen a bigger project:
linting started on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
linting completed on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
linting started on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/import_export.php
linting started on: file:///home/justin/src/custom-post-type-ui/classes/class.cptui_admin_ui.php
linting started on: file:///home/justin/src/custom-post-type-ui/classes/class.cptui_debug_info.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/about.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/listings.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/taxonomies.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/support.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/utility.php
linting started on: file:///home/justin/src/custom-post-type-ui/tests/CPTUI-Admin-UI-Inputs-Test.php
linting started on: file:///home/justin/src/custom-post-type-ui/tests/CPTUI-Utilities-Test.php
linting started on: file:///home/justin/src/custom-post-type-ui/tests/bootstrap.php
linting started on: file:///home/justin/src/custom-post-type-ui/inc/post-types.php
linting completed on: file:///home/justin/src/custom-post-type-ui/tests/bootstrap.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/about.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/utility.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/listings.php
linting completed on: file:///home/justin/src/custom-post-type-ui/classes/class.cptui_debug_info.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/support.php
linting completed on: file:///home/justin/src/custom-post-type-ui/tests/CPTUI-Admin-UI-Inputs-Test.php
linting completed on: file:///home/justin/src/custom-post-type-ui/tests/CPTUI-Utilities-Test.php
linting completed on: file:///home/justin/src/custom-post-type-ui/classes/class.cptui_admin_ui.php
linting completed on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/import_export.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/taxonomies.php
linting completed on: file:///home/justin/src/custom-post-type-ui/inc/post-types.php
@jrfoell Thank you for the detailed report. I can't reproduce your issue using the specified repository and the steps you took. My output while changing between the two branched multiple times is:
[Trace - 8:46:26 PM] Sending request 'initialize - (0)'.
[Trace - 8:46:26 PM] Received response 'initialize - (0)' in 91ms.
[Trace - 8:46:26 PM] Sending notification 'initialized'.
[Trace - 8:46:26 PM] Sending notification 'workspace/didChangeConfiguration'.
[Trace - 8:46:26 PM] Sending notification 'textDocument/didOpen'.
[Trace - 8:46:26 PM] Received notification 'textDocument/didStartValidate'.
[Trace - 8:46:26 PM] Linting started on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:46:26 PM] Received notification 'textDocument/didEndValidate'.
[Trace - 8:46:26 PM] Linting completed on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:46:26 PM] Received notification 'textDocument/publishDiagnostics'.
[Trace - 8:46:59 PM] Sending notification 'textDocument/didChange'.
[Trace - 8:46:59 PM] Received notification 'textDocument/didStartValidate'.
[Trace - 8:46:59 PM] Linting started on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:46:59 PM] Received notification 'textDocument/didEndValidate'.
[Trace - 8:46:59 PM] Linting completed on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:46:59 PM] Received notification 'textDocument/publishDiagnostics'.
[Trace - 8:47:10 PM] Sending notification 'textDocument/didChange'.
[Trace - 8:47:10 PM] Received notification 'textDocument/didStartValidate'.
[Trace - 8:47:10 PM] Linting started on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:47:10 PM] Received notification 'textDocument/didEndValidate'.
[Trace - 8:47:10 PM] Linting completed on: file:///Users/ikappas/Desktop/custom-postype-ui/custom-post-type-ui.php
[Trace - 8:47:10 PM] Received notification 'textDocument/publishDiagnostics'.
@jrfoell Which version of vscode-phpcs are you using?
Currently PHP_CodeSniffer version 3.1.0.
I'm going to run a couple more tests because I'm seeing inconsistent results. On one run I got the error:
phpcs: A composer configuration file was found at the root of your project but seems uninitialized. You may need to initialize your dependencies using "composer install".
Which doesn't seem like it should be related to phpcs.
I disabled all of my extensions except phpcs. Using vscode 1.17.2. On the latest development commit ea9fc05 here's what I do and what I get.
Launch vscode
Open vscode-phpcs folder
Go to debug pane, select Client+Server
and click play.
In child window get (expected) warning:
[/home/justin/src/vscode-phpcs/phpcs]: Overwriting extension /home/justin/.vscode/extensions/ikappas.phpcs-0.7.0 with /home/justin/src/vscode-phpcs/phpcs.
In parent window get (unexpected) error:
Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:6199).
In child window:
Open custom-post-type-ui.php
Get (unexpected) error:
phpcs: A composer configuration file was found at the root of your project but seems uninitialized. You may need to initialize your dependencies using "composer install".
Notice phpcs has not yet linted the file that I've opened. switch branches now phpcs will have linted the file
Full trace:
[Trace - 3:23:24 PM] Sending request 'initialize - (0)'.
Debugger listening on port 6199.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:6199/70a83cdd-9bec-4d51-98a3-d91adef92893
[Trace - 3:23:24 PM] Received response 'initialize - (0)' in 189ms.
[Trace - 3:23:24 PM] Sending notification 'initialized'.
[Trace - 3:23:24 PM] Sending notification 'workspace/didChangeConfiguration'.
[Trace - 3:23:24 PM] Sending notification 'textDocument/didOpen'.
[Trace - 3:23:24 PM] Received request 'window/showMessageRequest - (0)'.
[Trace - 3:23:24 PM] Received request 'window/showMessageRequest - (1)'.
[Trace - 3:23:24 PM] Received request 'window/showMessageRequest - (2)'.
[Trace - 3:24:56 PM] Sending notification 'textDocument/didChange'.
[Trace - 3:24:56 PM] Received notification 'textDocument/didStartValidate'.
[Trace - 3:24:57 PM] Linting started on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
[Trace - 3:24:57 PM] Received notification 'textDocument/didEndValidate'.
[Trace - 3:24:57 PM] Linting completed on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
[Trace - 3:24:57 PM] Received notification 'textDocument/publishDiagnostics'.
[Trace - 3:24:57 PM] Received notification 'textDocument/didStartValidate'.
[Trace - 3:24:57 PM] Linting started on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
[Trace - 3:24:57 PM] Received notification 'textDocument/didEndValidate'.
[Trace - 3:24:57 PM] Linting completed on: file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php
[Trace - 3:24:57 PM] Received notification 'textDocument/publishDiagnostics'.
Strangely, the issue with phpcs not linting my file right when I open it is inconsistent :(
@jrfoell I run into this issues while testing. Let me explain:
Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:6199).
This is expected if a php file is not open when vscode launches the server is not ready and the server debug process times out. It is mentioned as a note at the bottom of README.md
phpcs: A composer configuration file was found at the root of your project but seems uninitialized. You may need to initialize your dependencies using "composer install".
This happens on the 354-admin-ui-enhancements
branch because it does not have a composer.lock file. If you launch vscode on master
you wouldn't get this error.
I understand your point on inconsistency but I am unsure on what the best way is to handle this. The extension has two path resolvers that come into play when phpcs.executablePath
is not set. The first one looks for a composer.json then a composer.lock which it parses for PHP_CodeSniffer dependency. The whole parsing is necessary because it is possible to change both vendor and bin paths in composer.json and it is not enough to check against a /vendor/bin/phpcs
. Now take into account that some users need to have composer.json reside in a subfolder and things get messier. If the composer resolver fails to locate the vendored phpcs it checks the global paths to check if phpcs is available. If that fails too then you get the Unable to locate phpcs...
error
The trace shows that only file:///home/justin/src/custom-post-type-ui/custom-post-type-ui.php was linted while switching branches
@jrfoell btw if you set the phpcs.executablePath
the experience is consistent.
Thanks @ikappas your explanation of those errors helps :+1: Sorry that I missed the one from the development readme.
That makes sense about the composer inclusion. I added "phpcs.executablePath": "/usr/bin/phpcs"
to my configuration and things are now working as expected :100:
@jrfoell I will probably remove the A composer configuration file was found...
error altogether so that the resolver fails silently.
I would keep the composer error message - it makes sense now that you've explained it and will make sense to those using a specific phpcs version as a dependency in their project's composer file.
BTW - you should add this option to the extension documentation that is seen through vscode :)
phpcs.executablePath
You could add some additional information there about how the composer resolution is performed if it's not set and if any composer.json files are located.
@jrfoell the documentation will be updated on vscode extension marketplace when the 1.0.0 final is published. Meanwhile the you can check phpcs/README.md
Closing this as resolved.
This is a duplicate of #19 which is currently closed.
This happens to me all the time when I'm switching between two branches in git that have a significant amount of files added/changed. It seems like vscode spawns an instance of phpcs for every file changed or added. The result is an insane load while they run - to the point where it seems like my computer has locked.
Not sure if there's a setting in vscode to limit the number of phpcs instances it will run?