You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-29Lines changed: 39 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,22 @@ The goal of this project is to provide a simple and fast GDScript code formatter
6
6
7
7
*You can learn more about the motivation behind this project in the [Motivation section](#motivation) below.*
8
8
9
+
## Installing and running the formatter
10
+
11
+
You can find binaries for Windows, macOS, and Linux in the [releases tab](releases) of this repository. Download the binary for your platform, unzip it, rename it to the command name you want (e.g. `gdscript-format`) and place it somewhere in your system PATH.
12
+
13
+
To format a file, run:
14
+
15
+
```
16
+
gdscript-format path/to/file.gd
17
+
```
18
+
19
+
Format with check mode, to use in a build system (exit code 1 if changes needed):
20
+
21
+
```bash
22
+
gdscript-format --check path/to/file.gd
23
+
```
24
+
9
25
## Status
10
26
11
27
Ready for daily use for commonly written code - 09/04/2025 - The formatter now has many formatting rules implemented and is ready to test. It includes:
@@ -58,6 +74,16 @@ You can insert the line returns anywhere in the array, and the formatter will ke
58
74
59
75
Contributions are welcome! I've compiled some guides and guidelines below to help you get started with contributing to the GDScript formatter. If you need more information or want to discuss ideas for the formatter, please get in touch on the [GDQuest Discord](https://discord.gg/87NNb3Z).
60
76
77
+
### Building the formatter locally for development
78
+
79
+
To build the formatter locally for testing, you need the Rust language compiler and the Rust language build system `cargo`. Then you can run:
80
+
81
+
```bash
82
+
cargo build
83
+
```
84
+
85
+
It'll download all the dependencies, compile them, and build a binary in a `target/debug/` folder. You can then run the built program with `cargo run -- [args]`.
86
+
61
87
### Adding new formatting rules
62
88
63
89
To add new formatting rules to the GDScript formatter, you can follow these steps:
@@ -86,28 +112,6 @@ Here are the most important directories and files in the project:
86
112
-`config/`: Contains configuration files for Topiary - basically a small file that tells Topiary how to run the formatter for GDScript.
87
113
-`docs/`: This folder will compile images and recaps or cheat sheets with some tricks to help when working with Tree Sitter queries and Topiary.
88
114
89
-
## Installing and running the formatter
90
-
91
-
Install Topiary's command line tool: https://topiary.tweag.io/book/getting-started/installation/index.html
92
-
93
-
Build the formatter as a program (requires the Rust language compiler, the Rust language build system `cargo`, and Topiary to be installed):
94
-
95
-
```bash
96
-
cargo build
97
-
```
98
-
99
-
Format a file:
100
-
101
-
```
102
-
cargo run -- path/to/file.gd
103
-
```
104
-
105
-
Format with check mode, to use in a build system (exit code 1 if changes needed):
106
-
107
-
```bash
108
-
cargo run -- --check path/to/file.gd
109
-
```
110
-
111
115
### Development workflow
112
116
113
117
To test formatting on a simple code snippet, you can use `echo` or `cat` to pass GDScript code into the Topiary formatter. This is useful for quick tests since the output is directly printed to the console.
@@ -176,16 +180,22 @@ MIT
176
180
177
181
## Motivation
178
182
179
-
Having an official GDScript formatter has been planned since the early days of Godot, but it has always been part of the engine's development backlog. It's a tool Godot users would use daily, so in 2022, we set out to sponsor the development of an [official GDScript formatter](https://github.com/godotengine/godot/pull/76211) built into Godot 4.
183
+
The Godot team has wanted an official GDScript formatter since the early days, but it has always been part of the engine's development backlog. It's a tool Godot users would use daily, so in 2022, we set out to sponsor the development of an [official GDScript formatter](https://github.com/godotengine/godot/pull/76211) built into Godot 4.
180
184
181
-
A lot of work went into this project from GDQuest. Then, following the suggestion to chop up the work into small chunks, a dedicated contributor, Scony, took over the project and tried breaking down the implementation [into small chunks](https://github.com/godotengine/godot/pull/97383) to make it much easier to review and merge. However, there isn't an active maintainer to review and merge the work, and the project has been stalled for a while now. The process is looking to take a long time, and we need solutions we can iterate upon quickly and use today.
185
+
We put a lot of work into this project at GDQuest. Then, following the suggestion to break up the work into smaller contributions, a dedicated contributor, Scony, took over the project and tried breaking down the implementation [into small chunks](https://github.com/godotengine/godot/pull/97383) to make it much easier to review and merge. However, there isn't an active maintainer to review and merge the work, and the project has been stuck for a while now. The process looks like it will take a long time, and we need solutions we can work on quickly and use today.
182
186
183
-
Scony has been maintaining a solid set of community tools for GDScript, including a code formatter written in Python: [Godot GDScript Toolkit](https://github.com/Scony/godot-gdscript-toolkit). It's a great project that has been used by many Godot developers. So, why start another one?
187
+
Scony has been maintaining a solid set of community tools for GDScript, including a code formatter written in Python: [Godot GDScript Toolkit](https://github.com/Scony/godot-gdscript-toolkit). It's a great project that many Godot developers have used. So, why start another one?
184
188
185
-
The main motivation to experiment with this project is that the ruleset of Scony's formatter has grown quite advanced over the years, and it has limitations for us at GDQuest that make it not work for our projects. Some of these limitations are also not easy to overcome.
189
+
The main reason to try this project is that Scony's formatter has grown quite complex over the years, and it has limitations for us at GDQuest that make it not work for our projects. Some of these limitations are also not easy to fix.
186
190
187
-
Since Scony made his great formatter, new technologies have emerged that make it much easier to implement and maintain one. Thanks to Tree Sitter and Topiary, in just a couple of hours, you can now kickstart a code formatter that can be compiled to native code and used in any code editor or IDE.
191
+
Since Scony made his great formatter, new technologies have come up that could make it much easier to build and maintain one: Tree Sitter and Topiary. This project started as a suggestion from one of Godot's core contributors to test these new technologies for GDScript formatting. While testing it, I could get results within just a couple of hours and found it to be a very promising approach that could lead to a simple and fast formatter that's relatively easy to maintain and extend for the community.
188
192
189
-
**Tree-sitter** is a powerful parser generator that makes it easy to create programming language parsers that run natively (it generates C code). It gives you a simple query language to detect patterns in the code and process them, a bit like CSS selectors (but simpler and more restricted). It's used in modern code editors for syntax highlighting, code navigation, outline, folding, and more (Zed, Neovim, Emacs, Helix, Lapce...).
193
+
<details>
194
+
<summary>What is Tree-sitter?</summary>
195
+
Tree-sitter is a powerful parser generator that makes it easy to create programming language parsers that run natively (it generates C code). It gives you a simple query language to find patterns in the code and process them, a bit like CSS selectors (but simpler and more limited). It's used in modern code editors for syntax highlighting, code navigation, outline, folding, and more (Zed, Neovim, Emacs, Helix, Lapce...).
196
+
</details>
190
197
191
-
**Topiary** is a Rust library and command line program that makes it easy to implement a code formatter using a parser based on Tree Sitter. You use the Tree Sitter query language to define how the code should be formatted, and Topiary takes care of the rest.
198
+
<details>
199
+
<summary>What is Topiary?</summary>
200
+
Topiary is a Rust library and command line program that makes it easy to build a code formatter using a parser based on Tree Sitter. You use the Tree Sitter query language to define how the code should be formatted, and Topiary handles the rest.
0 commit comments