-
Notifications
You must be signed in to change notification settings - Fork 925
Add project-specific configuration file support. #165
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
Conversation
|
||
use toml::Parser; | ||
|
||
// Tries to read a file and parse the conents as a toml table. Panics on error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: contents
That looks good, I would just move the new methods from |
|
||
run(args, WriteMode::Overwrite, &def_config); | ||
let def_path = get_default_file(); | ||
println!("Default config file: {}", def_path.display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be info!
, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project doesn't have the log crate, idk if I should add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already using rust-lang/log.
I haven't moved anything yet, what parts do you think should move? TOML merging? Path lookups? |
TOML parsing and merging should be in |
None => { | ||
let mut errmsg = String::new(); | ||
|
||
try!(writeln!(errmsg, "TOML error in file {}", path.as_ref().display())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try!
here is misleading, since the writeln!
will never fail: let mut errmsg = format!("TOML error in file {}\n", path.as_ref().display());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it won't fail I can just put a let _ = ...
in front of it to stop the warning.
Now Config has |
I think you can remove @nrc Please confirm. |
I use it here. |
Sorry, I missed that. |
Instead of having |
I think we were waiting for a |
@euclio at the moment, the default.toml has to be next to the binary. I chose this because it's the only reliable path. Whatever folder the users choose for the binary will be valid as long as they also have a default.toml next to it. Eventually it should work with |
It seems |
My two cents on the issue: I believe the configuration should be done on a project level and not on a user level. It should therefore be fine to just have a single hardcoded default configuration and look for project files using the strategy that @sbstp has implemented. We could simply implement |
What happens if the project configuration file is incomplete? |
Merging it with the default sounds good to me. |
Ok. This is the reason why I kept the default file is because merging at the TOML level when the config is just a hashmap is much easier than merging on the objects. If we can find a clean way of merging the objects, I totally agree with you. |
Ah, right. That's an interesting issue. How about we parse the project file into a list of key-value pairs which override the default? I'm doing this in my test configuratikn PR and it seems to work. -----Original Message----- Ok. This is the reason why I kept the default file, it's because merging at the TOML level when the config is just a hashmap is much easier than merging on the objects. If we can find a clean way of merging the objects, I totally agree with you. |
It would be fine for merging configurations for a later PR and only accept complete configurations for now. |
Hey @sbstp, how is this going? Do you need additional input or assistance? It would be great if we could merge this! |
Sorry, I forgot. I'm going to rebase it and make the changes, shouldn't be too long. |
@marcusklaas I'm not sure what to do with the tests.https://github.com/nrc/rustfmt/blob/master/tests/system.rs#L123 reads from the comments for a config file path. Any clue on the best way to proceed here? EDIT: I might have something |
This looks great! Whenever the nightly is updated, this should be good to merge. Thank you for your persistence! One small thing: I think it may be good to have a sample |
On the other hand, it may become outdated if we're not careful. What do you think? |
Sorry for the message spam, but I think it should be fine. We can point to |
Yea I was thinking that documenting the config options would be a good idea. Example of the output would be nice. |
I'm probably going to work on merging after this, it shouldn't be too hard. |
Add project-specific configuration file support.
Noyce! -----Original Message----- Merged #165. |
It's now possible to create a file relative to a project that
will override the default values. That file is called "rustfmt.toml".
The default values are stored in a file called "default.toml" and
are expected to be in the same folder as the binary, regardless
of where the binary is stored.
A "default.toml" is still written next to the manifest because
the test suite needs it.