3 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
4 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
7 base_db::SourceDatabase,
8 defs::{Definition, NameClass, NameRefClass},
12 use itertools::Itertools;
14 use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
17 display::{macro_label, ShortLabel, TryToNav},
18 doc_links::{remove_links, rewrite_links},
19 markdown_remove::remove_markdown,
21 runnables::{runnable_fn, runnable_mod},
22 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
25 #[derive(Clone, Debug, PartialEq, Eq)]
26 pub struct HoverConfig {
27 pub implementations: bool,
30 pub goto_type_def: bool,
31 pub links_in_hover: bool,
36 pub const NO_ACTIONS: Self = Self {
37 implementations: false,
45 pub fn any(&self) -> bool {
46 self.implementations || self.runnable() || self.goto_type_def
49 pub fn none(&self) -> bool {
53 pub fn runnable(&self) -> bool {
54 self.run || self.debug
58 #[derive(Debug, Clone)]
59 pub enum HoverAction {
61 Implementation(FilePosition),
62 GoToType(Vec<HoverGotoTypeData>),
65 #[derive(Debug, Clone, Eq, PartialEq)]
66 pub struct HoverGotoTypeData {
68 pub nav: NavigationTarget,
71 /// Contains the results when hovering over an item
72 #[derive(Debug, Default)]
73 pub struct HoverResult {
75 pub actions: Vec<HoverAction>,
80 // Shows additional information, like type of an expression or documentation for definition when "focusing" code.
81 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
84 position: FilePosition,
87 ) -> Option<RangeInfo<HoverResult>> {
88 let sema = Semantics::new(db);
89 let file = sema.parse(position.file_id).syntax().clone();
90 let token = pick_best(file.token_at_offset(position.offset))?;
91 let token = sema.descend_into_macros(token);
93 let mut res = HoverResult::default();
95 let node = token.parent();
96 let definition = match_ast! {
98 // we don't use NameClass::referenced_or_defined here as we do not want to resolve
99 // field pattern shorthands to their definition
100 ast::Name(name) => NameClass::classify(&sema, &name).and_then(|class| match class {
101 NameClass::ConstReference(def) => Some(def),
102 def => def.defined(sema.db),
104 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)),
105 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime)
106 .map_or_else(|| NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced(sema.db)), |d| d.defined(sema.db)),
110 if let Some(definition) = definition {
111 let famous_defs = match &definition {
112 Definition::ModuleDef(ModuleDef::BuiltinType(_)) => {
113 Some(FamousDefs(&sema, sema.scope(&node).krate()))
117 if let Some(markup) = hover_for_definition(db, definition, famous_defs.as_ref()) {
118 res.markup = process_markup(sema.db, definition, &markup, links_in_hover, markdown);
119 if let Some(action) = show_implementations_action(db, definition) {
120 res.actions.push(action);
123 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
124 res.actions.push(action);
127 if let Some(action) = goto_type_action(db, definition) {
128 res.actions.push(action);
131 let range = sema.original_range(&node).range;
132 return Some(RangeInfo::new(range, res));
136 if token.kind() == syntax::SyntaxKind::COMMENT {
137 // don't highlight the entire parent node on comment hover
140 if let res @ Some(_) = hover_for_keyword(&sema, links_in_hover, markdown, &token) {
146 .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
148 let ty = match_ast! {
150 ast::Expr(it) => sema.type_of_expr(&it)?,
151 ast::Pat(it) => sema.type_of_pat(&it)?,
152 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
153 // (e.g expanding a builtin macro). So we give up here.
154 ast::MacroCall(_it) => return None,
159 res.markup = if markdown {
160 Markup::fenced_block(&ty.display(db))
162 ty.display(db).to_string().into()
164 let range = sema.original_range(&node).range;
165 Some(RangeInfo::new(range, res))
168 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
169 fn to_action(nav_target: NavigationTarget) -> HoverAction {
170 HoverAction::Implementation(FilePosition {
171 file_id: nav_target.file_id,
172 offset: nav_target.focus_or_full_range().start(),
176 let adt = match def {
177 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
178 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
179 Definition::SelfType(it) => it.target_ty(db).as_adt(),
182 adt.try_to_nav(db).map(to_action)
186 sema: &Semantics<RootDatabase>,
189 ) -> Option<HoverAction> {
191 Definition::ModuleDef(it) => match it {
192 ModuleDef::Module(it) => runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it)),
193 ModuleDef::Function(func) => {
194 let src = func.source(sema.db)?;
195 if src.file_id != file_id.into() {
196 cov_mark::hit!(hover_macro_generated_struct_fn_doc_comment);
197 cov_mark::hit!(hover_macro_generated_struct_fn_doc_attr);
201 runnable_fn(&sema, func).map(HoverAction::Runnable)
209 fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
210 let mut targets: Vec<ModuleDef> = Vec::new();
211 let mut push_new_def = |item: ModuleDef| {
212 if !targets.contains(&item) {
217 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
218 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
221 Definition::Local(it) => it.ty(db),
222 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
227 if let Some(adt) = t.as_adt() {
228 push_new_def(adt.into());
229 } else if let Some(trait_) = t.as_dyn_trait() {
230 push_new_def(trait_.into());
231 } else if let Some(traits) = t.as_impl_traits(db) {
232 traits.into_iter().for_each(|it| push_new_def(it.into()));
233 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
234 push_new_def(trait_.into());
239 let targets = targets
242 Some(HoverGotoTypeData {
243 mod_path: render_path(db, it.module(db)?, it.name(db).map(|name| name.to_string())),
244 nav: it.try_to_nav(db)?,
249 Some(HoverAction::GoToType(targets))
253 docs: Option<String>,
254 desc: Option<String>,
255 mod_path: Option<String>,
256 ) -> Option<Markup> {
259 let mut buf = String::new();
261 if let Some(mod_path) = mod_path {
262 if !mod_path.is_empty() {
263 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
266 format_to!(buf, "```rust\n{}\n```", desc);
268 if let Some(doc) = docs {
269 format_to!(buf, "\n___\n\n{}", doc);
273 None => docs.map(Markup::from),
281 links_in_hover: bool,
284 let markup = markup.as_str();
285 let markup = if !markdown {
286 remove_markdown(markup)
287 } else if links_in_hover {
288 rewrite_links(db, markup, &def)
295 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
297 Definition::Field(f) => Some(f.parent_def(db).name(db)),
298 Definition::Local(l) => l.parent(db).name(db),
299 Definition::ModuleDef(md) => match md {
300 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
301 AssocItemContainer::Trait(t) => Some(t.name(db)),
302 AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
304 ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
309 .map(|name| name.to_string())
312 fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
314 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
315 let module_path = module
319 .flat_map(|it| it.name(db).map(|name| name.to_string()));
320 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
323 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
324 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
327 fn hover_for_definition(
330 famous_defs: Option<&FamousDefs>,
331 ) -> Option<Markup> {
332 let mod_path = definition_mod_path(db, &def);
334 Definition::Macro(it) => {
335 let label = macro_label(&it.source(db)?.value);
336 from_def_source_labeled(db, it, Some(label), mod_path)
338 Definition::Field(def) => {
339 let src = def.source(db)?.value;
340 if let FieldSource::Named(it) = src {
341 from_def_source_labeled(db, def, it.short_label(), mod_path)
346 Definition::ModuleDef(it) => match it {
347 ModuleDef::Module(it) => from_def_source_labeled(
350 match it.definition_source(db).value {
351 ModuleSource::Module(it) => it.short_label(),
352 ModuleSource::SourceFile(it) => it.short_label(),
353 ModuleSource::BlockExpr(it) => it.short_label(),
357 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
358 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
359 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
360 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
361 ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
362 ModuleDef::Const(it) => from_def_source(db, it, mod_path),
363 ModuleDef::Static(it) => from_def_source(db, it, mod_path),
364 ModuleDef::Trait(it) => from_def_source(db, it, mod_path),
365 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path),
366 ModuleDef::BuiltinType(it) => famous_defs
367 .and_then(|fd| hover_for_builtin(fd, it))
368 .or_else(|| Some(Markup::fenced_block(&it.name()))),
370 Definition::Local(it) => hover_for_local(it, db),
371 Definition::SelfType(impl_def) => {
372 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
373 Adt::Struct(it) => from_def_source(db, it, mod_path),
374 Adt::Union(it) => from_def_source(db, it, mod_path),
375 Adt::Enum(it) => from_def_source(db, it, mod_path),
378 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
379 Definition::GenericParam(it) => match it {
380 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
381 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
382 GenericParam::ConstParam(it) => from_def_source(db, it, None),
386 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
388 D: HasSource<Ast = A> + HasAttrs + Copy,
391 let short_label = def.source(db)?.value.short_label();
392 from_def_source_labeled(db, def, short_label, mod_path)
395 fn from_def_source_labeled<D>(
398 short_label: Option<String>,
399 mod_path: Option<String>,
404 let docs = def.attrs(db).docs().map(Into::into);
405 hover_markup(docs, short_label, mod_path)
409 fn hover_for_local(it: hir::Local, db: &RootDatabase) -> Option<Markup> {
411 let ty = ty.display(db);
412 let is_mut = if it.is_mut(db) { "mut " } else { "" };
413 let desc = match it.source(db).value {
414 Either::Left(ident) => {
415 let name = it.name(db).unwrap();
416 let let_kw = if ident
419 .map_or(false, |p| p.kind() == LET_STMT || p.kind() == CONDITION)
425 format!("{}{}{}: {}", let_kw, is_mut, name, ty)
427 Either::Right(_) => format!("{}self: {}", is_mut, ty),
429 hover_markup(None, Some(desc), None)
432 fn hover_for_keyword(
433 sema: &Semantics<RootDatabase>,
434 links_in_hover: bool,
437 ) -> Option<RangeInfo<HoverResult>> {
438 if !token.kind().is_keyword() {
441 let famous_defs = FamousDefs(&sema, sema.scope(&token.parent()).krate());
442 // std exposes {}_keyword modules with docstrings on the root to document keywords
443 let keyword_mod = format!("{}_keyword", token.text());
444 let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
445 let docs = doc_owner.attrs(sema.db).docs()?;
446 let markup = process_markup(
448 Definition::ModuleDef(doc_owner.into()),
449 &hover_markup(Some(docs.into()), Some(token.text().into()), None)?,
453 Some(RangeInfo::new(token.text_range(), HoverResult { markup, actions: Default::default() }))
456 fn hover_for_builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option<Markup> {
457 // std exposes prim_{} modules with docstrings on the root to document the builtins
458 let primitive_mod = format!("prim_{}", builtin.name());
459 let doc_owner = find_std_module(famous_defs, &primitive_mod)?;
460 let docs = doc_owner.attrs(famous_defs.0.db).docs()?;
461 hover_markup(Some(docs.into()), Some(builtin.name().to_string()), None)
464 fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module> {
465 let db = famous_defs.0.db;
466 let std_crate = famous_defs.std()?;
467 let std_root_module = std_crate.root_module(db);
470 .find(|module| module.name(db).map_or(false, |module| module.to_string() == name))
473 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
474 return tokens.max_by_key(priority);
475 fn priority(n: &SyntaxToken) -> usize {
477 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
478 T!['('] | T![')'] => 2,
479 kind if kind.is_trivia() => 0,
487 use expect_test::{expect, Expect};
488 use ide_db::base_db::FileLoader;
494 fn check_hover_no_result(ra_fixture: &str) {
495 let (analysis, position) = fixture::position(ra_fixture);
496 assert!(analysis.hover(position, true, true).unwrap().is_none());
499 fn check(ra_fixture: &str, expect: Expect) {
500 let (analysis, position) = fixture::position(ra_fixture);
501 let hover = analysis.hover(position, true, true).unwrap().unwrap();
503 let content = analysis.db.file_text(position.file_id);
504 let hovered_element = &content[hover.range];
506 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
507 expect.assert_eq(&actual)
510 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
511 let (analysis, position) = fixture::position(ra_fixture);
512 let hover = analysis.hover(position, false, true).unwrap().unwrap();
514 let content = analysis.db.file_text(position.file_id);
515 let hovered_element = &content[hover.range];
517 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
518 expect.assert_eq(&actual)
521 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
522 let (analysis, position) = fixture::position(ra_fixture);
523 let hover = analysis.hover(position, true, false).unwrap().unwrap();
525 let content = analysis.db.file_text(position.file_id);
526 let hovered_element = &content[hover.range];
528 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
529 expect.assert_eq(&actual)
532 fn check_actions(ra_fixture: &str, expect: Expect) {
533 let (analysis, position) = fixture::position(ra_fixture);
534 let hover = analysis.hover(position, true, true).unwrap().unwrap();
535 expect.assert_debug_eq(&hover.info.actions)
539 fn hover_shows_type_of_an_expression() {
542 pub fn foo() -> u32 { 1 }
545 let foo_test = foo()$0;
558 fn hover_remove_markdown_if_configured() {
559 check_hover_no_markdown(
561 pub fn foo() -> u32 { 1 }
564 let foo_test = foo()$0;
575 fn hover_shows_long_type_of_an_expression() {
578 struct Scan<A, B, C> { a: A, b: B, c: C }
579 struct Iter<I> { inner: I }
580 enum Option<T> { Some(T), None }
582 struct OtherStruct<T> { i: T }
584 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
585 Iter { inner: Scan { a, b, c } }
590 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
591 Option::Some(*memo + value)
594 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
601 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
608 fn hover_shows_fn_signature() {
609 // Single file with result
612 pub fn foo() -> u32 { 1 }
614 fn main() { let foo_test = fo$0o(); }
629 // Multiple candidates but results are ambiguous.
633 pub fn foo() -> u32 { 1 }
636 pub fn foo() -> &str { "" }
639 pub fn foo(a: u32, b: u32) {}
646 fn main() { let foo_test = fo$0o(); }
658 fn hover_shows_fn_signature_with_type_params() {
661 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
663 fn main() { let foo_test = fo$0o(); }
673 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
680 fn hover_shows_fn_signature_on_fn_name() {
683 pub fn foo$0(a: u32, b: u32) -> u32 {}
695 pub fn foo(a: u32, b: u32) -> u32
702 fn hover_shows_fn_doc() {
707 /// # use std::path::Path;
709 /// foo(Path::new("hello, world!"))
711 pub fn foo$0(_: &Path) {}
731 # use std::path::Path;
733 foo(Path::new("hello, world!"))
740 fn hover_shows_fn_doc_attr_raw_string() {
743 #[doc = r#"Raw string doc attr"#]
744 pub fn foo$0(_: &Path) {}
767 fn hover_shows_struct_field_info() {
768 // Hovering over the field when instantiating
771 struct Foo { field_a: u32 }
774 let foo = Foo { field_a$0: 0, };
790 // Hovering over the field in the definition
793 struct Foo { field_a$0: u32 }
796 let foo = Foo { field_a: 0 };
814 fn hover_const_static() {
816 r#"const foo$0: u32 = 123;"#,
830 r#"static foo$0: u32 = 456;"#,
846 fn hover_default_generic_types() {
849 struct Test<K, T = u8> { k: K, t: T }
852 let zz$0 = Test { t: 23u8, k: 33 };
858 let zz: Test<i32, u8>
868 enum Option<T> { Some(T) }
871 fn main() { So$0me(12); }
888 enum Option<T> { Some(T) }
891 fn main() { let b$0ar = Some(12); }
904 fn hover_enum_variant() {
936 let s = Option::Som$0e(12);
958 fn hover_for_local_variable() {
960 r#"fn func(foo: i32) { fo$0o; }"#,
972 fn hover_for_local_variable_pat() {
974 r#"fn func(fo$0o: i32) {}"#,
986 fn hover_local_var_edge() {
988 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
1000 fn hover_for_param_edge() {
1002 r#"fn func($0foo: i32) {}"#,
1014 fn hover_for_param_with_multiple_traits() {
1017 type Target: ?Sized;
1020 type Target: ?Sized;
1022 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
1027 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
1034 fn test_hover_infer_associated_method_result() {
1037 struct Thing { x: u32 }
1040 fn new() -> Thing { Thing { x: 0 } }
1043 fn main() { let foo_$0test = Thing::new(); }
1056 fn test_hover_infer_associated_method_exact() {
1060 struct Thing { x: u32 }
1063 fn new() -> Thing { Thing { x: 0 } }
1067 fn main() { let foo_test = wrapper::Thing::new$0(); }
1073 test::wrapper::Thing
1084 fn test_hover_infer_associated_const_in_pattern() {
1115 fn test_hover_self() {
1118 struct Thing { x: u32 }
1120 fn new() -> Self { Self$0 { x: 0 } }
1137 struct Thing { x: u32 }
1139 fn new() -> Self$0 { Self { x: 0 } }
1158 pub fn new() -> Self$0 { Thing::A }
1177 pub fn thing(a: Self$0) {}
1195 fn test_hover_shadowing_pat() {
1216 fn test_hover_macro_invocation() {
1219 macro_rules! foo { () => {} }
1221 fn f() { fo$0o!(); }
1238 fn test_hover_tuple_field() {
1240 r#"struct TS(String, i32$0);"#,
1252 fn test_hover_through_macro() {
1255 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1258 fn bar() { fo$0o(); }
1276 fn test_hover_through_expr_in_macro() {
1279 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1280 fn foo(bar:u32) { let a = id!(ba$0r); }
1293 fn test_hover_through_expr_in_macro_recursive() {
1296 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1297 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1298 fn foo(bar:u32) { let a = id!(ba$0r); }
1311 fn test_hover_through_func_in_macro_recursive() {
1314 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1315 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1316 fn bar() -> u32 { 0 }
1317 fn foo() { let a = id!([0u32, bar($0)] ); }
1329 fn test_hover_through_literal_string_in_macro() {
1332 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1334 let mastered_for_itunes = "";
1335 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1348 fn test_hover_through_assert_macro() {
1351 #[rustc_builtin_macro]
1352 macro_rules! assert {}
1354 fn bar() -> bool { true }
1374 fn test_hover_through_literal_string_in_builtin_macro() {
1375 check_hover_no_result(
1377 #[rustc_builtin_macro]
1378 macro_rules! format {}
1381 format!("hel$0lo {}", 0);
1388 fn test_hover_non_ascii_space_doc() {
1391 /// <- `\u{3000}` here
1394 fn bar() { fo$0o(); }
1415 fn test_hover_function_show_qualifiers() {
1417 r#"async fn foo$0() {}"#,
1431 r#"pub const unsafe fn foo$0() {}"#,
1440 pub const unsafe fn foo()
1445 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1454 pub(crate) async unsafe extern "C" fn foo()
1461 fn test_hover_trait_show_qualifiers() {
1463 r"unsafe trait foo$0() {}",
1480 fn test_hover_extern_crate() {
1483 //- /main.rs crate:main deps:std
1485 //- /std/lib.rs crate:std
1486 //! Standard library for this test
1493 Standard library for this test
1501 //- /main.rs crate:main deps:std
1502 extern crate std as ab$0c;
1503 //- /std/lib.rs crate:std
1504 //! Standard library for this test
1511 Standard library for this test
1520 fn test_hover_mod_with_same_name_as_function() {
1523 use self::m$0y::Bar;
1524 mod my { pub struct Bar; }
1543 fn test_hover_struct_doc_comment() {
1549 fn foo() { let bar = Ba$0r; }
1570 fn test_hover_struct_doc_attr() {
1576 fn foo() { let bar = Ba$0r; }
1597 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1601 #[doc = "bar docs 1"]
1602 #[doc = "bar docs 2"]
1605 fn foo() { let bar = Ba$0r; }
1628 fn test_hover_path_link() {
1632 /// [Foo](struct.Foo.html)
1648 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1654 fn test_hover_path_link_no_strip() {
1658 /// [struct Foo](struct.Foo.html)
1674 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1679 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1681 fn test_hover_path_link_field() {
1686 /// [Foo](struct.Foo.html)
1703 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1709 fn test_hover_intra_link() {
1731 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1737 fn test_hover_intra_link_html_root_url() {
1740 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1761 [Foo](https://example.com/test/foo/struct.Foo.html)
1767 fn test_hover_intra_link_shortlink() {
1787 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1793 fn test_hover_intra_link_shortlink_code() {
1813 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1819 fn test_hover_intra_link_namespaced() {
1840 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1846 fn test_hover_intra_link_shortlink_namspaced_code() {
1866 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1872 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1892 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1898 fn test_hover_intra_link_reference() {
1920 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1925 fn test_hover_intra_link_reference_to_trait_method() {
1933 /// [buzz]: Foo::buzz
1949 [Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)
1955 fn test_hover_external_url() {
1959 /// [external](https://www.google.com)
1975 [external](https://www.google.com)
1980 // Check that we don't rewrite links which we can't identify
1982 fn test_hover_unknown_target() {
2008 fn test_doc_links_enum_variant() {
2029 [E](https://docs.rs/test/*/test/enum.E.html)
2035 fn test_doc_links_field() {
2056 [`S`](https://docs.rs/test/*/test/struct.S.html)
2062 fn test_hover_no_links() {
2063 check_hover_no_links(
2066 /// case 1. bare URL: https://www.example.com/
2067 /// case 2. inline URL with title: [example](https://www.example.com/)
2068 /// case 3. code reference: [`Result`]
2069 /// case 4. code reference but miss footnote: [`String`]
2070 /// case 5. autolink: <http://www.example.com/>
2071 /// case 6. email address: <test@example.com>
2072 /// case 7. reference: [example][example]
2073 /// case 8. collapsed link: [example][]
2074 /// case 9. shortcut link: [example]
2075 /// case 10. inline without URL: [example]()
2076 /// case 11. reference: [foo][foo]
2077 /// case 12. reference: [foo][bar]
2078 /// case 13. collapsed link: [foo][]
2079 /// case 14. shortcut link: [foo]
2080 /// case 15. inline without URL: [foo]()
2081 /// case 16. just escaped text: \[foo]
2082 /// case 17. inline link: [Foo](foo::Foo)
2084 /// [`Result`]: ../../std/result/enum.Result.html
2085 /// [^example]: https://www.example.com/
2102 case 1. bare URL: https://www.example.com/
2103 case 2. inline URL with title: [example](https://www.example.com/)
2104 case 3. code reference: `Result`
2105 case 4. code reference but miss footnote: `String`
2106 case 5. autolink: http://www.example.com/
2107 case 6. email address: test@example.com
2108 case 7. reference: example
2109 case 8. collapsed link: example
2110 case 9. shortcut link: example
2111 case 10. inline without URL: example
2112 case 11. reference: foo
2113 case 12. reference: foo
2114 case 13. collapsed link: foo
2115 case 14. shortcut link: foo
2116 case 15. inline without URL: foo
2117 case 16. just escaped text: \[foo]
2118 case 17. inline link: Foo
2120 [^example]: https://www.example.com/
2126 fn test_hover_macro_generated_struct_fn_doc_comment() {
2127 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
2143 fn foo() { let bar = Bar; bar.fo$0o(); }
2164 fn test_hover_macro_generated_struct_fn_doc_attr() {
2165 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
2173 #[doc = "Do the foo"]
2181 fn foo() { let bar = Bar; bar.fo$0o(); }
2202 fn test_hover_trait_has_impl_action() {
2204 r#"trait foo$0() {}"#,
2221 fn test_hover_struct_has_impl_action() {
2223 r"struct foo$0() {}",
2240 fn test_hover_union_has_impl_action() {
2242 r#"union foo$0() {}"#,
2259 fn test_hover_enum_has_impl_action() {
2261 r"enum foo$0() { A, B }",
2278 fn test_hover_self_has_impl_action() {
2280 r#"struct foo where Self$0:;"#,
2297 fn test_hover_test_has_action() {
2307 nav: NavigationTarget {
2312 focus_range: 11..19,
2333 fn test_hover_test_mod_has_action() {
2345 nav: NavigationTarget {
2366 fn test_hover_struct_has_goto_type_action() {
2371 fn main() { let s$0t = S{ f1:0 }; }
2378 mod_path: "test::S",
2379 nav: NavigationTarget {
2387 description: "struct S",
2398 fn test_hover_generic_struct_has_goto_type_actions() {
2402 struct S<T>{ f1: T }
2404 fn main() { let s$0t = S{ f1:Arg(0) }; }
2411 mod_path: "test::S",
2412 nav: NavigationTarget {
2417 focus_range: 24..25,
2420 description: "struct S",
2424 mod_path: "test::Arg",
2425 nav: NavigationTarget {
2433 description: "struct Arg",
2444 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2448 struct S<T>{ f1: T }
2450 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2457 mod_path: "test::S",
2458 nav: NavigationTarget {
2463 focus_range: 24..25,
2466 description: "struct S",
2470 mod_path: "test::Arg",
2471 nav: NavigationTarget {
2479 description: "struct Arg",
2490 fn test_hover_tuple_has_goto_type_actions() {
2499 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2506 mod_path: "test::A",
2507 nav: NavigationTarget {
2515 description: "struct A",
2519 mod_path: "test::B",
2520 nav: NavigationTarget {
2525 focus_range: 22..23,
2528 description: "struct B",
2532 mod_path: "test::M::C",
2533 nav: NavigationTarget {
2538 focus_range: 53..54,
2541 description: "pub struct C",
2552 fn test_hover_return_impl_trait_has_goto_type_action() {
2556 fn foo() -> impl Foo {}
2558 fn main() { let s$0t = foo(); }
2565 mod_path: "test::Foo",
2566 nav: NavigationTarget {
2574 description: "trait Foo",
2585 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2590 fn foo() -> impl Foo<S> {}
2592 fn main() { let s$0t = foo(); }
2599 mod_path: "test::Foo",
2600 nav: NavigationTarget {
2608 description: "trait Foo",
2612 mod_path: "test::S",
2613 nav: NavigationTarget {
2618 focus_range: 23..24,
2621 description: "struct S",
2632 fn test_hover_return_impl_traits_has_goto_type_action() {
2637 fn foo() -> impl Foo + Bar {}
2639 fn main() { let s$0t = foo(); }
2646 mod_path: "test::Foo",
2647 nav: NavigationTarget {
2655 description: "trait Foo",
2659 mod_path: "test::Bar",
2660 nav: NavigationTarget {
2665 focus_range: 19..22,
2668 description: "trait Bar",
2679 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2687 fn foo() -> impl Foo<S1> + Bar<S2> {}
2689 fn main() { let s$0t = foo(); }
2696 mod_path: "test::Foo",
2697 nav: NavigationTarget {
2705 description: "trait Foo",
2709 mod_path: "test::Bar",
2710 nav: NavigationTarget {
2715 focus_range: 22..25,
2718 description: "trait Bar",
2722 mod_path: "test::S1",
2723 nav: NavigationTarget {
2728 focus_range: 39..41,
2731 description: "struct S1",
2735 mod_path: "test::S2",
2736 nav: NavigationTarget {
2741 focus_range: 52..54,
2744 description: "struct S2",
2755 fn test_hover_arg_impl_trait_has_goto_type_action() {
2759 fn foo(ar$0g: &impl Foo) {}
2766 mod_path: "test::Foo",
2767 nav: NavigationTarget {
2775 description: "trait Foo",
2786 fn test_hover_arg_impl_traits_has_goto_type_action() {
2793 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2800 mod_path: "test::Foo",
2801 nav: NavigationTarget {
2809 description: "trait Foo",
2813 mod_path: "test::Bar",
2814 nav: NavigationTarget {
2819 focus_range: 19..22,
2822 description: "trait Bar",
2826 mod_path: "test::S",
2827 nav: NavigationTarget {
2832 focus_range: 36..37,
2835 description: "struct S",
2846 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2851 let fo$0o = async { S };
2854 #[prelude_import] use future::*;
2856 #[lang = "future_trait"]
2857 pub trait Future { type Output; }
2865 mod_path: "test::future::Future",
2866 nav: NavigationTarget {
2870 full_range: 101..163,
2871 focus_range: 140..146,
2874 description: "pub trait Future",
2878 mod_path: "test::S",
2879 nav: NavigationTarget {
2887 description: "struct S",
2898 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2903 fn foo(ar$0g: &impl Foo<S>) {}
2910 mod_path: "test::Foo",
2911 nav: NavigationTarget {
2919 description: "trait Foo",
2923 mod_path: "test::S",
2924 nav: NavigationTarget {
2929 focus_range: 23..24,
2932 description: "struct S",
2943 fn test_hover_dyn_return_has_goto_type_action() {
2951 fn foo() -> B<dyn Foo> {}
2953 fn main() { let s$0t = foo(); }
2960 mod_path: "test::B",
2961 nav: NavigationTarget {
2966 focus_range: 49..50,
2969 description: "struct B",
2973 mod_path: "test::Foo",
2974 nav: NavigationTarget {
2982 description: "trait Foo",
2993 fn test_hover_dyn_arg_has_goto_type_action() {
2997 fn foo(ar$0g: &dyn Foo) {}
3004 mod_path: "test::Foo",
3005 nav: NavigationTarget {
3013 description: "trait Foo",
3024 fn test_hover_generic_dyn_arg_has_goto_type_action() {
3029 fn foo(ar$0g: &dyn Foo<S>) {}
3036 mod_path: "test::Foo",
3037 nav: NavigationTarget {
3045 description: "trait Foo",
3049 mod_path: "test::S",
3050 nav: NavigationTarget {
3055 focus_range: 23..24,
3058 description: "struct S",
3069 fn test_hover_goto_type_action_links_order() {
3072 trait ImplTrait<T> {}
3073 trait DynTrait<T> {}
3077 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3084 mod_path: "test::ImplTrait",
3085 nav: NavigationTarget {
3093 description: "trait ImplTrait",
3097 mod_path: "test::B",
3098 nav: NavigationTarget {
3103 focus_range: 50..51,
3106 description: "struct B",
3110 mod_path: "test::DynTrait",
3111 nav: NavigationTarget {
3116 focus_range: 28..36,
3119 description: "trait DynTrait",
3123 mod_path: "test::S",
3124 nav: NavigationTarget {
3129 focus_range: 65..66,
3132 description: "struct S",
3143 fn test_hover_associated_type_has_goto_type_action() {
3148 fn get(self) -> Self::Item {}
3154 impl Foo for S { type Item = Bar; }
3156 fn test() -> impl Foo { S {} }
3158 fn main() { let s$0t = test().get(); }
3165 mod_path: "test::Foo",
3166 nav: NavigationTarget {
3174 description: "trait Foo",
3185 fn test_hover_const_param_has_goto_type_action() {
3189 struct Foo<const BAR: Bar>;
3191 impl<const BAR: Bar> Foo<BAR$0> {}
3198 mod_path: "test::Bar",
3199 nav: NavigationTarget {
3207 description: "struct Bar",
3218 fn test_hover_type_param_has_goto_type_action() {
3223 fn foo<T: Foo>(t: T$0){}
3230 mod_path: "test::Foo",
3231 nav: NavigationTarget {
3239 description: "trait Foo",
3250 fn test_hover_self_has_go_to_type() {
3263 mod_path: "test::Foo",
3264 nav: NavigationTarget {
3272 description: "struct Foo",
3283 fn hover_displays_normalized_crate_names() {
3286 //- /lib.rs crate:name-with-dashes
3288 pub struct Thing { x: u32 }
3291 pub fn new() -> Thing { Thing { x: 0 } }
3295 //- /main.rs crate:main deps:name-with-dashes
3296 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3302 name_with_dashes::wrapper::Thing
3306 pub fn new() -> Thing
3313 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3336 fn hover_self_param_shows_type() {
3355 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3361 fn bar(sel$0f: Arc<Foo>) {}
3375 fn hover_doc_outer_inner() {
3382 /// This comment belongs to the function
3406 fn hover_doc_outer_inner_attribue() {
3409 #[doc = "Be quick;"]
3411 #![doc = "time is mana"]
3413 #[doc = "This comment belongs to the function"]
3437 fn hover_comments_dont_highlight_parent() {
3438 check_hover_no_result(
3466 fn hover_lifetime() {
3468 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3480 fn hover_type_param() {
3487 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3493 T: Copy + Clone + Sized
3510 // lifetimes bounds arent being tracked yet
3514 impl<T: 'static> Foo<T$0> {}
3527 fn hover_const_param() {
3530 struct Foo<const LEN: usize>;
3531 impl<const LEN: usize> Foo<LEN$0> {}
3544 fn hover_const_pat() {
3548 const FOO: usize = 3;
3575 fn hover_mod_def() {
3591 fn hover_self_in_use() {
3594 //! This should not appear
3596 /// But this should appear
3599 use foo::bar::{self$0};
3614 But this should appear
3620 fn hover_keyword() {
3621 let ra_fixture = r#"//- /main.rs crate:main deps:std
3622 fn f() { retur$0n; }"#;
3623 let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
3635 Docs for return_keyword
3641 fn hover_builtin() {
3642 let ra_fixture = r#"//- /main.rs crate:main deps:std
3643 cosnt _: &str$0 = ""; }"#;
3644 let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);