diff options
author | Aleksey Kladov <[email protected]> | 2018-09-02 12:46:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-02 12:46:15 +0100 |
commit | 80be61ed78e8410e013cb94879435d54a4907c30 (patch) | |
tree | 3ab33c902644a3aa14b490be8a7caa9120da7537 /crates/server/src/main_loop/mod.rs | |
parent | 7fad13de73ded5b8a332c5f50c18671d612bd1e3 (diff) |
project model
Diffstat (limited to 'crates/server/src/main_loop/mod.rs')
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index ff267fcad..52fc00c9c 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -22,6 +22,7 @@ use { | |||
22 | vfs::{self, FileEvent}, | 22 | vfs::{self, FileEvent}, |
23 | server_world::{ServerWorldState, ServerWorld}, | 23 | server_world::{ServerWorldState, ServerWorld}, |
24 | main_loop::subscriptions::{Subscriptions}, | 24 | main_loop::subscriptions::{Subscriptions}, |
25 | project_model::{CargoWorkspace, workspace_loader}, | ||
25 | }; | 26 | }; |
26 | 27 | ||
27 | #[derive(Debug)] | 28 | #[derive(Debug)] |
@@ -37,20 +38,24 @@ pub fn main_loop( | |||
37 | ) -> Result<()> { | 38 | ) -> Result<()> { |
38 | let pool = ThreadPool::new(4); | 39 | let pool = ThreadPool::new(4); |
39 | let (task_sender, task_receiver) = bounded::<Task>(16); | 40 | let (task_sender, task_receiver) = bounded::<Task>(16); |
40 | let (fs_events_receiver, watcher) = vfs::watch(vec![root]); | 41 | let (fs_events_receiver, watcher) = vfs::watch(vec![root.clone()]); |
42 | let (ws_root_sender, ws_receiver, ws_watcher) = workspace_loader(); | ||
43 | ws_root_sender.send(root); | ||
41 | 44 | ||
42 | info!("server initialized, serving requests"); | 45 | info!("server initialized, serving requests"); |
43 | let mut state = ServerWorldState::new(); | 46 | let mut state = ServerWorldState::new(); |
44 | 47 | ||
45 | let mut pending_requests = HashMap::new(); | 48 | let mut pending_requests = HashMap::new(); |
46 | let mut subs = Subscriptions::new(); | 49 | let mut subs = Subscriptions::new(); |
47 | let res = main_loop_inner( | 50 | let main_res = main_loop_inner( |
48 | &pool, | 51 | &pool, |
49 | msg_receriver, | 52 | msg_receriver, |
50 | msg_sender, | 53 | msg_sender, |
51 | task_receiver.clone(), | 54 | task_receiver.clone(), |
52 | task_sender, | 55 | task_sender, |
53 | fs_events_receiver, | 56 | fs_events_receiver, |
57 | ws_root_sender, | ||
58 | ws_receiver, | ||
54 | &mut state, | 59 | &mut state, |
55 | &mut pending_requests, | 60 | &mut pending_requests, |
56 | &mut subs, | 61 | &mut subs, |
@@ -63,10 +68,14 @@ pub fn main_loop( | |||
63 | pool.join(); | 68 | pool.join(); |
64 | info!("...threadpool has finished"); | 69 | info!("...threadpool has finished"); |
65 | 70 | ||
66 | info!("waiting for file watcher to finish..."); | 71 | let vfs_res = watcher.stop(); |
67 | watcher.stop()?; | 72 | let ws_res = ws_watcher.stop(); |
68 | info!("...file watcher has finished"); | 73 | |
69 | res | 74 | main_res?; |
75 | vfs_res?; | ||
76 | ws_res?; | ||
77 | |||
78 | Ok(()) | ||
70 | } | 79 | } |
71 | 80 | ||
72 | fn main_loop_inner( | 81 | fn main_loop_inner( |
@@ -76,6 +85,8 @@ fn main_loop_inner( | |||
76 | task_receiver: Receiver<Task>, | 85 | task_receiver: Receiver<Task>, |
77 | task_sender: Sender<Task>, | 86 | task_sender: Sender<Task>, |
78 | fs_receiver: Receiver<Vec<FileEvent>>, | 87 | fs_receiver: Receiver<Vec<FileEvent>>, |
88 | _ws_roots_sender: Sender<PathBuf>, | ||
89 | ws_receiver: Receiver<Result<CargoWorkspace>>, | ||
79 | state: &mut ServerWorldState, | 90 | state: &mut ServerWorldState, |
80 | pending_requests: &mut HashMap<u64, JobHandle>, | 91 | pending_requests: &mut HashMap<u64, JobHandle>, |
81 | subs: &mut Subscriptions, | 92 | subs: &mut Subscriptions, |
@@ -87,6 +98,7 @@ fn main_loop_inner( | |||
87 | Msg(RawMessage), | 98 | Msg(RawMessage), |
88 | Task(Task), | 99 | Task(Task), |
89 | Fs(Vec<FileEvent>), | 100 | Fs(Vec<FileEvent>), |
101 | Ws(Result<CargoWorkspace>), | ||
90 | FsWatcherDead, | 102 | FsWatcherDead, |
91 | } | 103 | } |
92 | trace!("selecting"); | 104 | trace!("selecting"); |
@@ -100,6 +112,10 @@ fn main_loop_inner( | |||
100 | Some(events) => Event::Fs(events), | 112 | Some(events) => Event::Fs(events), |
101 | None => Event::FsWatcherDead, | 113 | None => Event::FsWatcherDead, |
102 | } | 114 | } |
115 | recv(ws_receiver, ws) => match ws { | ||
116 | None => bail!("workspace watcher died"), | ||
117 | Some(ws) => Event::Ws(ws), | ||
118 | } | ||
103 | }; | 119 | }; |
104 | trace!("selected {:?}", event); | 120 | trace!("selected {:?}", event); |
105 | let mut state_changed = false; | 121 | let mut state_changed = false; |
@@ -111,6 +127,17 @@ fn main_loop_inner( | |||
111 | state.apply_fs_changes(events); | 127 | state.apply_fs_changes(events); |
112 | state_changed = true; | 128 | state_changed = true; |
113 | } | 129 | } |
130 | Event::Ws(ws) => { | ||
131 | match ws { | ||
132 | Ok(ws) => { | ||
133 | let not = RawNotification::new::<req::DidReloadWorkspace>(vec![ws.clone()]); | ||
134 | msg_sender.send(RawMessage::Notification(not)); | ||
135 | state.set_workspaces(vec![ws]); | ||
136 | state_changed = true; | ||
137 | } | ||
138 | Err(e) => warn!("loading workspace failed: {}", e), | ||
139 | } | ||
140 | } | ||
114 | Event::Msg(msg) => { | 141 | Event::Msg(msg) => { |
115 | match msg { | 142 | match msg { |
116 | RawMessage::Request(req) => { | 143 | RawMessage::Request(req) => { |