-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Implement 'roc format <dir_or_files>' command #2066
Conversation
cli/src/format.rs
Outdated
// files, | ||
// roc_builtins::std::standard_stdlib(), | ||
// Path::new("./generated-docs"), | ||
// ) |
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.
🎨 Seems like this comment is no longer needed, yeah?
cli/src/format.rs
Outdated
|
||
std::fs::write(&file, buf).unwrap(); | ||
} | ||
Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, 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.
Instead of panic!
can we use one of these? #2046
cli/src/main.rs
Outdated
match maybe_values { | ||
None => { | ||
let mut os_string_values: Vec<OsString> = Vec::new(); | ||
read_all_roc_files(&OsStr::new("./").to_os_string(), &mut os_string_values)?; |
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 think https://doc.rust-lang.org/std/env/fn.current_dir.html is probably more portable than "./"
c114fb6
to
1f16b95
Compare
cli/src/main.rs
Outdated
@@ -101,7 +101,7 @@ fn main() -> io::Result<()> { | |||
match maybe_values { | |||
None => { | |||
let mut os_string_values: Vec<OsString> = Vec::new(); | |||
read_all_roc_files(&OsStr::new("./").to_os_string(), &mut os_string_values)?; | |||
read_all_roc_files(&std::env::current_dir().unwrap().as_os_str().to_os_string(), &mut os_string_values)?; |
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.
Can
read_all_roc_files(&std::env::current_dir().unwrap().as_os_str().to_os_string(), &mut os_string_values)?; | |
read_all_roc_files(&std::env::current_dir()?.as_os_str().to_os_string(), &mut os_string_values)?; |
be done here instead of an unwrap?
1f16b95
to
c017865
Compare
c017865
to
c5388ba
Compare
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.
Sweet, thanks @joshuawarner32! 🎉
I noticed this was conspicuously missing.
Note when trying to format a roc few files in the repo, I immediately ran into missing parts of the formatter, which I'll work on next.
Having this command is both (1) independently useful, and (2) a good stepping stone to #2010, where we'll want to parse, simplify/reduce the ast, then write it out again (invoking the same code this does).