Skip to content

Commit

Permalink
Add ignored test to demonstrate ImportMap bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zacps committed Sep 5, 2020
1 parent 6709c16 commit 09982d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/hir_def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl ImportMap {

/// Returns the `ModPath` needed to import/mention `item`, relative to this crate's root.
pub fn path_of(&self, item: ItemInNs) -> Option<&ModPath> {
eprintln!("{:#?}", self.map);
Some(&self.map.get(&item)?.path)
}

Expand Down
35 changes: 26 additions & 9 deletions crates/ide/src/doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
// 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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"#]],
)
}
}

0 comments on commit 09982d8

Please sign in to comment.