sandhje / vscode-phpmd

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

No output was received after executing the phpmd command #34

Closed oldschool777 closed 6 years ago

oldschool777 commented 6 years ago

Okay, I'm sure it's something that I'm doing, or not doing, but I can't figure it out for the life of me.

I installed the extension, leaving everything as defaults. I have only switched the verbose flag to true to attempt to track down this issue.

I get the following output, with the error at the end: [Info - 9:37:28 PM] New document opened, starting validation. [Info - 9:37:28 PM] PHP Mess Detector validation started for perforce://print/c%3A/p4_personal/Contracting_Work/NSIP/TimeTrack/web/development/php/feed.php?-q [Info - 9:37:28 PM] PHP command test successful (PHP 5.6.6 (cli) ...) [Info - 9:37:28 PM] PHP Mess Detector test succesful (PHPMD 2.6.0) [Info - 9:37:28 PM] File c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php test successful [Info - 9:37:28 PM] Running phpmd command (php C:\Users\Eric\.vscode\extensions\ecodes.vscode-phpmd-1.0.3\phpmd\phpmd.phar "c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php" xml "cleancode,codesize,controversial,design,unusedcode,naming") [Error - 9:37:28 PM] An error occured during document validation after open with the following message: An error occured, no output was received after executing the phpmd command

Running the exact same command on the Windows command line (php C:\Users\Eric.vscode\extensions\ecodes.vscode-phpmd-1.0.3\phpmd\phpmd.phar "c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php" xml "cleancode,codesize,controversial,design,unusedcode,naming"), I get xml output data.

Any assistance on this issue would be greatly appreciated.

oldschool777 commented 6 years ago

I just tried opening another folder that is not tied to my Perforce SCM, and I don't seem to get that error, and it shows me output from phpmd. Any idea why this would make a difference, and if so, how I can get the extension to work with source controlled files?

oldschool777 commented 6 years ago

Okay, I just blew my own theory out of the water...

If I just open the folder, and not the workspace I built the connects to SCM, I have the same issue, as shown here: [Info - 11:11:14 PM] Language server connection initialized. [Info - 11:11:14 PM] Configuration change triggerd, validating all open documents. [Info - 11:11:14 PM] Creating controller [Info - 11:11:14 PM] New document opened, starting validation. [Info - 11:11:14 PM] PHP Mess Detector validation started for file:///c%3A/p4_personal/Contracting_Work/NSIP/TimeTrack/web/development/php/feed.php [Info - 11:11:14 PM] PHP command test successful (PHP 5.6.6 (cli) ...) [Info - 11:11:14 PM] PHP Mess Detector test succesful (PHPMD 2.6.0) [Info - 11:11:14 PM] File c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php test successful [Info - 11:11:14 PM] Running phpmd command (php C:\Users\Eric\.vscode\extensions\ecodes.vscode-phpmd-1.0.3\phpmd\phpmd.phar "c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php" xml "cleancode,codesize,controversial,design,unusedcode,naming") [Error - 11:11:14 PM] An error occured during document validation after open with the following message: An error occured, no output was received after executing the phpmd command

As you can see, it's the same file that Mess Detector is starting validation for, except in this case, it just has the "file:///" prefix, instead of "perforce://print/" prefix.

On the other hand, the file that I mentioned in my previous post works just fine, as this log shows: [Info - 11:15:04 PM] New document opened, starting validation. [Info - 11:15:04 PM] PHP Mess Detector validation started for file:///x%3A/web/apps/Handicap/info.php [Info - 11:15:04 PM] PHP command test successful (PHP 5.6.6 (cli) ...) [Info - 11:15:04 PM] PHP Mess Detector test succesful (PHPMD 2.6.0) [Info - 11:15:04 PM] File x:\web\apps\Handicap\info.php test successful [Info - 11:15:04 PM] Running phpmd command (php C:\Users\Eric\.vscode\extensions\ecodes.vscode-phpmd-1.0.3\phpmd\phpmd.phar "x:\web\apps\Handicap\info.php" xml "cleancode,codesize,controversial,design,unusedcode,naming") [Info - 11:15:04 PM] PHP Mess Detector validation completed for file:///x%3A/web/apps/Handicap/info.php. 5 problems found [Info - 11:15:04 PM] Document validation after open completed successfully

The one that works happens to be on a shared drive, and has a shorter path, but the file that is not working does not have an extremely long path or anything, so I'm not sure what is causing one to work, and not the other.

Again, any help or suggestions would be greatly appreciated.

sandhje commented 6 years ago

Hi,

That's a really strange issue. So if you say the command does return xml when you run it on the windows command line it makes no sense it doesn't in the extension. What happens if you run the command in the vscode terminal instead of directly in the windows command prompt? Also could you put the same file (feed.php) in the x:\web\apps\Handicap folder to see if it does validate correctly there, instead of testing a different file, to see that it is not an issue with the file itself? As a third option you could try disabling any other extensions you have running to rule out any conflicts, although I don't think the problem would be there because your logs show the phpmd command closes without output, no other extension should be able to influence that.

oldschool777 commented 6 years ago

The file feed.php does process just fine if I move it to the other directory.

Attempting to use the vscode terminal seems to error out like the extension, compared to working in the standard command prompt. This is the output I/O from that: C:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php>php C:\Users\Eric\.vscode\extensions\ecodes.vscode-phpmd-1.0.3\phpmd\phpmd.phar "c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\feed.php" xml "cleancode,codesize,controversial,design,unusedcode,naming" Unable to parse file "phar://C:/Users/Eric/.vscode/extensions/ecodes.vscode-phpmd-1.0.3/phpmd/phpmd.phar/vendor/pdepend/pdepend/src/main/php/PDepend/DependencyInjection/../../../resources\services.xml".

And here's where the plot thickens... When I run it in the command prompt, I was just using the default location where the command prompt opens to, being my user home directory. However, when I got to the exact same path as the vscode terminal starts for this project, I get the same error in the command prompt, that I do in the vscode terminal. Likewise, if I go to the root in the vscode terminal, I get the expected XML output, with no error. So, going back to the command prompt, I have to go up 2 directories, before it will work, from "C:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\" to "C:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\". It still didn't work when I went up just one directory to "C:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\".

This doesn't make any sense to me, as the path for the actual file it's checking doesn't change in the command being passed to php and phpmd.phar, it is just the current working directory. As far as I can tell, it shouldn't be a path issue when searching for php or phpmd.phar, because the php exec is in my path (and going up 2 directories wouldn't help anyhow), and phpmd.phar is provided with full path when passed to php. Also, there are no spaced or anything in my CWD path. It really makes no sense, as to why that CWD wouldn't work, when another will. I assume it has to do with the length of the CWD, but I don't know why that would matter, when the path passed to php and the phpmd.phar script doesn't change.

oldschool777 commented 6 years ago

I found this: https://github.com/pdepend/pdepend/issues/296

So, it appears the issue is not actually with your extension, however, I wonder if you can change the CWD to the root, potentially, before running phpmd? Or maybe have a config option to specify the directory to run it out of, to work around the problem? Based on later posts in that forum, it looks like it may affect non-Windows systems, as well.

sandhje commented 6 years ago

Judging from the pdepend issue you linked I guess you could solve this by installing phpmd globally on your system through composer or downloading a phar from the phpmd site site and adding it to the extension's phpmd.command configuration option (see the readme). That way you can control its location and version (one of the comments was that PHPMD 2.5 did not show the same problems). That would equal to what you are suggesting, that is, "having a directory to run it out-of".

Could you try this and let me know if it fixes your issue?

oldschool777 commented 6 years ago

I don’t think the path to phpmd and/or pdepend is the issue. I’ve tried putting the phpmd.phar in a higher level directory and have gotten similar results. The issue seems to be where the call originates from.

So, being in a deep directory when the php call to launch phpmd is made causes the problem, versus being in a high level directory, when it succeeds, with the phpmd.phar (and therefore including pdepend) in the same location for both.

I don’t think the guess about the relative directory for pdepend in that post is accurate, because the relative path doesn’t have the CWD included in the error I get.

That’s why I suggested an option to set the CWD/launch directory for the actual php call to execute phpmd, because that’s the only way I’ve gotten it to work.

oldschool777 commented 6 years ago

I just got back home and tried one more thing. I tried putting the phpmd.phar in my php directory, under "c:/php/packages/phpmd.phar". From the command-line, and in the terminal window, running from the long path, this command works: php C:\php\packages\phpmd.phar "c:\p4_personal\Contracting_Work\NSIP\TimeTrack\web\development\php\Classes\Cal\DataBuilder.inc" xml "cleancode,codesize,controversial,design,unusedcode,naming"

Based on that, I tried to set a custom location for the phpmd.phar file like so: "phpmd.command": "c:/php/packages/phpmd.phar"

But that doesn't work, and gives me the following output with verbose logging on: [Info - 8:30:47 PM] Language server connection initialized. [Info - 8:30:47 PM] Configuration change triggerd, validating all open documents. [Info - 8:30:47 PM] Creating controller [Info - 8:30:47 PM] New document opened, starting validation. [Info - 8:30:47 PM] PHP Mess Detector validation started for file:///c%3A/p4_personal/Contracting_Work/NSIP/TimeTrack/web/development/php/Classes/Cal/DataBuilder.inc [Info - 8:30:47 PM] PHP mess detector command not using global PHP, skipping PHP test [Error - 8:30:47 PM] An error occured during document validation after open with the following message: An error occured, no output was received after executing the phpmd command

Using the custom path definitely has different output, and doesn't even show me the command that it tries to use to run the file against phpmd. And it says that it's not using the global PHP, so it's skipping the PHP test, which I'm not entirely sure what that means.

Based on this, I think I could get it working if I could: 1) Have an option to run the "php phpmd.phar..." command from a custom directory, which I could set as the root, or some high level directory, or 2) get the custom phpmd path to work with the extension, so that I can use the shallower path for the phpmd.phar file.

Any help you could provide to get either of those solutions running for me, would be very much appreciated.

sandhje commented 6 years ago

So the global php thingy means that if you do not "change" the phpmd.command setting the extension tries to detect wether you have php available globally on your system, that is, it is on your PATH (windows). Since you change the command setting, the extension does not know whether you want to use a php executable on a custom location or have a phpmd command globally available (like when you install it with composer, than you can simply do "phpmd -v" on the commandline if you have the composer folder in your PATH).

So since "global php" can no longer be assumed as you changed the setting, you also need to include that in the setting. Your phpmd.command setting should look like:

"phpmd.command": "php c:/php/packages/phpmd.phar"

(including "php"). Could you try with that setting? That should not give you the "no output was received" error.

oldschool777 commented 6 years ago

Awesome! That did it. Hopefully the pdepend issue will get sorted out in a later version of that package, but for now, this work around gets me sorted out.

Thanks again for your help on this!

kmcconnell commented 6 years ago

I'm getting the same error on MacOS 10.13.4 VSCode 1.24.0. I only recently noticed it happening and we've had the extension and settings in place for the past 8 months unchanged.

[Info  - 19:52:54] Language server connection initialized.
[Info  - 19:52:54] Configuration change triggerd, validating all open documents.
[Info  - 19:52:54] New document opened, starting validation.
[Error - 19:52:55] An error occured during document validation after open with the following message: An error occured, no output was received after executing the phpmd command

Our settings (verbose was added for troubleshooting):

"phpmd.rules": "phpmd.xml",
"phpmd.verbose": true

Running phpmd on command line presents no issues. The phpmd phar is installed at /usr/local/bin/phpmd. However it doesn't work in VSCode. I tried another phpmd extension for VSCode and it worked fine, although the extension itself is poorly supported and feature lacking, so I'd love to get this extension working again.

sandhje commented 6 years ago

Did you also set the "phpmd.command" setting? The extension package contains a phpmd phar of its own which it uses if you leave that setting empty. It could be that that phar is giving errors while the one in your /usr/local/bin is not. Please try setting the exact command you used in your console in the phpmd.command setting. Note, I do not have a mac at hand so can't test this on one but it "should work" ;)

sandhje commented 6 years ago

Closing due to lack of response to the last remark.

lalmat commented 4 years ago

Ok, I've just been confronted to the same problem... I had a blank line at the start of my phpmd.xml config... So frustrating !

sandhje commented 4 years ago

Sorry to hear about that, I'm afraid that phpmd is not very forgiving when it comes to the config xml... Unfortunately at the extension end I cannot do much about that, since the extension is just a wrapper around phpmd. You can always file an issue with them off course at https://github.com/phpmd/phpmd/issues. If there is anything in the extension that I can change that would have helped you to identify the problem sooner please let me know and I will consider putting it on the work list for the next release.