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_assists/src/assist_ctx.rs | 8 ++++++-- crates/ra_assists/src/assists/add_new.rs | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 9d533fa0c..43f0d664b 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,6 +1,6 @@ //! This module defines `AssistCtx` -- the API surface that is exposed to assists. use either::Either; -use hir::{db::HirDatabase, InFile, SourceAnalyzer}; +use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder}; use ra_db::FileRange; use ra_fmt::{leading_indent, reindent}; use ra_syntax::{ @@ -142,12 +142,16 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { pub(crate) fn covering_element(&self) -> SyntaxElement { find_covering_element(self.source_file.syntax(), self.frange.range) } + pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> { + SourceBinder::new(self.db) + } pub(crate) fn source_analyzer( &self, node: &SyntaxNode, offset: Option, ) -> SourceAnalyzer { - SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset) + let src = InFile::new(self.frange.file_id.into(), node); + self.source_binder().analyze(src, offset) } pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs index d148d6e73..aedcd6286 100644 --- a/crates/ra_assists/src/assists/add_new.rs +++ b/crates/ra_assists/src/assists/add_new.rs @@ -1,5 +1,5 @@ use format_buf::format; -use hir::{db::HirDatabase, FromSource, InFile}; +use hir::{db::HirDatabase, InFile}; use join_to_string::join; use ra_syntax::{ ast::{ @@ -136,15 +136,16 @@ fn find_struct_impl( let module = strukt.syntax().ancestors().find(|node| { ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) })?; + let mut sb = ctx.source_binder(); let struct_ty = { let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; - hir::Struct::from_source(db, src)?.ty(db) + sb.to_def::(src)?.ty(db) }; let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| { let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; - let blk = hir::ImplBlock::from_source(db, src)?; + let blk = sb.to_def::(src)?; let same_ty = blk.target_ty(db) == struct_ty; let not_trait_impl = blk.target_trait(db).is_none(); -- cgit v1.2.3