mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-09 10:56:20 +00:00
Merge pull request #2147 from zed-industries/fix-pyright
Always respond to language server, even when its requests are malformed
This commit is contained in:
commit
373e88e9fb
1 changed files with 54 additions and 30 deletions
|
@ -65,6 +65,7 @@ struct Request<'a, T> {
|
|||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct AnyResponse<'a> {
|
||||
jsonrpc: &'a str,
|
||||
id: usize,
|
||||
#[serde(default)]
|
||||
error: Option<Error>,
|
||||
|
@ -204,8 +205,9 @@ impl LanguageServer {
|
|||
} else {
|
||||
on_unhandled_notification(msg);
|
||||
}
|
||||
} else if let Ok(AnyResponse { id, error, result }) =
|
||||
serde_json::from_slice(&buffer)
|
||||
} else if let Ok(AnyResponse {
|
||||
id, error, result, ..
|
||||
}) = serde_json::from_slice(&buffer)
|
||||
{
|
||||
if let Some(handler) = response_handlers
|
||||
.lock()
|
||||
|
@ -461,35 +463,57 @@ impl LanguageServer {
|
|||
method,
|
||||
Box::new(move |id, params, cx| {
|
||||
if let Some(id) = id {
|
||||
if let Some(params) = serde_json::from_str(params).log_err() {
|
||||
let response = f(params, cx.clone());
|
||||
cx.foreground()
|
||||
.spawn({
|
||||
let outbound_tx = outbound_tx.clone();
|
||||
async move {
|
||||
let response = match response.await {
|
||||
Ok(result) => Response {
|
||||
jsonrpc: JSON_RPC_VERSION,
|
||||
id,
|
||||
result: Some(result),
|
||||
error: None,
|
||||
},
|
||||
Err(error) => Response {
|
||||
jsonrpc: JSON_RPC_VERSION,
|
||||
id,
|
||||
result: None,
|
||||
error: Some(Error {
|
||||
message: error.to_string(),
|
||||
}),
|
||||
},
|
||||
};
|
||||
if let Some(response) = serde_json::to_vec(&response).log_err()
|
||||
{
|
||||
outbound_tx.try_send(response).ok();
|
||||
match serde_json::from_str(params) {
|
||||
Ok(params) => {
|
||||
let response = f(params, cx.clone());
|
||||
cx.foreground()
|
||||
.spawn({
|
||||
let outbound_tx = outbound_tx.clone();
|
||||
async move {
|
||||
let response = match response.await {
|
||||
Ok(result) => Response {
|
||||
jsonrpc: JSON_RPC_VERSION,
|
||||
id,
|
||||
result: Some(result),
|
||||
error: None,
|
||||
},
|
||||
Err(error) => Response {
|
||||
jsonrpc: JSON_RPC_VERSION,
|
||||
id,
|
||||
result: None,
|
||||
error: Some(Error {
|
||||
message: error.to_string(),
|
||||
}),
|
||||
},
|
||||
};
|
||||
if let Some(response) =
|
||||
serde_json::to_vec(&response).log_err()
|
||||
{
|
||||
outbound_tx.try_send(response).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
Err(error) => {
|
||||
log::error!(
|
||||
"error deserializing {} request: {:?}, message: {:?}",
|
||||
method,
|
||||
error,
|
||||
params
|
||||
);
|
||||
let response = AnyResponse {
|
||||
jsonrpc: JSON_RPC_VERSION,
|
||||
id,
|
||||
result: None,
|
||||
error: Some(Error {
|
||||
message: error.to_string(),
|
||||
}),
|
||||
};
|
||||
if let Some(response) = serde_json::to_vec(&response).log_err() {
|
||||
outbound_tx.try_send(response).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue