adventuregamestudio / ags

AGS editor and engine source code
Other
675 stars 159 forks source link

AGS 4: Watch Variables feature potential improvements #2447

Open ivan-mogilko opened 2 weeks ago

ivan-mogilko commented 2 weeks ago

This is a list of potential fixes and improvements copied from #2430 discussion.

ericoporto commented 2 weeks ago

I've been playing with Autocomplete (of AGS Editor) and recently with the Watch Variable panel in VBA (in Excel) and had an idea of offering the autocomplete that we can get in the line of the script that is on break (is this line known anywhere?) on the typing box we get in the watch variable. The idea came to me because the watch pane in VBA also doesn't have autocomplete and after using it for a bit for an issue at work I reminded that the one in ags also didn't have.

ivan-mogilko commented 2 weeks ago

that we can get in the line of the script that is on break (is this line known anywhere?)

Sort of, this line is known from the message that comes to Editor each time after a break or step. This message contains a callstack, with script/line pairs. I don't think if it's currently saved anywhere except for the Callstack panel.

ericoporto commented 2 weeks ago

Uhm, ok, so the issue here is if we want to have that specific line in autocomplete, so we can have all the local variables, the way to do requires we have access to the ScriptEditor, which both the script and the line will be get in the ZoomToFile call here

https://github.com/adventuregamestudio/ags/blob/e3a35543d5427232cbffb8f3d9f6389f337f0e5e/Editor/AGS.Editor/AGSEditor.cs#L370-L376

So what I can do is at some point here pass the script name and line to the watch panel (or somewhere else?), and then I can get this from there. I thought to do it even in that NotifyWatchVariables but I am unsure how to pass arguments and how that works - all these calls use those "invoke" which I know are needed for Winforms stuff but I don't understand how they work (are they async?).

And then having such info I can then know when someone is typing in watch variable which script and line should the autocomplete show relative to, and then I can pickup this from the corresponding scintilla wrapper instance. I need to play more with this before I have anything...

ivan-mogilko commented 2 weeks ago

I suppose, there could be a event named, as an example, OnScriptDebugPosition. This event could be located somewhere in GUIController, Debugger or other global manager. This event would be fire when: a) break point happens; b) step in script happens; c) script position is selected in Callstack window. (question is how to make callstack window trigger this event)

Any panel, such as WatchVariables window, would be able to subscribe to this event, and update itself upon receiving it.

WatchVariables would likely need to save "current debug position" for any future value updates.

ericoporto commented 2 weeks ago

I think C is not needed as the local variables shown there won't be in scope (for the engine internally I think), so we won't be able to read from there.

Regarding B, I thought that when a step is done the engine throws a break itself.

ivan-mogilko commented 2 weeks ago

I think C is not needed as the local variables shown there won't be in scope (for the engine internally I think), so we won't be able to read from there.

True, this is for the future, when engine supports backtracing callstack (task number 6 in this list).