aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r--crates/server/src/main_loop/mod.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 610aa4264..ff267fcad 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -11,7 +11,10 @@ use serde::{Serialize, de::DeserializeOwned};
11use crossbeam_channel::{bounded, Sender, Receiver}; 11use crossbeam_channel::{bounded, Sender, Receiver};
12use languageserver_types::{NumberOrString}; 12use languageserver_types::{NumberOrString};
13use libanalysis::{FileId, JobHandle, JobToken}; 13use libanalysis::{FileId, JobHandle, JobToken};
14use gen_lsp_server::{RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode}; 14use gen_lsp_server::{
15 RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode,
16 handle_shutdown,
17};
15 18
16use { 19use {
17 req, 20 req,
@@ -21,6 +24,7 @@ use {
21 main_loop::subscriptions::{Subscriptions}, 24 main_loop::subscriptions::{Subscriptions},
22}; 25};
23 26
27#[derive(Debug)]
24enum Task { 28enum Task {
25 Respond(RawResponse), 29 Respond(RawResponse),
26 Notify(RawNotification), 30 Notify(RawNotification),
@@ -40,7 +44,7 @@ pub fn main_loop(
40 44
41 let mut pending_requests = HashMap::new(); 45 let mut pending_requests = HashMap::new();
42 let mut subs = Subscriptions::new(); 46 let mut subs = Subscriptions::new();
43 main_loop_inner( 47 let res = main_loop_inner(
44 &pool, 48 &pool,
45 msg_receriver, 49 msg_receriver,
46 msg_sender, 50 msg_sender,
@@ -50,17 +54,19 @@ pub fn main_loop(
50 &mut state, 54 &mut state,
51 &mut pending_requests, 55 &mut pending_requests,
52 &mut subs, 56 &mut subs,
53 )?; 57 );
54 58
55 info!("waiting for background jobs to finish..."); 59 info!("waiting for tasks to finish...");
56 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); 60 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
61 info!("...tasks have finished");
62 info!("joining threadpool...");
57 pool.join(); 63 pool.join();
58 info!("...background jobs have finished"); 64 info!("...threadpool has finished");
59 65
60 info!("waiting for file watcher to finish..."); 66 info!("waiting for file watcher to finish...");
61 watcher.stop()?; 67 watcher.stop()?;
62 info!("...file watcher has finished"); 68 info!("...file watcher has finished");
63 Ok(()) 69 res
64} 70}
65 71
66fn main_loop_inner( 72fn main_loop_inner(
@@ -73,15 +79,17 @@ fn main_loop_inner(
73 state: &mut ServerWorldState, 79 state: &mut ServerWorldState,
74 pending_requests: &mut HashMap<u64, JobHandle>, 80 pending_requests: &mut HashMap<u64, JobHandle>,
75 subs: &mut Subscriptions, 81 subs: &mut Subscriptions,
76) -> Result<u64> { 82) -> Result<()> {
77 let mut fs_receiver = Some(fs_receiver); 83 let mut fs_receiver = Some(fs_receiver);
78 loop { 84 loop {
85 #[derive(Debug)]
79 enum Event { 86 enum Event {
80 Msg(RawMessage), 87 Msg(RawMessage),
81 Task(Task), 88 Task(Task),
82 Fs(Vec<FileEvent>), 89 Fs(Vec<FileEvent>),
83 FsWatcherDead, 90 FsWatcherDead,
84 } 91 }
92 trace!("selecting");
85 let event = select! { 93 let event = select! {
86 recv(msg_receiver, msg) => match msg { 94 recv(msg_receiver, msg) => match msg {
87 Some(msg) => Event::Msg(msg), 95 Some(msg) => Event::Msg(msg),
@@ -93,6 +101,7 @@ fn main_loop_inner(
93 None => Event::FsWatcherDead, 101 None => Event::FsWatcherDead,
94 } 102 }
95 }; 103 };
104 trace!("selected {:?}", event);
96 let mut state_changed = false; 105 let mut state_changed = false;
97 match event { 106 match event {
98 Event::FsWatcherDead => fs_receiver = None, 107 Event::FsWatcherDead => fs_receiver = None,
@@ -105,9 +114,9 @@ fn main_loop_inner(
105 Event::Msg(msg) => { 114 Event::Msg(msg) => {
106 match msg { 115 match msg {
107 RawMessage::Request(req) => { 116 RawMessage::Request(req) => {
108 let req = match req.cast::<req::Shutdown>() { 117 let req = match handle_shutdown(req, msg_sender) {
109 Ok((id, _params)) => return Ok(id), 118 Some(req) => req,
110 Err(req) => req, 119 None => return Ok(()),
111 }; 120 };
112 match on_request(state, pending_requests, pool, &task_sender, req)? { 121 match on_request(state, pending_requests, pool, &task_sender, req)? {
113 None => (), 122 None => (),
@@ -290,7 +299,7 @@ impl<'a> PoolDispatcher<'a> {
290 let sender = self.sender.clone(); 299 let sender = self.sender.clone();
291 self.pool.execute(move || { 300 self.pool.execute(move || {
292 let resp = match f(world, params, token) { 301 let resp = match f(world, params, token) {
293 Ok(resp) => RawResponse::ok(id, resp), 302 Ok(resp) => RawResponse::ok::<R>(id, resp),
294 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), 303 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()),
295 }; 304 };
296 let task = Task::Respond(resp); 305 let task = Task::Respond(resp);