diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 24 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 28 | ||||
-rw-r--r-- | crates/server/src/path_map.rs | 5 |
3 files changed, 50 insertions, 7 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); |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 1fbcc7d1f..a8340df59 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -167,7 +167,10 @@ fn on_request( | |||
167 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { | 167 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { |
168 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); | 168 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); |
169 | 169 | ||
170 | let world = world.snapshot(); | 170 | let world = world.snapshot({ |
171 | let pm = path_map.clone(); | ||
172 | move |id, path| pm.resolve(id, path) | ||
173 | }); | ||
171 | let path_map = path_map.clone(); | 174 | let path_map = path_map.clone(); |
172 | let sender = sender.clone(); | 175 | let sender = sender.clone(); |
173 | pool.execute(move || { | 176 | pool.execute(move || { |
@@ -234,7 +237,14 @@ fn on_notification( | |||
234 | mem_map.insert(file_id, None); | 237 | mem_map.insert(file_id, None); |
235 | world.change_file(file_id, Some(params.text_document.text)); | 238 | world.change_file(file_id, Some(params.text_document.text)); |
236 | update_file_notifications_on_threadpool( | 239 | update_file_notifications_on_threadpool( |
237 | pool, world.snapshot(), path_map.clone(), sender.clone(), uri, | 240 | pool, |
241 | world.snapshot({ | ||
242 | let pm = path_map.clone(); | ||
243 | move |id, path| pm.resolve(id, path) | ||
244 | }), | ||
245 | path_map.clone(), | ||
246 | sender.clone(), | ||
247 | uri, | ||
238 | ); | 248 | ); |
239 | Ok(()) | 249 | Ok(()) |
240 | })?; | 250 | })?; |
@@ -245,7 +255,14 @@ fn on_notification( | |||
245 | .text; | 255 | .text; |
246 | world.change_file(file_id, Some(text)); | 256 | world.change_file(file_id, Some(text)); |
247 | update_file_notifications_on_threadpool( | 257 | update_file_notifications_on_threadpool( |
248 | pool, world.snapshot(), path_map.clone(), sender.clone(), params.text_document.uri, | 258 | pool, |
259 | world.snapshot({ | ||
260 | let pm = path_map.clone(); | ||
261 | move |id, path| pm.resolve(id, path) | ||
262 | }), | ||
263 | path_map.clone(), | ||
264 | sender.clone(), | ||
265 | params.text_document.uri, | ||
249 | ); | 266 | ); |
250 | Ok(()) | 267 | Ok(()) |
251 | })?; | 268 | })?; |
@@ -281,7 +298,10 @@ fn handle_request_on_threadpool<R: req::ClientRequest>( | |||
281 | ) -> Result<()> | 298 | ) -> Result<()> |
282 | { | 299 | { |
283 | dispatch::handle_request::<R, _>(req, |params, resp| { | 300 | dispatch::handle_request::<R, _>(req, |params, resp| { |
284 | let world = world.snapshot(); | 301 | let world = world.snapshot({ |
302 | let pm = path_map.clone(); | ||
303 | move |id, path| pm.resolve(id, path) | ||
304 | }); | ||
285 | let path_map = path_map.clone(); | 305 | let path_map = path_map.clone(); |
286 | let sender = sender.clone(); | 306 | let sender = sender.clone(); |
287 | pool.execute(move || { | 307 | pool.execute(move || { |
diff --git a/crates/server/src/path_map.rs b/crates/server/src/path_map.rs index 2454ba05f..e198e165d 100644 --- a/crates/server/src/path_map.rs +++ b/crates/server/src/path_map.rs | |||
@@ -34,6 +34,11 @@ impl PathMap { | |||
34 | .as_path() | 34 | .as_path() |
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn resolve(&self, id: FileId, relpath: &Path) -> Option<FileId> { | ||
38 | let path = self.get_path(id).join(relpath); | ||
39 | self.get_id(&path) | ||
40 | } | ||
41 | |||
37 | fn insert(&mut self, path: PathBuf, id: FileId) { | 42 | fn insert(&mut self, path: PathBuf, id: FileId) { |
38 | self.path2id.insert(path.clone(), id); | 43 | self.path2id.insert(path.clone(), id); |
39 | self.id2path.insert(id, path.clone()); | 44 | self.id2path.insert(id, path.clone()); |