mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
extracts .roc files from folders before formatting
This commit is contained in:
parent
7179f87536
commit
8bafbf3beb
1 changed files with 38 additions and 0 deletions
|
@ -25,7 +25,45 @@ use roc_parse::{
|
||||||
};
|
};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
|
||||||
|
fn flatten_folders(files: std::vec::Vec<PathBuf>) -> std::vec::Vec<PathBuf> {
|
||||||
|
files.into_iter().flat_map(|file| {
|
||||||
|
if file.is_dir() {
|
||||||
|
match file.read_dir() {
|
||||||
|
Ok(directory) => directory
|
||||||
|
.flat_map(|result| match result {
|
||||||
|
Ok(file) => {
|
||||||
|
let path = file.path();
|
||||||
|
|
||||||
|
if path.is_dir() {
|
||||||
|
flatten_folders(vec![path])
|
||||||
|
} else if path.ends_with(".roc") {
|
||||||
|
vec![path]
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => internal_error!(
|
||||||
|
"There was an error while trying to read a file from a folder: {:?}",
|
||||||
|
error
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
Err(error) => {
|
||||||
|
internal_error!(
|
||||||
|
"There was an error while trying to read the contents of a directory: {:?}",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vec![file]
|
||||||
|
}
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn format(files: std::vec::Vec<PathBuf>, mode: FormatMode) -> Result<(), String> {
|
pub fn format(files: std::vec::Vec<PathBuf>, mode: FormatMode) -> Result<(), String> {
|
||||||
|
let files = flatten_folders(files);
|
||||||
|
|
||||||
for file in files {
|
for file in files {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue