Skip to content
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

Preserve script state (breakpoints, bookmarks, folding) after closing a script in the editor #37

Closed
iwek7 opened this issue Sep 5, 2019 · 5 comments · Fixed by godotengine/godot#53235
Milestone

Comments

@iwek7
Copy link

iwek7 commented Sep 5, 2019

What is proposed

Right now when editor code tab closes information about breakpoints and bookmarks is erased. I would like those data to be kept somewhere so that when you reopen closed tab bookmarks and breakpoints are still there. This is very basic feature of any IDE and Godot should support it too.

Describe implementation detail for your proposal (in code), if possible:

So long story short - information about breakpoints and bookmarks is kept in godot configuration fie editor_layout.cfg as a part of script metadata in open_scripts section. When you close editor this section remains intact therefore when you open godot again breakpoints/bookmarks get reloaded correctly. However when you close tab it gets deleted form open_scripts section and info about breakpoints/bookmarks is lost.

I think we sould keep this information at all times - either separate section could be added to one of config files (and removed from open_scripts section) or separate config file could be kept for this. After opening script then we could do lookup in this section to find breakpoints for the file.

Describe the project you are working on:

2D card game, irrelevant to the task.

Describe how this feature / enhancement will help your project:

Will improve debugging and bookmark usage

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

don't have any

If this enhancement will not be used often, can it be worked around with a few lines of script?:

No it can't. Workaround is not using Godot code editor or not closing code tabs at all.

Is there a reason why this should be core and not an add-on in the asset library?:

Quite obvious - its an build-in editor feature.

Am I willing to work on this?

Yes I'd gladly provide PR for this, all I need is to consult with some core dev about how to implement it as I fear tinkering with config files can break backwards compatibility.

Ps. please add to the proposal template some point like 'explain feature' (like I added at the top) I feel like I could fill current template and provide 0 information about what I want to do.

@Calinou
Copy link
Member

Calinou commented Sep 5, 2019

Was this implemented by godotengine/godot#27979? Still, if you wish your breakpoints to be stored in a more reliable way, you can write the breakpoint keyword anywhere or use the assert() function, which will break if the condition evaluates to false:

var x = 5

# Condition is true, will enter the block and break
if x == 5:
    breakpoint

# Evaluates to `true`, won't break
assert(x == 5)

@iwek7
Copy link
Author

iwek7 commented Sep 5, 2019

Hi Calinou, I've seen that PR and it does not implement what I am asking for. Paul keeps track of breakpoints in open tabs section in config file (as explained in post). If tab is closed it is gone from this section and so are the breakpoints.

Consider following gif:
breakpoint

Here I do following:

  1. Add Breakpoint
  2. save file
  3. close file
  4. open file
  5. breakpoint is gone

Check it out in pretty much any other IDE you can name - add breakpoint, close file, open it and breakpoint will be there (from the ones I've used Intellij, QTCreator and Eclispe work like this).

Regarding breakpoint keyword I know that you can argue that it is substitute for real breakpoint feature (or even for conditional breakpoints) but in my opinion you should not be forced to modify your source code to do the job IDE fails to do - in this case to preserve breakpoints after closing files.

@iwek7
Copy link
Author

iwek7 commented Sep 5, 2019

Also what I'm showing if from master e205cbbd0 for what it's worth,

Edit:
and that is the very section of editor_layou.cfg where breakpoint info is kept:
image

@Paulb23
Copy link
Member

Paulb23 commented Sep 7, 2019

This makes sense, I would extend it out to include the rest of the metadata already stored, not just breakpoints and bookmarks.

For implementation, as the user could have quite a lot of scripts, I would lean towards storing this in a separate ConfigFile called something like script_editor_states.cfg. Writing the full metadata when when a script or the engine is closed. With a lookup in place, the editor_layout.cfg can be reverted back to only contain a list of scripts, rather then the full state, keeping backwards compatibility in mind.

The difficulty comes in trying to handle built-in scripts (if we even should?) as they are not currently restored on load. In addition to this, preventing the script_editor_states.cfg from becoming bloated with scripts that don't exist or have been renamed ect, especially in a very large project. As of right now that section is cleared and written afresh on engine close.

@iwek7
Copy link
Author

iwek7 commented Sep 8, 2019

Hi Paul, thanks for answer and guidance on this.

Regarding update of script_editor_states I will try to update metadata when scripts are renamed/removed by godot. However, this will not prevent situation in which something is changed directly in filesystem (not via godot). Perhaps we could put some process in place that will analyze contents of script_editor_states.cfg at godot startup and remove entries for scripts that does not exist anymore so that content of the file will be kept in reasonable check.

I will start working on PR for this but scope seems big so it will take some time. Perhaps for starters I will move only metadata of bookmarks and breakpoints to script_editor_states.cfg and the leave the rest of metadata for later.

@Paulb23 Paulb23 changed the title Don't delete the data about breakpoints/bookmarks after closing file Don't delete the data about script state (breakpoints,bookmarks,folding) after closing file Sep 4, 2021
@Calinou Calinou changed the title Don't delete the data about script state (breakpoints,bookmarks,folding) after closing file Preserve script state (breakpoints, bookmarks, folding) after closing a script in the editor Sep 29, 2021
@akien-mga akien-mga added this to the 4.0 milestone Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants