Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 93bf1cb

Browse files
committed
Simplify visitor logic a bit
1 parent fba2499 commit 93bf1cb

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/lsps0/msgs.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
359359
while let Some(key) = map.next_key()? {
360360
match key {
361361
"id" => {
362-
id = Some(map.next_value()?);
362+
id = map.next_value()?;
363363
}
364364
"method" => {
365365
method = Some(map.next_value()?);
@@ -379,8 +379,16 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
379379
}
380380
}
381381

382-
match (id, method) {
383-
(Some(id), Some(method)) => match method {
382+
let id = id.ok_or_else(|| {
383+
if let Some(method) = method {
384+
de::Error::custom(format!("Received unknown notification: {}", method))
385+
} else {
386+
de::Error::custom("Received invalid JSON-RPC object: one of method or id required")
387+
}
388+
})?;
389+
390+
match method {
391+
Some(method) => match method {
384392
LSPS0_LISTPROTOCOLS_METHOD_NAME => {
385393
self.request_id_to_method.insert(id.clone(), method.to_string());
386394

@@ -437,7 +445,7 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
437445
method
438446
))),
439447
},
440-
(Some(id), None) => match self.request_id_to_method.get(&id) {
448+
None => match self.request_id_to_method.get(&id) {
441449
Some(method) => match method.as_str() {
442450
LSPS0_LISTPROTOCOLS_METHOD_NAME => {
443451
if let Some(error) = error {
@@ -536,12 +544,6 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
536544
id
537545
))),
538546
},
539-
(None, Some(method)) => {
540-
Err(de::Error::custom(format!("Received unknown notification: {}", method)))
541-
}
542-
(None, None) => Err(de::Error::custom(
543-
"Received invalid JSON-RPC object: one of method or id required",
544-
)),
545547
}
546548
}
547549
}

0 commit comments

Comments
 (0)