mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
changes implementation of folder flattening
This commit is contained in:
parent
c0709a91f3
commit
36dffc8c5f
1 changed files with 26 additions and 27 deletions
|
@ -26,42 +26,41 @@ use roc_parse::{
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
|
||||||
fn flatten_directories(files: std::vec::Vec<PathBuf>) -> std::vec::Vec<PathBuf> {
|
fn flatten_directories(files: std::vec::Vec<PathBuf>) -> std::vec::Vec<PathBuf> {
|
||||||
files
|
let mut to_flatten = files;
|
||||||
.into_iter()
|
let mut files = vec![];
|
||||||
.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() {
|
while let Some(path) = to_flatten.pop() {
|
||||||
flatten_directories(vec![path])
|
if path.is_dir() {
|
||||||
} else if path.ends_with(".roc") {
|
match path.read_dir() {
|
||||||
vec![path]
|
Ok(directory) => {
|
||||||
} else {
|
for item in directory {
|
||||||
vec![]
|
match item {
|
||||||
|
Ok(file) => {
|
||||||
|
let file_path = file.path();
|
||||||
|
if file_path.is_dir() {
|
||||||
|
to_flatten.push(file_path);
|
||||||
|
} else if file_path.ends_with(".roc") {
|
||||||
|
files.push(file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(error) => internal_error!(
|
Err(error) => internal_error!(
|
||||||
"There was an error while trying to read a file from a directory: {:?}",
|
"There was an error while trying to read a file from a directory: {:?}",
|
||||||
error
|
error
|
||||||
),
|
),
|
||||||
})
|
}
|
||||||
.collect(),
|
|
||||||
Err(error) => {
|
|
||||||
internal_error!(
|
|
||||||
"There was an error while trying to read the contents of a directory: {:?}",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
vec![file]
|
Err(error) => internal_error!(
|
||||||
|
"There was an error while trying to read the contents of a directory: {:?}",
|
||||||
|
error
|
||||||
|
),
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.collect()
|
files.push(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(files: std::vec::Vec<PathBuf>, mode: FormatMode) -> Result<(), String> {
|
pub fn format(files: std::vec::Vec<PathBuf>, mode: FormatMode) -> Result<(), String> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue