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
137 let node = token.ancestors().find(|n| {
138 ast::Expr::can_cast(n.kind())
139 || ast::Pat::can_cast(n.kind())
140 || ast::SelfParam::can_cast(n.kind())
143 let ty = match_ast! {
145 ast::Expr(it) => sema.type_of_expr(&it)?,
146 ast::Pat(it) => sema.type_of_pat(&it)?,
147 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
148 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
149 // (e.g expanding a builtin macro). So we give up here.
150 ast::MacroCall(_it) => return None,
155 res.markup = if markdown {
156 Markup::fenced_block(&ty.display(db))
158 ty.display(db).to_string().into()
160 let range = sema.original_range(&node).range;
161 Some(RangeInfo::new(range, res))
164 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
165 fn to_action(nav_target: NavigationTarget) -> HoverAction {
166 HoverAction::Implementation(FilePosition {
167 file_id: nav_target.file_id,
168 offset: nav_target.focus_or_full_range().start(),
172 let adt = match def {
173 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
174 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
175 Definition::SelfType(it) => it.target_ty(db).as_adt(),
178 adt.try_to_nav(db).map(to_action)
182 sema: &Semantics<RootDatabase>,
185 ) -> Option<HoverAction> {
187 Definition::ModuleDef(it) => match it {
188 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
189 ModuleSource::Module(it) => {
190 runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it))
194 ModuleDef::Function(func) => {
195 let src = func.source(sema.db)?;
196 if src.file_id != file_id.into() {
197 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
198 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
202 runnable_fn(&sema, func).map(HoverAction::Runnable)
210 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
211 let mut targets: Vec<ModuleDef> = Vec::new();
212 let mut push_new_def = |item: ModuleDef| {
213 if !targets.contains(&item) {
218 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
219 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
222 Definition::Local(it) => it.ty(db),
223 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
228 if let Some(adt) = t.as_adt() {
229 push_new_def(adt.into());
230 } else if let Some(trait_) = t.as_dyn_trait() {
231 push_new_def(trait_.into());
232 } else if let Some(traits) = t.as_impl_traits(db) {
233 traits.into_iter().for_each(|it| push_new_def(it.into()));
234 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
235 push_new_def(trait_.into());
240 let targets = targets
243 Some(HoverGotoTypeData {
244 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
245 nav: it.try_to_nav(db)?,
250 Some(HoverAction::GoToType(targets))
254 docs: Option<String>,
255 desc: Option<String>,
256 mod_path: Option<String>,
257 ) -> Option<Markup> {
260 let mut buf = String::new();
262 if let Some(mod_path) = mod_path {
263 if !mod_path.is_empty() {
264 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
267 format_to!(buf, "```rust\n{}\n```", desc);
269 if let Some(doc) = docs {
270 format_to!(buf, "\n___\n\n{}", doc);
274 None => docs.map(Markup::from),
278 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
280 Definition::Field(f) => Some(f.parent_def(db).name(db)),
281 Definition::Local(l) => l.parent(db).name(db),
282 Definition::ModuleDef(md) => match md {
283 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
284 AssocItemContainer::Trait(t) => Some(t.name(db)),
285 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
287 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
292 .map(|name| name.to_string())
295 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
297 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
298 let module_path = module
302 .flat_map(|it| it.name(db).map(|name| name.to_string()));
303 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
306 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
307 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
310 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
311 let mod_path = definition_mod_path(db, &def);
313 Definition::Macro(it) => {
314 let label = macro_label(&it.source(db)?.value);
315 from_def_source_labeled(db, it, Some(label), mod_path)
317 Definition::Field(def) => {
318 let src = def.source(db)?.value;
319 if let FieldSource::Named(it) = src {
320 from_def_source_labeled(db, def, it.short_label(), mod_path)
325 Definition::ModuleDef(it) => match it {
326 ModuleDef::Module(it) => from_def_source_labeled(
329 match it.definition_source(db).value {
330 ModuleSource::Module(it) => it.short_label(),
331 ModuleSource::SourceFile(it) => it.short_label(),
335 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
336 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
337 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
338 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
339 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
340 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
341 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
342 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
343 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
344 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
346 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
347 Definition::SelfType(impl_def) => {
348 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
349 Adt::Struct(it) => from_def_source(db, it, mod_path),
350 Adt::Union(it) => from_def_source(db, it, mod_path),
351 Adt::Enum(it) => from_def_source(db, it, mod_path),
354 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
355 Definition::GenericParam(it) => match it {
356 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
357 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
358 GenericParam::ConstParam(it) => from_def_source(db, it, None),
362 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
364 D: HasSource<Ast = A> + HasAttrs + Copy,
367 let short_label = def.source(db)?.value.short_label();
368 from_def_source_labeled(db, def, short_label, mod_path)
371 fn from_def_source_labeled<D>(
374 short_label: Option<String>,
375 mod_path: Option<String>,
380 let docs = def.attrs(db).docs().map(Into::into);
381 hover_markup(docs, short_label, mod_path)
385 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
386 return tokens.max_by_key(priority);
387 fn priority(n: &SyntaxToken) -> usize {
389 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
390 T!['('] | T![')'] => 2,
391 kind if kind.is_trivia() => 0,
399 use expect_test::{expect, Expect};
400 use ide_db::base_db::FileLoader;
406 fn check_hover_no_result(ra_fixture: &str) {
407 let (analysis, position) = fixture::position(ra_fixture);
408 assert!(analysis.hover(position, true, true).unwrap().is_none());
411 fn check(ra_fixture: &str, expect: Expect) {
412 let (analysis, position) = fixture::position(ra_fixture);
413 let hover = analysis.hover(position, true, true).unwrap().unwrap();
415 let content = analysis.db.file_text(position.file_id);
416 let hovered_element = &content[hover.range];
418 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
419 expect.assert_eq(&actual)
422 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
423 let (analysis, position) = fixture::position(ra_fixture);
424 let hover = analysis.hover(position, false, true).unwrap().unwrap();
426 let content = analysis.db.file_text(position.file_id);
427 let hovered_element = &content[hover.range];
429 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
430 expect.assert_eq(&actual)
433 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
434 let (analysis, position) = fixture::position(ra_fixture);
435 let hover = analysis.hover(position, true, false).unwrap().unwrap();
437 let content = analysis.db.file_text(position.file_id);
438 let hovered_element = &content[hover.range];
440 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
441 expect.assert_eq(&actual)
444 fn check_actions(ra_fixture: &str, expect: Expect) {
445 let (analysis, position) = fixture::position(ra_fixture);
446 let hover = analysis.hover(position, true, true).unwrap().unwrap();
447 expect.assert_debug_eq(&hover.info.actions)
451 fn hover_shows_type_of_an_expression() {
454 pub fn foo() -> u32 { 1 }
457 let foo_test = foo()$0;
470 fn hover_remove_markdown_if_configured() {
471 check_hover_no_markdown(
473 pub fn foo() -> u32 { 1 }
476 let foo_test = foo()$0;
487 fn hover_shows_long_type_of_an_expression() {
490 struct Scan<A, B, C> { a: A, b: B, c: C }
491 struct Iter<I> { inner: I }
492 enum Option<T> { Some(T), None }
494 struct OtherStruct<T> { i: T }
496 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
497 Iter { inner: Scan { a, b, c } }
502 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
503 Option::Some(*memo + value)
506 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
513 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
520 fn hover_shows_fn_signature() {
521 // Single file with result
524 pub fn foo() -> u32 { 1 }
526 fn main() { let foo_test = fo$0o(); }
541 // Multiple candidates but results are ambiguous.
545 pub fn foo() -> u32 { 1 }
548 pub fn foo() -> &str { "" }
551 pub fn foo(a: u32, b: u32) {}
558 fn main() { let foo_test = fo$0o(); }
570 fn hover_shows_fn_signature_with_type_params() {
573 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
575 fn main() { let foo_test = fo$0o(); }
585 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
592 fn hover_shows_fn_signature_on_fn_name() {
595 pub fn foo$0(a: u32, b: u32) -> u32 {}
607 pub fn foo(a: u32, b: u32) -> u32
614 fn hover_shows_fn_doc() {
619 /// # use std::path::Path;
621 /// foo(Path::new("hello, world!"))
623 pub fn foo$0(_: &Path) {}
643 # use std::path::Path;
645 foo(Path::new("hello, world!"))
652 fn hover_shows_fn_doc_attr_raw_string() {
655 #[doc = r#"Raw string doc attr"#]
656 pub fn foo$0(_: &Path) {}
679 fn hover_shows_struct_field_info() {
680 // Hovering over the field when instantiating
683 struct Foo { field_a: u32 }
686 let foo = Foo { field_a$0: 0, };
702 // Hovering over the field in the definition
705 struct Foo { field_a$0: u32 }
708 let foo = Foo { field_a: 0 };
726 fn hover_const_static() {
728 r#"const foo$0: u32 = 123;"#,
742 r#"static foo$0: u32 = 456;"#,
758 fn hover_default_generic_types() {
761 struct Test<K, T = u8> { k: K, t: T }
764 let zz$0 = Test { t: 23u8, k: 33 };
780 enum Option<T> { Some(T) }
783 fn main() { So$0me(12); }
800 enum Option<T> { Some(T) }
803 fn main() { let b$0ar = Some(12); }
816 fn hover_enum_variant() {
848 let s = Option::Som$0e(12);
870 fn hover_for_local_variable() {
872 r#"fn func(foo: i32) { fo$0o; }"#,
884 fn hover_for_local_variable_pat() {
886 r#"fn func(fo$0o: i32) {}"#,
898 fn hover_local_var_edge() {
900 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
912 fn hover_for_param_edge() {
914 r#"fn func($0foo: i32) {}"#,
926 fn hover_for_param_with_multiple_traits() {
934 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
939 impl Deref<Target = u8> + DerefMut<Target = u8>
946 fn test_hover_infer_associated_method_result() {
949 struct Thing { x: u32 }
952 fn new() -> Thing { Thing { x: 0 } }
955 fn main() { let foo_$0test = Thing::new(); }
968 fn test_hover_infer_associated_method_exact() {
972 struct Thing { x: u32 }
975 fn new() -> Thing { Thing { x: 0 } }
979 fn main() { let foo_test = wrapper::Thing::new$0(); }
996 fn test_hover_infer_associated_const_in_pattern() {
1027 fn test_hover_self() {
1030 struct Thing { x: u32 }
1032 fn new() -> Self { Self$0 { x: 0 } }
1049 struct Thing { x: u32 }
1051 fn new() -> Self$0 { Self { x: 0 } }
1070 pub fn new() -> Self$0 { Thing::A }
1089 pub fn thing(a: Self$0) {}
1107 fn test_hover_shadowing_pat() {
1128 fn test_hover_macro_invocation() {
1131 macro_rules! foo { () => {} }
1133 fn f() { fo$0o!(); }
1150 fn test_hover_tuple_field() {
1152 r#"struct TS(String, i32$0);"#,
1164 fn test_hover_through_macro() {
1167 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1170 fn bar() { fo$0o(); }
1188 fn test_hover_through_expr_in_macro() {
1191 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1192 fn foo(bar:u32) { let a = id!(ba$0r); }
1205 fn test_hover_through_expr_in_macro_recursive() {
1208 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1209 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1210 fn foo(bar:u32) { let a = id!(ba$0r); }
1223 fn test_hover_through_func_in_macro_recursive() {
1226 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1227 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1228 fn bar() -> u32 { 0 }
1229 fn foo() { let a = id!([0u32, bar($0)] ); }
1241 fn test_hover_through_literal_string_in_macro() {
1244 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1246 let mastered_for_itunes = "";
1247 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1260 fn test_hover_through_assert_macro() {
1263 #[rustc_builtin_macro]
1264 macro_rules! assert {}
1266 fn bar() -> bool { true }
1286 fn test_hover_through_literal_string_in_builtin_macro() {
1287 check_hover_no_result(
1289 #[rustc_builtin_macro]
1290 macro_rules! format {}
1293 format!("hel$0lo {}", 0);
1300 fn test_hover_non_ascii_space_doc() {
1303 /// <- `\u{3000}` here
1306 fn bar() { fo$0o(); }
1327 fn test_hover_function_show_qualifiers() {
1329 r#"async fn foo$0() {}"#,
1343 r#"pub const unsafe fn foo$0() {}"#,
1352 pub const unsafe fn foo()
1357 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1366 pub(crate) async unsafe extern "C" fn foo()
1373 fn test_hover_trait_show_qualifiers() {
1375 r"unsafe trait foo$0() {}",
1392 fn test_hover_extern_crate() {
1395 //- /main.rs crate:main deps:std
1397 //- /std/lib.rs crate:std
1398 //! Standard library for this test
1405 Standard library for this test
1413 //- /main.rs crate:main deps:std
1414 extern crate std as ab$0c;
1415 //- /std/lib.rs crate:std
1416 //! Standard library for this test
1423 Standard library for this test
1432 fn test_hover_mod_with_same_name_as_function() {
1435 use self::m$0y::Bar;
1436 mod my { pub struct Bar; }
1455 fn test_hover_struct_doc_comment() {
1461 fn foo() { let bar = Ba$0r; }
1482 fn test_hover_struct_doc_attr() {
1488 fn foo() { let bar = Ba$0r; }
1509 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1513 #[doc = "bar docs 1"]
1514 #[doc = "bar docs 2"]
1517 fn foo() { let bar = Ba$0r; }
1540 fn test_hover_path_link() {
1544 /// [Foo](struct.Foo.html)
1560 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1566 fn test_hover_path_link_no_strip() {
1570 /// [struct Foo](struct.Foo.html)
1586 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1591 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1593 fn test_hover_path_link_field() {
1598 /// [Foo](struct.Foo.html)
1615 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1621 fn test_hover_intra_link() {
1643 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1649 fn test_hover_intra_link_html_root_url() {
1652 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1673 [Foo](https://example.com/test/foo/struct.Foo.html)
1679 fn test_hover_intra_link_shortlink() {
1699 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1705 fn test_hover_intra_link_shortlink_code() {
1725 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1731 fn test_hover_intra_link_namespaced() {
1752 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1758 fn test_hover_intra_link_shortlink_namspaced_code() {
1778 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1784 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1804 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1810 fn test_hover_intra_link_reference() {
1832 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1838 fn test_hover_external_url() {
1842 /// [external](https://www.google.com)
1858 [external](https://www.google.com)
1863 // Check that we don't rewrite links which we can't identify
1865 fn test_hover_unknown_target() {
1891 fn test_doc_links_enum_variant() {
1912 [E](https://docs.rs/test/*/test/enum.E.html)
1918 fn test_doc_links_field() {
1939 [`S`](https://docs.rs/test/*/test/struct.S.html)
1945 fn test_hover_no_links() {
1946 check_hover_no_links(
1949 /// case 1. bare URL: https://www.example.com/
1950 /// case 2. inline URL with title: [example](https://www.example.com/)
1951 /// case 3. code reference: [`Result`]
1952 /// case 4. code reference but miss footnote: [`String`]
1953 /// case 5. autolink: <http://www.example.com/>
1954 /// case 6. email address: <test@example.com>
1955 /// case 7. reference: [example][example]
1956 /// case 8. collapsed link: [example][]
1957 /// case 9. shortcut link: [example]
1958 /// case 10. inline without URL: [example]()
1959 /// case 11. reference: [foo][foo]
1960 /// case 12. reference: [foo][bar]
1961 /// case 13. collapsed link: [foo][]
1962 /// case 14. shortcut link: [foo]
1963 /// case 15. inline without URL: [foo]()
1964 /// case 16. just escaped text: \[foo]
1965 /// case 17. inline link: [Foo](foo::Foo)
1967 /// [`Result`]: ../../std/result/enum.Result.html
1968 /// [^example]: https://www.example.com/
1985 case 1. bare URL: https://www.example.com/
1986 case 2. inline URL with title: [example](https://www.example.com/)
1987 case 3. code reference: `Result`
1988 case 4. code reference but miss footnote: `String`
1989 case 5. autolink: http://www.example.com/
1990 case 6. email address: test@example.com
1991 case 7. reference: example
1992 case 8. collapsed link: example
1993 case 9. shortcut link: example
1994 case 10. inline without URL: example
1995 case 11. reference: foo
1996 case 12. reference: foo
1997 case 13. collapsed link: foo
1998 case 14. shortcut link: foo
1999 case 15. inline without URL: foo
2000 case 16. just escaped text: \[foo]
2001 case 17. inline link: Foo
2003 [^example]: https://www.example.com/
2009 fn test_hover_macro_generated_struct_fn_doc_comment() {
2010 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2026 fn foo() { let bar = Bar; bar.fo$0o(); }
2047 fn test_hover_macro_generated_struct_fn_doc_attr() {
2048 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2056 #[doc = "Do the foo"]
2064 fn foo() { let bar = Bar; bar.fo$0o(); }
2085 fn test_hover_trait_has_impl_action() {
2087 r#"trait foo$0() {}"#,
2104 fn test_hover_struct_has_impl_action() {
2106 r"struct foo$0() {}",
2123 fn test_hover_union_has_impl_action() {
2125 r#"union foo$0() {}"#,
2142 fn test_hover_enum_has_impl_action() {
2144 r"enum foo$0() { A, B }",
2161 fn test_hover_self_has_impl_action() {
2163 r#"struct foo where Self$0:;"#,
2180 fn test_hover_test_has_action() {
2190 nav: NavigationTarget {
2195 focus_range: 11..19,
2216 fn test_hover_test_mod_has_action() {
2228 nav: NavigationTarget {
2249 fn test_hover_struct_has_goto_type_action() {
2254 fn main() { let s$0t = S{ f1:0 }; }
2261 mod_path: "test::S",
2262 nav: NavigationTarget {
2270 description: "struct S",
2281 fn test_hover_generic_struct_has_goto_type_actions() {
2285 struct S<T>{ f1: T }
2287 fn main() { let s$0t = S{ f1:Arg(0) }; }
2294 mod_path: "test::S",
2295 nav: NavigationTarget {
2300 focus_range: 24..25,
2303 description: "struct S",
2307 mod_path: "test::Arg",
2308 nav: NavigationTarget {
2316 description: "struct Arg",
2327 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2331 struct S<T>{ f1: T }
2333 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2340 mod_path: "test::S",
2341 nav: NavigationTarget {
2346 focus_range: 24..25,
2349 description: "struct S",
2353 mod_path: "test::Arg",
2354 nav: NavigationTarget {
2362 description: "struct Arg",
2373 fn test_hover_tuple_has_goto_type_actions() {
2382 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2389 mod_path: "test::A",
2390 nav: NavigationTarget {
2398 description: "struct A",
2402 mod_path: "test::B",
2403 nav: NavigationTarget {
2408 focus_range: 22..23,
2411 description: "struct B",
2415 mod_path: "test::M::C",
2416 nav: NavigationTarget {
2421 focus_range: 53..54,
2424 description: "pub struct C",
2435 fn test_hover_return_impl_trait_has_goto_type_action() {
2439 fn foo() -> impl Foo {}
2441 fn main() { let s$0t = foo(); }
2448 mod_path: "test::Foo",
2449 nav: NavigationTarget {
2457 description: "trait Foo",
2468 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2473 fn foo() -> impl Foo<S> {}
2475 fn main() { let s$0t = foo(); }
2482 mod_path: "test::Foo",
2483 nav: NavigationTarget {
2491 description: "trait Foo",
2495 mod_path: "test::S",
2496 nav: NavigationTarget {
2501 focus_range: 23..24,
2504 description: "struct S",
2515 fn test_hover_return_impl_traits_has_goto_type_action() {
2520 fn foo() -> impl Foo + Bar {}
2522 fn main() { let s$0t = foo(); }
2529 mod_path: "test::Foo",
2530 nav: NavigationTarget {
2538 description: "trait Foo",
2542 mod_path: "test::Bar",
2543 nav: NavigationTarget {
2548 focus_range: 19..22,
2551 description: "trait Bar",
2562 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2570 fn foo() -> impl Foo<S1> + Bar<S2> {}
2572 fn main() { let s$0t = foo(); }
2579 mod_path: "test::Foo",
2580 nav: NavigationTarget {
2588 description: "trait Foo",
2592 mod_path: "test::Bar",
2593 nav: NavigationTarget {
2598 focus_range: 22..25,
2601 description: "trait Bar",
2605 mod_path: "test::S1",
2606 nav: NavigationTarget {
2611 focus_range: 39..41,
2614 description: "struct S1",
2618 mod_path: "test::S2",
2619 nav: NavigationTarget {
2624 focus_range: 52..54,
2627 description: "struct S2",
2638 fn test_hover_arg_impl_trait_has_goto_type_action() {
2642 fn foo(ar$0g: &impl Foo) {}
2649 mod_path: "test::Foo",
2650 nav: NavigationTarget {
2658 description: "trait Foo",
2669 fn test_hover_arg_impl_traits_has_goto_type_action() {
2676 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2683 mod_path: "test::Foo",
2684 nav: NavigationTarget {
2692 description: "trait Foo",
2696 mod_path: "test::Bar",
2697 nav: NavigationTarget {
2702 focus_range: 19..22,
2705 description: "trait Bar",
2709 mod_path: "test::S",
2710 nav: NavigationTarget {
2715 focus_range: 36..37,
2718 description: "struct S",
2729 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2734 let fo$0o = async { S };
2737 #[prelude_import] use future::*;
2739 #[lang = "future_trait"]
2740 pub trait Future { type Output; }
2748 mod_path: "test::future::Future",
2749 nav: NavigationTarget {
2753 full_range: 101..163,
2754 focus_range: 140..146,
2757 description: "pub trait Future",
2761 mod_path: "test::S",
2762 nav: NavigationTarget {
2770 description: "struct S",
2781 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2786 fn foo(ar$0g: &impl Foo<S>) {}
2793 mod_path: "test::Foo",
2794 nav: NavigationTarget {
2802 description: "trait Foo",
2806 mod_path: "test::S",
2807 nav: NavigationTarget {
2812 focus_range: 23..24,
2815 description: "struct S",
2826 fn test_hover_dyn_return_has_goto_type_action() {
2834 fn foo() -> B<dyn Foo> {}
2836 fn main() { let s$0t = foo(); }
2843 mod_path: "test::B",
2844 nav: NavigationTarget {
2849 focus_range: 49..50,
2852 description: "struct B",
2856 mod_path: "test::Foo",
2857 nav: NavigationTarget {
2865 description: "trait Foo",
2876 fn test_hover_dyn_arg_has_goto_type_action() {
2880 fn foo(ar$0g: &dyn Foo) {}
2887 mod_path: "test::Foo",
2888 nav: NavigationTarget {
2896 description: "trait Foo",
2907 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2912 fn foo(ar$0g: &dyn Foo<S>) {}
2919 mod_path: "test::Foo",
2920 nav: NavigationTarget {
2928 description: "trait Foo",
2932 mod_path: "test::S",
2933 nav: NavigationTarget {
2938 focus_range: 23..24,
2941 description: "struct S",
2952 fn test_hover_goto_type_action_links_order() {
2955 trait ImplTrait<T> {}
2956 trait DynTrait<T> {}
2960 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2967 mod_path: "test::ImplTrait",
2968 nav: NavigationTarget {
2976 description: "trait ImplTrait",
2980 mod_path: "test::B",
2981 nav: NavigationTarget {
2986 focus_range: 50..51,
2989 description: "struct B",
2993 mod_path: "test::DynTrait",
2994 nav: NavigationTarget {
2999 focus_range: 28..36,
3002 description: "trait DynTrait",
3006 mod_path: "test::S",
3007 nav: NavigationTarget {
3012 focus_range: 65..66,
3015 description: "struct S",
3026 fn test_hover_associated_type_has_goto_type_action() {
3031 fn get(self) -> Self::Item {}
3037 impl Foo for S { type Item = Bar; }
3039 fn test() -> impl Foo { S {} }
3041 fn main() { let s$0t = test().get(); }
3048 mod_path: "test::Foo",
3049 nav: NavigationTarget {
3057 description: "trait Foo",
3068 fn test_hover_const_param_has_goto_type_action() {
3072 struct Foo<const BAR: Bar>;
3074 impl<const BAR: Bar> Foo<BAR$0> {}
3081 mod_path: "test::Bar",
3082 nav: NavigationTarget {
3090 description: "struct Bar",
3101 fn test_hover_type_param_has_goto_type_action() {
3106 fn foo<T: Foo>(t: T$0){}
3113 mod_path: "test::Foo",
3114 nav: NavigationTarget {
3122 description: "trait Foo",
3133 fn hover_displays_normalized_crate_names() {
3136 //- /lib.rs crate:name-with-dashes
3138 pub struct Thing { x: u32 }
3141 pub fn new() -> Thing { Thing { x: 0 } }
3145 //- /main.rs crate:main deps:name-with-dashes
3146 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3152 name_with_dashes::wrapper::Thing
3156 pub fn new() -> Thing
3163 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3186 fn hover_self_param_shows_type() {
3204 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3210 fn bar(sel$0f: Arc<Foo>) {}
3223 fn hover_doc_outer_inner() {
3230 /// This comment belongs to the function
3254 fn hover_doc_outer_inner_attribue() {
3257 #[doc = "Be quick;"]
3259 #![doc = "time is mana"]
3261 #[doc = "This comment belongs to the function"]
3285 fn hover_comments_dont_highlight_parent() {
3286 check_hover_no_result(
3314 fn hover_lifetime() {
3316 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3328 fn hover_type_param() {
3335 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3341 T: Copy + Clone + Sized
3358 // lifetimes aren't being substituted yet
3362 impl<T: 'static> Foo<T$0> {}
3375 fn hover_const_param() {
3378 struct Foo<const LEN: usize>;
3379 impl<const LEN: usize> Foo<LEN$0> {}