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)),
115 if let Some(definition) = definition {
116 if let Some(markup) = hover_for_definition(db, definition) {
117 let markup = if !markdown {
118 remove_markdown(&markup.as_str())
119 } else if links_in_hover {
120 rewrite_links(db, &markup.as_str(), &definition)
122 remove_links(&markup.as_str())
124 res.markup = Markup::from(markup);
125 if let Some(action) = show_implementations_action(db, definition) {
126 res.actions.push(action);
129 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
130 res.actions.push(action);
133 if let Some(action) = goto_type_action(db, definition) {
134 res.actions.push(action);
137 let range = sema.original_range(&node).range;
138 return Some(RangeInfo::new(range, res));
142 if token.kind() == syntax::SyntaxKind::COMMENT {
143 // don't highlight the entire parent node on comment hover
147 let node = token.ancestors().find(|n| {
148 ast::Expr::can_cast(n.kind())
149 || ast::Pat::can_cast(n.kind())
150 || ast::SelfParam::can_cast(n.kind())
153 let ty = match_ast! {
155 ast::Expr(it) => sema.type_of_expr(&it)?,
156 ast::Pat(it) => sema.type_of_pat(&it)?,
157 ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
158 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
159 // (e.g expanding a builtin macro). So we give up here.
160 ast::MacroCall(_it) => return None,
165 res.markup = if markdown {
166 Markup::fenced_block(&ty.display(db))
168 ty.display(db).to_string().into()
170 let range = sema.original_range(&node).range;
171 Some(RangeInfo::new(range, res))
174 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
175 fn to_action(nav_target: NavigationTarget) -> HoverAction {
176 HoverAction::Implementaion(FilePosition {
177 file_id: nav_target.file_id,
178 offset: nav_target.focus_or_full_range().start(),
183 Definition::ModuleDef(it) => match it {
184 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.to_nav(db))),
185 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.to_nav(db))),
186 ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.to_nav(db))),
187 ModuleDef::Trait(it) => Some(to_action(it.to_nav(db))),
195 sema: &Semantics<RootDatabase>,
198 ) -> Option<HoverAction> {
200 Definition::ModuleDef(it) => match it {
201 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
202 ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id)
203 .map(|it| HoverAction::Runnable(it)),
206 ModuleDef::Function(it) => {
207 let src = it.source(sema.db);
208 if src.file_id != file_id.into() {
209 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
210 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
215 runnable(&sema, src.value.syntax().clone(), file_id)
216 .map(|it| HoverAction::Runnable(it))
224 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
226 Definition::Local(it) => {
227 let mut targets: Vec<ModuleDef> = Vec::new();
228 let mut push_new_def = |item: ModuleDef| {
229 if !targets.contains(&item) {
234 it.ty(db).walk(db, |t| {
235 if let Some(adt) = t.as_adt() {
236 push_new_def(adt.into());
237 } else if let Some(trait_) = t.as_dyn_trait() {
238 push_new_def(trait_.into());
239 } else if let Some(traits) = t.as_impl_traits(db) {
240 traits.into_iter().for_each(|it| push_new_def(it.into()));
241 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
242 push_new_def(trait_.into());
246 let targets = targets
249 Some(HoverGotoTypeData {
250 mod_path: render_path(
253 it.name(db).map(|name| name.to_string()),
255 nav: it.try_to_nav(db)?,
260 Some(HoverAction::GoToType(targets))
267 docs: Option<String>,
268 desc: Option<String>,
269 mod_path: Option<String>,
270 ) -> Option<Markup> {
273 let mut buf = String::new();
275 if let Some(mod_path) = mod_path {
276 if !mod_path.is_empty() {
277 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
280 format_to!(buf, "```rust\n{}\n```", desc);
282 if let Some(doc) = docs {
283 format_to!(buf, "\n___\n\n{}", doc);
287 None => docs.map(Markup::from),
291 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
293 Definition::Field(f) => Some(f.parent_def(db).name(db)),
294 Definition::Local(l) => l.parent(db).name(db),
295 Definition::ModuleDef(md) => match md {
296 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
297 AssocItemContainer::Trait(t) => Some(t.name(db)),
298 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
300 ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
305 .map(|name| name.to_string())
308 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
310 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
311 let module_path = module
315 .flat_map(|it| it.name(db).map(|name| name.to_string()));
316 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
319 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
320 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
323 fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
324 let mod_path = definition_mod_path(db, &def);
326 Definition::Macro(it) => {
327 // FIXME: Currently proc-macro do not have ast-node,
328 // such that it does not have source
329 // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
330 if it.is_proc_macro() {
333 let label = macro_label(&it.source(db).value);
334 from_def_source_labeled(db, it, Some(label), mod_path)
336 Definition::Field(def) => {
337 let src = def.source(db).value;
338 if let FieldSource::Named(it) = src {
339 from_def_source_labeled(db, def, it.short_label(), mod_path)
344 Definition::ModuleDef(it) => match it {
345 ModuleDef::Module(it) => from_def_source_labeled(
348 match it.definition_source(db).value {
349 ModuleSource::Module(it) => it.short_label(),
350 ModuleSource::SourceFile(it) => it.short_label(),
354 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
355 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
356 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
357 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
358 ModuleDef::EnumVariant(it) => from_def_source(db, it, mod_path),
359 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
360 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
361 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
362 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
363 ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
365 Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
366 Definition::SelfType(impl_def) => {
367 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
368 Adt::Struct(it) => from_def_source(db, it, mod_path),
369 Adt::Union(it) => from_def_source(db, it, mod_path),
370 Adt::Enum(it) => from_def_source(db, it, mod_path),
373 Definition::TypeParam(_) | Definition::LifetimeParam(_) => {
374 // FIXME: Hover for generic param
379 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
381 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 => 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<|>);"#,
1178 fn test_hover_through_macro() {
1181 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1184 fn bar() { fo<|>o(); }
1202 fn test_hover_through_expr_in_macro() {
1205 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1206 fn foo(bar:u32) { let a = id!(ba<|>r); }
1219 fn test_hover_through_expr_in_macro_recursive() {
1222 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1223 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1224 fn foo(bar:u32) { let a = id!(ba<|>r); }
1237 fn test_hover_through_func_in_macro_recursive() {
1240 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1241 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1242 fn bar() -> u32 { 0 }
1243 fn foo() { let a = id!([0u32, bar(<|>)] ); }
1255 fn test_hover_through_literal_string_in_macro() {
1258 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1260 let mastered_for_itunes = "";
1261 let _ = arr!("Tr<|>acks", &mastered_for_itunes);
1274 fn test_hover_through_assert_macro() {
1277 #[rustc_builtin_macro]
1278 macro_rules! assert {}
1280 fn bar() -> bool { true }
1300 fn test_hover_through_literal_string_in_builtin_macro() {
1301 check_hover_no_result(
1303 #[rustc_builtin_macro]
1304 macro_rules! format {}
1307 format!("hel<|>lo {}", 0);
1314 fn test_hover_non_ascii_space_doc() {
1317 /// <- `\u{3000}` here
1320 fn bar() { fo<|>o(); }
1341 fn test_hover_function_show_qualifiers() {
1343 r#"async fn foo<|>() {}"#,
1357 r#"pub const unsafe fn foo<|>() {}"#,
1366 pub const unsafe fn foo()
1371 r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
1380 pub(crate) async unsafe extern "C" fn foo()
1387 fn test_hover_trait_show_qualifiers() {
1389 r"unsafe trait foo<|>() {}",
1406 fn test_hover_extern_crate() {
1409 //- /main.rs crate:main deps:std
1410 extern crate st<|>d;
1411 //- /std/lib.rs crate:std
1412 //! Standard library for this test
1419 Standard library for this test
1427 //- /main.rs crate:main deps:std
1428 extern crate std as ab<|>c;
1429 //- /std/lib.rs crate:std
1430 //! Standard library for this test
1437 Standard library for this test
1446 fn test_hover_mod_with_same_name_as_function() {
1449 use self::m<|>y::Bar;
1450 mod my { pub struct Bar; }
1469 fn test_hover_struct_doc_comment() {
1475 fn foo() { let bar = Ba<|>r; }
1496 fn test_hover_struct_doc_attr() {
1502 fn foo() { let bar = Ba<|>r; }
1523 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1527 #[doc = "bar docs 1"]
1528 #[doc = "bar docs 2"]
1531 fn foo() { let bar = Ba<|>r; }
1554 fn test_hover_path_link() {
1558 /// [Foo](struct.Foo.html)
1574 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1580 fn test_hover_path_link_no_strip() {
1584 /// [struct Foo](struct.Foo.html)
1600 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1605 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1607 fn test_hover_path_link_field() {
1612 /// [Foo](struct.Foo.html)
1629 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1635 fn test_hover_intra_link() {
1657 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1663 fn test_hover_intra_link_html_root_url() {
1666 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1687 [Foo](https://example.com/test/foo/struct.Foo.html)
1693 fn test_hover_intra_link_shortlink() {
1713 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1719 fn test_hover_intra_link_shortlink_code() {
1739 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1745 fn test_hover_intra_link_namespaced() {
1766 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1772 fn test_hover_intra_link_shortlink_namspaced_code() {
1792 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1798 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1818 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1824 fn test_hover_intra_link_reference() {
1846 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1852 fn test_hover_external_url() {
1856 /// [external](https://www.google.com)
1872 [external](https://www.google.com)
1877 // Check that we don't rewrite links which we can't identify
1879 fn test_hover_unknown_target() {
1905 fn test_doc_links_enum_variant() {
1926 [E](https://docs.rs/test/*/test/enum.E.html)
1932 fn test_doc_links_field() {
1953 [`S`](https://docs.rs/test/*/test/struct.S.html)
1959 fn test_hover_no_links() {
1960 check_hover_no_links(
1963 /// case 1. bare URL: https://www.example.com/
1964 /// case 2. inline URL with title: [example](https://www.example.com/)
1965 /// case 3. code refrence: [`Result`]
1966 /// case 4. code refrence but miss footnote: [`String`]
1967 /// case 5. autolink: <http://www.example.com/>
1968 /// case 6. email address: <test@example.com>
1969 /// case 7. refrence: [example][example]
1970 /// case 8. collapsed link: [example][]
1971 /// case 9. shortcut link: [example]
1972 /// case 10. inline without URL: [example]()
1973 /// case 11. refrence: [foo][foo]
1974 /// case 12. refrence: [foo][bar]
1975 /// case 13. collapsed link: [foo][]
1976 /// case 14. shortcut link: [foo]
1977 /// case 15. inline without URL: [foo]()
1978 /// case 16. just escaped text: \[foo]
1979 /// case 17. inline link: [Foo](foo::Foo)
1981 /// [`Result`]: ../../std/result/enum.Result.html
1982 /// [^example]: https://www.example.com/
1999 case 1. bare URL: https://www.example.com/
2000 case 2. inline URL with title: [example](https://www.example.com/)
2001 case 3. code refrence: `Result`
2002 case 4. code refrence but miss footnote: `String`
2003 case 5. autolink: http://www.example.com/
2004 case 6. email address: test@example.com
2005 case 7. refrence: example
2006 case 8. collapsed link: example
2007 case 9. shortcut link: example
2008 case 10. inline without URL: example
2009 case 11. refrence: foo
2010 case 12. refrence: foo
2011 case 13. collapsed link: foo
2012 case 14. shortcut link: foo
2013 case 15. inline without URL: foo
2014 case 16. just escaped text: \[foo]
2015 case 17. inline link: Foo
2017 [^example]: https://www.example.com/
2023 fn test_hover_macro_generated_struct_fn_doc_comment() {
2024 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2040 fn foo() { let bar = Bar; bar.fo<|>o(); }
2061 fn test_hover_macro_generated_struct_fn_doc_attr() {
2062 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2070 #[doc = "Do the foo"]
2078 fn foo() { let bar = Bar; bar.fo<|>o(); }
2099 fn test_hover_trait_has_impl_action() {
2101 r#"trait foo<|>() {}"#,
2118 fn test_hover_struct_has_impl_action() {
2120 r"struct foo<|>() {}",
2137 fn test_hover_union_has_impl_action() {
2139 r#"union foo<|>() {}"#,
2156 fn test_hover_enum_has_impl_action() {
2158 r"enum foo<|>() { A, B }",
2175 fn test_hover_test_has_action() {
2185 nav: NavigationTarget {
2190 focus_range: 11..19,
2211 fn test_hover_test_mod_has_action() {
2223 nav: NavigationTarget {
2244 fn test_hover_struct_has_goto_type_action() {
2249 fn main() { let s<|>t = S{ f1:0 }; }
2256 mod_path: "test::S",
2257 nav: NavigationTarget {
2265 description: "struct S",
2276 fn test_hover_generic_struct_has_goto_type_actions() {
2280 struct S<T>{ f1: T }
2282 fn main() { let s<|>t = S{ f1:Arg(0) }; }
2289 mod_path: "test::S",
2290 nav: NavigationTarget {
2295 focus_range: 24..25,
2298 description: "struct S",
2302 mod_path: "test::Arg",
2303 nav: NavigationTarget {
2311 description: "struct Arg",
2322 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2326 struct S<T>{ f1: T }
2328 fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2335 mod_path: "test::S",
2336 nav: NavigationTarget {
2341 focus_range: 24..25,
2344 description: "struct S",
2348 mod_path: "test::Arg",
2349 nav: NavigationTarget {
2357 description: "struct Arg",
2368 fn test_hover_tuple_has_goto_type_actions() {
2377 fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2384 mod_path: "test::A",
2385 nav: NavigationTarget {
2393 description: "struct A",
2397 mod_path: "test::B",
2398 nav: NavigationTarget {
2403 focus_range: 22..23,
2406 description: "struct B",
2410 mod_path: "test::M::C",
2411 nav: NavigationTarget {
2416 focus_range: 53..54,
2419 description: "pub struct C",
2430 fn test_hover_return_impl_trait_has_goto_type_action() {
2434 fn foo() -> impl Foo {}
2436 fn main() { let s<|>t = foo(); }
2443 mod_path: "test::Foo",
2444 nav: NavigationTarget {
2452 description: "trait Foo",
2463 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2468 fn foo() -> impl Foo<S> {}
2470 fn main() { let s<|>t = foo(); }
2477 mod_path: "test::Foo",
2478 nav: NavigationTarget {
2486 description: "trait Foo",
2490 mod_path: "test::S",
2491 nav: NavigationTarget {
2496 focus_range: 23..24,
2499 description: "struct S",
2510 fn test_hover_return_impl_traits_has_goto_type_action() {
2515 fn foo() -> impl Foo + Bar {}
2517 fn main() { let s<|>t = foo(); }
2524 mod_path: "test::Foo",
2525 nav: NavigationTarget {
2533 description: "trait Foo",
2537 mod_path: "test::Bar",
2538 nav: NavigationTarget {
2543 focus_range: 19..22,
2546 description: "trait Bar",
2557 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2565 fn foo() -> impl Foo<S1> + Bar<S2> {}
2567 fn main() { let s<|>t = foo(); }
2574 mod_path: "test::Foo",
2575 nav: NavigationTarget {
2583 description: "trait Foo",
2587 mod_path: "test::Bar",
2588 nav: NavigationTarget {
2593 focus_range: 22..25,
2596 description: "trait Bar",
2600 mod_path: "test::S1",
2601 nav: NavigationTarget {
2606 focus_range: 39..41,
2609 description: "struct S1",
2613 mod_path: "test::S2",
2614 nav: NavigationTarget {
2619 focus_range: 52..54,
2622 description: "struct S2",
2633 fn test_hover_arg_impl_trait_has_goto_type_action() {
2637 fn foo(ar<|>g: &impl Foo) {}
2644 mod_path: "test::Foo",
2645 nav: NavigationTarget {
2653 description: "trait Foo",
2664 fn test_hover_arg_impl_traits_has_goto_type_action() {
2671 fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2678 mod_path: "test::Foo",
2679 nav: NavigationTarget {
2687 description: "trait Foo",
2691 mod_path: "test::Bar",
2692 nav: NavigationTarget {
2697 focus_range: 19..22,
2700 description: "trait Bar",
2704 mod_path: "test::S",
2705 nav: NavigationTarget {
2710 focus_range: 36..37,
2713 description: "struct S",
2724 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2729 let fo<|>o = async { S };
2732 #[prelude_import] use future::*;
2734 #[lang = "future_trait"]
2735 pub trait Future { type Output; }
2743 mod_path: "test::future::Future",
2744 nav: NavigationTarget {
2748 full_range: 101..163,
2749 focus_range: 140..146,
2752 description: "pub trait Future",
2756 mod_path: "test::S",
2757 nav: NavigationTarget {
2765 description: "struct S",
2776 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2781 fn foo(ar<|>g: &impl Foo<S>) {}
2788 mod_path: "test::Foo",
2789 nav: NavigationTarget {
2797 description: "trait Foo",
2801 mod_path: "test::S",
2802 nav: NavigationTarget {
2807 focus_range: 23..24,
2810 description: "struct S",
2821 fn test_hover_dyn_return_has_goto_type_action() {
2829 fn foo() -> B<dyn Foo> {}
2831 fn main() { let s<|>t = foo(); }
2838 mod_path: "test::B",
2839 nav: NavigationTarget {
2844 focus_range: 49..50,
2847 description: "struct B",
2851 mod_path: "test::Foo",
2852 nav: NavigationTarget {
2860 description: "trait Foo",
2871 fn test_hover_dyn_arg_has_goto_type_action() {
2875 fn foo(ar<|>g: &dyn Foo) {}
2882 mod_path: "test::Foo",
2883 nav: NavigationTarget {
2891 description: "trait Foo",
2902 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2907 fn foo(ar<|>g: &dyn Foo<S>) {}
2914 mod_path: "test::Foo",
2915 nav: NavigationTarget {
2923 description: "trait Foo",
2927 mod_path: "test::S",
2928 nav: NavigationTarget {
2933 focus_range: 23..24,
2936 description: "struct S",
2947 fn test_hover_goto_type_action_links_order() {
2950 trait ImplTrait<T> {}
2951 trait DynTrait<T> {}
2955 fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2962 mod_path: "test::ImplTrait",
2963 nav: NavigationTarget {
2971 description: "trait ImplTrait",
2975 mod_path: "test::B",
2976 nav: NavigationTarget {
2981 focus_range: 50..51,
2984 description: "struct B",
2988 mod_path: "test::DynTrait",
2989 nav: NavigationTarget {
2994 focus_range: 28..36,
2997 description: "trait DynTrait",
3001 mod_path: "test::S",
3002 nav: NavigationTarget {
3007 focus_range: 65..66,
3010 description: "struct S",
3021 fn test_hover_associated_type_has_goto_type_action() {
3026 fn get(self) -> Self::Item {}
3032 impl Foo for S { type Item = Bar; }
3034 fn test() -> impl Foo { S {} }
3036 fn main() { let s<|>t = test().get(); }
3043 mod_path: "test::Foo",
3044 nav: NavigationTarget {
3052 description: "trait Foo",
3063 fn hover_displays_normalized_crate_names() {
3066 //- /lib.rs crate:name-with-dashes
3068 pub struct Thing { x: u32 }
3071 pub fn new() -> Thing { Thing { x: 0 } }
3075 //- /main.rs crate:main deps:name-with-dashes
3076 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
3082 name_with_dashes::wrapper::Thing
3086 pub fn new() -> Thing
3093 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3102 let S { f<|> } = &s;
3116 fn hover_self_param_shows_type() {
3134 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3140 fn bar(sel<|>f: Arc<Foo>) {}
3153 fn hover_doc_outer_inner() {
3160 /// This comment belongs to the function
3184 fn hover_doc_outer_inner_attribue() {
3187 #[doc = "Be quick;"]
3189 #![doc = "time is mana"]
3191 #[doc = "This comment belongs to the function"]
3215 fn hover_comments_dont_highlight_parent() {
3216 check_hover_no_result(