Skip to content

Commit 7543653

Browse files
Merge pull request #20384 from vxpm/fix-external-docs
fix external docs for exported macros
2 parents bd08e2e + d399bec commit 7543653

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/ide/src/doc_links.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ fn get_doc_links(
390390

391391
let (mut web_url, mut local_url) = get_doc_base_urls(db, target, target_dir, sysroot);
392392

393-
if let Some(path) = mod_path_of_def(db, target) {
393+
let append_mod = !matches!(def, Definition::Macro(m) if m.is_macro_export(db));
394+
if append_mod && let Some(path) = mod_path_of_def(db, target) {
394395
web_url = join_url(web_url, &path);
395396
local_url = join_url(local_url, &path);
396397
}

crates/ide/src/doc_links/tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,30 @@ fn foo() {
414414
)
415415
}
416416

417+
#[test]
418+
fn external_docs_macro_export() {
419+
check_external_docs(
420+
r#"
421+
//- /lib.rs crate:foo
422+
pub mod inner {
423+
#[macro_export]
424+
macro_rules! my_macro {
425+
() => {};
426+
}
427+
}
428+
429+
//- /main.rs crate:bar deps:foo
430+
fn main() {
431+
foo::my_m$0acro!();
432+
}
433+
"#,
434+
Some("/home/user/project"),
435+
Some(expect![[r#"https://docs.rs/foo/*/foo/macro.my_macro.html"#]]),
436+
Some(expect![[r#"file:///home/user/project/doc/foo/macro.my_macro.html"#]]),
437+
Some("/sysroot"),
438+
);
439+
}
440+
417441
#[test]
418442
fn doc_links_items_simple() {
419443
check_doc_links(

0 commit comments

Comments
 (0)