2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
5 use ide_db::base_db::SourceDatabase;
7 defs::{Definition, NameClass, NameRefClass},
10 use itertools::Itertools;
12 use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
16 display::{macro_label, ShortLabel, TryToNav},
17 doc_links::{remove_links, rewrite_links},
18 markdown_remove::remove_markdown,
20 runnables::{runnable_fn, runnable_mod},
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,
35 pub const NO_ACTIONS: Self = Self {
36 implementations: false,
44 pub fn any(&self) -> bool {
45 self.implementations || self.runnable() || self.goto_type_def
48 pub fn none(&self) -> bool {
52 pub fn runnable(&self) -> bool {
53 self.run || self.debug
57 #[derive(Debug, Clone)]
58 pub enum HoverAction {
60 Implementation(FilePosition),
61 GoToType(Vec<HoverGotoTypeData>),
64 #[derive(Debug, Clone, Eq, PartialEq)]
65 pub struct HoverGotoTypeData {
67 pub nav: NavigationTarget,
70 /// Contains the results when hovering over an item
71 #[derive(Debug, Default)]
72 pub struct HoverResult {
74 pub actions: Vec<HoverAction>,
79 // Shows additional information, like type of an expression or documentation for definition when "focusing" code.
80 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
83 position: FilePosition,
86 ) -> Option<RangeInfo<HoverResult>> {
87 let sema = Semantics::new(db);
88 let file = sema.parse(position.file_id).syntax().clone();
89 let token = pick_best(file.token_at_offset(position.offset))?;
90 let token = sema.descend_into_macros(token);
92 let mut res = HoverResult::default();
94 let node = token.parent();
95 let definition = match_ast! {
97 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.defined(sema.db)),
98 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)),
99 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
100 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
104 if let Some(definition) = definition {
105 if let Some(markup) = hover_for_definition(db, definition) {
106 let markup = markup.as_str();
107 let markup = if !markdown {
108 remove_markdown(markup)
109 } else if links_in_hover {
110 rewrite_links(db, markup, &definition)
114 res.markup = Markup::from(markup);
115 if let Some(action) = show_implementations_action(db, definition) {
116 res.actions.push(action);
119 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
120 res.actions.push(action);
123 if let Some(action) = goto_type_action(db, definition) {
124 res.actions.push(action);
127 let range = sema.original_range(&node).range;
128 return Some(RangeInfo::new(range, res));
132 if token.kind() == syntax::SyntaxKind::COMMENT {
133 // don't highlight the entire parent node on comment hover
139 .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
141 let ty = match_ast! {
143 ast::Expr(it) => sema.type_of_expr(&it)?,
144 ast::Pat(it) => sema.type_of_pat(&it)?,
145 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
146 // (e.g expanding a builtin macro). So we give up here.
147 ast::MacroCall(_it) => return None,
152 res.markup = if markdown {
153 Markup::fenced_block(&ty.display(db))
155 ty.display(db).to_string().into()
157 let range = sema.original_range(&node).range;
158 Some(RangeInfo::new(range, res))
161 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
162 fn to_action(nav_target: NavigationTarget) -> HoverAction {
163 HoverAction::Implementation(FilePosition {
164 file_id: nav_target.file_id,
165 offset: nav_target.focus_or_full_range().start(),
169 let adt = match def {
170 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
171 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
172 Definition::SelfType(it) => it.target_ty(db).as_adt(),
175 adt.try_to_nav(db).map(to_action)
179 sema: &Semantics<RootDatabase>,
182 ) -> Option<HoverAction> {
184 Definition::ModuleDef(it) => match it {
185 ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)),
186 ModuleDef::Function(func) => {
187 let src = func.source(sema.db)?;
188 if src.file_id != file_id.into() {
189 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
190 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
194 runnable_fn(&sema, func).map(HoverAction::Runnable)
202 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
203 let mut targets: Vec<ModuleDef> = Vec::new();
204 let mut push_new_def = |item: ModuleDef| {
205 if !targets.contains(&item) {
210 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
211 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
214 Definition::Local(it) => it.ty(db),
215 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
220 if let Some(adt) = t.as_adt() {
221 push_new_def(adt.into());
222 } else if let Some(trait_) = t.as_dyn_trait() {
223 push_new_def(trait_.into());
224 } else if let Some(traits) = t.as_impl_traits(db) {
225 traits.into_iter().for_each(|it| push_new_def(it.into()));
226 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
227 push_new_def(trait_.into());
232 let targets = targets
235 Some(HoverGotoTypeData {
236 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
237 nav: it.try_to_nav(db)?,
242 Some(HoverAction::GoToType(targets))
246 docs: Option<String>,
247 desc: Option<String>,
248 mod_path: Option<String>,
249 ) -> Option<Markup> {
252 let mut buf = String::new();
254 if let Some(mod_path) = mod_path {
255 if !mod_path.is_empty() {
256 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
259 format_to!(buf, "```rust\n{}\n```", desc);
261 if let Some(doc) = docs {
262 format_to!(buf, "\n___\n\n{}", doc);
266 None => docs.map(Markup::from),
270 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
272 Definition::Field(f) => Some(f.parent_def(db).name(db)),
273 Definition::Local(l) => l.parent(db).name(db),
274 Definition::ModuleDef(md) => match md {
275 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
276 AssocItemContainer::Trait(t) => Some(t.name(db)),
277 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
279 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
284 .map(|name| name.to_string())
287 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
289 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
290 let module_path = module
294 .flat_map(|it| it.name(db).map(|name| name.to_string()));
295 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
298 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
299 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
302 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
303 let mod_path = definition_mod_path(db, &def);
305 Definition::Macro(it) => {
306 let label = macro_label(&it.source(db)?.value);
307 from_def_source_labeled(db, it, Some(label), mod_path)
309 Definition::Field(def) => {
310 let src = def.source(db)?.value;
311 if let FieldSource::Named(it) = src {
312 from_def_source_labeled(db, def, it.short_label(), mod_path)
317 Definition::ModuleDef(it) => match it {
318 ModuleDef::Module(it) => from_def_source_labeled(
321 match it.definition_source(db).value {
322 ModuleSource::Module(it) => it.short_label(),
323 ModuleSource::SourceFile(it) => it.short_label(),
327 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
328 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
329 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
330 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
331 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
332 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
333 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
334 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
335 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
336 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
338 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
339 Definition::SelfType(impl_def) => {
340 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
341 Adt::Struct(it) => from_def_source(db, it, mod_path),
342 Adt::Union(it) => from_def_source(db, it, mod_path),
343 Adt::Enum(it) => from_def_source(db, it, mod_path),
346 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
347 Definition::GenericParam(it) => match it {
348 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
349 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
350 GenericParam::ConstParam(it) => from_def_source(db, it, None),
354 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
356 D: HasSource<Ast = A> + HasAttrs + Copy,
359 let short_label = def.source(db)?.value.short_label();
360 from_def_source_labeled(db, def, short_label, mod_path)
363 fn from_def_source_labeled<D>(
366 short_label: Option<String>,
367 mod_path: Option<String>,
372 let docs = def.attrs(db).docs().map(Into::into);
373 hover_markup(docs, short_label, mod_path)
377 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
378 return tokens.max_by_key(priority);
379 fn priority(n: &SyntaxToken) -> usize {
381 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 3,
382 T!['('] | T![')'] => 2,
383 kind if kind.is_trivia() => 0,
391 use expect_test::{expect, Expect};
392 use ide_db::base_db::FileLoader;
398 fn check_hover_no_result(ra_fixture: &str) {
399 let (analysis, position) = fixture::position(ra_fixture);
400 assert!(analysis.hover(position, true, true).unwrap().is_none());
403 fn check(ra_fixture: &str, expect: Expect) {
404 let (analysis, position) = fixture::position(ra_fixture);
405 let hover = analysis.hover(position, true, true).unwrap().unwrap();
407 let content = analysis.db.file_text(position.file_id);
408 let hovered_element = &content[hover.range];
410 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
411 expect.assert_eq(&actual)
414 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
415 let (analysis, position) = fixture::position(ra_fixture);
416 let hover = analysis.hover(position, false, true).unwrap().unwrap();
418 let content = analysis.db.file_text(position.file_id);
419 let hovered_element = &content[hover.range];
421 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
422 expect.assert_eq(&actual)
425 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
426 let (analysis, position) = fixture::position(ra_fixture);
427 let hover = analysis.hover(position, true, false).unwrap().unwrap();
429 let content = analysis.db.file_text(position.file_id);
430 let hovered_element = &content[hover.range];
432 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
433 expect.assert_eq(&actual)
436 fn check_actions(ra_fixture: &str, expect: Expect) {
437 let (analysis, position) = fixture::position(ra_fixture);
438 let hover = analysis.hover(position, true, true).unwrap().unwrap();
439 expect.assert_debug_eq(&hover.info.actions)
443 fn hover_shows_type_of_an_expression() {
446 pub fn foo() -> u32 { 1 }
449 let foo_test = foo()$0;
462 fn hover_remove_markdown_if_configured() {
463 check_hover_no_markdown(
465 pub fn foo() -> u32 { 1 }
468 let foo_test = foo()$0;
479 fn hover_shows_long_type_of_an_expression() {
482 struct Scan<A, B, C> { a: A, b: B, c: C }
483 struct Iter<I> { inner: I }
484 enum Option<T> { Some(T), None }
486 struct OtherStruct<T> { i: T }
488 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
489 Iter { inner: Scan { a, b, c } }
494 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
495 Option::Some(*memo + value)
498 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
505 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
512 fn hover_shows_fn_signature() {
513 // Single file with result
516 pub fn foo() -> u32 { 1 }
518 fn main() { let foo_test = fo$0o(); }
533 // Multiple candidates but results are ambiguous.
537 pub fn foo() -> u32 { 1 }
540 pub fn foo() -> &str { "" }
543 pub fn foo(a: u32, b: u32) {}
550 fn main() { let foo_test = fo$0o(); }
562 fn hover_shows_fn_signature_with_type_params() {
565 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
567 fn main() { let foo_test = fo$0o(); }
577 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
584 fn hover_shows_fn_signature_on_fn_name() {
587 pub fn foo$0(a: u32, b: u32) -> u32 {}
599 pub fn foo(a: u32, b: u32) -> u32
606 fn hover_shows_fn_doc() {
611 /// # use std::path::Path;
613 /// foo(Path::new("hello, world!"))
615 pub fn foo$0(_: &Path) {}
635 # use std::path::Path;
637 foo(Path::new("hello, world!"))
644 fn hover_shows_fn_doc_attr_raw_string() {
647 #[doc = r#"Raw string doc attr"#]
648 pub fn foo$0(_: &Path) {}
671 fn hover_shows_struct_field_info() {
672 // Hovering over the field when instantiating
675 struct Foo { field_a: u32 }
678 let foo = Foo { field_a$0: 0, };
694 // Hovering over the field in the definition
697 struct Foo { field_a$0: u32 }
700 let foo = Foo { field_a: 0 };
718 fn hover_const_static() {
720 r#"const foo$0: u32 = 123;"#,
734 r#"static foo$0: u32 = 456;"#,
750 fn hover_default_generic_types() {
753 struct Test<K, T = u8> { k: K, t: T }
756 let zz$0 = Test { t: 23u8, k: 33 };
772 enum Option<T> { Some(T) }
775 fn main() { So$0me(12); }
792 enum Option<T> { Some(T) }
795 fn main() { let b$0ar = Some(12); }
808 fn hover_enum_variant() {
840 let s = Option::Som$0e(12);
862 fn hover_for_local_variable() {
864 r#"fn func(foo: i32) { fo$0o; }"#,
876 fn hover_for_local_variable_pat() {
878 r#"fn func(fo$0o: i32) {}"#,
890 fn hover_local_var_edge() {
892 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
904 fn hover_for_param_edge() {
906 r#"fn func($0foo: i32) {}"#,
918 fn hover_for_param_with_multiple_traits() {
926 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
931 impl Deref<Target = u8> + DerefMut<Target = u8>
938 fn test_hover_infer_associated_method_result() {
941 struct Thing { x: u32 }
944 fn new() -> Thing { Thing { x: 0 } }
947 fn main() { let foo_$0test = Thing::new(); }
960 fn test_hover_infer_associated_method_exact() {
964 struct Thing { x: u32 }
967 fn new() -> Thing { Thing { x: 0 } }
971 fn main() { let foo_test = wrapper::Thing::new$0(); }
988 fn test_hover_infer_associated_const_in_pattern() {
1019 fn test_hover_self() {
1022 struct Thing { x: u32 }
1024 fn new() -> Self { Self$0 { x: 0 } }
1041 struct Thing { x: u32 }
1043 fn new() -> Self$0 { Self { x: 0 } }
1062 pub fn new() -> Self$0 { Thing::A }
1081 pub fn thing(a: Self$0) {}
1099 fn test_hover_shadowing_pat() {
1120 fn test_hover_macro_invocation() {
1123 macro_rules! foo { () => {} }
1125 fn f() { fo$0o!(); }
1142 fn test_hover_tuple_field() {
1144 r#"struct TS(String, i32$0);"#,
1156 fn test_hover_through_macro() {
1159 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1162 fn bar() { fo$0o(); }
1180 fn test_hover_through_expr_in_macro() {
1183 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1184 fn foo(bar:u32) { let a = id!(ba$0r); }
1197 fn test_hover_through_expr_in_macro_recursive() {
1200 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1201 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1202 fn foo(bar:u32) { let a = id!(ba$0r); }
1215 fn test_hover_through_func_in_macro_recursive() {
1218 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1219 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1220 fn bar() -> u32 { 0 }
1221 fn foo() { let a = id!([0u32, bar($0)] ); }
1233 fn test_hover_through_literal_string_in_macro() {
1236 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1238 let mastered_for_itunes = "";
1239 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1252 fn test_hover_through_assert_macro() {
1255 #[rustc_builtin_macro]
1256 macro_rules! assert {}
1258 fn bar() -> bool { true }
1278 fn test_hover_through_literal_string_in_builtin_macro() {
1279 check_hover_no_result(
1281 #[rustc_builtin_macro]
1282 macro_rules! format {}
1285 format!("hel$0lo {}", 0);
1292 fn test_hover_non_ascii_space_doc() {
1295 /// <- `\u{3000}` here
1298 fn bar() { fo$0o(); }
1319 fn test_hover_function_show_qualifiers() {
1321 r#"async fn foo$0() {}"#,
1335 r#"pub const unsafe fn foo$0() {}"#,
1344 pub const unsafe fn foo()
1349 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1358 pub(crate) async unsafe extern "C" fn foo()
1365 fn test_hover_trait_show_qualifiers() {
1367 r"unsafe trait foo$0() {}",
1384 fn test_hover_extern_crate() {
1387 //- /main.rs crate:main deps:std
1389 //- /std/lib.rs crate:std
1390 //! Standard library for this test
1397 Standard library for this test
1405 //- /main.rs crate:main deps:std
1406 extern crate std as ab$0c;
1407 //- /std/lib.rs crate:std
1408 //! Standard library for this test
1415 Standard library for this test
1424 fn test_hover_mod_with_same_name_as_function() {
1427 use self::m$0y::Bar;
1428 mod my { pub struct Bar; }
1447 fn test_hover_struct_doc_comment() {
1453 fn foo() { let bar = Ba$0r; }
1474 fn test_hover_struct_doc_attr() {
1480 fn foo() { let bar = Ba$0r; }
1501 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1505 #[doc = "bar docs 1"]
1506 #[doc = "bar docs 2"]
1509 fn foo() { let bar = Ba$0r; }
1532 fn test_hover_path_link() {
1536 /// [Foo](struct.Foo.html)
1552 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1558 fn test_hover_path_link_no_strip() {
1562 /// [struct Foo](struct.Foo.html)
1578 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1583 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1585 fn test_hover_path_link_field() {
1590 /// [Foo](struct.Foo.html)
1607 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1613 fn test_hover_intra_link() {
1635 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1641 fn test_hover_intra_link_html_root_url() {
1644 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1665 [Foo](https://example.com/test/foo/struct.Foo.html)
1671 fn test_hover_intra_link_shortlink() {
1691 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1697 fn test_hover_intra_link_shortlink_code() {
1717 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1723 fn test_hover_intra_link_namespaced() {
1744 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1750 fn test_hover_intra_link_shortlink_namspaced_code() {
1770 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1776 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1796 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1802 fn test_hover_intra_link_reference() {
1824 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1830 fn test_hover_external_url() {
1834 /// [external](https://www.google.com)
1850 [external](https://www.google.com)
1855 // Check that we don't rewrite links which we can't identify
1857 fn test_hover_unknown_target() {
1883 fn test_doc_links_enum_variant() {
1904 [E](https://docs.rs/test/*/test/enum.E.html)
1910 fn test_doc_links_field() {
1931 [`S`](https://docs.rs/test/*/test/struct.S.html)
1937 fn test_hover_no_links() {
1938 check_hover_no_links(
1941 /// case 1. bare URL: https://www.example.com/
1942 /// case 2. inline URL with title: [example](https://www.example.com/)
1943 /// case 3. code reference: [`Result`]
1944 /// case 4. code reference but miss footnote: [`String`]
1945 /// case 5. autolink: <http://www.example.com/>
1946 /// case 6. email address: <test@example.com>
1947 /// case 7. reference: [example][example]
1948 /// case 8. collapsed link: [example][]
1949 /// case 9. shortcut link: [example]
1950 /// case 10. inline without URL: [example]()
1951 /// case 11. reference: [foo][foo]
1952 /// case 12. reference: [foo][bar]
1953 /// case 13. collapsed link: [foo][]
1954 /// case 14. shortcut link: [foo]
1955 /// case 15. inline without URL: [foo]()
1956 /// case 16. just escaped text: \[foo]
1957 /// case 17. inline link: [Foo](foo::Foo)
1959 /// [`Result`]: ../../std/result/enum.Result.html
1960 /// [^example]: https://www.example.com/
1977 case 1. bare URL: https://www.example.com/
1978 case 2. inline URL with title: [example](https://www.example.com/)
1979 case 3. code reference: `Result`
1980 case 4. code reference but miss footnote: `String`
1981 case 5. autolink: http://www.example.com/
1982 case 6. email address: test@example.com
1983 case 7. reference: example
1984 case 8. collapsed link: example
1985 case 9. shortcut link: example
1986 case 10. inline without URL: example
1987 case 11. reference: foo
1988 case 12. reference: foo
1989 case 13. collapsed link: foo
1990 case 14. shortcut link: foo
1991 case 15. inline without URL: foo
1992 case 16. just escaped text: \[foo]
1993 case 17. inline link: Foo
1995 [^example]: https://www.example.com/
2001 fn test_hover_macro_generated_struct_fn_doc_comment() {
2002 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2018 fn foo() { let bar = Bar; bar.fo$0o(); }
2039 fn test_hover_macro_generated_struct_fn_doc_attr() {
2040 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2048 #[doc = "Do the foo"]
2056 fn foo() { let bar = Bar; bar.fo$0o(); }
2077 fn test_hover_trait_has_impl_action() {
2079 r#"trait foo$0() {}"#,
2096 fn test_hover_struct_has_impl_action() {
2098 r"struct foo$0() {}",
2115 fn test_hover_union_has_impl_action() {
2117 r#"union foo$0() {}"#,
2134 fn test_hover_enum_has_impl_action() {
2136 r"enum foo$0() { A, B }",
2153 fn test_hover_self_has_impl_action() {
2155 r#"struct foo where Self$0:;"#,
2172 fn test_hover_test_has_action() {
2182 nav: NavigationTarget {
2187 focus_range: 11..19,
2208 fn test_hover_test_mod_has_action() {
2220 nav: NavigationTarget {
2241 fn test_hover_struct_has_goto_type_action() {
2246 fn main() { let s$0t = S{ f1:0 }; }
2253 mod_path: "test::S",
2254 nav: NavigationTarget {
2262 description: "struct S",
2273 fn test_hover_generic_struct_has_goto_type_actions() {
2277 struct S<T>{ f1: T }
2279 fn main() { let s$0t = S{ f1:Arg(0) }; }
2286 mod_path: "test::S",
2287 nav: NavigationTarget {
2292 focus_range: 24..25,
2295 description: "struct S",
2299 mod_path: "test::Arg",
2300 nav: NavigationTarget {
2308 description: "struct Arg",
2319 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2323 struct S<T>{ f1: T }
2325 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2332 mod_path: "test::S",
2333 nav: NavigationTarget {
2338 focus_range: 24..25,
2341 description: "struct S",
2345 mod_path: "test::Arg",
2346 nav: NavigationTarget {
2354 description: "struct Arg",
2365 fn test_hover_tuple_has_goto_type_actions() {
2374 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2381 mod_path: "test::A",
2382 nav: NavigationTarget {
2390 description: "struct A",
2394 mod_path: "test::B",
2395 nav: NavigationTarget {
2400 focus_range: 22..23,
2403 description: "struct B",
2407 mod_path: "test::M::C",
2408 nav: NavigationTarget {
2413 focus_range: 53..54,
2416 description: "pub struct C",
2427 fn test_hover_return_impl_trait_has_goto_type_action() {
2431 fn foo() -> impl Foo {}
2433 fn main() { let s$0t = foo(); }
2440 mod_path: "test::Foo",
2441 nav: NavigationTarget {
2449 description: "trait Foo",
2460 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2465 fn foo() -> impl Foo<S> {}
2467 fn main() { let s$0t = foo(); }
2474 mod_path: "test::Foo",
2475 nav: NavigationTarget {
2483 description: "trait Foo",
2487 mod_path: "test::S",
2488 nav: NavigationTarget {
2493 focus_range: 23..24,
2496 description: "struct S",
2507 fn test_hover_return_impl_traits_has_goto_type_action() {
2512 fn foo() -> impl Foo + Bar {}
2514 fn main() { let s$0t = foo(); }
2521 mod_path: "test::Foo",
2522 nav: NavigationTarget {
2530 description: "trait Foo",
2534 mod_path: "test::Bar",
2535 nav: NavigationTarget {
2540 focus_range: 19..22,
2543 description: "trait Bar",
2554 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2562 fn foo() -> impl Foo<S1> + Bar<S2> {}
2564 fn main() { let s$0t = foo(); }
2571 mod_path: "test::Foo",
2572 nav: NavigationTarget {
2580 description: "trait Foo",
2584 mod_path: "test::Bar",
2585 nav: NavigationTarget {
2590 focus_range: 22..25,
2593 description: "trait Bar",
2597 mod_path: "test::S1",
2598 nav: NavigationTarget {
2603 focus_range: 39..41,
2606 description: "struct S1",
2610 mod_path: "test::S2",
2611 nav: NavigationTarget {
2616 focus_range: 52..54,
2619 description: "struct S2",
2630 fn test_hover_arg_impl_trait_has_goto_type_action() {
2634 fn foo(ar$0g: &impl Foo) {}
2641 mod_path: "test::Foo",
2642 nav: NavigationTarget {
2650 description: "trait Foo",
2661 fn test_hover_arg_impl_traits_has_goto_type_action() {
2668 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2675 mod_path: "test::Foo",
2676 nav: NavigationTarget {
2684 description: "trait Foo",
2688 mod_path: "test::Bar",
2689 nav: NavigationTarget {
2694 focus_range: 19..22,
2697 description: "trait Bar",
2701 mod_path: "test::S",
2702 nav: NavigationTarget {
2707 focus_range: 36..37,
2710 description: "struct S",
2721 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2726 let fo$0o = async { S };
2729 #[prelude_import] use future::*;
2731 #[lang = "future_trait"]
2732 pub trait Future { type Output; }
2740 mod_path: "test::future::Future",
2741 nav: NavigationTarget {
2745 full_range: 101..163,
2746 focus_range: 140..146,
2749 description: "pub trait Future",
2753 mod_path: "test::S",
2754 nav: NavigationTarget {
2762 description: "struct S",
2773 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2778 fn foo(ar$0g: &impl Foo<S>) {}
2785 mod_path: "test::Foo",
2786 nav: NavigationTarget {
2794 description: "trait Foo",
2798 mod_path: "test::S",
2799 nav: NavigationTarget {
2804 focus_range: 23..24,
2807 description: "struct S",
2818 fn test_hover_dyn_return_has_goto_type_action() {
2826 fn foo() -> B<dyn Foo> {}
2828 fn main() { let s$0t = foo(); }
2835 mod_path: "test::B",
2836 nav: NavigationTarget {
2841 focus_range: 49..50,
2844 description: "struct B",
2848 mod_path: "test::Foo",
2849 nav: NavigationTarget {
2857 description: "trait Foo",
2868 fn test_hover_dyn_arg_has_goto_type_action() {
2872 fn foo(ar$0g: &dyn Foo) {}
2879 mod_path: "test::Foo",
2880 nav: NavigationTarget {
2888 description: "trait Foo",
2899 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2904 fn foo(ar$0g: &dyn Foo<S>) {}
2911 mod_path: "test::Foo",
2912 nav: NavigationTarget {
2920 description: "trait Foo",
2924 mod_path: "test::S",
2925 nav: NavigationTarget {
2930 focus_range: 23..24,
2933 description: "struct S",
2944 fn test_hover_goto_type_action_links_order() {
2947 trait ImplTrait<T> {}
2948 trait DynTrait<T> {}
2952 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2959 mod_path: "test::ImplTrait",
2960 nav: NavigationTarget {
2968 description: "trait ImplTrait",
2972 mod_path: "test::B",
2973 nav: NavigationTarget {
2978 focus_range: 50..51,
2981 description: "struct B",
2985 mod_path: "test::DynTrait",
2986 nav: NavigationTarget {
2991 focus_range: 28..36,
2994 description: "trait DynTrait",
2998 mod_path: "test::S",
2999 nav: NavigationTarget {
3004 focus_range: 65..66,
3007 description: "struct S",
3018 fn test_hover_associated_type_has_goto_type_action() {
3023 fn get(self) -> Self::Item {}
3029 impl Foo for S { type Item = Bar; }
3031 fn test() -> impl Foo { S {} }
3033 fn main() { let s$0t = test().get(); }
3040 mod_path: "test::Foo",
3041 nav: NavigationTarget {
3049 description: "trait Foo",
3060 fn test_hover_const_param_has_goto_type_action() {
3064 struct Foo<const BAR: Bar>;
3066 impl<const BAR: Bar> Foo<BAR$0> {}
3073 mod_path: "test::Bar",
3074 nav: NavigationTarget {
3082 description: "struct Bar",
3093 fn test_hover_type_param_has_goto_type_action() {
3098 fn foo<T: Foo>(t: T$0){}
3105 mod_path: "test::Foo",
3106 nav: NavigationTarget {
3114 description: "trait Foo",
3125 fn test_hover_self_has_go_to_type() {
3138 mod_path: "test::Foo",
3139 nav: NavigationTarget {
3147 description: "struct Foo",
3158 fn hover_displays_normalized_crate_names() {
3161 //- /lib.rs crate:name-with-dashes
3163 pub struct Thing { x: u32 }
3166 pub fn new() -> Thing { Thing { x: 0 } }
3170 //- /main.rs crate:main deps:name-with-dashes
3171 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3177 name_with_dashes::wrapper::Thing
3181 pub fn new() -> Thing
3188 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3211 fn hover_self_param_shows_type() {
3230 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3236 fn bar(sel$0f: Arc<Foo>) {}
3250 fn hover_doc_outer_inner() {
3257 /// This comment belongs to the function
3281 fn hover_doc_outer_inner_attribue() {
3284 #[doc = "Be quick;"]
3286 #![doc = "time is mana"]
3288 #[doc = "This comment belongs to the function"]
3312 fn hover_comments_dont_highlight_parent() {
3313 check_hover_no_result(
3341 fn hover_lifetime() {
3343 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3355 fn hover_type_param() {
3362 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3368 T: Copy + Clone + Sized
3385 // lifetimes aren't being substituted yet
3389 impl<T: 'static> Foo<T$0> {}
3402 fn hover_const_param() {
3405 struct Foo<const LEN: usize>;
3406 impl<const LEN: usize> Foo<LEN$0> {}