1 use base_db::SourceDatabase;
3 Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay,
4 Module, ModuleDef, ModuleSource, Semantics,
7 defs::{classify_name, classify_name_ref, Definition},
10 use itertools::Itertools;
12 use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
16 display::{macro_label, ShortLabel, ToNav, TryToNav},
17 link_rewrite::{remove_links, rewrite_links},
20 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
23 #[derive(Clone, Debug, PartialEq, Eq)]
24 pub struct HoverConfig {
25 pub implementations: bool,
28 pub goto_type_def: bool,
29 pub links_in_hover: bool,
32 impl Default for HoverConfig {
33 fn default() -> Self {
35 implementations: true,
45 pub const NO_ACTIONS: Self = Self {
46 implementations: false,
53 pub fn any(&self) -> bool {
54 self.implementations || self.runnable() || self.goto_type_def
57 pub fn none(&self) -> bool {
61 pub fn runnable(&self) -> bool {
62 self.run || self.debug
66 #[derive(Debug, Clone)]
67 pub enum HoverAction {
69 Implementaion(FilePosition),
70 GoToType(Vec<HoverGotoTypeData>),
73 #[derive(Debug, Clone, Eq, PartialEq)]
74 pub struct HoverGotoTypeData {
76 pub nav: NavigationTarget,
79 /// Contains the results when hovering over an item
80 #[derive(Debug, Default)]
81 pub struct HoverResult {
83 pub actions: Vec<HoverAction>,
88 // Shows additional information, like type of an expression or documentation for definition when "focusing" code.
89 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
92 position: FilePosition,
94 ) -> Option<RangeInfo<HoverResult>> {
95 let sema = Semantics::new(db);
96 let file = sema.parse(position.file_id).syntax().clone();
97 let token = pick_best(file.token_at_offset(position.offset))?;
98 let token = sema.descend_into_macros(token);
100 let mut res = HoverResult::default();
102 let node = token.parent();
103 let definition = match_ast! {
105 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)),
106 ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)),
110 if let Some(definition) = definition {
111 if let Some(markup) = hover_for_definition(db, definition) {
112 let markup = if links_in_hover {
113 rewrite_links(db, &markup.as_str(), &definition)
115 remove_links(&markup.as_str())
117 res.markup = Markup::from(markup);
118 if let Some(action) = show_implementations_action(db, definition) {
119 res.actions.push(action);
122 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
123 res.actions.push(action);
126 if let Some(action) = goto_type_action(db, definition) {
127 res.actions.push(action);
130 let range = sema.original_range(&node).range;
131 return Some(RangeInfo::new(range, res));
137 .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?;
139 let ty = match_ast! {
141 ast::Expr(it) => sema.type_of_expr(&it)?,
142 ast::Pat(it) => sema.type_of_pat(&it)?,
143 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
144 // (e.g expanding a builtin macro). So we give up here.
145 ast::MacroCall(_it) => return None,
150 res.markup = Markup::fenced_block(&ty.display(db));
151 let range = sema.original_range(&node).range;
152 Some(RangeInfo::new(range, res))
155 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
156 fn to_action(nav_target: NavigationTarget) -> HoverAction {
157 HoverAction::Implementaion(FilePosition {
158 file_id: nav_target.file_id,
159 offset: nav_target.focus_or_full_range().start(),
164 Definition::ModuleDef(it) => match it {
165 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.to_nav(db))),
166 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.to_nav(db))),
167 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.to_nav(db))),
168 ModuleDef::Trait(it) => Some(to_action(it.to_nav(db))),
176 sema: &Semantics<RootDatabase>,
179 ) -> Option<HoverAction> {
181 Definition::ModuleDef(it) => match it {
182 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
183 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
184 .map(|it| HoverAction::Runnable(it)),
187 ModuleDef::Function(it) => {
188 let src = it.source(sema.db);
189 if src.file_id != file_id.into() {
190 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
191 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
196 runnable(&sema, src.value.syntax().clone(), file_id)
197 .map(|it| HoverAction::Runnable(it))
205 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
207 Definition::Local(it) => {
208 let mut targets: Vec<ModuleDef> = Vec::new();
209 let mut push_new_def = |item: ModuleDef| {
210 if !targets.contains(&item) {
215 it.ty(db).walk(db, |t| {
216 if let Some(adt) = t.as_adt() {
217 push_new_def(adt.into());
218 } else if let Some(trait_) = t.as_dyn_trait() {
219 push_new_def(trait_.into());
220 } else if let Some(traits) = t.as_impl_traits(db) {
221 traits.into_iter().for_each(|it| push_new_def(it.into()));
222 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
223 push_new_def(trait_.into());
227 let targets = targets
230 Some(HoverGotoTypeData {
231 mod_path: render_path(
234 it.name(db).map(|name| name.to_string()),
236 nav: it.try_to_nav(db)?,
241 Some(HoverAction::GoToType(targets))
248 docs: Option<String>,
249 desc: Option<String>,
250 mod_path: Option<String>,
251 ) -> Option<Markup> {
254 let mut buf = String::new();
256 if let Some(mod_path) = mod_path {
257 if !mod_path.is_empty() {
258 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
261 format_to!(buf, "```rust\n{}\n```", desc);
263 if let Some(doc) = docs {
264 format_to!(buf, "\n___\n\n{}", doc);
268 None => docs.map(Markup::from),
272 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
274 Definition::Field(f) => Some(f.parent_def(db).name(db)),
275 Definition::Local(l) => l.parent(db).name(db),
276 Definition::ModuleDef(md) => match md {
277 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
278 AssocItemContainer::Trait(t) => Some(t.name(db)),
279 AssocItemContainer::ImplDef(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
281 ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
284 Definition::SelfType(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
287 .map(|name| name.to_string())
290 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
292 db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string);
293 let module_path = module
297 .flat_map(|it| it.name(db).map(|name| name.to_string()));
298 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
301 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
302 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
305 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
306 let mod_path = definition_mod_path(db, &def);
308 Definition::Macro(it) => {
309 let src = it.source(db);
310 let docs = Documentation::from_ast(&src.value).map(Into::into);
311 hover_markup(docs, Some(macro_label(&src.value)), mod_path)
313 Definition::Field(it) => {
314 let src = it.source(db);
316 FieldSource::Named(it) => {
317 let docs = Documentation::from_ast(&it).map(Into::into);
318 hover_markup(docs, it.short_label(), mod_path)
323 Definition::ModuleDef(it) => match it {
324 ModuleDef::Module(it) => match it.definition_source(db).value {
325 ModuleSource::Module(it) => {
326 let docs = Documentation::from_ast(&it).map(Into::into);
327 hover_markup(docs, it.short_label(), mod_path)
329 ModuleSource::SourceFile(it) => {
330 let docs = Documentation::from_ast(&it).map(Into::into);
331 hover_markup(docs, it.short_label(), mod_path)
334 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
335 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
336 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
337 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
338 ModuleDef::EnumVariant(it) => from_def_source(db, it, mod_path),
339 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
340 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
341 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
342 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
343 ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
345 Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
346 Definition::TypeParam(_) | Definition::SelfType(_) => {
347 // FIXME: Hover for generic param
352 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
354 D: HasSource<Ast = A>,
355 A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel + ast::AttrsOwner,
357 let src = def.source(db);
358 let docs = Documentation::from_ast(&src.value).map(Into::into);
359 hover_markup(docs, src.value.short_label(), mod_path)
363 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
364 return tokens.max_by_key(priority);
365 fn priority(n: &SyntaxToken) -> usize {
367 IDENT | INT_NUMBER => 3,
368 T!['('] | T![')'] => 2,
369 kind if kind.is_trivia() => 0,
377 use base_db::FileLoader;
378 use expect_test::{expect, Expect};
384 fn check_hover_no_result(ra_fixture: &str) {
385 let (analysis, position) = fixture::position(ra_fixture);
386 assert!(analysis.hover(position, true).unwrap().is_none());
389 fn check(ra_fixture: &str, expect: Expect) {
390 let (analysis, position) = fixture::position(ra_fixture);
391 let hover = analysis.hover(position, true).unwrap().unwrap();
393 let content = analysis.db.file_text(position.file_id);
394 let hovered_element = &content[hover.range];
396 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
397 expect.assert_eq(&actual)
400 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
401 let (analysis, position) = fixture::position(ra_fixture);
402 let hover = analysis.hover(position, false).unwrap().unwrap();
404 let content = analysis.db.file_text(position.file_id);
405 let hovered_element = &content[hover.range];
407 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
408 expect.assert_eq(&actual)
411 fn check_actions(ra_fixture: &str, expect: Expect) {
412 let (analysis, position) = fixture::position(ra_fixture);
413 let hover = analysis.hover(position, true).unwrap().unwrap();
414 expect.assert_debug_eq(&hover.info.actions)
418 fn hover_shows_type_of_an_expression() {
421 pub fn foo() -> u32 { 1 }
424 let foo_test = foo()<|>;
437 fn hover_shows_long_type_of_an_expression() {
440 struct Scan<A, B, C> { a: A, b: B, c: C }
441 struct Iter<I> { inner: I }
442 enum Option<T> { Some(T), None }
444 struct OtherStruct<T> { i: T }
446 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
447 Iter { inner: Scan { a, b, c } }
452 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
453 Option::Some(*memo + value)
456 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
463 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
470 fn hover_shows_fn_signature() {
471 // Single file with result
474 pub fn foo() -> u32 { 1 }
476 fn main() { let foo_test = fo<|>o(); }
491 // Multiple candidates but results are ambiguous.
495 pub fn foo() -> u32 { 1 }
498 pub fn foo() -> &str { "" }
501 pub fn foo(a: u32, b: u32) {}
508 fn main() { let foo_test = fo<|>o(); }
520 fn hover_shows_fn_signature_with_type_params() {
523 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
525 fn main() { let foo_test = fo<|>o(); }
535 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
542 fn hover_shows_fn_signature_on_fn_name() {
545 pub fn foo<|>(a: u32, b: u32) -> u32 {}
557 pub fn foo(a: u32, b: u32) -> u32
564 fn hover_shows_fn_doc() {
569 /// # use std::path::Path;
571 /// foo(Path::new("hello, world!"))
573 pub fn foo<|>(_: &Path) {}
593 # use std::path::Path;
595 foo(Path::new("hello, world!"))
602 fn hover_shows_struct_field_info() {
603 // Hovering over the field when instantiating
606 struct Foo { field_a: u32 }
609 let foo = Foo { field_a<|>: 0, };
625 // Hovering over the field in the definition
628 struct Foo { field_a<|>: u32 }
631 let foo = Foo { field_a: 0 };
649 fn hover_const_static() {
651 r#"const foo<|>: u32 = 123;"#,
665 r#"static foo<|>: u32 = 456;"#,
681 fn hover_default_generic_types() {
684 struct Test<K, T = u8> { k: K, t: T }
687 let zz<|> = Test { t: 23u8, k: 33 };
703 enum Option<T> { Some(T) }
706 fn main() { So<|>me(12); }
723 enum Option<T> { Some(T) }
726 fn main() { let b<|>ar = Some(12); }
739 fn hover_enum_variant() {
771 let s = Option::Som<|>e(12);
793 fn hover_for_local_variable() {
795 r#"fn func(foo: i32) { fo<|>o; }"#,
807 fn hover_for_local_variable_pat() {
809 r#"fn func(fo<|>o: i32) {}"#,
821 fn hover_local_var_edge() {
823 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
835 fn hover_for_param_edge() {
837 r#"fn func(<|>foo: i32) {}"#,
849 fn hover_for_param_with_multiple_traits() {
857 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
862 impl Deref<Target = u8> + DerefMut<Target = u8>
869 fn test_hover_infer_associated_method_result() {
872 struct Thing { x: u32 }
875 fn new() -> Thing { Thing { x: 0 } }
878 fn main() { let foo_<|>test = Thing::new(); }
891 fn test_hover_infer_associated_method_exact() {
895 struct Thing { x: u32 }
898 fn new() -> Thing { Thing { x: 0 } }
902 fn main() { let foo_test = wrapper::Thing::new<|>(); }
919 fn test_hover_infer_associated_const_in_pattern() {
950 fn test_hover_self() {
953 struct Thing { x: u32 }
955 fn new() -> Self { Self<|> { x: 0 } }
965 } /* FIXME: revive these tests
966 let (analysis, position) = fixture::position(
968 struct Thing { x: u32 }
970 fn new() -> Self<|> {
977 let hover = analysis.hover(position).unwrap().unwrap();
978 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("Thing"));
980 let (analysis, position) = fixture::position(
984 pub fn new() -> Self<|> {
990 let hover = analysis.hover(position).unwrap().unwrap();
991 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing"));
993 let (analysis, position) = fixture::position(
997 pub fn thing(a: Self<|>) {
1002 let hover = analysis.hover(position).unwrap().unwrap();
1003 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing"));
1007 fn test_hover_shadowing_pat() {
1028 fn test_hover_macro_invocation() {
1031 macro_rules! foo { () => {} }
1033 fn f() { fo<|>o!(); }
1050 fn test_hover_tuple_field() {
1052 r#"struct TS(String, i32<|>);"#,
1061 fn test_hover_through_macro() {
1064 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1067 fn bar() { fo<|>o(); }
1085 fn test_hover_through_expr_in_macro() {
1088 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1089 fn foo(bar:u32) { let a = id!(ba<|>r); }
1102 fn test_hover_through_expr_in_macro_recursive() {
1105 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1106 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1107 fn foo(bar:u32) { let a = id!(ba<|>r); }
1120 fn test_hover_through_func_in_macro_recursive() {
1123 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1124 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1125 fn bar() -> u32 { 0 }
1126 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1138 fn test_hover_through_literal_string_in_macro() {
1141 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1143 let mastered_for_itunes = "";
1144 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1157 fn test_hover_through_assert_macro() {
1160 #[rustc_builtin_macro]
1161 macro_rules! assert {}
1163 fn bar() -> bool { true }
1183 fn test_hover_through_literal_string_in_builtin_macro() {
1184 check_hover_no_result(
1186 #[rustc_builtin_macro]
1187 macro_rules! format {}
1190 format!("hel<|>lo {}", 0);
1197 fn test_hover_non_ascii_space_doc() {
1200 /// <- `\u{3000}` here
1203 fn bar() { fo<|>o(); }
1224 fn test_hover_function_show_qualifiers() {
1226 r#"async fn foo<|>() {}"#,
1240 r#"pub const unsafe fn foo<|>() {}"#,
1249 pub const unsafe fn foo()
1254 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1263 pub(crate) async unsafe extern "C" fn foo()
1270 fn test_hover_trait_show_qualifiers() {
1272 r"unsafe trait foo<|>() {}",
1289 fn test_hover_extern_crate() {
1292 //- /main.rs crate:main deps:std
1293 extern crate st<|>d;
1294 //- /std/lib.rs crate:std
1295 //! Standard library for this test
1302 Standard library for this test
1310 //- /main.rs crate:main deps:std
1311 extern crate std as ab<|>c;
1312 //- /std/lib.rs crate:std
1313 //! Standard library for this test
1320 Standard library for this test
1329 fn test_hover_mod_with_same_name_as_function() {
1332 use self::m<|>y::Bar;
1333 mod my { pub struct Bar; }
1352 fn test_hover_struct_doc_comment() {
1358 fn foo() { let bar = Ba<|>r; }
1379 fn test_hover_struct_doc_attr() {
1385 fn foo() { let bar = Ba<|>r; }
1406 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1410 #[doc = "bar docs 1"]
1411 #[doc = "bar docs 2"]
1414 fn foo() { let bar = Ba<|>r; }
1439 fn test_hover_path_link() {
1443 /// [Foo](struct.Foo.html)
1459 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1465 fn test_hover_path_link_no_strip() {
1469 /// [struct Foo](struct.Foo.html)
1485 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1490 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1492 fn test_hover_path_link_field() {
1497 /// [Foo](struct.Foo.html)
1514 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1520 fn test_hover_intra_link() {
1542 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1548 fn test_hover_intra_link_html_root_url() {
1551 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1572 [Foo](https://example.com/test/foo/struct.Foo.html)
1578 fn test_hover_intra_link_shortlink() {
1598 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1604 fn test_hover_intra_link_shortlink_code() {
1624 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1630 fn test_hover_intra_link_namespaced() {
1651 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1657 fn test_hover_intra_link_shortlink_namspaced_code() {
1677 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1683 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1703 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1709 fn test_hover_intra_link_reference() {
1731 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1737 fn test_hover_external_url() {
1741 /// [external](https://www.google.com)
1757 [external](https://www.google.com)
1762 // Check that we don't rewrite links which we can't identify
1764 fn test_hover_unknown_target() {
1790 fn test_doc_links_enum_variant() {
1811 [E](https://docs.rs/test/*/test/enum.E.html)
1817 fn test_doc_links_field() {
1838 [`S`](https://docs.rs/test/*/test/struct.S.html)
1844 fn test_hover_no_links() {
1845 check_hover_no_links(
1848 /// case 1. bare URL: https://www.example.com/
1849 /// case 2. inline URL with title: [example](https://www.example.com/)
1850 /// case 3. code refrence: [`Result`]
1851 /// case 4. code refrence but miss footnote: [`String`]
1852 /// case 5. autolink: <http://www.example.com/>
1853 /// case 6. email address: <test@example.com>
1854 /// case 7. refrence: [example][example]
1855 /// case 8. collapsed link: [example][]
1856 /// case 9. shortcut link: [example]
1857 /// case 10. inline without URL: [example]()
1858 /// case 11. refrence: [foo][foo]
1859 /// case 12. refrence: [foo][bar]
1860 /// case 13. collapsed link: [foo][]
1861 /// case 14. shortcut link: [foo]
1862 /// case 15. inline without URL: [foo]()
1863 /// case 16. just escaped text: \[foo]
1864 /// case 17. inline link: [Foo](foo::Foo)
1866 /// [`Result`]: ../../std/result/enum.Result.html
1867 /// [^example]: https://www.example.com/
1884 case 1. bare URL: https://www.example.com/
1885 case 2. inline URL with title: [example](https://www.example.com/)
1886 case 3. code refrence: `Result`
1887 case 4. code refrence but miss footnote: `String`
1888 case 5. autolink: http://www.example.com/
1889 case 6. email address: test@example.com
1890 case 7. refrence: example
1891 case 8. collapsed link: example
1892 case 9. shortcut link: example
1893 case 10. inline without URL: example
1894 case 11. refrence: foo
1895 case 12. refrence: foo
1896 case 13. collapsed link: foo
1897 case 14. shortcut link: foo
1898 case 15. inline without URL: foo
1899 case 16. just escaped text: \[foo]
1900 case 17. inline link: Foo
1902 [^example]: https://www.example.com/
1908 fn test_hover_macro_generated_struct_fn_doc_comment() {
1909 mark::check!(hover_macro_generated_struct_fn_doc_comment);
1925 fn foo() { let bar = Bar; bar.fo<|>o(); }
1946 fn test_hover_macro_generated_struct_fn_doc_attr() {
1947 mark::check!(hover_macro_generated_struct_fn_doc_attr);
1955 #[doc = "Do the foo"]
1963 fn foo() { let bar = Bar; bar.fo<|>o(); }
1984 fn test_hover_trait_has_impl_action() {
1986 r#"trait foo<|>() {}"#,
2003 fn test_hover_struct_has_impl_action() {
2005 r"struct foo<|>() {}",
2022 fn test_hover_union_has_impl_action() {
2024 r#"union foo<|>() {}"#,
2041 fn test_hover_enum_has_impl_action() {
2043 r"enum foo<|>() { A, B }",
2060 fn test_hover_test_has_action() {
2070 nav: NavigationTarget {
2080 container_name: None,
2101 fn test_hover_test_mod_has_action() {
2113 nav: NavigationTarget {
2123 container_name: None,
2139 fn test_hover_struct_has_goto_type_action() {
2144 fn main() { let s<|>t = S{ f1:0 }; }
2151 mod_path: "test::S",
2152 nav: NavigationTarget {
2162 container_name: None,
2177 fn test_hover_generic_struct_has_goto_type_actions() {
2181 struct S<T>{ f1: T }
2183 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2190 mod_path: "test::S",
2191 nav: NavigationTarget {
2201 container_name: None,
2209 mod_path: "test::Arg",
2210 nav: NavigationTarget {
2220 container_name: None,
2235 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2239 struct S<T>{ f1: T }
2241 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2248 mod_path: "test::S",
2249 nav: NavigationTarget {
2259 container_name: None,
2267 mod_path: "test::Arg",
2268 nav: NavigationTarget {
2278 container_name: None,
2293 fn test_hover_tuple_has_goto_type_actions() {
2302 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2309 mod_path: "test::A",
2310 nav: NavigationTarget {
2320 container_name: None,
2328 mod_path: "test::B",
2329 nav: NavigationTarget {
2339 container_name: None,
2347 mod_path: "test::M::C",
2348 nav: NavigationTarget {
2358 container_name: None,
2373 fn test_hover_return_impl_trait_has_goto_type_action() {
2377 fn foo() -> impl Foo {}
2379 fn main() { let s<|>t = foo(); }
2386 mod_path: "test::Foo",
2387 nav: NavigationTarget {
2397 container_name: None,
2412 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2417 fn foo() -> impl Foo<S> {}
2419 fn main() { let s<|>t = foo(); }
2426 mod_path: "test::Foo",
2427 nav: NavigationTarget {
2437 container_name: None,
2445 mod_path: "test::S",
2446 nav: NavigationTarget {
2456 container_name: None,
2471 fn test_hover_return_impl_traits_has_goto_type_action() {
2476 fn foo() -> impl Foo + Bar {}
2478 fn main() { let s<|>t = foo(); }
2485 mod_path: "test::Foo",
2486 nav: NavigationTarget {
2496 container_name: None,
2504 mod_path: "test::Bar",
2505 nav: NavigationTarget {
2515 container_name: None,
2530 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2538 fn foo() -> impl Foo<S1> + Bar<S2> {}
2540 fn main() { let s<|>t = foo(); }
2547 mod_path: "test::Foo",
2548 nav: NavigationTarget {
2558 container_name: None,
2566 mod_path: "test::Bar",
2567 nav: NavigationTarget {
2577 container_name: None,
2585 mod_path: "test::S1",
2586 nav: NavigationTarget {
2596 container_name: None,
2604 mod_path: "test::S2",
2605 nav: NavigationTarget {
2615 container_name: None,
2630 fn test_hover_arg_impl_trait_has_goto_type_action() {
2634 fn foo(ar<|>g: &impl Foo) {}
2641 mod_path: "test::Foo",
2642 nav: NavigationTarget {
2652 container_name: None,
2667 fn test_hover_arg_impl_traits_has_goto_type_action() {
2674 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2681 mod_path: "test::Foo",
2682 nav: NavigationTarget {
2692 container_name: None,
2700 mod_path: "test::Bar",
2701 nav: NavigationTarget {
2711 container_name: None,
2719 mod_path: "test::S",
2720 nav: NavigationTarget {
2730 container_name: None,
2745 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2750 let fo<|>o = async { S };
2753 #[prelude_import] use future::*;
2755 #[lang = "future_trait"]
2756 pub trait Future { type Output; }
2764 mod_path: "test::future::Future",
2765 nav: NavigationTarget {
2769 full_range: 101..163,
2775 container_name: None,
2783 mod_path: "test::S",
2784 nav: NavigationTarget {
2794 container_name: None,
2809 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2814 fn foo(ar<|>g: &impl Foo<S>) {}
2821 mod_path: "test::Foo",
2822 nav: NavigationTarget {
2832 container_name: None,
2840 mod_path: "test::S",
2841 nav: NavigationTarget {
2851 container_name: None,
2866 fn test_hover_dyn_return_has_goto_type_action() {
2874 fn foo() -> B<dyn Foo> {}
2876 fn main() { let s<|>t = foo(); }
2883 mod_path: "test::B",
2884 nav: NavigationTarget {
2894 container_name: None,
2902 mod_path: "test::Foo",
2903 nav: NavigationTarget {
2913 container_name: None,
2928 fn test_hover_dyn_arg_has_goto_type_action() {
2932 fn foo(ar<|>g: &dyn Foo) {}
2939 mod_path: "test::Foo",
2940 nav: NavigationTarget {
2950 container_name: None,
2965 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2970 fn foo(ar<|>g: &dyn Foo<S>) {}
2977 mod_path: "test::Foo",
2978 nav: NavigationTarget {
2988 container_name: None,
2996 mod_path: "test::S",
2997 nav: NavigationTarget {
3007 container_name: None,
3022 fn test_hover_goto_type_action_links_order() {
3025 trait ImplTrait<T> {}
3026 trait DynTrait<T> {}
3030 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3037 mod_path: "test::ImplTrait",
3038 nav: NavigationTarget {
3048 container_name: None,
3056 mod_path: "test::B",
3057 nav: NavigationTarget {
3067 container_name: None,
3075 mod_path: "test::DynTrait",
3076 nav: NavigationTarget {
3086 container_name: None,
3094 mod_path: "test::S",
3095 nav: NavigationTarget {
3105 container_name: None,
3120 fn test_hover_associated_type_has_goto_type_action() {
3125 fn get(self) -> Self::Item {}
3131 impl Foo for S { type Item = Bar; }
3133 fn test() -> impl Foo { S {} }
3135 fn main() { let s<|>t = test().get(); }
3142 mod_path: "test::Foo",
3143 nav: NavigationTarget {
3153 container_name: None,