From 0085d757668ccd9fcaa0ba3100225832b9f74e9e Mon Sep 17 00:00:00 2001 From: He1pa <56333845+He1pa@users.noreply.github.com> Date: Thu, 23 Nov 2023 04:17:20 -0800 Subject: [PATCH] fix: fix func `get_kcl_files` (#912) Signed-off-by: he1pa <18012015693@163.com> --- kclvm/driver/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kclvm/driver/src/lib.rs b/kclvm/driver/src/lib.rs index d090809a5..e849deea6 100644 --- a/kclvm/driver/src/lib.rs +++ b/kclvm/driver/src/lib.rs @@ -275,11 +275,16 @@ pub fn lookup_compile_unit_path(file: &str) -> io::Result { /// Get kcl files from path. pub fn get_kcl_files>(path: P, recursively: bool) -> Result> { let mut files = vec![]; - for entry in WalkDir::new(path).into_iter().filter_map(|e| e.ok()) { + let walkdir = if recursively { + WalkDir::new(path) + } else { + WalkDir::new(path).max_depth(1) + }; + for entry in walkdir.into_iter().filter_map(|e| e.ok()) { let path = entry.path(); if path.is_file() { let file = path.to_str().unwrap(); - if file.ends_with(KCL_FILE_SUFFIX) && (recursively || entry.depth() == 1) { + if file.ends_with(KCL_FILE_SUFFIX) { files.push(file.to_string()) } }