diff options
author | Aleksey Kladov <[email protected]> | 2018-08-16 22:18:14 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-16 22:18:14 +0100 |
commit | 55e87e0b742b46d40b1a5ef1598804e48e45f0e0 (patch) | |
tree | 1431468696b493ac7e8d68d1a1dcb14d3bfa64f5 /crates/libanalysis/src | |
parent | 6a3f819f795d656f36a2967647a83438f8fb58c4 (diff) |
mod resolve work
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 24 |
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; | |||
15 | use rayon::prelude::*; | 15 | use rayon::prelude::*; |
16 | 16 | ||
17 | use std::{ | 17 | use 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; | |||
35 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; | 37 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; |
36 | const INDEXING_THRESHOLD: usize = 128; | 38 | const INDEXING_THRESHOLD: usize = 128; |
37 | 39 | ||
40 | pub type FileResolver = dyn Fn(FileId, &Path) -> Option<FileId> + Send + Sync; | ||
41 | |||
38 | pub struct WorldState { | 42 | pub struct WorldState { |
39 | data: Arc<WorldData> | 43 | data: Arc<WorldData> |
40 | } | 44 | } |
41 | 45 | ||
42 | #[derive(Clone, Debug)] | 46 | #[derive(Clone)] |
43 | pub struct World { | 47 | pub struct World { |
48 | file_resolver: Arc<FileResolver>, | ||
44 | data: Arc<WorldData>, | 49 | data: Arc<WorldData>, |
45 | } | 50 | } |
46 | 51 | ||
52 | impl 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)] |
48 | pub struct FileId(pub u32); | 59 | pub 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); |