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, 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 Implementation(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)),
112 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
113 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
117 if let Some(definition) = definition {
118 if let Some(markup) = hover_for_definition(db, definition) {
119 let markup = markup.as_str();
120 let markup = if !markdown {
121 remove_markdown(markup)
122 } else if links_in_hover {
123 rewrite_links(db, markup, &definition)
127 res.markup = Markup::from(markup);
128 if let Some(action) = show_implementations_action(db, definition) {
129 res.actions.push(action);
132 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
133 res.actions.push(action);
136 if let Some(action) = goto_type_action(db, definition) {
137 res.actions.push(action);
140 let range = sema.original_range(&node).range;
141 return Some(RangeInfo::new(range, res));
145 if token.kind() == syntax::SyntaxKind::COMMENT {
146 // don't highlight the entire parent node on comment hover
150 let node = token.ancestors().find(|n| {
151 ast::Expr::can_cast(n.kind())
152 || ast::Pat::can_cast(n.kind())
153 || ast::SelfParam::can_cast(n.kind())
156 let ty = match_ast! {
158 ast::Expr(it) => sema.type_of_expr(&it)?,
159 ast::Pat(it) => sema.type_of_pat(&it)?,
160 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
161 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
162 // (e.g expanding a builtin macro). So we give up here.
163 ast::MacroCall(_it) => return None,
168 res.markup = if markdown {
169 Markup::fenced_block(&ty.display(db))
171 ty.display(db).to_string().into()
173 let range = sema.original_range(&node).range;
174 Some(RangeInfo::new(range, res))
177 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
178 fn to_action(nav_target: NavigationTarget) -> HoverAction {
179 HoverAction::Implementation(FilePosition {
180 file_id: nav_target.file_id,
181 offset: nav_target.focus_or_full_range().start(),
185 let adt = match def {
186 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
187 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
188 Definition::SelfType(it) => it.target_ty(db).as_adt(),
192 Adt::Struct(it) => it.try_to_nav(db),
193 Adt::Union(it) => it.try_to_nav(db),
194 Adt::Enum(it) => it.try_to_nav(db),
200 sema: &Semantics<RootDatabase>,
203 ) -> Option<HoverAction> {
205 Definition::ModuleDef(it) => match it {
206 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
207 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
208 .map(|it| HoverAction::Runnable(it)),
211 ModuleDef::Function(it) => {
213 let src = it.source(sema.db)?;
214 if src.file_id != file_id.into() {
215 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
216 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
221 runnable(&sema, src.value.syntax().clone(), file_id)
222 .map(|it| HoverAction::Runnable(it))
230 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
232 Definition::Local(it) => it.ty(db),
233 Definition::ConstParam(it) => it.ty(db),
236 let mut targets: Vec<ModuleDef> = Vec::new();
237 let mut push_new_def = |item: ModuleDef| {
238 if !targets.contains(&item) {
244 if let Some(adt) = t.as_adt() {
245 push_new_def(adt.into());
246 } else if let Some(trait_) = t.as_dyn_trait() {
247 push_new_def(trait_.into());
248 } else if let Some(traits) = t.as_impl_traits(db) {
249 traits.into_iter().for_each(|it| push_new_def(it.into()));
250 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
251 push_new_def(trait_.into());
255 let targets = targets
258 Some(HoverGotoTypeData {
259 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
260 nav: it.try_to_nav(db)?,
265 Some(HoverAction::GoToType(targets))
269 docs: Option<String>,
270 desc: Option<String>,
271 mod_path: Option<String>,
272 ) -> Option<Markup> {
275 let mut buf = String::new();
277 if let Some(mod_path) = mod_path {
278 if !mod_path.is_empty() {
279 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
282 format_to!(buf, "```rust\n{}\n```", desc);
284 if let Some(doc) = docs {
285 format_to!(buf, "\n___\n\n{}", doc);
289 None => docs.map(Markup::from),
293 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
295 Definition::Field(f) => Some(f.parent_def(db).name(db)),
296 Definition::Local(l) => l.parent(db).name(db),
297 Definition::ModuleDef(md) => match md {
298 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
299 AssocItemContainer::Trait(t) => Some(t.name(db)),
300 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
302 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
307 .map(|name| name.to_string())
310 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
312 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
313 let module_path = module
317 .flat_map(|it| it.name(db).map(|name| name.to_string()));
318 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
321 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
322 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
325 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
326 let mod_path = definition_mod_path(db, &def);
328 Definition::Macro(it) => {
329 let label = macro_label(&it.source(db)?.value);
330 from_def_source_labeled(db, it, Some(label), mod_path)
332 Definition::Field(def) => {
334 let src = def.source(db)?.value;
335 if let FieldSource::Named(it) = src {
336 from_def_source_labeled(db, def, it.short_label(), mod_path)
341 Definition::ModuleDef(it) => match it {
342 ModuleDef::Module(it) => from_def_source_labeled(
345 match it.definition_source(db).value {
346 ModuleSource::Module(it) => it.short_label(),
347 ModuleSource::SourceFile(it) => it.short_label(),
351 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
352 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
353 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
354 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
355 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
356 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
357 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
358 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
359 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
360 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
362 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
363 Definition::SelfType(impl_def) => {
364 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
365 Adt::Struct(it) => from_def_source(db, it, mod_path),
366 Adt::Union(it) => from_def_source(db, it, mod_path),
367 Adt::Enum(it) => from_def_source(db, it, mod_path),
370 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
371 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
372 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
373 Definition::ConstParam(it) => from_def_source(db, it, None),
376 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
378 D: HasSource<Ast = A> + HasAttrs + Copy,
382 let short_label = def.source(db)?.value.short_label();
383 from_def_source_labeled(db, def, short_label, mod_path)
386 fn from_def_source_labeled<D>(
389 short_label: Option<String>,
390 mod_path: Option<String>,
395 let docs = def.attrs(db).docs().map(Into::into);
396 hover_markup(docs, short_label, mod_path)
400 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
401 return tokens.max_by_key(priority);
402 fn priority(n: &SyntaxToken) -> usize {
404 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
405 T!['('] | T![')'] => 2,
406 kind if kind.is_trivia() => 0,
414 use expect_test::{expect, Expect};
415 use ide_db::base_db::FileLoader;
421 fn check_hover_no_result(ra_fixture: &str) {
422 let (analysis, position) = fixture::position(ra_fixture);
423 assert!(analysis.hover(position, true, true).unwrap().is_none());
426 fn check(ra_fixture: &str, expect: Expect) {
427 let (analysis, position) = fixture::position(ra_fixture);
428 let hover = analysis.hover(position, true, true).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_hover_no_links(ra_fixture: &str, expect: Expect) {
438 let (analysis, position) = fixture::position(ra_fixture);
439 let hover = analysis.hover(position, false, true).unwrap().unwrap();
441 let content = analysis.db.file_text(position.file_id);
442 let hovered_element = &content[hover.range];
444 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
445 expect.assert_eq(&actual)
448 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
449 let (analysis, position) = fixture::position(ra_fixture);
450 let hover = analysis.hover(position, true, false).unwrap().unwrap();
452 let content = analysis.db.file_text(position.file_id);
453 let hovered_element = &content[hover.range];
455 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
456 expect.assert_eq(&actual)
459 fn check_actions(ra_fixture: &str, expect: Expect) {
460 let (analysis, position) = fixture::position(ra_fixture);
461 let hover = analysis.hover(position, true, true).unwrap().unwrap();
462 expect.assert_debug_eq(&hover.info.actions)
466 fn hover_shows_type_of_an_expression() {
469 pub fn foo() -> u32 { 1 }
472 let foo_test = foo()<|>;
485 fn hover_remove_markdown_if_configured() {
486 check_hover_no_markdown(
488 pub fn foo() -> u32 { 1 }
491 let foo_test = foo()<|>;
502 fn hover_shows_long_type_of_an_expression() {
505 struct Scan<A, B, C> { a: A, b: B, c: C }
506 struct Iter<I> { inner: I }
507 enum Option<T> { Some(T), None }
509 struct OtherStruct<T> { i: T }
511 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
512 Iter { inner: Scan { a, b, c } }
517 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
518 Option::Some(*memo + value)
521 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
528 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
535 fn hover_shows_fn_signature() {
536 // Single file with result
539 pub fn foo() -> u32 { 1 }
541 fn main() { let foo_test = fo<|>o(); }
556 // Multiple candidates but results are ambiguous.
560 pub fn foo() -> u32 { 1 }
563 pub fn foo() -> &str { "" }
566 pub fn foo(a: u32, b: u32) {}
573 fn main() { let foo_test = fo<|>o(); }
585 fn hover_shows_fn_signature_with_type_params() {
588 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
590 fn main() { let foo_test = fo<|>o(); }
600 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
607 fn hover_shows_fn_signature_on_fn_name() {
610 pub fn foo<|>(a: u32, b: u32) -> u32 {}
622 pub fn foo(a: u32, b: u32) -> u32
629 fn hover_shows_fn_doc() {
634 /// # use std::path::Path;
636 /// foo(Path::new("hello, world!"))
638 pub fn foo<|>(_: &Path) {}
658 # use std::path::Path;
660 foo(Path::new("hello, world!"))
667 fn hover_shows_fn_doc_attr_raw_string() {
670 #[doc = r#"Raw string doc attr"#]
671 pub fn foo<|>(_: &Path) {}
694 fn hover_shows_struct_field_info() {
695 // Hovering over the field when instantiating
698 struct Foo { field_a: u32 }
701 let foo = Foo { field_a<|>: 0, };
717 // Hovering over the field in the definition
720 struct Foo { field_a<|>: u32 }
723 let foo = Foo { field_a: 0 };
741 fn hover_const_static() {
743 r#"const foo<|>: u32 = 123;"#,
757 r#"static foo<|>: u32 = 456;"#,
773 fn hover_default_generic_types() {
776 struct Test<K, T = u8> { k: K, t: T }
779 let zz<|> = Test { t: 23u8, k: 33 };
795 enum Option<T> { Some(T) }
798 fn main() { So<|>me(12); }
815 enum Option<T> { Some(T) }
818 fn main() { let b<|>ar = Some(12); }
831 fn hover_enum_variant() {
863 let s = Option::Som<|>e(12);
885 fn hover_for_local_variable() {
887 r#"fn func(foo: i32) { fo<|>o; }"#,
899 fn hover_for_local_variable_pat() {
901 r#"fn func(fo<|>o: i32) {}"#,
913 fn hover_local_var_edge() {
915 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
927 fn hover_for_param_edge() {
929 r#"fn func(<|>foo: i32) {}"#,
941 fn hover_for_param_with_multiple_traits() {
949 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
954 impl Deref<Target = u8> + DerefMut<Target = u8>
961 fn test_hover_infer_associated_method_result() {
964 struct Thing { x: u32 }
967 fn new() -> Thing { Thing { x: 0 } }
970 fn main() { let foo_<|>test = Thing::new(); }
983 fn test_hover_infer_associated_method_exact() {
987 struct Thing { x: u32 }
990 fn new() -> Thing { Thing { x: 0 } }
994 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1000 test::wrapper::Thing
1011 fn test_hover_infer_associated_const_in_pattern() {
1042 fn test_hover_self() {
1045 struct Thing { x: u32 }
1047 fn new() -> Self { Self<|> { x: 0 } }
1064 struct Thing { x: u32 }
1066 fn new() -> Self<|> { Self { x: 0 } }
1085 pub fn new() -> Self<|> { Thing::A }
1104 pub fn thing(a: Self<|>) {}
1122 fn test_hover_shadowing_pat() {
1143 fn test_hover_macro_invocation() {
1146 macro_rules! foo { () => {} }
1148 fn f() { fo<|>o!(); }
1165 fn test_hover_tuple_field() {
1167 r#"struct TS(String, i32<|>);"#,
1179 fn test_hover_through_macro() {
1182 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1185 fn bar() { fo<|>o(); }
1203 fn test_hover_through_expr_in_macro() {
1206 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1207 fn foo(bar:u32) { let a = id!(ba<|>r); }
1220 fn test_hover_through_expr_in_macro_recursive() {
1223 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1224 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1225 fn foo(bar:u32) { let a = id!(ba<|>r); }
1238 fn test_hover_through_func_in_macro_recursive() {
1241 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1242 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1243 fn bar() -> u32 { 0 }
1244 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1256 fn test_hover_through_literal_string_in_macro() {
1259 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1261 let mastered_for_itunes = "";
1262 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1275 fn test_hover_through_assert_macro() {
1278 #[rustc_builtin_macro]
1279 macro_rules! assert {}
1281 fn bar() -> bool { true }
1301 fn test_hover_through_literal_string_in_builtin_macro() {
1302 check_hover_no_result(
1304 #[rustc_builtin_macro]
1305 macro_rules! format {}
1308 format!("hel<|>lo {}", 0);
1315 fn test_hover_non_ascii_space_doc() {
1318 /// <- `\u{3000}` here
1321 fn bar() { fo<|>o(); }
1342 fn test_hover_function_show_qualifiers() {
1344 r#"async fn foo<|>() {}"#,
1358 r#"pub const unsafe fn foo<|>() {}"#,
1367 pub const unsafe fn foo()
1372 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1381 pub(crate) async unsafe extern "C" fn foo()
1388 fn test_hover_trait_show_qualifiers() {
1390 r"unsafe trait foo<|>() {}",
1407 fn test_hover_extern_crate() {
1410 //- /main.rs crate:main deps:std
1411 extern crate st<|>d;
1412 //- /std/lib.rs crate:std
1413 //! Standard library for this test
1420 Standard library for this test
1428 //- /main.rs crate:main deps:std
1429 extern crate std as ab<|>c;
1430 //- /std/lib.rs crate:std
1431 //! Standard library for this test
1438 Standard library for this test
1447 fn test_hover_mod_with_same_name_as_function() {
1450 use self::m<|>y::Bar;
1451 mod my { pub struct Bar; }
1470 fn test_hover_struct_doc_comment() {
1476 fn foo() { let bar = Ba<|>r; }
1497 fn test_hover_struct_doc_attr() {
1503 fn foo() { let bar = Ba<|>r; }
1524 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1528 #[doc = "bar docs 1"]
1529 #[doc = "bar docs 2"]
1532 fn foo() { let bar = Ba<|>r; }
1555 fn test_hover_path_link() {
1559 /// [Foo](struct.Foo.html)
1575 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1581 fn test_hover_path_link_no_strip() {
1585 /// [struct Foo](struct.Foo.html)
1601 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1606 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1608 fn test_hover_path_link_field() {
1613 /// [Foo](struct.Foo.html)
1630 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1636 fn test_hover_intra_link() {
1658 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1664 fn test_hover_intra_link_html_root_url() {
1667 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1688 [Foo](https://example.com/test/foo/struct.Foo.html)
1694 fn test_hover_intra_link_shortlink() {
1714 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1720 fn test_hover_intra_link_shortlink_code() {
1740 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1746 fn test_hover_intra_link_namespaced() {
1767 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1773 fn test_hover_intra_link_shortlink_namspaced_code() {
1793 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1799 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1819 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1825 fn test_hover_intra_link_reference() {
1847 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1853 fn test_hover_external_url() {
1857 /// [external](https://www.google.com)
1873 [external](https://www.google.com)
1878 // Check that we don't rewrite links which we can't identify
1880 fn test_hover_unknown_target() {
1906 fn test_doc_links_enum_variant() {
1927 [E](https://docs.rs/test/*/test/enum.E.html)
1933 fn test_doc_links_field() {
1954 [`S`](https://docs.rs/test/*/test/struct.S.html)
1960 fn test_hover_no_links() {
1961 check_hover_no_links(
1964 /// case 1. bare URL: https://www.example.com/
1965 /// case 2. inline URL with title: [example](https://www.example.com/)
1966 /// case 3. code refrence: [`Result`]
1967 /// case 4. code refrence but miss footnote: [`String`]
1968 /// case 5. autolink: <http://www.example.com/>
1969 /// case 6. email address: <test@example.com>
1970 /// case 7. refrence: [example][example]
1971 /// case 8. collapsed link: [example][]
1972 /// case 9. shortcut link: [example]
1973 /// case 10. inline without URL: [example]()
1974 /// case 11. refrence: [foo][foo]
1975 /// case 12. refrence: [foo][bar]
1976 /// case 13. collapsed link: [foo][]
1977 /// case 14. shortcut link: [foo]
1978 /// case 15. inline without URL: [foo]()
1979 /// case 16. just escaped text: \[foo]
1980 /// case 17. inline link: [Foo](foo::Foo)
1982 /// [`Result`]: ../../std/result/enum.Result.html
1983 /// [^example]: https://www.example.com/
2000 case 1. bare URL: https://www.example.com/
2001 case 2. inline URL with title: [example](https://www.example.com/)
2002 case 3. code refrence: `Result`
2003 case 4. code refrence but miss footnote: `String`
2004 case 5. autolink: http://www.example.com/
2005 case 6. email address: test@example.com
2006 case 7. refrence: example
2007 case 8. collapsed link: example
2008 case 9. shortcut link: example
2009 case 10. inline without URL: example
2010 case 11. refrence: foo
2011 case 12. refrence: foo
2012 case 13. collapsed link: foo
2013 case 14. shortcut link: foo
2014 case 15. inline without URL: foo
2015 case 16. just escaped text: \[foo]
2016 case 17. inline link: Foo
2018 [^example]: https://www.example.com/
2024 fn test_hover_macro_generated_struct_fn_doc_comment() {
2025 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2041 fn foo() { let bar = Bar; bar.fo<|>o(); }
2062 fn test_hover_macro_generated_struct_fn_doc_attr() {
2063 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2071 #[doc = "Do the foo"]
2079 fn foo() { let bar = Bar; bar.fo<|>o(); }
2100 fn test_hover_trait_has_impl_action() {
2102 r#"trait foo<|>() {}"#,
2119 fn test_hover_struct_has_impl_action() {
2121 r"struct foo<|>() {}",
2138 fn test_hover_union_has_impl_action() {
2140 r#"union foo<|>() {}"#,
2157 fn test_hover_enum_has_impl_action() {
2159 r"enum foo<|>() { A, B }",
2176 fn test_hover_self_has_impl_action() {
2178 r#"struct foo where Self<|>:;"#,
2195 fn test_hover_test_has_action() {
2205 nav: NavigationTarget {
2210 focus_range: 11..19,
2231 fn test_hover_test_mod_has_action() {
2243 nav: NavigationTarget {
2264 fn test_hover_struct_has_goto_type_action() {
2269 fn main() { let s<|>t = S{ f1:0 }; }
2276 mod_path: "test::S",
2277 nav: NavigationTarget {
2285 description: "struct S",
2296 fn test_hover_generic_struct_has_goto_type_actions() {
2300 struct S<T>{ f1: T }
2302 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2309 mod_path: "test::S",
2310 nav: NavigationTarget {
2315 focus_range: 24..25,
2318 description: "struct S",
2322 mod_path: "test::Arg",
2323 nav: NavigationTarget {
2331 description: "struct Arg",
2342 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2346 struct S<T>{ f1: T }
2348 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2355 mod_path: "test::S",
2356 nav: NavigationTarget {
2361 focus_range: 24..25,
2364 description: "struct S",
2368 mod_path: "test::Arg",
2369 nav: NavigationTarget {
2377 description: "struct Arg",
2388 fn test_hover_tuple_has_goto_type_actions() {
2397 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2404 mod_path: "test::A",
2405 nav: NavigationTarget {
2413 description: "struct A",
2417 mod_path: "test::B",
2418 nav: NavigationTarget {
2423 focus_range: 22..23,
2426 description: "struct B",
2430 mod_path: "test::M::C",
2431 nav: NavigationTarget {
2436 focus_range: 53..54,
2439 description: "pub struct C",
2450 fn test_hover_return_impl_trait_has_goto_type_action() {
2454 fn foo() -> impl Foo {}
2456 fn main() { let s<|>t = foo(); }
2463 mod_path: "test::Foo",
2464 nav: NavigationTarget {
2472 description: "trait Foo",
2483 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2488 fn foo() -> impl Foo<S> {}
2490 fn main() { let s<|>t = foo(); }
2497 mod_path: "test::Foo",
2498 nav: NavigationTarget {
2506 description: "trait Foo",
2510 mod_path: "test::S",
2511 nav: NavigationTarget {
2516 focus_range: 23..24,
2519 description: "struct S",
2530 fn test_hover_return_impl_traits_has_goto_type_action() {
2535 fn foo() -> impl Foo + Bar {}
2537 fn main() { let s<|>t = foo(); }
2544 mod_path: "test::Foo",
2545 nav: NavigationTarget {
2553 description: "trait Foo",
2557 mod_path: "test::Bar",
2558 nav: NavigationTarget {
2563 focus_range: 19..22,
2566 description: "trait Bar",
2577 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2585 fn foo() -> impl Foo<S1> + Bar<S2> {}
2587 fn main() { let s<|>t = foo(); }
2594 mod_path: "test::Foo",
2595 nav: NavigationTarget {
2603 description: "trait Foo",
2607 mod_path: "test::Bar",
2608 nav: NavigationTarget {
2613 focus_range: 22..25,
2616 description: "trait Bar",
2620 mod_path: "test::S1",
2621 nav: NavigationTarget {
2626 focus_range: 39..41,
2629 description: "struct S1",
2633 mod_path: "test::S2",
2634 nav: NavigationTarget {
2639 focus_range: 52..54,
2642 description: "struct S2",
2653 fn test_hover_arg_impl_trait_has_goto_type_action() {
2657 fn foo(ar<|>g: &impl Foo) {}
2664 mod_path: "test::Foo",
2665 nav: NavigationTarget {
2673 description: "trait Foo",
2684 fn test_hover_arg_impl_traits_has_goto_type_action() {
2691 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2698 mod_path: "test::Foo",
2699 nav: NavigationTarget {
2707 description: "trait Foo",
2711 mod_path: "test::Bar",
2712 nav: NavigationTarget {
2717 focus_range: 19..22,
2720 description: "trait Bar",
2724 mod_path: "test::S",
2725 nav: NavigationTarget {
2730 focus_range: 36..37,
2733 description: "struct S",
2744 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2749 let fo<|>o = async { S };
2752 #[prelude_import] use future::*;
2754 #[lang = "future_trait"]
2755 pub trait Future { type Output; }
2763 mod_path: "test::future::Future",
2764 nav: NavigationTarget {
2768 full_range: 101..163,
2769 focus_range: 140..146,
2772 description: "pub trait Future",
2776 mod_path: "test::S",
2777 nav: NavigationTarget {
2785 description: "struct S",
2796 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2801 fn foo(ar<|>g: &impl Foo<S>) {}
2808 mod_path: "test::Foo",
2809 nav: NavigationTarget {
2817 description: "trait Foo",
2821 mod_path: "test::S",
2822 nav: NavigationTarget {
2827 focus_range: 23..24,
2830 description: "struct S",
2841 fn test_hover_dyn_return_has_goto_type_action() {
2849 fn foo() -> B<dyn Foo> {}
2851 fn main() { let s<|>t = foo(); }
2858 mod_path: "test::B",
2859 nav: NavigationTarget {
2864 focus_range: 49..50,
2867 description: "struct B",
2871 mod_path: "test::Foo",
2872 nav: NavigationTarget {
2880 description: "trait Foo",
2891 fn test_hover_dyn_arg_has_goto_type_action() {
2895 fn foo(ar<|>g: &dyn Foo) {}
2902 mod_path: "test::Foo",
2903 nav: NavigationTarget {
2911 description: "trait Foo",
2922 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2927 fn foo(ar<|>g: &dyn Foo<S>) {}
2934 mod_path: "test::Foo",
2935 nav: NavigationTarget {
2943 description: "trait Foo",
2947 mod_path: "test::S",
2948 nav: NavigationTarget {
2953 focus_range: 23..24,
2956 description: "struct S",
2967 fn test_hover_goto_type_action_links_order() {
2970 trait ImplTrait<T> {}
2971 trait DynTrait<T> {}
2975 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2982 mod_path: "test::ImplTrait",
2983 nav: NavigationTarget {
2991 description: "trait ImplTrait",
2995 mod_path: "test::B",
2996 nav: NavigationTarget {
3001 focus_range: 50..51,
3004 description: "struct B",
3008 mod_path: "test::DynTrait",
3009 nav: NavigationTarget {
3014 focus_range: 28..36,
3017 description: "trait DynTrait",
3021 mod_path: "test::S",
3022 nav: NavigationTarget {
3027 focus_range: 65..66,
3030 description: "struct S",
3041 fn test_hover_associated_type_has_goto_type_action() {
3046 fn get(self) -> Self::Item {}
3052 impl Foo for S { type Item = Bar; }
3054 fn test() -> impl Foo { S {} }
3056 fn main() { let s<|>t = test().get(); }
3063 mod_path: "test::Foo",
3064 nav: NavigationTarget {
3072 description: "trait Foo",
3083 fn test_hover_const_param_has_goto_type_action() {
3087 struct Foo<const BAR: Bar>;
3089 impl<const BAR: Bar> Foo<BAR<|>> {}
3096 mod_path: "test::Bar",
3097 nav: NavigationTarget {
3105 description: "struct Bar",
3116 fn hover_displays_normalized_crate_names() {
3119 //- /lib.rs crate:name-with-dashes
3121 pub struct Thing { x: u32 }
3124 pub fn new() -> Thing { Thing { x: 0 } }
3128 //- /main.rs crate:main deps:name-with-dashes
3129 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3135 name_with_dashes::wrapper::Thing
3139 pub fn new() -> Thing
3146 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3155 let S { f<|> } = &s;
3169 fn hover_self_param_shows_type() {
3187 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3193 fn bar(sel<|>f: Arc<Foo>) {}
3206 fn hover_doc_outer_inner() {
3213 /// This comment belongs to the function
3237 fn hover_doc_outer_inner_attribue() {
3240 #[doc = "Be quick;"]
3242 #![doc = "time is mana"]
3244 #[doc = "This comment belongs to the function"]
3268 fn hover_comments_dont_highlight_parent() {
3269 check_hover_no_result(
3297 fn hover_lifetime() {
3299 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,
3311 fn hover_type_param() {
3318 impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
3324 T: Copy + Clone + Sized
3331 impl<T> Foo<T<|>> {}
3341 // lifetimes aren't being substituted yet
3345 impl<T: 'static> Foo<T<|>> {}
3358 fn hover_const_param() {
3361 struct Foo<const LEN: usize>;
3362 impl<const LEN: usize> Foo<LEN<|>> {}