aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/doc_links.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index b9d8b8a2b..250f10f9f 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
132 let import_map = db.import_map(krate.into()); 132 let import_map = db.import_map(krate.into());
133 let base = once(krate.display_name(db)?.to_string()) 133 let base = once(krate.display_name(db)?.to_string())
134 .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) 134 .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
135 .join("/"); 135 .join("/")
136 + "/";
136 137
137 let filename = get_symbol_filename(db, &target_def); 138 let filename = get_symbol_filename(db, &target_def);
138 let fragment = match definition { 139 let fragment = match definition {
@@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
152 _ => None, 153 _ => None,
153 }; 154 };
154 155
155 get_doc_url(db, &krate) 156 get_doc_url(db, &krate)?
156 .and_then(|url| url.join(&base).ok()) 157 .join(&base)
157 .and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok())) 158 .ok()
159 .and_then(|mut url| {
160 if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) {
161 url.path_segments_mut().ok()?.pop();
162 };
163 Some(url)
164 })
165 .and_then(|url| url.join(filename.as_deref()?).ok())
158 .and_then( 166 .and_then(
159 |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, 167 |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) },
160 ) 168 )
@@ -522,6 +530,18 @@ pub struct Foo {
522 ); 530 );
523 } 531 }
524 532
533 #[test]
534 fn test_module() {
535 check(
536 r#"
537pub mod foo {
538 pub mod ba<|>r {}
539}
540 "#,
541 expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]],
542 )
543 }
544
525 // FIXME: ImportMap will return re-export paths instead of public module 545 // FIXME: ImportMap will return re-export paths instead of public module
526 // paths. The correct path to documentation will never be a re-export. 546 // paths. The correct path to documentation will never be a re-export.
527 // This problem stops us from resolving stdlib items included in the prelude 547 // This problem stops us from resolving stdlib items included in the prelude