2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
6 base_db::SourceDatabase,
7 defs::{Definition, NameClass, NameRefClass},
10 use itertools::Itertools;
12 use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
16 display::{macro_label, ShortLabel, TryToNav},
17 doc_links::{remove_links, rewrite_links},
18 markdown_remove::remove_markdown,
20 runnables::{runnable_fn, runnable_mod},
21 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
24 #[derive(Clone, Debug, PartialEq, Eq)]
25 pub struct HoverConfig {
26 pub implementations: bool,
29 pub goto_type_def: bool,
30 pub links_in_hover: bool,
35 pub const NO_ACTIONS: Self = Self {
36 implementations: false,
44 pub fn any(&self) -> bool {
45 self.implementations || self.runnable() || self.goto_type_def
48 pub fn none(&self) -> bool {
52 pub fn runnable(&self) -> bool {
53 self.run || self.debug
57 #[derive(Debug, Clone)]
58 pub enum HoverAction {
60 Implementation(FilePosition),
61 GoToType(Vec<HoverGotoTypeData>),
64 #[derive(Debug, Clone, Eq, PartialEq)]
65 pub struct HoverGotoTypeData {
67 pub nav: NavigationTarget,
70 /// Contains the results when hovering over an item
71 #[derive(Debug, Default)]
72 pub struct HoverResult {
74 pub actions: Vec<HoverAction>,
79 // Shows additional information, like type of an expression or documentation for definition when "focusing" code.
80 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
83 position: FilePosition,
86 ) -> Option<RangeInfo<HoverResult>> {
87 let sema = Semantics::new(db);
88 let file = sema.parse(position.file_id).syntax().clone();
89 let token = pick_best(file.token_at_offset(position.offset))?;
90 let token = sema.descend_into_macros(token);
92 let mut res = HoverResult::default();
94 let node = token.parent();
95 let definition = match_ast! {
97 // we don't use NameClass::referenced_or_defined here as we do not want to resolve
98 // field pattern shorthands to their definition
99 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|class| match class {
100 NameClass::ConstReference(def) => Some(def),
101 def => def.defined(sema.db),
103 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)),
104 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
105 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
109 if let Some(definition) = definition {
110 if let Some(markup) = hover_for_definition(db, definition) {
111 let markup = markup.as_str();
112 let markup = if !markdown {
113 remove_markdown(markup)
114 } else if links_in_hover {
115 rewrite_links(db, markup, &definition)
119 res.markup = Markup::from(markup);
120 if let Some(action) = show_implementations_action(db, definition) {
121 res.actions.push(action);
124 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
125 res.actions.push(action);
128 if let Some(action) = goto_type_action(db, definition) {
129 res.actions.push(action);
132 let range = sema.original_range(&node).range;
133 return Some(RangeInfo::new(range, res));
137 if token.kind() == syntax::SyntaxKind::COMMENT {
138 // don't highlight the entire parent node on comment hover
144 .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
146 let ty = match_ast! {
148 ast::Expr(it) => sema.type_of_expr(&it)?,
149 ast::Pat(it) => sema.type_of_pat(&it)?,
150 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
151 // (e.g expanding a builtin macro). So we give up here.
152 ast::MacroCall(_it) => return None,
157 res.markup = if markdown {
158 Markup::fenced_block(&ty.display(db))
160 ty.display(db).to_string().into()
162 let range = sema.original_range(&node).range;
163 Some(RangeInfo::new(range, res))
166 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
167 fn to_action(nav_target: NavigationTarget) -> HoverAction {
168 HoverAction::Implementation(FilePosition {
169 file_id: nav_target.file_id,
170 offset: nav_target.focus_or_full_range().start(),
174 let adt = match def {
175 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
176 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
177 Definition::SelfType(it) => it.target_ty(db).as_adt(),
180 adt.try_to_nav(db).map(to_action)
184 sema: &Semantics<RootDatabase>,
187 ) -> Option<HoverAction> {
189 Definition::ModuleDef(it) => match it {
190 ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)),
191 ModuleDef::Function(func) => {
192 let src = func.source(sema.db)?;
193 if src.file_id != file_id.into() {
194 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
195 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
199 runnable_fn(&sema, func).map(HoverAction::Runnable)
207 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
208 let mut targets: Vec<ModuleDef> = Vec::new();
209 let mut push_new_def = |item: ModuleDef| {
210 if !targets.contains(&item) {
215 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
216 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
219 Definition::Local(it) => it.ty(db),
220 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
225 if let Some(adt) = t.as_adt() {
226 push_new_def(adt.into());
227 } else if let Some(trait_) = t.as_dyn_trait() {
228 push_new_def(trait_.into());
229 } else if let Some(traits) = t.as_impl_traits(db) {
230 traits.into_iter().for_each(|it| push_new_def(it.into()));
231 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
232 push_new_def(trait_.into());
237 let targets = targets
240 Some(HoverGotoTypeData {
241 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
242 nav: it.try_to_nav(db)?,
247 Some(HoverAction::GoToType(targets))
251 docs: Option<String>,
252 desc: Option<String>,
253 mod_path: Option<String>,
254 ) -> Option<Markup> {
257 let mut buf = String::new();
259 if let Some(mod_path) = mod_path {
260 if !mod_path.is_empty() {
261 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
264 format_to!(buf, "```rust\n{}\n```", desc);
266 if let Some(doc) = docs {
267 format_to!(buf, "\n___\n\n{}", doc);
271 None => docs.map(Markup::from),
275 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
277 Definition::Field(f) => Some(f.parent_def(db).name(db)),
278 Definition::Local(l) => l.parent(db).name(db),
279 Definition::ModuleDef(md) => match md {
280 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
281 AssocItemContainer::Trait(t) => Some(t.name(db)),
282 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
284 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
289 .map(|name| name.to_string())
292 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
294 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
295 let module_path = module
299 .flat_map(|it| it.name(db).map(|name| name.to_string()));
300 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
303 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
304 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
307 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
308 let mod_path = definition_mod_path(db, &def);
310 Definition::Macro(it) => {
311 let label = macro_label(&it.source(db)?.value);
312 from_def_source_labeled(db, it, Some(label), mod_path)
314 Definition::Field(def) => {
315 let src = def.source(db)?.value;
316 if let FieldSource::Named(it) = src {
317 from_def_source_labeled(db, def, it.short_label(), mod_path)
322 Definition::ModuleDef(it) => match it {
323 ModuleDef::Module(it) => from_def_source_labeled(
326 match it.definition_source(db).value {
327 ModuleSource::Module(it) => it.short_label(),
328 ModuleSource::SourceFile(it) => it.short_label(),
329 ModuleSource::BlockExpr(it) => it.short_label(),
333 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
334 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
335 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
336 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
337 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
338 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
339 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
340 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
341 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
342 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it.name())),
344 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
345 Definition::SelfType(impl_def) => {
346 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
347 Adt::Struct(it) => from_def_source(db, it, mod_path),
348 Adt::Union(it) => from_def_source(db, it, mod_path),
349 Adt::Enum(it) => from_def_source(db, it, mod_path),
352 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
353 Definition::GenericParam(it) => match it {
354 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
355 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
356 GenericParam::ConstParam(it) => from_def_source(db, it, None),
360 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
362 D: HasSource<Ast = A> + HasAttrs + Copy,
365 let short_label = def.source(db)?.value.short_label();
366 from_def_source_labeled(db, def, short_label, mod_path)
369 fn from_def_source_labeled<D>(
372 short_label: Option<String>,
373 mod_path: Option<String>,
378 let docs = def.attrs(db).docs().map(Into::into);
379 hover_markup(docs, short_label, mod_path)
383 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
384 return tokens.max_by_key(priority);
385 fn priority(n: &SyntaxToken) -> usize {
387 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 3,
388 T!['('] | T![')'] => 2,
389 kind if kind.is_trivia() => 0,
397 use expect_test::{expect, Expect};
398 use ide_db::base_db::FileLoader;
404 fn check_hover_no_result(ra_fixture: &str) {
405 let (analysis, position) = fixture::position(ra_fixture);
406 assert!(analysis.hover(position, true, true).unwrap().is_none());
409 fn check(ra_fixture: &str, expect: Expect) {
410 let (analysis, position) = fixture::position(ra_fixture);
411 let hover = analysis.hover(position, true, true).unwrap().unwrap();
413 let content = analysis.db.file_text(position.file_id);
414 let hovered_element = &content[hover.range];
416 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
417 expect.assert_eq(&actual)
420 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
421 let (analysis, position) = fixture::position(ra_fixture);
422 let hover = analysis.hover(position, false, true).unwrap().unwrap();
424 let content = analysis.db.file_text(position.file_id);
425 let hovered_element = &content[hover.range];
427 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
428 expect.assert_eq(&actual)
431 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
432 let (analysis, position) = fixture::position(ra_fixture);
433 let hover = analysis.hover(position, true, false).unwrap().unwrap();
435 let content = analysis.db.file_text(position.file_id);
436 let hovered_element = &content[hover.range];
438 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
439 expect.assert_eq(&actual)
442 fn check_actions(ra_fixture: &str, expect: Expect) {
443 let (analysis, position) = fixture::position(ra_fixture);
444 let hover = analysis.hover(position, true, true).unwrap().unwrap();
445 expect.assert_debug_eq(&hover.info.actions)
449 fn hover_shows_type_of_an_expression() {
452 pub fn foo() -> u32 { 1 }
455 let foo_test = foo()$0;
468 fn hover_remove_markdown_if_configured() {
469 check_hover_no_markdown(
471 pub fn foo() -> u32 { 1 }
474 let foo_test = foo()$0;
485 fn hover_shows_long_type_of_an_expression() {
488 struct Scan<A, B, C> { a: A, b: B, c: C }
489 struct Iter<I> { inner: I }
490 enum Option<T> { Some(T), None }
492 struct OtherStruct<T> { i: T }
494 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
495 Iter { inner: Scan { a, b, c } }
500 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
501 Option::Some(*memo + value)
504 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
511 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
518 fn hover_shows_fn_signature() {
519 // Single file with result
522 pub fn foo() -> u32 { 1 }
524 fn main() { let foo_test = fo$0o(); }
539 // Multiple candidates but results are ambiguous.
543 pub fn foo() -> u32 { 1 }
546 pub fn foo() -> &str { "" }
549 pub fn foo(a: u32, b: u32) {}
556 fn main() { let foo_test = fo$0o(); }
568 fn hover_shows_fn_signature_with_type_params() {
571 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
573 fn main() { let foo_test = fo$0o(); }
583 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
590 fn hover_shows_fn_signature_on_fn_name() {
593 pub fn foo$0(a: u32, b: u32) -> u32 {}
605 pub fn foo(a: u32, b: u32) -> u32
612 fn hover_shows_fn_doc() {
617 /// # use std::path::Path;
619 /// foo(Path::new("hello, world!"))
621 pub fn foo$0(_: &Path) {}
641 # use std::path::Path;
643 foo(Path::new("hello, world!"))
650 fn hover_shows_fn_doc_attr_raw_string() {
653 #[doc = r#"Raw string doc attr"#]
654 pub fn foo$0(_: &Path) {}
677 fn hover_shows_struct_field_info() {
678 // Hovering over the field when instantiating
681 struct Foo { field_a: u32 }
684 let foo = Foo { field_a$0: 0, };
700 // Hovering over the field in the definition
703 struct Foo { field_a$0: u32 }
706 let foo = Foo { field_a: 0 };
724 fn hover_const_static() {
726 r#"const foo$0: u32 = 123;"#,
740 r#"static foo$0: u32 = 456;"#,
756 fn hover_default_generic_types() {
759 struct Test<K, T = u8> { k: K, t: T }
762 let zz$0 = Test { t: 23u8, k: 33 };
778 enum Option<T> { Some(T) }
781 fn main() { So$0me(12); }
798 enum Option<T> { Some(T) }
801 fn main() { let b$0ar = Some(12); }
814 fn hover_enum_variant() {
846 let s = Option::Som$0e(12);
868 fn hover_for_local_variable() {
870 r#"fn func(foo: i32) { fo$0o; }"#,
882 fn hover_for_local_variable_pat() {
884 r#"fn func(fo$0o: i32) {}"#,
896 fn hover_local_var_edge() {
898 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
910 fn hover_for_param_edge() {
912 r#"fn func($0foo: i32) {}"#,
924 fn hover_for_param_with_multiple_traits() {
932 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
937 impl Deref<Target = u8> + DerefMut<Target = u8>
944 fn test_hover_infer_associated_method_result() {
947 struct Thing { x: u32 }
950 fn new() -> Thing { Thing { x: 0 } }
953 fn main() { let foo_$0test = Thing::new(); }
966 fn test_hover_infer_associated_method_exact() {
970 struct Thing { x: u32 }
973 fn new() -> Thing { Thing { x: 0 } }
977 fn main() { let foo_test = wrapper::Thing::new$0(); }
994 fn test_hover_infer_associated_const_in_pattern() {
1025 fn test_hover_self() {
1028 struct Thing { x: u32 }
1030 fn new() -> Self { Self$0 { x: 0 } }
1047 struct Thing { x: u32 }
1049 fn new() -> Self$0 { Self { x: 0 } }
1068 pub fn new() -> Self$0 { Thing::A }
1087 pub fn thing(a: Self$0) {}
1105 fn test_hover_shadowing_pat() {
1126 fn test_hover_macro_invocation() {
1129 macro_rules! foo { () => {} }
1131 fn f() { fo$0o!(); }
1148 fn test_hover_tuple_field() {
1150 r#"struct TS(String, i32$0);"#,
1162 fn test_hover_through_macro() {
1165 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1168 fn bar() { fo$0o(); }
1186 fn test_hover_through_expr_in_macro() {
1189 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1190 fn foo(bar:u32) { let a = id!(ba$0r); }
1203 fn test_hover_through_expr_in_macro_recursive() {
1206 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1207 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1208 fn foo(bar:u32) { let a = id!(ba$0r); }
1221 fn test_hover_through_func_in_macro_recursive() {
1224 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1225 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1226 fn bar() -> u32 { 0 }
1227 fn foo() { let a = id!([0u32, bar($0)] ); }
1239 fn test_hover_through_literal_string_in_macro() {
1242 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1244 let mastered_for_itunes = "";
1245 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1258 fn test_hover_through_assert_macro() {
1261 #[rustc_builtin_macro]
1262 macro_rules! assert {}
1264 fn bar() -> bool { true }
1284 fn test_hover_through_literal_string_in_builtin_macro() {
1285 check_hover_no_result(
1287 #[rustc_builtin_macro]
1288 macro_rules! format {}
1291 format!("hel$0lo {}", 0);
1298 fn test_hover_non_ascii_space_doc() {
1301 /// <- `\u{3000}` here
1304 fn bar() { fo$0o(); }
1325 fn test_hover_function_show_qualifiers() {
1327 r#"async fn foo$0() {}"#,
1341 r#"pub const unsafe fn foo$0() {}"#,
1350 pub const unsafe fn foo()
1355 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1364 pub(crate) async unsafe extern "C" fn foo()
1371 fn test_hover_trait_show_qualifiers() {
1373 r"unsafe trait foo$0() {}",
1390 fn test_hover_extern_crate() {
1393 //- /main.rs crate:main deps:std
1395 //- /std/lib.rs crate:std
1396 //! Standard library for this test
1403 Standard library for this test
1411 //- /main.rs crate:main deps:std
1412 extern crate std as ab$0c;
1413 //- /std/lib.rs crate:std
1414 //! Standard library for this test
1421 Standard library for this test
1430 fn test_hover_mod_with_same_name_as_function() {
1433 use self::m$0y::Bar;
1434 mod my { pub struct Bar; }
1453 fn test_hover_struct_doc_comment() {
1459 fn foo() { let bar = Ba$0r; }
1480 fn test_hover_struct_doc_attr() {
1486 fn foo() { let bar = Ba$0r; }
1507 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1511 #[doc = "bar docs 1"]
1512 #[doc = "bar docs 2"]
1515 fn foo() { let bar = Ba$0r; }
1538 fn test_hover_path_link() {
1542 /// [Foo](struct.Foo.html)
1558 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1564 fn test_hover_path_link_no_strip() {
1568 /// [struct Foo](struct.Foo.html)
1584 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1589 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1591 fn test_hover_path_link_field() {
1596 /// [Foo](struct.Foo.html)
1613 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1619 fn test_hover_intra_link() {
1641 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1647 fn test_hover_intra_link_html_root_url() {
1650 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1671 [Foo](https://example.com/test/foo/struct.Foo.html)
1677 fn test_hover_intra_link_shortlink() {
1697 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1703 fn test_hover_intra_link_shortlink_code() {
1723 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1729 fn test_hover_intra_link_namespaced() {
1750 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1756 fn test_hover_intra_link_shortlink_namspaced_code() {
1776 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1782 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1802 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1808 fn test_hover_intra_link_reference() {
1830 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1835 fn test_hover_intra_link_reference_to_trait_method() {
1843 /// [buzz]: Foo::buzz
1859 [Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)
1865 fn test_hover_external_url() {
1869 /// [external](https://www.google.com)
1885 [external](https://www.google.com)
1890 // Check that we don't rewrite links which we can't identify
1892 fn test_hover_unknown_target() {
1918 fn test_doc_links_enum_variant() {
1939 [E](https://docs.rs/test/*/test/enum.E.html)
1945 fn test_doc_links_field() {
1966 [`S`](https://docs.rs/test/*/test/struct.S.html)
1972 fn test_hover_no_links() {
1973 check_hover_no_links(
1976 /// case 1. bare URL: https://www.example.com/
1977 /// case 2. inline URL with title: [example](https://www.example.com/)
1978 /// case 3. code reference: [`Result`]
1979 /// case 4. code reference but miss footnote: [`String`]
1980 /// case 5. autolink: <http://www.example.com/>
1981 /// case 6. email address: <test@example.com>
1982 /// case 7. reference: [example][example]
1983 /// case 8. collapsed link: [example][]
1984 /// case 9. shortcut link: [example]
1985 /// case 10. inline without URL: [example]()
1986 /// case 11. reference: [foo][foo]
1987 /// case 12. reference: [foo][bar]
1988 /// case 13. collapsed link: [foo][]
1989 /// case 14. shortcut link: [foo]
1990 /// case 15. inline without URL: [foo]()
1991 /// case 16. just escaped text: \[foo]
1992 /// case 17. inline link: [Foo](foo::Foo)
1994 /// [`Result`]: ../../std/result/enum.Result.html
1995 /// [^example]: https://www.example.com/
2012 case 1. bare URL: https://www.example.com/
2013 case 2. inline URL with title: [example](https://www.example.com/)
2014 case 3. code reference: `Result`
2015 case 4. code reference but miss footnote: `String`
2016 case 5. autolink: http://www.example.com/
2017 case 6. email address: test@example.com
2018 case 7. reference: example
2019 case 8. collapsed link: example
2020 case 9. shortcut link: example
2021 case 10. inline without URL: example
2022 case 11. reference: foo
2023 case 12. reference: foo
2024 case 13. collapsed link: foo
2025 case 14. shortcut link: foo
2026 case 15. inline without URL: foo
2027 case 16. just escaped text: \[foo]
2028 case 17. inline link: Foo
2030 [^example]: https://www.example.com/
2036 fn test_hover_macro_generated_struct_fn_doc_comment() {
2037 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2053 fn foo() { let bar = Bar; bar.fo$0o(); }
2074 fn test_hover_macro_generated_struct_fn_doc_attr() {
2075 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2083 #[doc = "Do the foo"]
2091 fn foo() { let bar = Bar; bar.fo$0o(); }
2112 fn test_hover_trait_has_impl_action() {
2114 r#"trait foo$0() {}"#,
2131 fn test_hover_struct_has_impl_action() {
2133 r"struct foo$0() {}",
2150 fn test_hover_union_has_impl_action() {
2152 r#"union foo$0() {}"#,
2169 fn test_hover_enum_has_impl_action() {
2171 r"enum foo$0() { A, B }",
2188 fn test_hover_self_has_impl_action() {
2190 r#"struct foo where Self$0:;"#,
2207 fn test_hover_test_has_action() {
2217 nav: NavigationTarget {
2222 focus_range: 11..19,
2243 fn test_hover_test_mod_has_action() {
2255 nav: NavigationTarget {
2276 fn test_hover_struct_has_goto_type_action() {
2281 fn main() { let s$0t = S{ f1:0 }; }
2288 mod_path: "test::S",
2289 nav: NavigationTarget {
2297 description: "struct S",
2308 fn test_hover_generic_struct_has_goto_type_actions() {
2312 struct S<T>{ f1: T }
2314 fn main() { let s$0t = S{ f1:Arg(0) }; }
2321 mod_path: "test::S",
2322 nav: NavigationTarget {
2327 focus_range: 24..25,
2330 description: "struct S",
2334 mod_path: "test::Arg",
2335 nav: NavigationTarget {
2343 description: "struct Arg",
2354 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2358 struct S<T>{ f1: T }
2360 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2367 mod_path: "test::S",
2368 nav: NavigationTarget {
2373 focus_range: 24..25,
2376 description: "struct S",
2380 mod_path: "test::Arg",
2381 nav: NavigationTarget {
2389 description: "struct Arg",
2400 fn test_hover_tuple_has_goto_type_actions() {
2409 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2416 mod_path: "test::A",
2417 nav: NavigationTarget {
2425 description: "struct A",
2429 mod_path: "test::B",
2430 nav: NavigationTarget {
2435 focus_range: 22..23,
2438 description: "struct B",
2442 mod_path: "test::M::C",
2443 nav: NavigationTarget {
2448 focus_range: 53..54,
2451 description: "pub struct C",
2462 fn test_hover_return_impl_trait_has_goto_type_action() {
2466 fn foo() -> impl Foo {}
2468 fn main() { let s$0t = foo(); }
2475 mod_path: "test::Foo",
2476 nav: NavigationTarget {
2484 description: "trait Foo",
2495 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2500 fn foo() -> impl Foo<S> {}
2502 fn main() { let s$0t = foo(); }
2509 mod_path: "test::Foo",
2510 nav: NavigationTarget {
2518 description: "trait Foo",
2522 mod_path: "test::S",
2523 nav: NavigationTarget {
2528 focus_range: 23..24,
2531 description: "struct S",
2542 fn test_hover_return_impl_traits_has_goto_type_action() {
2547 fn foo() -> impl Foo + Bar {}
2549 fn main() { let s$0t = foo(); }
2556 mod_path: "test::Foo",
2557 nav: NavigationTarget {
2565 description: "trait Foo",
2569 mod_path: "test::Bar",
2570 nav: NavigationTarget {
2575 focus_range: 19..22,
2578 description: "trait Bar",
2589 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2597 fn foo() -> impl Foo<S1> + Bar<S2> {}
2599 fn main() { let s$0t = foo(); }
2606 mod_path: "test::Foo",
2607 nav: NavigationTarget {
2615 description: "trait Foo",
2619 mod_path: "test::Bar",
2620 nav: NavigationTarget {
2625 focus_range: 22..25,
2628 description: "trait Bar",
2632 mod_path: "test::S1",
2633 nav: NavigationTarget {
2638 focus_range: 39..41,
2641 description: "struct S1",
2645 mod_path: "test::S2",
2646 nav: NavigationTarget {
2651 focus_range: 52..54,
2654 description: "struct S2",
2665 fn test_hover_arg_impl_trait_has_goto_type_action() {
2669 fn foo(ar$0g: &impl Foo) {}
2676 mod_path: "test::Foo",
2677 nav: NavigationTarget {
2685 description: "trait Foo",
2696 fn test_hover_arg_impl_traits_has_goto_type_action() {
2703 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2710 mod_path: "test::Foo",
2711 nav: NavigationTarget {
2719 description: "trait Foo",
2723 mod_path: "test::Bar",
2724 nav: NavigationTarget {
2729 focus_range: 19..22,
2732 description: "trait Bar",
2736 mod_path: "test::S",
2737 nav: NavigationTarget {
2742 focus_range: 36..37,
2745 description: "struct S",
2756 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2761 let fo$0o = async { S };
2764 #[prelude_import] use future::*;
2766 #[lang = "future_trait"]
2767 pub trait Future { type Output; }
2775 mod_path: "test::future::Future",
2776 nav: NavigationTarget {
2780 full_range: 101..163,
2781 focus_range: 140..146,
2784 description: "pub trait Future",
2788 mod_path: "test::S",
2789 nav: NavigationTarget {
2797 description: "struct S",
2808 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2813 fn foo(ar$0g: &impl Foo<S>) {}
2820 mod_path: "test::Foo",
2821 nav: NavigationTarget {
2829 description: "trait Foo",
2833 mod_path: "test::S",
2834 nav: NavigationTarget {
2839 focus_range: 23..24,
2842 description: "struct S",
2853 fn test_hover_dyn_return_has_goto_type_action() {
2861 fn foo() -> B<dyn Foo> {}
2863 fn main() { let s$0t = foo(); }
2870 mod_path: "test::B",
2871 nav: NavigationTarget {
2876 focus_range: 49..50,
2879 description: "struct B",
2883 mod_path: "test::Foo",
2884 nav: NavigationTarget {
2892 description: "trait Foo",
2903 fn test_hover_dyn_arg_has_goto_type_action() {
2907 fn foo(ar$0g: &dyn Foo) {}
2914 mod_path: "test::Foo",
2915 nav: NavigationTarget {
2923 description: "trait Foo",
2934 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2939 fn foo(ar$0g: &dyn Foo<S>) {}
2946 mod_path: "test::Foo",
2947 nav: NavigationTarget {
2955 description: "trait Foo",
2959 mod_path: "test::S",
2960 nav: NavigationTarget {
2965 focus_range: 23..24,
2968 description: "struct S",
2979 fn test_hover_goto_type_action_links_order() {
2982 trait ImplTrait<T> {}
2983 trait DynTrait<T> {}
2987 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2994 mod_path: "test::ImplTrait",
2995 nav: NavigationTarget {
3003 description: "trait ImplTrait",
3007 mod_path: "test::B",
3008 nav: NavigationTarget {
3013 focus_range: 50..51,
3016 description: "struct B",
3020 mod_path: "test::DynTrait",
3021 nav: NavigationTarget {
3026 focus_range: 28..36,
3029 description: "trait DynTrait",
3033 mod_path: "test::S",
3034 nav: NavigationTarget {
3039 focus_range: 65..66,
3042 description: "struct S",
3053 fn test_hover_associated_type_has_goto_type_action() {
3058 fn get(self) -> Self::Item {}
3064 impl Foo for S { type Item = Bar; }
3066 fn test() -> impl Foo { S {} }
3068 fn main() { let s$0t = test().get(); }
3075 mod_path: "test::Foo",
3076 nav: NavigationTarget {
3084 description: "trait Foo",
3095 fn test_hover_const_param_has_goto_type_action() {
3099 struct Foo<const BAR: Bar>;
3101 impl<const BAR: Bar> Foo<BAR$0> {}
3108 mod_path: "test::Bar",
3109 nav: NavigationTarget {
3117 description: "struct Bar",
3128 fn test_hover_type_param_has_goto_type_action() {
3133 fn foo<T: Foo>(t: T$0){}
3140 mod_path: "test::Foo",
3141 nav: NavigationTarget {
3149 description: "trait Foo",
3160 fn test_hover_self_has_go_to_type() {
3173 mod_path: "test::Foo",
3174 nav: NavigationTarget {
3182 description: "struct Foo",
3193 fn hover_displays_normalized_crate_names() {
3196 //- /lib.rs crate:name-with-dashes
3198 pub struct Thing { x: u32 }
3201 pub fn new() -> Thing { Thing { x: 0 } }
3205 //- /main.rs crate:main deps:name-with-dashes
3206 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3212 name_with_dashes::wrapper::Thing
3216 pub fn new() -> Thing
3223 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3246 fn hover_self_param_shows_type() {
3265 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3271 fn bar(sel$0f: Arc<Foo>) {}
3285 fn hover_doc_outer_inner() {
3292 /// This comment belongs to the function
3316 fn hover_doc_outer_inner_attribue() {
3319 #[doc = "Be quick;"]
3321 #![doc = "time is mana"]
3323 #[doc = "This comment belongs to the function"]
3347 fn hover_comments_dont_highlight_parent() {
3348 check_hover_no_result(
3376 fn hover_lifetime() {
3378 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3390 fn hover_type_param() {
3397 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3403 T: Copy + Clone + Sized
3420 // lifetimes bounds arent being tracked yet
3424 impl<T: 'static> Foo<T$0> {}
3437 fn hover_const_param() {
3440 struct Foo<const LEN: usize>;
3441 impl<const LEN: usize> Foo<LEN$0> {}
3454 fn hover_const_pat() {
3458 const FOO: usize = 3;
3474 const FOO: usize = 3
3485 fn hover_mod_def() {
3501 fn hover_self_in_use() {
3504 //! This should not appear
3506 /// But this should appear
3509 use foo::bar::{self$0};
3524 But this should appear