sandhje / vscode-phpmd

VSCode PHP Mess Detector extension
MIT License
15 stars 4 forks source link

Extension validates Symfony cache files upon clearing cache #31

Closed entepe85 closed 6 years ago

entepe85 commented 6 years ago

When running the built-in Symfony development server and clearing the Symfony cache through the CLI the extension starts validating all cached PHP files thus causing a massive spike in CPU load, rendering my system barely usable. Subsequently PHPMD execution fails because the cached files are cleared.

sandhje commented 6 years ago

Hi Nils, thanks for taking the time to report this. It seems strange to me that the extension would start scanning the files once you clear the cache through the CLI. If you look at "/src/server/Server" you can see that the extension only triggers in the following situations:

I intentionally left out the scanning of an entire folder to keep the extension performant.

Could you maybe turn on the verbose logging of the extension in your vscode settings and post the output of that logging here (found in the "output panel" when you switch the selectbox to "PHP Mess Detector"). That way I might be able to see what is causing the extension to validate those cache files.

entepe85 commented 6 years ago

Hi Sandhjé. Thanks for your feedback. I'll turn on verbose logging and report back.

entepe85 commented 6 years ago

Here's an example of what I've got so far:

[Info - 12:15:47] PHP mess detector command not using global PHP, skipping PHP test [Info - 12:15:47] New document opened, starting validation. [Info - 12:15:47] PHP Mess Detector validation started for file:///Users/butenschoen/Sites/knust/var/cache/de_/Container4p7fhvs/getWebProfiler_Controller_ProfilerService.php

[Info - 12:15:48] PHP Mess Detector test succesful (PHPMD 2.4.3) [Info - 12:15:48] File /Users/butenschoen/Sites/knust/var/cache/de_/Container4p7fhvs/getWebProfiler_Controller_ProfilerService.php test successful [Info - 12:15:48] Running phpmd command (phpmd "/Users/butenschoen/Sites/knust/var/cache/de_/Container4p7fhvs/getWebProfiler_Controller_ProfilerService.php" xml "./ruleset.xml")

[Info - 12:15:51] PHP Mess Detector validation completed for file:///Users/butenschoen/Sites/knust/var/cache/de_/Container4p7fhvs/getWebProfiler_Controller_ProfilerService.php. 0 problems found

Those repeat for all cached files but also for the same file several times. Here's about 40% of the output at Pastebin. Unfortunately I couldn't paste it all there due to size restrictions for non-pro users.

A possible explanation of the duplicate scanning/validation of files could possibly be the cache warming by Symfony.

One more thing which I'd like to add is that even though I explicitly excluded Symfonys cache directory (and some others) through my ruleset.xml they get scanned:

`./var/cache.

.*/vendor.*
<exclude-pattern>.*/tests.*</exclude-pattern>`
entepe85 commented 6 years ago

It just occured to me, being a total layman when it comes to VS Code extensions, that the notification handlers onDidOpenTextDocument and onDidSaveTextDocument might be misfiring when clearing the cache - that is, if I understand lines 238 and 253 of Server.ts correctly. Maybe some ignore mechanism in the handling of those events might help.

entepe85 commented 6 years ago

Closing this issue. What I called misfiring of events was actually another extension (HvyIndustries/Crane) opening PHP files to index them for IntelliSense in the background causing them to be validated by PHPMD.

sandhje commented 6 years ago

Thnx for analysing this issue. I'll install Crane myself and check to see if I can add some kind of ignoring mechanism so we can "workaround" this issue. I'm planning on working on a new release the comming weeks, might take some time though as this is all in the evening hours ;).