-
Notifications
You must be signed in to change notification settings - Fork 117
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
Tact source code formatter #162
Comments
Good suggestion. Alternatively, we could just re-use the aforementioned prettier plugin made in tact-lang/tact-vscode.
Yes, but if anything, it would be nice to make the formatter "opinionated" and idiomatic, like the psf/black formatter for Python, or the default formatter for Golang, gofmt. That is, to figure out the optimal defaults and allow no change — this would significantly simplify all the formatting means, as all code would be in either of two states: unformatted, or formatted according to the one and only set of official rules.
I do agree. Besides, the possible static analyzer (linter) or other similar tooling too. |
Good idea! The first step could be to indeed move the code from |
The initial implementation of the formatter is available in the @heli0dus could you please take a look? You could simply fork the Before merging this, we should consider the following:
|
Does the formatter handle comments? Can't find mentions of them in its sources.
Also, regarding to configuration, I think that it's best to go into the direction of Go (gofmt), Dart (dart fmt) and Black (Python code formatter), which do not support any configuration and provide "good enough" defaults that form a standard across all code bases. So we can omit this point, I think.
We should definitely do so for trailing commas in arguments of Those (or alternative/additional) rules should probably also go under style guide |
No, since it requires changes in the frontend that should be additionally discussed. It would be great to implement this later in a separate PR, while the goal of #335 is to introduce an API for third parties and internal use that will help test the compiler itself. Our next step would be make a tool for end-users.
That's a good point. I agree that the tool could have only the default configuration. However, it might be beneficial to have configuration options in the API internals, as it could be useful for internal use to have, for example, a more concise format of the formatted code.
Agreed. I think we should also add some newlines in long binary expressions, e.g., between big numbers, as I see them a lot in the fuzzer. |
#335 implemented a pretty-printer, but we still don't have a formatter |
What do we need to prepare a production version of the formatter? From my perspective, it would be nice to:
Creating a binary and integrating it to text editors is a quite trivial task (at least for neovim). |
Sounds like a great plan! |
Good points, @jubnzv!
We'll only need to add it to the public API, then use that in the LSP — and all the clients that will be using the language server will also get formatting right away! As a bonus, we may also expose the formatter in Tact's CLI. Something like |
Currently, tact-vscode does source code formatting using a plugin for Prettier.
I believe a formatter should be a part of the language package. Also, we can have better control over how code is formatted.
Btw, since we now have a Tree-sitter grammar for Tact, formatting can be done using Topiary.
The formatter should probably be aware of tactdoc comments: #232. Or at least keep the formatting of comments intact
The text was updated successfully, but these errors were encountered: