mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
React on message-less LSP requests properly (#2620)
This commit is contained in:
commit
7ff194f21f
1 changed files with 20 additions and 7 deletions
|
@ -103,14 +103,14 @@ struct Notification<'a, T> {
|
||||||
params: T,
|
params: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
struct AnyNotification<'a> {
|
struct AnyNotification<'a> {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
id: Option<usize>,
|
id: Option<usize>,
|
||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
method: &'a str,
|
method: &'a str,
|
||||||
#[serde(borrow)]
|
#[serde(borrow, default)]
|
||||||
params: &'a RawValue,
|
params: Option<&'a RawValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
@ -157,9 +157,12 @@ impl LanguageServer {
|
||||||
"unhandled notification {}:\n{}",
|
"unhandled notification {}:\n{}",
|
||||||
notification.method,
|
notification.method,
|
||||||
serde_json::to_string_pretty(
|
serde_json::to_string_pretty(
|
||||||
&Value::from_str(notification.params.get()).unwrap()
|
¬ification
|
||||||
|
.params
|
||||||
|
.and_then(|params| Value::from_str(params.get()).ok())
|
||||||
|
.unwrap_or(Value::Null)
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -279,7 +282,11 @@ impl LanguageServer {
|
||||||
|
|
||||||
if let Ok(msg) = serde_json::from_slice::<AnyNotification>(&buffer) {
|
if let Ok(msg) = serde_json::from_slice::<AnyNotification>(&buffer) {
|
||||||
if let Some(handler) = notification_handlers.lock().get_mut(msg.method) {
|
if let Some(handler) = notification_handlers.lock().get_mut(msg.method) {
|
||||||
handler(msg.id, msg.params.get(), cx.clone());
|
handler(
|
||||||
|
msg.id,
|
||||||
|
&msg.params.map(|params| params.get()).unwrap_or("null"),
|
||||||
|
cx.clone(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
on_unhandled_notification(msg);
|
on_unhandled_notification(msg);
|
||||||
}
|
}
|
||||||
|
@ -828,7 +835,13 @@ impl LanguageServer {
|
||||||
cx,
|
cx,
|
||||||
move |msg| {
|
move |msg| {
|
||||||
notifications_tx
|
notifications_tx
|
||||||
.try_send((msg.method.to_string(), msg.params.get().to_string()))
|
.try_send((
|
||||||
|
msg.method.to_string(),
|
||||||
|
msg.params
|
||||||
|
.map(|raw_value| raw_value.get())
|
||||||
|
.unwrap_or("null")
|
||||||
|
.to_string(),
|
||||||
|
))
|
||||||
.ok();
|
.ok();
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Reference in a new issue