1//! Types representing the current state of the language server.
23use std::fmt::{self, Debug, Formatter};
4use std::sync::atomic::{AtomicU8, Ordering};
56/// A list of possible states the language server can be in.
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8#[repr(u8)]
9pub enum State {
10/// Server has not received an `initialize` request.
11Uninitialized = 0,
12/// Server received an `initialize` request, but has not yet responded.
13Initializing = 1,
14/// Server received and responded success to an `initialize` request.
15Initialized = 2,
16/// Server received a `shutdown` request.
17ShutDown = 3,
18/// Server received an `exit` notification.
19Exited = 4,
20}
2122/// Atomic value which represents the current state of the server.
23pub struct ServerState(AtomicU8);
2425impl ServerState {
26pub const fn new() -> Self {
27 ServerState(AtomicU8::new(State::Uninitialized as u8))
28 }
2930pub fn set(&self, state: State) {
31self.0.store(state as u8, Ordering::SeqCst);
32 }
3334pub fn get(&self) -> State {
35match self.0.load(Ordering::SeqCst) {
360 => State::Uninitialized,
371 => State::Initializing,
382 => State::Initialized,
393 => State::ShutDown,
404 => State::Exited,
41_ => unreachable!(),
42 }
43 }
44}
4546impl Debug for ServerState {
47fn fmt(&self, f: &mut Formatter) -> fmt::Result {
48self.get().fmt(f)
49 }
50}