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,
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::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::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::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
361 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
362 Definition::ConstParam(it) => from_def_source(db, it, None),
365 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
367 D: HasSource<Ast = A> + HasAttrs + Copy,
370 let short_label = def.source(db)?.value.short_label();
371 from_def_source_labeled(db, def, short_label, mod_path)
374 fn from_def_source_labeled<D>(
377 short_label: Option<String>,
378 mod_path: Option<String>,
383 let docs = def.attrs(db).docs().map(Into::into);
384 hover_markup(docs, short_label, mod_path)
388 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
389 return tokens.max_by_key(priority);
390 fn priority(n: &SyntaxToken) -> usize {
392 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
393 T!['('] | T![')'] => 2,
394 kind if kind.is_trivia() => 0,
402 use expect_test::{expect, Expect};
403 use ide_db::base_db::FileLoader;
409 fn check_hover_no_result(ra_fixture: &str) {
410 let (analysis, position) = fixture::position(ra_fixture);
411 assert!(analysis.hover(position, true, true).unwrap().is_none());
414 fn check(ra_fixture: &str, expect: Expect) {
415 let (analysis, position) = fixture::position(ra_fixture);
416 let hover = analysis.hover(position, true, true).unwrap().unwrap();
418 let content = analysis.db.file_text(position.file_id);
419 let hovered_element = &content[hover.range];
421 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
422 expect.assert_eq(&actual)
425 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
426 let (analysis, position) = fixture::position(ra_fixture);
427 let hover = analysis.hover(position, false, true).unwrap().unwrap();
429 let content = analysis.db.file_text(position.file_id);
430 let hovered_element = &content[hover.range];
432 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
433 expect.assert_eq(&actual)
436 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
437 let (analysis, position) = fixture::position(ra_fixture);
438 let hover = analysis.hover(position, true, false).unwrap().unwrap();
440 let content = analysis.db.file_text(position.file_id);
441 let hovered_element = &content[hover.range];
443 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
444 expect.assert_eq(&actual)
447 fn check_actions(ra_fixture: &str, expect: Expect) {
448 let (analysis, position) = fixture::position(ra_fixture);
449 let hover = analysis.hover(position, true, true).unwrap().unwrap();
450 expect.assert_debug_eq(&hover.info.actions)
454 fn hover_shows_type_of_an_expression() {
457 pub fn foo() -> u32 { 1 }
460 let foo_test = foo()$0;
473 fn hover_remove_markdown_if_configured() {
474 check_hover_no_markdown(
476 pub fn foo() -> u32 { 1 }
479 let foo_test = foo()$0;
490 fn hover_shows_long_type_of_an_expression() {
493 struct Scan<A, B, C> { a: A, b: B, c: C }
494 struct Iter<I> { inner: I }
495 enum Option<T> { Some(T), None }
497 struct OtherStruct<T> { i: T }
499 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
500 Iter { inner: Scan { a, b, c } }
505 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
506 Option::Some(*memo + value)
509 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
516 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
523 fn hover_shows_fn_signature() {
524 // Single file with result
527 pub fn foo() -> u32 { 1 }
529 fn main() { let foo_test = fo$0o(); }
544 // Multiple candidates but results are ambiguous.
548 pub fn foo() -> u32 { 1 }
551 pub fn foo() -> &str { "" }
554 pub fn foo(a: u32, b: u32) {}
561 fn main() { let foo_test = fo$0o(); }
573 fn hover_shows_fn_signature_with_type_params() {
576 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
578 fn main() { let foo_test = fo$0o(); }
588 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
595 fn hover_shows_fn_signature_on_fn_name() {
598 pub fn foo$0(a: u32, b: u32) -> u32 {}
610 pub fn foo(a: u32, b: u32) -> u32
617 fn hover_shows_fn_doc() {
622 /// # use std::path::Path;
624 /// foo(Path::new("hello, world!"))
626 pub fn foo$0(_: &Path) {}
646 # use std::path::Path;
648 foo(Path::new("hello, world!"))
655 fn hover_shows_fn_doc_attr_raw_string() {
658 #[doc = r#"Raw string doc attr"#]
659 pub fn foo$0(_: &Path) {}
682 fn hover_shows_struct_field_info() {
683 // Hovering over the field when instantiating
686 struct Foo { field_a: u32 }
689 let foo = Foo { field_a$0: 0, };
705 // Hovering over the field in the definition
708 struct Foo { field_a$0: u32 }
711 let foo = Foo { field_a: 0 };
729 fn hover_const_static() {
731 r#"const foo$0: u32 = 123;"#,
745 r#"static foo$0: u32 = 456;"#,
761 fn hover_default_generic_types() {
764 struct Test<K, T = u8> { k: K, t: T }
767 let zz$0 = Test { t: 23u8, k: 33 };
783 enum Option<T> { Some(T) }
786 fn main() { So$0me(12); }
803 enum Option<T> { Some(T) }
806 fn main() { let b$0ar = Some(12); }
819 fn hover_enum_variant() {
851 let s = Option::Som$0e(12);
873 fn hover_for_local_variable() {
875 r#"fn func(foo: i32) { fo$0o; }"#,
887 fn hover_for_local_variable_pat() {
889 r#"fn func(fo$0o: i32) {}"#,
901 fn hover_local_var_edge() {
903 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
915 fn hover_for_param_edge() {
917 r#"fn func($0foo: i32) {}"#,
929 fn hover_for_param_with_multiple_traits() {
937 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
942 impl Deref<Target = u8> + DerefMut<Target = u8>
949 fn test_hover_infer_associated_method_result() {
952 struct Thing { x: u32 }
955 fn new() -> Thing { Thing { x: 0 } }
958 fn main() { let foo_$0test = Thing::new(); }
971 fn test_hover_infer_associated_method_exact() {
975 struct Thing { x: u32 }
978 fn new() -> Thing { Thing { x: 0 } }
982 fn main() { let foo_test = wrapper::Thing::new$0(); }
999 fn test_hover_infer_associated_const_in_pattern() {
1030 fn test_hover_self() {
1033 struct Thing { x: u32 }
1035 fn new() -> Self { Self$0 { x: 0 } }
1052 struct Thing { x: u32 }
1054 fn new() -> Self$0 { Self { x: 0 } }
1073 pub fn new() -> Self$0 { Thing::A }
1092 pub fn thing(a: Self$0) {}
1110 fn test_hover_shadowing_pat() {
1131 fn test_hover_macro_invocation() {
1134 macro_rules! foo { () => {} }
1136 fn f() { fo$0o!(); }
1153 fn test_hover_tuple_field() {
1155 r#"struct TS(String, i32$0);"#,
1167 fn test_hover_through_macro() {
1170 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1173 fn bar() { fo$0o(); }
1191 fn test_hover_through_expr_in_macro() {
1194 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1195 fn foo(bar:u32) { let a = id!(ba$0r); }
1208 fn test_hover_through_expr_in_macro_recursive() {
1211 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1212 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1213 fn foo(bar:u32) { let a = id!(ba$0r); }
1226 fn test_hover_through_func_in_macro_recursive() {
1229 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1230 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1231 fn bar() -> u32 { 0 }
1232 fn foo() { let a = id!([0u32, bar($0)] ); }
1244 fn test_hover_through_literal_string_in_macro() {
1247 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1249 let mastered_for_itunes = "";
1250 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1263 fn test_hover_through_assert_macro() {
1266 #[rustc_builtin_macro]
1267 macro_rules! assert {}
1269 fn bar() -> bool { true }
1289 fn test_hover_through_literal_string_in_builtin_macro() {
1290 check_hover_no_result(
1292 #[rustc_builtin_macro]
1293 macro_rules! format {}
1296 format!("hel$0lo {}", 0);
1303 fn test_hover_non_ascii_space_doc() {
1306 /// <- `\u{3000}` here
1309 fn bar() { fo$0o(); }
1330 fn test_hover_function_show_qualifiers() {
1332 r#"async fn foo$0() {}"#,
1346 r#"pub const unsafe fn foo$0() {}"#,
1355 pub const unsafe fn foo()
1360 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1369 pub(crate) async unsafe extern "C" fn foo()
1376 fn test_hover_trait_show_qualifiers() {
1378 r"unsafe trait foo$0() {}",
1395 fn test_hover_extern_crate() {
1398 //- /main.rs crate:main deps:std
1400 //- /std/lib.rs crate:std
1401 //! Standard library for this test
1408 Standard library for this test
1416 //- /main.rs crate:main deps:std
1417 extern crate std as ab$0c;
1418 //- /std/lib.rs crate:std
1419 //! Standard library for this test
1426 Standard library for this test
1435 fn test_hover_mod_with_same_name_as_function() {
1438 use self::m$0y::Bar;
1439 mod my { pub struct Bar; }
1458 fn test_hover_struct_doc_comment() {
1464 fn foo() { let bar = Ba$0r; }
1485 fn test_hover_struct_doc_attr() {
1491 fn foo() { let bar = Ba$0r; }
1512 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1516 #[doc = "bar docs 1"]
1517 #[doc = "bar docs 2"]
1520 fn foo() { let bar = Ba$0r; }
1543 fn test_hover_path_link() {
1547 /// [Foo](struct.Foo.html)
1563 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1569 fn test_hover_path_link_no_strip() {
1573 /// [struct Foo](struct.Foo.html)
1589 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1594 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1596 fn test_hover_path_link_field() {
1601 /// [Foo](struct.Foo.html)
1618 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1624 fn test_hover_intra_link() {
1646 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1652 fn test_hover_intra_link_html_root_url() {
1655 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1676 [Foo](https://example.com/test/foo/struct.Foo.html)
1682 fn test_hover_intra_link_shortlink() {
1702 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1708 fn test_hover_intra_link_shortlink_code() {
1728 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1734 fn test_hover_intra_link_namespaced() {
1755 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1761 fn test_hover_intra_link_shortlink_namspaced_code() {
1781 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1787 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1807 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1813 fn test_hover_intra_link_reference() {
1835 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1841 fn test_hover_external_url() {
1845 /// [external](https://www.google.com)
1861 [external](https://www.google.com)
1866 // Check that we don't rewrite links which we can't identify
1868 fn test_hover_unknown_target() {
1894 fn test_doc_links_enum_variant() {
1915 [E](https://docs.rs/test/*/test/enum.E.html)
1921 fn test_doc_links_field() {
1942 [`S`](https://docs.rs/test/*/test/struct.S.html)
1948 fn test_hover_no_links() {
1949 check_hover_no_links(
1952 /// case 1. bare URL: https://www.example.com/
1953 /// case 2. inline URL with title: [example](https://www.example.com/)
1954 /// case 3. code reference: [`Result`]
1955 /// case 4. code reference but miss footnote: [`String`]
1956 /// case 5. autolink: <http://www.example.com/>
1957 /// case 6. email address: <test@example.com>
1958 /// case 7. reference: [example][example]
1959 /// case 8. collapsed link: [example][]
1960 /// case 9. shortcut link: [example]
1961 /// case 10. inline without URL: [example]()
1962 /// case 11. reference: [foo][foo]
1963 /// case 12. reference: [foo][bar]
1964 /// case 13. collapsed link: [foo][]
1965 /// case 14. shortcut link: [foo]
1966 /// case 15. inline without URL: [foo]()
1967 /// case 16. just escaped text: \[foo]
1968 /// case 17. inline link: [Foo](foo::Foo)
1970 /// [`Result`]: ../../std/result/enum.Result.html
1971 /// [^example]: https://www.example.com/
1988 case 1. bare URL: https://www.example.com/
1989 case 2. inline URL with title: [example](https://www.example.com/)
1990 case 3. code reference: `Result`
1991 case 4. code reference but miss footnote: `String`
1992 case 5. autolink: http://www.example.com/
1993 case 6. email address: test@example.com
1994 case 7. reference: example
1995 case 8. collapsed link: example
1996 case 9. shortcut link: example
1997 case 10. inline without URL: example
1998 case 11. reference: foo
1999 case 12. reference: foo
2000 case 13. collapsed link: foo
2001 case 14. shortcut link: foo
2002 case 15. inline without URL: foo
2003 case 16. just escaped text: \[foo]
2004 case 17. inline link: Foo
2006 [^example]: https://www.example.com/
2012 fn test_hover_macro_generated_struct_fn_doc_comment() {
2013 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2029 fn foo() { let bar = Bar; bar.fo$0o(); }
2050 fn test_hover_macro_generated_struct_fn_doc_attr() {
2051 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2059 #[doc = "Do the foo"]
2067 fn foo() { let bar = Bar; bar.fo$0o(); }
2088 fn test_hover_trait_has_impl_action() {
2090 r#"trait foo$0() {}"#,
2107 fn test_hover_struct_has_impl_action() {
2109 r"struct foo$0() {}",
2126 fn test_hover_union_has_impl_action() {
2128 r#"union foo$0() {}"#,
2145 fn test_hover_enum_has_impl_action() {
2147 r"enum foo$0() { A, B }",
2164 fn test_hover_self_has_impl_action() {
2166 r#"struct foo where Self$0:;"#,
2183 fn test_hover_test_has_action() {
2193 nav: NavigationTarget {
2198 focus_range: 11..19,
2219 fn test_hover_test_mod_has_action() {
2231 nav: NavigationTarget {
2252 fn test_hover_struct_has_goto_type_action() {
2257 fn main() { let s$0t = S{ f1:0 }; }
2264 mod_path: "test::S",
2265 nav: NavigationTarget {
2273 description: "struct S",
2284 fn test_hover_generic_struct_has_goto_type_actions() {
2288 struct S<T>{ f1: T }
2290 fn main() { let s$0t = S{ f1:Arg(0) }; }
2297 mod_path: "test::S",
2298 nav: NavigationTarget {
2303 focus_range: 24..25,
2306 description: "struct S",
2310 mod_path: "test::Arg",
2311 nav: NavigationTarget {
2319 description: "struct Arg",
2330 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2334 struct S<T>{ f1: T }
2336 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2343 mod_path: "test::S",
2344 nav: NavigationTarget {
2349 focus_range: 24..25,
2352 description: "struct S",
2356 mod_path: "test::Arg",
2357 nav: NavigationTarget {
2365 description: "struct Arg",
2376 fn test_hover_tuple_has_goto_type_actions() {
2385 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2392 mod_path: "test::A",
2393 nav: NavigationTarget {
2401 description: "struct A",
2405 mod_path: "test::B",
2406 nav: NavigationTarget {
2411 focus_range: 22..23,
2414 description: "struct B",
2418 mod_path: "test::M::C",
2419 nav: NavigationTarget {
2424 focus_range: 53..54,
2427 description: "pub struct C",
2438 fn test_hover_return_impl_trait_has_goto_type_action() {
2442 fn foo() -> impl Foo {}
2444 fn main() { let s$0t = foo(); }
2451 mod_path: "test::Foo",
2452 nav: NavigationTarget {
2460 description: "trait Foo",
2471 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2476 fn foo() -> impl Foo<S> {}
2478 fn main() { let s$0t = foo(); }
2485 mod_path: "test::Foo",
2486 nav: NavigationTarget {
2494 description: "trait Foo",
2498 mod_path: "test::S",
2499 nav: NavigationTarget {
2504 focus_range: 23..24,
2507 description: "struct S",
2518 fn test_hover_return_impl_traits_has_goto_type_action() {
2523 fn foo() -> impl Foo + Bar {}
2525 fn main() { let s$0t = foo(); }
2532 mod_path: "test::Foo",
2533 nav: NavigationTarget {
2541 description: "trait Foo",
2545 mod_path: "test::Bar",
2546 nav: NavigationTarget {
2551 focus_range: 19..22,
2554 description: "trait Bar",
2565 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2573 fn foo() -> impl Foo<S1> + Bar<S2> {}
2575 fn main() { let s$0t = foo(); }
2582 mod_path: "test::Foo",
2583 nav: NavigationTarget {
2591 description: "trait Foo",
2595 mod_path: "test::Bar",
2596 nav: NavigationTarget {
2601 focus_range: 22..25,
2604 description: "trait Bar",
2608 mod_path: "test::S1",
2609 nav: NavigationTarget {
2614 focus_range: 39..41,
2617 description: "struct S1",
2621 mod_path: "test::S2",
2622 nav: NavigationTarget {
2627 focus_range: 52..54,
2630 description: "struct S2",
2641 fn test_hover_arg_impl_trait_has_goto_type_action() {
2645 fn foo(ar$0g: &impl Foo) {}
2652 mod_path: "test::Foo",
2653 nav: NavigationTarget {
2661 description: "trait Foo",
2672 fn test_hover_arg_impl_traits_has_goto_type_action() {
2679 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2686 mod_path: "test::Foo",
2687 nav: NavigationTarget {
2695 description: "trait Foo",
2699 mod_path: "test::Bar",
2700 nav: NavigationTarget {
2705 focus_range: 19..22,
2708 description: "trait Bar",
2712 mod_path: "test::S",
2713 nav: NavigationTarget {
2718 focus_range: 36..37,
2721 description: "struct S",
2732 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2737 let fo$0o = async { S };
2740 #[prelude_import] use future::*;
2742 #[lang = "future_trait"]
2743 pub trait Future { type Output; }
2751 mod_path: "test::future::Future",
2752 nav: NavigationTarget {
2756 full_range: 101..163,
2757 focus_range: 140..146,
2760 description: "pub trait Future",
2764 mod_path: "test::S",
2765 nav: NavigationTarget {
2773 description: "struct S",
2784 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2789 fn foo(ar$0g: &impl Foo<S>) {}
2796 mod_path: "test::Foo",
2797 nav: NavigationTarget {
2805 description: "trait Foo",
2809 mod_path: "test::S",
2810 nav: NavigationTarget {
2815 focus_range: 23..24,
2818 description: "struct S",
2829 fn test_hover_dyn_return_has_goto_type_action() {
2837 fn foo() -> B<dyn Foo> {}
2839 fn main() { let s$0t = foo(); }
2846 mod_path: "test::B",
2847 nav: NavigationTarget {
2852 focus_range: 49..50,
2855 description: "struct B",
2859 mod_path: "test::Foo",
2860 nav: NavigationTarget {
2868 description: "trait Foo",
2879 fn test_hover_dyn_arg_has_goto_type_action() {
2883 fn foo(ar$0g: &dyn Foo) {}
2890 mod_path: "test::Foo",
2891 nav: NavigationTarget {
2899 description: "trait Foo",
2910 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2915 fn foo(ar$0g: &dyn Foo<S>) {}
2922 mod_path: "test::Foo",
2923 nav: NavigationTarget {
2931 description: "trait Foo",
2935 mod_path: "test::S",
2936 nav: NavigationTarget {
2941 focus_range: 23..24,
2944 description: "struct S",
2955 fn test_hover_goto_type_action_links_order() {
2958 trait ImplTrait<T> {}
2959 trait DynTrait<T> {}
2963 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2970 mod_path: "test::ImplTrait",
2971 nav: NavigationTarget {
2979 description: "trait ImplTrait",
2983 mod_path: "test::B",
2984 nav: NavigationTarget {
2989 focus_range: 50..51,
2992 description: "struct B",
2996 mod_path: "test::DynTrait",
2997 nav: NavigationTarget {
3002 focus_range: 28..36,
3005 description: "trait DynTrait",
3009 mod_path: "test::S",
3010 nav: NavigationTarget {
3015 focus_range: 65..66,
3018 description: "struct S",
3029 fn test_hover_associated_type_has_goto_type_action() {
3034 fn get(self) -> Self::Item {}
3040 impl Foo for S { type Item = Bar; }
3042 fn test() -> impl Foo { S {} }
3044 fn main() { let s$0t = test().get(); }
3051 mod_path: "test::Foo",
3052 nav: NavigationTarget {
3060 description: "trait Foo",
3071 fn test_hover_const_param_has_goto_type_action() {
3075 struct Foo<const BAR: Bar>;
3077 impl<const BAR: Bar> Foo<BAR$0> {}
3084 mod_path: "test::Bar",
3085 nav: NavigationTarget {
3093 description: "struct Bar",
3104 fn test_hover_type_param_has_goto_type_action() {
3109 fn foo<T: Foo>(t: T$0){}
3116 mod_path: "test::Foo",
3117 nav: NavigationTarget {
3125 description: "trait Foo",
3136 fn hover_displays_normalized_crate_names() {
3139 //- /lib.rs crate:name-with-dashes
3141 pub struct Thing { x: u32 }
3144 pub fn new() -> Thing { Thing { x: 0 } }
3148 //- /main.rs crate:main deps:name-with-dashes
3149 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3155 name_with_dashes::wrapper::Thing
3159 pub fn new() -> Thing
3166 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3189 fn hover_self_param_shows_type() {
3207 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3213 fn bar(sel$0f: Arc<Foo>) {}
3226 fn hover_doc_outer_inner() {
3233 /// This comment belongs to the function
3257 fn hover_doc_outer_inner_attribue() {
3260 #[doc = "Be quick;"]
3262 #![doc = "time is mana"]
3264 #[doc = "This comment belongs to the function"]
3288 fn hover_comments_dont_highlight_parent() {
3289 check_hover_no_result(
3317 fn hover_lifetime() {
3319 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3331 fn hover_type_param() {
3338 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3344 T: Copy + Clone + Sized
3361 // lifetimes aren't being substituted yet
3365 impl<T: 'static> Foo<T$0> {}
3378 fn hover_const_param() {
3381 struct Foo<const LEN: usize>;
3382 impl<const LEN: usize> Foo<LEN$0> {}