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

Add a GDScript code formatter in the script editor #1200

Closed
aki-cat opened this issue Jul 15, 2020 · 10 comments
Closed

Add a GDScript code formatter in the script editor #1200

aki-cat opened this issue Jul 15, 2020 · 10 comments

Comments

@aki-cat
Copy link

aki-cat commented Jul 15, 2020

Describe the project you are working on:
N/A.

Describe the problem or limitation you are having in your project:
Maintaining a uniform code style between files is time-consuming, and when working with multiple people, it becomes nearly impossible.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Original Issue
I'm just ressurrecting that issue because I have been watching it and didn't find any tracker for it anymore.

The desired functionality is to automatically reformat code in GDscript editor to some standard code style (like the one in the docs, for instance). Be it everytime the user saves the script or via a specific command, or maybe even both.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
A toggle in the editor menu would activate and deactivate this feature. You could configure it to reformat the file every time you save or you could configure a command that reformats the file to a hotkey.

This would greatly help with cleaning trailing whitespaces, enforcing line column limits, and generally keeping your code clean and uniform between developers.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
It should be used fairly often by any coders with some experience. There is a third-party solution, however: Godot GDScript toolkit.

Is there a reason why this should be core and not an add-on in the asset library?:
GDScript is under constant changes and improvements. This kind of tool would work best if updated accordingly to the latest updates. Thus, being part of the core would be desirable.

@Calinou

This comment has been minimized.

@aki-cat

This comment has been minimized.

@Calinou Calinou reopened this Jul 23, 2020
@Calinou Calinou removed the archived label Jul 23, 2020
@Calinou Calinou changed the title Code style formatter in Editor Add a GDScript code formatter in the script editor Sep 13, 2020
@shinspiegel
Copy link

This is a very good idea.
How should I proced to help this idea to become a reality?

@Calinou
Copy link
Member

Calinou commented Jun 13, 2021

@shinspiegel Adding a code formatter is not a simple undertaking, so I'd recommend discussing this with @vnen if you have C++ programming experience.

Code formatters generally work by taking the script's abstract syntax tree (AST) and re-emitting it as text under a predetermined set of rules (spacing, line breaks, etc).

@shinspiegel
Copy link

@Calinou, I've almost no experience with C++, but I'm willing to learn to improve the project.

@Calinou
Copy link
Member

Calinou commented Jun 16, 2021

@Calinou, I've almost no experience with C++, but I'm willing to learn to improve the project.

If you are looking at issues that are easy to fix for new C++ programmers, I would recommend looking at issues labeled junior job on the main Godot repository.

Writing a code formatter in a high-level programming language like Python is hard enough as it is, and it'll be even harder in C++. Not to mention you'd also need to integrate it within the Godot editor, and that requires deep understanding of how the editor works.

@bluenote10
Copy link

If this gets implemented it may be worthwhile to draw inspiration from black. It's magic semantic trailing comma feature is a super powerful feature, and in general its style defaults produce very readable code, and would be sensible for GDScript as well.

@NathanLovato
Copy link

We're working on this! My teammate @Razoric480 started coding the formatter for Godot 4. The goal is to follow the official GDScript style guide and offer minimal options to customize the output (maybe line length and perhaps 1 vs 2 lines between functions, as Godot users have entire codebases using one or the other).

@NathanLovato
Copy link

After talking with the developers, we're gonna make a new proposal that explains the implementation details we're going for to make it easy for the GDScript maintainers to review and suggest a different approach.

@YuriSizov
Copy link
Contributor

Superseded by #3630 which proposes a specific implementation.

@aaronfranke aaronfranke closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2022
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

7 participants