2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
6 base_db::SourceDatabase,
7 defs::{Definition, NameClass, NameRefClass},
11 use itertools::Itertools;
13 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 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
197 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) => Some(Markup::fenced_block(&it.ty(db).display(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_keyword(
410 sema: &Semantics<RootDatabase>,
411 links_in_hover: bool,
414 ) -> Option<RangeInfo<HoverResult>> {
415 if !token.kind().is_keyword() {
418 let famous_defs = FamousDefs(&sema, sema.scope(&token.parent()).krate());
419 // std exposes {}_keyword modules with docstrings on the root to document keywords
420 let keyword_mod = format!("{}_keyword", token.text());
421 let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
422 let docs = doc_owner.attrs(sema.db).docs()?;
423 let markup = process_markup(
425 Definition::ModuleDef(doc_owner.into()),
426 &hover_markup(Some(docs.into()), Some(token.text().into()), None)?,
430 Some(RangeInfo::new(token.text_range(), HoverResult { markup, actions: Default::default() }))
433 fn hover_for_builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option<Markup> {
434 // std exposes prim_{} modules with docstrings on the root to document the builtins
435 let primitive_mod = format!("prim_{}", builtin.name());
436 let doc_owner = find_std_module(famous_defs, &primitive_mod)?;
437 let docs = doc_owner.attrs(famous_defs.0.db).docs()?;
438 hover_markup(Some(docs.into()), Some(builtin.name().to_string()), None)
441 fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module> {
442 let db = famous_defs.0.db;
443 let std_crate = famous_defs.std()?;
444 let std_root_module = std_crate.root_module(db);
447 .find(|module| module.name(db).map_or(false, |module| module.to_string() == name))
450 fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
451 return tokens.max_by_key(priority);
452 fn priority(n: &SyntaxToken) -> usize {
454 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
455 T!['('] | T![')'] => 2,
456 kind if kind.is_trivia() => 0,
464 use expect_test::{expect, Expect};
465 use ide_db::base_db::FileLoader;
471 fn check_hover_no_result(ra_fixture: &str) {
472 let (analysis, position) = fixture::position(ra_fixture);
473 assert!(analysis.hover(position, true, true).unwrap().is_none());
476 fn check(ra_fixture: &str, expect: Expect) {
477 let (analysis, position) = fixture::position(ra_fixture);
478 let hover = analysis.hover(position, true, true).unwrap().unwrap();
480 let content = analysis.db.file_text(position.file_id);
481 let hovered_element = &content[hover.range];
483 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
484 expect.assert_eq(&actual)
487 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
488 let (analysis, position) = fixture::position(ra_fixture);
489 let hover = analysis.hover(position, false, true).unwrap().unwrap();
491 let content = analysis.db.file_text(position.file_id);
492 let hovered_element = &content[hover.range];
494 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
495 expect.assert_eq(&actual)
498 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
499 let (analysis, position) = fixture::position(ra_fixture);
500 let hover = analysis.hover(position, true, false).unwrap().unwrap();
502 let content = analysis.db.file_text(position.file_id);
503 let hovered_element = &content[hover.range];
505 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
506 expect.assert_eq(&actual)
509 fn check_actions(ra_fixture: &str, expect: Expect) {
510 let (analysis, position) = fixture::position(ra_fixture);
511 let hover = analysis.hover(position, true, true).unwrap().unwrap();
512 expect.assert_debug_eq(&hover.info.actions)
516 fn hover_shows_type_of_an_expression() {
519 pub fn foo() -> u32 { 1 }
522 let foo_test = foo()$0;
535 fn hover_remove_markdown_if_configured() {
536 check_hover_no_markdown(
538 pub fn foo() -> u32 { 1 }
541 let foo_test = foo()$0;
552 fn hover_shows_long_type_of_an_expression() {
555 struct Scan<A, B, C> { a: A, b: B, c: C }
556 struct Iter<I> { inner: I }
557 enum Option<T> { Some(T), None }
559 struct OtherStruct<T> { i: T }
561 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
562 Iter { inner: Scan { a, b, c } }
567 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
568 Option::Some(*memo + value)
571 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
578 Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
585 fn hover_shows_fn_signature() {
586 // Single file with result
589 pub fn foo() -> u32 { 1 }
591 fn main() { let foo_test = fo$0o(); }
606 // Multiple candidates but results are ambiguous.
610 pub fn foo() -> u32 { 1 }
613 pub fn foo() -> &str { "" }
616 pub fn foo(a: u32, b: u32) {}
623 fn main() { let foo_test = fo$0o(); }
635 fn hover_shows_fn_signature_with_type_params() {
638 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
640 fn main() { let foo_test = fo$0o(); }
650 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str
657 fn hover_shows_fn_signature_on_fn_name() {
660 pub fn foo$0(a: u32, b: u32) -> u32 {}
672 pub fn foo(a: u32, b: u32) -> u32
679 fn hover_shows_fn_doc() {
684 /// # use std::path::Path;
686 /// foo(Path::new("hello, world!"))
688 pub fn foo$0(_: &Path) {}
708 # use std::path::Path;
710 foo(Path::new("hello, world!"))
717 fn hover_shows_fn_doc_attr_raw_string() {
720 #[doc = r#"Raw string doc attr"#]
721 pub fn foo$0(_: &Path) {}
744 fn hover_shows_struct_field_info() {
745 // Hovering over the field when instantiating
748 struct Foo { field_a: u32 }
751 let foo = Foo { field_a$0: 0, };
767 // Hovering over the field in the definition
770 struct Foo { field_a$0: u32 }
773 let foo = Foo { field_a: 0 };
791 fn hover_const_static() {
793 r#"const foo$0: u32 = 123;"#,
807 r#"static foo$0: u32 = 456;"#,
823 fn hover_default_generic_types() {
826 struct Test<K, T = u8> { k: K, t: T }
829 let zz$0 = Test { t: 23u8, k: 33 };
845 enum Option<T> { Some(T) }
848 fn main() { So$0me(12); }
865 enum Option<T> { Some(T) }
868 fn main() { let b$0ar = Some(12); }
881 fn hover_enum_variant() {
913 let s = Option::Som$0e(12);
935 fn hover_for_local_variable() {
937 r#"fn func(foo: i32) { fo$0o; }"#,
949 fn hover_for_local_variable_pat() {
951 r#"fn func(fo$0o: i32) {}"#,
963 fn hover_local_var_edge() {
965 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
977 fn hover_for_param_edge() {
979 r#"fn func($0foo: i32) {}"#,
991 fn hover_for_param_with_multiple_traits() {
999 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
1004 impl Deref<Target = u8> + DerefMut<Target = u8>
1011 fn test_hover_infer_associated_method_result() {
1014 struct Thing { x: u32 }
1017 fn new() -> Thing { Thing { x: 0 } }
1020 fn main() { let foo_$0test = Thing::new(); }
1033 fn test_hover_infer_associated_method_exact() {
1037 struct Thing { x: u32 }
1040 fn new() -> Thing { Thing { x: 0 } }
1044 fn main() { let foo_test = wrapper::Thing::new$0(); }
1050 test::wrapper::Thing
1061 fn test_hover_infer_associated_const_in_pattern() {
1092 fn test_hover_self() {
1095 struct Thing { x: u32 }
1097 fn new() -> Self { Self$0 { x: 0 } }
1114 struct Thing { x: u32 }
1116 fn new() -> Self$0 { Self { x: 0 } }
1135 pub fn new() -> Self$0 { Thing::A }
1154 pub fn thing(a: Self$0) {}
1172 fn test_hover_shadowing_pat() {
1193 fn test_hover_macro_invocation() {
1196 macro_rules! foo { () => {} }
1198 fn f() { fo$0o!(); }
1215 fn test_hover_tuple_field() {
1217 r#"struct TS(String, i32$0);"#,
1229 fn test_hover_through_macro() {
1232 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1235 fn bar() { fo$0o(); }
1253 fn test_hover_through_expr_in_macro() {
1256 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1257 fn foo(bar:u32) { let a = id!(ba$0r); }
1270 fn test_hover_through_expr_in_macro_recursive() {
1273 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1274 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1275 fn foo(bar:u32) { let a = id!(ba$0r); }
1288 fn test_hover_through_func_in_macro_recursive() {
1291 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1292 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1293 fn bar() -> u32 { 0 }
1294 fn foo() { let a = id!([0u32, bar($0)] ); }
1306 fn test_hover_through_literal_string_in_macro() {
1309 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1311 let mastered_for_itunes = "";
1312 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1325 fn test_hover_through_assert_macro() {
1328 #[rustc_builtin_macro]
1329 macro_rules! assert {}
1331 fn bar() -> bool { true }
1351 fn test_hover_through_literal_string_in_builtin_macro() {
1352 check_hover_no_result(
1354 #[rustc_builtin_macro]
1355 macro_rules! format {}
1358 format!("hel$0lo {}", 0);
1365 fn test_hover_non_ascii_space_doc() {
1368 /// <- `\u{3000}` here
1371 fn bar() { fo$0o(); }
1392 fn test_hover_function_show_qualifiers() {
1394 r#"async fn foo$0() {}"#,
1408 r#"pub const unsafe fn foo$0() {}"#,
1417 pub const unsafe fn foo()
1422 r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
1431 pub(crate) async unsafe extern "C" fn foo()
1438 fn test_hover_trait_show_qualifiers() {
1440 r"unsafe trait foo$0() {}",
1457 fn test_hover_extern_crate() {
1460 //- /main.rs crate:main deps:std
1462 //- /std/lib.rs crate:std
1463 //! Standard library for this test
1470 Standard library for this test
1478 //- /main.rs crate:main deps:std
1479 extern crate std as ab$0c;
1480 //- /std/lib.rs crate:std
1481 //! Standard library for this test
1488 Standard library for this test
1497 fn test_hover_mod_with_same_name_as_function() {
1500 use self::m$0y::Bar;
1501 mod my { pub struct Bar; }
1520 fn test_hover_struct_doc_comment() {
1526 fn foo() { let bar = Ba$0r; }
1547 fn test_hover_struct_doc_attr() {
1553 fn foo() { let bar = Ba$0r; }
1574 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1578 #[doc = "bar docs 1"]
1579 #[doc = "bar docs 2"]
1582 fn foo() { let bar = Ba$0r; }
1605 fn test_hover_path_link() {
1609 /// [Foo](struct.Foo.html)
1625 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1631 fn test_hover_path_link_no_strip() {
1635 /// [struct Foo](struct.Foo.html)
1651 [struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
1656 #[ignore = "path based links currently only support documentation on ModuleDef items"]
1658 fn test_hover_path_link_field() {
1663 /// [Foo](struct.Foo.html)
1680 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1686 fn test_hover_intra_link() {
1708 [Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
1714 fn test_hover_intra_link_html_root_url() {
1717 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
1738 [Foo](https://example.com/test/foo/struct.Foo.html)
1744 fn test_hover_intra_link_shortlink() {
1764 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1770 fn test_hover_intra_link_shortlink_code() {
1790 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1796 fn test_hover_intra_link_namespaced() {
1817 [Foo](https://docs.rs/test/*/test/struct.Foo.html)
1823 fn test_hover_intra_link_shortlink_namspaced_code() {
1843 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1849 fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
1869 [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
1875 fn test_hover_intra_link_reference() {
1897 [my Foo](https://docs.rs/test/*/test/struct.Foo.html)
1902 fn test_hover_intra_link_reference_to_trait_method() {
1910 /// [buzz]: Foo::buzz
1926 [Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)
1932 fn test_hover_external_url() {
1936 /// [external](https://www.google.com)
1952 [external](https://www.google.com)
1957 // Check that we don't rewrite links which we can't identify
1959 fn test_hover_unknown_target() {
1985 fn test_doc_links_enum_variant() {
2006 [E](https://docs.rs/test/*/test/enum.E.html)
2012 fn test_doc_links_field() {
2033 [`S`](https://docs.rs/test/*/test/struct.S.html)
2039 fn test_hover_no_links() {
2040 check_hover_no_links(
2043 /// case 1. bare URL: https://www.example.com/
2044 /// case 2. inline URL with title: [example](https://www.example.com/)
2045 /// case 3. code reference: [`Result`]
2046 /// case 4. code reference but miss footnote: [`String`]
2047 /// case 5. autolink: <http://www.example.com/>
2048 /// case 6. email address: <test@example.com>
2049 /// case 7. reference: [example][example]
2050 /// case 8. collapsed link: [example][]
2051 /// case 9. shortcut link: [example]
2052 /// case 10. inline without URL: [example]()
2053 /// case 11. reference: [foo][foo]
2054 /// case 12. reference: [foo][bar]
2055 /// case 13. collapsed link: [foo][]
2056 /// case 14. shortcut link: [foo]
2057 /// case 15. inline without URL: [foo]()
2058 /// case 16. just escaped text: \[foo]
2059 /// case 17. inline link: [Foo](foo::Foo)
2061 /// [`Result`]: ../../std/result/enum.Result.html
2062 /// [^example]: https://www.example.com/
2079 case 1. bare URL: https://www.example.com/
2080 case 2. inline URL with title: [example](https://www.example.com/)
2081 case 3. code reference: `Result`
2082 case 4. code reference but miss footnote: `String`
2083 case 5. autolink: http://www.example.com/
2084 case 6. email address: test@example.com
2085 case 7. reference: example
2086 case 8. collapsed link: example
2087 case 9. shortcut link: example
2088 case 10. inline without URL: example
2089 case 11. reference: foo
2090 case 12. reference: foo
2091 case 13. collapsed link: foo
2092 case 14. shortcut link: foo
2093 case 15. inline without URL: foo
2094 case 16. just escaped text: \[foo]
2095 case 17. inline link: Foo
2097 [^example]: https://www.example.com/
2103 fn test_hover_macro_generated_struct_fn_doc_comment() {
2104 mark::check!(hover_macro_generated_struct_fn_doc_comment);
2120 fn foo() { let bar = Bar; bar.fo$0o(); }
2141 fn test_hover_macro_generated_struct_fn_doc_attr() {
2142 mark::check!(hover_macro_generated_struct_fn_doc_attr);
2150 #[doc = "Do the foo"]
2158 fn foo() { let bar = Bar; bar.fo$0o(); }
2179 fn test_hover_trait_has_impl_action() {
2181 r#"trait foo$0() {}"#,
2198 fn test_hover_struct_has_impl_action() {
2200 r"struct foo$0() {}",
2217 fn test_hover_union_has_impl_action() {
2219 r#"union foo$0() {}"#,
2236 fn test_hover_enum_has_impl_action() {
2238 r"enum foo$0() { A, B }",
2255 fn test_hover_self_has_impl_action() {
2257 r#"struct foo where Self$0:;"#,
2274 fn test_hover_test_has_action() {
2284 nav: NavigationTarget {
2289 focus_range: 11..19,
2310 fn test_hover_test_mod_has_action() {
2322 nav: NavigationTarget {
2343 fn test_hover_struct_has_goto_type_action() {
2348 fn main() { let s$0t = S{ f1:0 }; }
2355 mod_path: "test::S",
2356 nav: NavigationTarget {
2364 description: "struct S",
2375 fn test_hover_generic_struct_has_goto_type_actions() {
2379 struct S<T>{ f1: T }
2381 fn main() { let s$0t = S{ f1:Arg(0) }; }
2388 mod_path: "test::S",
2389 nav: NavigationTarget {
2394 focus_range: 24..25,
2397 description: "struct S",
2401 mod_path: "test::Arg",
2402 nav: NavigationTarget {
2410 description: "struct Arg",
2421 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2425 struct S<T>{ f1: T }
2427 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2434 mod_path: "test::S",
2435 nav: NavigationTarget {
2440 focus_range: 24..25,
2443 description: "struct S",
2447 mod_path: "test::Arg",
2448 nav: NavigationTarget {
2456 description: "struct Arg",
2467 fn test_hover_tuple_has_goto_type_actions() {
2476 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2483 mod_path: "test::A",
2484 nav: NavigationTarget {
2492 description: "struct A",
2496 mod_path: "test::B",
2497 nav: NavigationTarget {
2502 focus_range: 22..23,
2505 description: "struct B",
2509 mod_path: "test::M::C",
2510 nav: NavigationTarget {
2515 focus_range: 53..54,
2518 description: "pub struct C",
2529 fn test_hover_return_impl_trait_has_goto_type_action() {
2533 fn foo() -> impl Foo {}
2535 fn main() { let s$0t = foo(); }
2542 mod_path: "test::Foo",
2543 nav: NavigationTarget {
2551 description: "trait Foo",
2562 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2567 fn foo() -> impl Foo<S> {}
2569 fn main() { let s$0t = foo(); }
2576 mod_path: "test::Foo",
2577 nav: NavigationTarget {
2585 description: "trait Foo",
2589 mod_path: "test::S",
2590 nav: NavigationTarget {
2595 focus_range: 23..24,
2598 description: "struct S",
2609 fn test_hover_return_impl_traits_has_goto_type_action() {
2614 fn foo() -> impl Foo + Bar {}
2616 fn main() { let s$0t = foo(); }
2623 mod_path: "test::Foo",
2624 nav: NavigationTarget {
2632 description: "trait Foo",
2636 mod_path: "test::Bar",
2637 nav: NavigationTarget {
2642 focus_range: 19..22,
2645 description: "trait Bar",
2656 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2664 fn foo() -> impl Foo<S1> + Bar<S2> {}
2666 fn main() { let s$0t = foo(); }
2673 mod_path: "test::Foo",
2674 nav: NavigationTarget {
2682 description: "trait Foo",
2686 mod_path: "test::Bar",
2687 nav: NavigationTarget {
2692 focus_range: 22..25,
2695 description: "trait Bar",
2699 mod_path: "test::S1",
2700 nav: NavigationTarget {
2705 focus_range: 39..41,
2708 description: "struct S1",
2712 mod_path: "test::S2",
2713 nav: NavigationTarget {
2718 focus_range: 52..54,
2721 description: "struct S2",
2732 fn test_hover_arg_impl_trait_has_goto_type_action() {
2736 fn foo(ar$0g: &impl Foo) {}
2743 mod_path: "test::Foo",
2744 nav: NavigationTarget {
2752 description: "trait Foo",
2763 fn test_hover_arg_impl_traits_has_goto_type_action() {
2770 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2777 mod_path: "test::Foo",
2778 nav: NavigationTarget {
2786 description: "trait Foo",
2790 mod_path: "test::Bar",
2791 nav: NavigationTarget {
2796 focus_range: 19..22,
2799 description: "trait Bar",
2803 mod_path: "test::S",
2804 nav: NavigationTarget {
2809 focus_range: 36..37,
2812 description: "struct S",
2823 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2828 let fo$0o = async { S };
2831 #[prelude_import] use future::*;
2833 #[lang = "future_trait"]
2834 pub trait Future { type Output; }
2842 mod_path: "test::future::Future",
2843 nav: NavigationTarget {
2847 full_range: 101..163,
2848 focus_range: 140..146,
2851 description: "pub trait Future",
2855 mod_path: "test::S",
2856 nav: NavigationTarget {
2864 description: "struct S",
2875 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2880 fn foo(ar$0g: &impl Foo<S>) {}
2887 mod_path: "test::Foo",
2888 nav: NavigationTarget {
2896 description: "trait Foo",
2900 mod_path: "test::S",
2901 nav: NavigationTarget {
2906 focus_range: 23..24,
2909 description: "struct S",
2920 fn test_hover_dyn_return_has_goto_type_action() {
2928 fn foo() -> B<dyn Foo> {}
2930 fn main() { let s$0t = foo(); }
2937 mod_path: "test::B",
2938 nav: NavigationTarget {
2943 focus_range: 49..50,
2946 description: "struct B",
2950 mod_path: "test::Foo",
2951 nav: NavigationTarget {
2959 description: "trait Foo",
2970 fn test_hover_dyn_arg_has_goto_type_action() {
2974 fn foo(ar$0g: &dyn Foo) {}
2981 mod_path: "test::Foo",
2982 nav: NavigationTarget {
2990 description: "trait Foo",
3001 fn test_hover_generic_dyn_arg_has_goto_type_action() {
3006 fn foo(ar$0g: &dyn Foo<S>) {}
3013 mod_path: "test::Foo",
3014 nav: NavigationTarget {
3022 description: "trait Foo",
3026 mod_path: "test::S",
3027 nav: NavigationTarget {
3032 focus_range: 23..24,
3035 description: "struct S",
3046 fn test_hover_goto_type_action_links_order() {
3049 trait ImplTrait<T> {}
3050 trait DynTrait<T> {}
3054 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3061 mod_path: "test::ImplTrait",
3062 nav: NavigationTarget {
3070 description: "trait ImplTrait",
3074 mod_path: "test::B",
3075 nav: NavigationTarget {
3080 focus_range: 50..51,
3083 description: "struct B",
3087 mod_path: "test::DynTrait",
3088 nav: NavigationTarget {
3093 focus_range: 28..36,
3096 description: "trait DynTrait",
3100 mod_path: "test::S",
3101 nav: NavigationTarget {
3106 focus_range: 65..66,
3109 description: "struct S",
3120 fn test_hover_associated_type_has_goto_type_action() {
3125 fn get(self) -> Self::Item {}
3131 impl Foo for S { type Item = Bar; }
3133 fn test() -> impl Foo { S {} }
3135 fn main() { let s$0t = test().get(); }
3142 mod_path: "test::Foo",
3143 nav: NavigationTarget {
3151 description: "trait Foo",
3162 fn test_hover_const_param_has_goto_type_action() {
3166 struct Foo<const BAR: Bar>;
3168 impl<const BAR: Bar> Foo<BAR$0> {}
3175 mod_path: "test::Bar",
3176 nav: NavigationTarget {
3184 description: "struct Bar",
3195 fn test_hover_type_param_has_goto_type_action() {
3200 fn foo<T: Foo>(t: T$0){}
3207 mod_path: "test::Foo",
3208 nav: NavigationTarget {
3216 description: "trait Foo",
3227 fn test_hover_self_has_go_to_type() {
3240 mod_path: "test::Foo",
3241 nav: NavigationTarget {
3249 description: "struct Foo",
3260 fn hover_displays_normalized_crate_names() {
3263 //- /lib.rs crate:name-with-dashes
3265 pub struct Thing { x: u32 }
3268 pub fn new() -> Thing { Thing { x: 0 } }
3272 //- /main.rs crate:main deps:name-with-dashes
3273 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3279 name_with_dashes::wrapper::Thing
3283 pub fn new() -> Thing
3290 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3313 fn hover_self_param_shows_type() {
3332 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3338 fn bar(sel$0f: Arc<Foo>) {}
3352 fn hover_doc_outer_inner() {
3359 /// This comment belongs to the function
3383 fn hover_doc_outer_inner_attribue() {
3386 #[doc = "Be quick;"]
3388 #![doc = "time is mana"]
3390 #[doc = "This comment belongs to the function"]
3414 fn hover_comments_dont_highlight_parent() {
3415 check_hover_no_result(
3443 fn hover_lifetime() {
3445 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3457 fn hover_type_param() {
3464 impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3470 T: Copy + Clone + Sized
3487 // lifetimes bounds arent being tracked yet
3491 impl<T: 'static> Foo<T$0> {}
3504 fn hover_const_param() {
3507 struct Foo<const LEN: usize>;
3508 impl<const LEN: usize> Foo<LEN$0> {}
3521 fn hover_const_pat() {
3525 const FOO: usize = 3;
3541 const FOO: usize = 3
3552 fn hover_mod_def() {
3568 fn hover_self_in_use() {
3571 //! This should not appear
3573 /// But this should appear
3576 use foo::bar::{self$0};
3591 But this should appear
3597 fn hover_keyword() {
3598 let ra_fixture = r#"//- /main.rs crate:main deps:std
3599 fn f() { retur$0n; }"#;
3600 let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
3612 Docs for return_keyword
3618 fn hover_builtin() {
3619 let ra_fixture = r#"//- /main.rs crate:main deps:std
3620 cosnt _: &str$0 = ""; }"#;
3621 let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);