godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Add a shortcut to create a method definition in the script editor #8479

Open jrfilms89 opened 11 months ago

jrfilms89 commented 11 months ago

Describe the project you are working on

A Mother-like top-down 2D RPG.

Describe the problem or limitation you are having in your project

When coding you may call a func name before the function has been written out in the script. This then requires you to go to the bottom of the script and manually type out the required function header. In Visual Studio, there is a implement method shortcut that will generate the empty method for you so you can continue coding without error pop ups before continuing onto the newly created method, or jumping straight into the method via shortcut key.

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

Adding shortcut keys to generate the new function from the call you just typed, and a shortcut key to jump straight into that function your text cursor indicator is currently on. This quickens the scripting process, keeps your hands on the keyboard, and reduces redundant typing. Quality of life improvement for long scripting hours.

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

Similar to how a Signal generates the function in the connected script. Just having the ability to generate an empty function after typing out some code that calls it.

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

This can be worked out with a plugin, but since the functionality already exists for signals, it should easily be turned into a shortcut/drop down box option in the IDE for GDScript.

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

This is simple functionality can save countless hours from the whole community with the amount of time developers spend manually writing out functions after pre-calling the function somewhere else in the code. With games requiring hundreds of scripts, hundreds of games being worked on everyday, and hundreds of people writing code for multiple hours everyday, this implementation will be a huge pay off for a minor update.

Having this be hidden in an add-on or plugin would be a waste of opportunity for GDScript and Godot and only cause many developers to miss out on a quality of life shortcut key.

AThousandShips commented 11 months ago

IMO this would be a backwards workflow, what's wrong with just writing the function first before using it? In my opinion you should write code with intentionality, and if you do you'll never end up in a situation where you call a function before you've set up the prototype for it, and planned it out, that's my workflow

This is simple functionality can save countless hours from the whole community with the amount of time developers spend manually writing out functions after pre-calling the function somewhere else in the code.

This is just hyperbole, it takes a second to type out the prototype, and you still have to fill in the function, so you're not saving any time

While I think this might be a useful feature to have, I disagree with the notion it's an important part of the editing process and that it solves real issues other than convenience

Calinou commented 11 months ago
KoBeWi commented 11 months ago

This then requires you to go to the bottom of the script and manually type out the required function header.

You can go to bottom using Ctrl+End. If you leave a bookmark before jumping you can easily go back to where you wanted to call the method, so the time required is minimal.

RedMser commented 11 months ago

Can't find a proposal for this right now, but what about opening a "Quick Actions" menu on errors? So the missing function definition causes an error, and you could press a shortcut or button to pop up a menu to generate the missing function definition. Kind of like the 💡 menu accessible through the gutter in Visual Studio and VSCode.

2Q==

jrfilms89 commented 11 months ago

You're logic is what's the point of shortcut keys, essentially. Why press Ctrl+V to paste when you can just move your mouse to the Edit drop down list and click paste from there? Because it saves a small amount of time. But this small amount of time scaled can equal a significant amount of time.

The way I code is forward thinking. As do my colleagues. We will be coding inside a function block and know that we want to call to a new function for different logic handling. So we end up typing out the undeclared function name as we are continuing our train of thought in that particular block of code, before continuing on to fleshing out the function we had just called earlier. By having a quick shortcut combo we can press after typing the undeclared function name (like in Visual Studio) we can in an instant without breaking our train of thought, generated that function as an empty but ready to code in method at the bottom of our script.

Not having to type out generic line of code like this when you type thousands to hundreds of thousands of lines of code, adds up over time.

For some, this may seem backwards workflow. But if you know how you are wanting to implement some logic and how you want to structure your code, it happens often where you will type out _some_function() before you have created that function and you may want to finish whatever logic you want to come after that line of code before jumping in and working inside the new method block.

I apologize if I debate redundant points, I just know that the years I've spent in software and all the colleagues I've worked along side in the C#/Visual Studio space, that we often used these shortcut features and they are magical as time-savers and for quality of life.

On Mon, Nov 20, 2023, 04:28 A Thousand Ships @.***> wrote:

IMO this would be a backwards workflow, what's wrong with just writing the function first before using it?

This is simple functionality can save countless hours from the whole community with the amount of time developers spend manually writing out functions after pre-calling the function somewhere else in the code.

This is just hyperbole, it takes a second to type out the prototype, and you still have to fill in the function, so you're not saving any time

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot-proposals/issues/8479#issuecomment-1818580746, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP4MRCEM6N3K2VHHECOLB3TYFMPDPAVCNFSM6AAAAAA7SJFCDOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJYGU4DANZUGY . You are receiving this because you authored the thread.Message ID: @.***>

AThousandShips commented 11 months ago

I genuinely do not think the workflow of calling a method before you declare it often enough that you'd need this functionality makes any sense and I've never had that problem myself in my +15 years of programming, and I don't see how it saves any time to do this, you still need to fix with the argument names and return type, I still argue that the claims of this saving "countless hours" is hyperbole in the extreme

Again I think that this is a potentially useful feature, but needs to be evaluated from a perspective based on the usefulness of it and necessity, and I genuinely think that if having this significantly eases your workflow because you keep needing to break your flow and declare a method, you should first work on your workflow

But that's my opinion on this, but I don't think I'm alone in thinking this workflow is backwards

jrfilms89 commented 11 months ago

I do respect your opinion and thought on the topic. I Feel I should say that because I feel my last comment seemed a little harsh. Truly wasn't intended if it came across that way.

And I agree this feature would just be a quality of life improvement and not a necessary feature. But there are many things we can say that are in all programs that are just for quality of life and can make a huge difference to the experience.

Sure there isn't necessarily an immediate issue to require this to be fixed asap, but still I see it as a missed opportunity to not have this in its closed ecosystem.

Does this make or break it as an engine? Of course not. Do I think this requires immediate attention? Definitely not. But as a newer user in Godot and trying to go all in on its ecosystem, it's something I'm just shocked doesn't exist when the concept is already there when creating Signals from the editor.

On Mon, Nov 20, 2023, 17:05 A Thousand Ships @.***> wrote:

I genuinely do not think the workflow of calling a method before you declare it often enough that you'd need this functionality makes any sense and I've never had that problem myself in my +15 years of programming, and I don't see how it saves any time to do this, you still need to fix with the argument names and return type

Again I think that this is a potentially useful feature, but needs to be evaluated from a perspective based on the usefulness of it and necessity, and I genuinely think that if having this significantly eases your workflow because you keep needing to break your flow and declare a method, you should first work on your workflow

But that's my opinion on this, but I don't think I'm alone in thinking this workflow is backwards

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot-proposals/issues/8479#issuecomment-1819880009, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP4MRCF3V47YCFYJB5T76L3YFPH4NAVCNFSM6AAAAAA7SJFCDOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJZHA4DAMBQHE . You are receiving this because you authored the thread.Message ID: @.***>

RealityStop commented 4 months ago

Coming from other languages and IDEs, this is definitely a missed feature. I encounter this exact situation nearly every time I connect a signal. Due to my own idiosyncrasy, I do not connect signals in the Node tab, as I do not like "untraceable" references when I refactor something, and I instead wire all signals in code. This may sound backwards to you, and I don't propose that it is a better workflow, but it does have its benefits. I can simply search for all references to my signal, I can easily know if it is safe to delete a signal, etc. And I feel that it should be a supported workflow.

Most of the time, I'm creating a new function to handle the signal response (unless trivial (ex: queue_free()) and I'll type a name I want it to have and then I have to manually construct the function and arguments every time. For some signals, this is quite involved, to the extent that sometimes I will use the signal editor to create the function, then use the signal editor to delete the connection, leaving me with the implemented response function with the proper arguments that I can reference in the connect() call.

It works, but if the signal type is known (and other instances where a Callable with known arguments is present), can a modified process be used to create the function prototype and save the manual effort of setting up the arguments?

The current best-implementation Rider plugin does include these features (https://gitlab.com/IceExplosive/gdscript/-/blob/master/documentation/features/features.md), but it would be nice to have this feature in the built-in script editor to mimic the UI workflow.