]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide/src/hover.rs
internal: retire famous_defs_fixture
[rust.git] / crates / ide / src / hover.rs
index 1c6d36939b23ccee6012cba353e4632a2bf0ef44..409f81ca09f6669f546ef372b73bfaab2d96128f 100644 (file)
@@ -131,7 +131,7 @@ pub(crate) fn hover(
                     let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
                     let (idl_range, link, ns) =
                         extract_definitions_from_markdown(docs.as_str()).into_iter().find_map(|(range, link, ns)| {
-                            let InFile { file_id, value: range } = doc_mapping.map(range.clone())?;
+                            let InFile { file_id, value: range } = doc_mapping.map(range)?;
                             if file_id == position.file_id.into() && range.contains(position.offset) {
                                 Some((range, link, ns))
                             } else {
@@ -288,7 +288,7 @@ fn runnable_action(
 ) -> Option<HoverAction> {
     match def {
         Definition::ModuleDef(it) => match it {
-            ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)),
+            ModuleDef::Module(it) => runnable_mod(sema, it).map(HoverAction::Runnable),
             ModuleDef::Function(func) => {
                 let src = func.source(sema.db)?;
                 if src.file_id != file_id.into() {
@@ -297,7 +297,7 @@ fn runnable_action(
                     return None;
                 }
 
-                runnable_fn(&sema, func).map(HoverAction::Runnable)
+                runnable_fn(sema, func).map(HoverAction::Runnable)
             }
             _ => None,
         },
@@ -432,7 +432,7 @@ fn hover_for_definition(
     return match def {
         Definition::Macro(it) => match &it.source(db)?.value {
             Either::Left(mac) => {
-                let label = macro_label(&mac);
+                let label = macro_label(mac);
                 from_def_source_labeled(db, it, Some(label), mod_path)
             }
             Either::Right(_) => {
@@ -516,7 +516,7 @@ fn hover_for_keyword(
     if !token.kind().is_keyword() {
         return None;
     }
-    let famous_defs = FamousDefs(&sema, sema.scope(&token.parent()?).krate());
+    let famous_defs = FamousDefs(sema, sema.scope(&token.parent()?).krate());
     // std exposes {}_keyword modules with docstrings on the root to document keywords
     let keyword_mod = format!("{}_keyword", token.text());
     let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
@@ -568,8 +568,6 @@ mod tests {
 
     use crate::fixture;
 
-    use super::*;
-
     fn check_hover_no_result(ra_fixture: &str) {
         let (analysis, position) = fixture::position(ra_fixture);
         assert!(analysis.hover(position, true, true).unwrap().is_none());
@@ -1821,9 +1819,10 @@ pub struct Bar
         );
     }
 
-    #[ignore = "path based links currently only support documentation on ModuleDef items"]
     #[test]
     fn test_hover_path_link_field() {
+        // FIXME: Should be
+        //  [Foo](https://docs.rs/test/*/test/struct.Foo.html)
         check(
             r#"
 pub struct Foo;
@@ -1845,7 +1844,7 @@ pub struct Bar {
 
                 ---
 
-                [Foo](https://docs.rs/test/*/test/struct.Foo.html)
+                [Foo](struct.Foo.html)
             "#]],
         );
     }
@@ -2999,29 +2998,24 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
     fn test_hover_async_block_impl_trait_has_goto_type_action() {
         check_actions(
             r#"
+//- minicore: future
 struct S;
 fn foo() {
     let fo$0o = async { S };
 }
-
-#[prelude_import] use future::*;
-mod future {
-    #[lang = "future_trait"]
-    pub trait Future { type Output; }
-}
 "#,
             expect![[r#"
                 [
                     GoToType(
                         [
                             HoverGotoTypeData {
-                                mod_path: "test::future::Future",
+                                mod_path: "core::future::Future",
                                 nav: NavigationTarget {
                                     file_id: FileId(
-                                        0,
+                                        1,
                                     ),
-                                    full_range: 101..163,
-                                    focus_range: 140..146,
+                                    full_range: 248..430,
+                                    focus_range: 287..293,
                                     name: "Future",
                                     kind: Trait,
                                     description: "pub trait Future",
@@ -3817,11 +3811,14 @@ mod bar
 
     #[test]
     fn hover_keyword() {
-        let ra_fixture = r#"//- /main.rs crate:main deps:std
-fn f() { retur$0n; }"#;
-        let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
         check(
-            &fixture,
+            r#"
+//- /main.rs crate:main deps:std
+fn f() { retur$0n; }
+//- /libstd.rs crate:std
+/// Docs for return_keyword
+mod return_keyword {}
+"#,
             expect![[r#"
                 *return*
 
@@ -3838,11 +3835,15 @@ fn hover_keyword() {
 
     #[test]
     fn hover_builtin() {
-        let ra_fixture = r#"//- /main.rs crate:main deps:std
-cosnt _: &str$0 = ""; }"#;
-        let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
         check(
-            &fixture,
+            r#"
+//- /main.rs crate:main deps:std
+cosnt _: &str$0 = ""; }
+
+//- /libstd.rs crate:std
+/// Docs for prim_str
+mod prim_str {}
+"#,
             expect![[r#"
                 *str*