-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor: add local variables to watch panel automatically #2451
Editor: add local variables to watch panel automatically #2451
Conversation
66c4ab8
to
7b89fea
Compare
e511176
to
9eaac57
Compare
Added a very minimal left click context menu to add things to watch pane - I tried deducing if a string was actually a variable but it isn't simple, you need to check the autocomplete cache of all scripts using FindVariable and it still may come up empty if one of them failed to parse correctly, which can be very frustrating, it turns out a dumber approach that allows adding any word to the watchpane is better. This is useful for things in the global context that aren't automatically added to the watch pane but that you still want to keep track. |
9eaac57
to
c021c24
Compare
Sorry for not responding earlier, I'd like to review and deal with this PR draft now if possible. |
Right, I will do it tonight. The reason I never took it off of draft status is it had an issue that it would occasionally lock the AGS game when I ran. After I rebase, if I find the issue again I will mention it. The last commit is probably safe without the rest of it btw. |
7eba8f4
to
c0a8775
Compare
Hey, I did the rebase but I haven't been able to test it yet. :/ |
There's something funny, having For example:
will add "int" variable to the watch panel. Not sure which part of this feature is causing this. I'll continue testing. |
So, I noticed that this method Looking at GetListOfLocalVariablesForCurrentPosition, it seems like this method does not have to be in ScintillaWrapper at all, because it does not access any of scintilla's functionality, but only AutoComplete functionality. It may be possible to move this method to AutoComplete class, where it would accept only IScript, and work with its Text and AutoCompleteData directly. EDIT: hmm, the only thing that we need from scintilla in that case is line's position. I suppose that this position may be get without scintilla's goto by calculating linebreaks in script text. At last, even if above is not done, I think the position may be received without calling "Goto", AFAIK Scintilla has a method to return text position for each given line, it may be exposed in ScintillaWrapper too. |
Overall, I think that this is a pretty good PR. This extra feature is achieved with a small amount of code, and is rather straightforward. The only questionable thing there is how local variables are scanned every time, but they are limited by a single function's scope, and it's rather the problem of autocomplete system. IMO it's a shame that AutoComplete does not cache local variables as it does globals. But this may be improved separately. Something that bothers me slightly in the code is that extra stuff is done under Bugs:
I suggest adding a checkable option in the panel's context menu that turns automatic local variables on and off, in case a user does not want to see them. Then, in my opinion, the context menu should not let Remove or Clear automatically added local variables. Since they get re-added after a single step anyway. To summarize:
"Add to Watch" menu command is a very nice addition, but it has couple of bugs:
|
c0a8775
to
3a9a3c4
Compare
Thanks for the review, did you not get the issue where ags occasionally locks itself? That is the biggest issue for me, I couldn't progress much because I kept hitting the locking issue, it happens when debugging a game, I noticed in my Sandwalker game but I also got it in others, if I kept using the step function it would eventually lock the game - alt+tab to it would find a hang window. @ivan-mogilko hey, I am having a hard time upgrading a 3.6.1 project to ags4, it looks like I "fixed" by using private Task SaveAndDisposeBitmapAsync(Bitmap bmp, string filename) => Task.Run(() =>
{
using (bmp)
{
string dir = Path.GetDirectoryName(filename);
Directory.CreateDirectory(dir);
bmp.Save(filename, ImageFormat.Png);
}
}); |
No, but I did not test for too long. To clarify, this locks the running game, not the editor, correct? |
Correct, the Editor keeps working, it's only the game. I will make a video to show, because it's weird, and Windows gets unhappy that the game window is hang so it does that thing where it shows the "it has stopped working" message and gives you the option to kill it. |
This may be debugged by attaching another instance of MSVS to a running game process, after it was started by the Editor. |
3a9a3c4
to
5177802
Compare
2024-11-04.20-11-35.mp4Just to show the video of what I mean, if I "step into" a few times, it's like there is some desync, I can't actually load the game because it's actually halted by the editor and just hitting play (to go to the next break point) or pause (which I think just shows the next instruction) brings the game back and you can continue debugging. I will try using two MSVS so I can attach the second one to the engine and try to pickup what is going on. Edit: erh, not sure what I was expecting... The engine is just looping in the while inside the Btw, I see I am getting a bunch of // my very small room script
Overlay* ovr[20];
function room_RepExec()
{
int max = 20;
for(int i=0; i<max; i++)
{
int randx = Random(Screen.Width-1);
int randy = Random(Screen.Height-1);
if(ovr[i] == null) {
ovr[i] = Overlay.CreateGraphical(0, 0, 2100 + Random(10));
}
ovr[i].X = randx;
ovr[i].Y = randy;
}
} |
5177802
to
9806acd
Compare
Uhm, this is an interesting idea, I tried one way of making it here The problem is... There is a bug in Windows 11 that the checkbox scales weirdly and may not be visible in context menus... (I think the bug is reported here dotnet/winforms#9258). Anyway, in my PC the checkbox is sort of hard to understand it's a checkbox. I think this could be put in the Editor Preferences and be done, and if in the future we have more needs for the watchpanel we may add some toolbar in it like the log panel. |
I do not think that this is a good reason to not add an option into context menu. That's cosmetic issue vs convenient control element. Besides, there are already multiple checkable options in the Editor's menus: "Word Wrap" in the Edit menu, and items in Layout menu. Maybe we'll have a need to have other checkable options in context menus as well. That would be annoying to have to constantly think of workarounds for each such option only because of menu drawing issue. I see following alternatives here:
Personally, I would just do p1, and then look for p2 solution as a separate task in spare time... |
Ah yes, toolbar is another good alternative.
I'll see if I can reproduce this today. |
I found that it's very easy to reproduce the hanging problem: just place a breakpoint inside a repeating script, and hold F5. It happens in a split second. My impression is that this is because _communicator.SendMessage is being called from multiple threads and its private members are not being protected by any lock. EDIT: alternatively, DebuggingController, that owns communicator, could send messages under a lock. On a separate note, the message exchange between editor and engine is implemented by waiting for an "ack" after each message, which may slow things down in theory, for very large number of messages, but idk if that's an immediate issue. |
@ericoporto I created a commit in my repo here: ivan-mogilko@145d5a9 This seems to fix the engine getting locked in the waiting state. Please try if that works for you? |
I confirm that fix makes the error go away!!!! |
I believe I did these.
I haven't yet done this, still haven't figured it out, I will try again tomorrow. |
Is not that how it currently works? Last time I checked the code, i noticed that you are inserting local variables at index 0 in the list. |
I thought it was a task list but I couldn't figure it what I did wrong. Will look into the Add to Watch issues then. |
I think I fixed the problems in the new features of auto-local vars and add to watch!
I don't plan to fix this in this PR, couldn't find a reliable way to filter for only variables. Edit: was looking into another Scintilla based custom ide that has a watch pane just now https://github.com/GeorgRottensteiner/C64Studio/blob/master/C64Studio/Documents/SourceASM.cs I think we actually managed to organize things alright but it's nice to see other "similar" projects for ideas. |
This change assumes local variables are usually meaningful in the context of the function being debugged. The user can still add and remove variables to watch, for meaningful global variables.
bff867a
to
5170507
Compare
5170507
to
626ddcc
Compare
fix winforms issue where the checkbox in context menu scales incorrectly and the tick inside the checkbox may not show in some computers.
Also, _communicator.SendMessage is called under a lock. This supposedly fixes a case when messages may be sent from multiple threads (e.g. with methods like QueryVariable).
626ddcc
to
0d4f4a1
Compare
when checked back it now shows the variables in the watch panel properly
OK, I managed to implement 1, 2, 3, 4 and 5! This PR ended up being 11 different commits, should I squash everything or better leave them as they are? The way it is I think at least documents a little why each piece of the code was added, at least per features/issues.
This is the only thing I don't plan to implement, I am leaving this one for the future. I have no idea how to properly do this. |
This change assumes local variables are usually meaningful in the context of the function being debugged.
The user can still add and remove variables to watch, for meaningful global variables.
This is a draft that perhaps should have been an issue, but anyway, I wanted to show to see what is useful or not from this. The limitation here is the
GetListOfLocalVariablesForCurrentPosition
function, which relies on parsers in both AutoComplete and ScintillaWrapper which aren't perfect - perhaps they could be improved with more testing.2024-06-19.19-55-54.mp4
Made a fix for the blinking in the video above please try and see what you think of this change.
watch_panel.mp4