godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Implement clicking Output panel lines to open the script and line number the `print()` was called from #9367

Open teebarjunk opened 6 months ago

teebarjunk commented 6 months ago

Describe the project you are working on

Being able to click an Output message and go directly to where it was called from can save a lot of development time.

Describe the problem or limitation you are having in your project

Sometimes it is hard to track down where a print() statement is being called from, especially while debugging on a large project.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Clicking an Output line takes you to the script and line where print was called from.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I've implemented this as a plugin here: https://github.com/teebarjunk/output_link

It uses the new print_rich() function, passing a reference from get_stack() script like [url=stack.script|stack.line]Printed message here.[/url]

Either when using the print() commands, or a new print_from() command, pass a reference to the stack script path and line number, then in the Output RichTextLabel, wrap [url][/url] tags around it, and connect a function to the meta_clicked signal that will move the editor to the line.

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

It can be worked around.

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

Every type of project could benefit, especially large ones that need more intense debugging.

And all the necessary features are already in place to implement.

kleonc commented 6 months ago
How would it work with duplicate messages collapsing enabled? Godot_v4 2 1-stable_win64_zzlRwLrRRz Godot_v4 2 1-stable_win64_GwHZhpwgWJ
teebarjunk commented 6 months ago

Didn't even know about that feature.

Just tested it in my implementation here and it automatically grouped them into separate "clumps" when called at the same line.

Screenshot_20240324_102459Screenshot_20240324_102516

Calinou commented 6 months ago

If you make all output text clickable, it'll become hard to select for copying. The clickable area should likely be located within a gutter on the left of the actual text to prevent usability from regressing on this aspect.