diff options
author | Aleksey Kladov <[email protected]> | 2019-02-14 17:43:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-14 18:11:07 +0000 |
commit | bf352cd2511775a331d77dee261b64bd8359dacb (patch) | |
tree | ba7d988ebef437d5a9d7beac048b5ac0dbd2fe9c /crates/ra_lsp_server/src | |
parent | 10bf61b83b2600ed3cb7e7825f1cd0ee83e9b7e7 (diff) |
automatically wait for worker threads
closes #817
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 26 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/project_model.rs | 6 |
2 files changed, 15 insertions, 17 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index a51299851..06443bb76 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -54,19 +54,20 @@ pub fn main_loop( | |||
54 | ) -> Result<()> { | 54 | ) -> Result<()> { |
55 | let pool = ThreadPool::new(THREADPOOL_SIZE); | 55 | let pool = ThreadPool::new(THREADPOOL_SIZE); |
56 | let (task_sender, task_receiver) = unbounded::<Task>(); | 56 | let (task_sender, task_receiver) = unbounded::<Task>(); |
57 | let (ws_worker, ws_watcher) = workspace_loader(); | ||
58 | 57 | ||
59 | ws_worker.send(ws_root.clone()).unwrap(); | ||
60 | // FIXME: support dynamic workspace loading. | 58 | // FIXME: support dynamic workspace loading. |
61 | let workspaces = match ws_worker.recv().unwrap() { | 59 | let workspaces = { |
62 | Ok(ws) => vec![ws], | 60 | let ws_worker = workspace_loader(); |
63 | Err(e) => { | 61 | ws_worker.sender().send(ws_root.clone()).unwrap(); |
64 | log::error!("loading workspace failed: {}", e); | 62 | match ws_worker.receiver().recv().unwrap() { |
65 | Vec::new() | 63 | Ok(ws) => vec![ws], |
64 | Err(e) => { | ||
65 | log::error!("loading workspace failed: {}", e); | ||
66 | Vec::new() | ||
67 | } | ||
66 | } | 68 | } |
67 | }; | 69 | }; |
68 | ws_worker.shutdown(); | 70 | |
69 | ws_watcher.shutdown().map_err(|_| format_err!("ws watcher died"))?; | ||
70 | let mut state = ServerWorldState::new(ws_root.clone(), workspaces); | 71 | let mut state = ServerWorldState::new(ws_root.clone(), workspaces); |
71 | 72 | ||
72 | log::info!("server initialized, serving requests"); | 73 | log::info!("server initialized, serving requests"); |
@@ -94,12 +95,9 @@ pub fn main_loop( | |||
94 | log::info!("...threadpool has finished"); | 95 | log::info!("...threadpool has finished"); |
95 | 96 | ||
96 | let vfs = Arc::try_unwrap(state.vfs).expect("all snapshots should be dead"); | 97 | let vfs = Arc::try_unwrap(state.vfs).expect("all snapshots should be dead"); |
97 | let vfs_res = vfs.into_inner().shutdown(); | 98 | drop(vfs); |
98 | 99 | ||
99 | main_res?; | 100 | main_res |
100 | vfs_res.map_err(|_| format_err!("fs watcher died"))?; | ||
101 | |||
102 | Ok(()) | ||
103 | } | 101 | } |
104 | 102 | ||
105 | enum Event { | 103 | enum Event { |
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 6800eb138..7d6440fad 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::path::PathBuf; | 1 | use std::path::PathBuf; |
2 | 2 | ||
3 | use thread_worker::{WorkerHandle, Worker}; | 3 | use thread_worker::Worker; |
4 | 4 | ||
5 | use crate::Result; | 5 | use crate::Result; |
6 | 6 | ||
@@ -8,8 +8,8 @@ pub use ra_project_model::{ | |||
8 | ProjectWorkspace, CargoWorkspace, Package, Target, TargetKind, Sysroot, | 8 | ProjectWorkspace, CargoWorkspace, Package, Target, TargetKind, Sysroot, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | pub fn workspace_loader() -> (Worker<PathBuf, Result<ProjectWorkspace>>, WorkerHandle) { | 11 | pub fn workspace_loader() -> Worker<PathBuf, Result<ProjectWorkspace>> { |
12 | thread_worker::spawn::<PathBuf, Result<ProjectWorkspace>, _>( | 12 | Worker::<PathBuf, Result<ProjectWorkspace>>::spawn( |
13 | "workspace loader", | 13 | "workspace loader", |
14 | 1, | 14 | 1, |
15 | |input_receiver, output_sender| { | 15 | |input_receiver, output_sender| { |