bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
258 stars 27 forks source link

vs code rustfmt override dosen't use project leptosfmt.toml #113

Closed Root-Time closed 1 month ago

Root-Time commented 7 months ago

Could we add an option that is possible that the override at rust-analyzer.rustfmt.overrideCommand uses the project config file?

jonsaw commented 6 months ago

I got it to work by changing the .vscode/settings.json override command to this:

{
    "rust-analyzer.rustfmt.overrideCommand": ["leptosfmt", "--config-file", "${workspaceFolder}/leptosfmt.toml", "--stdin", "--rustfmt"]
}
bram209 commented 3 months ago

Is this only a problem with workspaces, or with standalone cargo projects as well?

fiadliel commented 2 months ago

Even without a workspace, hx src/app.rs has the CWD of src/ (tested with recent helix, replacing the override command with pwd). This makes it hard to use any configuration value that isn't mirrored in flags, e.g. attr_value_brace_style will become more important to configure shortly.

It might be worth using the approach of rustfmt, which is to recursively look in parent directories up to the root, viz. https://github.com/rust-lang/rustfmt/blob/88944668fec947339291d04e6f0b9c4392cea937/src/config/mod.rs#L263

fiadliel commented 1 month ago

I think the issue comes from here: https://github.com/rust-lang/rust-analyzer/blob/935883fd826c46e7e7e6de19cf24377c21f1b2ba/crates/rust-analyzer/src/handlers/request.rs#L2188

R-A changes the working directory to the path of the file being formatted, to try to pick up any local rustfmt.toml files.