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(),
324 ModuleSource::BlockExpr(it) => it.short_label(),
328 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
329 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
330 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
331 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
332 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
333 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
334 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
335 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
336 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
337 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
339 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
340 Definition::SelfType(impl_def) => {
341 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
342 Adt::Struct(it) => from_def_source(db, it, mod_path),
343 Adt::Union(it) => from_def_source(db, it, mod_path),
344 Adt::Enum(it) => from_def_source(db, it, mod_path),
347 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
348 Definition::GenericParam(it) => match it {
349 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
350 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
351 GenericParam::ConstParam(it) => from_def_source(db, it, None),
355 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
357 D: HasSource<Ast = A> + HasAttrs + Copy,
360 let short_label = def.source(db)?.value.short_label();
361 from_def_source_labeled(db, def, short_label, mod_path)
364 fn from_def_source_labeled<D>(
367 short_label: Option<String>,
368 mod_path: Option<String>,
373 let docs = def.attrs(db).docs().map(Into::into);
374 hover_markup(docs, short_label, mod_path)
378 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
379 return tokens.max_by_key(priority);
380 fn priority(n: &SyntaxToken) -> usize {
382 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 3,
383 T!['('] | T![')'] => 2,
384 kind if kind.is_trivia() => 0,
392 use expect_test::{expect, Expect};
393 use ide_db::base_db::FileLoader;
399 fn check_hover_no_result(ra_fixture: &str) {
400 let (analysis, position) = fixture::position(ra_fixture);
401 assert!(analysis.hover(position, true, true).unwrap().is_none());
404 fn check(ra_fixture: &str, expect: Expect) {
405 let (analysis, position) = fixture::position(ra_fixture);
406 let hover = analysis.hover(position, true, true).unwrap().unwrap();
408 let content = analysis.db.file_text(position.file_id);
409 let hovered_element = &content[hover.range];
411 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
412 expect.assert_eq(&actual)
415 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
416 let (analysis, position) = fixture::position(ra_fixture);
417 let hover = analysis.hover(position, false, true).unwrap().unwrap();
419 let content = analysis.db.file_text(position.file_id);
420 let hovered_element = &content[hover.range];
422 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
423 expect.assert_eq(&actual)
426 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
427 let (analysis, position) = fixture::position(ra_fixture);
428 let hover = analysis.hover(position, true, false).unwrap().unwrap();
430 let content = analysis.db.file_text(position.file_id);
431 let hovered_element = &content[hover.range];
433 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
434 expect.assert_eq(&actual)
437 fn check_actions(ra_fixture: &str, expect: Expect) {
438 let (analysis, position) = fixture::position(ra_fixture);
439 let hover = analysis.hover(position, true, true).unwrap().unwrap();
440 expect.assert_debug_eq(&hover.info.actions)
444 fn hover_shows_type_of_an_expression() {
447 pub fn foo() -> u32 { 1 }
450 let foo_test = foo()$0;
463 fn hover_remove_markdown_if_configured() {
464 check_hover_no_markdown(
466 pub fn foo() -> u32 { 1 }
469 let foo_test = foo()$0;
480 fn hover_shows_long_type_of_an_expression() {
483 struct Scan<A, B, C> { a: A, b: B, c: C }
484 struct Iter<I> { inner: I }
485 enum Option<T> { Some(T), None }
487 struct OtherStruct<T> { i: T }
489 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
490 Iter { inner: Scan { a, b, c } }
495 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
496 Option::Some(*memo + value)
499 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
506 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
513 fn hover_shows_fn_signature() {
514 // Single file with result
517 pub fn foo() -> u32 { 1 }
519 fn main() { let foo_test = fo$0o(); }
534 // Multiple candidates but results are ambiguous.
538 pub fn foo() -> u32 { 1 }
541 pub fn foo() -> &str { "" }
544 pub fn foo(a: u32, b: u32) {}
551 fn main() { let foo_test = fo$0o(); }
563 fn hover_shows_fn_signature_with_type_params() {
566 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
568 fn main() { let foo_test = fo$0o(); }
578 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
585 fn hover_shows_fn_signature_on_fn_name() {
588 pub fn foo$0(a: u32, b: u32) -> u32 {}
600 pub fn foo(a: u32, b: u32) -> u32
607 fn hover_shows_fn_doc() {
612 /// # use std::path::Path;
614 /// foo(Path::new("hello, world!"))
616 pub fn foo$0(_: &Path) {}
636 # use std::path::Path;
638 foo(Path::new("hello, world!"))
645 fn hover_shows_fn_doc_attr_raw_string() {
648 #[doc = r#"Raw string doc attr"#]
649 pub fn foo$0(_: &Path) {}
672 fn hover_shows_struct_field_info() {
673 // Hovering over the field when instantiating
676 struct Foo { field_a: u32 }
679 let foo = Foo { field_a$0: 0, };
695 // Hovering over the field in the definition
698 struct Foo { field_a$0: u32 }
701 let foo = Foo { field_a: 0 };
719 fn hover_const_static() {
721 r#"const foo$0: u32 = 123;"#,
735 r#"static foo$0: u32 = 456;"#,
751 fn hover_default_generic_types() {
754 struct Test<K, T = u8> { k: K, t: T }
757 let zz$0 = Test { t: 23u8, k: 33 };
773 enum Option<T> { Some(T) }
776 fn main() { So$0me(12); }
793 enum Option<T> { Some(T) }
796 fn main() { let b$0ar = Some(12); }
809 fn hover_enum_variant() {
841 let s = Option::Som$0e(12);
863 fn hover_for_local_variable() {
865 r#"fn func(foo: i32) { fo$0o; }"#,
877 fn hover_for_local_variable_pat() {
879 r#"fn func(fo$0o: i32) {}"#,
891 fn hover_local_var_edge() {
893 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
905 fn hover_for_param_edge() {
907 r#"fn func($0foo: i32) {}"#,
919 fn hover_for_param_with_multiple_traits() {
927 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
932 impl Deref<Target = u8> + DerefMut<Target = u8>
939 fn test_hover_infer_associated_method_result() {
942 struct Thing { x: u32 }
945 fn new() -> Thing { Thing { x: 0 } }
948 fn main() { let foo_$0test = Thing::new(); }
961 fn test_hover_infer_associated_method_exact() {
965 struct Thing { x: u32 }
968 fn new() -> Thing { Thing { x: 0 } }
972 fn main() { let foo_test = wrapper::Thing::new$0(); }
989 fn test_hover_infer_associated_const_in_pattern() {
1020 fn test_hover_self() {
1023 struct Thing { x: u32 }
1025 fn new() -> Self { Self$0 { x: 0 } }
1042 struct Thing { x: u32 }
1044 fn new() -> Self$0 { Self { x: 0 } }
1063 pub fn new() -> Self$0 { Thing::A }
1082 pub fn thing(a: Self$0) {}
1100 fn test_hover_shadowing_pat() {
1121 fn test_hover_macro_invocation() {
1124 macro_rules! foo { () => {} }
1126 fn f() { fo$0o!(); }
1143 fn test_hover_tuple_field() {
1145 r#"struct TS(String, i32$0);"#,
1157 fn test_hover_through_macro() {
1160 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1163 fn bar() { fo$0o(); }
1181 fn test_hover_through_expr_in_macro() {
1184 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1185 fn foo(bar:u32) { let a = id!(ba$0r); }
1198 fn test_hover_through_expr_in_macro_recursive() {
1201 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1202 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1203 fn foo(bar:u32) { let a = id!(ba$0r); }
1216 fn test_hover_through_func_in_macro_recursive() {
1219 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1220 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1221 fn bar() -> u32 { 0 }
1222 fn foo() { let a = id!([0u32, bar($0)] ); }
1234 fn test_hover_through_literal_string_in_macro() {
1237 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1239 let mastered_for_itunes = "";
1240 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1253 fn test_hover_through_assert_macro() {
1256 #[rustc_builtin_macro]
1257 macro_rules! assert {}
1259 fn bar() -> bool { true }
1279 fn test_hover_through_literal_string_in_builtin_macro() {
1280 check_hover_no_result(
1282 #[rustc_builtin_macro]
1283 macro_rules! format {}
1286 format!("hel$0lo {}", 0);
1293 fn test_hover_non_ascii_space_doc() {
1296 /// <- `\u{3000}` here
1299 fn bar() { fo$0o(); }
1320 fn test_hover_function_show_qualifiers() {
1322 r#"async fn foo$0() {}"#,
1336 r#"pub const unsafe fn foo$0() {}"#,
1345 pub const unsafe fn foo()
1350 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1359 pub(crate) async unsafe extern "C" fn foo()
1366 fn test_hover_trait_show_qualifiers() {
1368 r"unsafe trait foo$0() {}",
1385 fn test_hover_extern_crate() {
1388 //- /main.rs crate:main deps:std
1390 //- /std/lib.rs crate:std
1391 //! Standard library for this test
1398 Standard library for this test
1406 //- /main.rs crate:main deps:std
1407 extern crate std as ab$0c;
1408 //- /std/lib.rs crate:std
1409 //! Standard library for this test
1416 Standard library for this test
1425 fn test_hover_mod_with_same_name_as_function() {
1428 use self::m$0y::Bar;
1429 mod my { pub struct Bar; }
1448 fn test_hover_struct_doc_comment() {
1454 fn foo() { let bar = Ba$0r; }
1475 fn test_hover_struct_doc_attr() {
1481 fn foo() { let bar = Ba$0r; }
1502 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1506 #[doc = "bar docs 1"]
1507 #[doc = "bar docs 2"]
1510 fn foo() { let bar = Ba$0r; }
1533 fn test_hover_path_link() {
1537 /// [Foo](struct.Foo.html)
1553 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1559 fn test_hover_path_link_no_strip() {
1563 /// [struct Foo](struct.Foo.html)
1579 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1584 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1586 fn test_hover_path_link_field() {
1591 /// [Foo](struct.Foo.html)
1608 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1614 fn test_hover_intra_link() {
1636 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1642 fn test_hover_intra_link_html_root_url() {
1645 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1666 [Foo](https://example.com/test/foo/struct.Foo.html)
1672 fn test_hover_intra_link_shortlink() {
1692 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1698 fn test_hover_intra_link_shortlink_code() {
1718 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1724 fn test_hover_intra_link_namespaced() {
1745 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1751 fn test_hover_intra_link_shortlink_namspaced_code() {
1771 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1777 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1797 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1803 fn test_hover_intra_link_reference() {
1825 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1831 fn test_hover_external_url() {
1835 /// [external](https://www.google.com)
1851 [external](https://www.google.com)
1856 // Check that we don't rewrite links which we can't identify
1858 fn test_hover_unknown_target() {
1884 fn test_doc_links_enum_variant() {
1905 [E](https://docs.rs/test/*/test/enum.E.html)
1911 fn test_doc_links_field() {
1932 [`S`](https://docs.rs/test/*/test/struct.S.html)
1938 fn test_hover_no_links() {
1939 check_hover_no_links(
1942 /// case 1. bare URL: https://www.example.com/
1943 /// case 2. inline URL with title: [example](https://www.example.com/)
1944 /// case 3. code reference: [`Result`]
1945 /// case 4. code reference but miss footnote: [`String`]
1946 /// case 5. autolink: <http://www.example.com/>
1947 /// case 6. email address: <test@example.com>
1948 /// case 7. reference: [example][example]
1949 /// case 8. collapsed link: [example][]
1950 /// case 9. shortcut link: [example]
1951 /// case 10. inline without URL: [example]()
1952 /// case 11. reference: [foo][foo]
1953 /// case 12. reference: [foo][bar]
1954 /// case 13. collapsed link: [foo][]
1955 /// case 14. shortcut link: [foo]
1956 /// case 15. inline without URL: [foo]()
1957 /// case 16. just escaped text: \[foo]
1958 /// case 17. inline link: [Foo](foo::Foo)
1960 /// [`Result`]: ../../std/result/enum.Result.html
1961 /// [^example]: https://www.example.com/
1978 case 1. bare URL: https://www.example.com/
1979 case 2. inline URL with title: [example](https://www.example.com/)
1980 case 3. code reference: `Result`
1981 case 4. code reference but miss footnote: `String`
1982 case 5. autolink: http://www.example.com/
1983 case 6. email address: test@example.com
1984 case 7. reference: example
1985 case 8. collapsed link: example
1986 case 9. shortcut link: example
1987 case 10. inline without URL: example
1988 case 11. reference: foo
1989 case 12. reference: foo
1990 case 13. collapsed link: foo
1991 case 14. shortcut link: foo
1992 case 15. inline without URL: foo
1993 case 16. just escaped text: \[foo]
1994 case 17. inline link: Foo
1996 [^example]: https://www.example.com/
2002 fn test_hover_macro_generated_struct_fn_doc_comment() {
2003 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2019 fn foo() { let bar = Bar; bar.fo$0o(); }
2040 fn test_hover_macro_generated_struct_fn_doc_attr() {
2041 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2049 #[doc = "Do the foo"]
2057 fn foo() { let bar = Bar; bar.fo$0o(); }
2078 fn test_hover_trait_has_impl_action() {
2080 r#"trait foo$0() {}"#,
2097 fn test_hover_struct_has_impl_action() {
2099 r"struct foo$0() {}",
2116 fn test_hover_union_has_impl_action() {
2118 r#"union foo$0() {}"#,
2135 fn test_hover_enum_has_impl_action() {
2137 r"enum foo$0() { A, B }",
2154 fn test_hover_self_has_impl_action() {
2156 r#"struct foo where Self$0:;"#,
2173 fn test_hover_test_has_action() {
2183 nav: NavigationTarget {
2188 focus_range: 11..19,
2209 fn test_hover_test_mod_has_action() {
2221 nav: NavigationTarget {
2242 fn test_hover_struct_has_goto_type_action() {
2247 fn main() { let s$0t = S{ f1:0 }; }
2254 mod_path: "test::S",
2255 nav: NavigationTarget {
2263 description: "struct S",
2274 fn test_hover_generic_struct_has_goto_type_actions() {
2278 struct S<T>{ f1: T }
2280 fn main() { let s$0t = S{ f1:Arg(0) }; }
2287 mod_path: "test::S",
2288 nav: NavigationTarget {
2293 focus_range: 24..25,
2296 description: "struct S",
2300 mod_path: "test::Arg",
2301 nav: NavigationTarget {
2309 description: "struct Arg",
2320 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2324 struct S<T>{ f1: T }
2326 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2333 mod_path: "test::S",
2334 nav: NavigationTarget {
2339 focus_range: 24..25,
2342 description: "struct S",
2346 mod_path: "test::Arg",
2347 nav: NavigationTarget {
2355 description: "struct Arg",
2366 fn test_hover_tuple_has_goto_type_actions() {
2375 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2382 mod_path: "test::A",
2383 nav: NavigationTarget {
2391 description: "struct A",
2395 mod_path: "test::B",
2396 nav: NavigationTarget {
2401 focus_range: 22..23,
2404 description: "struct B",
2408 mod_path: "test::M::C",
2409 nav: NavigationTarget {
2414 focus_range: 53..54,
2417 description: "pub struct C",
2428 fn test_hover_return_impl_trait_has_goto_type_action() {
2432 fn foo() -> impl Foo {}
2434 fn main() { let s$0t = foo(); }
2441 mod_path: "test::Foo",
2442 nav: NavigationTarget {
2450 description: "trait Foo",
2461 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2466 fn foo() -> impl Foo<S> {}
2468 fn main() { let s$0t = foo(); }
2475 mod_path: "test::Foo",
2476 nav: NavigationTarget {
2484 description: "trait Foo",
2488 mod_path: "test::S",
2489 nav: NavigationTarget {
2494 focus_range: 23..24,
2497 description: "struct S",
2508 fn test_hover_return_impl_traits_has_goto_type_action() {
2513 fn foo() -> impl Foo + Bar {}
2515 fn main() { let s$0t = foo(); }
2522 mod_path: "test::Foo",
2523 nav: NavigationTarget {
2531 description: "trait Foo",
2535 mod_path: "test::Bar",
2536 nav: NavigationTarget {
2541 focus_range: 19..22,
2544 description: "trait Bar",
2555 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2563 fn foo() -> impl Foo<S1> + Bar<S2> {}
2565 fn main() { let s$0t = foo(); }
2572 mod_path: "test::Foo",
2573 nav: NavigationTarget {
2581 description: "trait Foo",
2585 mod_path: "test::Bar",
2586 nav: NavigationTarget {
2591 focus_range: 22..25,
2594 description: "trait Bar",
2598 mod_path: "test::S1",
2599 nav: NavigationTarget {
2604 focus_range: 39..41,
2607 description: "struct S1",
2611 mod_path: "test::S2",
2612 nav: NavigationTarget {
2617 focus_range: 52..54,
2620 description: "struct S2",
2631 fn test_hover_arg_impl_trait_has_goto_type_action() {
2635 fn foo(ar$0g: &impl Foo) {}
2642 mod_path: "test::Foo",
2643 nav: NavigationTarget {
2651 description: "trait Foo",
2662 fn test_hover_arg_impl_traits_has_goto_type_action() {
2669 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2676 mod_path: "test::Foo",
2677 nav: NavigationTarget {
2685 description: "trait Foo",
2689 mod_path: "test::Bar",
2690 nav: NavigationTarget {
2695 focus_range: 19..22,
2698 description: "trait Bar",
2702 mod_path: "test::S",
2703 nav: NavigationTarget {
2708 focus_range: 36..37,
2711 description: "struct S",
2722 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2727 let fo$0o = async { S };
2730 #[prelude_import] use future::*;
2732 #[lang = "future_trait"]
2733 pub trait Future { type Output; }
2741 mod_path: "test::future::Future",
2742 nav: NavigationTarget {
2746 full_range: 101..163,
2747 focus_range: 140..146,
2750 description: "pub trait Future",
2754 mod_path: "test::S",
2755 nav: NavigationTarget {
2763 description: "struct S",
2774 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2779 fn foo(ar$0g: &impl Foo<S>) {}
2786 mod_path: "test::Foo",
2787 nav: NavigationTarget {
2795 description: "trait Foo",
2799 mod_path: "test::S",
2800 nav: NavigationTarget {
2805 focus_range: 23..24,
2808 description: "struct S",
2819 fn test_hover_dyn_return_has_goto_type_action() {
2827 fn foo() -> B<dyn Foo> {}
2829 fn main() { let s$0t = foo(); }
2836 mod_path: "test::B",
2837 nav: NavigationTarget {
2842 focus_range: 49..50,
2845 description: "struct B",
2849 mod_path: "test::Foo",
2850 nav: NavigationTarget {
2858 description: "trait Foo",
2869 fn test_hover_dyn_arg_has_goto_type_action() {
2873 fn foo(ar$0g: &dyn Foo) {}
2880 mod_path: "test::Foo",
2881 nav: NavigationTarget {
2889 description: "trait Foo",
2900 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2905 fn foo(ar$0g: &dyn Foo<S>) {}
2912 mod_path: "test::Foo",
2913 nav: NavigationTarget {
2921 description: "trait Foo",
2925 mod_path: "test::S",
2926 nav: NavigationTarget {
2931 focus_range: 23..24,
2934 description: "struct S",
2945 fn test_hover_goto_type_action_links_order() {
2948 trait ImplTrait<T> {}
2949 trait DynTrait<T> {}
2953 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2960 mod_path: "test::ImplTrait",
2961 nav: NavigationTarget {
2969 description: "trait ImplTrait",
2973 mod_path: "test::B",
2974 nav: NavigationTarget {
2979 focus_range: 50..51,
2982 description: "struct B",
2986 mod_path: "test::DynTrait",
2987 nav: NavigationTarget {
2992 focus_range: 28..36,
2995 description: "trait DynTrait",
2999 mod_path: "test::S",
3000 nav: NavigationTarget {
3005 focus_range: 65..66,
3008 description: "struct S",
3019 fn test_hover_associated_type_has_goto_type_action() {
3024 fn get(self) -> Self::Item {}
3030 impl Foo for S { type Item = Bar; }
3032 fn test() -> impl Foo { S {} }
3034 fn main() { let s$0t = test().get(); }
3041 mod_path: "test::Foo",
3042 nav: NavigationTarget {
3050 description: "trait Foo",
3061 fn test_hover_const_param_has_goto_type_action() {
3065 struct Foo<const BAR: Bar>;
3067 impl<const BAR: Bar> Foo<BAR$0> {}
3074 mod_path: "test::Bar",
3075 nav: NavigationTarget {
3083 description: "struct Bar",
3094 fn test_hover_type_param_has_goto_type_action() {
3099 fn foo<T: Foo>(t: T$0){}
3106 mod_path: "test::Foo",
3107 nav: NavigationTarget {
3115 description: "trait Foo",
3126 fn test_hover_self_has_go_to_type() {
3139 mod_path: "test::Foo",
3140 nav: NavigationTarget {
3148 description: "struct Foo",
3159 fn hover_displays_normalized_crate_names() {
3162 //- /lib.rs crate:name-with-dashes
3164 pub struct Thing { x: u32 }
3167 pub fn new() -> Thing { Thing { x: 0 } }
3171 //- /main.rs crate:main deps:name-with-dashes
3172 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3178 name_with_dashes::wrapper::Thing
3182 pub fn new() -> Thing
3189 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3212 fn hover_self_param_shows_type() {
3231 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3237 fn bar(sel$0f: Arc<Foo>) {}
3251 fn hover_doc_outer_inner() {
3258 /// This comment belongs to the function
3282 fn hover_doc_outer_inner_attribue() {
3285 #[doc = "Be quick;"]
3287 #![doc = "time is mana"]
3289 #[doc = "This comment belongs to the function"]
3313 fn hover_comments_dont_highlight_parent() {
3314 check_hover_no_result(
3342 fn hover_lifetime() {
3344 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3356 fn hover_type_param() {
3363 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3369 T: Copy + Clone + Sized
3386 // lifetimes aren't being substituted yet
3390 impl<T: 'static> Foo<T$0> {}
3403 fn hover_const_param() {
3406 struct Foo<const LEN: usize>;
3407 impl<const LEN: usize> Foo<LEN$0> {}