accepting review suggestions

This commit is contained in:
Bruno Ortiz 2023-04-13 13:06:43 -03:00
parent c372fb3495
commit 66fe84d936
13 changed files with 67 additions and 97 deletions

View file

@ -57,7 +57,35 @@ pub(crate) fn fetch_dependency_list(
Ok(FetchDependencyListResult {
crates: crates
.into_iter()
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })
.filter_map(|it| {
let root_file_path = state.file_id_to_file_path(it.root_file_id);
crate_path(it.name.as_ref(), root_file_path).map(|crate_path| CrateInfoResult {
name: it.name,
version: it.version,
path: crate_path.to_string(),
})
})
.collect(),
})
}
//Thats a best effort to try and find the crate path
fn crate_path(crate_name: Option<&String>, root_file_path: VfsPath) -> Option<VfsPath> {
crate_name.and_then(|crate_name| {
let mut crate_path = None;
let mut root_path = root_file_path;
while let Some(path) = root_path.parent() {
match path.name_and_extension() {
Some((name, _)) => {
if name.starts_with(crate_name.as_str()) {
crate_path = Some(path);
break;
}
}
None => break,
}
root_path = path;
}
crate_path
})
}

View file

@ -30,8 +30,8 @@ pub struct AnalyzerStatusParams {
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CrateInfoResult {
pub name: String,
pub version: String,
pub name: Option<String>,
pub version: Option<String>,
pub path: String,
}
pub enum FetchDependencyList {}

View file

@ -45,7 +45,7 @@ fn check_lsp_extensions_docs() {
sh.read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
let text = lsp_extensions_md
.lines()
.find_map(|line| dbg!(line.strip_prefix("lsp_ext.rs hash:")))
.find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
.unwrap()
.trim();
u64::from_str_radix(text, 16).unwrap()