lsp: explicitly drop locks in handle_input (#12276)

Due to lifetime extension rules, we were holding onto the request
handler map mutex during parsing of the request itself. This had no
grand repercussions; it only prevented registering a handler for next
request until parsing of the previous one was done.



Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-05-25 12:25:17 +02:00 committed by GitHub
parent 32f11dfa00
commit e5085dfef6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -452,24 +452,27 @@ 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) { let mut notification_handlers = notification_handlers.lock();
if let Some(handler) = notification_handlers.get_mut(msg.method) {
handler( handler(
msg.id, msg.id,
msg.params.map(|params| params.get()).unwrap_or("null"), msg.params.map(|params| params.get()).unwrap_or("null"),
cx.clone(), cx.clone(),
); );
} else { } else {
drop(notification_handlers);
on_unhandled_notification(msg); on_unhandled_notification(msg);
} }
} else if let Ok(AnyResponse { } else if let Ok(AnyResponse {
id, error, result, .. id, error, result, ..
}) = serde_json::from_slice(&buffer) }) = serde_json::from_slice(&buffer)
{ {
let mut response_handlers = response_handlers.lock();
if let Some(handler) = response_handlers if let Some(handler) = response_handlers
.lock()
.as_mut() .as_mut()
.and_then(|handlers| handlers.remove(&id)) .and_then(|handlers| handlers.remove(&id))
{ {
drop(response_handlers);
if let Some(error) = error { if let Some(error) = error {
handler(Err(error)); handler(Err(error));
} else if let Some(result) = result { } else if let Some(result) = result {