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, ToNav, 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 Implementaion(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 = if !markdown {
120 remove_markdown(&markup.as_str())
121 } else if links_in_hover {
122 rewrite_links(db, &markup.as_str(), &definition)
124 remove_links(&markup.as_str())
126 res.markup = Markup::from(markup);
127 if let Some(action) = show_implementations_action(db, definition) {
128 res.actions.push(action);
131 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
132 res.actions.push(action);
135 if let Some(action) = goto_type_action(db, definition) {
136 res.actions.push(action);
139 let range = sema.original_range(&node).range;
140 return Some(RangeInfo::new(range, res));
144 if token.kind() == syntax::SyntaxKind::COMMENT {
145 // don't highlight the entire parent node on comment hover
149 let node = token.ancestors().find(|n| {
150 ast::Expr::can_cast(n.kind())
151 || ast::Pat::can_cast(n.kind())
152 || ast::SelfParam::can_cast(n.kind())
155 let ty = match_ast! {
157 ast::Expr(it) => sema.type_of_expr(&it)?,
158 ast::Pat(it) => sema.type_of_pat(&it)?,
159 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
160 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
161 // (e.g expanding a builtin macro). So we give up here.
162 ast::MacroCall(_it) => return None,
167 res.markup = if markdown {
168 Markup::fenced_block(&ty.display(db))
170 ty.display(db).to_string().into()
172 let range = sema.original_range(&node).range;
173 Some(RangeInfo::new(range, res))
176 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
177 fn to_action(nav_target: NavigationTarget) -> HoverAction {
178 HoverAction::Implementaion(FilePosition {
179 file_id: nav_target.file_id,
180 offset: nav_target.focus_or_full_range().start(),
185 Definition::ModuleDef(it) => match it {
186 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.to_nav(db))),
187 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.to_nav(db))),
188 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.to_nav(db))),
189 ModuleDef::Trait(it) => Some(to_action(it.to_nav(db))),
197 sema: &Semantics<RootDatabase>,
200 ) -> Option<HoverAction> {
202 Definition::ModuleDef(it) => match it {
203 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
204 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
205 .map(|it| HoverAction::Runnable(it)),
208 ModuleDef::Function(it) => {
209 let src = it.source(sema.db);
210 if src.file_id != file_id.into() {
211 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
212 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
217 runnable(&sema, src.value.syntax().clone(), file_id)
218 .map(|it| HoverAction::Runnable(it))
226 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
228 Definition::Local(it) => {
229 let mut targets: Vec<ModuleDef> = Vec::new();
230 let mut push_new_def = |item: ModuleDef| {
231 if !targets.contains(&item) {
236 it.ty(db).walk(db, |t| {
237 if let Some(adt) = t.as_adt() {
238 push_new_def(adt.into());
239 } else if let Some(trait_) = t.as_dyn_trait() {
240 push_new_def(trait_.into());
241 } else if let Some(traits) = t.as_impl_traits(db) {
242 traits.into_iter().for_each(|it| push_new_def(it.into()));
243 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
244 push_new_def(trait_.into());
248 let targets = targets
251 Some(HoverGotoTypeData {
252 mod_path: render_path(
255 it.name(db).map(|name| name.to_string()),
257 nav: it.try_to_nav(db)?,
262 Some(HoverAction::GoToType(targets))
269 docs: Option<String>,
270 desc: Option<String>,
271 mod_path: Option<String>,
272 ) -> Option<Markup> {
275 let mut buf = String::new();
277 if let Some(mod_path) = mod_path {
278 if !mod_path.is_empty() {
279 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
282 format_to!(buf, "```rust\n{}\n```", desc);
284 if let Some(doc) = docs {
285 format_to!(buf, "\n___\n\n{}", doc);
289 None => docs.map(Markup::from),
293 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
295 Definition::Field(f) => Some(f.parent_def(db).name(db)),
296 Definition::Local(l) => l.parent(db).name(db),
297 Definition::ModuleDef(md) => match md {
298 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
299 AssocItemContainer::Trait(t) => Some(t.name(db)),
300 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
302 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
307 .map(|name| name.to_string())
310 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
312 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
313 let module_path = module
317 .flat_map(|it| it.name(db).map(|name| name.to_string()));
318 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
321 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
322 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
325 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
326 let mod_path = definition_mod_path(db, &def);
328 Definition::Macro(it) => {
329 // FIXME: Currently proc-macro do not have ast-node,
330 // such that it does not have source
331 // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
332 if it.is_proc_macro() {
335 let label = macro_label(&it.source(db).value);
336 from_def_source_labeled(db, it, Some(label), mod_path)
338 Definition::Field(def) => {
339 let src = def.source(db).value;
340 if let FieldSource::Named(it) = src {
341 from_def_source_labeled(db, def, it.short_label(), mod_path)
346 Definition::ModuleDef(it) => match it {
347 ModuleDef::Module(it) => from_def_source_labeled(
350 match it.definition_source(db).value {
351 ModuleSource::Module(it) => it.short_label(),
352 ModuleSource::SourceFile(it) => it.short_label(),
356 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
357 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
358 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
359 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
360 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
361 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
362 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
363 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
364 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
365 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
367 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
368 Definition::SelfType(impl_def) => {
369 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
370 Adt::Struct(it) => from_def_source(db, it, mod_path),
371 Adt::Union(it) => from_def_source(db, it, mod_path),
372 Adt::Enum(it) => from_def_source(db, it, mod_path),
375 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
376 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
377 Definition::TypeParam(_) | Definition::ConstParam(_) => {
378 // FIXME: Hover for generic param
383 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
385 D: HasSource<Ast = A> + HasAttrs + Copy,
388 let short_label = def.source(db).value.short_label();
389 from_def_source_labeled(db, def, short_label, mod_path)
392 fn from_def_source_labeled<D>(
395 short_label: Option<String>,
396 mod_path: Option<String>,
401 let docs = def.attrs(db).docs().map(Into::into);
402 hover_markup(docs, short_label, mod_path)
406 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
407 return tokens.max_by_key(priority);
408 fn priority(n: &SyntaxToken) -> usize {
410 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
411 T!['('] | T![')'] => 2,
412 kind if kind.is_trivia() => 0,
420 use expect_test::{expect, Expect};
421 use ide_db::base_db::FileLoader;
427 fn check_hover_no_result(ra_fixture: &str) {
428 let (analysis, position) = fixture::position(ra_fixture);
429 assert!(analysis.hover(position, true, true).unwrap().is_none());
432 fn check(ra_fixture: &str, expect: Expect) {
433 let (analysis, position) = fixture::position(ra_fixture);
434 let hover = analysis.hover(position, true, true).unwrap().unwrap();
436 let content = analysis.db.file_text(position.file_id);
437 let hovered_element = &content[hover.range];
439 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
440 expect.assert_eq(&actual)
443 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
444 let (analysis, position) = fixture::position(ra_fixture);
445 let hover = analysis.hover(position, false, true).unwrap().unwrap();
447 let content = analysis.db.file_text(position.file_id);
448 let hovered_element = &content[hover.range];
450 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
451 expect.assert_eq(&actual)
454 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
455 let (analysis, position) = fixture::position(ra_fixture);
456 let hover = analysis.hover(position, true, false).unwrap().unwrap();
458 let content = analysis.db.file_text(position.file_id);
459 let hovered_element = &content[hover.range];
461 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
462 expect.assert_eq(&actual)
465 fn check_actions(ra_fixture: &str, expect: Expect) {
466 let (analysis, position) = fixture::position(ra_fixture);
467 let hover = analysis.hover(position, true, true).unwrap().unwrap();
468 expect.assert_debug_eq(&hover.info.actions)
472 fn hover_shows_type_of_an_expression() {
475 pub fn foo() -> u32 { 1 }
478 let foo_test = foo()<|>;
491 fn hover_remove_markdown_if_configured() {
492 check_hover_no_markdown(
494 pub fn foo() -> u32 { 1 }
497 let foo_test = foo()<|>;
508 fn hover_shows_long_type_of_an_expression() {
511 struct Scan<A, B, C> { a: A, b: B, c: C }
512 struct Iter<I> { inner: I }
513 enum Option<T> { Some(T), None }
515 struct OtherStruct<T> { i: T }
517 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
518 Iter { inner: Scan { a, b, c } }
523 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
524 Option::Some(*memo + value)
527 let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
534 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
541 fn hover_shows_fn_signature() {
542 // Single file with result
545 pub fn foo() -> u32 { 1 }
547 fn main() { let foo_test = fo<|>o(); }
562 // Multiple candidates but results are ambiguous.
566 pub fn foo() -> u32 { 1 }
569 pub fn foo() -> &str { "" }
572 pub fn foo(a: u32, b: u32) {}
579 fn main() { let foo_test = fo<|>o(); }
591 fn hover_shows_fn_signature_with_type_params() {
594 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
596 fn main() { let foo_test = fo<|>o(); }
606 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
613 fn hover_shows_fn_signature_on_fn_name() {
616 pub fn foo<|>(a: u32, b: u32) -> u32 {}
628 pub fn foo(a: u32, b: u32) -> u32
635 fn hover_shows_fn_doc() {
640 /// # use std::path::Path;
642 /// foo(Path::new("hello, world!"))
644 pub fn foo<|>(_: &Path) {}
664 # use std::path::Path;
666 foo(Path::new("hello, world!"))
673 fn hover_shows_fn_doc_attr_raw_string() {
676 #[doc = r#"Raw string doc attr"#]
677 pub fn foo<|>(_: &Path) {}
700 fn hover_shows_struct_field_info() {
701 // Hovering over the field when instantiating
704 struct Foo { field_a: u32 }
707 let foo = Foo { field_a<|>: 0, };
723 // Hovering over the field in the definition
726 struct Foo { field_a<|>: u32 }
729 let foo = Foo { field_a: 0 };
747 fn hover_const_static() {
749 r#"const foo<|>: u32 = 123;"#,
763 r#"static foo<|>: u32 = 456;"#,
779 fn hover_default_generic_types() {
782 struct Test<K, T = u8> { k: K, t: T }
785 let zz<|> = Test { t: 23u8, k: 33 };
801 enum Option<T> { Some(T) }
804 fn main() { So<|>me(12); }
821 enum Option<T> { Some(T) }
824 fn main() { let b<|>ar = Some(12); }
837 fn hover_enum_variant() {
869 let s = Option::Som<|>e(12);
891 fn hover_for_local_variable() {
893 r#"fn func(foo: i32) { fo<|>o; }"#,
905 fn hover_for_local_variable_pat() {
907 r#"fn func(fo<|>o: i32) {}"#,
919 fn hover_local_var_edge() {
921 r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
933 fn hover_for_param_edge() {
935 r#"fn func(<|>foo: i32) {}"#,
947 fn hover_for_param_with_multiple_traits() {
955 fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
960 impl Deref<Target = u8> + DerefMut<Target = u8>
967 fn test_hover_infer_associated_method_result() {
970 struct Thing { x: u32 }
973 fn new() -> Thing { Thing { x: 0 } }
976 fn main() { let foo_<|>test = Thing::new(); }
989 fn test_hover_infer_associated_method_exact() {
993 struct Thing { x: u32 }
996 fn new() -> Thing { Thing { x: 0 } }
1000 fn main() { let foo_test = wrapper::Thing::new<|>(); }
1006 test::wrapper::Thing
1017 fn test_hover_infer_associated_const_in_pattern() {
1048 fn test_hover_self() {
1051 struct Thing { x: u32 }
1053 fn new() -> Self { Self<|> { x: 0 } }
1070 struct Thing { x: u32 }
1072 fn new() -> Self<|> { Self { x: 0 } }
1091 pub fn new() -> Self<|> { Thing::A }
1110 pub fn thing(a: Self<|>) {}
1128 fn test_hover_shadowing_pat() {
1149 fn test_hover_macro_invocation() {
1152 macro_rules! foo { () => {} }
1154 fn f() { fo<|>o!(); }
1171 fn test_hover_tuple_field() {
1173 r#"struct TS(String, i32<|>);"#,
1185 fn test_hover_through_macro() {
1188 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1191 fn bar() { fo<|>o(); }
1209 fn test_hover_through_expr_in_macro() {
1212 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1213 fn foo(bar:u32) { let a = id!(ba<|>r); }
1226 fn test_hover_through_expr_in_macro_recursive() {
1229 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1230 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1231 fn foo(bar:u32) { let a = id!(ba<|>r); }
1244 fn test_hover_through_func_in_macro_recursive() {
1247 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1248 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1249 fn bar() -> u32 { 0 }
1250 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1262 fn test_hover_through_literal_string_in_macro() {
1265 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1267 let mastered_for_itunes = "";
1268 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1281 fn test_hover_through_assert_macro() {
1284 #[rustc_builtin_macro]
1285 macro_rules! assert {}
1287 fn bar() -> bool { true }
1307 fn test_hover_through_literal_string_in_builtin_macro() {
1308 check_hover_no_result(
1310 #[rustc_builtin_macro]
1311 macro_rules! format {}
1314 format!("hel<|>lo {}", 0);
1321 fn test_hover_non_ascii_space_doc() {
1324 /// <- `\u{3000}` here
1327 fn bar() { fo<|>o(); }
1348 fn test_hover_function_show_qualifiers() {
1350 r#"async fn foo<|>() {}"#,
1364 r#"pub const unsafe fn foo<|>() {}"#,
1373 pub const unsafe fn foo()
1378 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1387 pub(crate) async unsafe extern "C" fn foo()
1394 fn test_hover_trait_show_qualifiers() {
1396 r"unsafe trait foo<|>() {}",
1413 fn test_hover_extern_crate() {
1416 //- /main.rs crate:main deps:std
1417 extern crate st<|>d;
1418 //- /std/lib.rs crate:std
1419 //! Standard library for this test
1426 Standard library for this test
1434 //- /main.rs crate:main deps:std
1435 extern crate std as ab<|>c;
1436 //- /std/lib.rs crate:std
1437 //! Standard library for this test
1444 Standard library for this test
1453 fn test_hover_mod_with_same_name_as_function() {
1456 use self::m<|>y::Bar;
1457 mod my { pub struct Bar; }
1476 fn test_hover_struct_doc_comment() {
1482 fn foo() { let bar = Ba<|>r; }
1503 fn test_hover_struct_doc_attr() {
1509 fn foo() { let bar = Ba<|>r; }
1530 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1534 #[doc = "bar docs 1"]
1535 #[doc = "bar docs 2"]
1538 fn foo() { let bar = Ba<|>r; }
1561 fn test_hover_path_link() {
1565 /// [Foo](struct.Foo.html)
1581 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1587 fn test_hover_path_link_no_strip() {
1591 /// [struct Foo](struct.Foo.html)
1607 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1612 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1614 fn test_hover_path_link_field() {
1619 /// [Foo](struct.Foo.html)
1636 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1642 fn test_hover_intra_link() {
1664 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1670 fn test_hover_intra_link_html_root_url() {
1673 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1694 [Foo](https://example.com/test/foo/struct.Foo.html)
1700 fn test_hover_intra_link_shortlink() {
1720 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1726 fn test_hover_intra_link_shortlink_code() {
1746 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1752 fn test_hover_intra_link_namespaced() {
1773 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1779 fn test_hover_intra_link_shortlink_namspaced_code() {
1799 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1805 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1825 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1831 fn test_hover_intra_link_reference() {
1853 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1859 fn test_hover_external_url() {
1863 /// [external](https://www.google.com)
1879 [external](https://www.google.com)
1884 // Check that we don't rewrite links which we can't identify
1886 fn test_hover_unknown_target() {
1912 fn test_doc_links_enum_variant() {
1933 [E](https://docs.rs/test/*/test/enum.E.html)
1939 fn test_doc_links_field() {
1960 [`S`](https://docs.rs/test/*/test/struct.S.html)
1966 fn test_hover_no_links() {
1967 check_hover_no_links(
1970 /// case 1. bare URL: https://www.example.com/
1971 /// case 2. inline URL with title: [example](https://www.example.com/)
1972 /// case 3. code refrence: [`Result`]
1973 /// case 4. code refrence but miss footnote: [`String`]
1974 /// case 5. autolink: <http://www.example.com/>
1975 /// case 6. email address: <test@example.com>
1976 /// case 7. refrence: [example][example]
1977 /// case 8. collapsed link: [example][]
1978 /// case 9. shortcut link: [example]
1979 /// case 10. inline without URL: [example]()
1980 /// case 11. refrence: [foo][foo]
1981 /// case 12. refrence: [foo][bar]
1982 /// case 13. collapsed link: [foo][]
1983 /// case 14. shortcut link: [foo]
1984 /// case 15. inline without URL: [foo]()
1985 /// case 16. just escaped text: \[foo]
1986 /// case 17. inline link: [Foo](foo::Foo)
1988 /// [`Result`]: ../../std/result/enum.Result.html
1989 /// [^example]: https://www.example.com/
2006 case 1. bare URL: https://www.example.com/
2007 case 2. inline URL with title: [example](https://www.example.com/)
2008 case 3. code refrence: `Result`
2009 case 4. code refrence but miss footnote: `String`
2010 case 5. autolink: http://www.example.com/
2011 case 6. email address: test@example.com
2012 case 7. refrence: example
2013 case 8. collapsed link: example
2014 case 9. shortcut link: example
2015 case 10. inline without URL: example
2016 case 11. refrence: foo
2017 case 12. refrence: foo
2018 case 13. collapsed link: foo
2019 case 14. shortcut link: foo
2020 case 15. inline without URL: foo
2021 case 16. just escaped text: \[foo]
2022 case 17. inline link: Foo
2024 [^example]: https://www.example.com/
2030 fn test_hover_macro_generated_struct_fn_doc_comment() {
2031 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2047 fn foo() { let bar = Bar; bar.fo<|>o(); }
2068 fn test_hover_macro_generated_struct_fn_doc_attr() {
2069 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2077 #[doc = "Do the foo"]
2085 fn foo() { let bar = Bar; bar.fo<|>o(); }
2106 fn test_hover_trait_has_impl_action() {
2108 r#"trait foo<|>() {}"#,
2125 fn test_hover_struct_has_impl_action() {
2127 r"struct foo<|>() {}",
2144 fn test_hover_union_has_impl_action() {
2146 r#"union foo<|>() {}"#,
2163 fn test_hover_enum_has_impl_action() {
2165 r"enum foo<|>() { A, B }",
2182 fn test_hover_test_has_action() {
2192 nav: NavigationTarget {
2197 focus_range: 11..19,
2218 fn test_hover_test_mod_has_action() {
2230 nav: NavigationTarget {
2251 fn test_hover_struct_has_goto_type_action() {
2256 fn main() { let s<|>t = S{ f1:0 }; }
2263 mod_path: "test::S",
2264 nav: NavigationTarget {
2272 description: "struct S",
2283 fn test_hover_generic_struct_has_goto_type_actions() {
2287 struct S<T>{ f1: T }
2289 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2296 mod_path: "test::S",
2297 nav: NavigationTarget {
2302 focus_range: 24..25,
2305 description: "struct S",
2309 mod_path: "test::Arg",
2310 nav: NavigationTarget {
2318 description: "struct Arg",
2329 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2333 struct S<T>{ f1: T }
2335 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2342 mod_path: "test::S",
2343 nav: NavigationTarget {
2348 focus_range: 24..25,
2351 description: "struct S",
2355 mod_path: "test::Arg",
2356 nav: NavigationTarget {
2364 description: "struct Arg",
2375 fn test_hover_tuple_has_goto_type_actions() {
2384 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2391 mod_path: "test::A",
2392 nav: NavigationTarget {
2400 description: "struct A",
2404 mod_path: "test::B",
2405 nav: NavigationTarget {
2410 focus_range: 22..23,
2413 description: "struct B",
2417 mod_path: "test::M::C",
2418 nav: NavigationTarget {
2423 focus_range: 53..54,
2426 description: "pub struct C",
2437 fn test_hover_return_impl_trait_has_goto_type_action() {
2441 fn foo() -> impl Foo {}
2443 fn main() { let s<|>t = foo(); }
2450 mod_path: "test::Foo",
2451 nav: NavigationTarget {
2459 description: "trait Foo",
2470 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2475 fn foo() -> impl Foo<S> {}
2477 fn main() { let s<|>t = foo(); }
2484 mod_path: "test::Foo",
2485 nav: NavigationTarget {
2493 description: "trait Foo",
2497 mod_path: "test::S",
2498 nav: NavigationTarget {
2503 focus_range: 23..24,
2506 description: "struct S",
2517 fn test_hover_return_impl_traits_has_goto_type_action() {
2522 fn foo() -> impl Foo + Bar {}
2524 fn main() { let s<|>t = foo(); }
2531 mod_path: "test::Foo",
2532 nav: NavigationTarget {
2540 description: "trait Foo",
2544 mod_path: "test::Bar",
2545 nav: NavigationTarget {
2550 focus_range: 19..22,
2553 description: "trait Bar",
2564 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2572 fn foo() -> impl Foo<S1> + Bar<S2> {}
2574 fn main() { let s<|>t = foo(); }
2581 mod_path: "test::Foo",
2582 nav: NavigationTarget {
2590 description: "trait Foo",
2594 mod_path: "test::Bar",
2595 nav: NavigationTarget {
2600 focus_range: 22..25,
2603 description: "trait Bar",
2607 mod_path: "test::S1",
2608 nav: NavigationTarget {
2613 focus_range: 39..41,
2616 description: "struct S1",
2620 mod_path: "test::S2",
2621 nav: NavigationTarget {
2626 focus_range: 52..54,
2629 description: "struct S2",
2640 fn test_hover_arg_impl_trait_has_goto_type_action() {
2644 fn foo(ar<|>g: &impl Foo) {}
2651 mod_path: "test::Foo",
2652 nav: NavigationTarget {
2660 description: "trait Foo",
2671 fn test_hover_arg_impl_traits_has_goto_type_action() {
2678 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2685 mod_path: "test::Foo",
2686 nav: NavigationTarget {
2694 description: "trait Foo",
2698 mod_path: "test::Bar",
2699 nav: NavigationTarget {
2704 focus_range: 19..22,
2707 description: "trait Bar",
2711 mod_path: "test::S",
2712 nav: NavigationTarget {
2717 focus_range: 36..37,
2720 description: "struct S",
2731 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2736 let fo<|>o = async { S };
2739 #[prelude_import] use future::*;
2741 #[lang = "future_trait"]
2742 pub trait Future { type Output; }
2750 mod_path: "test::future::Future",
2751 nav: NavigationTarget {
2755 full_range: 101..163,
2756 focus_range: 140..146,
2759 description: "pub trait Future",
2763 mod_path: "test::S",
2764 nav: NavigationTarget {
2772 description: "struct S",
2783 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2788 fn foo(ar<|>g: &impl Foo<S>) {}
2795 mod_path: "test::Foo",
2796 nav: NavigationTarget {
2804 description: "trait Foo",
2808 mod_path: "test::S",
2809 nav: NavigationTarget {
2814 focus_range: 23..24,
2817 description: "struct S",
2828 fn test_hover_dyn_return_has_goto_type_action() {
2836 fn foo() -> B<dyn Foo> {}
2838 fn main() { let s<|>t = foo(); }
2845 mod_path: "test::B",
2846 nav: NavigationTarget {
2851 focus_range: 49..50,
2854 description: "struct B",
2858 mod_path: "test::Foo",
2859 nav: NavigationTarget {
2867 description: "trait Foo",
2878 fn test_hover_dyn_arg_has_goto_type_action() {
2882 fn foo(ar<|>g: &dyn Foo) {}
2889 mod_path: "test::Foo",
2890 nav: NavigationTarget {
2898 description: "trait Foo",
2909 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2914 fn foo(ar<|>g: &dyn Foo<S>) {}
2921 mod_path: "test::Foo",
2922 nav: NavigationTarget {
2930 description: "trait Foo",
2934 mod_path: "test::S",
2935 nav: NavigationTarget {
2940 focus_range: 23..24,
2943 description: "struct S",
2954 fn test_hover_goto_type_action_links_order() {
2957 trait ImplTrait<T> {}
2958 trait DynTrait<T> {}
2962 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2969 mod_path: "test::ImplTrait",
2970 nav: NavigationTarget {
2978 description: "trait ImplTrait",
2982 mod_path: "test::B",
2983 nav: NavigationTarget {
2988 focus_range: 50..51,
2991 description: "struct B",
2995 mod_path: "test::DynTrait",
2996 nav: NavigationTarget {
3001 focus_range: 28..36,
3004 description: "trait DynTrait",
3008 mod_path: "test::S",
3009 nav: NavigationTarget {
3014 focus_range: 65..66,
3017 description: "struct S",
3028 fn test_hover_associated_type_has_goto_type_action() {
3033 fn get(self) -> Self::Item {}
3039 impl Foo for S { type Item = Bar; }
3041 fn test() -> impl Foo { S {} }
3043 fn main() { let s<|>t = test().get(); }
3050 mod_path: "test::Foo",
3051 nav: NavigationTarget {
3059 description: "trait Foo",
3070 fn hover_displays_normalized_crate_names() {
3073 //- /lib.rs crate:name-with-dashes
3075 pub struct Thing { x: u32 }
3078 pub fn new() -> Thing { Thing { x: 0 } }
3082 //- /main.rs crate:main deps:name-with-dashes
3083 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3089 name_with_dashes::wrapper::Thing
3093 pub fn new() -> Thing
3100 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3109 let S { f<|> } = &s;
3123 fn hover_self_param_shows_type() {
3141 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3147 fn bar(sel<|>f: Arc<Foo>) {}
3160 fn hover_doc_outer_inner() {
3167 /// This comment belongs to the function
3191 fn hover_doc_outer_inner_attribue() {
3194 #[doc = "Be quick;"]
3196 #![doc = "time is mana"]
3198 #[doc = "This comment belongs to the function"]
3222 fn hover_comments_dont_highlight_parent() {
3223 check_hover_no_result(
3251 fn hover_lifetime() {
3253 r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,