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

Suggest class name after class_name based on script file name #2279

Open
me2beats opened this issue Feb 11, 2021 · 4 comments
Open

Suggest class name after class_name based on script file name #2279

me2beats opened this issue Feb 11, 2021 · 4 comments

Comments

@me2beats
Copy link

Describe the project you are working on

Editor plugins (gdscript)

Describe the problem or limitation you are having in your project

When creating custom classes using class_name I almost always give them a name that is similar to their scripts file name.
Precisely speaking, I first come up with the class name say MyClass then I create a script my_class.gd and write there class_name MyClass.
Doing this often can be a bit annoying considering this could be automated.

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

The idea is use autocompletion for that.

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

When a script my_class.gd is created, I just could type cla and then autocompletion could appear with the custom class name based on the script name, that is class_name MyClass could be suggested in this case.

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

Well, you just could write class name manually every time, or you could somehow copy-paste script file name and then change it to PascalCase. But this is not convinient.

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

Solving the problem using autocompletion with a plugin (al least with gdscript one) is not available now, because there is no API for working with autompletion.

But I can see some options of how to solve it:

  • a plugin that adds class_name MyClass line to current script; this would be hacky due to lack of exposed ScriptEditor API (for example this one)
  • a plugin that creates a script by class name (it opens a popup where you specify the class name MyClass, and when confirmed, it creates a script in the folder selected in the filesystem dock, with name my_class.gd and adds class_name MyClass line there); this could be fine, but this may be inconvenient / not enough if you have already created a script and only then decided to make it a custom class

However despite the possibility of creating a plugin that solve the problem, I find it useful to have this in core.

@Xrayez
Copy link
Contributor

Xrayez commented Feb 12, 2021

The engine has snake_case to PascalCase methods to help implementing this proposal: #719.

@dumenglume
Copy link

Would love to see this added (if it isn't implemented somewhere already). I can't actually think of any downside to implementing this. Folks who don't want class names to automatically be added can just leave the field blank.

@tetrapod00
Copy link

tetrapod00 commented Oct 28, 2024

This is a good idea, but IMO better overall UX would be to not require typing the name at all. The Create Script window could have another checkbox/toggle to automatically create a class name (or [GlobalClass] in C#). If the Named class checkbox is checked, this script would be created with the first line class_name NewScript extends Node.

godot windows editor x86_64_b9Ex27UDve

@Calinou
Copy link
Member

Calinou commented Oct 28, 2024

There used to be a class name option in the script creation dialog, but it was removed in 4.2 as it was a read-only field that was always N/A when using GDScript:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants