Skip to content

codeitlikemiley/leptos-fmt

Repository files navigation

leptos-fmt

Open VSX | Vscode Marketplace

Open VSX Downloads Vscode Marketplace

Uses the built in Rust analyzer to auto-format your Leptos code. You can invoke command palette command with Leptos Init to generate the override command on your .vscode/settings.json file.

For Complex Project , and you dont want to override fmt on workspace level, and avoid pulluting override command on other projects.

You can invoke command palette command with Format with Leptosfmt or bind it to a key.

Demo

Demo

Requirements

  • Rust: Ensure you have Rust installed on your machine.
  • Leptosfmt: This extension requires leptosfmt. Install it using:
cargo install leptosfmt

Using built in Rust Analyzer (rust-lang.rust-analyzer)

  1. Press Ctrl+Shift+P to open the command palette.
  2. Type Leptos Init to any Leptos project.
Note: it would generate this on `.vscode/settings.json`
{
    "rust-analyzer.procMacro.ignored": {
        "leptos_macro": [
            "server"
        ]
    },
    "rust-analyzer.rustfmt.overrideCommand": [
        "leptosfmt",
        "--stdin",
        "--rustfmt"
    ],
    "rust-analyzer.cargo.features": [
        "ssr"
    ]
}

Custom Key Bindings

Screenshot 2024-11-12 at 7 29 24 PM
  1. Press Ctrl+Shift+P to open the command palette.
  2. Type Keyboard Shortcuts to open the keyboard shortcuts settings.
  3. Search for leptos-fmt.format
  4. Bind it to a keybinding to your preference e.g. OPT + SHIFT + F

Custom Paths

Screenshot 2024-11-12 at 7 28 03 PM
  1. Press CMD or CTRL + , to open the settings.
  2. type leptos
  3. find leptos-fmt.path and set it to the path of your leptosfmt binary
  4. find leptos-fmt.cargoHome and set it to the path of your cargo home directory