Expose version string of crates fom HIR

This commit is contained in:
Lukas Wirth 2021-10-30 16:17:04 +02:00
parent b9fa37f5b4
commit 52f5af7165
8 changed files with 111 additions and 1 deletions

View file

@ -473,12 +473,17 @@ fn get_doc_base_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
}
_ => {
krate.get_html_root_url(db).or_else(|| {
let version = krate.version(db);
// Fallback to docs.rs. This uses `display_name` and can never be
// correct, but that's what fallbacks are about.
//
// FIXME: clicking on the link should just open the file in the editor,
// instead of falling back to external urls.
Some(format!("https://docs.rs/{krate}/*/", krate = display_name))
Some(format!(
"https://docs.rs/{krate}/{version}/",
krate = display_name,
version = version.as_deref().unwrap_or("*")
))
})?
}
};

View file

@ -219,6 +219,7 @@ impl Analysis {
file_id,
Edition::CURRENT,
None,
None,
cfg_options.clone(),
cfg_options,
Env::default(),