Dialplan syntax validator for IntelliJ IDEA

Is there any plugin or addon for any IntelliJ IDEA to validate dialplan synxtax, or highlighting errors in the dialplan?

Because the dialplan interpreter is basically a text macro processor, and because each command parses its own arguments, I’m not sure that you could actually produce a static checker that would work in the general case.

I guess there has been a trend to standardising the parsing of command arguments, and not many people will bundle multiple parameters into one variable, but people do still make quite heavy use of variables, and, for example, it would need quite a sophisticated static analyser to ensure that the first parameter of Dial was a valid dialstring.

Basically, the interpreter evaluates the whole parameter list as a single string, so commas are just ordinary characters to it, and passes the expanded string to the application, which then breaks it up into parameters, etc. Actually it is quite possible that it really generates a string with everything after the comma after the priority, then parses that into the application name and the parameter string, but I’ve not tried this, and never seen anyone taking advantage of it.

There is a Notepad++ style[1] that has color syntax for the dialplan, that I use. It doesn’t flag anything as a problem per se, but it makes it much easier to visually see if there is a problem somewhere. If you’re missing a brace or something like that, the whole file gets thrown off and you immediately know there’s a syntax issue.

Also, there is a change currently up for review[2], which does do some analysis of the dialplan at load time to check for issues before they throw exceptions at runtime.

[1] GitHub - xilitium/Asterisk-Dialplan-Syntax-Highlighting: Traditional Asterisk Dialplan Syntax Highlighting for Notepad++

[2] https://gerrit.asterisk.org/c/asterisk/+/17719

There seem to be two, conflicting, “false negatives” in the initial description.

I’m not sure how it can avoid false positives unless it treats all variables as wild cards, as I believe that variables can contain parameter delimiters, so the parameter count wouldn’t be safe if a variable is present.

I’m not sure how it can avoid false positives unless it treats all variables as wild cards, as I believe that variables can contain parameter delimiters, so the parameter count wouldn’t be safe if a variable is present.

The approach currently taken is to consider it “safe” if there are variables present, for exactly that reason.

For example, you could have:

same => n,Set(dialargs=DAHDI/3)
same => n,Dial(${dialargs})

There’s simply no way to statically know if individually lines, containing variables, are correct, without actually simulating dialplan execution, which is beyond the scope of the review.

Therefore, we say anything with a variable in certain places is “good” to avoid false positives.

The goal is that there should not be false positives, but there may be false negatives. In other words, if the module raises a warning, it’s an actual issue, but the lack of raised warnings does not necessarily indicate there won’t be issues at runtime.

A lot of examples I see here seem to overuse variables. Given that many people cut and paste code they often don’t seem to realise that they could use literals. You may find that it doesn’t work well for the average beginner.

Nothing’s going to be a perfect solution, that much is granted.

Some issues can always be detected, such as missing a priority label or dumb syntax errors like that.

It’s also possible to warn about branching to nonexistent locations, something that’s helped me a lot with large dialplans that change overtime, with references to stuff that doesn’t exist anymore.

Obviously, different folks will see different utility from it. I’m not really specifically targeting beginners with this, whose dialplans are likely to be so small that they might not get much benefit anyways.

Nothing can do with IntelliJ IDEA IDE in any way.
How about to use VIM which has syntax highlighting?

There is a syntax highlighter (and probably some intellisense) for VSCode: Asterisk Syntax Highlighter - Visual Studio Marketplace

I use this and generally can recommend - ofc it’s fare from perfect but it’s better than nothing :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.