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, ToNav, 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.to_nav(db))),
187 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.to_nav(db))),
188 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.to_nav(db))),
189 ModuleDef::Trait(it) => Some(to_action(it.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_old(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_old(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(_) | Definition::ConstParam(_) => {
374 // FIXME: Hover for generic param
379 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
381 D: HasSource<Ast = A> + HasAttrs + Copy,
385 let short_label = def.source_old(db).value.short_label();
386 from_def_source_labeled(db, def, short_label, mod_path)
389 fn from_def_source_labeled<D>(
392 short_label: Option<String>,
393 mod_path: Option<String>,
398 let docs = def.attrs(db).docs().map(Into::into);
399 hover_markup(docs, short_label, mod_path)
403 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
404 return tokens.max_by_key(priority);
405 fn priority(n: &SyntaxToken) -> usize {
407 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
408 T!['('] | T![')'] => 2,
409 kind if kind.is_trivia() => 0,
417 use expect_test::{expect, Expect};
418 use ide_db::base_db::FileLoader;
424 fn check_hover_no_result(ra_fixture: &str) {
425 let (analysis, position) = fixture::position(ra_fixture);
426 assert!(analysis.hover(position, true, true).unwrap().is_none());
429 fn check(ra_fixture: &str, expect: Expect) {
430 let (analysis, position) = fixture::position(ra_fixture);
431 let hover = analysis.hover(position, true, true).unwrap().unwrap();
433 let content = analysis.db.file_text(position.file_id);
434 let hovered_element = &content[hover.range];
436 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
437 expect.assert_eq(&actual)
440 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
441 let (analysis, position) = fixture::position(ra_fixture);
442 let hover = analysis.hover(position, false, true).unwrap().unwrap();
444 let content = analysis.db.file_text(position.file_id);
445 let hovered_element = &content[hover.range];
447 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
448 expect.assert_eq(&actual)
451 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
452 let (analysis, position) = fixture::position(ra_fixture);
453 let hover = analysis.hover(position, true, false).unwrap().unwrap();
455 let content = analysis.db.file_text(position.file_id);
456 let hovered_element = &content[hover.range];
458 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
459 expect.assert_eq(&actual)
462 fn check_actions(ra_fixture: &str, expect: Expect) {
463 let (analysis, position) = fixture::position(ra_fixture);
464 let hover = analysis.hover(position, true, true).unwrap().unwrap();
465 expect.assert_debug_eq(&hover.info.actions)
469 fn hover_shows_type_of_an_expression() {
472 pub fn foo() -> u32 { 1 }
475 let foo_test = foo()<|>;
488 fn hover_remove_markdown_if_configured() {
489 check_hover_no_markdown(
491 pub fn foo() -> u32 { 1 }
494 let foo_test = foo()<|>;
505 fn hover_shows_long_type_of_an_expression() {
508 struct Scan<A, B, C> { a: A, b: B, c: C }
509 struct Iter<I> { inner: I }
510 enum Option<T> { Some(T), None }
512 struct OtherStruct<T> { i: T }
514 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
515 Iter { inner: Scan { a, b, c } }
520 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
521 Option::Some(*memo + value)
524 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
531 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
538 fn hover_shows_fn_signature() {
539 // Single file with result
542 pub fn foo() -> u32 { 1 }
544 fn main() { let foo_test = fo<|>o(); }
559 // Multiple candidates but results are ambiguous.
563 pub fn foo() -> u32 { 1 }
566 pub fn foo() -> &str { "" }
569 pub fn foo(a: u32, b: u32) {}
576 fn main() { let foo_test = fo<|>o(); }
588 fn hover_shows_fn_signature_with_type_params() {
591 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
593 fn main() { let foo_test = fo<|>o(); }
603 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
610 fn hover_shows_fn_signature_on_fn_name() {
613 pub fn foo<|>(a: u32, b: u32) -> u32 {}
625 pub fn foo(a: u32, b: u32) -> u32
632 fn hover_shows_fn_doc() {
637 /// # use std::path::Path;
639 /// foo(Path::new("hello, world!"))
641 pub fn foo<|>(_: &Path) {}
661 # use std::path::Path;
663 foo(Path::new("hello, world!"))
670 fn hover_shows_fn_doc_attr_raw_string() {
673 #[doc = r#"Raw string doc attr"#]
674 pub fn foo<|>(_: &Path) {}
697 fn hover_shows_struct_field_info() {
698 // Hovering over the field when instantiating
701 struct Foo { field_a: u32 }
704 let foo = Foo { field_a<|>: 0, };
720 // Hovering over the field in the definition
723 struct Foo { field_a<|>: u32 }
726 let foo = Foo { field_a: 0 };
744 fn hover_const_static() {
746 r#"const foo<|>: u32 = 123;"#,
760 r#"static foo<|>: u32 = 456;"#,
776 fn hover_default_generic_types() {
779 struct Test<K, T = u8> { k: K, t: T }
782 let zz<|> = Test { t: 23u8, k: 33 };
798 enum Option<T> { Some(T) }
801 fn main() { So<|>me(12); }
818 enum Option<T> { Some(T) }
821 fn main() { let b<|>ar = Some(12); }
834 fn hover_enum_variant() {
866 let s = Option::Som<|>e(12);
888 fn hover_for_local_variable() {
890 r#"fn func(foo: i32) { fo<|>o; }"#,
902 fn hover_for_local_variable_pat() {
904 r#"fn func(fo<|>o: i32) {}"#,
916 fn hover_local_var_edge() {
918 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
930 fn hover_for_param_edge() {
932 r#"fn func(<|>foo: i32) {}"#,
944 fn hover_for_param_with_multiple_traits() {
952 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
957 impl Deref<Target = u8> + DerefMut<Target = u8>
964 fn test_hover_infer_associated_method_result() {
967 struct Thing { x: u32 }
970 fn new() -> Thing { Thing { x: 0 } }
973 fn main() { let foo_<|>test = Thing::new(); }
986 fn test_hover_infer_associated_method_exact() {
990 struct Thing { x: u32 }
993 fn new() -> Thing { Thing { x: 0 } }
997 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1003 test::wrapper::Thing
1014 fn test_hover_infer_associated_const_in_pattern() {
1045 fn test_hover_self() {
1048 struct Thing { x: u32 }
1050 fn new() -> Self { Self<|> { x: 0 } }
1067 struct Thing { x: u32 }
1069 fn new() -> Self<|> { Self { x: 0 } }
1088 pub fn new() -> Self<|> { Thing::A }
1107 pub fn thing(a: Self<|>) {}
1125 fn test_hover_shadowing_pat() {
1146 fn test_hover_macro_invocation() {
1149 macro_rules! foo { () => {} }
1151 fn f() { fo<|>o!(); }
1168 fn test_hover_tuple_field() {
1170 r#"struct TS(String, i32<|>);"#,
1182 fn test_hover_through_macro() {
1185 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1188 fn bar() { fo<|>o(); }
1206 fn test_hover_through_expr_in_macro() {
1209 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1210 fn foo(bar:u32) { let a = id!(ba<|>r); }
1223 fn test_hover_through_expr_in_macro_recursive() {
1226 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1227 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1228 fn foo(bar:u32) { let a = id!(ba<|>r); }
1241 fn test_hover_through_func_in_macro_recursive() {
1244 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1245 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1246 fn bar() -> u32 { 0 }
1247 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1259 fn test_hover_through_literal_string_in_macro() {
1262 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1264 let mastered_for_itunes = "";
1265 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1278 fn test_hover_through_assert_macro() {
1281 #[rustc_builtin_macro]
1282 macro_rules! assert {}
1284 fn bar() -> bool { true }
1304 fn test_hover_through_literal_string_in_builtin_macro() {
1305 check_hover_no_result(
1307 #[rustc_builtin_macro]
1308 macro_rules! format {}
1311 format!("hel<|>lo {}", 0);
1318 fn test_hover_non_ascii_space_doc() {
1321 /// <- `\u{3000}` here
1324 fn bar() { fo<|>o(); }
1345 fn test_hover_function_show_qualifiers() {
1347 r#"async fn foo<|>() {}"#,
1361 r#"pub const unsafe fn foo<|>() {}"#,
1370 pub const unsafe fn foo()
1375 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1384 pub(crate) async unsafe extern "C" fn foo()
1391 fn test_hover_trait_show_qualifiers() {
1393 r"unsafe trait foo<|>() {}",
1410 fn test_hover_extern_crate() {
1413 //- /main.rs crate:main deps:std
1414 extern crate st<|>d;
1415 //- /std/lib.rs crate:std
1416 //! Standard library for this test
1423 Standard library for this test
1431 //- /main.rs crate:main deps:std
1432 extern crate std as ab<|>c;
1433 //- /std/lib.rs crate:std
1434 //! Standard library for this test
1441 Standard library for this test
1450 fn test_hover_mod_with_same_name_as_function() {
1453 use self::m<|>y::Bar;
1454 mod my { pub struct Bar; }
1473 fn test_hover_struct_doc_comment() {
1479 fn foo() { let bar = Ba<|>r; }
1500 fn test_hover_struct_doc_attr() {
1506 fn foo() { let bar = Ba<|>r; }
1527 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1531 #[doc = "bar docs 1"]
1532 #[doc = "bar docs 2"]
1535 fn foo() { let bar = Ba<|>r; }
1558 fn test_hover_path_link() {
1562 /// [Foo](struct.Foo.html)
1578 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1584 fn test_hover_path_link_no_strip() {
1588 /// [struct Foo](struct.Foo.html)
1604 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1609 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1611 fn test_hover_path_link_field() {
1616 /// [Foo](struct.Foo.html)
1633 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1639 fn test_hover_intra_link() {
1661 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1667 fn test_hover_intra_link_html_root_url() {
1670 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1691 [Foo](https://example.com/test/foo/struct.Foo.html)
1697 fn test_hover_intra_link_shortlink() {
1717 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1723 fn test_hover_intra_link_shortlink_code() {
1743 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1749 fn test_hover_intra_link_namespaced() {
1770 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1776 fn test_hover_intra_link_shortlink_namspaced_code() {
1796 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1802 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1822 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1828 fn test_hover_intra_link_reference() {
1850 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1856 fn test_hover_external_url() {
1860 /// [external](https://www.google.com)
1876 [external](https://www.google.com)
1881 // Check that we don't rewrite links which we can't identify
1883 fn test_hover_unknown_target() {
1909 fn test_doc_links_enum_variant() {
1930 [E](https://docs.rs/test/*/test/enum.E.html)
1936 fn test_doc_links_field() {
1957 [`S`](https://docs.rs/test/*/test/struct.S.html)
1963 fn test_hover_no_links() {
1964 check_hover_no_links(
1967 /// case 1. bare URL: https://www.example.com/
1968 /// case 2. inline URL with title: [example](https://www.example.com/)
1969 /// case 3. code refrence: [`Result`]
1970 /// case 4. code refrence but miss footnote: [`String`]
1971 /// case 5. autolink: <http://www.example.com/>
1972 /// case 6. email address: <test@example.com>
1973 /// case 7. refrence: [example][example]
1974 /// case 8. collapsed link: [example][]
1975 /// case 9. shortcut link: [example]
1976 /// case 10. inline without URL: [example]()
1977 /// case 11. refrence: [foo][foo]
1978 /// case 12. refrence: [foo][bar]
1979 /// case 13. collapsed link: [foo][]
1980 /// case 14. shortcut link: [foo]
1981 /// case 15. inline without URL: [foo]()
1982 /// case 16. just escaped text: \[foo]
1983 /// case 17. inline link: [Foo](foo::Foo)
1985 /// [`Result`]: ../../std/result/enum.Result.html
1986 /// [^example]: https://www.example.com/
2003 case 1. bare URL: https://www.example.com/
2004 case 2. inline URL with title: [example](https://www.example.com/)
2005 case 3. code refrence: `Result`
2006 case 4. code refrence but miss footnote: `String`
2007 case 5. autolink: http://www.example.com/
2008 case 6. email address: test@example.com
2009 case 7. refrence: example
2010 case 8. collapsed link: example
2011 case 9. shortcut link: example
2012 case 10. inline without URL: example
2013 case 11. refrence: foo
2014 case 12. refrence: foo
2015 case 13. collapsed link: foo
2016 case 14. shortcut link: foo
2017 case 15. inline without URL: foo
2018 case 16. just escaped text: \[foo]
2019 case 17. inline link: Foo
2021 [^example]: https://www.example.com/
2027 fn test_hover_macro_generated_struct_fn_doc_comment() {
2028 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2044 fn foo() { let bar = Bar; bar.fo<|>o(); }
2065 fn test_hover_macro_generated_struct_fn_doc_attr() {
2066 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2074 #[doc = "Do the foo"]
2082 fn foo() { let bar = Bar; bar.fo<|>o(); }
2103 fn test_hover_trait_has_impl_action() {
2105 r#"trait foo<|>() {}"#,
2122 fn test_hover_struct_has_impl_action() {
2124 r"struct foo<|>() {}",
2141 fn test_hover_union_has_impl_action() {
2143 r#"union foo<|>() {}"#,
2160 fn test_hover_enum_has_impl_action() {
2162 r"enum foo<|>() { A, B }",
2179 fn test_hover_test_has_action() {
2189 nav: NavigationTarget {
2194 focus_range: 11..19,
2215 fn test_hover_test_mod_has_action() {
2227 nav: NavigationTarget {
2248 fn test_hover_struct_has_goto_type_action() {
2253 fn main() { let s<|>t = S{ f1:0 }; }
2260 mod_path: "test::S",
2261 nav: NavigationTarget {
2269 description: "struct S",
2280 fn test_hover_generic_struct_has_goto_type_actions() {
2284 struct S<T>{ f1: T }
2286 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2293 mod_path: "test::S",
2294 nav: NavigationTarget {
2299 focus_range: 24..25,
2302 description: "struct S",
2306 mod_path: "test::Arg",
2307 nav: NavigationTarget {
2315 description: "struct Arg",
2326 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2330 struct S<T>{ f1: T }
2332 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2339 mod_path: "test::S",
2340 nav: NavigationTarget {
2345 focus_range: 24..25,
2348 description: "struct S",
2352 mod_path: "test::Arg",
2353 nav: NavigationTarget {
2361 description: "struct Arg",
2372 fn test_hover_tuple_has_goto_type_actions() {
2381 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2388 mod_path: "test::A",
2389 nav: NavigationTarget {
2397 description: "struct A",
2401 mod_path: "test::B",
2402 nav: NavigationTarget {
2407 focus_range: 22..23,
2410 description: "struct B",
2414 mod_path: "test::M::C",
2415 nav: NavigationTarget {
2420 focus_range: 53..54,
2423 description: "pub struct C",
2434 fn test_hover_return_impl_trait_has_goto_type_action() {
2438 fn foo() -> impl Foo {}
2440 fn main() { let s<|>t = foo(); }
2447 mod_path: "test::Foo",
2448 nav: NavigationTarget {
2456 description: "trait Foo",
2467 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2472 fn foo() -> impl Foo<S> {}
2474 fn main() { let s<|>t = foo(); }
2481 mod_path: "test::Foo",
2482 nav: NavigationTarget {
2490 description: "trait Foo",
2494 mod_path: "test::S",
2495 nav: NavigationTarget {
2500 focus_range: 23..24,
2503 description: "struct S",
2514 fn test_hover_return_impl_traits_has_goto_type_action() {
2519 fn foo() -> impl Foo + Bar {}
2521 fn main() { let s<|>t = foo(); }
2528 mod_path: "test::Foo",
2529 nav: NavigationTarget {
2537 description: "trait Foo",
2541 mod_path: "test::Bar",
2542 nav: NavigationTarget {
2547 focus_range: 19..22,
2550 description: "trait Bar",
2561 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2569 fn foo() -> impl Foo<S1> + Bar<S2> {}
2571 fn main() { let s<|>t = foo(); }
2578 mod_path: "test::Foo",
2579 nav: NavigationTarget {
2587 description: "trait Foo",
2591 mod_path: "test::Bar",
2592 nav: NavigationTarget {
2597 focus_range: 22..25,
2600 description: "trait Bar",
2604 mod_path: "test::S1",
2605 nav: NavigationTarget {
2610 focus_range: 39..41,
2613 description: "struct S1",
2617 mod_path: "test::S2",
2618 nav: NavigationTarget {
2623 focus_range: 52..54,
2626 description: "struct S2",
2637 fn test_hover_arg_impl_trait_has_goto_type_action() {
2641 fn foo(ar<|>g: &impl Foo) {}
2648 mod_path: "test::Foo",
2649 nav: NavigationTarget {
2657 description: "trait Foo",
2668 fn test_hover_arg_impl_traits_has_goto_type_action() {
2675 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2682 mod_path: "test::Foo",
2683 nav: NavigationTarget {
2691 description: "trait Foo",
2695 mod_path: "test::Bar",
2696 nav: NavigationTarget {
2701 focus_range: 19..22,
2704 description: "trait Bar",
2708 mod_path: "test::S",
2709 nav: NavigationTarget {
2714 focus_range: 36..37,
2717 description: "struct S",
2728 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2733 let fo<|>o = async { S };
2736 #[prelude_import] use future::*;
2738 #[lang = "future_trait"]
2739 pub trait Future { type Output; }
2747 mod_path: "test::future::Future",
2748 nav: NavigationTarget {
2752 full_range: 101..163,
2753 focus_range: 140..146,
2756 description: "pub trait Future",
2760 mod_path: "test::S",
2761 nav: NavigationTarget {
2769 description: "struct S",
2780 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2785 fn foo(ar<|>g: &impl Foo<S>) {}
2792 mod_path: "test::Foo",
2793 nav: NavigationTarget {
2801 description: "trait Foo",
2805 mod_path: "test::S",
2806 nav: NavigationTarget {
2811 focus_range: 23..24,
2814 description: "struct S",
2825 fn test_hover_dyn_return_has_goto_type_action() {
2833 fn foo() -> B<dyn Foo> {}
2835 fn main() { let s<|>t = foo(); }
2842 mod_path: "test::B",
2843 nav: NavigationTarget {
2848 focus_range: 49..50,
2851 description: "struct B",
2855 mod_path: "test::Foo",
2856 nav: NavigationTarget {
2864 description: "trait Foo",
2875 fn test_hover_dyn_arg_has_goto_type_action() {
2879 fn foo(ar<|>g: &dyn Foo) {}
2886 mod_path: "test::Foo",
2887 nav: NavigationTarget {
2895 description: "trait Foo",
2906 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2911 fn foo(ar<|>g: &dyn Foo<S>) {}
2918 mod_path: "test::Foo",
2919 nav: NavigationTarget {
2927 description: "trait Foo",
2931 mod_path: "test::S",
2932 nav: NavigationTarget {
2937 focus_range: 23..24,
2940 description: "struct S",
2951 fn test_hover_goto_type_action_links_order() {
2954 trait ImplTrait<T> {}
2955 trait DynTrait<T> {}
2959 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2966 mod_path: "test::ImplTrait",
2967 nav: NavigationTarget {
2975 description: "trait ImplTrait",
2979 mod_path: "test::B",
2980 nav: NavigationTarget {
2985 focus_range: 50..51,
2988 description: "struct B",
2992 mod_path: "test::DynTrait",
2993 nav: NavigationTarget {
2998 focus_range: 28..36,
3001 description: "trait DynTrait",
3005 mod_path: "test::S",
3006 nav: NavigationTarget {
3011 focus_range: 65..66,
3014 description: "struct S",
3025 fn test_hover_associated_type_has_goto_type_action() {
3030 fn get(self) -> Self::Item {}
3036 impl Foo for S { type Item = Bar; }
3038 fn test() -> impl Foo { S {} }
3040 fn main() { let s<|>t = test().get(); }
3047 mod_path: "test::Foo",
3048 nav: NavigationTarget {
3056 description: "trait Foo",
3067 fn hover_displays_normalized_crate_names() {
3070 //- /lib.rs crate:name-with-dashes
3072 pub struct Thing { x: u32 }
3075 pub fn new() -> Thing { Thing { x: 0 } }
3079 //- /main.rs crate:main deps:name-with-dashes
3080 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3086 name_with_dashes::wrapper::Thing
3090 pub fn new() -> Thing
3097 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3106 let S { f<|> } = &s;
3120 fn hover_self_param_shows_type() {
3138 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3144 fn bar(sel<|>f: Arc<Foo>) {}
3157 fn hover_doc_outer_inner() {
3164 /// This comment belongs to the function
3188 fn hover_doc_outer_inner_attribue() {
3191 #[doc = "Be quick;"]
3193 #![doc = "time is mana"]
3195 #[doc = "This comment belongs to the function"]
3219 fn hover_comments_dont_highlight_parent() {
3220 check_hover_no_result(
3248 fn hover_lifetime() {
3250 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,