aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/hover.rs
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-03-08 13:26:57 +0000
committerKirill Bulatov <[email protected]>2020-03-08 21:00:50 +0000
commit5cffef56e2c373f6d67b0f7b70d7ade995795c04 (patch)
tree4549fa9ccf4e204057d35f4bbc6c18987690f0ab /crates/ra_ide/src/hover.rs
parent32f5276465266522ebc01b8417feeba99bf00f6f (diff)
Consider crate declaration names
Diffstat (limited to 'crates/ra_ide/src/hover.rs')
-rw-r--r--crates/ra_ide/src/hover.rs43
1 files changed, 13 insertions, 30 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index da3b67943..f87054838 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -1,8 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{ 3use hir::{
4 Adt, AsAssocItem, AssocItemContainer, HasSource, HirDisplay, ModuleDef, ModuleSource, Semantics, 4 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef,
5 ModuleSource, Semantics,
5}; 6};
7use ra_db::SourceDatabase;
6use ra_ide_db::{ 8use ra_ide_db::{
7 defs::{classify_name, classify_name_ref, Definition}, 9 defs::{classify_name, classify_name_ref, Definition},
8 RootDatabase, 10 RootDatabase,
@@ -119,7 +121,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
119 121
120fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { 122fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
121 let mod_path = def.module(db).map(|module| { 123 let mod_path = def.module(db).map(|module| {
122 once(db.get_crate_original_name(&module.krate().into())) 124 once(db.crate_graph().declaration_name(&module.krate().into()).cloned())
123 .chain( 125 .chain(
124 module 126 module
125 .path_to_root(db) 127 .path_to_root(db)
@@ -144,7 +146,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option<Strin
144 Definition::StructField(it) => { 146 Definition::StructField(it) => {
145 let src = it.source(db); 147 let src = it.source(db);
146 match src.value { 148 match src.value {
147 hir::FieldSource::Named(it) => { 149 FieldSource::Named(it) => {
148 hover_text(it.doc_comment_text(), it.short_label(), mod_path) 150 hover_text(it.doc_comment_text(), it.short_label(), mod_path)
149 } 151 }
150 _ => None, 152 _ => None,
@@ -576,21 +578,23 @@ fn func(foo: i32) { if true { <|>foo; }; }
576 fn test_hover_infer_associated_method_exact() { 578 fn test_hover_infer_associated_method_exact() {
577 let (analysis, position) = single_file_with_position( 579 let (analysis, position) = single_file_with_position(
578 " 580 "
579 struct Thing { x: u32 } 581 mod wrapper {
582 struct Thing { x: u32 }
580 583
581 impl Thing { 584 impl Thing {
582 fn new() -> Thing { 585 fn new() -> Thing {
583 Thing { x: 0 } 586 Thing { x: 0 }
587 }
584 } 588 }
585 } 589 }
586 590
587 fn main() { 591 fn main() {
588 let foo_test = Thing::new<|>(); 592 let foo_test = wrapper::Thing::new<|>();
589 } 593 }
590 ", 594 ",
591 ); 595 );
592 let hover = analysis.hover(position).unwrap().unwrap(); 596 let hover = analysis.hover(position).unwrap().unwrap();
593 assert_eq!(trim_markup_opt(hover.info.first()), Some("fn new() -> Thing")); 597 assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing"));
594 assert_eq!(hover.info.is_exact(), true); 598 assert_eq!(hover.info.is_exact(), true);
595 } 599 }
596 600
@@ -863,25 +867,4 @@ fn func(foo: i32) { if true { <|>foo; }; }
863 &["fn foo()\n```\n\n<- `\u{3000}` here"], 867 &["fn foo()\n```\n\n<- `\u{3000}` here"],
864 ); 868 );
865 } 869 }
866
867 #[test]
868 fn zzz() {
869 check_hover_result(
870 "
871 //- /main.rs
872 mod vvv {
873 pub struct Test;
874
875 impl Test {
876 pub fn whatever() {}
877 }
878 }
879
880 fn main() {
881 vvv::Test::what<|>ever();
882 }
883 ",
884 &["vvv::Test\npub fn whatever()"],
885 );
886 }
887} 870}