aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authornmio <[email protected]>2020-02-24 16:38:59 +0000
committernmio <[email protected]>2020-02-24 16:38:59 +0000
commit34e3ef61bd25c635721066c1f881d7f041366a0a (patch)
tree38aba48e72fb44f8770f6a0a588245dc86b3cf18 /crates/ra_project_model/src
parent49b9c8a0524e53f9bd75b50b6e87d7d88587629f (diff)
Initial debugging code
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/lib.rs47
1 files changed, 42 insertions, 5 deletions
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;
7use std::{ 7use std::{
8 error::Error, 8 error::Error,
9 fs::File, 9 fs::File,
10 fs::read_dir,
10 io::BufReader, 11 io::BufReader,
11 path::{Path, PathBuf}, 12 path::{Path, PathBuf},
12 process::Command, 13 process::Command,
@@ -406,18 +407,54 @@ fn find_rust_project_json(path: &Path) -> Option<PathBuf> {
406 None 407 None
407} 408}
408 409
409fn find_cargo_toml(path: &Path) -> Result<PathBuf> { 410fn find_cargo_toml_down_the_fs(path: &Path) -> Option<PathBuf> {
410 if path.ends_with("Cargo.toml") {
411 return Ok(path.to_path_buf());
412 }
413 let mut curr = Some(path); 411 let mut curr = Some(path);
414 while let Some(path) = curr { 412 while let Some(path) = curr {
415 let candidate = path.join("Cargo.toml"); 413 let candidate = path.join("Cargo.toml");
416 if candidate.exists() { 414 if candidate.exists() {
417 return Ok(candidate); 415 return Some(candidate);
418 } 416 }
419 curr = path.parent(); 417 curr = path.parent();
420 } 418 }
419
420 None
421}
422
423fn find_cargo_toml_up_the_fs(path: &Path) -> Option<PathBuf> {
424 log::info!("find_cargo_toml_up_the_fs()");
425 let entities = match read_dir(path) {
426 Ok(entities) => entities,
427 Err(e) => {
428 log::info!("err {}", e);
429 return None
430 }
431 };
432
433 log::info!("entities: {:?}", entities);
434 for entity in entities.filter_map(Result::ok) {
435 let candidate = entity.path().join("Cargo.toml");
436 log::info!("candidate: {:?}, exists: {}", candidate, candidate.exists());
437 if candidate.exists() {
438 return Some(candidate);
439 }
440 }
441
442 None
443}
444
445fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
446 if path.ends_with("Cargo.toml") {
447 return Ok(path.to_path_buf());
448 }
449
450 if let Some(p) = find_cargo_toml_down_the_fs(path) {
451 return Ok(p)
452 }
453
454 if let Some(p) = find_cargo_toml_up_the_fs(path) {
455 return Ok(p)
456 }
457
421 Err(CargoTomlNotFoundError(path.to_path_buf()).into()) 458 Err(CargoTomlNotFoundError(path.to_path_buf()).into())
422} 459}
423 460