aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-16 22:18:14 +0100
committerAleksey Kladov <[email protected]>2018-08-16 22:18:14 +0100
commit55e87e0b742b46d40b1a5ef1598804e48e45f0e0 (patch)
tree1431468696b493ac7e8d68d1a1dcb14d3bfa64f5 /crates/libanalysis/src
parent6a3f819f795d656f36a2967647a83438f8fb58c4 (diff)
mod resolve work
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r--crates/libanalysis/src/lib.rs24
1 files changed, 21 insertions, 3 deletions
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;
15use rayon::prelude::*; 15use rayon::prelude::*;
16 16
17use std::{ 17use std::{
18 fmt,
19 path::Path,
18 sync::{ 20 sync::{
19 Arc, 21 Arc,
20 atomic::{AtomicUsize, Ordering::SeqCst}, 22 atomic::{AtomicUsize, Ordering::SeqCst},
@@ -35,15 +37,24 @@ pub use self::symbol_index::Query;
35pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 37pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
36const INDEXING_THRESHOLD: usize = 128; 38const INDEXING_THRESHOLD: usize = 128;
37 39
40pub type FileResolver = dyn Fn(FileId, &Path) -> Option<FileId> + Send + Sync;
41
38pub struct WorldState { 42pub struct WorldState {
39 data: Arc<WorldData> 43 data: Arc<WorldData>
40} 44}
41 45
42#[derive(Clone, Debug)] 46#[derive(Clone)]
43pub struct World { 47pub struct World {
48 file_resolver: Arc<FileResolver>,
44 data: Arc<WorldData>, 49 data: Arc<WorldData>,
45} 50}
46 51
52impl fmt::Debug for World {
53 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54 (&*self.data).fmt(f)
55 }
56}
57
47#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 58#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
48pub struct FileId(pub u32); 59pub struct FileId(pub u32);
49 60
@@ -54,8 +65,11 @@ impl WorldState {
54 } 65 }
55 } 66 }
56 67
57 pub fn snapshot(&self) -> World { 68 pub fn snapshot(&self, file_resolver: impl Fn(FileId, &Path) -> Option<FileId> + 'static + Send + Sync) -> World {
58 World { data: self.data.clone() } 69 World {
70 file_resolver: Arc::new(file_resolver),
71 data: self.data.clone()
72 }
59 } 73 }
60 74
61 pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { 75 pub fn change_file(&mut self, file_id: FileId, text: Option<String>) {
@@ -134,6 +148,10 @@ impl World {
134 Ok(self.world_symbols(query).collect()) 148 Ok(self.world_symbols(query).collect())
135 } 149 }
136 150
151 fn resolve_relative_path(&self, id: FileId, path: &Path) -> Option<FileId> {
152 (self.file_resolver)(id, path)
153 }
154
137 fn reindex(&self) { 155 fn reindex(&self) {
138 let data = &*self.data; 156 let data = &*self.data;
139 let unindexed = data.unindexed.load(SeqCst); 157 let unindexed = data.unindexed.load(SeqCst);