From 55e87e0b742b46d40b1a5ef1598804e48e45f0e0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 00:18:14 +0300 Subject: mod resolve work --- crates/libanalysis/src/lib.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'crates/libanalysis/src') diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 85c23e4d9..9429f8f55 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs @@ -15,6 +15,8 @@ use once_cell::sync::OnceCell; use rayon::prelude::*; use std::{ + fmt, + path::Path, sync::{ Arc, atomic::{AtomicUsize, Ordering::SeqCst}, @@ -35,15 +37,24 @@ pub use self::symbol_index::Query; pub type Result = ::std::result::Result; const INDEXING_THRESHOLD: usize = 128; +pub type FileResolver = dyn Fn(FileId, &Path) -> Option + Send + Sync; + pub struct WorldState { data: Arc } -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct World { + file_resolver: Arc, data: Arc, } +impl fmt::Debug for World { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + (&*self.data).fmt(f) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FileId(pub u32); @@ -54,8 +65,11 @@ impl WorldState { } } - pub fn snapshot(&self) -> World { - World { data: self.data.clone() } + pub fn snapshot(&self, file_resolver: impl Fn(FileId, &Path) -> Option + 'static + Send + Sync) -> World { + World { + file_resolver: Arc::new(file_resolver), + data: self.data.clone() + } } pub fn change_file(&mut self, file_id: FileId, text: Option) { @@ -134,6 +148,10 @@ impl World { Ok(self.world_symbols(query).collect()) } + fn resolve_relative_path(&self, id: FileId, path: &Path) -> Option { + (self.file_resolver)(id, path) + } + fn reindex(&self) { let data = &*self.data; let unindexed = data.unindexed.load(SeqCst); -- cgit v1.2.3