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, runnable_fn},
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(),
179 Adt::Struct(it) => it.try_to_nav(db),
180 Adt::Union(it) => it.try_to_nav(db),
181 Adt::Enum(it) => it.try_to_nav(db),
187 sema: &Semantics<RootDatabase>,
190 ) -> Option<HoverAction> {
192 Definition::ModuleDef(it) => match it {
193 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
194 ModuleSource::Module(it) => {
195 runnable(&sema, it.syntax().clone()).map(|it| HoverAction::Runnable(it))
199 ModuleDef::Function(func) => {
200 let src = func.source(sema.db)?;
201 if src.file_id != file_id.into() {
202 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
203 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
207 runnable_fn(&sema, func).map(HoverAction::Runnable)
215 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
216 let mut targets: Vec<ModuleDef> = Vec::new();
217 let mut push_new_def = |item: ModuleDef| {
218 if !targets.contains(&item) {
223 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
224 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
227 Definition::Local(it) => it.ty(db),
228 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
233 if let Some(adt) = t.as_adt() {
234 push_new_def(adt.into());
235 } else if let Some(trait_) = t.as_dyn_trait() {
236 push_new_def(trait_.into());
237 } else if let Some(traits) = t.as_impl_traits(db) {
238 traits.into_iter().for_each(|it| push_new_def(it.into()));
239 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
240 push_new_def(trait_.into());
245 let targets = targets
248 Some(HoverGotoTypeData {
249 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
250 nav: it.try_to_nav(db)?,
255 Some(HoverAction::GoToType(targets))
259 docs: Option<String>,
260 desc: Option<String>,
261 mod_path: Option<String>,
262 ) -> Option<Markup> {
265 let mut buf = String::new();
267 if let Some(mod_path) = mod_path {
268 if !mod_path.is_empty() {
269 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
272 format_to!(buf, "```rust\n{}\n```", desc);
274 if let Some(doc) = docs {
275 format_to!(buf, "\n___\n\n{}", doc);
279 None => docs.map(Markup::from),
283 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
285 Definition::Field(f) => Some(f.parent_def(db).name(db)),
286 Definition::Local(l) => l.parent(db).name(db),
287 Definition::ModuleDef(md) => match md {
288 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
289 AssocItemContainer::Trait(t) => Some(t.name(db)),
290 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
292 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
297 .map(|name| name.to_string())
300 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
302 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
303 let module_path = module
307 .flat_map(|it| it.name(db).map(|name| name.to_string()));
308 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
311 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
312 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
315 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
316 let mod_path = definition_mod_path(db, &def);
318 Definition::Macro(it) => {
319 let label = macro_label(&it.source(db)?.value);
320 from_def_source_labeled(db, it, Some(label), mod_path)
322 Definition::Field(def) => {
323 let src = def.source(db)?.value;
324 if let FieldSource::Named(it) = src {
325 from_def_source_labeled(db, def, it.short_label(), mod_path)
330 Definition::ModuleDef(it) => match it {
331 ModuleDef::Module(it) => from_def_source_labeled(
334 match it.definition_source(db).value {
335 ModuleSource::Module(it) => it.short_label(),
336 ModuleSource::SourceFile(it) => it.short_label(),
340 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
341 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
342 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
343 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
344 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
345 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
346 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
347 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
348 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
349 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
351 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
352 Definition::SelfType(impl_def) => {
353 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
354 Adt::Struct(it) => from_def_source(db, it, mod_path),
355 Adt::Union(it) => from_def_source(db, it, mod_path),
356 Adt::Enum(it) => from_def_source(db, it, mod_path),
359 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
360 Definition::GenericParam(it) => match it {
361 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
362 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
363 GenericParam::ConstParam(it) => from_def_source(db, it, None),
367 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
369 D: HasSource<Ast = A> + HasAttrs + Copy,
372 let short_label = def.source(db)?.value.short_label();
373 from_def_source_labeled(db, def, short_label, mod_path)
376 fn from_def_source_labeled<D>(
379 short_label: Option<String>,
380 mod_path: Option<String>,
385 let docs = def.attrs(db).docs().map(Into::into);
386 hover_markup(docs, short_label, mod_path)
390 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
391 return tokens.max_by_key(priority);
392 fn priority(n: &SyntaxToken) -> usize {
394 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
395 T!['('] | T![')'] => 2,
396 kind if kind.is_trivia() => 0,
404 use expect_test::{expect, Expect};
405 use ide_db::base_db::FileLoader;
411 fn check_hover_no_result(ra_fixture: &str) {
412 let (analysis, position) = fixture::position(ra_fixture);
413 assert!(analysis.hover(position, true, true).unwrap().is_none());
416 fn check(ra_fixture: &str, expect: Expect) {
417 let (analysis, position) = fixture::position(ra_fixture);
418 let hover = analysis.hover(position, true, true).unwrap().unwrap();
420 let content = analysis.db.file_text(position.file_id);
421 let hovered_element = &content[hover.range];
423 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
424 expect.assert_eq(&actual)
427 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
428 let (analysis, position) = fixture::position(ra_fixture);
429 let hover = analysis.hover(position, false, true).unwrap().unwrap();
431 let content = analysis.db.file_text(position.file_id);
432 let hovered_element = &content[hover.range];
434 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
435 expect.assert_eq(&actual)
438 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
439 let (analysis, position) = fixture::position(ra_fixture);
440 let hover = analysis.hover(position, true, false).unwrap().unwrap();
442 let content = analysis.db.file_text(position.file_id);
443 let hovered_element = &content[hover.range];
445 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
446 expect.assert_eq(&actual)
449 fn check_actions(ra_fixture: &str, expect: Expect) {
450 let (analysis, position) = fixture::position(ra_fixture);
451 let hover = analysis.hover(position, true, true).unwrap().unwrap();
452 expect.assert_debug_eq(&hover.info.actions)
456 fn hover_shows_type_of_an_expression() {
459 pub fn foo() -> u32 { 1 }
462 let foo_test = foo()$0;
475 fn hover_remove_markdown_if_configured() {
476 check_hover_no_markdown(
478 pub fn foo() -> u32 { 1 }
481 let foo_test = foo()$0;
492 fn hover_shows_long_type_of_an_expression() {
495 struct Scan<A, B, C> { a: A, b: B, c: C }
496 struct Iter<I> { inner: I }
497 enum Option<T> { Some(T), None }
499 struct OtherStruct<T> { i: T }
501 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
502 Iter { inner: Scan { a, b, c } }
507 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
508 Option::Some(*memo + value)
511 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
518 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
525 fn hover_shows_fn_signature() {
526 // Single file with result
529 pub fn foo() -> u32 { 1 }
531 fn main() { let foo_test = fo$0o(); }
546 // Multiple candidates but results are ambiguous.
550 pub fn foo() -> u32 { 1 }
553 pub fn foo() -> &str { "" }
556 pub fn foo(a: u32, b: u32) {}
563 fn main() { let foo_test = fo$0o(); }
575 fn hover_shows_fn_signature_with_type_params() {
578 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
580 fn main() { let foo_test = fo$0o(); }
590 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
597 fn hover_shows_fn_signature_on_fn_name() {
600 pub fn foo$0(a: u32, b: u32) -> u32 {}
612 pub fn foo(a: u32, b: u32) -> u32
619 fn hover_shows_fn_doc() {
624 /// # use std::path::Path;
626 /// foo(Path::new("hello, world!"))
628 pub fn foo$0(_: &Path) {}
648 # use std::path::Path;
650 foo(Path::new("hello, world!"))
657 fn hover_shows_fn_doc_attr_raw_string() {
660 #[doc = r#"Raw string doc attr"#]
661 pub fn foo$0(_: &Path) {}
684 fn hover_shows_struct_field_info() {
685 // Hovering over the field when instantiating
688 struct Foo { field_a: u32 }
691 let foo = Foo { field_a$0: 0, };
707 // Hovering over the field in the definition
710 struct Foo { field_a$0: u32 }
713 let foo = Foo { field_a: 0 };
731 fn hover_const_static() {
733 r#"const foo$0: u32 = 123;"#,
747 r#"static foo$0: u32 = 456;"#,
763 fn hover_default_generic_types() {
766 struct Test<K, T = u8> { k: K, t: T }
769 let zz$0 = Test { t: 23u8, k: 33 };
785 enum Option<T> { Some(T) }
788 fn main() { So$0me(12); }
805 enum Option<T> { Some(T) }
808 fn main() { let b$0ar = Some(12); }
821 fn hover_enum_variant() {
853 let s = Option::Som$0e(12);
875 fn hover_for_local_variable() {
877 r#"fn func(foo: i32) { fo$0o; }"#,
889 fn hover_for_local_variable_pat() {
891 r#"fn func(fo$0o: i32) {}"#,
903 fn hover_local_var_edge() {
905 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
917 fn hover_for_param_edge() {
919 r#"fn func($0foo: i32) {}"#,
931 fn hover_for_param_with_multiple_traits() {
939 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
944 impl Deref<Target = u8> + DerefMut<Target = u8>
951 fn test_hover_infer_associated_method_result() {
954 struct Thing { x: u32 }
957 fn new() -> Thing { Thing { x: 0 } }
960 fn main() { let foo_$0test = Thing::new(); }
973 fn test_hover_infer_associated_method_exact() {
977 struct Thing { x: u32 }
980 fn new() -> Thing { Thing { x: 0 } }
984 fn main() { let foo_test = wrapper::Thing::new$0(); }
1001 fn test_hover_infer_associated_const_in_pattern() {
1032 fn test_hover_self() {
1035 struct Thing { x: u32 }
1037 fn new() -> Self { Self$0 { x: 0 } }
1054 struct Thing { x: u32 }
1056 fn new() -> Self$0 { Self { x: 0 } }
1075 pub fn new() -> Self$0 { Thing::A }
1094 pub fn thing(a: Self$0) {}
1112 fn test_hover_shadowing_pat() {
1133 fn test_hover_macro_invocation() {
1136 macro_rules! foo { () => {} }
1138 fn f() { fo$0o!(); }
1155 fn test_hover_tuple_field() {
1157 r#"struct TS(String, i32$0);"#,
1169 fn test_hover_through_macro() {
1172 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1175 fn bar() { fo$0o(); }
1193 fn test_hover_through_expr_in_macro() {
1196 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1197 fn foo(bar:u32) { let a = id!(ba$0r); }
1210 fn test_hover_through_expr_in_macro_recursive() {
1213 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1214 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1215 fn foo(bar:u32) { let a = id!(ba$0r); }
1228 fn test_hover_through_func_in_macro_recursive() {
1231 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1232 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1233 fn bar() -> u32 { 0 }
1234 fn foo() { let a = id!([0u32, bar($0)] ); }
1246 fn test_hover_through_literal_string_in_macro() {
1249 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1251 let mastered_for_itunes = "";
1252 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1265 fn test_hover_through_assert_macro() {
1268 #[rustc_builtin_macro]
1269 macro_rules! assert {}
1271 fn bar() -> bool { true }
1291 fn test_hover_through_literal_string_in_builtin_macro() {
1292 check_hover_no_result(
1294 #[rustc_builtin_macro]
1295 macro_rules! format {}
1298 format!("hel$0lo {}", 0);
1305 fn test_hover_non_ascii_space_doc() {
1308 /// <- `\u{3000}` here
1311 fn bar() { fo$0o(); }
1332 fn test_hover_function_show_qualifiers() {
1334 r#"async fn foo$0() {}"#,
1348 r#"pub const unsafe fn foo$0() {}"#,
1357 pub const unsafe fn foo()
1362 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1371 pub(crate) async unsafe extern "C" fn foo()
1378 fn test_hover_trait_show_qualifiers() {
1380 r"unsafe trait foo$0() {}",
1397 fn test_hover_extern_crate() {
1400 //- /main.rs crate:main deps:std
1402 //- /std/lib.rs crate:std
1403 //! Standard library for this test
1410 Standard library for this test
1418 //- /main.rs crate:main deps:std
1419 extern crate std as ab$0c;
1420 //- /std/lib.rs crate:std
1421 //! Standard library for this test
1428 Standard library for this test
1437 fn test_hover_mod_with_same_name_as_function() {
1440 use self::m$0y::Bar;
1441 mod my { pub struct Bar; }
1460 fn test_hover_struct_doc_comment() {
1466 fn foo() { let bar = Ba$0r; }
1487 fn test_hover_struct_doc_attr() {
1493 fn foo() { let bar = Ba$0r; }
1514 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1518 #[doc = "bar docs 1"]
1519 #[doc = "bar docs 2"]
1522 fn foo() { let bar = Ba$0r; }
1545 fn test_hover_path_link() {
1549 /// [Foo](struct.Foo.html)
1565 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1571 fn test_hover_path_link_no_strip() {
1575 /// [struct Foo](struct.Foo.html)
1591 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1596 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1598 fn test_hover_path_link_field() {
1603 /// [Foo](struct.Foo.html)
1620 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1626 fn test_hover_intra_link() {
1648 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1654 fn test_hover_intra_link_html_root_url() {
1657 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1678 [Foo](https://example.com/test/foo/struct.Foo.html)
1684 fn test_hover_intra_link_shortlink() {
1704 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1710 fn test_hover_intra_link_shortlink_code() {
1730 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1736 fn test_hover_intra_link_namespaced() {
1757 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1763 fn test_hover_intra_link_shortlink_namspaced_code() {
1783 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1789 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1809 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1815 fn test_hover_intra_link_reference() {
1837 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1843 fn test_hover_external_url() {
1847 /// [external](https://www.google.com)
1863 [external](https://www.google.com)
1868 // Check that we don't rewrite links which we can't identify
1870 fn test_hover_unknown_target() {
1896 fn test_doc_links_enum_variant() {
1917 [E](https://docs.rs/test/*/test/enum.E.html)
1923 fn test_doc_links_field() {
1944 [`S`](https://docs.rs/test/*/test/struct.S.html)
1950 fn test_hover_no_links() {
1951 check_hover_no_links(
1954 /// case 1. bare URL: https://www.example.com/
1955 /// case 2. inline URL with title: [example](https://www.example.com/)
1956 /// case 3. code refrence: [`Result`]
1957 /// case 4. code refrence but miss footnote: [`String`]
1958 /// case 5. autolink: <http://www.example.com/>
1959 /// case 6. email address: <test@example.com>
1960 /// case 7. refrence: [example][example]
1961 /// case 8. collapsed link: [example][]
1962 /// case 9. shortcut link: [example]
1963 /// case 10. inline without URL: [example]()
1964 /// case 11. refrence: [foo][foo]
1965 /// case 12. refrence: [foo][bar]
1966 /// case 13. collapsed link: [foo][]
1967 /// case 14. shortcut link: [foo]
1968 /// case 15. inline without URL: [foo]()
1969 /// case 16. just escaped text: \[foo]
1970 /// case 17. inline link: [Foo](foo::Foo)
1972 /// [`Result`]: ../../std/result/enum.Result.html
1973 /// [^example]: https://www.example.com/
1990 case 1. bare URL: https://www.example.com/
1991 case 2. inline URL with title: [example](https://www.example.com/)
1992 case 3. code refrence: `Result`
1993 case 4. code refrence but miss footnote: `String`
1994 case 5. autolink: http://www.example.com/
1995 case 6. email address: test@example.com
1996 case 7. refrence: example
1997 case 8. collapsed link: example
1998 case 9. shortcut link: example
1999 case 10. inline without URL: example
2000 case 11. refrence: foo
2001 case 12. refrence: foo
2002 case 13. collapsed link: foo
2003 case 14. shortcut link: foo
2004 case 15. inline without URL: foo
2005 case 16. just escaped text: \[foo]
2006 case 17. inline link: Foo
2008 [^example]: https://www.example.com/
2014 fn test_hover_macro_generated_struct_fn_doc_comment() {
2015 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2031 fn foo() { let bar = Bar; bar.fo$0o(); }
2052 fn test_hover_macro_generated_struct_fn_doc_attr() {
2053 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2061 #[doc = "Do the foo"]
2069 fn foo() { let bar = Bar; bar.fo$0o(); }
2090 fn test_hover_trait_has_impl_action() {
2092 r#"trait foo$0() {}"#,
2109 fn test_hover_struct_has_impl_action() {
2111 r"struct foo$0() {}",
2128 fn test_hover_union_has_impl_action() {
2130 r#"union foo$0() {}"#,
2147 fn test_hover_enum_has_impl_action() {
2149 r"enum foo$0() { A, B }",
2166 fn test_hover_self_has_impl_action() {
2168 r#"struct foo where Self$0:;"#,
2185 fn test_hover_test_has_action() {
2195 nav: NavigationTarget {
2200 focus_range: 11..19,
2221 fn test_hover_test_mod_has_action() {
2233 nav: NavigationTarget {
2254 fn test_hover_struct_has_goto_type_action() {
2259 fn main() { let s$0t = S{ f1:0 }; }
2266 mod_path: "test::S",
2267 nav: NavigationTarget {
2275 description: "struct S",
2286 fn test_hover_generic_struct_has_goto_type_actions() {
2290 struct S<T>{ f1: T }
2292 fn main() { let s$0t = S{ f1:Arg(0) }; }
2299 mod_path: "test::S",
2300 nav: NavigationTarget {
2305 focus_range: 24..25,
2308 description: "struct S",
2312 mod_path: "test::Arg",
2313 nav: NavigationTarget {
2321 description: "struct Arg",
2332 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2336 struct S<T>{ f1: T }
2338 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2345 mod_path: "test::S",
2346 nav: NavigationTarget {
2351 focus_range: 24..25,
2354 description: "struct S",
2358 mod_path: "test::Arg",
2359 nav: NavigationTarget {
2367 description: "struct Arg",
2378 fn test_hover_tuple_has_goto_type_actions() {
2387 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2394 mod_path: "test::A",
2395 nav: NavigationTarget {
2403 description: "struct A",
2407 mod_path: "test::B",
2408 nav: NavigationTarget {
2413 focus_range: 22..23,
2416 description: "struct B",
2420 mod_path: "test::M::C",
2421 nav: NavigationTarget {
2426 focus_range: 53..54,
2429 description: "pub struct C",
2440 fn test_hover_return_impl_trait_has_goto_type_action() {
2444 fn foo() -> impl Foo {}
2446 fn main() { let s$0t = foo(); }
2453 mod_path: "test::Foo",
2454 nav: NavigationTarget {
2462 description: "trait Foo",
2473 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2478 fn foo() -> impl Foo<S> {}
2480 fn main() { let s$0t = foo(); }
2487 mod_path: "test::Foo",
2488 nav: NavigationTarget {
2496 description: "trait Foo",
2500 mod_path: "test::S",
2501 nav: NavigationTarget {
2506 focus_range: 23..24,
2509 description: "struct S",
2520 fn test_hover_return_impl_traits_has_goto_type_action() {
2525 fn foo() -> impl Foo + Bar {}
2527 fn main() { let s$0t = foo(); }
2534 mod_path: "test::Foo",
2535 nav: NavigationTarget {
2543 description: "trait Foo",
2547 mod_path: "test::Bar",
2548 nav: NavigationTarget {
2553 focus_range: 19..22,
2556 description: "trait Bar",
2567 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2575 fn foo() -> impl Foo<S1> + Bar<S2> {}
2577 fn main() { let s$0t = foo(); }
2584 mod_path: "test::Foo",
2585 nav: NavigationTarget {
2593 description: "trait Foo",
2597 mod_path: "test::Bar",
2598 nav: NavigationTarget {
2603 focus_range: 22..25,
2606 description: "trait Bar",
2610 mod_path: "test::S1",
2611 nav: NavigationTarget {
2616 focus_range: 39..41,
2619 description: "struct S1",
2623 mod_path: "test::S2",
2624 nav: NavigationTarget {
2629 focus_range: 52..54,
2632 description: "struct S2",
2643 fn test_hover_arg_impl_trait_has_goto_type_action() {
2647 fn foo(ar$0g: &impl Foo) {}
2654 mod_path: "test::Foo",
2655 nav: NavigationTarget {
2663 description: "trait Foo",
2674 fn test_hover_arg_impl_traits_has_goto_type_action() {
2681 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2688 mod_path: "test::Foo",
2689 nav: NavigationTarget {
2697 description: "trait Foo",
2701 mod_path: "test::Bar",
2702 nav: NavigationTarget {
2707 focus_range: 19..22,
2710 description: "trait Bar",
2714 mod_path: "test::S",
2715 nav: NavigationTarget {
2720 focus_range: 36..37,
2723 description: "struct S",
2734 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2739 let fo$0o = async { S };
2742 #[prelude_import] use future::*;
2744 #[lang = "future_trait"]
2745 pub trait Future { type Output; }
2753 mod_path: "test::future::Future",
2754 nav: NavigationTarget {
2758 full_range: 101..163,
2759 focus_range: 140..146,
2762 description: "pub trait Future",
2766 mod_path: "test::S",
2767 nav: NavigationTarget {
2775 description: "struct S",
2786 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2791 fn foo(ar$0g: &impl Foo<S>) {}
2798 mod_path: "test::Foo",
2799 nav: NavigationTarget {
2807 description: "trait Foo",
2811 mod_path: "test::S",
2812 nav: NavigationTarget {
2817 focus_range: 23..24,
2820 description: "struct S",
2831 fn test_hover_dyn_return_has_goto_type_action() {
2839 fn foo() -> B<dyn Foo> {}
2841 fn main() { let s$0t = foo(); }
2848 mod_path: "test::B",
2849 nav: NavigationTarget {
2854 focus_range: 49..50,
2857 description: "struct B",
2861 mod_path: "test::Foo",
2862 nav: NavigationTarget {
2870 description: "trait Foo",
2881 fn test_hover_dyn_arg_has_goto_type_action() {
2885 fn foo(ar$0g: &dyn Foo) {}
2892 mod_path: "test::Foo",
2893 nav: NavigationTarget {
2901 description: "trait Foo",
2912 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2917 fn foo(ar$0g: &dyn Foo<S>) {}
2924 mod_path: "test::Foo",
2925 nav: NavigationTarget {
2933 description: "trait Foo",
2937 mod_path: "test::S",
2938 nav: NavigationTarget {
2943 focus_range: 23..24,
2946 description: "struct S",
2957 fn test_hover_goto_type_action_links_order() {
2960 trait ImplTrait<T> {}
2961 trait DynTrait<T> {}
2965 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2972 mod_path: "test::ImplTrait",
2973 nav: NavigationTarget {
2981 description: "trait ImplTrait",
2985 mod_path: "test::B",
2986 nav: NavigationTarget {
2991 focus_range: 50..51,
2994 description: "struct B",
2998 mod_path: "test::DynTrait",
2999 nav: NavigationTarget {
3004 focus_range: 28..36,
3007 description: "trait DynTrait",
3011 mod_path: "test::S",
3012 nav: NavigationTarget {
3017 focus_range: 65..66,
3020 description: "struct S",
3031 fn test_hover_associated_type_has_goto_type_action() {
3036 fn get(self) -> Self::Item {}
3042 impl Foo for S { type Item = Bar; }
3044 fn test() -> impl Foo { S {} }
3046 fn main() { let s$0t = test().get(); }
3053 mod_path: "test::Foo",
3054 nav: NavigationTarget {
3062 description: "trait Foo",
3073 fn test_hover_const_param_has_goto_type_action() {
3077 struct Foo<const BAR: Bar>;
3079 impl<const BAR: Bar> Foo<BAR$0> {}
3086 mod_path: "test::Bar",
3087 nav: NavigationTarget {
3095 description: "struct Bar",
3106 fn test_hover_type_param_has_goto_type_action() {
3111 fn foo<T: Foo>(t: T$0){}
3118 mod_path: "test::Foo",
3119 nav: NavigationTarget {
3127 description: "trait Foo",
3138 fn hover_displays_normalized_crate_names() {
3141 //- /lib.rs crate:name-with-dashes
3143 pub struct Thing { x: u32 }
3146 pub fn new() -> Thing { Thing { x: 0 } }
3150 //- /main.rs crate:main deps:name-with-dashes
3151 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3157 name_with_dashes::wrapper::Thing
3161 pub fn new() -> Thing
3168 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3191 fn hover_self_param_shows_type() {
3209 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3215 fn bar(sel$0f: Arc<Foo>) {}
3228 fn hover_doc_outer_inner() {
3235 /// This comment belongs to the function
3259 fn hover_doc_outer_inner_attribue() {
3262 #[doc = "Be quick;"]
3264 #![doc = "time is mana"]
3266 #[doc = "This comment belongs to the function"]
3290 fn hover_comments_dont_highlight_parent() {
3291 check_hover_no_result(
3319 fn hover_lifetime() {
3321 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3333 fn hover_type_param() {
3340 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3346 T: Copy + Clone + Sized
3363 // lifetimes aren't being substituted yet
3367 impl<T: 'static> Foo<T$0> {}
3380 fn hover_const_param() {
3383 struct Foo<const LEN: usize>;
3384 impl<const LEN: usize> Foo<LEN$0> {}