mitranim / sublime-rust-fmt

Sublime Text plugin that formats Rust code with rustfmt
30 stars 3 forks source link

Use correct rustfmt.toml by traversing up the directory tree #3

Closed LukasKalbertodt closed 6 years ago

LukasKalbertodt commented 6 years ago

When formatting buffers corresponding to a file on disk, it would be nice to get the same behavior as when executing rustfmt from the command line: it searches for a rustfmt.toml starting at the directory of the file and going up from there. As far as I can see, this plugin does not search for a rustfmt.toml at the moment..

mitranim commented 6 years ago

Thanks for raising the issue.

Should be fairly easy to support by passing the current directory to rustfmt as --config-path and letting it find the config by itself. Unfortunately, the feature only works in rustfmt-nightly, which fails to run on my system. Fairly safe to assume that many others use the regular rustfmt. Should probably wait until it stabilizes.

LukasKalbertodt commented 6 years ago

Oh, I see. I do use the nighlty version via "executable": ["rustup", "run", "nightly", "rustfmt"]. Maybe we could add a flag unstableFeatures in the settings to enable things like this? I don't expect rustfmt to stabilize anytime soon tbh :/

Apart from that: I'm fairly sure even the old (stable) rustfmt was configurable via rustfmt.toml and that it would also traverse all parents directories until a configuration file is found. Maybe this plugin could start rustfmt in the directory of the file being formatted(*)? Shouldn't that work?

(*) Or maybe: path of sublime project if a project is opened, otherwise path of file being formatted.

mitranim commented 6 years ago

There's actually a fresh pull request for that. Until it's merged, you could pull from csmulhern/sublime-rust-fmt and see if it works for you, or suggest changes if not.

mitranim commented 6 years ago

Released 0.1.5 with support for config files. Let me know if it works for you.

LukasKalbertodt commented 6 years ago

Works for me :)

Thank you and @csmulhern for solving my issues with this plugin so quickly!