From c2aa141938aa772d71bc6572f057d9c9dbd7c40f Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Sat, 5 Sep 2020 17:21:52 +1200 Subject: [PATCH] Add ignored test to demonstrate ImportMap bug --- crates/ide/src/doc_links.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index fea243ba9703..f9d469b95974 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -60,14 +60,6 @@ pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) out } -// FIXME: -// BUG: For Option::Some -// Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some -// Instead of https://doc.rust-lang.org/nightly/core/option/enum.Option.html -// This could be worked around by turning the `EnumVariant` into `Enum` before attempting resolution, -// but it's really just working around the problem. Ideally we need to implement a slightly different -// version of import map which follows the same process as rustdoc. Otherwise there'll always be some -// edge cases where we select the wrong import path. fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option { // Get the outermost definition for the moduledef. This is used to resolve the public path to the type, // then we can join the method, field, etc onto it if required. @@ -396,7 +388,7 @@ mod tests { fn check(ra_fixture: &str, expect: Expect) { let (analysis, position) = analysis_and_position(ra_fixture); - let url = analysis.external_docs(position).unwrap().unwrap(); + let url = analysis.external_docs(position).unwrap().expect("could not find url for symbol"); expect.assert_eq(&url) } @@ -474,4 +466,29 @@ pub struct Foo { expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#structfield.field"##]], ); } + + // FIXME: ImportMap will return re-export paths instead of public module + // paths. The correct path to documentation will never be a re-export. + // This problem stops us from resolving stdlib items included in the prelude + // such as `Option::Some` correctly. + #[ignore = "ImportMap may return re-exports"] + #[test] + fn test_reexport_order() { + check( + r#" +pub mod wrapper { + pub use module::Item; + + pub mod module { + pub struct Item; + } +} + +fn foo() { + let bar: wrapper::It<|>em; +} + "#, + expect![[r#"https://docs.rs/test/*/test/wrapper/module/struct.Item.html"#]], + ) + } }