]> git.lizzy.rs Git - rust.git/blob - crates/ide/src/hover.rs
1c6d36939b23ccee6012cba353e4632a2bf0ef44
[rust.git] / crates / ide / src / hover.rs
1 use either::Either;
2 use hir::{
3     AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, InFile, Module,
4     ModuleDef, Semantics,
5 };
6 use ide_db::{
7     base_db::SourceDatabase,
8     defs::{Definition, NameClass, NameRefClass},
9     helpers::{
10         generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES},
11         FamousDefs,
12     },
13     RootDatabase,
14 };
15 use itertools::Itertools;
16 use stdx::format_to;
17 use syntax::{
18     algo, ast, match_ast, AstNode, AstToken, Direction, SyntaxKind::*, SyntaxToken, TokenAtOffset,
19     T,
20 };
21
22 use crate::{
23     display::{macro_label, TryToNav},
24     doc_links::{
25         doc_attributes, extract_definitions_from_markdown, remove_links, resolve_doc_path_for_def,
26         rewrite_links,
27     },
28     markdown_remove::remove_markdown,
29     markup::Markup,
30     runnables::{runnable_fn, runnable_mod},
31     FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
32 };
33
34 #[derive(Clone, Debug, PartialEq, Eq)]
35 pub struct HoverConfig {
36     pub implementations: bool,
37     pub references: bool,
38     pub run: bool,
39     pub debug: bool,
40     pub goto_type_def: bool,
41     pub links_in_hover: bool,
42     pub markdown: bool,
43 }
44
45 impl HoverConfig {
46     pub const NO_ACTIONS: Self = Self {
47         implementations: false,
48         references: false,
49         run: false,
50         debug: false,
51         goto_type_def: false,
52         links_in_hover: true,
53         markdown: true,
54     };
55
56     pub fn any(&self) -> bool {
57         self.implementations || self.references || self.runnable() || self.goto_type_def
58     }
59
60     pub fn none(&self) -> bool {
61         !self.any()
62     }
63
64     pub fn runnable(&self) -> bool {
65         self.run || self.debug
66     }
67 }
68
69 #[derive(Debug, Clone)]
70 pub enum HoverAction {
71     Runnable(Runnable),
72     Implementation(FilePosition),
73     Reference(FilePosition),
74     GoToType(Vec<HoverGotoTypeData>),
75 }
76
77 #[derive(Debug, Clone, Eq, PartialEq)]
78 pub struct HoverGotoTypeData {
79     pub mod_path: String,
80     pub nav: NavigationTarget,
81 }
82
83 /// Contains the results when hovering over an item
84 #[derive(Debug, Default)]
85 pub struct HoverResult {
86     pub markup: Markup,
87     pub actions: Vec<HoverAction>,
88 }
89
90 // Feature: Hover
91 //
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.
94 //
95 // image::https://user-images.githubusercontent.com/48062697/113020658-b5f98b80-917a-11eb-9f88-3dbc27320c95.gif[]
96 pub(crate) fn hover(
97     db: &RootDatabase,
98     position: FilePosition,
99     links_in_hover: bool,
100     markdown: bool,
101 ) -> Option<RangeInfo<HoverResult>> {
102     let sema = Semantics::new(db);
103     let file = sema.parse(position.file_id).syntax().clone();
104     let token = pick_best(file.token_at_offset(position.offset))?;
105     let token = sema.descend_into_macros(token);
106
107     let mut res = HoverResult::default();
108
109     let node = token.parent()?;
110     let mut range = None;
111     let definition = match_ast! {
112         match node {
113             // we don't use NameClass::referenced_or_defined here as we do not want to resolve
114             // field pattern shorthands to their definition
115             ast::Name(name) => NameClass::classify(&sema, &name).and_then(|class| match class {
116                 NameClass::ConstReference(def) => Some(def),
117                 def => def.defined(db),
118             }),
119             ast::NameRef(name_ref) => {
120                 NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(db))
121             },
122             ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime).map_or_else(
123                 || NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(db)),
124                 |d| d.defined(db),
125             ),
126
127             _ => {
128                 if ast::Comment::cast(token.clone()).is_some() {
129                     cov_mark::hit!(no_highlight_on_comment_hover);
130                     let (attributes, def) = doc_attributes(&sema, &node)?;
131                     let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
132                     let (idl_range, link, ns) =
133                         extract_definitions_from_markdown(docs.as_str()).into_iter().find_map(|(range, link, ns)| {
134                             let InFile { file_id, value: range } = doc_mapping.map(range.clone())?;
135                             if file_id == position.file_id.into() && range.contains(position.offset) {
136                                 Some((range, link, ns))
137                             } else {
138                                 None
139                             }
140                         })?;
141                     range = Some(idl_range);
142                     resolve_doc_path_for_def(db, def, &link, ns).map(Definition::ModuleDef)
143                 } else if let res@Some(_) = try_hover_for_attribute(&token) {
144                     return res;
145                 } else {
146                     None
147                 }
148             },
149         }
150     };
151
152     if let Some(definition) = definition {
153         let famous_defs = match &definition {
154             Definition::ModuleDef(ModuleDef::BuiltinType(_)) => {
155                 Some(FamousDefs(&sema, sema.scope(&node).krate()))
156             }
157             _ => None,
158         };
159         if let Some(markup) = hover_for_definition(db, definition, famous_defs.as_ref()) {
160             res.markup = process_markup(sema.db, definition, &markup, links_in_hover, markdown);
161             if let Some(action) = show_implementations_action(db, definition) {
162                 res.actions.push(action);
163             }
164
165             if let Some(action) = show_fn_references_action(db, definition) {
166                 res.actions.push(action);
167             }
168
169             if let Some(action) = runnable_action(&sema, definition, position.file_id) {
170                 res.actions.push(action);
171             }
172
173             if let Some(action) = goto_type_action(db, definition) {
174                 res.actions.push(action);
175             }
176
177             let range = range.unwrap_or_else(|| sema.original_range(&node).range);
178             return Some(RangeInfo::new(range, res));
179         }
180     }
181
182     if let res @ Some(_) = hover_for_keyword(&sema, links_in_hover, markdown, &token) {
183         return res;
184     }
185
186     let node = token
187         .ancestors()
188         .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
189
190     let ty = match_ast! {
191         match node {
192             ast::Expr(it) => sema.type_of_expr(&it)?,
193             ast::Pat(it) => sema.type_of_pat(&it)?,
194             // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
195             // (e.g expanding a builtin macro). So we give up here.
196             ast::MacroCall(_it) => return None,
197             _ => return None,
198         }
199     };
200
201     res.markup = if markdown {
202         Markup::fenced_block(&ty.display(db))
203     } else {
204         ty.display(db).to_string().into()
205     };
206     let range = sema.original_range(&node).range;
207     Some(RangeInfo::new(range, res))
208 }
209
210 fn try_hover_for_attribute(token: &SyntaxToken) -> Option<RangeInfo<HoverResult>> {
211     let attr = token.ancestors().find_map(ast::Attr::cast)?;
212     let (path, tt) = attr.as_simple_call()?;
213     if !tt.syntax().text_range().contains(token.text_range().start()) {
214         return None;
215     }
216     let (is_clippy, lints) = match &*path {
217         "feature" => (false, FEATURES),
218         "allow" | "deny" | "forbid" | "warn" => {
219             let is_clippy = algo::non_trivia_sibling(token.clone().into(), Direction::Prev)
220                 .filter(|t| t.kind() == T![:])
221                 .and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
222                 .filter(|t| t.kind() == T![:])
223                 .and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
224                 .map_or(false, |t| {
225                     t.kind() == T![ident] && t.into_token().map_or(false, |t| t.text() == "clippy")
226                 });
227             if is_clippy {
228                 (true, CLIPPY_LINTS)
229             } else {
230                 (false, DEFAULT_LINTS)
231             }
232         }
233         _ => return None,
234     };
235
236     let tmp;
237     let needle = if is_clippy {
238         tmp = format!("clippy::{}", token.text());
239         &tmp
240     } else {
241         &*token.text()
242     };
243
244     let lint =
245         lints.binary_search_by_key(&needle, |lint| lint.label).ok().map(|idx| &lints[idx])?;
246     Some(RangeInfo::new(
247         token.text_range(),
248         HoverResult {
249             markup: Markup::from(format!("```\n{}\n```\n___\n\n{}", lint.label, lint.description)),
250             ..Default::default()
251         },
252     ))
253 }
254
255 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
256     fn to_action(nav_target: NavigationTarget) -> HoverAction {
257         HoverAction::Implementation(FilePosition {
258             file_id: nav_target.file_id,
259             offset: nav_target.focus_or_full_range().start(),
260         })
261     }
262
263     let adt = match def {
264         Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
265         Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
266         Definition::SelfType(it) => it.self_ty(db).as_adt(),
267         _ => None,
268     }?;
269     adt.try_to_nav(db).map(to_action)
270 }
271
272 fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
273     match def {
274         Definition::ModuleDef(ModuleDef::Function(it)) => it.try_to_nav(db).map(|nav_target| {
275             HoverAction::Reference(FilePosition {
276                 file_id: nav_target.file_id,
277                 offset: nav_target.focus_or_full_range().start(),
278             })
279         }),
280         _ => None,
281     }
282 }
283
284 fn runnable_action(
285     sema: &Semantics<RootDatabase>,
286     def: Definition,
287     file_id: FileId,
288 ) -> Option<HoverAction> {
289     match def {
290         Definition::ModuleDef(it) => match it {
291             ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)),
292             ModuleDef::Function(func) => {
293                 let src = func.source(sema.db)?;
294                 if src.file_id != file_id.into() {
295                     cov_mark::hit!(hover_macro_generated_struct_fn_doc_comment);
296                     cov_mark::hit!(hover_macro_generated_struct_fn_doc_attr);
297                     return None;
298                 }
299
300                 runnable_fn(&sema, func).map(HoverAction::Runnable)
301             }
302             _ => None,
303         },
304         _ => None,
305     }
306 }
307
308 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
309     let mut targets: Vec<ModuleDef> = Vec::new();
310     let mut push_new_def = |item: ModuleDef| {
311         if !targets.contains(&item) {
312             targets.push(item);
313         }
314     };
315
316     if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
317         it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
318     } else {
319         let ty = match def {
320             Definition::Local(it) => it.ty(db),
321             Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
322             _ => return None,
323         };
324
325         ty.walk(db, |t| {
326             if let Some(adt) = t.as_adt() {
327                 push_new_def(adt.into());
328             } else if let Some(trait_) = t.as_dyn_trait() {
329                 push_new_def(trait_.into());
330             } else if let Some(traits) = t.as_impl_traits(db) {
331                 traits.into_iter().for_each(|it| push_new_def(it.into()));
332             } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
333                 push_new_def(trait_.into());
334             }
335         });
336     }
337
338     let targets = targets
339         .into_iter()
340         .filter_map(|it| {
341             Some(HoverGotoTypeData {
342                 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
343                 nav: it.try_to_nav(db)?,
344             })
345         })
346         .collect();
347
348     Some(HoverAction::GoToType(targets))
349 }
350
351 fn hover_markup(
352     docs: Option<String>,
353     desc: Option<String>,
354     mod_path: Option<String>,
355 ) -> Option<Markup> {
356     match desc {
357         Some(desc) => {
358             let mut buf = String::new();
359
360             if let Some(mod_path) = mod_path {
361                 if !mod_path.is_empty() {
362                     format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
363                 }
364             }
365             format_to!(buf, "```rust\n{}\n```", desc);
366
367             if let Some(doc) = docs {
368                 format_to!(buf, "\n___\n\n{}", doc);
369             }
370             Some(buf.into())
371         }
372         None => docs.map(Markup::from),
373     }
374 }
375
376 fn process_markup(
377     db: &RootDatabase,
378     def: Definition,
379     markup: &Markup,
380     links_in_hover: bool,
381     markdown: bool,
382 ) -> Markup {
383     let markup = markup.as_str();
384     let markup = if !markdown {
385         remove_markdown(markup)
386     } else if links_in_hover {
387         rewrite_links(db, markup, &def)
388     } else {
389         remove_links(markup)
390     };
391     Markup::from(markup)
392 }
393
394 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
395     match def {
396         Definition::Field(f) => Some(f.parent_def(db).name(db)),
397         Definition::Local(l) => l.parent(db).name(db),
398         Definition::ModuleDef(md) => match md {
399             ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
400                 AssocItemContainer::Trait(t) => Some(t.name(db)),
401                 AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)),
402             },
403             ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
404             _ => None,
405         },
406         _ => None,
407     }
408     .map(|name| name.to_string())
409 }
410
411 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
412     let crate_name =
413         db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
414     let module_path = module
415         .path_to_root(db)
416         .into_iter()
417         .rev()
418         .flat_map(|it| it.name(db).map(|name| name.to_string()));
419     crate_name.into_iter().chain(module_path).chain(item_name).join("::")
420 }
421
422 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
423     def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
424 }
425
426 fn hover_for_definition(
427     db: &RootDatabase,
428     def: Definition,
429     famous_defs: Option<&FamousDefs>,
430 ) -> Option<Markup> {
431     let mod_path = definition_mod_path(db, &def);
432     return match def {
433         Definition::Macro(it) => match &it.source(db)?.value {
434             Either::Left(mac) => {
435                 let label = macro_label(&mac);
436                 from_def_source_labeled(db, it, Some(label), mod_path)
437             }
438             Either::Right(_) => {
439                 // FIXME
440                 None
441             }
442         },
443         Definition::Field(def) => from_hir_fmt(db, def, mod_path),
444         Definition::ModuleDef(it) => match it {
445             ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path),
446             ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path),
447             ModuleDef::Adt(it) => from_hir_fmt(db, it, mod_path),
448             ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path),
449             ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path),
450             ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path),
451             ModuleDef::Trait(it) => from_hir_fmt(db, it, mod_path),
452             ModuleDef::TypeAlias(it) => from_hir_fmt(db, it, mod_path),
453             ModuleDef::BuiltinType(it) => famous_defs
454                 .and_then(|fd| hover_for_builtin(fd, it))
455                 .or_else(|| Some(Markup::fenced_block(&it.name()))),
456         },
457         Definition::Local(it) => hover_for_local(it, db),
458         Definition::SelfType(impl_def) => {
459             impl_def.self_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path))
460         }
461         Definition::GenericParam(it) => from_hir_fmt(db, it, None),
462         Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
463     };
464
465     fn from_hir_fmt<D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
466     where
467         D: HasAttrs + HirDisplay,
468     {
469         let label = def.display(db).to_string();
470         from_def_source_labeled(db, def, Some(label), mod_path)
471     }
472
473     fn from_def_source_labeled<D>(
474         db: &RootDatabase,
475         def: D,
476         short_label: Option<String>,
477         mod_path: Option<String>,
478     ) -> Option<Markup>
479     where
480         D: HasAttrs,
481     {
482         let docs = def.attrs(db).docs().map(Into::into);
483         hover_markup(docs, short_label, mod_path)
484     }
485 }
486
487 fn hover_for_local(it: hir::Local, db: &RootDatabase) -> Option<Markup> {
488     let ty = it.ty(db);
489     let ty = ty.display(db);
490     let is_mut = if it.is_mut(db) { "mut " } else { "" };
491     let desc = match it.source(db).value {
492         Either::Left(ident) => {
493             let name = it.name(db).unwrap();
494             let let_kw = if ident
495                 .syntax()
496                 .parent()
497                 .map_or(false, |p| p.kind() == LET_STMT || p.kind() == CONDITION)
498             {
499                 "let "
500             } else {
501                 ""
502             };
503             format!("{}{}{}: {}", let_kw, is_mut, name, ty)
504         }
505         Either::Right(_) => format!("{}self: {}", is_mut, ty),
506     };
507     hover_markup(None, Some(desc), None)
508 }
509
510 fn hover_for_keyword(
511     sema: &Semantics<RootDatabase>,
512     links_in_hover: bool,
513     markdown: bool,
514     token: &SyntaxToken,
515 ) -> Option<RangeInfo<HoverResult>> {
516     if !token.kind().is_keyword() {
517         return None;
518     }
519     let famous_defs = FamousDefs(&sema, sema.scope(&token.parent()?).krate());
520     // std exposes {}_keyword modules with docstrings on the root to document keywords
521     let keyword_mod = format!("{}_keyword", token.text());
522     let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
523     let docs = doc_owner.attrs(sema.db).docs()?;
524     let markup = process_markup(
525         sema.db,
526         Definition::ModuleDef(doc_owner.into()),
527         &hover_markup(Some(docs.into()), Some(token.text().into()), None)?,
528         links_in_hover,
529         markdown,
530     );
531     Some(RangeInfo::new(token.text_range(), HoverResult { markup, actions: Default::default() }))
532 }
533
534 fn hover_for_builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option<Markup> {
535     // std exposes prim_{} modules with docstrings on the root to document the builtins
536     let primitive_mod = format!("prim_{}", builtin.name());
537     let doc_owner = find_std_module(famous_defs, &primitive_mod)?;
538     let docs = doc_owner.attrs(famous_defs.0.db).docs()?;
539     hover_markup(Some(docs.into()), Some(builtin.name().to_string()), None)
540 }
541
542 fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module> {
543     let db = famous_defs.0.db;
544     let std_crate = famous_defs.std()?;
545     let std_root_module = std_crate.root_module(db);
546     std_root_module
547         .children(db)
548         .find(|module| module.name(db).map_or(false, |module| module.to_string() == name))
549 }
550
551 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
552     return tokens.max_by_key(priority);
553
554     fn priority(n: &SyntaxToken) -> usize {
555         match n.kind() {
556             IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
557             T!['('] | T![')'] => 2,
558             kind if kind.is_trivia() => 0,
559             _ => 1,
560         }
561     }
562 }
563
564 #[cfg(test)]
565 mod tests {
566     use expect_test::{expect, Expect};
567     use ide_db::base_db::FileLoader;
568
569     use crate::fixture;
570
571     use super::*;
572
573     fn check_hover_no_result(ra_fixture: &str) {
574         let (analysis, position) = fixture::position(ra_fixture);
575         assert!(analysis.hover(position, true, true).unwrap().is_none());
576     }
577
578     fn check(ra_fixture: &str, expect: Expect) {
579         let (analysis, position) = fixture::position(ra_fixture);
580         let hover = analysis.hover(position, true, true).unwrap().unwrap();
581
582         let content = analysis.db.file_text(position.file_id);
583         let hovered_element = &content[hover.range];
584
585         let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
586         expect.assert_eq(&actual)
587     }
588
589     fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
590         let (analysis, position) = fixture::position(ra_fixture);
591         let hover = analysis.hover(position, false, true).unwrap().unwrap();
592
593         let content = analysis.db.file_text(position.file_id);
594         let hovered_element = &content[hover.range];
595
596         let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
597         expect.assert_eq(&actual)
598     }
599
600     fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
601         let (analysis, position) = fixture::position(ra_fixture);
602         let hover = analysis.hover(position, true, false).unwrap().unwrap();
603
604         let content = analysis.db.file_text(position.file_id);
605         let hovered_element = &content[hover.range];
606
607         let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
608         expect.assert_eq(&actual)
609     }
610
611     fn check_actions(ra_fixture: &str, expect: Expect) {
612         let (analysis, position) = fixture::position(ra_fixture);
613         let hover = analysis.hover(position, true, true).unwrap().unwrap();
614         expect.assert_debug_eq(&hover.info.actions)
615     }
616
617     #[test]
618     fn hover_shows_type_of_an_expression() {
619         check(
620             r#"
621 pub fn foo() -> u32 { 1 }
622
623 fn main() {
624     let foo_test = foo()$0;
625 }
626 "#,
627             expect![[r#"
628                 *foo()*
629                 ```rust
630                 u32
631                 ```
632             "#]],
633         );
634     }
635
636     #[test]
637     fn hover_remove_markdown_if_configured() {
638         check_hover_no_markdown(
639             r#"
640 pub fn foo() -> u32 { 1 }
641
642 fn main() {
643     let foo_test = foo()$0;
644 }
645 "#,
646             expect![[r#"
647                 *foo()*
648                 u32
649             "#]],
650         );
651     }
652
653     #[test]
654     fn hover_shows_long_type_of_an_expression() {
655         check(
656             r#"
657 struct Scan<A, B, C> { a: A, b: B, c: C }
658 struct Iter<I> { inner: I }
659 enum Option<T> { Some(T), None }
660
661 struct OtherStruct<T> { i: T }
662
663 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
664     Iter { inner: Scan { a, b, c } }
665 }
666
667 fn main() {
668     let num: i32 = 55;
669     let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
670         Option::Some(*memo + value)
671     };
672     let number = 5u32;
673     let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
674 }
675 "#,
676             expect![[r#"
677                 *iter*
678
679                 ```rust
680                 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
681                 ```
682             "#]],
683         );
684     }
685
686     #[test]
687     fn hover_shows_fn_signature() {
688         // Single file with result
689         check(
690             r#"
691 pub fn foo() -> u32 { 1 }
692
693 fn main() { let foo_test = fo$0o(); }
694 "#,
695             expect![[r#"
696                 *foo*
697
698                 ```rust
699                 test
700                 ```
701
702                 ```rust
703                 pub fn foo() -> u32
704                 ```
705             "#]],
706         );
707
708         // Multiple candidates but results are ambiguous.
709         check(
710             r#"
711 //- /a.rs
712 pub fn foo() -> u32 { 1 }
713
714 //- /b.rs
715 pub fn foo() -> &str { "" }
716
717 //- /c.rs
718 pub fn foo(a: u32, b: u32) {}
719
720 //- /main.rs
721 mod a;
722 mod b;
723 mod c;
724
725 fn main() { let foo_test = fo$0o(); }
726         "#,
727             expect![[r#"
728                 *foo*
729                 ```rust
730                 {unknown}
731                 ```
732             "#]],
733         );
734     }
735
736     #[test]
737     fn hover_shows_fn_signature_with_type_params() {
738         check(
739             r#"
740 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
741
742 fn main() { let foo_test = fo$0o(); }
743         "#,
744             expect![[r#"
745                 *foo*
746
747                 ```rust
748                 test
749                 ```
750
751                 ```rust
752                 pub fn foo<'a, T>(b: &'a T) -> &'a str
753                 where
754                     T: AsRef<str>,
755                 ```
756             "#]],
757         );
758     }
759
760     #[test]
761     fn hover_shows_fn_signature_on_fn_name() {
762         check(
763             r#"
764 pub fn foo$0(a: u32, b: u32) -> u32 {}
765
766 fn main() { }
767 "#,
768             expect![[r#"
769                 *foo*
770
771                 ```rust
772                 test
773                 ```
774
775                 ```rust
776                 pub fn foo(a: u32, b: u32) -> u32
777                 ```
778             "#]],
779         );
780     }
781
782     #[test]
783     fn hover_shows_fn_doc() {
784         check(
785             r#"
786 /// # Example
787 /// ```
788 /// # use std::path::Path;
789 /// #
790 /// foo(Path::new("hello, world!"))
791 /// ```
792 pub fn foo$0(_: &Path) {}
793
794 fn main() { }
795 "#,
796             expect![[r##"
797                 *foo*
798
799                 ```rust
800                 test
801                 ```
802
803                 ```rust
804                 pub fn foo(_: &Path)
805                 ```
806
807                 ---
808
809                 # Example
810
811                 ```
812                 # use std::path::Path;
813                 #
814                 foo(Path::new("hello, world!"))
815                 ```
816             "##]],
817         );
818     }
819
820     #[test]
821     fn hover_shows_fn_doc_attr_raw_string() {
822         check(
823             r##"
824 #[doc = r#"Raw string doc attr"#]
825 pub fn foo$0(_: &Path) {}
826
827 fn main() { }
828 "##,
829             expect![[r##"
830                 *foo*
831
832                 ```rust
833                 test
834                 ```
835
836                 ```rust
837                 pub fn foo(_: &Path)
838                 ```
839
840                 ---
841
842                 Raw string doc attr
843             "##]],
844         );
845     }
846
847     #[test]
848     fn hover_shows_struct_field_info() {
849         // Hovering over the field when instantiating
850         check(
851             r#"
852 struct Foo { field_a: u32 }
853
854 fn main() {
855     let foo = Foo { field_a$0: 0, };
856 }
857 "#,
858             expect![[r#"
859                 *field_a*
860
861                 ```rust
862                 test::Foo
863                 ```
864
865                 ```rust
866                 field_a: u32
867                 ```
868             "#]],
869         );
870
871         // Hovering over the field in the definition
872         check(
873             r#"
874 struct Foo { field_a$0: u32 }
875
876 fn main() {
877     let foo = Foo { field_a: 0 };
878 }
879 "#,
880             expect![[r#"
881                 *field_a*
882
883                 ```rust
884                 test::Foo
885                 ```
886
887                 ```rust
888                 field_a: u32
889                 ```
890             "#]],
891         );
892     }
893
894     #[test]
895     fn hover_const_static() {
896         check(
897             r#"const foo$0: u32 = 123;"#,
898             expect![[r#"
899                 *foo*
900
901                 ```rust
902                 test
903                 ```
904
905                 ```rust
906                 const foo: u32
907                 ```
908             "#]],
909         );
910         check(
911             r#"static foo$0: u32 = 456;"#,
912             expect![[r#"
913                 *foo*
914
915                 ```rust
916                 test
917                 ```
918
919                 ```rust
920                 static foo: u32
921                 ```
922             "#]],
923         );
924     }
925
926     #[test]
927     fn hover_default_generic_types() {
928         check(
929             r#"
930 struct Test<K, T = u8> { k: K, t: T }
931
932 fn main() {
933     let zz$0 = Test { t: 23u8, k: 33 };
934 }"#,
935             expect![[r#"
936                 *zz*
937
938                 ```rust
939                 let zz: Test<i32, u8>
940                 ```
941             "#]],
942         );
943     }
944
945     #[test]
946     fn hover_some() {
947         check(
948             r#"
949 enum Option<T> { Some(T) }
950 use Option::Some;
951
952 fn main() { So$0me(12); }
953 "#,
954             expect![[r#"
955                 *Some*
956
957                 ```rust
958                 test::Option
959                 ```
960
961                 ```rust
962                 Some(T)
963                 ```
964             "#]],
965         );
966
967         check(
968             r#"
969 enum Option<T> { Some(T) }
970 use Option::Some;
971
972 fn main() { let b$0ar = Some(12); }
973 "#,
974             expect![[r#"
975                 *bar*
976
977                 ```rust
978                 let bar: Option<i32>
979                 ```
980             "#]],
981         );
982     }
983
984     #[test]
985     fn hover_enum_variant() {
986         check(
987             r#"
988 enum Option<T> {
989     /// The None variant
990     Non$0e
991 }
992 "#,
993             expect![[r#"
994                 *None*
995
996                 ```rust
997                 test::Option
998                 ```
999
1000                 ```rust
1001                 None
1002                 ```
1003
1004                 ---
1005
1006                 The None variant
1007             "#]],
1008         );
1009
1010         check(
1011             r#"
1012 enum Option<T> {
1013     /// The Some variant
1014     Some(T)
1015 }
1016 fn main() {
1017     let s = Option::Som$0e(12);
1018 }
1019 "#,
1020             expect![[r#"
1021                 *Some*
1022
1023                 ```rust
1024                 test::Option
1025                 ```
1026
1027                 ```rust
1028                 Some(T)
1029                 ```
1030
1031                 ---
1032
1033                 The Some variant
1034             "#]],
1035         );
1036     }
1037
1038     #[test]
1039     fn hover_for_local_variable() {
1040         check(
1041             r#"fn func(foo: i32) { fo$0o; }"#,
1042             expect![[r#"
1043                 *foo*
1044
1045                 ```rust
1046                 foo: i32
1047                 ```
1048             "#]],
1049         )
1050     }
1051
1052     #[test]
1053     fn hover_for_local_variable_pat() {
1054         check(
1055             r#"fn func(fo$0o: i32) {}"#,
1056             expect![[r#"
1057                 *foo*
1058
1059                 ```rust
1060                 foo: i32
1061                 ```
1062             "#]],
1063         )
1064     }
1065
1066     #[test]
1067     fn hover_local_var_edge() {
1068         check(
1069             r#"fn func(foo: i32) { if true { $0foo; }; }"#,
1070             expect![[r#"
1071                 *foo*
1072
1073                 ```rust
1074                 foo: i32
1075                 ```
1076             "#]],
1077         )
1078     }
1079
1080     #[test]
1081     fn hover_for_param_edge() {
1082         check(
1083             r#"fn func($0foo: i32) {}"#,
1084             expect![[r#"
1085                 *foo*
1086
1087                 ```rust
1088                 foo: i32
1089                 ```
1090             "#]],
1091         )
1092     }
1093
1094     #[test]
1095     fn hover_for_param_with_multiple_traits() {
1096         check(
1097             r#"trait Deref {
1098                 type Target: ?Sized;
1099             }
1100             trait DerefMut {
1101                 type Target: ?Sized;
1102             }
1103             fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
1104             expect![[r#"
1105                 *_x*
1106
1107                 ```rust
1108                 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
1109                 ```
1110             "#]],
1111         )
1112     }
1113
1114     #[test]
1115     fn test_hover_infer_associated_method_result() {
1116         check(
1117             r#"
1118 struct Thing { x: u32 }
1119
1120 impl Thing {
1121     fn new() -> Thing { Thing { x: 0 } }
1122 }
1123
1124 fn main() { let foo_$0test = Thing::new(); }
1125             "#,
1126             expect![[r#"
1127                 *foo_test*
1128
1129                 ```rust
1130                 let foo_test: Thing
1131                 ```
1132             "#]],
1133         )
1134     }
1135
1136     #[test]
1137     fn test_hover_infer_associated_method_exact() {
1138         check(
1139             r#"
1140 mod wrapper {
1141     struct Thing { x: u32 }
1142
1143     impl Thing {
1144         fn new() -> Thing { Thing { x: 0 } }
1145     }
1146 }
1147
1148 fn main() { let foo_test = wrapper::Thing::new$0(); }
1149 "#,
1150             expect![[r#"
1151                 *new*
1152
1153                 ```rust
1154                 test::wrapper::Thing
1155                 ```
1156
1157                 ```rust
1158                 fn new() -> Thing
1159                 ```
1160             "#]],
1161         )
1162     }
1163
1164     #[test]
1165     fn test_hover_infer_associated_const_in_pattern() {
1166         check(
1167             r#"
1168 struct X;
1169 impl X {
1170     const C: u32 = 1;
1171 }
1172
1173 fn main() {
1174     match 1 {
1175         X::C$0 => {},
1176         2 => {},
1177         _ => {}
1178     };
1179 }
1180 "#,
1181             expect![[r#"
1182                 *C*
1183
1184                 ```rust
1185                 test
1186                 ```
1187
1188                 ```rust
1189                 const C: u32
1190                 ```
1191             "#]],
1192         )
1193     }
1194
1195     #[test]
1196     fn test_hover_self() {
1197         check(
1198             r#"
1199 struct Thing { x: u32 }
1200 impl Thing {
1201     fn new() -> Self { Self$0 { x: 0 } }
1202 }
1203 "#,
1204             expect![[r#"
1205                 *Self*
1206
1207                 ```rust
1208                 test
1209                 ```
1210
1211                 ```rust
1212                 struct Thing
1213                 ```
1214             "#]],
1215         );
1216         check(
1217             r#"
1218 struct Thing { x: u32 }
1219 impl Thing {
1220     fn new() -> Self$0 { Self { x: 0 } }
1221 }
1222 "#,
1223             expect![[r#"
1224                 *Self*
1225
1226                 ```rust
1227                 test
1228                 ```
1229
1230                 ```rust
1231                 struct Thing
1232                 ```
1233             "#]],
1234         );
1235         check(
1236             r#"
1237 enum Thing { A }
1238 impl Thing {
1239     pub fn new() -> Self$0 { Thing::A }
1240 }
1241 "#,
1242             expect![[r#"
1243                 *Self*
1244
1245                 ```rust
1246                 test
1247                 ```
1248
1249                 ```rust
1250                 enum Thing
1251                 ```
1252             "#]],
1253         );
1254         check(
1255             r#"
1256         enum Thing { A }
1257         impl Thing {
1258             pub fn thing(a: Self$0) {}
1259         }
1260         "#,
1261             expect![[r#"
1262                 *Self*
1263
1264                 ```rust
1265                 test
1266                 ```
1267
1268                 ```rust
1269                 enum Thing
1270                 ```
1271             "#]],
1272         );
1273     }
1274
1275     #[test]
1276     fn test_hover_shadowing_pat() {
1277         check(
1278             r#"
1279 fn x() {}
1280
1281 fn y() {
1282     let x = 0i32;
1283     x$0;
1284 }
1285 "#,
1286             expect![[r#"
1287                 *x*
1288
1289                 ```rust
1290                 let x: i32
1291                 ```
1292             "#]],
1293         )
1294     }
1295
1296     #[test]
1297     fn test_hover_macro_invocation() {
1298         check(
1299             r#"
1300 macro_rules! foo { () => {} }
1301
1302 fn f() { fo$0o!(); }
1303 "#,
1304             expect![[r#"
1305                 *foo*
1306
1307                 ```rust
1308                 test
1309                 ```
1310
1311                 ```rust
1312                 macro_rules! foo
1313                 ```
1314             "#]],
1315         )
1316     }
1317
1318     #[test]
1319     fn test_hover_macro2_invocation() {
1320         check(
1321             r#"
1322 /// foo bar
1323 ///
1324 /// foo bar baz
1325 macro foo() {}
1326
1327 fn f() { fo$0o!(); }
1328 "#,
1329             expect![[r#"
1330                 *foo*
1331
1332                 ```rust
1333                 test
1334                 ```
1335
1336                 ```rust
1337                 macro foo
1338                 ```
1339
1340                 ---
1341
1342                 foo bar
1343
1344                 foo bar baz
1345             "#]],
1346         )
1347     }
1348
1349     #[test]
1350     fn test_hover_tuple_field() {
1351         check(
1352             r#"struct TS(String, i32$0);"#,
1353             expect![[r#"
1354                 *i32*
1355
1356                 ```rust
1357                 i32
1358                 ```
1359             "#]],
1360         )
1361     }
1362
1363     #[test]
1364     fn test_hover_through_macro() {
1365         check(
1366             r#"
1367 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1368 fn foo() {}
1369 id! {
1370     fn bar() { fo$0o(); }
1371 }
1372 "#,
1373             expect![[r#"
1374                 *foo*
1375
1376                 ```rust
1377                 test
1378                 ```
1379
1380                 ```rust
1381                 fn foo()
1382                 ```
1383             "#]],
1384         );
1385     }
1386
1387     #[test]
1388     fn test_hover_through_expr_in_macro() {
1389         check(
1390             r#"
1391 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1392 fn foo(bar:u32) { let a = id!(ba$0r); }
1393 "#,
1394             expect![[r#"
1395                 *bar*
1396
1397                 ```rust
1398                 bar: u32
1399                 ```
1400             "#]],
1401         );
1402     }
1403
1404     #[test]
1405     fn test_hover_through_expr_in_macro_recursive() {
1406         check(
1407             r#"
1408 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1409 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1410 fn foo(bar:u32) { let a = id!(ba$0r); }
1411 "#,
1412             expect![[r#"
1413                 *bar*
1414
1415                 ```rust
1416                 bar: u32
1417                 ```
1418             "#]],
1419         );
1420     }
1421
1422     #[test]
1423     fn test_hover_through_func_in_macro_recursive() {
1424         check(
1425             r#"
1426 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1427 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1428 fn bar() -> u32 { 0 }
1429 fn foo() { let a = id!([0u32, bar($0)] ); }
1430 "#,
1431             expect![[r#"
1432                 *bar()*
1433                 ```rust
1434                 u32
1435                 ```
1436             "#]],
1437         );
1438     }
1439
1440     #[test]
1441     fn test_hover_through_literal_string_in_macro() {
1442         check(
1443             r#"
1444 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1445 fn foo() {
1446     let mastered_for_itunes = "";
1447     let _ = arr!("Tr$0acks", &mastered_for_itunes);
1448 }
1449 "#,
1450             expect![[r#"
1451                 *"Tracks"*
1452                 ```rust
1453                 &str
1454                 ```
1455             "#]],
1456         );
1457     }
1458
1459     #[test]
1460     fn test_hover_through_assert_macro() {
1461         check(
1462             r#"
1463 #[rustc_builtin_macro]
1464 macro_rules! assert {}
1465
1466 fn bar() -> bool { true }
1467 fn foo() {
1468     assert!(ba$0r());
1469 }
1470 "#,
1471             expect![[r#"
1472                 *bar*
1473
1474                 ```rust
1475                 test
1476                 ```
1477
1478                 ```rust
1479                 fn bar() -> bool
1480                 ```
1481             "#]],
1482         );
1483     }
1484
1485     #[test]
1486     fn test_hover_through_literal_string_in_builtin_macro() {
1487         check_hover_no_result(
1488             r#"
1489             #[rustc_builtin_macro]
1490             macro_rules! format {}
1491
1492             fn foo() {
1493                 format!("hel$0lo {}", 0);
1494             }
1495             "#,
1496         );
1497     }
1498
1499     #[test]
1500     fn test_hover_non_ascii_space_doc() {
1501         check(
1502             "
1503 /// <- `\u{3000}` here
1504 fn foo() { }
1505
1506 fn bar() { fo$0o(); }
1507 ",
1508             expect![[r#"
1509                 *foo*
1510
1511                 ```rust
1512                 test
1513                 ```
1514
1515                 ```rust
1516                 fn foo()
1517                 ```
1518
1519                 ---
1520
1521                 \<- ` ` here
1522             "#]],
1523         );
1524     }
1525
1526     #[test]
1527     fn test_hover_function_show_qualifiers() {
1528         check(
1529             r#"async fn foo$0() {}"#,
1530             expect![[r#"
1531                 *foo*
1532
1533                 ```rust
1534                 test
1535                 ```
1536
1537                 ```rust
1538                 async fn foo()
1539                 ```
1540             "#]],
1541         );
1542         check(
1543             r#"pub const unsafe fn foo$0() {}"#,
1544             expect![[r#"
1545                 *foo*
1546
1547                 ```rust
1548                 test
1549                 ```
1550
1551                 ```rust
1552                 pub const unsafe fn foo()
1553                 ```
1554             "#]],
1555         );
1556         // Top level `pub(crate)` will be displayed as no visibility.
1557         check(
1558             r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1559             expect![[r#"
1560                 *foo*
1561
1562                 ```rust
1563                 test::m
1564                 ```
1565
1566                 ```rust
1567                 pub(crate) async unsafe extern "C" fn foo()
1568                 ```
1569             "#]],
1570         );
1571     }
1572
1573     #[test]
1574     fn test_hover_trait_show_qualifiers() {
1575         check_actions(
1576             r"unsafe trait foo$0() {}",
1577             expect![[r#"
1578                 [
1579                     Implementation(
1580                         FilePosition {
1581                             file_id: FileId(
1582                                 0,
1583                             ),
1584                             offset: 13,
1585                         },
1586                     ),
1587                 ]
1588             "#]],
1589         );
1590     }
1591
1592     #[test]
1593     fn test_hover_extern_crate() {
1594         check(
1595             r#"
1596 //- /main.rs crate:main deps:std
1597 extern crate st$0d;
1598 //- /std/lib.rs crate:std
1599 //! Standard library for this test
1600 //!
1601 //! Printed?
1602 //! abc123
1603             "#,
1604             expect![[r#"
1605                 *std*
1606
1607                 ```rust
1608                 extern crate std
1609                 ```
1610
1611                 ---
1612
1613                 Standard library for this test
1614
1615                 Printed?
1616                 abc123
1617             "#]],
1618         );
1619         check(
1620             r#"
1621 //- /main.rs crate:main deps:std
1622 extern crate std as ab$0c;
1623 //- /std/lib.rs crate:std
1624 //! Standard library for this test
1625 //!
1626 //! Printed?
1627 //! abc123
1628             "#,
1629             expect![[r#"
1630                 *abc*
1631
1632                 ```rust
1633                 extern crate std
1634                 ```
1635
1636                 ---
1637
1638                 Standard library for this test
1639
1640                 Printed?
1641                 abc123
1642             "#]],
1643         );
1644     }
1645
1646     #[test]
1647     fn test_hover_mod_with_same_name_as_function() {
1648         check(
1649             r#"
1650 use self::m$0y::Bar;
1651 mod my { pub struct Bar; }
1652
1653 fn my() {}
1654 "#,
1655             expect![[r#"
1656                 *my*
1657
1658                 ```rust
1659                 test
1660                 ```
1661
1662                 ```rust
1663                 mod my
1664                 ```
1665             "#]],
1666         );
1667     }
1668
1669     #[test]
1670     fn test_hover_struct_doc_comment() {
1671         check(
1672             r#"
1673 /// This is an example
1674 /// multiline doc
1675 ///
1676 /// # Example
1677 ///
1678 /// ```
1679 /// let five = 5;
1680 ///
1681 /// assert_eq!(6, my_crate::add_one(5));
1682 /// ```
1683 struct Bar;
1684
1685 fn foo() { let bar = Ba$0r; }
1686 "#,
1687             expect![[r##"
1688                 *Bar*
1689
1690                 ```rust
1691                 test
1692                 ```
1693
1694                 ```rust
1695                 struct Bar
1696                 ```
1697
1698                 ---
1699
1700                 This is an example
1701                 multiline doc
1702
1703                 # Example
1704
1705                 ```
1706                 let five = 5;
1707
1708                 assert_eq!(6, my_crate::add_one(5));
1709                 ```
1710             "##]],
1711         );
1712     }
1713
1714     #[test]
1715     fn test_hover_struct_doc_attr() {
1716         check(
1717             r#"
1718 #[doc = "bar docs"]
1719 struct Bar;
1720
1721 fn foo() { let bar = Ba$0r; }
1722 "#,
1723             expect![[r#"
1724                 *Bar*
1725
1726                 ```rust
1727                 test
1728                 ```
1729
1730                 ```rust
1731                 struct Bar
1732                 ```
1733
1734                 ---
1735
1736                 bar docs
1737             "#]],
1738         );
1739     }
1740
1741     #[test]
1742     fn test_hover_struct_doc_attr_multiple_and_mixed() {
1743         check(
1744             r#"
1745 /// bar docs 0
1746 #[doc = "bar docs 1"]
1747 #[doc = "bar docs 2"]
1748 struct Bar;
1749
1750 fn foo() { let bar = Ba$0r; }
1751 "#,
1752             expect![[r#"
1753                 *Bar*
1754
1755                 ```rust
1756                 test
1757                 ```
1758
1759                 ```rust
1760                 struct Bar
1761                 ```
1762
1763                 ---
1764
1765                 bar docs 0
1766                 bar docs 1
1767                 bar docs 2
1768             "#]],
1769         );
1770     }
1771
1772     #[test]
1773     fn test_hover_path_link() {
1774         check(
1775             r#"
1776 pub struct Foo;
1777 /// [Foo](struct.Foo.html)
1778 pub struct B$0ar
1779 "#,
1780             expect![[r#"
1781                 *Bar*
1782
1783                 ```rust
1784                 test
1785                 ```
1786
1787                 ```rust
1788                 pub struct Bar
1789                 ```
1790
1791                 ---
1792
1793                 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1794             "#]],
1795         );
1796     }
1797
1798     #[test]
1799     fn test_hover_path_link_no_strip() {
1800         check(
1801             r#"
1802 pub struct Foo;
1803 /// [struct Foo](struct.Foo.html)
1804 pub struct B$0ar
1805 "#,
1806             expect![[r#"
1807                 *Bar*
1808
1809                 ```rust
1810                 test
1811                 ```
1812
1813                 ```rust
1814                 pub struct Bar
1815                 ```
1816
1817                 ---
1818
1819                 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1820             "#]],
1821         );
1822     }
1823
1824     #[ignore = "path based links currently only support documentation on ModuleDef items"]
1825     #[test]
1826     fn test_hover_path_link_field() {
1827         check(
1828             r#"
1829 pub struct Foo;
1830 pub struct Bar {
1831     /// [Foo](struct.Foo.html)
1832     fie$0ld: ()
1833 }
1834 "#,
1835             expect![[r#"
1836                 *field*
1837
1838                 ```rust
1839                 test::Bar
1840                 ```
1841
1842                 ```rust
1843                 field: ()
1844                 ```
1845
1846                 ---
1847
1848                 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1849             "#]],
1850         );
1851     }
1852
1853     #[test]
1854     fn test_hover_intra_link() {
1855         check(
1856             r#"
1857 pub mod foo {
1858     pub struct Foo;
1859 }
1860 /// [Foo](foo::Foo)
1861 pub struct B$0ar
1862 "#,
1863             expect![[r#"
1864                 *Bar*
1865
1866                 ```rust
1867                 test
1868                 ```
1869
1870                 ```rust
1871                 pub struct Bar
1872                 ```
1873
1874                 ---
1875
1876                 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1877             "#]],
1878         );
1879     }
1880
1881     #[test]
1882     fn test_hover_intra_link_html_root_url() {
1883         check(
1884             r#"
1885 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1886
1887 pub mod foo {
1888     pub struct Foo;
1889 }
1890 /// [Foo](foo::Foo)
1891 pub struct B$0ar
1892 "#,
1893             expect![[r#"
1894                 *Bar*
1895
1896                 ```rust
1897                 test
1898                 ```
1899
1900                 ```rust
1901                 pub struct Bar
1902                 ```
1903
1904                 ---
1905
1906                 [Foo](https://example.com/test/foo/struct.Foo.html)
1907             "#]],
1908         );
1909     }
1910
1911     #[test]
1912     fn test_hover_intra_link_shortlink() {
1913         check(
1914             r#"
1915 pub struct Foo;
1916 /// [Foo]
1917 pub struct B$0ar
1918 "#,
1919             expect![[r#"
1920                 *Bar*
1921
1922                 ```rust
1923                 test
1924                 ```
1925
1926                 ```rust
1927                 pub struct Bar
1928                 ```
1929
1930                 ---
1931
1932                 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1933             "#]],
1934         );
1935     }
1936
1937     #[test]
1938     fn test_hover_intra_link_shortlink_code() {
1939         check(
1940             r#"
1941 pub struct Foo;
1942 /// [`Foo`]
1943 pub struct B$0ar
1944 "#,
1945             expect![[r#"
1946                 *Bar*
1947
1948                 ```rust
1949                 test
1950                 ```
1951
1952                 ```rust
1953                 pub struct Bar
1954                 ```
1955
1956                 ---
1957
1958                 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1959             "#]],
1960         );
1961     }
1962
1963     #[test]
1964     fn test_hover_intra_link_namespaced() {
1965         check(
1966             r#"
1967 pub struct Foo;
1968 fn Foo() {}
1969 /// [Foo()]
1970 pub struct B$0ar
1971 "#,
1972             expect![[r#"
1973                 *Bar*
1974
1975                 ```rust
1976                 test
1977                 ```
1978
1979                 ```rust
1980                 pub struct Bar
1981                 ```
1982
1983                 ---
1984
1985                 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1986             "#]],
1987         );
1988     }
1989
1990     #[test]
1991     fn test_hover_intra_link_shortlink_namspaced_code() {
1992         check(
1993             r#"
1994 pub struct Foo;
1995 /// [`struct Foo`]
1996 pub struct B$0ar
1997 "#,
1998             expect![[r#"
1999                 *Bar*
2000
2001                 ```rust
2002                 test
2003                 ```
2004
2005                 ```rust
2006                 pub struct Bar
2007                 ```
2008
2009                 ---
2010
2011                 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
2012             "#]],
2013         );
2014     }
2015
2016     #[test]
2017     fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
2018         check(
2019             r#"
2020 pub struct Foo;
2021 /// [`struct@Foo`]
2022 pub struct B$0ar
2023 "#,
2024             expect![[r#"
2025                 *Bar*
2026
2027                 ```rust
2028                 test
2029                 ```
2030
2031                 ```rust
2032                 pub struct Bar
2033                 ```
2034
2035                 ---
2036
2037                 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
2038             "#]],
2039         );
2040     }
2041
2042     #[test]
2043     fn test_hover_intra_link_reference() {
2044         check(
2045             r#"
2046 pub struct Foo;
2047 /// [my Foo][foo]
2048 ///
2049 /// [foo]: Foo
2050 pub struct B$0ar
2051 "#,
2052             expect![[r#"
2053                 *Bar*
2054
2055                 ```rust
2056                 test
2057                 ```
2058
2059                 ```rust
2060                 pub struct Bar
2061                 ```
2062
2063                 ---
2064
2065                 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
2066             "#]],
2067         );
2068     }
2069     #[test]
2070     fn test_hover_intra_link_reference_to_trait_method() {
2071         check(
2072             r#"
2073 pub trait Foo {
2074     fn buzz() -> usize;
2075 }
2076 /// [Foo][buzz]
2077 ///
2078 /// [buzz]: Foo::buzz
2079 pub struct B$0ar
2080 "#,
2081             expect![[r#"
2082                 *Bar*
2083
2084                 ```rust
2085                 test
2086                 ```
2087
2088                 ```rust
2089                 pub struct Bar
2090                 ```
2091
2092                 ---
2093
2094                 [Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)
2095             "#]],
2096         );
2097     }
2098
2099     #[test]
2100     fn test_hover_external_url() {
2101         check(
2102             r#"
2103 pub struct Foo;
2104 /// [external](https://www.google.com)
2105 pub struct B$0ar
2106 "#,
2107             expect![[r#"
2108                 *Bar*
2109
2110                 ```rust
2111                 test
2112                 ```
2113
2114                 ```rust
2115                 pub struct Bar
2116                 ```
2117
2118                 ---
2119
2120                 [external](https://www.google.com)
2121             "#]],
2122         );
2123     }
2124
2125     // Check that we don't rewrite links which we can't identify
2126     #[test]
2127     fn test_hover_unknown_target() {
2128         check(
2129             r#"
2130 pub struct Foo;
2131 /// [baz](Baz)
2132 pub struct B$0ar
2133 "#,
2134             expect![[r#"
2135                 *Bar*
2136
2137                 ```rust
2138                 test
2139                 ```
2140
2141                 ```rust
2142                 pub struct Bar
2143                 ```
2144
2145                 ---
2146
2147                 [baz](Baz)
2148             "#]],
2149         );
2150     }
2151
2152     #[test]
2153     fn test_doc_links_enum_variant() {
2154         check(
2155             r#"
2156 enum E {
2157     /// [E]
2158     V$0 { field: i32 }
2159 }
2160 "#,
2161             expect![[r#"
2162                 *V*
2163
2164                 ```rust
2165                 test::E
2166                 ```
2167
2168                 ```rust
2169                 V { field: i32 }
2170                 ```
2171
2172                 ---
2173
2174                 [E](https://docs.rs/test/*/test/enum.E.html)
2175             "#]],
2176         );
2177     }
2178
2179     #[test]
2180     fn test_doc_links_field() {
2181         check(
2182             r#"
2183 struct S {
2184     /// [`S`]
2185     field$0: i32
2186 }
2187 "#,
2188             expect![[r#"
2189                 *field*
2190
2191                 ```rust
2192                 test::S
2193                 ```
2194
2195                 ```rust
2196                 field: i32
2197                 ```
2198
2199                 ---
2200
2201                 [`S`](https://docs.rs/test/*/test/struct.S.html)
2202             "#]],
2203         );
2204     }
2205
2206     #[test]
2207     fn test_hover_no_links() {
2208         check_hover_no_links(
2209             r#"
2210 /// Test cases:
2211 /// case 1.  bare URL: https://www.example.com/
2212 /// case 2.  inline URL with title: [example](https://www.example.com/)
2213 /// case 3.  code reference: [`Result`]
2214 /// case 4.  code reference but miss footnote: [`String`]
2215 /// case 5.  autolink: <http://www.example.com/>
2216 /// case 6.  email address: <test@example.com>
2217 /// case 7.  reference: [example][example]
2218 /// case 8.  collapsed link: [example][]
2219 /// case 9.  shortcut link: [example]
2220 /// case 10. inline without URL: [example]()
2221 /// case 11. reference: [foo][foo]
2222 /// case 12. reference: [foo][bar]
2223 /// case 13. collapsed link: [foo][]
2224 /// case 14. shortcut link: [foo]
2225 /// case 15. inline without URL: [foo]()
2226 /// case 16. just escaped text: \[foo]
2227 /// case 17. inline link: [Foo](foo::Foo)
2228 ///
2229 /// [`Result`]: ../../std/result/enum.Result.html
2230 /// [^example]: https://www.example.com/
2231 pub fn fo$0o() {}
2232 "#,
2233             expect![[r#"
2234                 *foo*
2235
2236                 ```rust
2237                 test
2238                 ```
2239
2240                 ```rust
2241                 pub fn foo()
2242                 ```
2243
2244                 ---
2245
2246                 Test cases:
2247                 case 1.  bare URL: https://www.example.com/
2248                 case 2.  inline URL with title: [example](https://www.example.com/)
2249                 case 3.  code reference: `Result`
2250                 case 4.  code reference but miss footnote: `String`
2251                 case 5.  autolink: http://www.example.com/
2252                 case 6.  email address: test@example.com
2253                 case 7.  reference: example
2254                 case 8.  collapsed link: example
2255                 case 9.  shortcut link: example
2256                 case 10. inline without URL: example
2257                 case 11. reference: foo
2258                 case 12. reference: foo
2259                 case 13. collapsed link: foo
2260                 case 14. shortcut link: foo
2261                 case 15. inline without URL: foo
2262                 case 16. just escaped text: \[foo]
2263                 case 17. inline link: Foo
2264
2265                 [^example]: https://www.example.com/
2266             "#]],
2267         );
2268     }
2269
2270     #[test]
2271     fn test_hover_macro_generated_struct_fn_doc_comment() {
2272         cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
2273
2274         check(
2275             r#"
2276 macro_rules! bar {
2277     () => {
2278         struct Bar;
2279         impl Bar {
2280             /// Do the foo
2281             fn foo(&self) {}
2282         }
2283     }
2284 }
2285
2286 bar!();
2287
2288 fn foo() { let bar = Bar; bar.fo$0o(); }
2289 "#,
2290             expect![[r#"
2291                 *foo*
2292
2293                 ```rust
2294                 test::Bar
2295                 ```
2296
2297                 ```rust
2298                 fn foo(&self)
2299                 ```
2300
2301                 ---
2302
2303                 Do the foo
2304             "#]],
2305         );
2306     }
2307
2308     #[test]
2309     fn test_hover_macro_generated_struct_fn_doc_attr() {
2310         cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
2311
2312         check(
2313             r#"
2314 macro_rules! bar {
2315     () => {
2316         struct Bar;
2317         impl Bar {
2318             #[doc = "Do the foo"]
2319             fn foo(&self) {}
2320         }
2321     }
2322 }
2323
2324 bar!();
2325
2326 fn foo() { let bar = Bar; bar.fo$0o(); }
2327 "#,
2328             expect![[r#"
2329                 *foo*
2330
2331                 ```rust
2332                 test::Bar
2333                 ```
2334
2335                 ```rust
2336                 fn foo(&self)
2337                 ```
2338
2339                 ---
2340
2341                 Do the foo
2342             "#]],
2343         );
2344     }
2345
2346     #[test]
2347     fn test_hover_trait_has_impl_action() {
2348         check_actions(
2349             r#"trait foo$0() {}"#,
2350             expect![[r#"
2351                 [
2352                     Implementation(
2353                         FilePosition {
2354                             file_id: FileId(
2355                                 0,
2356                             ),
2357                             offset: 6,
2358                         },
2359                     ),
2360                 ]
2361             "#]],
2362         );
2363     }
2364
2365     #[test]
2366     fn test_hover_struct_has_impl_action() {
2367         check_actions(
2368             r"struct foo$0() {}",
2369             expect![[r#"
2370                 [
2371                     Implementation(
2372                         FilePosition {
2373                             file_id: FileId(
2374                                 0,
2375                             ),
2376                             offset: 7,
2377                         },
2378                     ),
2379                 ]
2380             "#]],
2381         );
2382     }
2383
2384     #[test]
2385     fn test_hover_union_has_impl_action() {
2386         check_actions(
2387             r#"union foo$0() {}"#,
2388             expect![[r#"
2389                 [
2390                     Implementation(
2391                         FilePosition {
2392                             file_id: FileId(
2393                                 0,
2394                             ),
2395                             offset: 6,
2396                         },
2397                     ),
2398                 ]
2399             "#]],
2400         );
2401     }
2402
2403     #[test]
2404     fn test_hover_enum_has_impl_action() {
2405         check_actions(
2406             r"enum foo$0() { A, B }",
2407             expect![[r#"
2408                 [
2409                     Implementation(
2410                         FilePosition {
2411                             file_id: FileId(
2412                                 0,
2413                             ),
2414                             offset: 5,
2415                         },
2416                     ),
2417                 ]
2418             "#]],
2419         );
2420     }
2421
2422     #[test]
2423     fn test_hover_self_has_impl_action() {
2424         check_actions(
2425             r#"struct foo where Self$0:;"#,
2426             expect![[r#"
2427                 [
2428                     Implementation(
2429                         FilePosition {
2430                             file_id: FileId(
2431                                 0,
2432                             ),
2433                             offset: 7,
2434                         },
2435                     ),
2436                 ]
2437             "#]],
2438         );
2439     }
2440
2441     #[test]
2442     fn test_hover_test_has_action() {
2443         check_actions(
2444             r#"
2445 #[test]
2446 fn foo_$0test() {}
2447 "#,
2448             expect![[r#"
2449                 [
2450                     Reference(
2451                         FilePosition {
2452                             file_id: FileId(
2453                                 0,
2454                             ),
2455                             offset: 11,
2456                         },
2457                     ),
2458                     Runnable(
2459                         Runnable {
2460                             nav: NavigationTarget {
2461                                 file_id: FileId(
2462                                     0,
2463                                 ),
2464                                 full_range: 0..24,
2465                                 focus_range: 11..19,
2466                                 name: "foo_test",
2467                                 kind: Function,
2468                             },
2469                             kind: Test {
2470                                 test_id: Path(
2471                                     "foo_test",
2472                                 ),
2473                                 attr: TestAttr {
2474                                     ignore: false,
2475                                 },
2476                             },
2477                             cfg: None,
2478                         },
2479                     ),
2480                 ]
2481             "#]],
2482         );
2483     }
2484
2485     #[test]
2486     fn test_hover_test_mod_has_action() {
2487         check_actions(
2488             r#"
2489 mod tests$0 {
2490     #[test]
2491     fn foo_test() {}
2492 }
2493 "#,
2494             expect![[r#"
2495                 [
2496                     Runnable(
2497                         Runnable {
2498                             nav: NavigationTarget {
2499                                 file_id: FileId(
2500                                     0,
2501                                 ),
2502                                 full_range: 0..46,
2503                                 focus_range: 4..9,
2504                                 name: "tests",
2505                                 kind: Module,
2506                             },
2507                             kind: TestMod {
2508                                 path: "tests",
2509                             },
2510                             cfg: None,
2511                         },
2512                     ),
2513                 ]
2514             "#]],
2515         );
2516     }
2517
2518     #[test]
2519     fn test_hover_struct_has_goto_type_action() {
2520         check_actions(
2521             r#"
2522 struct S{ f1: u32 }
2523
2524 fn main() { let s$0t = S{ f1:0 }; }
2525             "#,
2526             expect![[r#"
2527                 [
2528                     GoToType(
2529                         [
2530                             HoverGotoTypeData {
2531                                 mod_path: "test::S",
2532                                 nav: NavigationTarget {
2533                                     file_id: FileId(
2534                                         0,
2535                                     ),
2536                                     full_range: 0..19,
2537                                     focus_range: 7..8,
2538                                     name: "S",
2539                                     kind: Struct,
2540                                     description: "struct S",
2541                                 },
2542                             },
2543                         ],
2544                     ),
2545                 ]
2546             "#]],
2547         );
2548     }
2549
2550     #[test]
2551     fn test_hover_generic_struct_has_goto_type_actions() {
2552         check_actions(
2553             r#"
2554 struct Arg(u32);
2555 struct S<T>{ f1: T }
2556
2557 fn main() { let s$0t = S{ f1:Arg(0) }; }
2558 "#,
2559             expect![[r#"
2560                 [
2561                     GoToType(
2562                         [
2563                             HoverGotoTypeData {
2564                                 mod_path: "test::S",
2565                                 nav: NavigationTarget {
2566                                     file_id: FileId(
2567                                         0,
2568                                     ),
2569                                     full_range: 17..37,
2570                                     focus_range: 24..25,
2571                                     name: "S",
2572                                     kind: Struct,
2573                                     description: "struct S<T>",
2574                                 },
2575                             },
2576                             HoverGotoTypeData {
2577                                 mod_path: "test::Arg",
2578                                 nav: NavigationTarget {
2579                                     file_id: FileId(
2580                                         0,
2581                                     ),
2582                                     full_range: 0..16,
2583                                     focus_range: 7..10,
2584                                     name: "Arg",
2585                                     kind: Struct,
2586                                     description: "struct Arg",
2587                                 },
2588                             },
2589                         ],
2590                     ),
2591                 ]
2592             "#]],
2593         );
2594     }
2595
2596     #[test]
2597     fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2598         check_actions(
2599             r#"
2600 struct Arg(u32);
2601 struct S<T>{ f1: T }
2602
2603 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2604             "#,
2605             expect![[r#"
2606                 [
2607                     GoToType(
2608                         [
2609                             HoverGotoTypeData {
2610                                 mod_path: "test::S",
2611                                 nav: NavigationTarget {
2612                                     file_id: FileId(
2613                                         0,
2614                                     ),
2615                                     full_range: 17..37,
2616                                     focus_range: 24..25,
2617                                     name: "S",
2618                                     kind: Struct,
2619                                     description: "struct S<T>",
2620                                 },
2621                             },
2622                             HoverGotoTypeData {
2623                                 mod_path: "test::Arg",
2624                                 nav: NavigationTarget {
2625                                     file_id: FileId(
2626                                         0,
2627                                     ),
2628                                     full_range: 0..16,
2629                                     focus_range: 7..10,
2630                                     name: "Arg",
2631                                     kind: Struct,
2632                                     description: "struct Arg",
2633                                 },
2634                             },
2635                         ],
2636                     ),
2637                 ]
2638             "#]],
2639         );
2640     }
2641
2642     #[test]
2643     fn test_hover_tuple_has_goto_type_actions() {
2644         check_actions(
2645             r#"
2646 struct A(u32);
2647 struct B(u32);
2648 mod M {
2649     pub struct C(u32);
2650 }
2651
2652 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2653 "#,
2654             expect![[r#"
2655                 [
2656                     GoToType(
2657                         [
2658                             HoverGotoTypeData {
2659                                 mod_path: "test::A",
2660                                 nav: NavigationTarget {
2661                                     file_id: FileId(
2662                                         0,
2663                                     ),
2664                                     full_range: 0..14,
2665                                     focus_range: 7..8,
2666                                     name: "A",
2667                                     kind: Struct,
2668                                     description: "struct A",
2669                                 },
2670                             },
2671                             HoverGotoTypeData {
2672                                 mod_path: "test::B",
2673                                 nav: NavigationTarget {
2674                                     file_id: FileId(
2675                                         0,
2676                                     ),
2677                                     full_range: 15..29,
2678                                     focus_range: 22..23,
2679                                     name: "B",
2680                                     kind: Struct,
2681                                     description: "struct B",
2682                                 },
2683                             },
2684                             HoverGotoTypeData {
2685                                 mod_path: "test::M::C",
2686                                 nav: NavigationTarget {
2687                                     file_id: FileId(
2688                                         0,
2689                                     ),
2690                                     full_range: 42..60,
2691                                     focus_range: 53..54,
2692                                     name: "C",
2693                                     kind: Struct,
2694                                     description: "pub struct C",
2695                                 },
2696                             },
2697                         ],
2698                     ),
2699                 ]
2700             "#]],
2701         );
2702     }
2703
2704     #[test]
2705     fn test_hover_return_impl_trait_has_goto_type_action() {
2706         check_actions(
2707             r#"
2708 trait Foo {}
2709 fn foo() -> impl Foo {}
2710
2711 fn main() { let s$0t = foo(); }
2712 "#,
2713             expect![[r#"
2714                 [
2715                     GoToType(
2716                         [
2717                             HoverGotoTypeData {
2718                                 mod_path: "test::Foo",
2719                                 nav: NavigationTarget {
2720                                     file_id: FileId(
2721                                         0,
2722                                     ),
2723                                     full_range: 0..12,
2724                                     focus_range: 6..9,
2725                                     name: "Foo",
2726                                     kind: Trait,
2727                                     description: "trait Foo",
2728                                 },
2729                             },
2730                         ],
2731                     ),
2732                 ]
2733             "#]],
2734         );
2735     }
2736
2737     #[test]
2738     fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2739         check_actions(
2740             r#"
2741 trait Foo<T> {}
2742 struct S;
2743 fn foo() -> impl Foo<S> {}
2744
2745 fn main() { let s$0t = foo(); }
2746 "#,
2747             expect![[r#"
2748                 [
2749                     GoToType(
2750                         [
2751                             HoverGotoTypeData {
2752                                 mod_path: "test::Foo",
2753                                 nav: NavigationTarget {
2754                                     file_id: FileId(
2755                                         0,
2756                                     ),
2757                                     full_range: 0..15,
2758                                     focus_range: 6..9,
2759                                     name: "Foo",
2760                                     kind: Trait,
2761                                     description: "trait Foo<T>",
2762                                 },
2763                             },
2764                             HoverGotoTypeData {
2765                                 mod_path: "test::S",
2766                                 nav: NavigationTarget {
2767                                     file_id: FileId(
2768                                         0,
2769                                     ),
2770                                     full_range: 16..25,
2771                                     focus_range: 23..24,
2772                                     name: "S",
2773                                     kind: Struct,
2774                                     description: "struct S",
2775                                 },
2776                             },
2777                         ],
2778                     ),
2779                 ]
2780             "#]],
2781         );
2782     }
2783
2784     #[test]
2785     fn test_hover_return_impl_traits_has_goto_type_action() {
2786         check_actions(
2787             r#"
2788 trait Foo {}
2789 trait Bar {}
2790 fn foo() -> impl Foo + Bar {}
2791
2792 fn main() { let s$0t = foo(); }
2793             "#,
2794             expect![[r#"
2795                 [
2796                     GoToType(
2797                         [
2798                             HoverGotoTypeData {
2799                                 mod_path: "test::Foo",
2800                                 nav: NavigationTarget {
2801                                     file_id: FileId(
2802                                         0,
2803                                     ),
2804                                     full_range: 0..12,
2805                                     focus_range: 6..9,
2806                                     name: "Foo",
2807                                     kind: Trait,
2808                                     description: "trait Foo",
2809                                 },
2810                             },
2811                             HoverGotoTypeData {
2812                                 mod_path: "test::Bar",
2813                                 nav: NavigationTarget {
2814                                     file_id: FileId(
2815                                         0,
2816                                     ),
2817                                     full_range: 13..25,
2818                                     focus_range: 19..22,
2819                                     name: "Bar",
2820                                     kind: Trait,
2821                                     description: "trait Bar",
2822                                 },
2823                             },
2824                         ],
2825                     ),
2826                 ]
2827             "#]],
2828         );
2829     }
2830
2831     #[test]
2832     fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2833         check_actions(
2834             r#"
2835 trait Foo<T> {}
2836 trait Bar<T> {}
2837 struct S1 {}
2838 struct S2 {}
2839
2840 fn foo() -> impl Foo<S1> + Bar<S2> {}
2841
2842 fn main() { let s$0t = foo(); }
2843 "#,
2844             expect![[r#"
2845                 [
2846                     GoToType(
2847                         [
2848                             HoverGotoTypeData {
2849                                 mod_path: "test::Foo",
2850                                 nav: NavigationTarget {
2851                                     file_id: FileId(
2852                                         0,
2853                                     ),
2854                                     full_range: 0..15,
2855                                     focus_range: 6..9,
2856                                     name: "Foo",
2857                                     kind: Trait,
2858                                     description: "trait Foo<T>",
2859                                 },
2860                             },
2861                             HoverGotoTypeData {
2862                                 mod_path: "test::Bar",
2863                                 nav: NavigationTarget {
2864                                     file_id: FileId(
2865                                         0,
2866                                     ),
2867                                     full_range: 16..31,
2868                                     focus_range: 22..25,
2869                                     name: "Bar",
2870                                     kind: Trait,
2871                                     description: "trait Bar<T>",
2872                                 },
2873                             },
2874                             HoverGotoTypeData {
2875                                 mod_path: "test::S1",
2876                                 nav: NavigationTarget {
2877                                     file_id: FileId(
2878                                         0,
2879                                     ),
2880                                     full_range: 32..44,
2881                                     focus_range: 39..41,
2882                                     name: "S1",
2883                                     kind: Struct,
2884                                     description: "struct S1",
2885                                 },
2886                             },
2887                             HoverGotoTypeData {
2888                                 mod_path: "test::S2",
2889                                 nav: NavigationTarget {
2890                                     file_id: FileId(
2891                                         0,
2892                                     ),
2893                                     full_range: 45..57,
2894                                     focus_range: 52..54,
2895                                     name: "S2",
2896                                     kind: Struct,
2897                                     description: "struct S2",
2898                                 },
2899                             },
2900                         ],
2901                     ),
2902                 ]
2903             "#]],
2904         );
2905     }
2906
2907     #[test]
2908     fn test_hover_arg_impl_trait_has_goto_type_action() {
2909         check_actions(
2910             r#"
2911 trait Foo {}
2912 fn foo(ar$0g: &impl Foo) {}
2913 "#,
2914             expect![[r#"
2915                 [
2916                     GoToType(
2917                         [
2918                             HoverGotoTypeData {
2919                                 mod_path: "test::Foo",
2920                                 nav: NavigationTarget {
2921                                     file_id: FileId(
2922                                         0,
2923                                     ),
2924                                     full_range: 0..12,
2925                                     focus_range: 6..9,
2926                                     name: "Foo",
2927                                     kind: Trait,
2928                                     description: "trait Foo",
2929                                 },
2930                             },
2931                         ],
2932                     ),
2933                 ]
2934             "#]],
2935         );
2936     }
2937
2938     #[test]
2939     fn test_hover_arg_impl_traits_has_goto_type_action() {
2940         check_actions(
2941             r#"
2942 trait Foo {}
2943 trait Bar<T> {}
2944 struct S{}
2945
2946 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2947 "#,
2948             expect![[r#"
2949                 [
2950                     GoToType(
2951                         [
2952                             HoverGotoTypeData {
2953                                 mod_path: "test::Foo",
2954                                 nav: NavigationTarget {
2955                                     file_id: FileId(
2956                                         0,
2957                                     ),
2958                                     full_range: 0..12,
2959                                     focus_range: 6..9,
2960                                     name: "Foo",
2961                                     kind: Trait,
2962                                     description: "trait Foo",
2963                                 },
2964                             },
2965                             HoverGotoTypeData {
2966                                 mod_path: "test::Bar",
2967                                 nav: NavigationTarget {
2968                                     file_id: FileId(
2969                                         0,
2970                                     ),
2971                                     full_range: 13..28,
2972                                     focus_range: 19..22,
2973                                     name: "Bar",
2974                                     kind: Trait,
2975                                     description: "trait Bar<T>",
2976                                 },
2977                             },
2978                             HoverGotoTypeData {
2979                                 mod_path: "test::S",
2980                                 nav: NavigationTarget {
2981                                     file_id: FileId(
2982                                         0,
2983                                     ),
2984                                     full_range: 29..39,
2985                                     focus_range: 36..37,
2986                                     name: "S",
2987                                     kind: Struct,
2988                                     description: "struct S",
2989                                 },
2990                             },
2991                         ],
2992                     ),
2993                 ]
2994             "#]],
2995         );
2996     }
2997
2998     #[test]
2999     fn test_hover_async_block_impl_trait_has_goto_type_action() {
3000         check_actions(
3001             r#"
3002 struct S;
3003 fn foo() {
3004     let fo$0o = async { S };
3005 }
3006
3007 #[prelude_import] use future::*;
3008 mod future {
3009     #[lang = "future_trait"]
3010     pub trait Future { type Output; }
3011 }
3012 "#,
3013             expect![[r#"
3014                 [
3015                     GoToType(
3016                         [
3017                             HoverGotoTypeData {
3018                                 mod_path: "test::future::Future",
3019                                 nav: NavigationTarget {
3020                                     file_id: FileId(
3021                                         0,
3022                                     ),
3023                                     full_range: 101..163,
3024                                     focus_range: 140..146,
3025                                     name: "Future",
3026                                     kind: Trait,
3027                                     description: "pub trait Future",
3028                                 },
3029                             },
3030                             HoverGotoTypeData {
3031                                 mod_path: "test::S",
3032                                 nav: NavigationTarget {
3033                                     file_id: FileId(
3034                                         0,
3035                                     ),
3036                                     full_range: 0..9,
3037                                     focus_range: 7..8,
3038                                     name: "S",
3039                                     kind: Struct,
3040                                     description: "struct S",
3041                                 },
3042                             },
3043                         ],
3044                     ),
3045                 ]
3046             "#]],
3047         );
3048     }
3049
3050     #[test]
3051     fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
3052         check_actions(
3053             r#"
3054 trait Foo<T> {}
3055 struct S {}
3056 fn foo(ar$0g: &impl Foo<S>) {}
3057 "#,
3058             expect![[r#"
3059                 [
3060                     GoToType(
3061                         [
3062                             HoverGotoTypeData {
3063                                 mod_path: "test::Foo",
3064                                 nav: NavigationTarget {
3065                                     file_id: FileId(
3066                                         0,
3067                                     ),
3068                                     full_range: 0..15,
3069                                     focus_range: 6..9,
3070                                     name: "Foo",
3071                                     kind: Trait,
3072                                     description: "trait Foo<T>",
3073                                 },
3074                             },
3075                             HoverGotoTypeData {
3076                                 mod_path: "test::S",
3077                                 nav: NavigationTarget {
3078                                     file_id: FileId(
3079                                         0,
3080                                     ),
3081                                     full_range: 16..27,
3082                                     focus_range: 23..24,
3083                                     name: "S",
3084                                     kind: Struct,
3085                                     description: "struct S",
3086                                 },
3087                             },
3088                         ],
3089                     ),
3090                 ]
3091             "#]],
3092         );
3093     }
3094
3095     #[test]
3096     fn test_hover_dyn_return_has_goto_type_action() {
3097         check_actions(
3098             r#"
3099 trait Foo {}
3100 struct S;
3101 impl Foo for S {}
3102
3103 struct B<T>{}
3104 fn foo() -> B<dyn Foo> {}
3105
3106 fn main() { let s$0t = foo(); }
3107 "#,
3108             expect![[r#"
3109                 [
3110                     GoToType(
3111                         [
3112                             HoverGotoTypeData {
3113                                 mod_path: "test::B",
3114                                 nav: NavigationTarget {
3115                                     file_id: FileId(
3116                                         0,
3117                                     ),
3118                                     full_range: 42..55,
3119                                     focus_range: 49..50,
3120                                     name: "B",
3121                                     kind: Struct,
3122                                     description: "struct B<T>",
3123                                 },
3124                             },
3125                             HoverGotoTypeData {
3126                                 mod_path: "test::Foo",
3127                                 nav: NavigationTarget {
3128                                     file_id: FileId(
3129                                         0,
3130                                     ),
3131                                     full_range: 0..12,
3132                                     focus_range: 6..9,
3133                                     name: "Foo",
3134                                     kind: Trait,
3135                                     description: "trait Foo",
3136                                 },
3137                             },
3138                         ],
3139                     ),
3140                 ]
3141             "#]],
3142         );
3143     }
3144
3145     #[test]
3146     fn test_hover_dyn_arg_has_goto_type_action() {
3147         check_actions(
3148             r#"
3149 trait Foo {}
3150 fn foo(ar$0g: &dyn Foo) {}
3151 "#,
3152             expect![[r#"
3153                 [
3154                     GoToType(
3155                         [
3156                             HoverGotoTypeData {
3157                                 mod_path: "test::Foo",
3158                                 nav: NavigationTarget {
3159                                     file_id: FileId(
3160                                         0,
3161                                     ),
3162                                     full_range: 0..12,
3163                                     focus_range: 6..9,
3164                                     name: "Foo",
3165                                     kind: Trait,
3166                                     description: "trait Foo",
3167                                 },
3168                             },
3169                         ],
3170                     ),
3171                 ]
3172             "#]],
3173         );
3174     }
3175
3176     #[test]
3177     fn test_hover_generic_dyn_arg_has_goto_type_action() {
3178         check_actions(
3179             r#"
3180 trait Foo<T> {}
3181 struct S {}
3182 fn foo(ar$0g: &dyn Foo<S>) {}
3183 "#,
3184             expect![[r#"
3185                 [
3186                     GoToType(
3187                         [
3188                             HoverGotoTypeData {
3189                                 mod_path: "test::Foo",
3190                                 nav: NavigationTarget {
3191                                     file_id: FileId(
3192                                         0,
3193                                     ),
3194                                     full_range: 0..15,
3195                                     focus_range: 6..9,
3196                                     name: "Foo",
3197                                     kind: Trait,
3198                                     description: "trait Foo<T>",
3199                                 },
3200                             },
3201                             HoverGotoTypeData {
3202                                 mod_path: "test::S",
3203                                 nav: NavigationTarget {
3204                                     file_id: FileId(
3205                                         0,
3206                                     ),
3207                                     full_range: 16..27,
3208                                     focus_range: 23..24,
3209                                     name: "S",
3210                                     kind: Struct,
3211                                     description: "struct S",
3212                                 },
3213                             },
3214                         ],
3215                     ),
3216                 ]
3217             "#]],
3218         );
3219     }
3220
3221     #[test]
3222     fn test_hover_goto_type_action_links_order() {
3223         check_actions(
3224             r#"
3225 trait ImplTrait<T> {}
3226 trait DynTrait<T> {}
3227 struct B<T> {}
3228 struct S {}
3229
3230 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3231             "#,
3232             expect![[r#"
3233                 [
3234                     GoToType(
3235                         [
3236                             HoverGotoTypeData {
3237                                 mod_path: "test::ImplTrait",
3238                                 nav: NavigationTarget {
3239                                     file_id: FileId(
3240                                         0,
3241                                     ),
3242                                     full_range: 0..21,
3243                                     focus_range: 6..15,
3244                                     name: "ImplTrait",
3245                                     kind: Trait,
3246                                     description: "trait ImplTrait<T>",
3247                                 },
3248                             },
3249                             HoverGotoTypeData {
3250                                 mod_path: "test::B",
3251                                 nav: NavigationTarget {
3252                                     file_id: FileId(
3253                                         0,
3254                                     ),
3255                                     full_range: 43..57,
3256                                     focus_range: 50..51,
3257                                     name: "B",
3258                                     kind: Struct,
3259                                     description: "struct B<T>",
3260                                 },
3261                             },
3262                             HoverGotoTypeData {
3263                                 mod_path: "test::DynTrait",
3264                                 nav: NavigationTarget {
3265                                     file_id: FileId(
3266                                         0,
3267                                     ),
3268                                     full_range: 22..42,
3269                                     focus_range: 28..36,
3270                                     name: "DynTrait",
3271                                     kind: Trait,
3272                                     description: "trait DynTrait<T>",
3273                                 },
3274                             },
3275                             HoverGotoTypeData {
3276                                 mod_path: "test::S",
3277                                 nav: NavigationTarget {
3278                                     file_id: FileId(
3279                                         0,
3280                                     ),
3281                                     full_range: 58..69,
3282                                     focus_range: 65..66,
3283                                     name: "S",
3284                                     kind: Struct,
3285                                     description: "struct S",
3286                                 },
3287                             },
3288                         ],
3289                     ),
3290                 ]
3291             "#]],
3292         );
3293     }
3294
3295     #[test]
3296     fn test_hover_associated_type_has_goto_type_action() {
3297         check_actions(
3298             r#"
3299 trait Foo {
3300     type Item;
3301     fn get(self) -> Self::Item {}
3302 }
3303
3304 struct Bar{}
3305 struct S{}
3306
3307 impl Foo for S { type Item = Bar; }
3308
3309 fn test() -> impl Foo { S {} }
3310
3311 fn main() { let s$0t = test().get(); }
3312 "#,
3313             expect![[r#"
3314                 [
3315                     GoToType(
3316                         [
3317                             HoverGotoTypeData {
3318                                 mod_path: "test::Foo",
3319                                 nav: NavigationTarget {
3320                                     file_id: FileId(
3321                                         0,
3322                                     ),
3323                                     full_range: 0..62,
3324                                     focus_range: 6..9,
3325                                     name: "Foo",
3326                                     kind: Trait,
3327                                     description: "trait Foo",
3328                                 },
3329                             },
3330                         ],
3331                     ),
3332                 ]
3333             "#]],
3334         );
3335     }
3336
3337     #[test]
3338     fn test_hover_const_param_has_goto_type_action() {
3339         check_actions(
3340             r#"
3341 struct Bar;
3342 struct Foo<const BAR: Bar>;
3343
3344 impl<const BAR: Bar> Foo<BAR$0> {}
3345 "#,
3346             expect![[r#"
3347                 [
3348                     GoToType(
3349                         [
3350                             HoverGotoTypeData {
3351                                 mod_path: "test::Bar",
3352                                 nav: NavigationTarget {
3353                                     file_id: FileId(
3354                                         0,
3355                                     ),
3356                                     full_range: 0..11,
3357                                     focus_range: 7..10,
3358                                     name: "Bar",
3359                                     kind: Struct,
3360                                     description: "struct Bar",
3361                                 },
3362                             },
3363                         ],
3364                     ),
3365                 ]
3366             "#]],
3367         );
3368     }
3369
3370     #[test]
3371     fn test_hover_type_param_has_goto_type_action() {
3372         check_actions(
3373             r#"
3374 trait Foo {}
3375
3376 fn foo<T: Foo>(t: T$0){}
3377 "#,
3378             expect![[r#"
3379                 [
3380                     GoToType(
3381                         [
3382                             HoverGotoTypeData {
3383                                 mod_path: "test::Foo",
3384                                 nav: NavigationTarget {
3385                                     file_id: FileId(
3386                                         0,
3387                                     ),
3388                                     full_range: 0..12,
3389                                     focus_range: 6..9,
3390                                     name: "Foo",
3391                                     kind: Trait,
3392                                     description: "trait Foo",
3393                                 },
3394                             },
3395                         ],
3396                     ),
3397                 ]
3398             "#]],
3399         );
3400     }
3401
3402     #[test]
3403     fn test_hover_self_has_go_to_type() {
3404         check_actions(
3405             r#"
3406 struct Foo;
3407 impl Foo {
3408     fn foo(&self$0) {}
3409 }
3410 "#,
3411             expect![[r#"
3412                 [
3413                     GoToType(
3414                         [
3415                             HoverGotoTypeData {
3416                                 mod_path: "test::Foo",
3417                                 nav: NavigationTarget {
3418                                     file_id: FileId(
3419                                         0,
3420                                     ),
3421                                     full_range: 0..11,
3422                                     focus_range: 7..10,
3423                                     name: "Foo",
3424                                     kind: Struct,
3425                                     description: "struct Foo",
3426                                 },
3427                             },
3428                         ],
3429                     ),
3430                 ]
3431             "#]],
3432         );
3433     }
3434
3435     #[test]
3436     fn hover_displays_normalized_crate_names() {
3437         check(
3438             r#"
3439 //- /lib.rs crate:name-with-dashes
3440 pub mod wrapper {
3441     pub struct Thing { x: u32 }
3442
3443     impl Thing {
3444         pub fn new() -> Thing { Thing { x: 0 } }
3445     }
3446 }
3447
3448 //- /main.rs crate:main deps:name-with-dashes
3449 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3450 "#,
3451             expect![[r#"
3452             *new*
3453
3454             ```rust
3455             name_with_dashes::wrapper::Thing
3456             ```
3457
3458             ```rust
3459             pub fn new() -> Thing
3460             ```
3461             "#]],
3462         )
3463     }
3464
3465     #[test]
3466     fn hover_field_pat_shorthand_ref_match_ergonomics() {
3467         check(
3468             r#"
3469 struct S {
3470     f: i32,
3471 }
3472
3473 fn main() {
3474     let s = S { f: 0 };
3475     let S { f$0 } = &s;
3476 }
3477 "#,
3478             expect![[r#"
3479                 *f*
3480
3481                 ```rust
3482                 f: &i32
3483                 ```
3484             "#]],
3485         );
3486     }
3487
3488     #[test]
3489     fn hover_self_param_shows_type() {
3490         check(
3491             r#"
3492 struct Foo {}
3493 impl Foo {
3494     fn bar(&sel$0f) {}
3495 }
3496 "#,
3497             expect![[r#"
3498                 *self*
3499
3500                 ```rust
3501                 self: &Foo
3502                 ```
3503             "#]],
3504         );
3505     }
3506
3507     #[test]
3508     fn hover_self_param_shows_type_for_arbitrary_self_type() {
3509         check(
3510             r#"
3511 struct Arc<T>(T);
3512 struct Foo {}
3513 impl Foo {
3514     fn bar(sel$0f: Arc<Foo>) {}
3515 }
3516 "#,
3517             expect![[r#"
3518                 *self*
3519
3520                 ```rust
3521                 self: Arc<Foo>
3522                 ```
3523             "#]],
3524         );
3525     }
3526
3527     #[test]
3528     fn hover_doc_outer_inner() {
3529         check(
3530             r#"
3531 /// Be quick;
3532 mod Foo$0 {
3533     //! time is mana
3534
3535     /// This comment belongs to the function
3536     fn foo() {}
3537 }
3538 "#,
3539             expect![[r#"
3540                 *Foo*
3541
3542                 ```rust
3543                 test
3544                 ```
3545
3546                 ```rust
3547                 mod Foo
3548                 ```
3549
3550                 ---
3551
3552                 Be quick;
3553                 time is mana
3554             "#]],
3555         );
3556     }
3557
3558     #[test]
3559     fn hover_doc_outer_inner_attribue() {
3560         check(
3561             r#"
3562 #[doc = "Be quick;"]
3563 mod Foo$0 {
3564     #![doc = "time is mana"]
3565
3566     #[doc = "This comment belongs to the function"]
3567     fn foo() {}
3568 }
3569 "#,
3570             expect![[r#"
3571                 *Foo*
3572
3573                 ```rust
3574                 test
3575                 ```
3576
3577                 ```rust
3578                 mod Foo
3579                 ```
3580
3581                 ---
3582
3583                 Be quick;
3584                 time is mana
3585             "#]],
3586         );
3587     }
3588
3589     #[test]
3590     fn hover_doc_block_style_indentend() {
3591         check(
3592             r#"
3593 /**
3594     foo
3595     ```rust
3596     let x = 3;
3597     ```
3598 */
3599 fn foo$0() {}
3600 "#,
3601             expect![[r#"
3602                 *foo*
3603
3604                 ```rust
3605                 test
3606                 ```
3607
3608                 ```rust
3609                 fn foo()
3610                 ```
3611
3612                 ---
3613
3614                 foo
3615
3616                 ```rust
3617                 let x = 3;
3618                 ```
3619             "#]],
3620         );
3621     }
3622
3623     #[test]
3624     fn hover_comments_dont_highlight_parent() {
3625         cov_mark::check!(no_highlight_on_comment_hover);
3626         check_hover_no_result(
3627             r#"
3628 fn no_hover() {
3629     // no$0hover
3630 }
3631 "#,
3632         );
3633     }
3634
3635     #[test]
3636     fn hover_label() {
3637         check(
3638             r#"
3639 fn foo() {
3640     'label$0: loop {}
3641 }
3642 "#,
3643             expect![[r#"
3644             *'label*
3645
3646             ```rust
3647             'label
3648             ```
3649             "#]],
3650         );
3651     }
3652
3653     #[test]
3654     fn hover_lifetime() {
3655         check(
3656             r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3657             expect![[r#"
3658             *'lifetime*
3659
3660             ```rust
3661             'lifetime
3662             ```
3663             "#]],
3664         );
3665     }
3666
3667     #[test]
3668     fn hover_type_param() {
3669         check(
3670             r#"
3671 struct Foo<T>(T);
3672 trait Copy {}
3673 trait Clone {}
3674 trait Sized {}
3675 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3676 "#,
3677             expect![[r#"
3678                 *T*
3679
3680                 ```rust
3681                 T: Copy + Clone + Sized
3682                 ```
3683             "#]],
3684         );
3685         check(
3686             r#"
3687 struct Foo<T>(T);
3688 impl<T> Foo<T$0> {}
3689 "#,
3690             expect![[r#"
3691                 *T*
3692
3693                 ```rust
3694                 T
3695                 ```
3696                 "#]],
3697         );
3698         // lifetimes bounds arent being tracked yet
3699         check(
3700             r#"
3701 struct Foo<T>(T);
3702 impl<T: 'static> Foo<T$0> {}
3703 "#,
3704             expect![[r#"
3705                 *T*
3706
3707                 ```rust
3708                 T
3709                 ```
3710                 "#]],
3711         );
3712     }
3713
3714     #[test]
3715     fn hover_const_param() {
3716         check(
3717             r#"
3718 struct Foo<const LEN: usize>;
3719 impl<const LEN: usize> Foo<LEN$0> {}
3720 "#,
3721             expect![[r#"
3722                 *LEN*
3723
3724                 ```rust
3725                 const LEN: usize
3726                 ```
3727             "#]],
3728         );
3729     }
3730
3731     #[test]
3732     fn hover_const_pat() {
3733         check(
3734             r#"
3735 /// This is a doc
3736 const FOO: usize = 3;
3737 fn foo() {
3738     match 5 {
3739         FOO$0 => (),
3740         _ => ()
3741     }
3742 }
3743 "#,
3744             expect![[r#"
3745                 *FOO*
3746
3747                 ```rust
3748                 test
3749                 ```
3750
3751                 ```rust
3752                 const FOO: usize
3753                 ```
3754
3755                 ---
3756
3757                 This is a doc
3758             "#]],
3759         );
3760     }
3761
3762     #[test]
3763     fn hover_mod_def() {
3764         check(
3765             r#"
3766 //- /main.rs
3767 mod foo$0;
3768 //- /foo.rs
3769 //! For the horde!
3770 "#,
3771             expect![[r#"
3772                 *foo*
3773
3774                 ```rust
3775                 test
3776                 ```
3777
3778                 ```rust
3779                 mod foo
3780                 ```
3781
3782                 ---
3783
3784                 For the horde!
3785             "#]],
3786         );
3787     }
3788
3789     #[test]
3790     fn hover_self_in_use() {
3791         check(
3792             r#"
3793 //! This should not appear
3794 mod foo {
3795     /// But this should appear
3796     pub mod bar {}
3797 }
3798 use foo::bar::{self$0};
3799 "#,
3800             expect![[r#"
3801                 *self*
3802
3803                 ```rust
3804                 test::foo
3805                 ```
3806
3807                 ```rust
3808                 mod bar
3809                 ```
3810
3811                 ---
3812
3813                 But this should appear
3814             "#]],
3815         )
3816     }
3817
3818     #[test]
3819     fn hover_keyword() {
3820         let ra_fixture = r#"//- /main.rs crate:main deps:std
3821 fn f() { retur$0n; }"#;
3822         let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
3823         check(
3824             &fixture,
3825             expect![[r#"
3826                 *return*
3827
3828                 ```rust
3829                 return
3830                 ```
3831
3832                 ---
3833
3834                 Docs for return_keyword
3835             "#]],
3836         );
3837     }
3838
3839     #[test]
3840     fn hover_builtin() {
3841         let ra_fixture = r#"//- /main.rs crate:main deps:std
3842 cosnt _: &str$0 = ""; }"#;
3843         let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
3844         check(
3845             &fixture,
3846             expect![[r#"
3847                 *str*
3848
3849                 ```rust
3850                 str
3851                 ```
3852
3853                 ---
3854
3855                 Docs for prim_str
3856             "#]],
3857         );
3858     }
3859
3860     #[test]
3861     fn hover_macro_expanded_function() {
3862         check(
3863             r#"
3864 struct S<'a, T>(&'a T);
3865 trait Clone {}
3866 macro_rules! foo {
3867     () => {
3868         fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3869             't: 't + 't,
3870             for<'a> T: Clone + 'a
3871         { 0 as _ }
3872     };
3873 }
3874
3875 foo!();
3876
3877 fn main() {
3878     bar$0;
3879 }
3880 "#,
3881             expect![[r#"
3882                 *bar*
3883
3884                 ```rust
3885                 test
3886                 ```
3887
3888                 ```rust
3889                 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3890                 where
3891                     T: Clone + 't,
3892                     't: 't + 't,
3893                     for<'a> T: Clone + 'a,
3894                 ```
3895             "#]],
3896         )
3897     }
3898
3899     #[test]
3900     fn hover_intra_doc_links() {
3901         check(
3902             r#"
3903
3904 pub mod theitem {
3905     /// This is the item. Cool!
3906     pub struct TheItem;
3907 }
3908
3909 /// Gives you a [`TheItem$0`].
3910 ///
3911 /// [`TheItem`]: theitem::TheItem
3912 pub fn gimme() -> theitem::TheItem {
3913     theitem::TheItem
3914 }
3915 "#,
3916             expect![[r#"
3917                 *[`TheItem`]*
3918
3919                 ```rust
3920                 test::theitem
3921                 ```
3922
3923                 ```rust
3924                 pub struct TheItem
3925                 ```
3926
3927                 ---
3928
3929                 This is the item. Cool!
3930             "#]],
3931         );
3932     }
3933
3934     #[test]
3935     fn hover_generic_assoc() {
3936         check(
3937             r#"
3938 fn foo<T: A>() where T::Assoc$0: {}
3939
3940 trait A {
3941     type Assoc;
3942 }"#,
3943             expect![[r#"
3944                 *Assoc*
3945
3946                 ```rust
3947                 test
3948                 ```
3949
3950                 ```rust
3951                 type Assoc
3952                 ```
3953             "#]],
3954         );
3955         check(
3956             r#"
3957 fn foo<T: A>() {
3958     let _: <T>::Assoc$0;
3959 }
3960
3961 trait A {
3962     type Assoc;
3963 }"#,
3964             expect![[r#"
3965                 *Assoc*
3966
3967                 ```rust
3968                 test
3969                 ```
3970
3971                 ```rust
3972                 type Assoc
3973                 ```
3974             "#]],
3975         );
3976         check(
3977             r#"
3978 trait A where
3979     Self::Assoc$0: ,
3980 {
3981     type Assoc;
3982 }"#,
3983             expect![[r#"
3984                 *Assoc*
3985
3986                 ```rust
3987                 test
3988                 ```
3989
3990                 ```rust
3991                 type Assoc
3992                 ```
3993             "#]],
3994         );
3995     }
3996
3997     #[test]
3998     fn string_shadowed_with_inner_items() {
3999         check(
4000             r#"
4001 //- /main.rs crate:main deps:alloc
4002
4003 /// Custom `String` type.
4004 struct String;
4005
4006 fn f() {
4007     let _: String$0;
4008
4009     fn inner() {}
4010 }
4011
4012 //- /alloc.rs crate:alloc
4013 #[prelude_import]
4014 pub use string::*;
4015
4016 mod string {
4017     /// This is `alloc::String`.
4018     pub struct String;
4019 }
4020             "#,
4021             expect![[r#"
4022                 *String*
4023
4024                 ```rust
4025                 main
4026                 ```
4027
4028                 ```rust
4029                 struct String
4030                 ```
4031
4032                 ---
4033
4034                 Custom `String` type.
4035             "#]],
4036         )
4037     }
4038
4039     #[test]
4040     fn function_doesnt_shadow_crate_in_use_tree() {
4041         check(
4042             r#"
4043 //- /main.rs crate:main deps:foo
4044 use foo$0::{foo};
4045
4046 //- /foo.rs crate:foo
4047 pub fn foo() {}
4048 "#,
4049             expect![[r#"
4050                 *foo*
4051
4052                 ```rust
4053                 extern crate foo
4054                 ```
4055             "#]],
4056         )
4057     }
4058
4059     #[test]
4060     fn hover_feature() {
4061         check(
4062             r#"#![feature(box_syntax$0)]"#,
4063             expect![[r##"
4064                 *box_syntax*
4065                 ```
4066                 box_syntax
4067                 ```
4068                 ___
4069
4070                 # `box_syntax`
4071
4072                 The tracking issue for this feature is: [#49733]
4073
4074                 [#49733]: https://github.com/rust-lang/rust/issues/49733
4075
4076                 See also [`box_patterns`](box-patterns.md)
4077
4078                 ------------------------
4079
4080                 Currently the only stable way to create a `Box` is via the `Box::new` method.
4081                 Also it is not possible in stable Rust to destructure a `Box` in a match
4082                 pattern. The unstable `box` keyword can be used to create a `Box`. An example
4083                 usage would be:
4084
4085                 ```rust
4086                 #![feature(box_syntax)]
4087
4088                 fn main() {
4089                     let b = box 5;
4090                 }
4091                 ```
4092
4093             "##]],
4094         )
4095     }
4096
4097     #[test]
4098     fn hover_lint() {
4099         check(
4100             r#"#![allow(arithmetic_overflow$0)]"#,
4101             expect![[r#"
4102                 *arithmetic_overflow*
4103                 ```
4104                 arithmetic_overflow
4105                 ```
4106                 ___
4107
4108                 arithmetic operation overflows
4109             "#]],
4110         )
4111     }
4112
4113     #[test]
4114     fn hover_clippy_lint() {
4115         check(
4116             r#"#![allow(clippy::almost_swapped$0)]"#,
4117             expect![[r#"
4118                 *almost_swapped*
4119                 ```
4120                 clippy::almost_swapped
4121                 ```
4122                 ___
4123
4124                 Checks for `foo = bar; bar = foo` sequences.
4125             "#]],
4126         )
4127     }
4128 }