From 34e3ef61bd25c635721066c1f881d7f041366a0a Mon Sep 17 00:00:00 2001 From: nmio Date: Mon, 24 Feb 2020 16:38:59 +0000 Subject: Initial debugging code --- crates/ra_project_model/src/lib.rs | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 9df6a0e07..a8594a697 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -7,6 +7,7 @@ mod sysroot; use std::{ error::Error, fs::File, + fs::read_dir, io::BufReader, path::{Path, PathBuf}, process::Command, @@ -406,18 +407,54 @@ fn find_rust_project_json(path: &Path) -> Option { None } -fn find_cargo_toml(path: &Path) -> Result { - if path.ends_with("Cargo.toml") { - return Ok(path.to_path_buf()); - } +fn find_cargo_toml_down_the_fs(path: &Path) -> Option { let mut curr = Some(path); while let Some(path) = curr { let candidate = path.join("Cargo.toml"); if candidate.exists() { - return Ok(candidate); + return Some(candidate); } curr = path.parent(); } + + None +} + +fn find_cargo_toml_up_the_fs(path: &Path) -> Option { + log::info!("find_cargo_toml_up_the_fs()"); + let entities = match read_dir(path) { + Ok(entities) => entities, + Err(e) => { + log::info!("err {}", e); + return None + } + }; + + log::info!("entities: {:?}", entities); + for entity in entities.filter_map(Result::ok) { + let candidate = entity.path().join("Cargo.toml"); + log::info!("candidate: {:?}, exists: {}", candidate, candidate.exists()); + if candidate.exists() { + return Some(candidate); + } + } + + None +} + +fn find_cargo_toml(path: &Path) -> Result { + if path.ends_with("Cargo.toml") { + return Ok(path.to_path_buf()); + } + + if let Some(p) = find_cargo_toml_down_the_fs(path) { + return Ok(p) + } + + if let Some(p) = find_cargo_toml_up_the_fs(path) { + return Ok(p) + } + Err(CargoTomlNotFoundError(path.to_path_buf()).into()) } -- cgit v1.2.3