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(),
178 adt.try_to_nav(db).map(to_action)
182 sema: &Semantics<RootDatabase>,
185 ) -> Option<HoverAction> {
187 Definition::ModuleDef(it) => match it {
188 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
189 ModuleSource::Module(it) => {
190 runnable(&sema, it.syntax().clone()).map(|it| HoverAction::Runnable(it))
194 ModuleDef::Function(func) => {
195 let src = func.source(sema.db)?;
196 if src.file_id != file_id.into() {
197 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
198 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
202 runnable_fn(&sema, func).map(HoverAction::Runnable)
210 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
211 let mut targets: Vec<ModuleDef> = Vec::new();
212 let mut push_new_def = |item: ModuleDef| {
213 if !targets.contains(&item) {
218 if let Definition::TypeParam(it) = def {
219 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
222 Definition::Local(it) => it.ty(db),
223 Definition::ConstParam(it) => it.ty(db),
228 if let Some(adt) = t.as_adt() {
229 push_new_def(adt.into());
230 } else if let Some(trait_) = t.as_dyn_trait() {
231 push_new_def(trait_.into());
232 } else if let Some(traits) = t.as_impl_traits(db) {
233 traits.into_iter().for_each(|it| push_new_def(it.into()));
234 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
235 push_new_def(trait_.into());
240 let targets = targets
243 Some(HoverGotoTypeData {
244 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
245 nav: it.try_to_nav(db)?,
250 Some(HoverAction::GoToType(targets))
254 docs: Option<String>,
255 desc: Option<String>,
256 mod_path: Option<String>,
257 ) -> Option<Markup> {
260 let mut buf = String::new();
262 if let Some(mod_path) = mod_path {
263 if !mod_path.is_empty() {
264 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
267 format_to!(buf, "```rust\n{}\n```", desc);
269 if let Some(doc) = docs {
270 format_to!(buf, "\n___\n\n{}", doc);
274 None => docs.map(Markup::from),
278 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
280 Definition::Field(f) => Some(f.parent_def(db).name(db)),
281 Definition::Local(l) => l.parent(db).name(db),
282 Definition::ModuleDef(md) => match md {
283 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
284 AssocItemContainer::Trait(t) => Some(t.name(db)),
285 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
287 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
292 .map(|name| name.to_string())
295 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
297 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
298 let module_path = module
302 .flat_map(|it| it.name(db).map(|name| name.to_string()));
303 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
306 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
307 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
310 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
311 let mod_path = definition_mod_path(db, &def);
313 Definition::Macro(it) => {
314 let label = macro_label(&it.source(db)?.value);
315 from_def_source_labeled(db, it, Some(label), mod_path)
317 Definition::Field(def) => {
318 let src = def.source(db)?.value;
319 if let FieldSource::Named(it) = src {
320 from_def_source_labeled(db, def, it.short_label(), mod_path)
325 Definition::ModuleDef(it) => match it {
326 ModuleDef::Module(it) => from_def_source_labeled(
329 match it.definition_source(db).value {
330 ModuleSource::Module(it) => it.short_label(),
331 ModuleSource::SourceFile(it) => it.short_label(),
335 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
336 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
337 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
338 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
339 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
340 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
341 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
342 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
343 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
344 ModuleDef::BuiltinType(it) => Some(Markup::fenced_block(&it)),
346 Definition::Local(it) => Some(Markup::fenced_block(&it.ty(db).display(db))),
347 Definition::SelfType(impl_def) => {
348 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
349 Adt::Struct(it) => from_def_source(db, it, mod_path),
350 Adt::Union(it) => from_def_source(db, it, mod_path),
351 Adt::Enum(it) => from_def_source(db, it, mod_path),
354 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
355 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
356 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
357 Definition::ConstParam(it) => from_def_source(db, it, None),
360 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
362 D: HasSource<Ast = A> + HasAttrs + Copy,
365 let short_label = def.source(db)?.value.short_label();
366 from_def_source_labeled(db, def, short_label, mod_path)
369 fn from_def_source_labeled<D>(
372 short_label: Option<String>,
373 mod_path: Option<String>,
378 let docs = def.attrs(db).docs().map(Into::into);
379 hover_markup(docs, short_label, mod_path)
383 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
384 return tokens.max_by_key(priority);
385 fn priority(n: &SyntaxToken) -> usize {
387 IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
388 T!['('] | T![')'] => 2,
389 kind if kind.is_trivia() => 0,
397 use expect_test::{expect, Expect};
398 use ide_db::base_db::FileLoader;
404 fn check_hover_no_result(ra_fixture: &str) {
405 let (analysis, position) = fixture::position(ra_fixture);
406 assert!(analysis.hover(position, true, true).unwrap().is_none());
409 fn check(ra_fixture: &str, expect: Expect) {
410 let (analysis, position) = fixture::position(ra_fixture);
411 let hover = analysis.hover(position, true, true).unwrap().unwrap();
413 let content = analysis.db.file_text(position.file_id);
414 let hovered_element = &content[hover.range];
416 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
417 expect.assert_eq(&actual)
420 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
421 let (analysis, position) = fixture::position(ra_fixture);
422 let hover = analysis.hover(position, false, true).unwrap().unwrap();
424 let content = analysis.db.file_text(position.file_id);
425 let hovered_element = &content[hover.range];
427 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
428 expect.assert_eq(&actual)
431 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
432 let (analysis, position) = fixture::position(ra_fixture);
433 let hover = analysis.hover(position, true, false).unwrap().unwrap();
435 let content = analysis.db.file_text(position.file_id);
436 let hovered_element = &content[hover.range];
438 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
439 expect.assert_eq(&actual)
442 fn check_actions(ra_fixture: &str, expect: Expect) {
443 let (analysis, position) = fixture::position(ra_fixture);
444 let hover = analysis.hover(position, true, true).unwrap().unwrap();
445 expect.assert_debug_eq(&hover.info.actions)
449 fn hover_shows_type_of_an_expression() {
452 pub fn foo() -> u32 { 1 }
455 let foo_test = foo()$0;
468 fn hover_remove_markdown_if_configured() {
469 check_hover_no_markdown(
471 pub fn foo() -> u32 { 1 }
474 let foo_test = foo()$0;
485 fn hover_shows_long_type_of_an_expression() {
488 struct Scan<A, B, C> { a: A, b: B, c: C }
489 struct Iter<I> { inner: I }
490 enum Option<T> { Some(T), None }
492 struct OtherStruct<T> { i: T }
494 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
495 Iter { inner: Scan { a, b, c } }
500 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
501 Option::Some(*memo + value)
504 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
511 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
518 fn hover_shows_fn_signature() {
519 // Single file with result
522 pub fn foo() -> u32 { 1 }
524 fn main() { let foo_test = fo$0o(); }
539 // Multiple candidates but results are ambiguous.
543 pub fn foo() -> u32 { 1 }
546 pub fn foo() -> &str { "" }
549 pub fn foo(a: u32, b: u32) {}
556 fn main() { let foo_test = fo$0o(); }
568 fn hover_shows_fn_signature_with_type_params() {
571 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
573 fn main() { let foo_test = fo$0o(); }
583 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
590 fn hover_shows_fn_signature_on_fn_name() {
593 pub fn foo$0(a: u32, b: u32) -> u32 {}
605 pub fn foo(a: u32, b: u32) -> u32
612 fn hover_shows_fn_doc() {
617 /// # use std::path::Path;
619 /// foo(Path::new("hello, world!"))
621 pub fn foo$0(_: &Path) {}
641 # use std::path::Path;
643 foo(Path::new("hello, world!"))
650 fn hover_shows_fn_doc_attr_raw_string() {
653 #[doc = r#"Raw string doc attr"#]
654 pub fn foo$0(_: &Path) {}
677 fn hover_shows_struct_field_info() {
678 // Hovering over the field when instantiating
681 struct Foo { field_a: u32 }
684 let foo = Foo { field_a$0: 0, };
700 // Hovering over the field in the definition
703 struct Foo { field_a$0: u32 }
706 let foo = Foo { field_a: 0 };
724 fn hover_const_static() {
726 r#"const foo$0: u32 = 123;"#,
740 r#"static foo$0: u32 = 456;"#,
756 fn hover_default_generic_types() {
759 struct Test<K, T = u8> { k: K, t: T }
762 let zz$0 = Test { t: 23u8, k: 33 };
778 enum Option<T> { Some(T) }
781 fn main() { So$0me(12); }
798 enum Option<T> { Some(T) }
801 fn main() { let b$0ar = Some(12); }
814 fn hover_enum_variant() {
846 let s = Option::Som$0e(12);
868 fn hover_for_local_variable() {
870 r#"fn func(foo: i32) { fo$0o; }"#,
882 fn hover_for_local_variable_pat() {
884 r#"fn func(fo$0o: i32) {}"#,
896 fn hover_local_var_edge() {
898 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
910 fn hover_for_param_edge() {
912 r#"fn func($0foo: i32) {}"#,
924 fn hover_for_param_with_multiple_traits() {
932 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
937 impl Deref<Target = u8> + DerefMut<Target = u8>
944 fn test_hover_infer_associated_method_result() {
947 struct Thing { x: u32 }
950 fn new() -> Thing { Thing { x: 0 } }
953 fn main() { let foo_$0test = Thing::new(); }
966 fn test_hover_infer_associated_method_exact() {
970 struct Thing { x: u32 }
973 fn new() -> Thing { Thing { x: 0 } }
977 fn main() { let foo_test = wrapper::Thing::new$0(); }
994 fn test_hover_infer_associated_const_in_pattern() {
1025 fn test_hover_self() {
1028 struct Thing { x: u32 }
1030 fn new() -> Self { Self$0 { x: 0 } }
1047 struct Thing { x: u32 }
1049 fn new() -> Self$0 { Self { x: 0 } }
1068 pub fn new() -> Self$0 { Thing::A }
1087 pub fn thing(a: Self$0) {}
1105 fn test_hover_shadowing_pat() {
1126 fn test_hover_macro_invocation() {
1129 macro_rules! foo { () => {} }
1131 fn f() { fo$0o!(); }
1148 fn test_hover_tuple_field() {
1150 r#"struct TS(String, i32$0);"#,
1162 fn test_hover_through_macro() {
1165 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1168 fn bar() { fo$0o(); }
1186 fn test_hover_through_expr_in_macro() {
1189 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1190 fn foo(bar:u32) { let a = id!(ba$0r); }
1203 fn test_hover_through_expr_in_macro_recursive() {
1206 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1207 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1208 fn foo(bar:u32) { let a = id!(ba$0r); }
1221 fn test_hover_through_func_in_macro_recursive() {
1224 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1225 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1226 fn bar() -> u32 { 0 }
1227 fn foo() { let a = id!([0u32, bar($0)] ); }
1239 fn test_hover_through_literal_string_in_macro() {
1242 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1244 let mastered_for_itunes = "";
1245 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1258 fn test_hover_through_assert_macro() {
1261 #[rustc_builtin_macro]
1262 macro_rules! assert {}
1264 fn bar() -> bool { true }
1284 fn test_hover_through_literal_string_in_builtin_macro() {
1285 check_hover_no_result(
1287 #[rustc_builtin_macro]
1288 macro_rules! format {}
1291 format!("hel$0lo {}", 0);
1298 fn test_hover_non_ascii_space_doc() {
1301 /// <- `\u{3000}` here
1304 fn bar() { fo$0o(); }
1325 fn test_hover_function_show_qualifiers() {
1327 r#"async fn foo$0() {}"#,
1341 r#"pub const unsafe fn foo$0() {}"#,
1350 pub const unsafe fn foo()
1355 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1364 pub(crate) async unsafe extern "C" fn foo()
1371 fn test_hover_trait_show_qualifiers() {
1373 r"unsafe trait foo$0() {}",
1390 fn test_hover_extern_crate() {
1393 //- /main.rs crate:main deps:std
1395 //- /std/lib.rs crate:std
1396 //! Standard library for this test
1403 Standard library for this test
1411 //- /main.rs crate:main deps:std
1412 extern crate std as ab$0c;
1413 //- /std/lib.rs crate:std
1414 //! Standard library for this test
1421 Standard library for this test
1430 fn test_hover_mod_with_same_name_as_function() {
1433 use self::m$0y::Bar;
1434 mod my { pub struct Bar; }
1453 fn test_hover_struct_doc_comment() {
1459 fn foo() { let bar = Ba$0r; }
1480 fn test_hover_struct_doc_attr() {
1486 fn foo() { let bar = Ba$0r; }
1507 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1511 #[doc = "bar docs 1"]
1512 #[doc = "bar docs 2"]
1515 fn foo() { let bar = Ba$0r; }
1538 fn test_hover_path_link() {
1542 /// [Foo](struct.Foo.html)
1558 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1564 fn test_hover_path_link_no_strip() {
1568 /// [struct Foo](struct.Foo.html)
1584 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1589 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1591 fn test_hover_path_link_field() {
1596 /// [Foo](struct.Foo.html)
1613 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1619 fn test_hover_intra_link() {
1641 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1647 fn test_hover_intra_link_html_root_url() {
1650 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1671 [Foo](https://example.com/test/foo/struct.Foo.html)
1677 fn test_hover_intra_link_shortlink() {
1697 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1703 fn test_hover_intra_link_shortlink_code() {
1723 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1729 fn test_hover_intra_link_namespaced() {
1750 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1756 fn test_hover_intra_link_shortlink_namspaced_code() {
1776 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1782 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1802 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1808 fn test_hover_intra_link_reference() {
1830 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1836 fn test_hover_external_url() {
1840 /// [external](https://www.google.com)
1856 [external](https://www.google.com)
1861 // Check that we don't rewrite links which we can't identify
1863 fn test_hover_unknown_target() {
1889 fn test_doc_links_enum_variant() {
1910 [E](https://docs.rs/test/*/test/enum.E.html)
1916 fn test_doc_links_field() {
1937 [`S`](https://docs.rs/test/*/test/struct.S.html)
1943 fn test_hover_no_links() {
1944 check_hover_no_links(
1947 /// case 1. bare URL: https://www.example.com/
1948 /// case 2. inline URL with title: [example](https://www.example.com/)
1949 /// case 3. code refrence: [`Result`]
1950 /// case 4. code refrence but miss footnote: [`String`]
1951 /// case 5. autolink: <http://www.example.com/>
1952 /// case 6. email address: <test@example.com>
1953 /// case 7. refrence: [example][example]
1954 /// case 8. collapsed link: [example][]
1955 /// case 9. shortcut link: [example]
1956 /// case 10. inline without URL: [example]()
1957 /// case 11. refrence: [foo][foo]
1958 /// case 12. refrence: [foo][bar]
1959 /// case 13. collapsed link: [foo][]
1960 /// case 14. shortcut link: [foo]
1961 /// case 15. inline without URL: [foo]()
1962 /// case 16. just escaped text: \[foo]
1963 /// case 17. inline link: [Foo](foo::Foo)
1965 /// [`Result`]: ../../std/result/enum.Result.html
1966 /// [^example]: https://www.example.com/
1983 case 1. bare URL: https://www.example.com/
1984 case 2. inline URL with title: [example](https://www.example.com/)
1985 case 3. code refrence: `Result`
1986 case 4. code refrence but miss footnote: `String`
1987 case 5. autolink: http://www.example.com/
1988 case 6. email address: test@example.com
1989 case 7. refrence: example
1990 case 8. collapsed link: example
1991 case 9. shortcut link: example
1992 case 10. inline without URL: example
1993 case 11. refrence: foo
1994 case 12. refrence: foo
1995 case 13. collapsed link: foo
1996 case 14. shortcut link: foo
1997 case 15. inline without URL: foo
1998 case 16. just escaped text: \[foo]
1999 case 17. inline link: Foo
2001 [^example]: https://www.example.com/
2007 fn test_hover_macro_generated_struct_fn_doc_comment() {
2008 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2024 fn foo() { let bar = Bar; bar.fo$0o(); }
2045 fn test_hover_macro_generated_struct_fn_doc_attr() {
2046 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2054 #[doc = "Do the foo"]
2062 fn foo() { let bar = Bar; bar.fo$0o(); }
2083 fn test_hover_trait_has_impl_action() {
2085 r#"trait foo$0() {}"#,
2102 fn test_hover_struct_has_impl_action() {
2104 r"struct foo$0() {}",
2121 fn test_hover_union_has_impl_action() {
2123 r#"union foo$0() {}"#,
2140 fn test_hover_enum_has_impl_action() {
2142 r"enum foo$0() { A, B }",
2159 fn test_hover_self_has_impl_action() {
2161 r#"struct foo where Self$0:;"#,
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$0t = 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$0t = 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$0t = 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$0t = (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$0t = 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$0t = 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$0t = 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$0t = 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$0g: &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$0g: &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$0o = 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$0g: &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$0t = 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$0g: &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$0g: &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$0rg: &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$0t = test().get(); }
3046 mod_path: "test::Foo",
3047 nav: NavigationTarget {
3055 description: "trait Foo",
3066 fn test_hover_const_param_has_goto_type_action() {
3070 struct Foo<const BAR: Bar>;
3072 impl<const BAR: Bar> Foo<BAR$0> {}
3079 mod_path: "test::Bar",
3080 nav: NavigationTarget {
3088 description: "struct Bar",
3099 fn test_hover_type_param_has_goto_type_action() {
3104 fn foo<T: Foo>(t: T$0){}
3111 mod_path: "test::Foo",
3112 nav: NavigationTarget {
3120 description: "trait Foo",
3131 fn hover_displays_normalized_crate_names() {
3134 //- /lib.rs crate:name-with-dashes
3136 pub struct Thing { x: u32 }
3139 pub fn new() -> Thing { Thing { x: 0 } }
3143 //- /main.rs crate:main deps:name-with-dashes
3144 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3150 name_with_dashes::wrapper::Thing
3154 pub fn new() -> Thing
3161 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3184 fn hover_self_param_shows_type() {
3202 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3208 fn bar(sel$0f: Arc<Foo>) {}
3221 fn hover_doc_outer_inner() {
3228 /// This comment belongs to the function
3252 fn hover_doc_outer_inner_attribue() {
3255 #[doc = "Be quick;"]
3257 #![doc = "time is mana"]
3259 #[doc = "This comment belongs to the function"]
3283 fn hover_comments_dont_highlight_parent() {
3284 check_hover_no_result(
3312 fn hover_lifetime() {
3314 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3326 fn hover_type_param() {
3333 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3339 T: Copy + Clone + Sized
3356 // lifetimes aren't being substituted yet
3360 impl<T: 'static> Foo<T$0> {}
3373 fn hover_const_param() {
3376 struct Foo<const LEN: usize>;
3377 impl<const LEN: usize> Foo<LEN$0> {}