openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.87k stars 3.58k forks source link

[jsscripting] Debugging Support #17415

Open bern77 opened 1 week ago

bern77 commented 1 week ago

It seems GraalVM provides debugging support based on Chrome Debugger: https://www.graalvm.org/latest/tools/chrome-debugger/

It would be very intersting to include this support also in the add-on to enable debugging functionality for rules development.

There's also a thread in the openHAB forum on this topic: https://community.openhab.org/t/debugging-support-for-jsscripting/158342

openhab-bot commented 1 week ago

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/debugging-support-for-jsscripting/158342/3

florian-h05 commented 1 week ago

As said in the forum, I think this is feasible to do, but as each rule/script is getting its own context, each one needs its own debugger backend. In general I don’t think it’s a good idea do have the debugger backend running by default, so I would propose to make it configurable for which scripts to enable the debugger backend.

Also see https://www.graalvm.org/latest/tools/chrome-debugger/#programmatic-launch-of-inspector-backend.

bern77 commented 1 week ago

Thanks for your fast response. Sounds good and makes sense to me not to enable a probably more ressource intensive functionality by default. Would it be possible though to enable debugging at runtime, i.e. avoiding a restart of OH or the add-on?

florian-h05 commented 1 week ago

Would it be possible though to enable debugging at runtime, i.e. avoiding a restart of OH or the add-on?

Yes, that would be possible. I am currently thinking of two options how to implement that, but I am not sure if they both would work:

  1. introduce a special comment that tells the script engine to enable debugging
  2. introduce a add-on setting where you can specify one (or probably multiple) script(s) to enable debugging for
bern77 commented 1 week ago

Wow, very cool 🙂

For my taste, staying inside the IDE (in my case VS Code) would be preferable over having to activate a setting via the browser in the OH admin interface. However, if the setting could be controlled also via textfiles, it should be fine as well. If it was possible to include this also in the VS Code extension for OH (something like right-click and 'enable debuggin' for a specific script) it would be super-intuitive.

But the idea with the comment sounds captivatingly elegant and very convenient to me. 👍