-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(lsp): fix possible race condition with tests expecting 3 publishDiagnostics messages, but getting 2 or 1 #12868
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,10 +589,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> = | ||
|
@@ -646,13 +645,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kitsonk would it be better to pass the diagnostics directly to this function? It seems like they get set in the collection and then they're taken from there. Maybe they shouldn't be put in the collection if lint isn't enabled or the specifier isn't enabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The considerations is that if you toggle a project as enabled or disabled (or for linting) the only way to clear diagnostics is to publish an empty set for each file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm not going to bother with this for now. I'll just fix this one issue in this PR. |
||
snapshot.performance.measure(mark); | ||
}; | ||
|
||
|
@@ -668,13 +666,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); | ||
}; | ||
|
||
|
@@ -690,13 +686,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); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition was right here where the lock is released and then the lock was acquired in
publish_diagnostics
.