rokucommunity / roku-debug

A compatibility wrapper around the BrightScript debug protocol https://developer.roku.com/en-ca/docs/developer-program/debugging/socket-based-debugger.md
MIT License
13 stars 9 forks source link

Use local vars and execute command for complex watch/repl expressions #118

Closed TwitchBronBron closed 1 year ago

TwitchBronBron commented 1 year ago

The debug protocol does not currently support complex expressions in the REPL or watch panel. To work around this, we should do the following:

  1. Whenever a hover/repl/watch request comes in, identify whether the expression is a simple variable expression (alpha, alpha.beta, alpha[0], alpha[0].beta, etc...), or a more complex expression such as function calls, string concatenation, etc.
  2. For all complex expressions, assign to a single local variable (perhaps call it __rokuDebug__evalVars) which will contain a collection of evaluated expressions. It'll end up looking something like this:
    __rokuDebug__evalVars = {}
    __rokuDebug__evalVars.expression1 = doSomething()
    __rokuDebug__evalVars.expression2 = 1 + 2 + 3
    __rokuDebug__evalVars.expression3 = "alpha" + str(3)
  3. We need to figure out of these variables should be purged on every debug step, or if they should live indefinitely for the lifetime of the function scope/application.
chrisdp commented 1 year ago

@TwitchBronBron shouldn't that variable be an array so that there is zero type conversion from the expression based on the discovery we did?

TwitchBronBron commented 1 year ago

No, based on our discovery a few weeks ago both arrays and AAs properly support the zero type conversion issue, as long as you do the assignment separately from the AA/Array declaration. Also, if we use an array, then we have to maintain array indexing in the debugger, whereas arbitrary AA keys can be auto-generated in the debugger without needing to know what index we're at.

TwitchBronBron commented 1 year ago

So, you're right. I mis-remembered that AAs lose the proper type. Yeah, then we need to use arrays instead. Ugh, that complicates this a bit because now we need to keep the array length in sync in the roku-debug side of things.

image