diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 1908bdec90..71f7ce1b19 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,6 +1,5 @@ //! This module defines `AssistCtx` -- the API surface that is exposed to assists. - -use hir::db::HirDatabase; +use hir::{db::HirDatabase, SourceAnalyzer}; use ra_db::FileRange; use ra_fmt::{leading_indent, reindent}; use ra_syntax::{ @@ -113,6 +112,13 @@ 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_analyzer( + &self, + node: &SyntaxNode, + offset: Option, + ) -> SourceAnalyzer { + SourceAnalyzer::new(self.db, self.frange.file_id, node, offset) + } pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { find_covering_element(self.source_file.syntax(), range) diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index ddda1a0f2c..562a096853 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs @@ -40,7 +40,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option) -> Option) -> Option< } else { let_stmt.syntax().text_range() }; - let analyzer = hir::SourceAnalyzer::new(ctx.db, ctx.frange.file_id, bind_pat.syntax(), None); + let analyzer = ctx.source_analyzer(bind_pat.syntax(), None); let refs = analyzer.find_all_refs(&bind_pat); let mut wrap_in_parens = vec![true; refs.len()]; diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 49e33ccc4e..e5b073a0f8 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -125,12 +125,12 @@ pub struct ModuleData { pub impls: Vec, } -#[derive(Default, Debug, PartialEq, Eq, Clone)] +#[derive(Default, Debug, PartialEq, Eq)] pub(crate) struct Declarations { fns: FxHashMap, FunctionId>, } -#[derive(Debug, Default, PartialEq, Eq, Clone)] +#[derive(Debug, Default, PartialEq, Eq)] pub struct ModuleScope { items: FxHashMap, /// Macros visable in current module in legacy textual scope