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 // FIXME: Currently proc-macro do not have ast-node,
331 // such that it does not have source
332 // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
333 if it.is_proc_macro() {
337 let label = macro_label(&it.source_old(db).value);
338 from_def_source_labeled(db, it, Some(label), mod_path)
340 Definition::Field(def) => {
342 let src = def.source_old(db).value;
343 if let FieldSource::Named(it) = src {
344 from_def_source_labeled(db, def, it.short_label(), mod_path)
349 Definition::ModuleDef(it) => match it {
350 ModuleDef::Module(it) => from_def_source_labeled(
353 match it.definition_source(db).value {
354 ModuleSource::Module(it) => it.short_label(),
355 ModuleSource::SourceFile(it) => it.short_label(),
359 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
360 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
361 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
362 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
363 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
364 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
365 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
366 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
367 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
368 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
370 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
371 Definition::SelfType(impl_def) => {
372 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
373 Adt::Struct(it) => from_def_source(db, it, mod_path),
374 Adt::Union(it) => from_def_source(db, it, mod_path),
375 Adt::Enum(it) => from_def_source(db, it, mod_path),
378 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
379 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
380 Definition::TypeParam(_) | Definition::ConstParam(_) => {
381 // FIXME: Hover for generic param
386 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
388 D: HasSource<Ast = A> + HasAttrs + Copy,
392 let short_label = def.source_old(db).value.short_label();
393 from_def_source_labeled(db, def, short_label, mod_path)
396 fn from_def_source_labeled<D>(
399 short_label: Option<String>,
400 mod_path: Option<String>,
405 let docs = def.attrs(db).docs().map(Into::into);
406 hover_markup(docs, short_label, mod_path)
410 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
411 return tokens.max_by_key(priority);
412 fn priority(n: &SyntaxToken) -> usize {
414 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
415 T!['('] | T![')'] => 2,
416 kind if kind.is_trivia() => 0,
424 use expect_test::{expect, Expect};
425 use ide_db::base_db::FileLoader;
431 fn check_hover_no_result(ra_fixture: &str) {
432 let (analysis, position) = fixture::position(ra_fixture);
433 assert!(analysis.hover(position, true, true).unwrap().is_none());
436 fn check(ra_fixture: &str, expect: Expect) {
437 let (analysis, position) = fixture::position(ra_fixture);
438 let hover = analysis.hover(position, true, true).unwrap().unwrap();
440 let content = analysis.db.file_text(position.file_id);
441 let hovered_element = &content[hover.range];
443 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
444 expect.assert_eq(&actual)
447 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
448 let (analysis, position) = fixture::position(ra_fixture);
449 let hover = analysis.hover(position, false, true).unwrap().unwrap();
451 let content = analysis.db.file_text(position.file_id);
452 let hovered_element = &content[hover.range];
454 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
455 expect.assert_eq(&actual)
458 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
459 let (analysis, position) = fixture::position(ra_fixture);
460 let hover = analysis.hover(position, true, false).unwrap().unwrap();
462 let content = analysis.db.file_text(position.file_id);
463 let hovered_element = &content[hover.range];
465 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
466 expect.assert_eq(&actual)
469 fn check_actions(ra_fixture: &str, expect: Expect) {
470 let (analysis, position) = fixture::position(ra_fixture);
471 let hover = analysis.hover(position, true, true).unwrap().unwrap();
472 expect.assert_debug_eq(&hover.info.actions)
476 fn hover_shows_type_of_an_expression() {
479 pub fn foo() -> u32 { 1 }
482 let foo_test = foo()<|>;
495 fn hover_remove_markdown_if_configured() {
496 check_hover_no_markdown(
498 pub fn foo() -> u32 { 1 }
501 let foo_test = foo()<|>;
512 fn hover_shows_long_type_of_an_expression() {
515 struct Scan<A, B, C> { a: A, b: B, c: C }
516 struct Iter<I> { inner: I }
517 enum Option<T> { Some(T), None }
519 struct OtherStruct<T> { i: T }
521 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
522 Iter { inner: Scan { a, b, c } }
527 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
528 Option::Some(*memo + value)
531 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
538 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
545 fn hover_shows_fn_signature() {
546 // Single file with result
549 pub fn foo() -> u32 { 1 }
551 fn main() { let foo_test = fo<|>o(); }
566 // Multiple candidates but results are ambiguous.
570 pub fn foo() -> u32 { 1 }
573 pub fn foo() -> &str { "" }
576 pub fn foo(a: u32, b: u32) {}
583 fn main() { let foo_test = fo<|>o(); }
595 fn hover_shows_fn_signature_with_type_params() {
598 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
600 fn main() { let foo_test = fo<|>o(); }
610 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
617 fn hover_shows_fn_signature_on_fn_name() {
620 pub fn foo<|>(a: u32, b: u32) -> u32 {}
632 pub fn foo(a: u32, b: u32) -> u32
639 fn hover_shows_fn_doc() {
644 /// # use std::path::Path;
646 /// foo(Path::new("hello, world!"))
648 pub fn foo<|>(_: &Path) {}
668 # use std::path::Path;
670 foo(Path::new("hello, world!"))
677 fn hover_shows_fn_doc_attr_raw_string() {
680 #[doc = r#"Raw string doc attr"#]
681 pub fn foo<|>(_: &Path) {}
704 fn hover_shows_struct_field_info() {
705 // Hovering over the field when instantiating
708 struct Foo { field_a: u32 }
711 let foo = Foo { field_a<|>: 0, };
727 // Hovering over the field in the definition
730 struct Foo { field_a<|>: u32 }
733 let foo = Foo { field_a: 0 };
751 fn hover_const_static() {
753 r#"const foo<|>: u32 = 123;"#,
767 r#"static foo<|>: u32 = 456;"#,
783 fn hover_default_generic_types() {
786 struct Test<K, T = u8> { k: K, t: T }
789 let zz<|> = Test { t: 23u8, k: 33 };
805 enum Option<T> { Some(T) }
808 fn main() { So<|>me(12); }
825 enum Option<T> { Some(T) }
828 fn main() { let b<|>ar = Some(12); }
841 fn hover_enum_variant() {
873 let s = Option::Som<|>e(12);
895 fn hover_for_local_variable() {
897 r#"fn func(foo: i32) { fo<|>o; }"#,
909 fn hover_for_local_variable_pat() {
911 r#"fn func(fo<|>o: i32) {}"#,
923 fn hover_local_var_edge() {
925 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
937 fn hover_for_param_edge() {
939 r#"fn func(<|>foo: i32) {}"#,
951 fn hover_for_param_with_multiple_traits() {
959 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
964 impl Deref<Target = u8> + DerefMut<Target = u8>
971 fn test_hover_infer_associated_method_result() {
974 struct Thing { x: u32 }
977 fn new() -> Thing { Thing { x: 0 } }
980 fn main() { let foo_<|>test = Thing::new(); }
993 fn test_hover_infer_associated_method_exact() {
997 struct Thing { x: u32 }
1000 fn new() -> Thing { Thing { x: 0 } }
1004 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1010 test::wrapper::Thing
1021 fn test_hover_infer_associated_const_in_pattern() {
1052 fn test_hover_self() {
1055 struct Thing { x: u32 }
1057 fn new() -> Self { Self<|> { x: 0 } }
1074 struct Thing { x: u32 }
1076 fn new() -> Self<|> { Self { x: 0 } }
1095 pub fn new() -> Self<|> { Thing::A }
1114 pub fn thing(a: Self<|>) {}
1132 fn test_hover_shadowing_pat() {
1153 fn test_hover_macro_invocation() {
1156 macro_rules! foo { () => {} }
1158 fn f() { fo<|>o!(); }
1175 fn test_hover_tuple_field() {
1177 r#"struct TS(String, i32<|>);"#,
1189 fn test_hover_through_macro() {
1192 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1195 fn bar() { fo<|>o(); }
1213 fn test_hover_through_expr_in_macro() {
1216 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1217 fn foo(bar:u32) { let a = id!(ba<|>r); }
1230 fn test_hover_through_expr_in_macro_recursive() {
1233 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1234 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1235 fn foo(bar:u32) { let a = id!(ba<|>r); }
1248 fn test_hover_through_func_in_macro_recursive() {
1251 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1252 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1253 fn bar() -> u32 { 0 }
1254 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1266 fn test_hover_through_literal_string_in_macro() {
1269 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1271 let mastered_for_itunes = "";
1272 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1285 fn test_hover_through_assert_macro() {
1288 #[rustc_builtin_macro]
1289 macro_rules! assert {}
1291 fn bar() -> bool { true }
1311 fn test_hover_through_literal_string_in_builtin_macro() {
1312 check_hover_no_result(
1314 #[rustc_builtin_macro]
1315 macro_rules! format {}
1318 format!("hel<|>lo {}", 0);
1325 fn test_hover_non_ascii_space_doc() {
1328 /// <- `\u{3000}` here
1331 fn bar() { fo<|>o(); }
1352 fn test_hover_function_show_qualifiers() {
1354 r#"async fn foo<|>() {}"#,
1368 r#"pub const unsafe fn foo<|>() {}"#,
1377 pub const unsafe fn foo()
1382 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1391 pub(crate) async unsafe extern "C" fn foo()
1398 fn test_hover_trait_show_qualifiers() {
1400 r"unsafe trait foo<|>() {}",
1417 fn test_hover_extern_crate() {
1420 //- /main.rs crate:main deps:std
1421 extern crate st<|>d;
1422 //- /std/lib.rs crate:std
1423 //! Standard library for this test
1430 Standard library for this test
1438 //- /main.rs crate:main deps:std
1439 extern crate std as ab<|>c;
1440 //- /std/lib.rs crate:std
1441 //! Standard library for this test
1448 Standard library for this test
1457 fn test_hover_mod_with_same_name_as_function() {
1460 use self::m<|>y::Bar;
1461 mod my { pub struct Bar; }
1480 fn test_hover_struct_doc_comment() {
1486 fn foo() { let bar = Ba<|>r; }
1507 fn test_hover_struct_doc_attr() {
1513 fn foo() { let bar = Ba<|>r; }
1534 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1538 #[doc = "bar docs 1"]
1539 #[doc = "bar docs 2"]
1542 fn foo() { let bar = Ba<|>r; }
1565 fn test_hover_path_link() {
1569 /// [Foo](struct.Foo.html)
1585 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1591 fn test_hover_path_link_no_strip() {
1595 /// [struct Foo](struct.Foo.html)
1611 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1616 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1618 fn test_hover_path_link_field() {
1623 /// [Foo](struct.Foo.html)
1640 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1646 fn test_hover_intra_link() {
1668 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1674 fn test_hover_intra_link_html_root_url() {
1677 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1698 [Foo](https://example.com/test/foo/struct.Foo.html)
1704 fn test_hover_intra_link_shortlink() {
1724 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1730 fn test_hover_intra_link_shortlink_code() {
1750 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1756 fn test_hover_intra_link_namespaced() {
1777 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1783 fn test_hover_intra_link_shortlink_namspaced_code() {
1803 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1809 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1829 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1835 fn test_hover_intra_link_reference() {
1857 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1863 fn test_hover_external_url() {
1867 /// [external](https://www.google.com)
1883 [external](https://www.google.com)
1888 // Check that we don't rewrite links which we can't identify
1890 fn test_hover_unknown_target() {
1916 fn test_doc_links_enum_variant() {
1937 [E](https://docs.rs/test/*/test/enum.E.html)
1943 fn test_doc_links_field() {
1964 [`S`](https://docs.rs/test/*/test/struct.S.html)
1970 fn test_hover_no_links() {
1971 check_hover_no_links(
1974 /// case 1. bare URL: https://www.example.com/
1975 /// case 2. inline URL with title: [example](https://www.example.com/)
1976 /// case 3. code refrence: [`Result`]
1977 /// case 4. code refrence but miss footnote: [`String`]
1978 /// case 5. autolink: <http://www.example.com/>
1979 /// case 6. email address: <test@example.com>
1980 /// case 7. refrence: [example][example]
1981 /// case 8. collapsed link: [example][]
1982 /// case 9. shortcut link: [example]
1983 /// case 10. inline without URL: [example]()
1984 /// case 11. refrence: [foo][foo]
1985 /// case 12. refrence: [foo][bar]
1986 /// case 13. collapsed link: [foo][]
1987 /// case 14. shortcut link: [foo]
1988 /// case 15. inline without URL: [foo]()
1989 /// case 16. just escaped text: \[foo]
1990 /// case 17. inline link: [Foo](foo::Foo)
1992 /// [`Result`]: ../../std/result/enum.Result.html
1993 /// [^example]: https://www.example.com/
2010 case 1. bare URL: https://www.example.com/
2011 case 2. inline URL with title: [example](https://www.example.com/)
2012 case 3. code refrence: `Result`
2013 case 4. code refrence but miss footnote: `String`
2014 case 5. autolink: http://www.example.com/
2015 case 6. email address: test@example.com
2016 case 7. refrence: example
2017 case 8. collapsed link: example
2018 case 9. shortcut link: example
2019 case 10. inline without URL: example
2020 case 11. refrence: foo
2021 case 12. refrence: foo
2022 case 13. collapsed link: foo
2023 case 14. shortcut link: foo
2024 case 15. inline without URL: foo
2025 case 16. just escaped text: \[foo]
2026 case 17. inline link: Foo
2028 [^example]: https://www.example.com/
2034 fn test_hover_macro_generated_struct_fn_doc_comment() {
2035 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2051 fn foo() { let bar = Bar; bar.fo<|>o(); }
2072 fn test_hover_macro_generated_struct_fn_doc_attr() {
2073 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2081 #[doc = "Do the foo"]
2089 fn foo() { let bar = Bar; bar.fo<|>o(); }
2110 fn test_hover_trait_has_impl_action() {
2112 r#"trait foo<|>() {}"#,
2129 fn test_hover_struct_has_impl_action() {
2131 r"struct foo<|>() {}",
2148 fn test_hover_union_has_impl_action() {
2150 r#"union foo<|>() {}"#,
2167 fn test_hover_enum_has_impl_action() {
2169 r"enum foo<|>() { A, B }",
2186 fn test_hover_test_has_action() {
2196 nav: NavigationTarget {
2201 focus_range: 11..19,
2222 fn test_hover_test_mod_has_action() {
2234 nav: NavigationTarget {
2255 fn test_hover_struct_has_goto_type_action() {
2260 fn main() { let s<|>t = S{ f1:0 }; }
2267 mod_path: "test::S",
2268 nav: NavigationTarget {
2276 description: "struct S",
2287 fn test_hover_generic_struct_has_goto_type_actions() {
2291 struct S<T>{ f1: T }
2293 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2300 mod_path: "test::S",
2301 nav: NavigationTarget {
2306 focus_range: 24..25,
2309 description: "struct S",
2313 mod_path: "test::Arg",
2314 nav: NavigationTarget {
2322 description: "struct Arg",
2333 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2337 struct S<T>{ f1: T }
2339 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2346 mod_path: "test::S",
2347 nav: NavigationTarget {
2352 focus_range: 24..25,
2355 description: "struct S",
2359 mod_path: "test::Arg",
2360 nav: NavigationTarget {
2368 description: "struct Arg",
2379 fn test_hover_tuple_has_goto_type_actions() {
2388 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2395 mod_path: "test::A",
2396 nav: NavigationTarget {
2404 description: "struct A",
2408 mod_path: "test::B",
2409 nav: NavigationTarget {
2414 focus_range: 22..23,
2417 description: "struct B",
2421 mod_path: "test::M::C",
2422 nav: NavigationTarget {
2427 focus_range: 53..54,
2430 description: "pub struct C",
2441 fn test_hover_return_impl_trait_has_goto_type_action() {
2445 fn foo() -> impl Foo {}
2447 fn main() { let s<|>t = foo(); }
2454 mod_path: "test::Foo",
2455 nav: NavigationTarget {
2463 description: "trait Foo",
2474 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2479 fn foo() -> impl Foo<S> {}
2481 fn main() { let s<|>t = foo(); }
2488 mod_path: "test::Foo",
2489 nav: NavigationTarget {
2497 description: "trait Foo",
2501 mod_path: "test::S",
2502 nav: NavigationTarget {
2507 focus_range: 23..24,
2510 description: "struct S",
2521 fn test_hover_return_impl_traits_has_goto_type_action() {
2526 fn foo() -> impl Foo + Bar {}
2528 fn main() { let s<|>t = foo(); }
2535 mod_path: "test::Foo",
2536 nav: NavigationTarget {
2544 description: "trait Foo",
2548 mod_path: "test::Bar",
2549 nav: NavigationTarget {
2554 focus_range: 19..22,
2557 description: "trait Bar",
2568 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2576 fn foo() -> impl Foo<S1> + Bar<S2> {}
2578 fn main() { let s<|>t = foo(); }
2585 mod_path: "test::Foo",
2586 nav: NavigationTarget {
2594 description: "trait Foo",
2598 mod_path: "test::Bar",
2599 nav: NavigationTarget {
2604 focus_range: 22..25,
2607 description: "trait Bar",
2611 mod_path: "test::S1",
2612 nav: NavigationTarget {
2617 focus_range: 39..41,
2620 description: "struct S1",
2624 mod_path: "test::S2",
2625 nav: NavigationTarget {
2630 focus_range: 52..54,
2633 description: "struct S2",
2644 fn test_hover_arg_impl_trait_has_goto_type_action() {
2648 fn foo(ar<|>g: &impl Foo) {}
2655 mod_path: "test::Foo",
2656 nav: NavigationTarget {
2664 description: "trait Foo",
2675 fn test_hover_arg_impl_traits_has_goto_type_action() {
2682 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2689 mod_path: "test::Foo",
2690 nav: NavigationTarget {
2698 description: "trait Foo",
2702 mod_path: "test::Bar",
2703 nav: NavigationTarget {
2708 focus_range: 19..22,
2711 description: "trait Bar",
2715 mod_path: "test::S",
2716 nav: NavigationTarget {
2721 focus_range: 36..37,
2724 description: "struct S",
2735 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2740 let fo<|>o = async { S };
2743 #[prelude_import] use future::*;
2745 #[lang = "future_trait"]
2746 pub trait Future { type Output; }
2754 mod_path: "test::future::Future",
2755 nav: NavigationTarget {
2759 full_range: 101..163,
2760 focus_range: 140..146,
2763 description: "pub trait Future",
2767 mod_path: "test::S",
2768 nav: NavigationTarget {
2776 description: "struct S",
2787 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2792 fn foo(ar<|>g: &impl Foo<S>) {}
2799 mod_path: "test::Foo",
2800 nav: NavigationTarget {
2808 description: "trait Foo",
2812 mod_path: "test::S",
2813 nav: NavigationTarget {
2818 focus_range: 23..24,
2821 description: "struct S",
2832 fn test_hover_dyn_return_has_goto_type_action() {
2840 fn foo() -> B<dyn Foo> {}
2842 fn main() { let s<|>t = foo(); }
2849 mod_path: "test::B",
2850 nav: NavigationTarget {
2855 focus_range: 49..50,
2858 description: "struct B",
2862 mod_path: "test::Foo",
2863 nav: NavigationTarget {
2871 description: "trait Foo",
2882 fn test_hover_dyn_arg_has_goto_type_action() {
2886 fn foo(ar<|>g: &dyn Foo) {}
2893 mod_path: "test::Foo",
2894 nav: NavigationTarget {
2902 description: "trait Foo",
2913 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2918 fn foo(ar<|>g: &dyn Foo<S>) {}
2925 mod_path: "test::Foo",
2926 nav: NavigationTarget {
2934 description: "trait Foo",
2938 mod_path: "test::S",
2939 nav: NavigationTarget {
2944 focus_range: 23..24,
2947 description: "struct S",
2958 fn test_hover_goto_type_action_links_order() {
2961 trait ImplTrait<T> {}
2962 trait DynTrait<T> {}
2966 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2973 mod_path: "test::ImplTrait",
2974 nav: NavigationTarget {
2982 description: "trait ImplTrait",
2986 mod_path: "test::B",
2987 nav: NavigationTarget {
2992 focus_range: 50..51,
2995 description: "struct B",
2999 mod_path: "test::DynTrait",
3000 nav: NavigationTarget {
3005 focus_range: 28..36,
3008 description: "trait DynTrait",
3012 mod_path: "test::S",
3013 nav: NavigationTarget {
3018 focus_range: 65..66,
3021 description: "struct S",
3032 fn test_hover_associated_type_has_goto_type_action() {
3037 fn get(self) -> Self::Item {}
3043 impl Foo for S { type Item = Bar; }
3045 fn test() -> impl Foo { S {} }
3047 fn main() { let s<|>t = test().get(); }
3054 mod_path: "test::Foo",
3055 nav: NavigationTarget {
3063 description: "trait Foo",
3074 fn hover_displays_normalized_crate_names() {
3077 //- /lib.rs crate:name-with-dashes
3079 pub struct Thing { x: u32 }
3082 pub fn new() -> Thing { Thing { x: 0 } }
3086 //- /main.rs crate:main deps:name-with-dashes
3087 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3093 name_with_dashes::wrapper::Thing
3097 pub fn new() -> Thing
3104 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3113 let S { f<|> } = &s;
3127 fn hover_self_param_shows_type() {
3145 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3151 fn bar(sel<|>f: Arc<Foo>) {}
3164 fn hover_doc_outer_inner() {
3171 /// This comment belongs to the function
3195 fn hover_doc_outer_inner_attribue() {
3198 #[doc = "Be quick;"]
3200 #![doc = "time is mana"]
3202 #[doc = "This comment belongs to the function"]
3226 fn hover_comments_dont_highlight_parent() {
3227 check_hover_no_result(
3255 fn hover_lifetime() {
3257 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,