Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide/src/doc_links.rs10
-rw-r--r--crates/ide/src/doc_links/tests.rs8
2 files changed, 8 insertions, 10 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index ac91354a34..017ca48e3b 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -535,13 +535,11 @@ fn get_doc_base_urls(
return (web_base, local_base);
- // On Windows, cargo metadata returns paths without leading slashes, but
- // Url::from_directory_path requires them.
- // In unix adding another "/" will not make any difference.
fn create_url_from_os_str(path: &OsStr) -> Option<Url> {
- let mut with_leading_slash = OsStr::new("/").to_os_string();
- with_leading_slash.push(path);
- Url::from_directory_path(with_leading_slash.as_os_str()).ok()
+ let mut with_prefix = OsStr::new("file:///").to_os_string();
+ with_prefix.push(path);
+ with_prefix.push("/");
+ with_prefix.to_str().and_then(|s| Url::parse(s).ok())
}
}
diff --git a/crates/ide/src/doc_links/tests.rs b/crates/ide/src/doc_links/tests.rs
index d04d124ce0..21bd9fb321 100644
--- a/crates/ide/src/doc_links/tests.rs
+++ b/crates/ide/src/doc_links/tests.rs
@@ -128,7 +128,7 @@ use foo$0::Foo;
//- /lib.rs crate:foo
pub struct Foo;
"#,
- Some(&OsStr::new("/home/user/project/")),
+ Some(&OsStr::new("/home/user/project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/index.html"#]]),
Some(expect![[r#"file:///home/user/project/doc/foo/index.html"#]]),
);
@@ -141,7 +141,7 @@ fn external_docs_doc_url_std_crate() {
//- /main.rs crate:std
use self$0;
"#,
- Some(&OsStr::new("/home/user/project/")),
+ Some(&OsStr::new("/home/user/project")),
Some(expect!["https://doc.rust-lang.org/stable/std/index.html"]),
None,
);
@@ -154,7 +154,7 @@ fn external_docs_doc_url_struct() {
//- /main.rs crate:foo
pub struct Fo$0o;
"#,
- Some(&OsStr::new("/home/user/project/")),
+ Some(&OsStr::new("/home/user/project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
Some(expect![[r#"file:///home/user/project/doc/foo/struct.Foo.html"#]]),
);
@@ -169,7 +169,7 @@ pub struct Fo$0o;
"#,
Some(&OsStr::new(r"C:\Users\user\project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
- Some(expect![[r#"file:///C:\Users\user\project/doc/foo/struct.Foo.html"#]]),
+ Some(expect![[r#"file:///C:/Users/user/project/doc/foo/struct.Foo.html"#]]),
);
}