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) => match it.definition_source(sema.db).value {
186 ModuleSource::Module(it) => {
187 runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it))
191 ModuleDef::Function(func) => {
192 let src = func.source(sema.db)?;
193 if src.file_id != file_id.into() {
194 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
195 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
199 runnable_fn(&sema, func).map(HoverAction::Runnable)
207 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
208 let mut targets: Vec<ModuleDef> = Vec::new();
209 let mut push_new_def = |item: ModuleDef| {
210 if !targets.contains(&item) {
215 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
216 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
219 Definition::Local(it) => it.ty(db),
220 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
225 if let Some(adt) = t.as_adt() {
226 push_new_def(adt.into());
227 } else if let Some(trait_) = t.as_dyn_trait() {
228 push_new_def(trait_.into());
229 } else if let Some(traits) = t.as_impl_traits(db) {
230 traits.into_iter().for_each(|it| push_new_def(it.into()));
231 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
232 push_new_def(trait_.into());
237 let targets = targets
240 Some(HoverGotoTypeData {
241 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
242 nav: it.try_to_nav(db)?,
247 Some(HoverAction::GoToType(targets))
251 docs: Option<String>,
252 desc: Option<String>,
253 mod_path: Option<String>,
254 ) -> Option<Markup> {
257 let mut buf = String::new();
259 if let Some(mod_path) = mod_path {
260 if !mod_path.is_empty() {
261 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
264 format_to!(buf, "```rust\n{}\n```", desc);
266 if let Some(doc) = docs {
267 format_to!(buf, "\n___\n\n{}", doc);
271 None => docs.map(Markup::from),
275 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
277 Definition::Field(f) => Some(f.parent_def(db).name(db)),
278 Definition::Local(l) => l.parent(db).name(db),
279 Definition::ModuleDef(md) => match md {
280 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
281 AssocItemContainer::Trait(t) => Some(t.name(db)),
282 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
284 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
289 .map(|name| name.to_string())
292 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
294 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
295 let module_path = module
299 .flat_map(|it| it.name(db).map(|name| name.to_string()));
300 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
303 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
304 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
307 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
308 let mod_path = definition_mod_path(db, &def);
310 Definition::Macro(it) => {
311 let label = macro_label(&it.source(db)?.value);
312 from_def_source_labeled(db, it, Some(label), mod_path)
314 Definition::Field(def) => {
315 let src = def.source(db)?.value;
316 if let FieldSource::Named(it) = src {
317 from_def_source_labeled(db, def, it.short_label(), mod_path)
322 Definition::ModuleDef(it) => match it {
323 ModuleDef::Module(it) => from_def_source_labeled(
326 match it.definition_source(db).value {
327 ModuleSource::Module(it) => it.short_label(),
328 ModuleSource::SourceFile(it) => it.short_label(),
332 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
333 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
334 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
335 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
336 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
337 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
338 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
339 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
340 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
341 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
343 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
344 Definition::SelfType(impl_def) => {
345 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
346 Adt::Struct(it) => from_def_source(db, it, mod_path),
347 Adt::Union(it) => from_def_source(db, it, mod_path),
348 Adt::Enum(it) => from_def_source(db, it, mod_path),
351 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
352 Definition::GenericParam(it) => match it {
353 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
354 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
355 GenericParam::ConstParam(it) => from_def_source(db, it, None),
359 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
361 D: HasSource<Ast = A> + HasAttrs + Copy,
364 let short_label = def.source(db)?.value.short_label();
365 from_def_source_labeled(db, def, short_label, mod_path)
368 fn from_def_source_labeled<D>(
371 short_label: Option<String>,
372 mod_path: Option<String>,
377 let docs = def.attrs(db).docs().map(Into::into);
378 hover_markup(docs, short_label, mod_path)
382 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
383 return tokens.max_by_key(priority);
384 fn priority(n: &SyntaxToken) -> usize {
386 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 3,
387 T!['('] | T![')'] => 2,
388 kind if kind.is_trivia() => 0,
396 use expect_test::{expect, Expect};
397 use ide_db::base_db::FileLoader;
403 fn check_hover_no_result(ra_fixture: &str) {
404 let (analysis, position) = fixture::position(ra_fixture);
405 assert!(analysis.hover(position, true, true).unwrap().is_none());
408 fn check(ra_fixture: &str, expect: Expect) {
409 let (analysis, position) = fixture::position(ra_fixture);
410 let hover = analysis.hover(position, true, true).unwrap().unwrap();
412 let content = analysis.db.file_text(position.file_id);
413 let hovered_element = &content[hover.range];
415 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
416 expect.assert_eq(&actual)
419 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
420 let (analysis, position) = fixture::position(ra_fixture);
421 let hover = analysis.hover(position, false, true).unwrap().unwrap();
423 let content = analysis.db.file_text(position.file_id);
424 let hovered_element = &content[hover.range];
426 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
427 expect.assert_eq(&actual)
430 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
431 let (analysis, position) = fixture::position(ra_fixture);
432 let hover = analysis.hover(position, true, false).unwrap().unwrap();
434 let content = analysis.db.file_text(position.file_id);
435 let hovered_element = &content[hover.range];
437 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
438 expect.assert_eq(&actual)
441 fn check_actions(ra_fixture: &str, expect: Expect) {
442 let (analysis, position) = fixture::position(ra_fixture);
443 let hover = analysis.hover(position, true, true).unwrap().unwrap();
444 expect.assert_debug_eq(&hover.info.actions)
448 fn hover_shows_type_of_an_expression() {
451 pub fn foo() -> u32 { 1 }
454 let foo_test = foo()$0;
467 fn hover_remove_markdown_if_configured() {
468 check_hover_no_markdown(
470 pub fn foo() -> u32 { 1 }
473 let foo_test = foo()$0;
484 fn hover_shows_long_type_of_an_expression() {
487 struct Scan<A, B, C> { a: A, b: B, c: C }
488 struct Iter<I> { inner: I }
489 enum Option<T> { Some(T), None }
491 struct OtherStruct<T> { i: T }
493 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
494 Iter { inner: Scan { a, b, c } }
499 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
500 Option::Some(*memo + value)
503 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
510 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
517 fn hover_shows_fn_signature() {
518 // Single file with result
521 pub fn foo() -> u32 { 1 }
523 fn main() { let foo_test = fo$0o(); }
538 // Multiple candidates but results are ambiguous.
542 pub fn foo() -> u32 { 1 }
545 pub fn foo() -> &str { "" }
548 pub fn foo(a: u32, b: u32) {}
555 fn main() { let foo_test = fo$0o(); }
567 fn hover_shows_fn_signature_with_type_params() {
570 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
572 fn main() { let foo_test = fo$0o(); }
582 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
589 fn hover_shows_fn_signature_on_fn_name() {
592 pub fn foo$0(a: u32, b: u32) -> u32 {}
604 pub fn foo(a: u32, b: u32) -> u32
611 fn hover_shows_fn_doc() {
616 /// # use std::path::Path;
618 /// foo(Path::new("hello, world!"))
620 pub fn foo$0(_: &Path) {}
640 # use std::path::Path;
642 foo(Path::new("hello, world!"))
649 fn hover_shows_fn_doc_attr_raw_string() {
652 #[doc = r#"Raw string doc attr"#]
653 pub fn foo$0(_: &Path) {}
676 fn hover_shows_struct_field_info() {
677 // Hovering over the field when instantiating
680 struct Foo { field_a: u32 }
683 let foo = Foo { field_a$0: 0, };
699 // Hovering over the field in the definition
702 struct Foo { field_a$0: u32 }
705 let foo = Foo { field_a: 0 };
723 fn hover_const_static() {
725 r#"const foo$0: u32 = 123;"#,
739 r#"static foo$0: u32 = 456;"#,
755 fn hover_default_generic_types() {
758 struct Test<K, T = u8> { k: K, t: T }
761 let zz$0 = Test { t: 23u8, k: 33 };
777 enum Option<T> { Some(T) }
780 fn main() { So$0me(12); }
797 enum Option<T> { Some(T) }
800 fn main() { let b$0ar = Some(12); }
813 fn hover_enum_variant() {
845 let s = Option::Som$0e(12);
867 fn hover_for_local_variable() {
869 r#"fn func(foo: i32) { fo$0o; }"#,
881 fn hover_for_local_variable_pat() {
883 r#"fn func(fo$0o: i32) {}"#,
895 fn hover_local_var_edge() {
897 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
909 fn hover_for_param_edge() {
911 r#"fn func($0foo: i32) {}"#,
923 fn hover_for_param_with_multiple_traits() {
931 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
936 impl Deref<Target = u8> + DerefMut<Target = u8>
943 fn test_hover_infer_associated_method_result() {
946 struct Thing { x: u32 }
949 fn new() -> Thing { Thing { x: 0 } }
952 fn main() { let foo_$0test = Thing::new(); }
965 fn test_hover_infer_associated_method_exact() {
969 struct Thing { x: u32 }
972 fn new() -> Thing { Thing { x: 0 } }
976 fn main() { let foo_test = wrapper::Thing::new$0(); }
993 fn test_hover_infer_associated_const_in_pattern() {
1024 fn test_hover_self() {
1027 struct Thing { x: u32 }
1029 fn new() -> Self { Self$0 { x: 0 } }
1046 struct Thing { x: u32 }
1048 fn new() -> Self$0 { Self { x: 0 } }
1067 pub fn new() -> Self$0 { Thing::A }
1086 pub fn thing(a: Self$0) {}
1104 fn test_hover_shadowing_pat() {
1125 fn test_hover_macro_invocation() {
1128 macro_rules! foo { () => {} }
1130 fn f() { fo$0o!(); }
1147 fn test_hover_tuple_field() {
1149 r#"struct TS(String, i32$0);"#,
1161 fn test_hover_through_macro() {
1164 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1167 fn bar() { fo$0o(); }
1185 fn test_hover_through_expr_in_macro() {
1188 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1189 fn foo(bar:u32) { let a = id!(ba$0r); }
1202 fn test_hover_through_expr_in_macro_recursive() {
1205 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1206 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1207 fn foo(bar:u32) { let a = id!(ba$0r); }
1220 fn test_hover_through_func_in_macro_recursive() {
1223 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1224 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1225 fn bar() -> u32 { 0 }
1226 fn foo() { let a = id!([0u32, bar($0)] ); }
1238 fn test_hover_through_literal_string_in_macro() {
1241 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1243 let mastered_for_itunes = "";
1244 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1257 fn test_hover_through_assert_macro() {
1260 #[rustc_builtin_macro]
1261 macro_rules! assert {}
1263 fn bar() -> bool { true }
1283 fn test_hover_through_literal_string_in_builtin_macro() {
1284 check_hover_no_result(
1286 #[rustc_builtin_macro]
1287 macro_rules! format {}
1290 format!("hel$0lo {}", 0);
1297 fn test_hover_non_ascii_space_doc() {
1300 /// <- `\u{3000}` here
1303 fn bar() { fo$0o(); }
1324 fn test_hover_function_show_qualifiers() {
1326 r#"async fn foo$0() {}"#,
1340 r#"pub const unsafe fn foo$0() {}"#,
1349 pub const unsafe fn foo()
1354 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1363 pub(crate) async unsafe extern "C" fn foo()
1370 fn test_hover_trait_show_qualifiers() {
1372 r"unsafe trait foo$0() {}",
1389 fn test_hover_extern_crate() {
1392 //- /main.rs crate:main deps:std
1394 //- /std/lib.rs crate:std
1395 //! Standard library for this test
1402 Standard library for this test
1410 //- /main.rs crate:main deps:std
1411 extern crate std as ab$0c;
1412 //- /std/lib.rs crate:std
1413 //! Standard library for this test
1420 Standard library for this test
1429 fn test_hover_mod_with_same_name_as_function() {
1432 use self::m$0y::Bar;
1433 mod my { pub struct Bar; }
1452 fn test_hover_struct_doc_comment() {
1458 fn foo() { let bar = Ba$0r; }
1479 fn test_hover_struct_doc_attr() {
1485 fn foo() { let bar = Ba$0r; }
1506 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1510 #[doc = "bar docs 1"]
1511 #[doc = "bar docs 2"]
1514 fn foo() { let bar = Ba$0r; }
1537 fn test_hover_path_link() {
1541 /// [Foo](struct.Foo.html)
1557 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1563 fn test_hover_path_link_no_strip() {
1567 /// [struct Foo](struct.Foo.html)
1583 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1588 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1590 fn test_hover_path_link_field() {
1595 /// [Foo](struct.Foo.html)
1612 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1618 fn test_hover_intra_link() {
1640 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1646 fn test_hover_intra_link_html_root_url() {
1649 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1670 [Foo](https://example.com/test/foo/struct.Foo.html)
1676 fn test_hover_intra_link_shortlink() {
1696 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1702 fn test_hover_intra_link_shortlink_code() {
1722 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1728 fn test_hover_intra_link_namespaced() {
1749 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1755 fn test_hover_intra_link_shortlink_namspaced_code() {
1775 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1781 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1801 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1807 fn test_hover_intra_link_reference() {
1829 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1835 fn test_hover_external_url() {
1839 /// [external](https://www.google.com)
1855 [external](https://www.google.com)
1860 // Check that we don't rewrite links which we can't identify
1862 fn test_hover_unknown_target() {
1888 fn test_doc_links_enum_variant() {
1909 [E](https://docs.rs/test/*/test/enum.E.html)
1915 fn test_doc_links_field() {
1936 [`S`](https://docs.rs/test/*/test/struct.S.html)
1942 fn test_hover_no_links() {
1943 check_hover_no_links(
1946 /// case 1. bare URL: https://www.example.com/
1947 /// case 2. inline URL with title: [example](https://www.example.com/)
1948 /// case 3. code reference: [`Result`]
1949 /// case 4. code reference but miss footnote: [`String`]
1950 /// case 5. autolink: <http://www.example.com/>
1951 /// case 6. email address: <test@example.com>
1952 /// case 7. reference: [example][example]
1953 /// case 8. collapsed link: [example][]
1954 /// case 9. shortcut link: [example]
1955 /// case 10. inline without URL: [example]()
1956 /// case 11. reference: [foo][foo]
1957 /// case 12. reference: [foo][bar]
1958 /// case 13. collapsed link: [foo][]
1959 /// case 14. shortcut link: [foo]
1960 /// case 15. inline without URL: [foo]()
1961 /// case 16. just escaped text: \[foo]
1962 /// case 17. inline link: [Foo](foo::Foo)
1964 /// [`Result`]: ../../std/result/enum.Result.html
1965 /// [^example]: https://www.example.com/
1982 case 1. bare URL: https://www.example.com/
1983 case 2. inline URL with title: [example](https://www.example.com/)
1984 case 3. code reference: `Result`
1985 case 4. code reference but miss footnote: `String`
1986 case 5. autolink: http://www.example.com/
1987 case 6. email address: test@example.com
1988 case 7. reference: example
1989 case 8. collapsed link: example
1990 case 9. shortcut link: example
1991 case 10. inline without URL: example
1992 case 11. reference: foo
1993 case 12. reference: foo
1994 case 13. collapsed link: foo
1995 case 14. shortcut link: foo
1996 case 15. inline without URL: foo
1997 case 16. just escaped text: \[foo]
1998 case 17. inline link: Foo
2000 [^example]: https://www.example.com/
2006 fn test_hover_macro_generated_struct_fn_doc_comment() {
2007 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2023 fn foo() { let bar = Bar; bar.fo$0o(); }
2044 fn test_hover_macro_generated_struct_fn_doc_attr() {
2045 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2053 #[doc = "Do the foo"]
2061 fn foo() { let bar = Bar; bar.fo$0o(); }
2082 fn test_hover_trait_has_impl_action() {
2084 r#"trait foo$0() {}"#,
2101 fn test_hover_struct_has_impl_action() {
2103 r"struct foo$0() {}",
2120 fn test_hover_union_has_impl_action() {
2122 r#"union foo$0() {}"#,
2139 fn test_hover_enum_has_impl_action() {
2141 r"enum foo$0() { A, B }",
2158 fn test_hover_self_has_impl_action() {
2160 r#"struct foo where Self$0:;"#,
2177 fn test_hover_test_has_action() {
2187 nav: NavigationTarget {
2192 focus_range: 11..19,
2213 fn test_hover_test_mod_has_action() {
2225 nav: NavigationTarget {
2246 fn test_hover_struct_has_goto_type_action() {
2251 fn main() { let s$0t = S{ f1:0 }; }
2258 mod_path: "test::S",
2259 nav: NavigationTarget {
2267 description: "struct S",
2278 fn test_hover_generic_struct_has_goto_type_actions() {
2282 struct S<T>{ f1: T }
2284 fn main() { let s$0t = S{ f1:Arg(0) }; }
2291 mod_path: "test::S",
2292 nav: NavigationTarget {
2297 focus_range: 24..25,
2300 description: "struct S",
2304 mod_path: "test::Arg",
2305 nav: NavigationTarget {
2313 description: "struct Arg",
2324 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2328 struct S<T>{ f1: T }
2330 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2337 mod_path: "test::S",
2338 nav: NavigationTarget {
2343 focus_range: 24..25,
2346 description: "struct S",
2350 mod_path: "test::Arg",
2351 nav: NavigationTarget {
2359 description: "struct Arg",
2370 fn test_hover_tuple_has_goto_type_actions() {
2379 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2386 mod_path: "test::A",
2387 nav: NavigationTarget {
2395 description: "struct A",
2399 mod_path: "test::B",
2400 nav: NavigationTarget {
2405 focus_range: 22..23,
2408 description: "struct B",
2412 mod_path: "test::M::C",
2413 nav: NavigationTarget {
2418 focus_range: 53..54,
2421 description: "pub struct C",
2432 fn test_hover_return_impl_trait_has_goto_type_action() {
2436 fn foo() -> impl Foo {}
2438 fn main() { let s$0t = foo(); }
2445 mod_path: "test::Foo",
2446 nav: NavigationTarget {
2454 description: "trait Foo",
2465 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2470 fn foo() -> impl Foo<S> {}
2472 fn main() { let s$0t = foo(); }
2479 mod_path: "test::Foo",
2480 nav: NavigationTarget {
2488 description: "trait Foo",
2492 mod_path: "test::S",
2493 nav: NavigationTarget {
2498 focus_range: 23..24,
2501 description: "struct S",
2512 fn test_hover_return_impl_traits_has_goto_type_action() {
2517 fn foo() -> impl Foo + Bar {}
2519 fn main() { let s$0t = foo(); }
2526 mod_path: "test::Foo",
2527 nav: NavigationTarget {
2535 description: "trait Foo",
2539 mod_path: "test::Bar",
2540 nav: NavigationTarget {
2545 focus_range: 19..22,
2548 description: "trait Bar",
2559 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2567 fn foo() -> impl Foo<S1> + Bar<S2> {}
2569 fn main() { let s$0t = foo(); }
2576 mod_path: "test::Foo",
2577 nav: NavigationTarget {
2585 description: "trait Foo",
2589 mod_path: "test::Bar",
2590 nav: NavigationTarget {
2595 focus_range: 22..25,
2598 description: "trait Bar",
2602 mod_path: "test::S1",
2603 nav: NavigationTarget {
2608 focus_range: 39..41,
2611 description: "struct S1",
2615 mod_path: "test::S2",
2616 nav: NavigationTarget {
2621 focus_range: 52..54,
2624 description: "struct S2",
2635 fn test_hover_arg_impl_trait_has_goto_type_action() {
2639 fn foo(ar$0g: &impl Foo) {}
2646 mod_path: "test::Foo",
2647 nav: NavigationTarget {
2655 description: "trait Foo",
2666 fn test_hover_arg_impl_traits_has_goto_type_action() {
2673 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2680 mod_path: "test::Foo",
2681 nav: NavigationTarget {
2689 description: "trait Foo",
2693 mod_path: "test::Bar",
2694 nav: NavigationTarget {
2699 focus_range: 19..22,
2702 description: "trait Bar",
2706 mod_path: "test::S",
2707 nav: NavigationTarget {
2712 focus_range: 36..37,
2715 description: "struct S",
2726 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2731 let fo$0o = async { S };
2734 #[prelude_import] use future::*;
2736 #[lang = "future_trait"]
2737 pub trait Future { type Output; }
2745 mod_path: "test::future::Future",
2746 nav: NavigationTarget {
2750 full_range: 101..163,
2751 focus_range: 140..146,
2754 description: "pub trait Future",
2758 mod_path: "test::S",
2759 nav: NavigationTarget {
2767 description: "struct S",
2778 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2783 fn foo(ar$0g: &impl Foo<S>) {}
2790 mod_path: "test::Foo",
2791 nav: NavigationTarget {
2799 description: "trait Foo",
2803 mod_path: "test::S",
2804 nav: NavigationTarget {
2809 focus_range: 23..24,
2812 description: "struct S",
2823 fn test_hover_dyn_return_has_goto_type_action() {
2831 fn foo() -> B<dyn Foo> {}
2833 fn main() { let s$0t = foo(); }
2840 mod_path: "test::B",
2841 nav: NavigationTarget {
2846 focus_range: 49..50,
2849 description: "struct B",
2853 mod_path: "test::Foo",
2854 nav: NavigationTarget {
2862 description: "trait Foo",
2873 fn test_hover_dyn_arg_has_goto_type_action() {
2877 fn foo(ar$0g: &dyn Foo) {}
2884 mod_path: "test::Foo",
2885 nav: NavigationTarget {
2893 description: "trait Foo",
2904 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2909 fn foo(ar$0g: &dyn Foo<S>) {}
2916 mod_path: "test::Foo",
2917 nav: NavigationTarget {
2925 description: "trait Foo",
2929 mod_path: "test::S",
2930 nav: NavigationTarget {
2935 focus_range: 23..24,
2938 description: "struct S",
2949 fn test_hover_goto_type_action_links_order() {
2952 trait ImplTrait<T> {}
2953 trait DynTrait<T> {}
2957 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2964 mod_path: "test::ImplTrait",
2965 nav: NavigationTarget {
2973 description: "trait ImplTrait",
2977 mod_path: "test::B",
2978 nav: NavigationTarget {
2983 focus_range: 50..51,
2986 description: "struct B",
2990 mod_path: "test::DynTrait",
2991 nav: NavigationTarget {
2996 focus_range: 28..36,
2999 description: "trait DynTrait",
3003 mod_path: "test::S",
3004 nav: NavigationTarget {
3009 focus_range: 65..66,
3012 description: "struct S",
3023 fn test_hover_associated_type_has_goto_type_action() {
3028 fn get(self) -> Self::Item {}
3034 impl Foo for S { type Item = Bar; }
3036 fn test() -> impl Foo { S {} }
3038 fn main() { let s$0t = test().get(); }
3045 mod_path: "test::Foo",
3046 nav: NavigationTarget {
3054 description: "trait Foo",
3065 fn test_hover_const_param_has_goto_type_action() {
3069 struct Foo<const BAR: Bar>;
3071 impl<const BAR: Bar> Foo<BAR$0> {}
3078 mod_path: "test::Bar",
3079 nav: NavigationTarget {
3087 description: "struct Bar",
3098 fn test_hover_type_param_has_goto_type_action() {
3103 fn foo<T: Foo>(t: T$0){}
3110 mod_path: "test::Foo",
3111 nav: NavigationTarget {
3119 description: "trait Foo",
3130 fn test_hover_self_has_go_to_type() {
3143 mod_path: "test::Foo",
3144 nav: NavigationTarget {
3152 description: "struct Foo",
3163 fn hover_displays_normalized_crate_names() {
3166 //- /lib.rs crate:name-with-dashes
3168 pub struct Thing { x: u32 }
3171 pub fn new() -> Thing { Thing { x: 0 } }
3175 //- /main.rs crate:main deps:name-with-dashes
3176 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3182 name_with_dashes::wrapper::Thing
3186 pub fn new() -> Thing
3193 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3216 fn hover_self_param_shows_type() {
3235 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3241 fn bar(sel$0f: Arc<Foo>) {}
3255 fn hover_doc_outer_inner() {
3262 /// This comment belongs to the function
3286 fn hover_doc_outer_inner_attribue() {
3289 #[doc = "Be quick;"]
3291 #![doc = "time is mana"]
3293 #[doc = "This comment belongs to the function"]
3317 fn hover_comments_dont_highlight_parent() {
3318 check_hover_no_result(
3346 fn hover_lifetime() {
3348 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3360 fn hover_type_param() {
3367 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3373 T: Copy + Clone + Sized
3390 // lifetimes aren't being substituted yet
3394 impl<T: 'static> Foo<T$0> {}
3407 fn hover_const_param() {
3410 struct Foo<const LEN: usize>;
3411 impl<const LEN: usize> Foo<LEN$0> {}