How to debug with VS code?

So I am using VS code to write my code and my code works well:

However in the log I get this:




    ==> /var/log/openhab2/openhab.log <==

    2019-07-20 11:11:50.383 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'light.rules', using it anyway:

    Unnecessary cast from String to String

    Assignment to final variable

    Constant condition is always false.

    Constant condition is always false.

    Unnecessary cast from String to String

    Unnecessary cast from String to String

    Unnecessary cast from String to String

    Unnecessary cast from String to String

    Unnecessary cast from String to String

    Unnecessary cast from String to String

    2019-07-20 11:11:50.865 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'light.rules'

So how can I get rid of this and how can I use VS code to debug my code so I can find out where these errors are? It would at least be useful if the log could point me to right line number in my rule file…

VSCode should be telling you which lines have these warnings.

These are all very easy. The String to String is caused by lines that include as String where it isn’t needed.

The Assignment to final variable is a case where you can a variable defined using a val but you later try to set it to something else using =. Change the variable to use var instead.

The condition is always false error means you have an if or switch statement that will never run because the condition will always be false no matter what. Review the conditions and make sure you understand what they mean and what they are supposed to do.

Ok,
I guess its this line where its unnecessary to cast to String:

val roomName = triggeringItem.name.split("_").get(0) as String

but how can I pick this up in the VS code and not have to guess in which line the log refers to?

If you have VSCode configured to connect to your running OH instance it should show the same words and warnings as when the rule gets loaded. It’s the same code that parses the Rules in both cases .