xixiaofinland / dotfiles-nix

dotfiles managed by nix flake
3 stars 1 forks source link

Setting up PMD for Salesforce project in Neovim #1

Closed ognjen-vuceljic closed 2 months ago

ognjen-vuceljic commented 3 months ago

Hello!

I'm not sure if this is the best place to post such a question, but looking at dotfiles and neovim config, I tried replicating some of the items in order to add PMD to my Salesforce project.

I looked at this discussion and tried applying the mentioned fixes, but had no luck.

Once I added the following part to none-ls.lua plugin

null_ls.builtins.diagnostics.pmd.with({
          filetypes = { "apex" },
          args = { "check", "--dir", "$ROOT", "--format", "json" },
          extra_args = { "--rulesets", "apex_ruleset.xml", },
        }),

the following error was received

image

Could you, please, let me know what the configuration issue might be?

Appreciate the help!

@xixiaofinland

xixiaofinland commented 2 months ago

Do you use PMD v6 or v7? If you use v6, it should be straightforward, manually run pmd in your console to see if it exists in the $PATH. Your error message seems to imply it is missing at the moment.

If you use v7, none-ls looks for a "pmd" executable, which corresponds to "pmd check" in v7. To address this, you can create a bash script and place it in your $PATH for none-ls to invoke.

To test the result, when you run "pmd" manually in the console now, you will actually be executing this bash script, which runs "pmd check" as a wrapper and attach your inputs.

#!/usr/bin/env bash
path/to/pmd/bin/pmd check "$@"
xixiaofinland commented 2 months ago

I'm currently using v6, but this setting worked for me for v7.

https://github.com/xixiaofinland/dotfiles-nix/blob/4ec92187c21e018772ef391577146e483653f51e/dotfiles/nvim/lua/plugins/null_ls.lua#L21

ognjen-vuceljic commented 2 months ago

Thank you @xixiaofinland

I am almost there, but a few final steps are missing.

Apologies, I didn't understand the following part:

If you use v7, none-ls looks for a "pmd" executable, which corresponds to "pmd check" in v7. To address this, you can create a bash script and place it in your $PATH for none-ls to invoke.

Basically, the part I didn't catch was where exactly, and how, to create the script. My understanding is that it needs to be a .sh file with the content from message above, and to be put in a particular folder.

Btw, this is what I am getting at the moment

image

PMD may have even run against this file, but no diagnostic messages are shown.

Many thanks for the help!

xixiaofinland commented 2 months ago

you need to name the bashscript as pmd without suffix, and put it into one of your $PATH directories, explanation.

By doing this, in console you can call pmd from anywhere, just like other globally installed tools node, npm etc.

xixiaofinland commented 2 months ago

I suggest you understand what $PATH does first. None-ls is simply invoking pmd with parameters defined in the configuration.

If you can run the same commands in console successfully, none-ls should be ok too. If no, then dig a bit deeper.

ognjen-vuceljic commented 2 months ago

Thank you @xixiaofinland , will take a look.

I think we can close this issue!