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)),
115 if let Some(definition) = definition {
116 if let Some(markup) = hover_for_definition(db, definition) {
117 let markup = if !markdown {
118 remove_markdown(&markup.as_str())
119 } else if links_in_hover {
120 rewrite_links(db, &markup.as_str(), &definition)
122 remove_links(&markup.as_str())
124 res.markup = Markup::from(markup);
125 if let Some(action) = show_implementations_action(db, definition) {
126 res.actions.push(action);
129 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
130 res.actions.push(action);
133 if let Some(action) = goto_type_action(db, definition) {
134 res.actions.push(action);
137 let range = sema.original_range(&node).range;
138 return Some(RangeInfo::new(range, res));
142 let node = token.ancestors().find(|n| {
143 ast::Expr::can_cast(n.kind())
144 || ast::Pat::can_cast(n.kind())
145 || ast::SelfParam::can_cast(n.kind())
148 let ty = match_ast! {
150 ast::Expr(it) => sema.type_of_expr(&it)?,
151 ast::Pat(it) => sema.type_of_pat(&it)?,
152 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
153 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
154 // (e.g expanding a builtin macro). So we give up here.
155 ast::MacroCall(_it) => return None,
160 res.markup = if markdown {
161 Markup::fenced_block(&ty.display(db))
163 ty.display(db).to_string().into()
165 let range = sema.original_range(&node).range;
166 Some(RangeInfo::new(range, res))
169 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
170 fn to_action(nav_target: NavigationTarget) -> HoverAction {
171 HoverAction::Implementaion(FilePosition {
172 file_id: nav_target.file_id,
173 offset: nav_target.focus_or_full_range().start(),
178 Definition::ModuleDef(it) => match it {
179 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.to_nav(db))),
180 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.to_nav(db))),
181 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.to_nav(db))),
182 ModuleDef::Trait(it) => Some(to_action(it.to_nav(db))),
190 sema: &Semantics<RootDatabase>,
193 ) -> Option<HoverAction> {
195 Definition::ModuleDef(it) => match it {
196 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
197 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
198 .map(|it| HoverAction::Runnable(it)),
201 ModuleDef::Function(it) => {
202 let src = it.source(sema.db);
203 if src.file_id != file_id.into() {
204 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
205 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
210 runnable(&sema, src.value.syntax().clone(), file_id)
211 .map(|it| HoverAction::Runnable(it))
219 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
221 Definition::Local(it) => {
222 let mut targets: Vec<ModuleDef> = Vec::new();
223 let mut push_new_def = |item: ModuleDef| {
224 if !targets.contains(&item) {
229 it.ty(db).walk(db, |t| {
230 if let Some(adt) = t.as_adt() {
231 push_new_def(adt.into());
232 } else if let Some(trait_) = t.as_dyn_trait() {
233 push_new_def(trait_.into());
234 } else if let Some(traits) = t.as_impl_traits(db) {
235 traits.into_iter().for_each(|it| push_new_def(it.into()));
236 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
237 push_new_def(trait_.into());
241 let targets = targets
244 Some(HoverGotoTypeData {
245 mod_path: render_path(
248 it.name(db).map(|name| name.to_string()),
250 nav: it.try_to_nav(db)?,
255 Some(HoverAction::GoToType(targets))
262 docs: Option<String>,
263 desc: Option<String>,
264 mod_path: Option<String>,
265 ) -> Option<Markup> {
268 let mut buf = String::new();
270 if let Some(mod_path) = mod_path {
271 if !mod_path.is_empty() {
272 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
275 format_to!(buf, "```rust\n{}\n```", desc);
277 if let Some(doc) = docs {
278 format_to!(buf, "\n___\n\n{}", doc);
282 None => docs.map(Markup::from),
286 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
288 Definition::Field(f) => Some(f.parent_def(db).name(db)),
289 Definition::Local(l) => l.parent(db).name(db),
290 Definition::ModuleDef(md) => match md {
291 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
292 AssocItemContainer::Trait(t) => Some(t.name(db)),
293 AssocItemContainer::ImplDef(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
295 ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
300 .map(|name| name.to_string())
303 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
305 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
306 let module_path = module
310 .flat_map(|it| it.name(db).map(|name| name.to_string()));
311 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
314 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
315 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
318 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
319 let mod_path = definition_mod_path(db, &def);
321 Definition::Macro(it) => {
322 let label = macro_label(&it.source(db).value);
323 from_def_source_labeled(db, it, Some(label), mod_path)
325 Definition::Field(def) => {
326 let src = def.source(db).value;
327 if let FieldSource::Named(it) = src {
328 from_def_source_labeled(db, def, it.short_label(), mod_path)
333 Definition::ModuleDef(it) => match it {
334 ModuleDef::Module(it) => from_def_source_labeled(
337 match it.definition_source(db).value {
338 ModuleSource::Module(it) => it.short_label(),
339 ModuleSource::SourceFile(it) => it.short_label(),
343 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
344 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
345 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
346 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
347 ModuleDef::EnumVariant(it) => from_def_source(db, it, mod_path),
348 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
349 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
350 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
351 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
352 ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
354 Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
355 Definition::SelfType(impl_def) => {
356 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
357 Adt::Struct(it) => from_def_source(db, it, mod_path),
358 Adt::Union(it) => from_def_source(db, it, mod_path),
359 Adt::Enum(it) => from_def_source(db, it, mod_path),
362 Definition::TypeParam(_) => {
363 // FIXME: Hover for generic param
368 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
370 D: HasSource<Ast = A> + HasAttrs + Copy,
373 let short_label = def.source(db).value.short_label();
374 from_def_source_labeled(db, def, short_label, mod_path)
377 fn from_def_source_labeled<D>(
380 short_label: Option<String>,
381 mod_path: Option<String>,
386 let docs = def.attrs(db).docs().map(Into::into);
387 hover_markup(docs, short_label, mod_path)
391 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
392 return tokens.max_by_key(priority);
393 fn priority(n: &SyntaxToken) -> usize {
395 IDENT | INT_NUMBER => 3,
396 T!['('] | T![')'] => 2,
397 kind if kind.is_trivia() => 0,
405 use expect_test::{expect, Expect};
406 use ide_db::base_db::FileLoader;
412 fn check_hover_no_result(ra_fixture: &str) {
413 let (analysis, position) = fixture::position(ra_fixture);
414 assert!(analysis.hover(position, true, true).unwrap().is_none());
417 fn check(ra_fixture: &str, expect: Expect) {
418 let (analysis, position) = fixture::position(ra_fixture);
419 let hover = analysis.hover(position, true, true).unwrap().unwrap();
421 let content = analysis.db.file_text(position.file_id);
422 let hovered_element = &content[hover.range];
424 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
425 expect.assert_eq(&actual)
428 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
429 let (analysis, position) = fixture::position(ra_fixture);
430 let hover = analysis.hover(position, false, true).unwrap().unwrap();
432 let content = analysis.db.file_text(position.file_id);
433 let hovered_element = &content[hover.range];
435 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
436 expect.assert_eq(&actual)
439 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
440 let (analysis, position) = fixture::position(ra_fixture);
441 let hover = analysis.hover(position, true, false).unwrap().unwrap();
443 let content = analysis.db.file_text(position.file_id);
444 let hovered_element = &content[hover.range];
446 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
447 expect.assert_eq(&actual)
450 fn check_actions(ra_fixture: &str, expect: Expect) {
451 let (analysis, position) = fixture::position(ra_fixture);
452 let hover = analysis.hover(position, true, true).unwrap().unwrap();
453 expect.assert_debug_eq(&hover.info.actions)
457 fn hover_shows_type_of_an_expression() {
460 pub fn foo() -> u32 { 1 }
463 let foo_test = foo()<|>;
476 fn hover_remove_markdown_if_configured() {
477 check_hover_no_markdown(
479 pub fn foo() -> u32 { 1 }
482 let foo_test = foo()<|>;
493 fn hover_shows_long_type_of_an_expression() {
496 struct Scan<A, B, C> { a: A, b: B, c: C }
497 struct Iter<I> { inner: I }
498 enum Option<T> { Some(T), None }
500 struct OtherStruct<T> { i: T }
502 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
503 Iter { inner: Scan { a, b, c } }
508 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
509 Option::Some(*memo + value)
512 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
519 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
526 fn hover_shows_fn_signature() {
527 // Single file with result
530 pub fn foo() -> u32 { 1 }
532 fn main() { let foo_test = fo<|>o(); }
547 // Multiple candidates but results are ambiguous.
551 pub fn foo() -> u32 { 1 }
554 pub fn foo() -> &str { "" }
557 pub fn foo(a: u32, b: u32) {}
564 fn main() { let foo_test = fo<|>o(); }
576 fn hover_shows_fn_signature_with_type_params() {
579 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
581 fn main() { let foo_test = fo<|>o(); }
591 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
598 fn hover_shows_fn_signature_on_fn_name() {
601 pub fn foo<|>(a: u32, b: u32) -> u32 {}
613 pub fn foo(a: u32, b: u32) -> u32
620 fn hover_shows_fn_doc() {
625 /// # use std::path::Path;
627 /// foo(Path::new("hello, world!"))
629 pub fn foo<|>(_: &Path) {}
649 # use std::path::Path;
651 foo(Path::new("hello, world!"))
658 fn hover_shows_fn_doc_attr_raw_string() {
661 #[doc = r#"Raw string doc attr"#]
662 pub fn foo<|>(_: &Path) {}
685 fn hover_shows_struct_field_info() {
686 // Hovering over the field when instantiating
689 struct Foo { field_a: u32 }
692 let foo = Foo { field_a<|>: 0, };
708 // Hovering over the field in the definition
711 struct Foo { field_a<|>: u32 }
714 let foo = Foo { field_a: 0 };
732 fn hover_const_static() {
734 r#"const foo<|>: u32 = 123;"#,
748 r#"static foo<|>: u32 = 456;"#,
764 fn hover_default_generic_types() {
767 struct Test<K, T = u8> { k: K, t: T }
770 let zz<|> = Test { t: 23u8, k: 33 };
786 enum Option<T> { Some(T) }
789 fn main() { So<|>me(12); }
806 enum Option<T> { Some(T) }
809 fn main() { let b<|>ar = Some(12); }
822 fn hover_enum_variant() {
854 let s = Option::Som<|>e(12);
876 fn hover_for_local_variable() {
878 r#"fn func(foo: i32) { fo<|>o; }"#,
890 fn hover_for_local_variable_pat() {
892 r#"fn func(fo<|>o: i32) {}"#,
904 fn hover_local_var_edge() {
906 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
918 fn hover_for_param_edge() {
920 r#"fn func(<|>foo: i32) {}"#,
932 fn hover_for_param_with_multiple_traits() {
940 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
945 impl Deref<Target = u8> + DerefMut<Target = u8>
952 fn test_hover_infer_associated_method_result() {
955 struct Thing { x: u32 }
958 fn new() -> Thing { Thing { x: 0 } }
961 fn main() { let foo_<|>test = Thing::new(); }
974 fn test_hover_infer_associated_method_exact() {
978 struct Thing { x: u32 }
981 fn new() -> Thing { Thing { x: 0 } }
985 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1002 fn test_hover_infer_associated_const_in_pattern() {
1033 fn test_hover_self() {
1036 struct Thing { x: u32 }
1038 fn new() -> Self { Self<|> { x: 0 } }
1055 struct Thing { x: u32 }
1057 fn new() -> Self<|> { Self { x: 0 } }
1076 pub fn new() -> Self<|> { Thing::A }
1095 pub fn thing(a: Self<|>) {}
1113 fn test_hover_shadowing_pat() {
1134 fn test_hover_macro_invocation() {
1137 macro_rules! foo { () => {} }
1139 fn f() { fo<|>o!(); }
1156 fn test_hover_tuple_field() {
1158 r#"struct TS(String, i32<|>);"#,
1167 fn test_hover_through_macro() {
1170 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1173 fn bar() { fo<|>o(); }
1191 fn test_hover_through_expr_in_macro() {
1194 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1195 fn foo(bar:u32) { let a = id!(ba<|>r); }
1208 fn test_hover_through_expr_in_macro_recursive() {
1211 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1212 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1213 fn foo(bar:u32) { let a = id!(ba<|>r); }
1226 fn test_hover_through_func_in_macro_recursive() {
1229 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1230 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1231 fn bar() -> u32 { 0 }
1232 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1244 fn test_hover_through_literal_string_in_macro() {
1247 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1249 let mastered_for_itunes = "";
1250 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1263 fn test_hover_through_assert_macro() {
1266 #[rustc_builtin_macro]
1267 macro_rules! assert {}
1269 fn bar() -> bool { true }
1289 fn test_hover_through_literal_string_in_builtin_macro() {
1290 check_hover_no_result(
1292 #[rustc_builtin_macro]
1293 macro_rules! format {}
1296 format!("hel<|>lo {}", 0);
1303 fn test_hover_non_ascii_space_doc() {
1306 /// <- `\u{3000}` here
1309 fn bar() { fo<|>o(); }
1330 fn test_hover_function_show_qualifiers() {
1332 r#"async fn foo<|>() {}"#,
1346 r#"pub const unsafe fn foo<|>() {}"#,
1355 pub const unsafe fn foo()
1360 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1369 pub(crate) async unsafe extern "C" fn foo()
1376 fn test_hover_trait_show_qualifiers() {
1378 r"unsafe trait foo<|>() {}",
1395 fn test_hover_extern_crate() {
1398 //- /main.rs crate:main deps:std
1399 extern crate st<|>d;
1400 //- /std/lib.rs crate:std
1401 //! Standard library for this test
1408 Standard library for this test
1416 //- /main.rs crate:main deps:std
1417 extern crate std as ab<|>c;
1418 //- /std/lib.rs crate:std
1419 //! Standard library for this test
1426 Standard library for this test
1435 fn test_hover_mod_with_same_name_as_function() {
1438 use self::m<|>y::Bar;
1439 mod my { pub struct Bar; }
1458 fn test_hover_struct_doc_comment() {
1464 fn foo() { let bar = Ba<|>r; }
1485 fn test_hover_struct_doc_attr() {
1491 fn foo() { let bar = Ba<|>r; }
1512 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1516 #[doc = "bar docs 1"]
1517 #[doc = "bar docs 2"]
1520 fn foo() { let bar = Ba<|>r; }
1543 fn test_hover_path_link() {
1547 /// [Foo](struct.Foo.html)
1563 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1569 fn test_hover_path_link_no_strip() {
1573 /// [struct Foo](struct.Foo.html)
1589 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1594 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1596 fn test_hover_path_link_field() {
1601 /// [Foo](struct.Foo.html)
1618 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1624 fn test_hover_intra_link() {
1646 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1652 fn test_hover_intra_link_html_root_url() {
1655 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1676 [Foo](https://example.com/test/foo/struct.Foo.html)
1682 fn test_hover_intra_link_shortlink() {
1702 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1708 fn test_hover_intra_link_shortlink_code() {
1728 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1734 fn test_hover_intra_link_namespaced() {
1755 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1761 fn test_hover_intra_link_shortlink_namspaced_code() {
1781 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1787 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1807 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1813 fn test_hover_intra_link_reference() {
1835 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1841 fn test_hover_external_url() {
1845 /// [external](https://www.google.com)
1861 [external](https://www.google.com)
1866 // Check that we don't rewrite links which we can't identify
1868 fn test_hover_unknown_target() {
1894 fn test_doc_links_enum_variant() {
1915 [E](https://docs.rs/test/*/test/enum.E.html)
1921 fn test_doc_links_field() {
1942 [`S`](https://docs.rs/test/*/test/struct.S.html)
1948 fn test_hover_no_links() {
1949 check_hover_no_links(
1952 /// case 1. bare URL: https://www.example.com/
1953 /// case 2. inline URL with title: [example](https://www.example.com/)
1954 /// case 3. code refrence: [`Result`]
1955 /// case 4. code refrence but miss footnote: [`String`]
1956 /// case 5. autolink: <http://www.example.com/>
1957 /// case 6. email address: <test@example.com>
1958 /// case 7. refrence: [example][example]
1959 /// case 8. collapsed link: [example][]
1960 /// case 9. shortcut link: [example]
1961 /// case 10. inline without URL: [example]()
1962 /// case 11. refrence: [foo][foo]
1963 /// case 12. refrence: [foo][bar]
1964 /// case 13. collapsed link: [foo][]
1965 /// case 14. shortcut link: [foo]
1966 /// case 15. inline without URL: [foo]()
1967 /// case 16. just escaped text: \[foo]
1968 /// case 17. inline link: [Foo](foo::Foo)
1970 /// [`Result`]: ../../std/result/enum.Result.html
1971 /// [^example]: https://www.example.com/
1988 case 1. bare URL: https://www.example.com/
1989 case 2. inline URL with title: [example](https://www.example.com/)
1990 case 3. code refrence: `Result`
1991 case 4. code refrence but miss footnote: `String`
1992 case 5. autolink: http://www.example.com/
1993 case 6. email address: test@example.com
1994 case 7. refrence: example
1995 case 8. collapsed link: example
1996 case 9. shortcut link: example
1997 case 10. inline without URL: example
1998 case 11. refrence: foo
1999 case 12. refrence: foo
2000 case 13. collapsed link: foo
2001 case 14. shortcut link: foo
2002 case 15. inline without URL: foo
2003 case 16. just escaped text: \[foo]
2004 case 17. inline link: Foo
2006 [^example]: https://www.example.com/
2012 fn test_hover_macro_generated_struct_fn_doc_comment() {
2013 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2029 fn foo() { let bar = Bar; bar.fo<|>o(); }
2050 fn test_hover_macro_generated_struct_fn_doc_attr() {
2051 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2059 #[doc = "Do the foo"]
2067 fn foo() { let bar = Bar; bar.fo<|>o(); }
2088 fn test_hover_trait_has_impl_action() {
2090 r#"trait foo<|>() {}"#,
2107 fn test_hover_struct_has_impl_action() {
2109 r"struct foo<|>() {}",
2126 fn test_hover_union_has_impl_action() {
2128 r#"union foo<|>() {}"#,
2145 fn test_hover_enum_has_impl_action() {
2147 r"enum foo<|>() { A, B }",
2164 fn test_hover_test_has_action() {
2174 nav: NavigationTarget {
2184 container_name: None,
2205 fn test_hover_test_mod_has_action() {
2217 nav: NavigationTarget {
2227 container_name: None,
2243 fn test_hover_struct_has_goto_type_action() {
2248 fn main() { let s<|>t = S{ f1:0 }; }
2255 mod_path: "test::S",
2256 nav: NavigationTarget {
2266 container_name: None,
2281 fn test_hover_generic_struct_has_goto_type_actions() {
2285 struct S<T>{ f1: T }
2287 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2294 mod_path: "test::S",
2295 nav: NavigationTarget {
2305 container_name: None,
2313 mod_path: "test::Arg",
2314 nav: NavigationTarget {
2324 container_name: None,
2339 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2343 struct S<T>{ f1: T }
2345 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2352 mod_path: "test::S",
2353 nav: NavigationTarget {
2363 container_name: None,
2371 mod_path: "test::Arg",
2372 nav: NavigationTarget {
2382 container_name: None,
2397 fn test_hover_tuple_has_goto_type_actions() {
2406 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2413 mod_path: "test::A",
2414 nav: NavigationTarget {
2424 container_name: None,
2432 mod_path: "test::B",
2433 nav: NavigationTarget {
2443 container_name: None,
2451 mod_path: "test::M::C",
2452 nav: NavigationTarget {
2462 container_name: None,
2477 fn test_hover_return_impl_trait_has_goto_type_action() {
2481 fn foo() -> impl Foo {}
2483 fn main() { let s<|>t = foo(); }
2490 mod_path: "test::Foo",
2491 nav: NavigationTarget {
2501 container_name: None,
2516 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2521 fn foo() -> impl Foo<S> {}
2523 fn main() { let s<|>t = foo(); }
2530 mod_path: "test::Foo",
2531 nav: NavigationTarget {
2541 container_name: None,
2549 mod_path: "test::S",
2550 nav: NavigationTarget {
2560 container_name: None,
2575 fn test_hover_return_impl_traits_has_goto_type_action() {
2580 fn foo() -> impl Foo + Bar {}
2582 fn main() { let s<|>t = foo(); }
2589 mod_path: "test::Foo",
2590 nav: NavigationTarget {
2600 container_name: None,
2608 mod_path: "test::Bar",
2609 nav: NavigationTarget {
2619 container_name: None,
2634 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2642 fn foo() -> impl Foo<S1> + Bar<S2> {}
2644 fn main() { let s<|>t = foo(); }
2651 mod_path: "test::Foo",
2652 nav: NavigationTarget {
2662 container_name: None,
2670 mod_path: "test::Bar",
2671 nav: NavigationTarget {
2681 container_name: None,
2689 mod_path: "test::S1",
2690 nav: NavigationTarget {
2700 container_name: None,
2708 mod_path: "test::S2",
2709 nav: NavigationTarget {
2719 container_name: None,
2734 fn test_hover_arg_impl_trait_has_goto_type_action() {
2738 fn foo(ar<|>g: &impl Foo) {}
2745 mod_path: "test::Foo",
2746 nav: NavigationTarget {
2756 container_name: None,
2771 fn test_hover_arg_impl_traits_has_goto_type_action() {
2778 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2785 mod_path: "test::Foo",
2786 nav: NavigationTarget {
2796 container_name: None,
2804 mod_path: "test::Bar",
2805 nav: NavigationTarget {
2815 container_name: None,
2823 mod_path: "test::S",
2824 nav: NavigationTarget {
2834 container_name: None,
2849 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2854 let fo<|>o = async { S };
2857 #[prelude_import] use future::*;
2859 #[lang = "future_trait"]
2860 pub trait Future { type Output; }
2868 mod_path: "test::future::Future",
2869 nav: NavigationTarget {
2873 full_range: 101..163,
2879 container_name: None,
2887 mod_path: "test::S",
2888 nav: NavigationTarget {
2898 container_name: None,
2913 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2918 fn foo(ar<|>g: &impl Foo<S>) {}
2925 mod_path: "test::Foo",
2926 nav: NavigationTarget {
2936 container_name: None,
2944 mod_path: "test::S",
2945 nav: NavigationTarget {
2955 container_name: None,
2970 fn test_hover_dyn_return_has_goto_type_action() {
2978 fn foo() -> B<dyn Foo> {}
2980 fn main() { let s<|>t = foo(); }
2987 mod_path: "test::B",
2988 nav: NavigationTarget {
2998 container_name: None,
3006 mod_path: "test::Foo",
3007 nav: NavigationTarget {
3017 container_name: None,
3032 fn test_hover_dyn_arg_has_goto_type_action() {
3036 fn foo(ar<|>g: &dyn Foo) {}
3043 mod_path: "test::Foo",
3044 nav: NavigationTarget {
3054 container_name: None,
3069 fn test_hover_generic_dyn_arg_has_goto_type_action() {
3074 fn foo(ar<|>g: &dyn Foo<S>) {}
3081 mod_path: "test::Foo",
3082 nav: NavigationTarget {
3092 container_name: None,
3100 mod_path: "test::S",
3101 nav: NavigationTarget {
3111 container_name: None,
3126 fn test_hover_goto_type_action_links_order() {
3129 trait ImplTrait<T> {}
3130 trait DynTrait<T> {}
3134 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3141 mod_path: "test::ImplTrait",
3142 nav: NavigationTarget {
3152 container_name: None,
3160 mod_path: "test::B",
3161 nav: NavigationTarget {
3171 container_name: None,
3179 mod_path: "test::DynTrait",
3180 nav: NavigationTarget {
3190 container_name: None,
3198 mod_path: "test::S",
3199 nav: NavigationTarget {
3209 container_name: None,
3224 fn test_hover_associated_type_has_goto_type_action() {
3229 fn get(self) -> Self::Item {}
3235 impl Foo for S { type Item = Bar; }
3237 fn test() -> impl Foo { S {} }
3239 fn main() { let s<|>t = test().get(); }
3246 mod_path: "test::Foo",
3247 nav: NavigationTarget {
3257 container_name: None,
3272 fn hover_displays_normalized_crate_names() {
3275 //- /lib.rs crate:name-with-dashes
3277 pub struct Thing { x: u32 }
3280 pub fn new() -> Thing { Thing { x: 0 } }
3284 //- /main.rs crate:main deps:name-with-dashes
3285 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3291 name_with_dashes::wrapper::Thing
3295 pub fn new() -> Thing
3302 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3311 let S { f<|> } = &s;
3325 fn hover_self_param_shows_type() {
3343 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3349 fn bar(sel<|>f: Arc<Foo>) {}
3362 fn hover_doc_outer_inner() {
3369 /// This comment belongs to the function
3393 fn hover_doc_outer_inner_attribue() {
3396 #[doc = "Be quick;"]
3398 #![doc = "time is mana"]
3400 #[doc = "This comment belongs to the function"]