aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs8
-rw-r--r--crates/ra_assists/src/assists/add_new.rs7
2 files changed, 10 insertions, 5 deletions
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 @@
1//! This module defines `AssistCtx` -- the API surface that is exposed to assists. 1//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
2use either::Either; 2use either::Either;
3use hir::{db::HirDatabase, InFile, SourceAnalyzer}; 3use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder};
4use ra_db::FileRange; 4use ra_db::FileRange;
5use ra_fmt::{leading_indent, reindent}; 5use ra_fmt::{leading_indent, reindent};
6use ra_syntax::{ 6use ra_syntax::{
@@ -142,12 +142,16 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
142 pub(crate) fn covering_element(&self) -> SyntaxElement { 142 pub(crate) fn covering_element(&self) -> SyntaxElement {
143 find_covering_element(self.source_file.syntax(), self.frange.range) 143 find_covering_element(self.source_file.syntax(), self.frange.range)
144 } 144 }
145 pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> {
146 SourceBinder::new(self.db)
147 }
145 pub(crate) fn source_analyzer( 148 pub(crate) fn source_analyzer(
146 &self, 149 &self,
147 node: &SyntaxNode, 150 node: &SyntaxNode,
148 offset: Option<TextUnit>, 151 offset: Option<TextUnit>,
149 ) -> SourceAnalyzer { 152 ) -> SourceAnalyzer {
150 SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset) 153 let src = InFile::new(self.frange.file_id.into(), node);
154 self.source_binder().analyze(src, offset)
151 } 155 }
152 156
153 pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { 157 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 @@
1use format_buf::format; 1use format_buf::format;
2use hir::{db::HirDatabase, FromSource, InFile}; 2use hir::{db::HirDatabase, InFile};
3use join_to_string::join; 3use join_to_string::join;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{ 5 ast::{
@@ -136,15 +136,16 @@ fn find_struct_impl(
136 let module = strukt.syntax().ancestors().find(|node| { 136 let module = strukt.syntax().ancestors().find(|node| {
137 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) 137 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
138 })?; 138 })?;
139 let mut sb = ctx.source_binder();
139 140
140 let struct_ty = { 141 let struct_ty = {
141 let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; 142 let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
142 hir::Struct::from_source(db, src)?.ty(db) 143 sb.to_def::<hir::Struct, _>(src)?.ty(db)
143 }; 144 };
144 145
145 let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| { 146 let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| {
146 let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; 147 let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
147 let blk = hir::ImplBlock::from_source(db, src)?; 148 let blk = sb.to_def::<hir::ImplBlock, _>(src)?;
148 149
149 let same_ty = blk.target_ty(db) == struct_ty; 150 let same_ty = blk.target_ty(db) == struct_ty;
150 let not_trait_impl = blk.target_trait(db).is_none(); 151 let not_trait_impl = blk.target_trait(db).is_none();