diff --git a/crates/ide-run/src/detect/dotnet.rs b/crates/ide-run/src/detect/dotnet.rs index e2c0a1e98b..33b50cb680 100644 --- a/crates/ide-run/src/detect/dotnet.rs +++ b/crates/ide-run/src/detect/dotnet.rs @@ -10,44 +10,57 @@ use std::{ path::Path, }; +fn is_skipped_dir(name: &str) -> bool { + let lower = name.to_ascii_lowercase(); + lower.starts_with('.') + || matches!( + lower.as_str(), + "bin" + | "obj" + | "node_modules" + | "target" + | "build" + | "dist" + | "vendor" + | "packages" + | "out" + | "venv" + | "__pycache__" + | "sourcepackages" + | "pods" + | "carthage" + | "deriveddata" + ) + || ide_workspace::unreal::GENERATED_DIRS.iter().any(|dir| dir.eq_ignore_ascii_case(&lower)) +} + pub(crate) fn detect(root: &Path, out: &mut Vec) { let mut dirs = vec![root.to_path_buf()]; let mut projects = BTreeSet::new(); while let Some(dir) = dirs.pop() { let Ok(entries) = fs::read_dir(&dir) else { continue }; for entry in entries.flatten() { - let path = entry.path(); - let name = entry.file_name().to_string_lossy().into_owned(); - if entry.file_type().is_ok_and(|t| t.is_dir()) { + let Ok(file_type) = entry.file_type() else { continue }; + let file_name = entry.file_name(); + if file_type.is_dir() { // Case-insensitive: Unreal's generated trees (`Binaries`, `Intermediate`, …) hold // tens of thousands of files and copies of the engine's own tool projects. - let lower = name.to_ascii_lowercase(); - if !lower.starts_with('.') - && !matches!( - lower.as_str(), - "bin" | "obj" | "node_modules" | "target" | "build" | "dist" | "vendor" | "packages" - ) - && !ide_workspace::unreal::GENERATED_DIRS.iter().any(|dir| dir.eq_ignore_ascii_case(&lower)) - { - dirs.push(path); + if !is_skipped_dir(&file_name.to_string_lossy()) { + dirs.push(entry.path()); } - } else if entry.file_type().is_ok_and(|t| t.is_file()) { - if is_project_file(&path) { - projects.insert(path); + } else if file_type.is_file() { + let name_path = Path::new(&file_name); + if is_project_file(name_path) { + projects.insert(entry.path()); continue; } - match path.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase().as_str() { - "sln" | "slnx" => { - if let Ok(src) = fs::read_to_string(&path) { - for project in solution_projects( - &src, - path.extension().is_some_and(|e| e.eq_ignore_ascii_case("slnx")), - ) { - projects.insert(dir.join(project)); - } - } + let Some(ext) = name_path.extension().and_then(|e| e.to_str()) else { continue }; + if (ext.eq_ignore_ascii_case("sln") || ext.eq_ignore_ascii_case("slnx")) + && let Ok(src) = fs::read_to_string(entry.path()) + { + for project in solution_projects(&src, ext.eq_ignore_ascii_case("slnx")) { + projects.insert(dir.join(project)); } - _ => {} } } } diff --git a/crates/ide-run/tests/dotnet.rs b/crates/ide-run/tests/dotnet.rs index 5662da8ce0..80eb731263 100644 --- a/crates/ide-run/tests/dotnet.rs +++ b/crates/ide-run/tests/dotnet.rs @@ -284,3 +284,17 @@ fn mixed_solutions_with_spaces_and_non_ascii_paths() { names.sort_unstable(); assert_eq!(names, ["Cs (.NET Project)", "Vb App (.NET Project)", "应用 (.NET Project)"]); } + +#[test] +fn detection_skips_dependency_and_build_trees_without_dropping_deep_projects() { + let temp = tempfile::tempdir().unwrap(); + let root = temp.path(); + // Deeply nested project without a solution near the root is still discovered. + write(root, "services/billing/api/src/Billing.Api/Billing.Api.csproj", CONSOLE); + for skipped in ["venv", "VENV", "__pycache__", "out", "Pods", "Carthage", "SourcePackages", "DerivedData"] { + write(root, &format!("{skipped}/Ignored.csproj"), CONSOLE); + } + let configs = detect(root); + let projects: Vec<&str> = configs.iter().map(|c| c.extras.params["project"].as_str()).collect(); + assert_eq!(projects, ["services/billing/api/src/Billing.Api/Billing.Api.csproj"]); +}