1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 09:10:40 -05:00

chore(lsp): fix possible race condition with tests expecting 3 publishDiagnostics messages (#12868)

The tests expect 3 publish notifications. It was possible for less than 3 to occur if two or more tasks set the diagnostics in the collection, exited the lock at the same time, then called `publish_diagnostics`
This commit is contained in:
David Sherret 2021-11-23 20:04:27 -05:00 committed by GitHub
parent fd6d0e309c
commit 0f90b4665a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -568,10 +568,9 @@ async fn generate_deps_diagnostics(
/// Publishes diagnostics to the client.
async fn publish_diagnostics(
client: &lspower::Client,
collection: Arc<Mutex<DiagnosticCollection>>,
collection: &mut DiagnosticCollection,
snapshot: &language_server::StateSnapshot,
) {
let mut collection = collection.lock().await;
if let Some(changes) = collection.take_changes() {
for specifier in changes {
let mut diagnostics: Vec<lsp::Diagnostic> =
@ -625,13 +624,12 @@ async fn update_diagnostics(
error!("Error generating lint diagnostics: {}", err);
})
.unwrap_or_default();
{
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::DenoLint, diagnostic_record);
}
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::DenoLint, diagnostic_record);
}
publish_diagnostics(client, collection, &snapshot).await;
publish_diagnostics(client, &mut collection, &snapshot).await;
snapshot.performance.measure(mark);
};
@ -647,13 +645,11 @@ async fn update_diagnostics(
error!("Error generating TypeScript diagnostics: {}", err);
})
.unwrap_or_default();
{
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::TypeScript, diagnostic_record);
}
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::TypeScript, diagnostic_record);
}
publish_diagnostics(client, collection, &snapshot).await;
publish_diagnostics(client, &mut collection, &snapshot).await;
snapshot.performance.measure(mark);
};
@ -669,13 +665,11 @@ async fn update_diagnostics(
error!("Error generating Deno diagnostics: {}", err);
})
.unwrap_or_default();
{
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::Deno, diagnostic_record);
}
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::Deno, diagnostic_record);
}
publish_diagnostics(client, collection, &snapshot).await;
publish_diagnostics(client, &mut collection, &snapshot).await;
snapshot.performance.measure(mark);
};