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(),
186 Definition::ModuleDef(it) => match it {
187 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)),
188 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)),
189 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.try_to_nav(db)?)),
190 ModuleDef::Trait(it) => Some(to_action(it.try_to_nav(db)?)),
198 sema: &Semantics<RootDatabase>,
201 ) -> Option<HoverAction> {
203 Definition::ModuleDef(it) => match it {
204 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
205 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
206 .map(|it| HoverAction::Runnable(it)),
209 ModuleDef::Function(it) => {
211 let src = it.source(sema.db)?;
212 if src.file_id != file_id.into() {
213 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
214 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
219 runnable(&sema, src.value.syntax().clone(), file_id)
220 .map(|it| HoverAction::Runnable(it))
228 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
230 Definition::Local(it) => {
231 let mut targets: Vec<ModuleDef> = Vec::new();
232 let mut push_new_def = |item: ModuleDef| {
233 if !targets.contains(&item) {
238 it.ty(db).walk(db, |t| {
239 if let Some(adt) = t.as_adt() {
240 push_new_def(adt.into());
241 } else if let Some(trait_) = t.as_dyn_trait() {
242 push_new_def(trait_.into());
243 } else if let Some(traits) = t.as_impl_traits(db) {
244 traits.into_iter().for_each(|it| push_new_def(it.into()));
245 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
246 push_new_def(trait_.into());
250 let targets = targets
253 Some(HoverGotoTypeData {
254 mod_path: render_path(
257 it.name(db).map(|name| name.to_string()),
259 nav: it.try_to_nav(db)?,
264 Some(HoverAction::GoToType(targets))
271 docs: Option<String>,
272 desc: Option<String>,
273 mod_path: Option<String>,
274 ) -> Option<Markup> {
277 let mut buf = String::new();
279 if let Some(mod_path) = mod_path {
280 if !mod_path.is_empty() {
281 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
284 format_to!(buf, "```rust\n{}\n```", desc);
286 if let Some(doc) = docs {
287 format_to!(buf, "\n___\n\n{}", doc);
291 None => docs.map(Markup::from),
295 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
297 Definition::Field(f) => Some(f.parent_def(db).name(db)),
298 Definition::Local(l) => l.parent(db).name(db),
299 Definition::ModuleDef(md) => match md {
300 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
301 AssocItemContainer::Trait(t) => Some(t.name(db)),
302 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
304 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
309 .map(|name| name.to_string())
312 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
314 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
315 let module_path = module
319 .flat_map(|it| it.name(db).map(|name| name.to_string()));
320 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
323 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
324 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
327 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
328 let mod_path = definition_mod_path(db, &def);
330 Definition::Macro(it) => {
331 let label = macro_label(&it.source(db)?.value);
332 from_def_source_labeled(db, it, Some(label), mod_path)
334 Definition::Field(def) => {
336 let src = def.source(db)?.value;
337 if let FieldSource::Named(it) = src {
338 from_def_source_labeled(db, def, it.short_label(), mod_path)
343 Definition::ModuleDef(it) => match it {
344 ModuleDef::Module(it) => from_def_source_labeled(
347 match it.definition_source(db).value {
348 ModuleSource::Module(it) => it.short_label(),
349 ModuleSource::SourceFile(it) => it.short_label(),
353 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
354 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
355 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
356 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
357 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
358 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
359 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
360 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
361 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
362 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
364 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
365 Definition::SelfType(impl_def) => {
366 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
367 Adt::Struct(it) => from_def_source(db, it, mod_path),
368 Adt::Union(it) => from_def_source(db, it, mod_path),
369 Adt::Enum(it) => from_def_source(db, it, mod_path),
372 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
373 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
374 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
375 Definition::ConstParam(it) => from_def_source(db, it, None),
378 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
380 D: HasSource<Ast = A> + HasAttrs + Copy,
384 let short_label = def.source(db)?.value.short_label();
385 from_def_source_labeled(db, def, short_label, mod_path)
388 fn from_def_source_labeled<D>(
391 short_label: Option<String>,
392 mod_path: Option<String>,
397 let docs = def.attrs(db).docs().map(Into::into);
398 hover_markup(docs, short_label, mod_path)
402 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
403 return tokens.max_by_key(priority);
404 fn priority(n: &SyntaxToken) -> usize {
406 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
407 T!['('] | T![')'] => 2,
408 kind if kind.is_trivia() => 0,
416 use expect_test::{expect, Expect};
417 use ide_db::base_db::FileLoader;
423 fn check_hover_no_result(ra_fixture: &str) {
424 let (analysis, position) = fixture::position(ra_fixture);
425 assert!(analysis.hover(position, true, true).unwrap().is_none());
428 fn check(ra_fixture: &str, expect: Expect) {
429 let (analysis, position) = fixture::position(ra_fixture);
430 let hover = analysis.hover(position, true, true).unwrap().unwrap();
432 let content = analysis.db.file_text(position.file_id);
433 let hovered_element = &content[hover.range];
435 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
436 expect.assert_eq(&actual)
439 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
440 let (analysis, position) = fixture::position(ra_fixture);
441 let hover = analysis.hover(position, false, true).unwrap().unwrap();
443 let content = analysis.db.file_text(position.file_id);
444 let hovered_element = &content[hover.range];
446 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
447 expect.assert_eq(&actual)
450 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
451 let (analysis, position) = fixture::position(ra_fixture);
452 let hover = analysis.hover(position, true, false).unwrap().unwrap();
454 let content = analysis.db.file_text(position.file_id);
455 let hovered_element = &content[hover.range];
457 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
458 expect.assert_eq(&actual)
461 fn check_actions(ra_fixture: &str, expect: Expect) {
462 let (analysis, position) = fixture::position(ra_fixture);
463 let hover = analysis.hover(position, true, true).unwrap().unwrap();
464 expect.assert_debug_eq(&hover.info.actions)
468 fn hover_shows_type_of_an_expression() {
471 pub fn foo() -> u32 { 1 }
474 let foo_test = foo()<|>;
487 fn hover_remove_markdown_if_configured() {
488 check_hover_no_markdown(
490 pub fn foo() -> u32 { 1 }
493 let foo_test = foo()<|>;
504 fn hover_shows_long_type_of_an_expression() {
507 struct Scan<A, B, C> { a: A, b: B, c: C }
508 struct Iter<I> { inner: I }
509 enum Option<T> { Some(T), None }
511 struct OtherStruct<T> { i: T }
513 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
514 Iter { inner: Scan { a, b, c } }
519 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
520 Option::Some(*memo + value)
523 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
530 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
537 fn hover_shows_fn_signature() {
538 // Single file with result
541 pub fn foo() -> u32 { 1 }
543 fn main() { let foo_test = fo<|>o(); }
558 // Multiple candidates but results are ambiguous.
562 pub fn foo() -> u32 { 1 }
565 pub fn foo() -> &str { "" }
568 pub fn foo(a: u32, b: u32) {}
575 fn main() { let foo_test = fo<|>o(); }
587 fn hover_shows_fn_signature_with_type_params() {
590 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
592 fn main() { let foo_test = fo<|>o(); }
602 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
609 fn hover_shows_fn_signature_on_fn_name() {
612 pub fn foo<|>(a: u32, b: u32) -> u32 {}
624 pub fn foo(a: u32, b: u32) -> u32
631 fn hover_shows_fn_doc() {
636 /// # use std::path::Path;
638 /// foo(Path::new("hello, world!"))
640 pub fn foo<|>(_: &Path) {}
660 # use std::path::Path;
662 foo(Path::new("hello, world!"))
669 fn hover_shows_fn_doc_attr_raw_string() {
672 #[doc = r#"Raw string doc attr"#]
673 pub fn foo<|>(_: &Path) {}
696 fn hover_shows_struct_field_info() {
697 // Hovering over the field when instantiating
700 struct Foo { field_a: u32 }
703 let foo = Foo { field_a<|>: 0, };
719 // Hovering over the field in the definition
722 struct Foo { field_a<|>: u32 }
725 let foo = Foo { field_a: 0 };
743 fn hover_const_static() {
745 r#"const foo<|>: u32 = 123;"#,
759 r#"static foo<|>: u32 = 456;"#,
775 fn hover_default_generic_types() {
778 struct Test<K, T = u8> { k: K, t: T }
781 let zz<|> = Test { t: 23u8, k: 33 };
797 enum Option<T> { Some(T) }
800 fn main() { So<|>me(12); }
817 enum Option<T> { Some(T) }
820 fn main() { let b<|>ar = Some(12); }
833 fn hover_enum_variant() {
865 let s = Option::Som<|>e(12);
887 fn hover_for_local_variable() {
889 r#"fn func(foo: i32) { fo<|>o; }"#,
901 fn hover_for_local_variable_pat() {
903 r#"fn func(fo<|>o: i32) {}"#,
915 fn hover_local_var_edge() {
917 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
929 fn hover_for_param_edge() {
931 r#"fn func(<|>foo: i32) {}"#,
943 fn hover_for_param_with_multiple_traits() {
951 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
956 impl Deref<Target = u8> + DerefMut<Target = u8>
963 fn test_hover_infer_associated_method_result() {
966 struct Thing { x: u32 }
969 fn new() -> Thing { Thing { x: 0 } }
972 fn main() { let foo_<|>test = Thing::new(); }
985 fn test_hover_infer_associated_method_exact() {
989 struct Thing { x: u32 }
992 fn new() -> Thing { Thing { x: 0 } }
996 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1002 test::wrapper::Thing
1013 fn test_hover_infer_associated_const_in_pattern() {
1044 fn test_hover_self() {
1047 struct Thing { x: u32 }
1049 fn new() -> Self { Self<|> { x: 0 } }
1066 struct Thing { x: u32 }
1068 fn new() -> Self<|> { Self { x: 0 } }
1087 pub fn new() -> Self<|> { Thing::A }
1106 pub fn thing(a: Self<|>) {}
1124 fn test_hover_shadowing_pat() {
1145 fn test_hover_macro_invocation() {
1148 macro_rules! foo { () => {} }
1150 fn f() { fo<|>o!(); }
1167 fn test_hover_tuple_field() {
1169 r#"struct TS(String, i32<|>);"#,
1181 fn test_hover_through_macro() {
1184 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1187 fn bar() { fo<|>o(); }
1205 fn test_hover_through_expr_in_macro() {
1208 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1209 fn foo(bar:u32) { let a = id!(ba<|>r); }
1222 fn test_hover_through_expr_in_macro_recursive() {
1225 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1226 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1227 fn foo(bar:u32) { let a = id!(ba<|>r); }
1240 fn test_hover_through_func_in_macro_recursive() {
1243 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1244 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1245 fn bar() -> u32 { 0 }
1246 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1258 fn test_hover_through_literal_string_in_macro() {
1261 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1263 let mastered_for_itunes = "";
1264 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1277 fn test_hover_through_assert_macro() {
1280 #[rustc_builtin_macro]
1281 macro_rules! assert {}
1283 fn bar() -> bool { true }
1303 fn test_hover_through_literal_string_in_builtin_macro() {
1304 check_hover_no_result(
1306 #[rustc_builtin_macro]
1307 macro_rules! format {}
1310 format!("hel<|>lo {}", 0);
1317 fn test_hover_non_ascii_space_doc() {
1320 /// <- `\u{3000}` here
1323 fn bar() { fo<|>o(); }
1344 fn test_hover_function_show_qualifiers() {
1346 r#"async fn foo<|>() {}"#,
1360 r#"pub const unsafe fn foo<|>() {}"#,
1369 pub const unsafe fn foo()
1374 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1383 pub(crate) async unsafe extern "C" fn foo()
1390 fn test_hover_trait_show_qualifiers() {
1392 r"unsafe trait foo<|>() {}",
1409 fn test_hover_extern_crate() {
1412 //- /main.rs crate:main deps:std
1413 extern crate st<|>d;
1414 //- /std/lib.rs crate:std
1415 //! Standard library for this test
1422 Standard library for this test
1430 //- /main.rs crate:main deps:std
1431 extern crate std as ab<|>c;
1432 //- /std/lib.rs crate:std
1433 //! Standard library for this test
1440 Standard library for this test
1449 fn test_hover_mod_with_same_name_as_function() {
1452 use self::m<|>y::Bar;
1453 mod my { pub struct Bar; }
1472 fn test_hover_struct_doc_comment() {
1478 fn foo() { let bar = Ba<|>r; }
1499 fn test_hover_struct_doc_attr() {
1505 fn foo() { let bar = Ba<|>r; }
1526 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1530 #[doc = "bar docs 1"]
1531 #[doc = "bar docs 2"]
1534 fn foo() { let bar = Ba<|>r; }
1557 fn test_hover_path_link() {
1561 /// [Foo](struct.Foo.html)
1577 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1583 fn test_hover_path_link_no_strip() {
1587 /// [struct Foo](struct.Foo.html)
1603 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1608 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1610 fn test_hover_path_link_field() {
1615 /// [Foo](struct.Foo.html)
1632 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1638 fn test_hover_intra_link() {
1660 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1666 fn test_hover_intra_link_html_root_url() {
1669 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1690 [Foo](https://example.com/test/foo/struct.Foo.html)
1696 fn test_hover_intra_link_shortlink() {
1716 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1722 fn test_hover_intra_link_shortlink_code() {
1742 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1748 fn test_hover_intra_link_namespaced() {
1769 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1775 fn test_hover_intra_link_shortlink_namspaced_code() {
1795 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1801 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1821 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1827 fn test_hover_intra_link_reference() {
1849 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1855 fn test_hover_external_url() {
1859 /// [external](https://www.google.com)
1875 [external](https://www.google.com)
1880 // Check that we don't rewrite links which we can't identify
1882 fn test_hover_unknown_target() {
1908 fn test_doc_links_enum_variant() {
1929 [E](https://docs.rs/test/*/test/enum.E.html)
1935 fn test_doc_links_field() {
1956 [`S`](https://docs.rs/test/*/test/struct.S.html)
1962 fn test_hover_no_links() {
1963 check_hover_no_links(
1966 /// case 1. bare URL: https://www.example.com/
1967 /// case 2. inline URL with title: [example](https://www.example.com/)
1968 /// case 3. code refrence: [`Result`]
1969 /// case 4. code refrence but miss footnote: [`String`]
1970 /// case 5. autolink: <http://www.example.com/>
1971 /// case 6. email address: <test@example.com>
1972 /// case 7. refrence: [example][example]
1973 /// case 8. collapsed link: [example][]
1974 /// case 9. shortcut link: [example]
1975 /// case 10. inline without URL: [example]()
1976 /// case 11. refrence: [foo][foo]
1977 /// case 12. refrence: [foo][bar]
1978 /// case 13. collapsed link: [foo][]
1979 /// case 14. shortcut link: [foo]
1980 /// case 15. inline without URL: [foo]()
1981 /// case 16. just escaped text: \[foo]
1982 /// case 17. inline link: [Foo](foo::Foo)
1984 /// [`Result`]: ../../std/result/enum.Result.html
1985 /// [^example]: https://www.example.com/
2002 case 1. bare URL: https://www.example.com/
2003 case 2. inline URL with title: [example](https://www.example.com/)
2004 case 3. code refrence: `Result`
2005 case 4. code refrence but miss footnote: `String`
2006 case 5. autolink: http://www.example.com/
2007 case 6. email address: test@example.com
2008 case 7. refrence: example
2009 case 8. collapsed link: example
2010 case 9. shortcut link: example
2011 case 10. inline without URL: example
2012 case 11. refrence: foo
2013 case 12. refrence: foo
2014 case 13. collapsed link: foo
2015 case 14. shortcut link: foo
2016 case 15. inline without URL: foo
2017 case 16. just escaped text: \[foo]
2018 case 17. inline link: Foo
2020 [^example]: https://www.example.com/
2026 fn test_hover_macro_generated_struct_fn_doc_comment() {
2027 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2043 fn foo() { let bar = Bar; bar.fo<|>o(); }
2064 fn test_hover_macro_generated_struct_fn_doc_attr() {
2065 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2073 #[doc = "Do the foo"]
2081 fn foo() { let bar = Bar; bar.fo<|>o(); }
2102 fn test_hover_trait_has_impl_action() {
2104 r#"trait foo<|>() {}"#,
2121 fn test_hover_struct_has_impl_action() {
2123 r"struct foo<|>() {}",
2140 fn test_hover_union_has_impl_action() {
2142 r#"union foo<|>() {}"#,
2159 fn test_hover_enum_has_impl_action() {
2161 r"enum foo<|>() { A, B }",
2178 fn test_hover_test_has_action() {
2188 nav: NavigationTarget {
2193 focus_range: 11..19,
2214 fn test_hover_test_mod_has_action() {
2226 nav: NavigationTarget {
2247 fn test_hover_struct_has_goto_type_action() {
2252 fn main() { let s<|>t = S{ f1:0 }; }
2259 mod_path: "test::S",
2260 nav: NavigationTarget {
2268 description: "struct S",
2279 fn test_hover_generic_struct_has_goto_type_actions() {
2283 struct S<T>{ f1: T }
2285 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2292 mod_path: "test::S",
2293 nav: NavigationTarget {
2298 focus_range: 24..25,
2301 description: "struct S",
2305 mod_path: "test::Arg",
2306 nav: NavigationTarget {
2314 description: "struct Arg",
2325 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2329 struct S<T>{ f1: T }
2331 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2338 mod_path: "test::S",
2339 nav: NavigationTarget {
2344 focus_range: 24..25,
2347 description: "struct S",
2351 mod_path: "test::Arg",
2352 nav: NavigationTarget {
2360 description: "struct Arg",
2371 fn test_hover_tuple_has_goto_type_actions() {
2380 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2387 mod_path: "test::A",
2388 nav: NavigationTarget {
2396 description: "struct A",
2400 mod_path: "test::B",
2401 nav: NavigationTarget {
2406 focus_range: 22..23,
2409 description: "struct B",
2413 mod_path: "test::M::C",
2414 nav: NavigationTarget {
2419 focus_range: 53..54,
2422 description: "pub struct C",
2433 fn test_hover_return_impl_trait_has_goto_type_action() {
2437 fn foo() -> impl Foo {}
2439 fn main() { let s<|>t = foo(); }
2446 mod_path: "test::Foo",
2447 nav: NavigationTarget {
2455 description: "trait Foo",
2466 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2471 fn foo() -> impl Foo<S> {}
2473 fn main() { let s<|>t = foo(); }
2480 mod_path: "test::Foo",
2481 nav: NavigationTarget {
2489 description: "trait Foo",
2493 mod_path: "test::S",
2494 nav: NavigationTarget {
2499 focus_range: 23..24,
2502 description: "struct S",
2513 fn test_hover_return_impl_traits_has_goto_type_action() {
2518 fn foo() -> impl Foo + Bar {}
2520 fn main() { let s<|>t = foo(); }
2527 mod_path: "test::Foo",
2528 nav: NavigationTarget {
2536 description: "trait Foo",
2540 mod_path: "test::Bar",
2541 nav: NavigationTarget {
2546 focus_range: 19..22,
2549 description: "trait Bar",
2560 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2568 fn foo() -> impl Foo<S1> + Bar<S2> {}
2570 fn main() { let s<|>t = foo(); }
2577 mod_path: "test::Foo",
2578 nav: NavigationTarget {
2586 description: "trait Foo",
2590 mod_path: "test::Bar",
2591 nav: NavigationTarget {
2596 focus_range: 22..25,
2599 description: "trait Bar",
2603 mod_path: "test::S1",
2604 nav: NavigationTarget {
2609 focus_range: 39..41,
2612 description: "struct S1",
2616 mod_path: "test::S2",
2617 nav: NavigationTarget {
2622 focus_range: 52..54,
2625 description: "struct S2",
2636 fn test_hover_arg_impl_trait_has_goto_type_action() {
2640 fn foo(ar<|>g: &impl Foo) {}
2647 mod_path: "test::Foo",
2648 nav: NavigationTarget {
2656 description: "trait Foo",
2667 fn test_hover_arg_impl_traits_has_goto_type_action() {
2674 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2681 mod_path: "test::Foo",
2682 nav: NavigationTarget {
2690 description: "trait Foo",
2694 mod_path: "test::Bar",
2695 nav: NavigationTarget {
2700 focus_range: 19..22,
2703 description: "trait Bar",
2707 mod_path: "test::S",
2708 nav: NavigationTarget {
2713 focus_range: 36..37,
2716 description: "struct S",
2727 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2732 let fo<|>o = async { S };
2735 #[prelude_import] use future::*;
2737 #[lang = "future_trait"]
2738 pub trait Future { type Output; }
2746 mod_path: "test::future::Future",
2747 nav: NavigationTarget {
2751 full_range: 101..163,
2752 focus_range: 140..146,
2755 description: "pub trait Future",
2759 mod_path: "test::S",
2760 nav: NavigationTarget {
2768 description: "struct S",
2779 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2784 fn foo(ar<|>g: &impl Foo<S>) {}
2791 mod_path: "test::Foo",
2792 nav: NavigationTarget {
2800 description: "trait Foo",
2804 mod_path: "test::S",
2805 nav: NavigationTarget {
2810 focus_range: 23..24,
2813 description: "struct S",
2824 fn test_hover_dyn_return_has_goto_type_action() {
2832 fn foo() -> B<dyn Foo> {}
2834 fn main() { let s<|>t = foo(); }
2841 mod_path: "test::B",
2842 nav: NavigationTarget {
2847 focus_range: 49..50,
2850 description: "struct B",
2854 mod_path: "test::Foo",
2855 nav: NavigationTarget {
2863 description: "trait Foo",
2874 fn test_hover_dyn_arg_has_goto_type_action() {
2878 fn foo(ar<|>g: &dyn Foo) {}
2885 mod_path: "test::Foo",
2886 nav: NavigationTarget {
2894 description: "trait Foo",
2905 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2910 fn foo(ar<|>g: &dyn Foo<S>) {}
2917 mod_path: "test::Foo",
2918 nav: NavigationTarget {
2926 description: "trait Foo",
2930 mod_path: "test::S",
2931 nav: NavigationTarget {
2936 focus_range: 23..24,
2939 description: "struct S",
2950 fn test_hover_goto_type_action_links_order() {
2953 trait ImplTrait<T> {}
2954 trait DynTrait<T> {}
2958 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2965 mod_path: "test::ImplTrait",
2966 nav: NavigationTarget {
2974 description: "trait ImplTrait",
2978 mod_path: "test::B",
2979 nav: NavigationTarget {
2984 focus_range: 50..51,
2987 description: "struct B",
2991 mod_path: "test::DynTrait",
2992 nav: NavigationTarget {
2997 focus_range: 28..36,
3000 description: "trait DynTrait",
3004 mod_path: "test::S",
3005 nav: NavigationTarget {
3010 focus_range: 65..66,
3013 description: "struct S",
3024 fn test_hover_associated_type_has_goto_type_action() {
3029 fn get(self) -> Self::Item {}
3035 impl Foo for S { type Item = Bar; }
3037 fn test() -> impl Foo { S {} }
3039 fn main() { let s<|>t = test().get(); }
3046 mod_path: "test::Foo",
3047 nav: NavigationTarget {
3055 description: "trait Foo",
3066 fn hover_displays_normalized_crate_names() {
3069 //- /lib.rs crate:name-with-dashes
3071 pub struct Thing { x: u32 }
3074 pub fn new() -> Thing { Thing { x: 0 } }
3078 //- /main.rs crate:main deps:name-with-dashes
3079 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3085 name_with_dashes::wrapper::Thing
3089 pub fn new() -> Thing
3096 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3105 let S { f<|> } = &s;
3119 fn hover_self_param_shows_type() {
3137 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3143 fn bar(sel<|>f: Arc<Foo>) {}
3156 fn hover_doc_outer_inner() {
3163 /// This comment belongs to the function
3187 fn hover_doc_outer_inner_attribue() {
3190 #[doc = "Be quick;"]
3192 #![doc = "time is mana"]
3194 #[doc = "This comment belongs to the function"]
3218 fn hover_comments_dont_highlight_parent() {
3219 check_hover_no_result(
3247 fn hover_lifetime() {
3249 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,
3261 fn hover_type_param() {
3268 impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
3274 T: Copy + Clone + Sized
3281 impl<T> Foo<T<|>> {}
3291 // lifetimes aren't being substituted yet
3295 impl<T: 'static> Foo<T<|>> {}
3308 fn hover_const_param() {
3311 struct Foo<const LEN: usize>;
3312 impl<const LEN: usize> Foo<LEN<|>> {}