Skip to content

Commit 4348263

Browse files
committed
Solve platform-specific issues
1 parent 637530b commit 4348263

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

crates/ide/src/doc_links.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,11 @@ fn get_doc_base_urls(
535535

536536
return (web_base, local_base);
537537

538-
// On Windows, cargo metadata returns paths without leading slashes, but
539-
// Url::from_directory_path requires them.
540-
// In unix adding another "/" will not make any difference.
541538
fn create_url_from_os_str(path: &OsStr) -> Option<Url> {
542-
let mut with_leading_slash = OsStr::new("/").to_os_string();
543-
with_leading_slash.push(path);
544-
Url::from_directory_path(with_leading_slash.as_os_str()).ok()
539+
let mut with_prefix = OsStr::new("file:///").to_os_string();
540+
with_prefix.push(path);
541+
with_prefix.push("/");
542+
with_prefix.to_str().and_then(|s| Url::parse(s).ok())
545543
}
546544
}
547545

crates/ide/src/doc_links/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ use foo$0::Foo;
128128
//- /lib.rs crate:foo
129129
pub struct Foo;
130130
"#,
131-
Some(&OsStr::new("/home/user/project/")),
131+
Some(&OsStr::new("/home/user/project")),
132132
Some(expect![[r#"https://docs.rs/foo/*/foo/index.html"#]]),
133133
Some(expect![[r#"file:///home/user/project/doc/foo/index.html"#]]),
134134
);
@@ -141,7 +141,7 @@ fn external_docs_doc_url_std_crate() {
141141
//- /main.rs crate:std
142142
use self$0;
143143
"#,
144-
Some(&OsStr::new("/home/user/project/")),
144+
Some(&OsStr::new("/home/user/project")),
145145
Some(expect!["https://doc.rust-lang.org/stable/std/index.html"]),
146146
None,
147147
);
@@ -154,7 +154,7 @@ fn external_docs_doc_url_struct() {
154154
//- /main.rs crate:foo
155155
pub struct Fo$0o;
156156
"#,
157-
Some(&OsStr::new("/home/user/project/")),
157+
Some(&OsStr::new("/home/user/project")),
158158
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
159159
Some(expect![[r#"file:///home/user/project/doc/foo/struct.Foo.html"#]]),
160160
);
@@ -169,7 +169,7 @@ pub struct Fo$0o;
169169
"#,
170170
Some(&OsStr::new(r"C:\Users\user\project")),
171171
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
172-
Some(expect![[r#"file:///C:\Users\user\project/doc/foo/struct.Foo.html"#]]),
172+
Some(expect![[r#"file:///C:/Users/user/project/doc/foo/struct.Foo.html"#]]),
173173
);
174174
}
175175

0 commit comments

Comments
 (0)