ExtendScript Debugger v1.x Needs a Rethink
[This was originally posted in another private forum here. Moved to this forum for more open discussion and link-ability.]
TL;DR
The ExtendScript Debugger has some serious problems that stem from its current implementation. In summation, the debugger does not work like other debuggers in VSCode (e.g. NodeJS) [or any other mainline IDE debugger (that I'm aware of)], which is the default expectation for any user. Specifically this means:
- The debugging session appears to stop immediately after being run.
- Compound Launch Configurations cannot be used.
- VSCode Breakpoints do not work unless very specific, non-obvious configuration settings are in place.
- VSCode Breakpoints might mysteriously fail to work, even with the non-obvious configuration settings in place.
All of the above issues are related to the current way that the ExtendScript Debugger extension handles a "Debug Session". Addressing these issues will very likely mean changing how this is performed. For more information, please see the following sections.
Beyond TL;DR The Expectations
As a user, I expect the ExtendScript Debugger to work exactly like any other debugger I interface with in VSCode. This means the following:
- A debug session lasts from when I click the "Start Debugging" button (or command) until I click the "Stop Debugging" button or the target context stops of its own accord (e.g. application closes).
- When the debug session is not running there is no connection between the target context and VSCode.
- When I adjust breakpoints while a debug session is active but not stopped, the debug session will respond accordingly.
The Default Reality
The reality is extremely different from the expectations. With a default configuration, the debugger has the following characteristics:
- With no breakpoints set, the debugger will appear to stop immediately after starting.
- With breakpoints set, the debugger might appear to stop immediately after starting. This depends on the context in which the breakpoints exist:
- Top level statement: Yes.
- Un-invoked Function declaration: No.
- No clear way to make the Debug Session last long enough to trigger a function from a CEP panel via CSInterface.evalScript().
That the debugger starts and stops immediately is extremely confusing. It really seems like there's no way to have the debugger exist in a "standby mode" that is capable of breaking on runtime script logic.
The Advanced Reality
By setting the debugLevel: 2 configuration option in the launch.json file, it is possible to coerce the VSCode Debugger Extension to actually handle breakpoints in runtime script logic. However, this results in the following quirks:
- The debugger will always stop at the first line of the script specified in the program configuration option when the "Start Debugging" action is triggered (button/command/etc.).
- The debugger appears to automatically start when a specified breakpoint is hit.
- Modification of breakpoints (add/remove/update) in the VSCode interface are not communicated to the background debug session automatically. This can result in the following confusing scenarios:
- Remove breakpoint: Ghost breakpoint triggered. "VSCode halted where no breakpoint is set!"
- Add breakpoint: Existing breakpoint ignored. "VSCode ignores my breakpoints!"
- Attempts to use Compound Launch Configurations do not work as expected. This would be a natural thing to try given that one may wish to attach to both the HTML and ExtendScript engines in a single debug session.
Beyond the above surprising quirks, the current implementation appears to leave a connection to a Host Application open at all times. The ExtendScript Debugger is put into a Polling mode with no clear way to break that connection.
Matching the Reality to Expectations
Adjusting the ExtendScript Debugger to operate more closely with expectations should be possible. Specifically, adjusting the extension to run as follows should go a long way to help:
- Create a connection to the host application and begin polling when the user explicitly Starts a debug session.
- Do not automatically stop the debug session unless the it ends for some unforeseeable reason (e.g. host application exits).
- Close the connection to the host application and stop polling when the user explicitly Ends a debug session.
- Watch for breakpoint changes in the adapter and update the active ExtendScript debug session live.
ExtendScript Debugger isn't "ESTK in VSCode"
The current functionality appears to attempt to emulate the "Play/Run" button in ESTK. The problem is that VSCode's debugging facilities are expected to run in a very different manner. This doesn't mean that you shouldn't support the ability for someone to write script and run it in a host application, just that you shouldn't rely on the debugger to do so. The ExtendScript Debugger should be adjusted to support the following features:
- A default debugging experience that works as near as possible to other debugging experiences in VSCode (see the previous section).
- A "Run Script in Target Host" command feature that runs the currently focused JS/JSX script in a selected target application.
- A "Debug Script in Target Host" command feature that effectively works the same as the default configuration does today.
- A "Connect Console to Target Host" command feature that provides the user with a console interface for a given engine on a target host so that they may issue direct commands to it (and possibly show a live-updated set of global data as with the ESTK Data Browser?).
Such an approach should do a good deal to clear things up for users and offer them desirable features that they have grown accustomed to with ESTK.
