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 Implementation(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 = markup.as_str();
120 let markup = if !markdown {
121 remove_markdown(markup)
122 } else if links_in_hover {
123 rewrite_links(db, markup, &definition)
127 res.markup = Markup::from(markup);
128 if let Some(action) = show_implementations_action(db, definition) {
129 res.actions.push(action);
132 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
133 res.actions.push(action);
136 if let Some(action) = goto_type_action(db, definition) {
137 res.actions.push(action);
140 let range = sema.original_range(&node).range;
141 return Some(RangeInfo::new(range, res));
145 if token.kind() == syntax::SyntaxKind::COMMENT {
146 // don't highlight the entire parent node on comment hover
150 let node = token.ancestors().find(|n| {
151 ast::Expr::can_cast(n.kind())
152 || ast::Pat::can_cast(n.kind())
153 || ast::SelfParam::can_cast(n.kind())
156 let ty = match_ast! {
158 ast::Expr(it) => sema.type_of_expr(&it)?,
159 ast::Pat(it) => sema.type_of_pat(&it)?,
160 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
161 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
162 // (e.g expanding a builtin macro). So we give up here.
163 ast::MacroCall(_it) => return None,
168 res.markup = if markdown {
169 Markup::fenced_block(&ty.display(db))
171 ty.display(db).to_string().into()
173 let range = sema.original_range(&node).range;
174 Some(RangeInfo::new(range, res))
177 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
178 fn to_action(nav_target: NavigationTarget) -> HoverAction {
179 HoverAction::Implementation(FilePosition {
180 file_id: nav_target.file_id,
181 offset: nav_target.focus_or_full_range().start(),
185 let adt = match def {
186 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
187 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
188 Definition::SelfType(it) => it.target_ty(db).as_adt(),
192 Adt::Struct(it) => it.try_to_nav(db),
193 Adt::Union(it) => it.try_to_nav(db),
194 Adt::Enum(it) => it.try_to_nav(db),
200 sema: &Semantics<RootDatabase>,
203 ) -> Option<HoverAction> {
205 Definition::ModuleDef(it) => match it {
206 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
207 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
208 .map(|it| HoverAction::Runnable(it)),
211 ModuleDef::Function(it) => {
213 let src = it.source(sema.db)?;
214 if src.file_id != file_id.into() {
215 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
216 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
221 runnable(&sema, src.value.syntax().clone(), file_id)
222 .map(|it| HoverAction::Runnable(it))
230 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
232 Definition::Local(it) => {
233 let mut targets: Vec<ModuleDef> = Vec::new();
234 let mut push_new_def = |item: ModuleDef| {
235 if !targets.contains(&item) {
240 it.ty(db).walk(db, |t| {
241 if let Some(adt) = t.as_adt() {
242 push_new_def(adt.into());
243 } else if let Some(trait_) = t.as_dyn_trait() {
244 push_new_def(trait_.into());
245 } else if let Some(traits) = t.as_impl_traits(db) {
246 traits.into_iter().for_each(|it| push_new_def(it.into()));
247 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
248 push_new_def(trait_.into());
252 let targets = targets
255 Some(HoverGotoTypeData {
256 mod_path: render_path(
259 it.name(db).map(|name| name.to_string()),
261 nav: it.try_to_nav(db)?,
266 Some(HoverAction::GoToType(targets))
273 docs: Option<String>,
274 desc: Option<String>,
275 mod_path: Option<String>,
276 ) -> Option<Markup> {
279 let mut buf = String::new();
281 if let Some(mod_path) = mod_path {
282 if !mod_path.is_empty() {
283 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
286 format_to!(buf, "```rust\n{}\n```", desc);
288 if let Some(doc) = docs {
289 format_to!(buf, "\n___\n\n{}", doc);
293 None => docs.map(Markup::from),
297 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
299 Definition::Field(f) => Some(f.parent_def(db).name(db)),
300 Definition::Local(l) => l.parent(db).name(db),
301 Definition::ModuleDef(md) => match md {
302 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
303 AssocItemContainer::Trait(t) => Some(t.name(db)),
304 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
306 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
311 .map(|name| name.to_string())
314 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
316 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
317 let module_path = module
321 .flat_map(|it| it.name(db).map(|name| name.to_string()));
322 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
325 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
326 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
329 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
330 let mod_path = definition_mod_path(db, &def);
332 Definition::Macro(it) => {
333 let label = macro_label(&it.source(db)?.value);
334 from_def_source_labeled(db, it, Some(label), mod_path)
336 Definition::Field(def) => {
338 let src = def.source(db)?.value;
339 if let FieldSource::Named(it) = src {
340 from_def_source_labeled(db, def, it.short_label(), mod_path)
345 Definition::ModuleDef(it) => match it {
346 ModuleDef::Module(it) => from_def_source_labeled(
349 match it.definition_source(db).value {
350 ModuleSource::Module(it) => it.short_label(),
351 ModuleSource::SourceFile(it) => it.short_label(),
355 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
356 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
357 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
358 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
359 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
360 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
361 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
362 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
363 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
364 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
366 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
367 Definition::SelfType(impl_def) => {
368 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
369 Adt::Struct(it) => from_def_source(db, it, mod_path),
370 Adt::Union(it) => from_def_source(db, it, mod_path),
371 Adt::Enum(it) => from_def_source(db, it, mod_path),
374 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
375 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
376 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
377 Definition::ConstParam(it) => from_def_source(db, it, None),
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_self_has_impl_action() {
2182 r#"struct foo where Self<|>:;"#,
2199 fn test_hover_test_has_action() {
2209 nav: NavigationTarget {
2214 focus_range: 11..19,
2235 fn test_hover_test_mod_has_action() {
2247 nav: NavigationTarget {
2268 fn test_hover_struct_has_goto_type_action() {
2273 fn main() { let s<|>t = S{ f1:0 }; }
2280 mod_path: "test::S",
2281 nav: NavigationTarget {
2289 description: "struct S",
2300 fn test_hover_generic_struct_has_goto_type_actions() {
2304 struct S<T>{ f1: T }
2306 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2313 mod_path: "test::S",
2314 nav: NavigationTarget {
2319 focus_range: 24..25,
2322 description: "struct S",
2326 mod_path: "test::Arg",
2327 nav: NavigationTarget {
2335 description: "struct Arg",
2346 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2350 struct S<T>{ f1: T }
2352 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2359 mod_path: "test::S",
2360 nav: NavigationTarget {
2365 focus_range: 24..25,
2368 description: "struct S",
2372 mod_path: "test::Arg",
2373 nav: NavigationTarget {
2381 description: "struct Arg",
2392 fn test_hover_tuple_has_goto_type_actions() {
2401 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2408 mod_path: "test::A",
2409 nav: NavigationTarget {
2417 description: "struct A",
2421 mod_path: "test::B",
2422 nav: NavigationTarget {
2427 focus_range: 22..23,
2430 description: "struct B",
2434 mod_path: "test::M::C",
2435 nav: NavigationTarget {
2440 focus_range: 53..54,
2443 description: "pub struct C",
2454 fn test_hover_return_impl_trait_has_goto_type_action() {
2458 fn foo() -> impl Foo {}
2460 fn main() { let s<|>t = foo(); }
2467 mod_path: "test::Foo",
2468 nav: NavigationTarget {
2476 description: "trait Foo",
2487 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2492 fn foo() -> impl Foo<S> {}
2494 fn main() { let s<|>t = foo(); }
2501 mod_path: "test::Foo",
2502 nav: NavigationTarget {
2510 description: "trait Foo",
2514 mod_path: "test::S",
2515 nav: NavigationTarget {
2520 focus_range: 23..24,
2523 description: "struct S",
2534 fn test_hover_return_impl_traits_has_goto_type_action() {
2539 fn foo() -> impl Foo + Bar {}
2541 fn main() { let s<|>t = foo(); }
2548 mod_path: "test::Foo",
2549 nav: NavigationTarget {
2557 description: "trait Foo",
2561 mod_path: "test::Bar",
2562 nav: NavigationTarget {
2567 focus_range: 19..22,
2570 description: "trait Bar",
2581 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2589 fn foo() -> impl Foo<S1> + Bar<S2> {}
2591 fn main() { let s<|>t = foo(); }
2598 mod_path: "test::Foo",
2599 nav: NavigationTarget {
2607 description: "trait Foo",
2611 mod_path: "test::Bar",
2612 nav: NavigationTarget {
2617 focus_range: 22..25,
2620 description: "trait Bar",
2624 mod_path: "test::S1",
2625 nav: NavigationTarget {
2630 focus_range: 39..41,
2633 description: "struct S1",
2637 mod_path: "test::S2",
2638 nav: NavigationTarget {
2643 focus_range: 52..54,
2646 description: "struct S2",
2657 fn test_hover_arg_impl_trait_has_goto_type_action() {
2661 fn foo(ar<|>g: &impl Foo) {}
2668 mod_path: "test::Foo",
2669 nav: NavigationTarget {
2677 description: "trait Foo",
2688 fn test_hover_arg_impl_traits_has_goto_type_action() {
2695 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2702 mod_path: "test::Foo",
2703 nav: NavigationTarget {
2711 description: "trait Foo",
2715 mod_path: "test::Bar",
2716 nav: NavigationTarget {
2721 focus_range: 19..22,
2724 description: "trait Bar",
2728 mod_path: "test::S",
2729 nav: NavigationTarget {
2734 focus_range: 36..37,
2737 description: "struct S",
2748 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2753 let fo<|>o = async { S };
2756 #[prelude_import] use future::*;
2758 #[lang = "future_trait"]
2759 pub trait Future { type Output; }
2767 mod_path: "test::future::Future",
2768 nav: NavigationTarget {
2772 full_range: 101..163,
2773 focus_range: 140..146,
2776 description: "pub trait Future",
2780 mod_path: "test::S",
2781 nav: NavigationTarget {
2789 description: "struct S",
2800 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2805 fn foo(ar<|>g: &impl Foo<S>) {}
2812 mod_path: "test::Foo",
2813 nav: NavigationTarget {
2821 description: "trait Foo",
2825 mod_path: "test::S",
2826 nav: NavigationTarget {
2831 focus_range: 23..24,
2834 description: "struct S",
2845 fn test_hover_dyn_return_has_goto_type_action() {
2853 fn foo() -> B<dyn Foo> {}
2855 fn main() { let s<|>t = foo(); }
2862 mod_path: "test::B",
2863 nav: NavigationTarget {
2868 focus_range: 49..50,
2871 description: "struct B",
2875 mod_path: "test::Foo",
2876 nav: NavigationTarget {
2884 description: "trait Foo",
2895 fn test_hover_dyn_arg_has_goto_type_action() {
2899 fn foo(ar<|>g: &dyn Foo) {}
2906 mod_path: "test::Foo",
2907 nav: NavigationTarget {
2915 description: "trait Foo",
2926 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2931 fn foo(ar<|>g: &dyn Foo<S>) {}
2938 mod_path: "test::Foo",
2939 nav: NavigationTarget {
2947 description: "trait Foo",
2951 mod_path: "test::S",
2952 nav: NavigationTarget {
2957 focus_range: 23..24,
2960 description: "struct S",
2971 fn test_hover_goto_type_action_links_order() {
2974 trait ImplTrait<T> {}
2975 trait DynTrait<T> {}
2979 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2986 mod_path: "test::ImplTrait",
2987 nav: NavigationTarget {
2995 description: "trait ImplTrait",
2999 mod_path: "test::B",
3000 nav: NavigationTarget {
3005 focus_range: 50..51,
3008 description: "struct B",
3012 mod_path: "test::DynTrait",
3013 nav: NavigationTarget {
3018 focus_range: 28..36,
3021 description: "trait DynTrait",
3025 mod_path: "test::S",
3026 nav: NavigationTarget {
3031 focus_range: 65..66,
3034 description: "struct S",
3045 fn test_hover_associated_type_has_goto_type_action() {
3050 fn get(self) -> Self::Item {}
3056 impl Foo for S { type Item = Bar; }
3058 fn test() -> impl Foo { S {} }
3060 fn main() { let s<|>t = test().get(); }
3067 mod_path: "test::Foo",
3068 nav: NavigationTarget {
3076 description: "trait Foo",
3087 fn hover_displays_normalized_crate_names() {
3090 //- /lib.rs crate:name-with-dashes
3092 pub struct Thing { x: u32 }
3095 pub fn new() -> Thing { Thing { x: 0 } }
3099 //- /main.rs crate:main deps:name-with-dashes
3100 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3106 name_with_dashes::wrapper::Thing
3110 pub fn new() -> Thing
3117 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3126 let S { f<|> } = &s;
3140 fn hover_self_param_shows_type() {
3158 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3164 fn bar(sel<|>f: Arc<Foo>) {}
3177 fn hover_doc_outer_inner() {
3184 /// This comment belongs to the function
3208 fn hover_doc_outer_inner_attribue() {
3211 #[doc = "Be quick;"]
3213 #![doc = "time is mana"]
3215 #[doc = "This comment belongs to the function"]
3239 fn hover_comments_dont_highlight_parent() {
3240 check_hover_no_result(
3268 fn hover_lifetime() {
3270 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,
3282 fn hover_type_param() {
3289 impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
3295 T: Copy + Clone + Sized
3302 impl<T> Foo<T<|>> {}
3312 // lifetimes aren't being substituted yet
3316 impl<T: 'static> Foo<T<|>> {}
3329 fn hover_const_param() {
3332 struct Foo<const LEN: usize>;
3333 impl<const LEN: usize> Foo<LEN<|>> {}