From 5cffef56e2c373f6d67b0f7b70d7ade995795c04 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 8 Mar 2020 15:26:57 +0200 Subject: Consider crate declaration names --- crates/ra_ide/src/hover.rs | 43 ++++++++++++-------------------------- crates/ra_ide/src/lib.rs | 8 ++++++- crates/ra_ide/src/mock_analysis.rs | 10 +++++++-- crates/ra_ide/src/parent_module.rs | 1 + 4 files changed, 29 insertions(+), 33 deletions(-) (limited to 'crates/ra_ide/src') 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 @@ //! FIXME: write short doc here use hir::{ - Adt, AsAssocItem, AssocItemContainer, HasSource, HirDisplay, ModuleDef, ModuleSource, Semantics, + Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef, + ModuleSource, Semantics, }; +use ra_db::SourceDatabase; use ra_ide_db::{ defs::{classify_name, classify_name_ref, Definition}, RootDatabase, @@ -119,7 +121,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option { let mod_path = def.module(db).map(|module| { - once(db.get_crate_original_name(&module.krate().into())) + once(db.crate_graph().declaration_name(&module.krate().into()).cloned()) .chain( module .path_to_root(db) @@ -144,7 +146,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option { let src = it.source(db); match src.value { - hir::FieldSource::Named(it) => { + FieldSource::Named(it) => { hover_text(it.doc_comment_text(), it.short_label(), mod_path) } _ => None, @@ -576,21 +578,23 @@ fn func(foo: i32) { if true { <|>foo; }; } fn test_hover_infer_associated_method_exact() { let (analysis, position) = single_file_with_position( " - struct Thing { x: u32 } + mod wrapper { + struct Thing { x: u32 } - impl Thing { - fn new() -> Thing { - Thing { x: 0 } + impl Thing { + fn new() -> Thing { + Thing { x: 0 } + } } } fn main() { - let foo_test = Thing::new<|>(); + let foo_test = wrapper::Thing::new<|>(); } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("fn new() -> Thing")); + assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing")); assert_eq!(hover.info.is_exact(), true); } @@ -863,25 +867,4 @@ fn func(foo: i32) { if true { <|>foo; }; } &["fn foo()\n```\n\n<- `\u{3000}` here"], ); } - - #[test] - fn zzz() { - check_hover_result( - " - //- /main.rs - mod vvv { - pub struct Test; - - impl Test { - pub fn whatever() {} - } - } - - fn main() { - vvv::Test::what<|>ever(); - } - ", - &["vvv::Test\npub fn whatever()"], - ); - } } 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 { // Default to enable test for single file. let mut cfg_options = CfgOptions::default(); cfg_options.insert_atom("test".into()); - crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default()); + crate_graph.add_crate_root( + file_id, + Edition::Edition2018, + None, + cfg_options, + Env::default(), + ); change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); change.set_crate_graph(crate_graph); 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 { root_crate = Some(crate_graph.add_crate_root( file_id, Edition2018, + None, cfg_options, Env::default(), )); } else if path.ends_with("/lib.rs") { - let other_crate = - crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default()); let crate_name = path.parent().unwrap().file_name().unwrap(); + let other_crate = crate_graph.add_crate_root( + file_id, + Edition2018, + Some(crate_name.to_owned()), + cfg_options, + Env::default(), + ); if let Some(root_crate) = root_crate { crate_graph .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 { let crate_id = crate_graph.add_crate_root( root_file, Edition2018, + None, CfgOptions::default(), Env::default(), ); -- cgit v1.2.3