mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
Initial debugging code
This commit is contained in:
parent
49b9c8a052
commit
34e3ef61bd
1 changed files with 42 additions and 5 deletions
|
@ -7,6 +7,7 @@ mod sysroot;
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
fs::File,
|
fs::File,
|
||||||
|
fs::read_dir,
|
||||||
io::BufReader,
|
io::BufReader,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
@ -406,18 +407,54 @@ fn find_rust_project_json(path: &Path) -> Option<PathBuf> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
|
fn find_cargo_toml_down_the_fs(path: &Path) -> Option<PathBuf> {
|
||||||
if path.ends_with("Cargo.toml") {
|
|
||||||
return Ok(path.to_path_buf());
|
|
||||||
}
|
|
||||||
let mut curr = Some(path);
|
let mut curr = Some(path);
|
||||||
while let Some(path) = curr {
|
while let Some(path) = curr {
|
||||||
let candidate = path.join("Cargo.toml");
|
let candidate = path.join("Cargo.toml");
|
||||||
if candidate.exists() {
|
if candidate.exists() {
|
||||||
return Ok(candidate);
|
return Some(candidate);
|
||||||
}
|
}
|
||||||
curr = path.parent();
|
curr = path.parent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_cargo_toml_up_the_fs(path: &Path) -> Option<PathBuf> {
|
||||||
|
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<PathBuf> {
|
||||||
|
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())
|
Err(CargoTomlNotFoundError(path.to_path_buf()).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue