Skip to content

Commit

Permalink
Use correct toolchain channel when generating builtin type doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed May 23, 2024
1 parent ac2708a commit 616fdd0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/tools/rust-analyzer/crates/ide/src/doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,23 @@ fn get_doc_base_urls(
let system_doc = sysroot
.map(|sysroot| format!("file:///{sysroot}/share/doc/rust/html/"))
.and_then(|it| Url::parse(&it).ok());
let krate = def.krate(db);
let channel = krate
.and_then(|krate| db.toolchain_channel(krate.into()))
.unwrap_or(ReleaseChannel::Nightly)
.as_str();

// special case base url of `BuiltinType` to core
// https://github.com/rust-lang/rust-analyzer/issues/12250
if let Definition::BuiltinType(..) = def {
let web_link = Url::parse("https://doc.rust-lang.org/nightly/core/").ok();
let web_link = Url::parse(&format!("https://doc.rust-lang.org/{channel}/core/")).ok();
let system_link = system_doc.and_then(|it| it.join("core/").ok());
return (web_link, system_link);
};

let Some(krate) = def.krate(db) else { return Default::default() };
let Some(krate) = krate else { return Default::default() };
let Some(display_name) = krate.display_name(db) else { return Default::default() };
let crate_data = &db.crate_graph()[krate.into()];
let channel = db.toolchain_channel(krate.into()).unwrap_or(ReleaseChannel::Nightly).as_str();

let (web_base, local_base) = match &crate_data.origin {
// std and co do not specify `html_root_url` any longer so we gotta handwrite this ourself.
Expand Down

0 comments on commit 616fdd0

Please sign in to comment.