From 9fcebbc51284408203c05219a0ee92519f51ea74 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Aug 2018 16:27:09 +0300 Subject: subscriptions --- crates/libanalysis/src/imp.rs | 20 +++++++++----------- crates/libanalysis/src/lib.rs | 8 +++++--- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'crates/libanalysis/src') diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs index 004942e72..97802bd50 100644 --- a/crates/libanalysis/src/imp.rs +++ b/crates/libanalysis/src/imp.rs @@ -39,11 +39,11 @@ impl AnalysisHostImpl { pub fn analysis( &self, - file_resolver: impl FileResolver, + file_resolver: Arc, ) -> AnalysisImpl { AnalysisImpl { needs_reindex: AtomicBool::new(false), - file_resolver: Arc::new(file_resolver), + file_resolver, data: self.data.clone(), } } @@ -78,7 +78,7 @@ impl AnalysisHostImpl { pub(crate) struct AnalysisImpl { needs_reindex: AtomicBool, - file_resolver: Arc, + file_resolver: Arc, data: Arc, } @@ -236,15 +236,13 @@ impl AnalysisImpl { ("add `#[derive]`", libeditor::add_derive(&file, offset).map(|f| f())), ("add impl", libeditor::add_impl(&file, offset).map(|f| f())), ]; - let mut res = Vec::new(); - for (name, local_edit) in actions { - if let Some(local_edit) = local_edit { - res.push(SourceChange::from_local_edit( - file_id, name, local_edit + actions.into_iter() + .filter_map(|(name, local_edit)| { + Some(SourceChange::from_local_edit( + file_id, name, local_edit?, )) - } - } - res + }) + .collect() } fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> { diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 810228632..c25d31f4b 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs @@ -12,6 +12,8 @@ mod symbol_index; mod module_map; mod imp; +use std::sync::Arc; + use relative_path::{RelativePath, RelativePathBuf}; use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; use imp::{AnalysisImpl, AnalysisHostImpl}; @@ -31,7 +33,7 @@ pub trait FileResolver: Send + Sync + 'static { #[derive(Debug)] pub struct AnalysisHost { - pub(crate) imp: AnalysisHostImpl + imp: AnalysisHostImpl } impl AnalysisHost { @@ -39,7 +41,7 @@ impl AnalysisHost { AnalysisHost { imp: AnalysisHostImpl::new() } } pub fn analysis(&self, file_resolver: impl FileResolver) -> Analysis { - Analysis { imp: self.imp.analysis(file_resolver) } + Analysis { imp: self.imp.analysis(Arc::new(file_resolver)) } } pub fn change_file(&mut self, file_id: FileId, text: Option) { self.change_files(::std::iter::once((file_id, text))); @@ -121,7 +123,7 @@ impl Query { #[derive(Clone, Debug)] pub struct Analysis { - pub(crate) imp: AnalysisImpl + imp: AnalysisImpl } impl Analysis { -- cgit v1.2.3