slint/tools/fmt
Tobias Hunger d785f2d5df compiler: Store an optional version number with the document
A None value means the file on disk is the golden version.

We have an editor, the LSP and the preview that all need to at least
notice when they have newer data then their peers. So IMHO it makes
sense to have an optional document version around.

The language server protocol makes use of a version number already. This
patch moves that code into the compiler so that it is stored with the
actual data getting versioned.
2023-12-18 14:21:50 +01:00
..
Cargo.toml janitor: Use workspace dependnecies for the slint crates 2023-09-25 16:34:16 +02:00
fmt.rs compiler: Store an optional version number with the document 2023-12-18 14:21:50 +01:00
lib.rs Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
main.rs compiler: Store an optional version number with the document 2023-12-18 14:21:50 +01:00
README.md reuse: remove glob for markdown files 2023-08-17 08:55:28 +02:00
writer.rs Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00

Slint-fmt

This tool for formatting .slint syntax is in a very early stage. There might be certain parts of the language that are not yet supported. If you find any such examples, please open an issue including the example and the expected output.

Building

Use cargo build --release or similar to build this crate.

Usage

The built binary can be used in following ways:

  • slint-fmt <path> - reads the file and outputs the formatted version to stdout
  • slint-fmt -i <path> - reads the file and saves the output to the same file
  • slint-fmt /dev/stdin - using /dev/stdin you can achieve the special behavior of reading from stdin and writing to stdout

Note that .slint files are formatted, while .md and .rs files are searched for .slint blocks. All other files are left untouched.

Usage with VSCode

While we don't yet have a proper VSCode integration for this formatter, here is a simple way how you can get around it.

  1. Install the extension Custom Format by Vehmloewff. Marketplace link
  2. Build slint-fmt locally.
  3. Add a section like this to your vscode settings.json:
{
  "custom-format.formatters": [
    {
      "language": "slint",
      "command": "/path/to/your/built/slint-fmt /dev/stdin"
    }
  ]
}
  1. (Optional) Allow formatting or save, or set this formatter as default for .slint files.
  2. Enjoy! Your .slint files are now formatted.