Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 776c917

Browse files
authored
Merge pull request #549 from Xanewok/exit-fix
Fix shutdown -> exit logic
2 parents 4dea9a7 + 5753962 commit 776c917

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/server/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'de> Deserialize<'de> for NoParams {
6060
}
6161

6262
pub trait Response {
63-
fn send<O: Output>(&self, id: usize, out: O);
63+
fn send<O: Output>(&self, id: usize, out: O);
6464
}
6565

6666
impl Response for NoResponse {
@@ -311,7 +311,7 @@ impl<O: Output> LsService<O> {
311311
};
312312

313313
let method = method.as_str().ok_or_else(|| jsonrpc::Error::invalid_request())?.to_owned();
314-
314+
315315
// Representing internally a missing parameter as Null instead of None,
316316
// (Null being unused value of param by the JSON-RPC 2.0 spec)
317317
// to unify the type handling – now the parameter type implements Deserialize.
@@ -402,17 +402,6 @@ impl<O: Output> LsService<O> {
402402

403403
trace!("Read message `{}`", msg_string);
404404

405-
{
406-
let shut_down = self.state.shut_down.load(Ordering::SeqCst);
407-
if shut_down {
408-
if msg_string != ExitNotification::METHOD {
409-
// We're shutdown, ignore any messages other than 'exit'. This is not actually
410-
// in the spec, I'm not sure we should do this, but it kinda makes sense.
411-
return ServerStateChange::Continue;
412-
}
413-
}
414-
}
415-
416405
let raw_message = match self.parse_message(&msg_string) {
417406
Ok(Some(rm)) => rm,
418407
Ok(None) => return ServerStateChange::Continue,
@@ -422,9 +411,20 @@ impl<O: Output> LsService<O> {
422411
return ServerStateChange::Break;
423412
}
424413
};
425-
414+
426415
trace!("Parsed message `{:?}`", raw_message);
427416

417+
// If we're in shutdown mode, ignore any messages other than 'exit'.
418+
// This is not actually in the spec, I'm not sure we should do this,
419+
// but it kinda makes sense.
420+
{
421+
let shut_down = self.state.shut_down.load(Ordering::SeqCst);
422+
if shut_down && raw_message.method != ExitNotification::METHOD {
423+
trace!("In shutdown mode, ignoring {:?}!", raw_message);
424+
return ServerStateChange::Continue;
425+
}
426+
}
427+
428428
if let Err(e) = self.dispatch_message(&raw_message) {
429429
debug!("dispatch error, {:?}", e);
430430
self.output.failure(raw_message.id.unwrap_or(Id::Null), e);

0 commit comments

Comments
 (0)