diff options
author | Kirill Bulatov <[email protected]> | 2020-03-08 13:26:57 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-03-08 21:00:50 +0000 |
commit | 5cffef56e2c373f6d67b0f7b70d7ade995795c04 (patch) | |
tree | 4549fa9ccf4e204057d35f4bbc6c18987690f0ab /crates/ra_ide/src | |
parent | 32f5276465266522ebc01b8417feeba99bf00f6f (diff) |
Consider crate declaration names
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/hover.rs | 43 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/parent_module.rs | 1 |
4 files changed, 29 insertions, 33 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 | ||
3 | use hir::{ | 3 | use hir::{ |
4 | Adt, AsAssocItem, AssocItemContainer, HasSource, HirDisplay, ModuleDef, ModuleSource, Semantics, | 4 | Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef, |
5 | ModuleSource, Semantics, | ||
5 | }; | 6 | }; |
7 | use ra_db::SourceDatabase; | ||
6 | use ra_ide_db::{ | 8 | use 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 | ||
120 | fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { | 122 | fn 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 | } |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 4dfe0553e..56bc57d5c 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -211,7 +211,13 @@ impl Analysis { | |||
211 | // Default to enable test for single file. | 211 | // Default to enable test for single file. |
212 | let mut cfg_options = CfgOptions::default(); | 212 | let mut cfg_options = CfgOptions::default(); |
213 | cfg_options.insert_atom("test".into()); | 213 | cfg_options.insert_atom("test".into()); |
214 | crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default()); | 214 | crate_graph.add_crate_root( |
215 | file_id, | ||
216 | Edition::Edition2018, | ||
217 | None, | ||
218 | cfg_options, | ||
219 | Env::default(), | ||
220 | ); | ||
215 | change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); | 221 | change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); |
216 | change.set_crate_graph(crate_graph); | 222 | change.set_crate_graph(crate_graph); |
217 | host.apply_change(change); | 223 | host.apply_change(change); |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index f4cd6deb7..90f84b052 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -99,13 +99,19 @@ impl MockAnalysis { | |||
99 | root_crate = Some(crate_graph.add_crate_root( | 99 | root_crate = Some(crate_graph.add_crate_root( |
100 | file_id, | 100 | file_id, |
101 | Edition2018, | 101 | Edition2018, |
102 | None, | ||
102 | cfg_options, | 103 | cfg_options, |
103 | Env::default(), | 104 | Env::default(), |
104 | )); | 105 | )); |
105 | } else if path.ends_with("/lib.rs") { | 106 | } else if path.ends_with("/lib.rs") { |
106 | let other_crate = | ||
107 | crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default()); | ||
108 | let crate_name = path.parent().unwrap().file_name().unwrap(); | 107 | let crate_name = path.parent().unwrap().file_name().unwrap(); |
108 | let other_crate = crate_graph.add_crate_root( | ||
109 | file_id, | ||
110 | Edition2018, | ||
111 | Some(crate_name.to_owned()), | ||
112 | cfg_options, | ||
113 | Env::default(), | ||
114 | ); | ||
109 | if let Some(root_crate) = root_crate { | 115 | if let Some(root_crate) = root_crate { |
110 | crate_graph | 116 | crate_graph |
111 | .add_dep(root_crate, CrateName::new(crate_name).unwrap(), other_crate) | 117 | .add_dep(root_crate, CrateName::new(crate_name).unwrap(), other_crate) |
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index 2c4bdb039..b73cefd97 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs | |||
@@ -133,6 +133,7 @@ mod tests { | |||
133 | let crate_id = crate_graph.add_crate_root( | 133 | let crate_id = crate_graph.add_crate_root( |
134 | root_file, | 134 | root_file, |
135 | Edition2018, | 135 | Edition2018, |
136 | None, | ||
136 | CfgOptions::default(), | 137 | CfgOptions::default(), |
137 | Env::default(), | 138 | Env::default(), |
138 | ); | 139 | ); |