From 81a45ca1b3606d2c328740aa7e2dc989b9e128a5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jan 2020 16:08:46 +0100 Subject: Make FromSource private --- crates/ra_ide/src/impls.rs | 31 ++++++++++++++++--------------- crates/ra_ide/src/references/classify.rs | 4 ++-- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index 31195036e..bd14a6d13 100644 --- a/crates/ra_ide/src/impls.rs +++ b/crates/ra_ide/src/impls.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{FromSource, ImplBlock}; +use hir::{ImplBlock, SourceBinder}; use ra_db::SourceDatabase; use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; @@ -12,6 +12,7 @@ pub(crate) fn goto_implementation( ) -> Option>> { let parse = db.parse(position.file_id); let syntax = parse.tree().syntax().clone(); + let mut sb = SourceBinder::new(db); let src = hir::ModuleSource::from_position(db, position); let module = hir::Module::from_definition( @@ -22,12 +23,12 @@ pub(crate) fn goto_implementation( if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( nominal_def.syntax().text_range(), - impls_for_def(db, position, &nominal_def, module)?, + impls_for_def(&mut sb, position, &nominal_def, module)?, )); } else if let Some(trait_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( trait_def.syntax().text_range(), - impls_for_trait(db, position, &trait_def, module)?, + impls_for_trait(&mut sb, position, &trait_def, module)?, )); } @@ -35,7 +36,7 @@ pub(crate) fn goto_implementation( } fn impls_for_def( - db: &RootDatabase, + sb: &mut SourceBinder, position: FilePosition, node: &ast::NominalDef, module: hir::Module, @@ -43,43 +44,43 @@ fn impls_for_def( let ty = match node { ast::NominalDef::StructDef(def) => { let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; - hir::Struct::from_source(db, src)?.ty(db) + sb.to_def::(src)?.ty(sb.db) } ast::NominalDef::EnumDef(def) => { let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; - hir::Enum::from_source(db, src)?.ty(db) + sb.to_def::(src)?.ty(sb.db) } ast::NominalDef::UnionDef(def) => { let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; - hir::Union::from_source(db, src)?.ty(db) + sb.to_def::(src)?.ty(sb.db) } }; let krate = module.krate(); - let impls = ImplBlock::all_in_crate(db, krate); + let impls = ImplBlock::all_in_crate(sb.db, krate); Some( impls .into_iter() - .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(db))) - .map(|imp| imp.to_nav(db)) + .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(sb.db))) + .map(|imp| imp.to_nav(sb.db)) .collect(), ) } fn impls_for_trait( - db: &RootDatabase, + sb: &mut SourceBinder, position: FilePosition, node: &ast::TraitDef, module: hir::Module, ) -> Option> { let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; - let tr = hir::Trait::from_source(db, src)?; + let tr = sb.to_def(src)?; let krate = module.krate(); - let impls = ImplBlock::for_trait(db, krate, tr); + let impls = ImplBlock::for_trait(sb.db, krate, tr); - Some(impls.into_iter().map(|imp| imp.to_nav(db)).collect()) + Some(impls.into_iter().map(|imp| imp.to_nav(sb.db)).collect()) } #[cfg(test)] @@ -210,7 +211,7 @@ mod tests { " //- /lib.rs #[derive(Copy)] - struct Foo<|>; + struct Foo<|>; ", &["impl IMPL_BLOCK FileId(1) [0; 15)"], ); diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 4a6e11e27..dcffc3df2 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -1,6 +1,6 @@ //! Functions that are used to classify an element from its definition or reference. -use hir::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceBinder}; +use hir::{InFile, Module, ModuleSource, PathResolution, SourceBinder}; use ra_prof::profile; use ra_syntax::{ast, match_ast, AstNode}; use test_utils::tested_by; @@ -101,7 +101,7 @@ pub(crate) fn classify_name( }, ast::MacroCall(it) => { let src = name.with_value(it); - let def = hir::MacroDef::from_source(sb.db, src.clone())?; + let def = sb.to_def(src.clone())?; let module_src = ModuleSource::from_child_node(sb.db, src.as_ref().map(|it| it.syntax())); let module = Module::from_definition(sb.db, src.with_value(module_src))?; -- cgit v1.2.3