anzwdev / al-code-outline

AL Code Outline for Visual Studio Code
MIT License
49 stars 12 forks source link

Show Code Analyzer Rules: Does not pick up multiple custom code analyzers #567

Open rvanbekkum opened 3 months ago

rvanbekkum commented 3 months ago

We are using multiple custom code analyzers, both the BusinessCentral.LinterCop and our own BusinessCentral.MyCustomCop. The Show Code Analyzer Rules command does pick up the LinterCop, but does not pick up the other custom code analyzer.

image

The BusinessCentral.MyCustomCop.dll is in the same directory as the BusinessCentral.LinterCop.dll, but the command does not include it in the overview. Would it be possible for it to pick up multiple custom code analyzers?

By the way, the settings.json file of the AL projects look something like the following:

{
    "al.codeAnalyzers": [
        "${AppSourceCop}",
        "${CodeCop}",
        "${PerTenantExtensionCop}",
        "${UICop}",
        "${analyzerfolder}BusinessCentral.LinterCop.dll",
        "${analyzerfolder}BusinessCentral.MyCustomCop.dll"
    ],
    "al.enableCodeAnalysis": true,
    "al.enableExternalRulesets": true,
    "al.ruleSetPath": "https://mycustomcop.blob.core.windows.net/rulesets/appsource/ruleset.json",
    ...
}
rvanbekkum commented 1 month ago

Hi @anzwdev,

I noticed you made a commit that made it into the new release. Thanks for looking into it! I tried the new release, but unfortunately I still do not get the rules of my custom code analyzer.

In the extensions folder I have the following:

image

But I do not have an option to select the custom code analyzer in the viewer: :(

image

Do you have any idea? Did you get it to work with a custom code analyzer?

anzwdev commented 1 month ago

Hi @rvanbekkum

There was a bug in analyzers detection, it was ignoring custom analyzers if they were added to the "al.codeAnalyzers" setting as "${analyzerfolder}". It worked when it was a full path to the file. Now, after the fix, the latest version of the extension should work with both cases. The current logic adds 4 standard code analyzers, Compiler and BusinessCentral.LinterCop if the LinterCop dll exists in the "Analyzers" folder. Then it adds any other analyzer that is defined in the "al.codeAnalyzers" setting and DLL file exists. I've tested it yesterday with 2 dlls, it worked with both full path and "${analyzerfolder}" in the "al.codeAnalyzers" setting.

If it is not working for you, then you must have different setting than my test environment. Maybe my extension reads wrong settings? Are you using multi-folder workspace?

rvanbekkum commented 1 month ago

Yes, I am using a multi-root workspace. The al.codeAnalyzers setting is defined per project in the workspace in its settings.json file. I haven't checked yet if it does work by opening the project specifically instead of the .code-workspace file which opens the multi-root workspace. I could check that as well tomorrow when I'm working/at my desk again 😉 Any more info I could provide that would help?

anzwdev commented 1 month ago

It looks like a problem with multi-root workspace projects. I've modified the code, it works for me now. Fix will be available in the next release.

rvanbekkum commented 1 month ago

I tried opening a specific folder/project instead of a multi-root workspace (.code-workspace file).

Then, the Show Code Analyzer Rules window does give the options to select custom code analyzers 😊,

image

BUT:

  1. It does not show the rules of the custom code analyzers :(

    image

  2. There is a duplicate entry for "BusinessCentral.LinterCop" and "${analyzerFolder}BusinessCentral.LinterCop.dll"

    The "BusinessCentral.LinterCop" entry does work, the "${analyzerFolder}BusinessCentral.LinterCop.dll" entry does not.

    image

rvanbekkum commented 1 month ago

I tried opening a specific folder/project instead of a multi-root workspace (.code-workspace file).

Then, the Show Code Analyzer Rules window does give the options to select custom code analyzers 😊,

image

BUT:

  1. It does not show the rules of the custom code analyzers :( image
  2. There is a duplicate entry for "BusinessCentral.LinterCop" and "${analyzerFolder}BusinessCentral.LinterCop.dll" The "BusinessCentral.LinterCop" entry does work, the "${analyzerFolder}BusinessCentral.LinterCop.dll" entry does not. image

This same issues persist with the latest update (v13.64.0) 😉

image

anzwdev commented 1 month ago

I think that I know where the problem is. The check that I've implemented in the extension code is case sensitive and it is looking for "${analyzerFolder}" while your screenshot shows "${analyzerfolder}". I will change it, but could you check if it works if you use "${analyzerFolder}" in the code analyzer name?

rvanbekkum commented 1 month ago

Good find! I actually took that casing from the instructions/examples in the LinterCop repository, e.g., https://github.com/StefanMaron/BusinessCentral.LinterCop/blob/master/.assets/VSCode.md

anzwdev commented 2 weeks ago

I've modified the logic, it should not be case sensitive anymore.

rvanbekkum commented 1 week ago

I did some tests the past few days, but unfortunately it doesn't work at all anymore :(

It also does not work for my colleagues.

My configuration:

AL Language extension for Microsoft Dynamics 365 Business Central Version: 13.1.1065068

(I have also tried switching back to version 13.0.1027618 but without any luck either)

AZ AL Dev Tools/AL Code Outline Version: 13.67.0

Visual Studio Code Version: 1.90.2 (system setup) Commit: 5437499feb04f7a586f677b155b039bc2b3669eb Date: 2024-06-18T22:34:26.404Z Electron: 29.4.0 ElectronBuildId: 9728852 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Windows_NT x64 10.0.22631

settings.json

{
    "al.codeAnalyzers": [
        "${AppSourceCop}",
        "${CodeCop}",
        "${PerTenantExtensionCop}",
        "${UICop}",
        "${analyzerFolder}BusinessCentral.LinterCop.dll",
        "${analyzerFolder}BusinessCentral.WSBCop.dll"
    ],
    "al.enableCodeAnalysis": true
}
anzwdev commented 1 week ago

Was it working earlier? Are these custom analyzers reporting any warnings? Can you see any errors when you run "Open AZ AL Dev Tools log file" command?

I've tried the command with a custom analyzer with a single AL project folder and with multi-root workspace and it works for me in all these cases. Does it work if you specify full path to your code analyzer instead of using "${analyzerFolder}" prefix?

rvanbekkum commented 1 week ago

Was it working earlier?

Yes, I remember seeing it work earlier, but now for me and my colleagues it does not work.

Are these custom analyzers reporting any warnings?

Yes, diagnostics are raised from the code analyzer rules of this code analyzer, e.g.,

image

Can you see any errors when you run "Open AZ AL Dev Tools log file" command?

No, there are no recent errors.

I've tried the command with a custom analyzer with a single AL project folder and with multi-root workspace and it works for me in all these cases. Does it work if you specify full path to your code analyzer instead of using "${analyzerFolder}" prefix?

I have tried with a multi-root workspace, single projectfolder, using "${analyzerfolder}BusinessCentral.WSBCop.dll" vs. "${analyzerFolder}BusinessCentral.WSBCop.dll", and now also with "C:/Users/r.vanbekkum/.vscode/extensions/ms-dynamics-smb.al-13.1.1065068/bin/Analyzers/BusinessCentral.WSBCop.dll". Unfortunately I cannot get it to work with any combination :(

It does show the code analyzer as a selectable option:

image

But once you change the filters, no rules are displayed:

image

I am not sure what the problem should be. I remember seeing the rules in the rules viewer for this code analyzer/cop. And I have tried all sorts of things. The code analyzer itself works perfectly fine as it raises diagnostics where we would expect them and no exceptions. It is compiled against the latest AL marketplace version which I am also using in my VS Code installation.

anzwdev commented 1 week ago

It looks like it is detected correctly, but then something is wrong when it is loaded into memory. I will modify this proces and write more information to the log.

anzwdev commented 3 days ago

I've released a new version of the extenson, it should save more information in the log if there are any problem with loading analyzers dlls. Could you test "Show Code Analyzer Rules" in the new version and check if there is anything in the log?