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 GDScript formatter #521

Closed
wants to merge 2 commits into from

Conversation

DaelonSuzuka
Copy link
Collaborator

This PR adds a formatting provider, which currently just execs gdformat or a compatible formatter.

I'm also working on a builtin formatter, which will most likely use tree-sitter, get compiled into a wasm package, and included directly in the extension. Unfortunately, tree-sitter and the surrounding ecosystem has truly been a nightmare to try and get started in.

@chrisl8
Copy link

chrisl8 commented Oct 27, 2023

This PR adds a formatting provider, which currently just execs gdformat or a compatible formatter.

In case you weren't aware, there is a VSCode plugin to run gdformat:
https://marketplace.visualstudio.com/items?itemName=Razoric.gdscript-toolkit-formatter

It also automatically installs gdformat if required.

It works well from my experience.

I'm also working on a builtin formatter, which will most likely use tree-sitter, get compiled into a wasm package, and included directly in the extension. Unfortunately, tree-sitter and the surrounding ecosystem has truly been a nightmare to try and get started in.

Are you planning to write a formatter from scratch? Very impressive!

@DaelonSuzuka
Copy link
Collaborator Author

In case you weren't aware, there is a VSCode plugin to run gdformat:

There's like 3 of them now for some reason. And Razoric's doesn't have the word "Godot" in the title or the description, so it only shows up when you search for "gdscript".

It works well from my experience.

It's alright. gdformat modifies the file on disk, which has negative interactions with things like unsaved changes in the editor buffer. VSCode has a proper internal API for this that handles it more responsibly.

Also python is... not a great choice for this kind of tooling.

Are you planning to write a formatter from scratch?

The formatter is already ~half done. The hard part is definitely the absolutely horrible packaging experience I've been having.

@Calinou
Copy link
Member

Calinou commented Oct 27, 2023

@DaelonSuzuka
Copy link
Collaborator Author

Note that a built-in GDScript formatter in Godot is being developed.

I knew that was happening but hadn't checked on it in a while. Am I correct in interpreting that it's a godot4-only effort? I would imagine it's not trivially cherry-pick-able for 3.x.

This PR adds an enum setting to let the user pick between gdformat and builtin. It'll be easy enough to add a third lsp option whenever the official one is usable.

@Calinou
Copy link
Member

Calinou commented Nov 3, 2023

Am I correct in interpreting that it's a godot4-only effort?

Yes 🙂

@DaelonSuzuka
Copy link
Collaborator Author

I decided to just implement this in #529 due to laziness.

@DaelonSuzuka DaelonSuzuka deleted the formatter branch January 6, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants