2 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module,
3 ModuleDef, ModuleSource, Semantics,
5 use ide_db::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,
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,
34 impl Default for HoverConfig {
35 fn default() -> Self {
37 implementations: true,
48 pub const NO_ACTIONS: Self = Self {
49 implementations: false,
57 pub fn any(&self) -> bool {
58 self.implementations || self.runnable() || self.goto_type_def
61 pub fn none(&self) -> bool {
65 pub fn runnable(&self) -> bool {
66 self.run || self.debug
70 #[derive(Debug, Clone)]
71 pub enum HoverAction {
73 Implementaion(FilePosition),
74 GoToType(Vec<HoverGotoTypeData>),
77 #[derive(Debug, Clone, Eq, PartialEq)]
78 pub struct HoverGotoTypeData {
80 pub nav: NavigationTarget,
83 /// Contains the results when hovering over an item
84 #[derive(Debug, Default)]
85 pub struct HoverResult {
87 pub actions: Vec<HoverAction>,
92 // Shows additional information, like type of an expression or documentation for definition when "focusing" code.
93 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
96 position: FilePosition,
99 ) -> Option<RangeInfo<HoverResult>> {
100 let sema = Semantics::new(db);
101 let file = sema.parse(position.file_id).syntax().clone();
102 let token = pick_best(file.token_at_offset(position.offset))?;
103 let token = sema.descend_into_macros(token);
105 let mut res = HoverResult::default();
107 let node = token.parent();
108 let definition = match_ast! {
110 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.defined(sema.db)),
111 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)),
112 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
113 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
117 if let Some(definition) = definition {
118 if let Some(markup) = hover_for_definition(db, definition) {
119 let markup = if !markdown {
120 remove_markdown(&markup.as_str())
121 } else if links_in_hover {
122 rewrite_links(db, &markup.as_str(), &definition)
124 remove_links(&markup.as_str())
126 res.markup = Markup::from(markup);
127 if let Some(action) = show_implementations_action(db, definition) {
128 res.actions.push(action);
131 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
132 res.actions.push(action);
135 if let Some(action) = goto_type_action(db, definition) {
136 res.actions.push(action);
139 let range = sema.original_range(&node).range;
140 return Some(RangeInfo::new(range, res));
144 if token.kind() == syntax::SyntaxKind::COMMENT {
145 // don't highlight the entire parent node on comment hover
149 let node = token.ancestors().find(|n| {
150 ast::Expr::can_cast(n.kind())
151 || ast::Pat::can_cast(n.kind())
152 || ast::SelfParam::can_cast(n.kind())
155 let ty = match_ast! {
157 ast::Expr(it) => sema.type_of_expr(&it)?,
158 ast::Pat(it) => sema.type_of_pat(&it)?,
159 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
160 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
161 // (e.g expanding a builtin macro). So we give up here.
162 ast::MacroCall(_it) => return None,
167 res.markup = if markdown {
168 Markup::fenced_block(&ty.display(db))
170 ty.display(db).to_string().into()
172 let range = sema.original_range(&node).range;
173 Some(RangeInfo::new(range, res))
176 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
177 fn to_action(nav_target: NavigationTarget) -> HoverAction {
178 HoverAction::Implementaion(FilePosition {
179 file_id: nav_target.file_id,
180 offset: nav_target.focus_or_full_range().start(),
185 Definition::ModuleDef(it) => match it {
186 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)),
187 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)),
188 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.try_to_nav(db)?)),
189 ModuleDef::Trait(it) => Some(to_action(it.try_to_nav(db)?)),
197 sema: &Semantics<RootDatabase>,
200 ) -> Option<HoverAction> {
202 Definition::ModuleDef(it) => match it {
203 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
204 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
205 .map(|it| HoverAction::Runnable(it)),
208 ModuleDef::Function(it) => {
210 let src = it.source(sema.db)?;
211 if src.file_id != file_id.into() {
212 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
213 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
218 runnable(&sema, src.value.syntax().clone(), file_id)
219 .map(|it| HoverAction::Runnable(it))
227 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
229 Definition::Local(it) => {
230 let mut targets: Vec<ModuleDef> = Vec::new();
231 let mut push_new_def = |item: ModuleDef| {
232 if !targets.contains(&item) {
237 it.ty(db).walk(db, |t| {
238 if let Some(adt) = t.as_adt() {
239 push_new_def(adt.into());
240 } else if let Some(trait_) = t.as_dyn_trait() {
241 push_new_def(trait_.into());
242 } else if let Some(traits) = t.as_impl_traits(db) {
243 traits.into_iter().for_each(|it| push_new_def(it.into()));
244 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
245 push_new_def(trait_.into());
249 let targets = targets
252 Some(HoverGotoTypeData {
253 mod_path: render_path(
256 it.name(db).map(|name| name.to_string()),
258 nav: it.try_to_nav(db)?,
263 Some(HoverAction::GoToType(targets))
270 docs: Option<String>,
271 desc: Option<String>,
272 mod_path: Option<String>,
273 ) -> Option<Markup> {
276 let mut buf = String::new();
278 if let Some(mod_path) = mod_path {
279 if !mod_path.is_empty() {
280 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
283 format_to!(buf, "```rust\n{}\n```", desc);
285 if let Some(doc) = docs {
286 format_to!(buf, "\n___\n\n{}", doc);
290 None => docs.map(Markup::from),
294 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
296 Definition::Field(f) => Some(f.parent_def(db).name(db)),
297 Definition::Local(l) => l.parent(db).name(db),
298 Definition::ModuleDef(md) => match md {
299 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
300 AssocItemContainer::Trait(t) => Some(t.name(db)),
301 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
303 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
308 .map(|name| name.to_string())
311 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
313 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
314 let module_path = module
318 .flat_map(|it| it.name(db).map(|name| name.to_string()));
319 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
322 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
323 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
326 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
327 let mod_path = definition_mod_path(db, &def);
329 Definition::Macro(it) => {
330 let label = macro_label(&it.source(db)?.value);
331 from_def_source_labeled(db, it, Some(label), mod_path)
333 Definition::Field(def) => {
335 let src = def.source(db)?.value;
336 if let FieldSource::Named(it) = src {
337 from_def_source_labeled(db, def, it.short_label(), mod_path)
342 Definition::ModuleDef(it) => match it {
343 ModuleDef::Module(it) => from_def_source_labeled(
346 match it.definition_source(db).value {
347 ModuleSource::Module(it) => it.short_label(),
348 ModuleSource::SourceFile(it) => it.short_label(),
352 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
353 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
354 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
355 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
356 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
357 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
358 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
359 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
360 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
361 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
363 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
364 Definition::SelfType(impl_def) => {
365 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
366 Adt::Struct(it) => from_def_source(db, it, mod_path),
367 Adt::Union(it) => from_def_source(db, it, mod_path),
368 Adt::Enum(it) => from_def_source(db, it, mod_path),
371 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
372 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
373 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
374 Definition::ConstParam(_) => {
375 // FIXME: Hover for generic const param
380 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
382 D: HasSource<Ast = A> + HasAttrs + Copy,
386 let short_label = def.source(db)?.value.short_label();
387 from_def_source_labeled(db, def, short_label, mod_path)
390 fn from_def_source_labeled<D>(
393 short_label: Option<String>,
394 mod_path: Option<String>,
399 let docs = def.attrs(db).docs().map(Into::into);
400 hover_markup(docs, short_label, mod_path)
404 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
405 return tokens.max_by_key(priority);
406 fn priority(n: &SyntaxToken) -> usize {
408 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
409 T!['('] | T![')'] => 2,
410 kind if kind.is_trivia() => 0,
418 use expect_test::{expect, Expect};
419 use ide_db::base_db::FileLoader;
425 fn check_hover_no_result(ra_fixture: &str) {
426 let (analysis, position) = fixture::position(ra_fixture);
427 assert!(analysis.hover(position, true, true).unwrap().is_none());
430 fn check(ra_fixture: &str, expect: Expect) {
431 let (analysis, position) = fixture::position(ra_fixture);
432 let hover = analysis.hover(position, true, true).unwrap().unwrap();
434 let content = analysis.db.file_text(position.file_id);
435 let hovered_element = &content[hover.range];
437 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
438 expect.assert_eq(&actual)
441 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
442 let (analysis, position) = fixture::position(ra_fixture);
443 let hover = analysis.hover(position, false, true).unwrap().unwrap();
445 let content = analysis.db.file_text(position.file_id);
446 let hovered_element = &content[hover.range];
448 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
449 expect.assert_eq(&actual)
452 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
453 let (analysis, position) = fixture::position(ra_fixture);
454 let hover = analysis.hover(position, true, false).unwrap().unwrap();
456 let content = analysis.db.file_text(position.file_id);
457 let hovered_element = &content[hover.range];
459 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
460 expect.assert_eq(&actual)
463 fn check_actions(ra_fixture: &str, expect: Expect) {
464 let (analysis, position) = fixture::position(ra_fixture);
465 let hover = analysis.hover(position, true, true).unwrap().unwrap();
466 expect.assert_debug_eq(&hover.info.actions)
470 fn hover_shows_type_of_an_expression() {
473 pub fn foo() -> u32 { 1 }
476 let foo_test = foo()<|>;
489 fn hover_remove_markdown_if_configured() {
490 check_hover_no_markdown(
492 pub fn foo() -> u32 { 1 }
495 let foo_test = foo()<|>;
506 fn hover_shows_long_type_of_an_expression() {
509 struct Scan<A, B, C> { a: A, b: B, c: C }
510 struct Iter<I> { inner: I }
511 enum Option<T> { Some(T), None }
513 struct OtherStruct<T> { i: T }
515 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
516 Iter { inner: Scan { a, b, c } }
521 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
522 Option::Some(*memo + value)
525 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
532 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
539 fn hover_shows_fn_signature() {
540 // Single file with result
543 pub fn foo() -> u32 { 1 }
545 fn main() { let foo_test = fo<|>o(); }
560 // Multiple candidates but results are ambiguous.
564 pub fn foo() -> u32 { 1 }
567 pub fn foo() -> &str { "" }
570 pub fn foo(a: u32, b: u32) {}
577 fn main() { let foo_test = fo<|>o(); }
589 fn hover_shows_fn_signature_with_type_params() {
592 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
594 fn main() { let foo_test = fo<|>o(); }
604 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
611 fn hover_shows_fn_signature_on_fn_name() {
614 pub fn foo<|>(a: u32, b: u32) -> u32 {}
626 pub fn foo(a: u32, b: u32) -> u32
633 fn hover_shows_fn_doc() {
638 /// # use std::path::Path;
640 /// foo(Path::new("hello, world!"))
642 pub fn foo<|>(_: &Path) {}
662 # use std::path::Path;
664 foo(Path::new("hello, world!"))
671 fn hover_shows_fn_doc_attr_raw_string() {
674 #[doc = r#"Raw string doc attr"#]
675 pub fn foo<|>(_: &Path) {}
698 fn hover_shows_struct_field_info() {
699 // Hovering over the field when instantiating
702 struct Foo { field_a: u32 }
705 let foo = Foo { field_a<|>: 0, };
721 // Hovering over the field in the definition
724 struct Foo { field_a<|>: u32 }
727 let foo = Foo { field_a: 0 };
745 fn hover_const_static() {
747 r#"const foo<|>: u32 = 123;"#,
761 r#"static foo<|>: u32 = 456;"#,
777 fn hover_default_generic_types() {
780 struct Test<K, T = u8> { k: K, t: T }
783 let zz<|> = Test { t: 23u8, k: 33 };
799 enum Option<T> { Some(T) }
802 fn main() { So<|>me(12); }
819 enum Option<T> { Some(T) }
822 fn main() { let b<|>ar = Some(12); }
835 fn hover_enum_variant() {
867 let s = Option::Som<|>e(12);
889 fn hover_for_local_variable() {
891 r#"fn func(foo: i32) { fo<|>o; }"#,
903 fn hover_for_local_variable_pat() {
905 r#"fn func(fo<|>o: i32) {}"#,
917 fn hover_local_var_edge() {
919 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
931 fn hover_for_param_edge() {
933 r#"fn func(<|>foo: i32) {}"#,
945 fn hover_for_param_with_multiple_traits() {
953 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
958 impl Deref<Target = u8> + DerefMut<Target = u8>
965 fn test_hover_infer_associated_method_result() {
968 struct Thing { x: u32 }
971 fn new() -> Thing { Thing { x: 0 } }
974 fn main() { let foo_<|>test = Thing::new(); }
987 fn test_hover_infer_associated_method_exact() {
991 struct Thing { x: u32 }
994 fn new() -> Thing { Thing { x: 0 } }
998 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1004 test::wrapper::Thing
1015 fn test_hover_infer_associated_const_in_pattern() {
1046 fn test_hover_self() {
1049 struct Thing { x: u32 }
1051 fn new() -> Self { Self<|> { x: 0 } }
1068 struct Thing { x: u32 }
1070 fn new() -> Self<|> { Self { x: 0 } }
1089 pub fn new() -> Self<|> { Thing::A }
1108 pub fn thing(a: Self<|>) {}
1126 fn test_hover_shadowing_pat() {
1147 fn test_hover_macro_invocation() {
1150 macro_rules! foo { () => {} }
1152 fn f() { fo<|>o!(); }
1169 fn test_hover_tuple_field() {
1171 r#"struct TS(String, i32<|>);"#,
1183 fn test_hover_through_macro() {
1186 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1189 fn bar() { fo<|>o(); }
1207 fn test_hover_through_expr_in_macro() {
1210 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1211 fn foo(bar:u32) { let a = id!(ba<|>r); }
1224 fn test_hover_through_expr_in_macro_recursive() {
1227 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1228 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1229 fn foo(bar:u32) { let a = id!(ba<|>r); }
1242 fn test_hover_through_func_in_macro_recursive() {
1245 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1246 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1247 fn bar() -> u32 { 0 }
1248 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1260 fn test_hover_through_literal_string_in_macro() {
1263 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1265 let mastered_for_itunes = "";
1266 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1279 fn test_hover_through_assert_macro() {
1282 #[rustc_builtin_macro]
1283 macro_rules! assert {}
1285 fn bar() -> bool { true }
1305 fn test_hover_through_literal_string_in_builtin_macro() {
1306 check_hover_no_result(
1308 #[rustc_builtin_macro]
1309 macro_rules! format {}
1312 format!("hel<|>lo {}", 0);
1319 fn test_hover_non_ascii_space_doc() {
1322 /// <- `\u{3000}` here
1325 fn bar() { fo<|>o(); }
1346 fn test_hover_function_show_qualifiers() {
1348 r#"async fn foo<|>() {}"#,
1362 r#"pub const unsafe fn foo<|>() {}"#,
1371 pub const unsafe fn foo()
1376 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1385 pub(crate) async unsafe extern "C" fn foo()
1392 fn test_hover_trait_show_qualifiers() {
1394 r"unsafe trait foo<|>() {}",
1411 fn test_hover_extern_crate() {
1414 //- /main.rs crate:main deps:std
1415 extern crate st<|>d;
1416 //- /std/lib.rs crate:std
1417 //! Standard library for this test
1424 Standard library for this test
1432 //- /main.rs crate:main deps:std
1433 extern crate std as ab<|>c;
1434 //- /std/lib.rs crate:std
1435 //! Standard library for this test
1442 Standard library for this test
1451 fn test_hover_mod_with_same_name_as_function() {
1454 use self::m<|>y::Bar;
1455 mod my { pub struct Bar; }
1474 fn test_hover_struct_doc_comment() {
1480 fn foo() { let bar = Ba<|>r; }
1501 fn test_hover_struct_doc_attr() {
1507 fn foo() { let bar = Ba<|>r; }
1528 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1532 #[doc = "bar docs 1"]
1533 #[doc = "bar docs 2"]
1536 fn foo() { let bar = Ba<|>r; }
1559 fn test_hover_path_link() {
1563 /// [Foo](struct.Foo.html)
1579 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1585 fn test_hover_path_link_no_strip() {
1589 /// [struct Foo](struct.Foo.html)
1605 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1610 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1612 fn test_hover_path_link_field() {
1617 /// [Foo](struct.Foo.html)
1634 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1640 fn test_hover_intra_link() {
1662 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1668 fn test_hover_intra_link_html_root_url() {
1671 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1692 [Foo](https://example.com/test/foo/struct.Foo.html)
1698 fn test_hover_intra_link_shortlink() {
1718 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1724 fn test_hover_intra_link_shortlink_code() {
1744 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1750 fn test_hover_intra_link_namespaced() {
1771 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1777 fn test_hover_intra_link_shortlink_namspaced_code() {
1797 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1803 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1823 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1829 fn test_hover_intra_link_reference() {
1851 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1857 fn test_hover_external_url() {
1861 /// [external](https://www.google.com)
1877 [external](https://www.google.com)
1882 // Check that we don't rewrite links which we can't identify
1884 fn test_hover_unknown_target() {
1910 fn test_doc_links_enum_variant() {
1931 [E](https://docs.rs/test/*/test/enum.E.html)
1937 fn test_doc_links_field() {
1958 [`S`](https://docs.rs/test/*/test/struct.S.html)
1964 fn test_hover_no_links() {
1965 check_hover_no_links(
1968 /// case 1. bare URL: https://www.example.com/
1969 /// case 2. inline URL with title: [example](https://www.example.com/)
1970 /// case 3. code refrence: [`Result`]
1971 /// case 4. code refrence but miss footnote: [`String`]
1972 /// case 5. autolink: <http://www.example.com/>
1973 /// case 6. email address: <test@example.com>
1974 /// case 7. refrence: [example][example]
1975 /// case 8. collapsed link: [example][]
1976 /// case 9. shortcut link: [example]
1977 /// case 10. inline without URL: [example]()
1978 /// case 11. refrence: [foo][foo]
1979 /// case 12. refrence: [foo][bar]
1980 /// case 13. collapsed link: [foo][]
1981 /// case 14. shortcut link: [foo]
1982 /// case 15. inline without URL: [foo]()
1983 /// case 16. just escaped text: \[foo]
1984 /// case 17. inline link: [Foo](foo::Foo)
1986 /// [`Result`]: ../../std/result/enum.Result.html
1987 /// [^example]: https://www.example.com/
2004 case 1. bare URL: https://www.example.com/
2005 case 2. inline URL with title: [example](https://www.example.com/)
2006 case 3. code refrence: `Result`
2007 case 4. code refrence but miss footnote: `String`
2008 case 5. autolink: http://www.example.com/
2009 case 6. email address: test@example.com
2010 case 7. refrence: example
2011 case 8. collapsed link: example
2012 case 9. shortcut link: example
2013 case 10. inline without URL: example
2014 case 11. refrence: foo
2015 case 12. refrence: foo
2016 case 13. collapsed link: foo
2017 case 14. shortcut link: foo
2018 case 15. inline without URL: foo
2019 case 16. just escaped text: \[foo]
2020 case 17. inline link: Foo
2022 [^example]: https://www.example.com/
2028 fn test_hover_macro_generated_struct_fn_doc_comment() {
2029 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2045 fn foo() { let bar = Bar; bar.fo<|>o(); }
2066 fn test_hover_macro_generated_struct_fn_doc_attr() {
2067 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2075 #[doc = "Do the foo"]
2083 fn foo() { let bar = Bar; bar.fo<|>o(); }
2104 fn test_hover_trait_has_impl_action() {
2106 r#"trait foo<|>() {}"#,
2123 fn test_hover_struct_has_impl_action() {
2125 r"struct foo<|>() {}",
2142 fn test_hover_union_has_impl_action() {
2144 r#"union foo<|>() {}"#,
2161 fn test_hover_enum_has_impl_action() {
2163 r"enum foo<|>() { A, B }",
2180 fn test_hover_test_has_action() {
2190 nav: NavigationTarget {
2195 focus_range: 11..19,
2216 fn test_hover_test_mod_has_action() {
2228 nav: NavigationTarget {
2249 fn test_hover_struct_has_goto_type_action() {
2254 fn main() { let s<|>t = S{ f1:0 }; }
2261 mod_path: "test::S",
2262 nav: NavigationTarget {
2270 description: "struct S",
2281 fn test_hover_generic_struct_has_goto_type_actions() {
2285 struct S<T>{ f1: T }
2287 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2294 mod_path: "test::S",
2295 nav: NavigationTarget {
2300 focus_range: 24..25,
2303 description: "struct S",
2307 mod_path: "test::Arg",
2308 nav: NavigationTarget {
2316 description: "struct Arg",
2327 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2331 struct S<T>{ f1: T }
2333 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2340 mod_path: "test::S",
2341 nav: NavigationTarget {
2346 focus_range: 24..25,
2349 description: "struct S",
2353 mod_path: "test::Arg",
2354 nav: NavigationTarget {
2362 description: "struct Arg",
2373 fn test_hover_tuple_has_goto_type_actions() {
2382 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2389 mod_path: "test::A",
2390 nav: NavigationTarget {
2398 description: "struct A",
2402 mod_path: "test::B",
2403 nav: NavigationTarget {
2408 focus_range: 22..23,
2411 description: "struct B",
2415 mod_path: "test::M::C",
2416 nav: NavigationTarget {
2421 focus_range: 53..54,
2424 description: "pub struct C",
2435 fn test_hover_return_impl_trait_has_goto_type_action() {
2439 fn foo() -> impl Foo {}
2441 fn main() { let s<|>t = foo(); }
2448 mod_path: "test::Foo",
2449 nav: NavigationTarget {
2457 description: "trait Foo",
2468 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2473 fn foo() -> impl Foo<S> {}
2475 fn main() { let s<|>t = foo(); }
2482 mod_path: "test::Foo",
2483 nav: NavigationTarget {
2491 description: "trait Foo",
2495 mod_path: "test::S",
2496 nav: NavigationTarget {
2501 focus_range: 23..24,
2504 description: "struct S",
2515 fn test_hover_return_impl_traits_has_goto_type_action() {
2520 fn foo() -> impl Foo + Bar {}
2522 fn main() { let s<|>t = foo(); }
2529 mod_path: "test::Foo",
2530 nav: NavigationTarget {
2538 description: "trait Foo",
2542 mod_path: "test::Bar",
2543 nav: NavigationTarget {
2548 focus_range: 19..22,
2551 description: "trait Bar",
2562 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2570 fn foo() -> impl Foo<S1> + Bar<S2> {}
2572 fn main() { let s<|>t = foo(); }
2579 mod_path: "test::Foo",
2580 nav: NavigationTarget {
2588 description: "trait Foo",
2592 mod_path: "test::Bar",
2593 nav: NavigationTarget {
2598 focus_range: 22..25,
2601 description: "trait Bar",
2605 mod_path: "test::S1",
2606 nav: NavigationTarget {
2611 focus_range: 39..41,
2614 description: "struct S1",
2618 mod_path: "test::S2",
2619 nav: NavigationTarget {
2624 focus_range: 52..54,
2627 description: "struct S2",
2638 fn test_hover_arg_impl_trait_has_goto_type_action() {
2642 fn foo(ar<|>g: &impl Foo) {}
2649 mod_path: "test::Foo",
2650 nav: NavigationTarget {
2658 description: "trait Foo",
2669 fn test_hover_arg_impl_traits_has_goto_type_action() {
2676 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2683 mod_path: "test::Foo",
2684 nav: NavigationTarget {
2692 description: "trait Foo",
2696 mod_path: "test::Bar",
2697 nav: NavigationTarget {
2702 focus_range: 19..22,
2705 description: "trait Bar",
2709 mod_path: "test::S",
2710 nav: NavigationTarget {
2715 focus_range: 36..37,
2718 description: "struct S",
2729 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2734 let fo<|>o = async { S };
2737 #[prelude_import] use future::*;
2739 #[lang = "future_trait"]
2740 pub trait Future { type Output; }
2748 mod_path: "test::future::Future",
2749 nav: NavigationTarget {
2753 full_range: 101..163,
2754 focus_range: 140..146,
2757 description: "pub trait Future",
2761 mod_path: "test::S",
2762 nav: NavigationTarget {
2770 description: "struct S",
2781 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2786 fn foo(ar<|>g: &impl Foo<S>) {}
2793 mod_path: "test::Foo",
2794 nav: NavigationTarget {
2802 description: "trait Foo",
2806 mod_path: "test::S",
2807 nav: NavigationTarget {
2812 focus_range: 23..24,
2815 description: "struct S",
2826 fn test_hover_dyn_return_has_goto_type_action() {
2834 fn foo() -> B<dyn Foo> {}
2836 fn main() { let s<|>t = foo(); }
2843 mod_path: "test::B",
2844 nav: NavigationTarget {
2849 focus_range: 49..50,
2852 description: "struct B",
2856 mod_path: "test::Foo",
2857 nav: NavigationTarget {
2865 description: "trait Foo",
2876 fn test_hover_dyn_arg_has_goto_type_action() {
2880 fn foo(ar<|>g: &dyn Foo) {}
2887 mod_path: "test::Foo",
2888 nav: NavigationTarget {
2896 description: "trait Foo",
2907 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2912 fn foo(ar<|>g: &dyn Foo<S>) {}
2919 mod_path: "test::Foo",
2920 nav: NavigationTarget {
2928 description: "trait Foo",
2932 mod_path: "test::S",
2933 nav: NavigationTarget {
2938 focus_range: 23..24,
2941 description: "struct S",
2952 fn test_hover_goto_type_action_links_order() {
2955 trait ImplTrait<T> {}
2956 trait DynTrait<T> {}
2960 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2967 mod_path: "test::ImplTrait",
2968 nav: NavigationTarget {
2976 description: "trait ImplTrait",
2980 mod_path: "test::B",
2981 nav: NavigationTarget {
2986 focus_range: 50..51,
2989 description: "struct B",
2993 mod_path: "test::DynTrait",
2994 nav: NavigationTarget {
2999 focus_range: 28..36,
3002 description: "trait DynTrait",
3006 mod_path: "test::S",
3007 nav: NavigationTarget {
3012 focus_range: 65..66,
3015 description: "struct S",
3026 fn test_hover_associated_type_has_goto_type_action() {
3031 fn get(self) -> Self::Item {}
3037 impl Foo for S { type Item = Bar; }
3039 fn test() -> impl Foo { S {} }
3041 fn main() { let s<|>t = test().get(); }
3048 mod_path: "test::Foo",
3049 nav: NavigationTarget {
3057 description: "trait Foo",
3068 fn hover_displays_normalized_crate_names() {
3071 //- /lib.rs crate:name-with-dashes
3073 pub struct Thing { x: u32 }
3076 pub fn new() -> Thing { Thing { x: 0 } }
3080 //- /main.rs crate:main deps:name-with-dashes
3081 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3087 name_with_dashes::wrapper::Thing
3091 pub fn new() -> Thing
3098 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3107 let S { f<|> } = &s;
3121 fn hover_self_param_shows_type() {
3139 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3145 fn bar(sel<|>f: Arc<Foo>) {}
3158 fn hover_doc_outer_inner() {
3165 /// This comment belongs to the function
3189 fn hover_doc_outer_inner_attribue() {
3192 #[doc = "Be quick;"]
3194 #![doc = "time is mana"]
3196 #[doc = "This comment belongs to the function"]
3220 fn hover_comments_dont_highlight_parent() {
3221 check_hover_no_result(
3249 fn hover_lifetime() {
3251 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,
3263 fn hover_type_param() {
3270 impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
3276 T: Copy + Clone + Sized
3283 impl<T> Foo<T<|>> {}
3293 // lifetimes aren't being substituted yet
3297 impl<T: 'static> Foo<T<|>> {}