Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/lsp-server/src/msg.rs')
| -rw-r--r-- | lib/lsp-server/src/msg.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/lsp-server/src/msg.rs b/lib/lsp-server/src/msg.rs index 305008e69a..eb8b6bbf04 100644 --- a/lib/lsp-server/src/msg.rs +++ b/lib/lsp-server/src/msg.rs @@ -16,6 +16,27 @@ pub enum Message { Notification(Notification), } +impl Message { + pub fn request(self) -> Option<Request> { + match self { + Self::Request(x) => Some(x), + _ => None, + } + } + pub fn response(self) -> Option<Response> { + match self { + Self::Response(x) => Some(x), + _ => None, + } + } + pub fn notification(self) -> Option<Notification> { + match self { + Self::Notification(x) => Some(x), + _ => None, + } + } +} + impl From<Request> for Message { fn from(request: Request) -> Message { Message::Request(request) @@ -36,11 +57,20 @@ impl From<Notification> for Message { #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(transparent)] -pub struct RequestId(IdRepr); +pub struct RequestId(pub IdRepr); + +impl RequestId { + pub fn i32(&self) -> i32 { + match self.0 { + IdRepr::I32(x) => x, + _ => panic!(), + } + } +} #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(untagged)] -enum IdRepr { +pub enum IdRepr { I32(i32), String(String), } @@ -247,10 +277,10 @@ impl Notification { Err(error) => Err(ExtractError::JsonError { method: self.method, error }), } } - pub(crate) fn is_exit(&self) -> bool { + pub fn is_exit(&self) -> bool { self.method == "exit" } - pub(crate) fn is_initialized(&self) -> bool { + pub fn is_initialized(&self) -> bool { self.method == "initialized" } } |