-
Notifications
You must be signed in to change notification settings - Fork 26
Added support for dot config (.typstfmt.toml) #109
Added support for dot config (.typstfmt.toml) #109
Conversation
small nitpick, could you please:
Thank you for this! |
This is why I've done this the way I've done this:
I know about |
My bad, it's |
What do you mean requests? I just think it's an error if anyone had both |
I already tried it:
I already faced this problem. We either have to import a crate like This gives the same error:
Ok, I'll show a warning in stderr. |
I didn't mean |
Feel free to tell me when you're ready for another review! |
Added explanation for the removal.
All done. |
src/main.rs
Outdated
second = dot_config_file_name | ||
); | ||
} | ||
if let Ok(mut f) = config.or(dot_config) { | ||
let mut buf = String::default(); | ||
f.read_to_string(&mut buf).unwrap_or_else(|err| { | ||
panic!("Failed to read config file {CONFIG_FILE_NAME:?}: {err}") |
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.
I feel like now, this can be confusing, can I ask you to fix it by replacing this line
panic!("Failed to read config file {CONFIG_FILE_NAME:?}: {err}")
with
panic!("Failed to read config file {CONFIG_FILE_NAME:?} (or/then .{CONFIG_FILE_NAME:?}): {err}")
Or something else if you have a better idea?
If you're tired of this PR and want to merge already no problem, I can take care of 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.
What about next error:
Config::from_toml(&buf).unwrap_or_else(|e| panic!("Config file invalid: {e}.\nYou'll maybe have to delete it and use -C to create a default config file."))
Error about reading config file should include file name, but TOML parser error shouldn't?
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.
That's also getting out of date, I didn't notice it. It should include the config file used,
maybe the most simple solution is to, in verbose mode, print which config file is used? But I think it would be nicer if each error contained the name of the file
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 don't even have a verbose mode yet. Ok, I'll update this message too. Everything else can be changed after merging this PR.
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 do have a verbose mode, it's when verbose is true, did you rebase work on master?
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.
Ohhhh, I checked on the old binary while being on the latest changes. Yes, there is a verbose option. The description says increase verbosity for non errors
. Pretty sure that panic!()
is an 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.
I meant we could have the error just complain and the verbose option always print the config file used (even on no 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.
Ahh (like an init logs), no that's definitely a separate feature.
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.
👍
Thanks for this contribution :) |
Are you sure the global config feature on master would work with this? I need to check. |
I read the code again and it would have a weird behavior indeed I think it needs to be rewritten as (pseudocode) if let Ok(mut f) = File::options().read(true).open(CONFIG_FILE_NAME)
else if let Ok(mut f) = File::options().read(true).open(DOT_CONFIG_FILE_NAME)
else /* try global file */
else default |
Changed only error messages that are related to the reading/parsing of a config file.
Nah, I also read the code and it looks fine. If global isn't loaded, then the program will panic. |
Looks really nice! Good job! |
Thanks a ton ! |
I don't know whether we should create dot file by default (
-C
) or not (I think a lot of formatters do create dot file by default), but support for reading from dot file should exist. The order/priority of reading config files (from highest to lowest):typstfmt.toml
→.typstfmt.toml
.