-
Notifications
You must be signed in to change notification settings - Fork 919
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
Consider CLI option for cargo.toml path & pull settings out of cargo.toml #4074
Comments
hey @mitranim - my thoughts below on a few specific points (many of which you noted in the linked thread).
IMHO, we should not attempt duplicate that behavior within $ echo "fn main () { }" | rustfmt --check
Diff in stdin at line 1:
-fn main () { }
+fn main() {}
rustfmt allows for config options to specified via the cli, but it also supports configuration via the One such thread where this has been discussed: (below quote cross posted comment from the author of the linked issue)
I'd disagree with this for the above reasons. If folks are running I think the main driver is that the default edition in rustfmt 1.x is |
@calebcartwright Editor plugins don't have a good way to use My editor plugin is the only place I run Changing rustfmt's default edition to 2018 is a different issue. I feel that with the 2021 edition on the horizon, we'll run into this same issue again in a year! There are also still 2015 edition projects that I contribute to, and it seems useful for rustfmt to stay configured with the correct edition for those by default. |
hi @LPGhatguy 👋 I understand that it'd be convenient in some situations to have rustfmt auto-detect the edition, and why you'd prefer that solution for your use case of auto-running rustfmt in your editor. However, there are cons with having the I know you'd prefer not to, but my suggestion for you is still to include a rustfmt.toml config file in your projects that need the 2018 edition. As I mentioned above, it's not uncommon for folks to do this and/or add the cli edition override when running directly. I've included a few examples for reference. https://github.com/rust-lang/rust-clippy/blob/master/rustfmt.toml#L5 FWIW, there's a lot of similarities here with Ultimately though, this is up to @topecongiro. If the decision is to include auto-detection of edition to the lib and/or cli, then I'm happy to help implement and support it. I just don't think that's the right solution, and I believe easiest and quickest solution for your use case is to include a rustfmt config file with the edition. |
@calebcartwright If |
No worries!
I wouldn't recommend editors try to use
@mitranim I know you don't want to deal directly with toml parsing in your extension, but if you'd like to support the use case, would something like running the |
Thanks for all the considerations. On my system, in a small Cargo project, getting the edition via I can see the value of keeping |
What do you think, how realistic is it to add stdio support to |
Ultimately the ask here, as I understand it, is to have the ability to format a single file with a non-default edition without having to tell rustfmt which non-default edition to use. Is that correct? |
Apologies for the slow response, been using the weekend to unplug. The ask is a bit more general: have the Rust formatting tools (either |
No worries @mitranim
Besides the Edition, what specific other data points from Cargo do you feel your editior plugin needs to pass to rustfmt? Perhaps I'm forgetting something, but I think you may be overestimating the quantity of data points from Cargo that are used for rustfmt. There's really only a handful of core items that
There's some minor transformation of optional args/flags folks expect to see with any no. 1 consists of all the entry point files for every target for every package within the workspace, and obviously no. 2 comes from the detected editions, and these are the only Cargo configuration data points that are detected and passed to For example in the case of a simple lib project, running In the context of a "format modified file on save" capability within an editor plugin, you definitely wouldn't want to run
I'd still suggest what's needed is not general, but very specific to the edition for the reasons outlined above. For a format-on-save feature, the only arg that should be passed to The only concrete ask I see is to have something in the rustfmt ecosystem detect that edition value so that editor plugins don't have to. Basically, "something" that results in -->
I'm slightly less opposed to trying to add this within IMO trying to support this particular use case directly within |
Oh, I thought I responded, but didn't actually send it. 🤦♀ I apologize for taking so much of your time with this. I can see where you're coming from. Between final users, plugins, |
It's not really a question about additional settings on the rustfmt side. It's just that something needs to provide a value for the edition setting to rustfmt, and rustfmt recommends users do that via the rustfmt config file. However, it seems it's common for editor plugins to provide a format-on-save feature to users even in the absence of users providing that edition value to rustfmt (config file, editor config/settings, etc.). That's a bit of an edge case relative to the main rustfmt cases IMO, though I do agree that it'd be valuable if something in the rustfmt ecosystem supported that use case so individual editor plugins didn't have to each re-invent their own solution. I just think that it'd be easier for that use case to be supported by something new vs. trying to cram it into rustfmt-on-save file-just-modified.rs which would be capable of detecting the corresponding edition and translating into the corresponding rustfmt file-just-modified.rs --edition 2018 There's other binaries included with the rustfmt package (like Maybe something like that could be done in the long term, but for the foreseeable future users would be better off following the rustfmt recommendation to include the rustfmt config file. |
Had this problem with enabling the format-on-save feature in emacs/rustic-mode. Ended up just configuring rustic-mode to always specify Thinking about the problem, I don't understand why The current awkwardness of having to specify the I think reasonable handling would be to check for a project file named |
Thanks to everyone for sharing your perspective! However, I'm going to close this issue because it's gotten too lengthy and hyperfocused on a single, non-viable solution to a problem such that it's no longer a great fit for discussion of the problem itself. The root problem is that editor/ide plugins don't have a manner in which to format a single file in a cargo-aware manner. This is exacerbated by the fact that Editor/IDE plugins would run into this exact same issue if they needed to run other tools directly, e.g. We're simply not going to address the problem with the proposed solution because it's not the right approach. The separation between the cargo-aware tooling/wrappers and direct/non-cargo-aware tooling is intentional and we're not going to break that. We do, however, already have a better solution to the problem that's already in progress and largely complete from a technical perspective. It's just pending on process due to the type of change it may introduce. I will post a note here once we've gotten that in place for broader awareness. |
Your point about keeping As an aside once such a command exists I think it'd make sense to deprecate the After my above comment, I'd already put together a quick self-contained update to Thinking about it overnight, another better angle could be to support formatting individual files in I think in an ideal world the syntax would look like this, where the files would be provided via positional arguments before any
Here's some example usage, which notably are all invalid commands in today's
You'd mentioned that there's already a plan in the works elsewhere for supporting formatting individual files, what is the venue for that discussion? As may be apparent I've got opinions... In the meantime I'll see about putting together another example demonstrating individual file support via |
@nickbp thanks for sharing your ideas on this. For your reference @calebcartwright and I are working to support single file formatting in
So to reiterate we've got most of the implementation details down, but there are still a few things that we need to think through before it's 100% ready (mostly around the interaction of certain conflicting command line options). Feel free to take a look at the thread and leave some feedback there! Although the PR was opened some time ago I've been prioritizing some other rustfmt initiatives and plan to come back to it when those have wrapped up! |
OK that's great! Thanks for the info, and for already putting so much effort into the fix. I'll follow along in the PR. I'll leave a comment about the above |
This is based on the discussion in mitranim/sublime-rust-fmt#11. Users expect
rustfmt
to be run with respect tocargo.toml
settings such asedition
. Currentlyrustfmt
supports them as CLI options. One option for plugins is to parsecargo.toml
, pull out these options and pass them torustfmt
, example: rust-lang/rust-analyzer#2477. I feel like it's the wrong approach. Let's simply pass torustfmt
the location ofcargo.toml
, and have it pull out any settings it supports.This way:
rustfmt
CLI options don't have to grow (maybe).Speaking of giving
rustfmt
the config file location. Maybe we could haverustfmt
automatically look for all the config files it supports, and simply tell it the innermost directory where to start the search? This way, editor plugins don't have to be updated in the future to support yet another config file. Thoughts?The text was updated successfully, but these errors were encountered: