«

»

Print this Post

Enable Code Analysis for AL

It’s the week of “undocumented features”, apparently. Today: code analysis. Apparently, the al-language extension comes with a built-in analysis for your al-code. Thing is: it’s disabled by default. Just go to settings (File/Preferences/Settings) and enabled it.

By adding the line to your settings.json of your environment (the right pane). Here is my settings.json-file:

You will get quite a number of “topics” it will analyse your code for. On the points it has issues with, it will show you a green line in your code, and you can see the exact “problem” as a tooltip when you hover over it, or in the “problems”-pane (CTRL+j / Problems). Here are just a few examples:

In this piece of code, I have 3 problems, which you can read below:

When hovering over the symbol with green line, you can see the problem. In this case, an unused variable:

What do you think of this one: you risk an overflow when you use this code:

Or one of my favorites: code that will never get executed:

Can I create my own analysis?

You can, but it’s a little bit cumbersome. You can create your own analysis-dll, drop it in the extension-folder, and go from there. I haven’t had a look at it .. because I’ll wait until this undocumented-but-already-cool-feature gets documented-and-even-cooler and supported, so we are sure that the work we put into it, is worth it. In the mean time: thumbs up, Microsoft! 🙂

Performance impact

I was told it does have a performance impact, so I guess that’s why it’s disabled by default. I haven’t noticed too much of an impact myself, to be honest.. but you are warned ;-).

5.00 avg. rating (98% score) - 3 votes

Permanent link to this article: http://www.waldo.be/2018/01/23/enable-code-analysis-for-al/

4 comments

2 pings

Skip to comment form

  1. Theis Andersen

    but we’re still not quite there 🙂

    while counter < numberOfRates – 1 do begin

    if i format the above in visual code using shift+alt+f it will move the begin down to the next line. And now i get a problem that it should be on the same line.

    and CurrPage.Somepage.Page.Somemethod(); will cause a problem that page should be with (). However if i set this a compile error shows.

    But for most cases it works very well. So thanks for the hint.

    1. waldo

      I guess it’s “undocumented” for a reason 😉

  2. Vytenis Jakas

    Well, I do recall quite a few people complaining about the slow VS Code editor performance, with the earlier versions of AL and the solution was to turn this off. So yes, this is probably why it’s off by default. But, even in the current state this feature is a hidden gem.

  3. Laura Nicolàs

    Hello Waldo,

    Thanks a lot for the tip. I have already enabled it, and I am not having any performance problem,

    I would also like to ask you a question:

    Imagine you have to develop an extension that is going to be used in 10,000
    different Dynamics NAV customers. What characteristics would that extension have?

    A blog post about this would be perfect .-)

    I have also opened a discussion at mibuso:
    https://forum.mibuso.com/discussion/70804/nav-2018-characteristics-of-a-scalable-extension

    Thanks a lot!

    Laura Nicolàs

  1. Enable the updated Code Analysis for AL – waldo's blog

    […] time ago, I wrote a blogpost on how to enable code analysis for AL development. At that point, it was an undocumented feature – not to say, it was an unfinished feature […]

  2. Enable the updated Code Analysis for AL - Waldo's Blog - Microsoft Dynamics NAV - Business Central/NAV Users - DUG

    […] time ago, I wrote a blogpost on how to enable code analysis for AL development. At that point, it was an undocumented feature – not to say, it was an unfinished feature […]

Leave a Reply

%d bloggers like this: