vscode-apex-pmd icon indicating copy to clipboard operation
vscode-apex-pmd copied to clipboard

Don't work anymore after update (no errors)

Open rsoesemann opened this issue 1 year ago • 7 comments

Since the update, the extension doesn't do anything anymore. No errors, no icon changes.

I always used it with my own local PMD. Stopped working now. But also without a local PMD.

Screenshot_2024-04-29_at_15_23_01 ong?

rsoesemann avatar Apr 29 '24 13:04 rsoesemann

What happens if you explicitly run Apex PMD?

To start the command you can click in the menu on Help/Show All Commands or press the hotkey Ctrl+Shift+P and type Apex. Select: "Apex Static Analysis: On File"

The output should contain at least the executed command.

adangel avatar Apr 29 '24 16:04 adangel

For me it gives error because of the value net.sourceforge.pmd.lang.rule.XPathRule in the class attribute of a custom ruleset node image

If I remove the custom ruleset no errors in output but PMD does not work at all like your case @rsoesemann

marco-audibene avatar Apr 30 '24 09:04 marco-audibene

If I remove the custom ruleset no errors in output but PMD does not work at all like your case @rsoesemann

What exactly does that mean? Can you have a look at the output view named "Apex PMD" again? Is it really empty? If Apex PMD tries to start PMD it outputs always the following two lines:

###################################
Analyzing path/to/file/being/analyzed.ext

Don't forget to scroll to the end. You can also "Clear Output" before calling Apex PMD, to be sure, you only see the output from the most recent Apex PMD execution.

If the configuration is messed up (non existing ruleset e.g.), then nothing else is output there.

If there are no violations found, then the output ends with:

stdout:"Problem","Package","File","Priority","Line","Description","Rule set","Rule"
0 issue(s) found

How do you test that it works correctly? Are you sure that file you are analyzing has some violations that should be detected? Also, at least from @marco-audibene screenshot, I see, that you are analyzing the file pmd-ruleset.xml - which is not a supported file for Apex PMD and I don't expect any violations there.

@rsoesemann Can you try the following things:

  • go back to version 0.6.2? Does it work?
  • go again to version 0.7.0? Does it work? (If yes, then vs code messed up the installation of the extension)
  • verify the settings: The extension has only 12 settings - in your screenshot there are 15 listed. Just enter @ext:chuckjonas.apex-pmd in the search box to show only the settings for this extension (instead of searching for pmd). I don't know of an easy way to export the effective settings, so you need to scroll from top to bottom and check that everything has the expected value (especially as I see that your settings are synced...).

If it still doesn't work, I'd suggest that you try to reproduce it on another machine. We have integration tests here in this project and they work on Mac, Windows and Linux. So I suspect some kind of local problem.

adangel avatar Apr 30 '24 17:04 adangel

@adangel I follow specific rulesets for my analysis. Some of them are out-of-the-box, while others I've crafted using XPath.

Despite scrolling to the end and clearing the output before running Apex PMD, I'm still encountering issues. It seems that custom rulesets generate the error I mentioned, while the standard ones don't flag any violations, leaving the output empty, similar to @rsoesemann's experience.

Yes of course I am sure the files I am anaysing are having violations.

The files I'm analyzing do have violations. Reverting Apex PMD to the previous version (0.6.2) on both Mac and Windows resolves the issue for me and my colleagues, restoring functionality to how it has been working for years. image

Hope this clarifies and helps.

marco-audibene avatar May 06 '24 22:05 marco-audibene

Thanks for the info. I'm still puzzled, why the output would be entirely empty (that means, not even indicating that plugin has tried to execute PMD at all).

Could you create a simple test project that shows this issue? Then I can try myself to reproduce this... The project doesn't need to be big, just one file which contains the expected violations, that should be detected. And maybe a ruleset.

About the custom ruleset: Version 0.7.0 of the plugin uses PMD 7, which means, you also need to update your ruleset to be working on PMD 7 - see #164. Sorry, I didn't read the screenshots closely enough earlier. So, when you switch between 0.6.2 and 0.7.0 of the plugin, you also need to use different rulesets. If PMD is not able to load the ruleset (for whatever reason), then no violations will be shown, but in the output panel "Apex PMD", you should see the error messages (which happens, as I can see in the screenshots).

If the output panel "Apex PMD" stays empty, then it might more be a incompatibility with vscode - but then neither 0.7.0 nor 0.6.2 should work...

adangel avatar May 07 '24 18:05 adangel

@rsoesemann Then something is wrong with your vscode installation.

You can have a look at "Output" > "Extension Host" - maybe some (error) messages are displayed there. You should at least see the following line:

2024-05-19 09:11:38.311 [info] ExtensionService#_doActivateExtension chuckjonas.apex-pmd, startup: true, activationEvent: '*'

Which indicates, that apex-pmd extension has been loaded.

You might also see some error messages via menu "Help" > "Toggle Developer Tools" > "Console".

When you have opened the two windows, then open some apex file and run Cmd+Shift+P "Apex Static Analysis: On File". This triggers the apex-pmd extension explicitly.

If all this doesn't show error messages related to apex-pmd (note: there might be many other errors shown...), then I can only recommend trying: uninstall apex-pmd and restart vscode and then install apex-pmd again and try again. If that doesn't help, try to reinstall vscode entirely...

adangel avatar May 23 '24 07:05 adangel

@adangel I am so sorry for not having responded here.

Yes: The extension runs perfectly when I manually start them on a file. With my custom ruleset and a Path to my local PMD 7.5.0.

I also see that on start

2024-09-11 15:20:46.038 [info] ExtensionService#_doActivateExtension chuckjonas.apex-pmd, startup: true, activationEvent: '*'

Screenshot 2024-09-11 at 15 22 21

It seems to be those settings (User and Workspace) that seem to be ignore. No rescan on open or save.

rsoesemann avatar Sep 11 '24 13:09 rsoesemann

Ok, one step forward: The extension works, if it is triggered explicitly through command "Apex Static Analysis: On File". But it isn't triggered on file open/file save.

That moves the problem from executing PMD to integrating to vscode.

The plugin uses

"activationEvents": [
    "*"
  ]

Which is something like deprecated - but this doesn't seem the problem, as the plugin is available in general. And you see the ExtensionService#_doActivateExtension message.

The save handler is defined here: https://github.com/ChuckJonas/vscode-apex-pmd/blob/24788c569f25a49fba55497b71f6a041b1baa578/src/extension.ts#L67-L73

We check the languageId of the document - if this doesn't match "apex", "visualforce" or "xml", then the plugin silently does nothing.

Do you have maybe another apex related plugin installed? Maybe that uses a different language id?

TextDocument's language id is just a string, for the language associated with the document (https://code.visualstudio.com/api/references/vscode-api#TextDocument).

The current language associated with the current document is apparently displayed in the statusbar: grafik grafik

If I change here e.g. "plaintext", then vscode-apex-pmd won't be triggered anymore on save.

Maybe we could add a new settings like "Enable debug logging" to help analyzing such problems. If enabled, we would then log, when the event "onDidSaveTextDocument" is triggered and what the language id was. Usually, this debug output should be disabled, as it probably creates many logs...

adangel avatar Sep 12 '24 08:09 adangel

I reinstalled the extension and now it works. Sorry for the fuzz. And thank you for your help.

rsoesemann avatar Sep 12 '24 13:09 rsoesemann