From 892671926bcb5fd9cd5df6fd2b8c7efb5f25582d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Nov 2019 01:00:00 +0300 Subject: Remove wrong clone --- crates/ra_hir_def/src/nameres.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 49e33ccc4..e5b073a0f 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 -- cgit v1.2.3 From f36ac059f362050dae36569940b94a331387294a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Nov 2019 01:14:56 +0300 Subject: Reduce some duplication --- crates/ra_assists/src/assist_ctx.rs | 10 ++++++++-- crates/ra_assists/src/assists/add_explicit_type.rs | 2 +- crates/ra_assists/src/assists/add_missing_impl_members.rs | 3 +-- crates/ra_assists/src/assists/fill_match_arms.rs | 3 +-- crates/ra_assists/src/assists/inline_local_variable.rs | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 1908bdec9..71f7ce1b1 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 ddda1a0f2..562a09685 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()]; -- cgit v1.2.3