-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Implement long-polling for workspace diagnsotics #19670
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
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
68792c3
to
cd0645c
Compare
api::request(request); | ||
tracing::debug!("Retrying request {}/{}", request.method, request.id); | ||
let task = api::request(request); | ||
scheduler.dispatch(task, &mut self.session, client); |
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.
Whooops
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.
Oh lol, is it that the request were never retried before this PR then?
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.
yes 😅
79178da
to
2995687
Compare
317164e
to
d9090a8
Compare
|
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.
This is awesome! Thank you for taking on the entire performance improvement part of workspace diagnostics!
crates/ty_server/src/server/api/requests/workspace_diagnostic.rs
Outdated
Show resolved
Hide resolved
crates/ty_server/src/server/api/requests/workspace_diagnostic.rs
Outdated
Show resolved
Hide resolved
crates/ty_server/src/server/api/requests/workspace_diagnostic.rs
Outdated
Show resolved
Hide resolved
api::request(request); | ||
tracing::debug!("Retrying request {}/{}", request.method, request.id); | ||
let task = api::request(request); | ||
scheduler.dispatch(task, &mut self.session, client); |
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.
Oh lol, is it that the request were never retried before this PR then?
|
||
// Make a workspace diagnostic request to a project with one file but no diagnostics | ||
// This should trigger long-polling since the project has no diagnostics | ||
let request_id = send_workspace_diagnostic_request(&mut server); |
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.
Can we update the workspace_diagnostic_request
method on TestServer
with more parameters like the progress params, partial result params, etc. instead of adding another function here?
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.
I sort of prefer test-local helpers because the method on TestServer
otherwise has to accept a WorkspaceDiagnosticParams
to support all combinations, in which case it is about as verbose as calling the method directly. What I can do is to give this function a better name
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.
We could update the parameters on the server method to accept the parts of WorkspaceDiagnosticParams
instead but I'm fine either way.
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.
Oh, I now remember why it is necessary. The key difference is that this method doesn't await the response because we need to handle the response specially (it's long polling)
2995687
to
54a2995
Compare
b53424d
to
c03e029
Compare
Summary
This PR implements long-polling for workspace diagnostics (as described in the spec).
Without long polling, VS Code keeps sending workspace/diagnostic requests every 2 seconds, even if the user didn't make any changes. This can take up a fair amount of CPU usage, even if all diagnostics are cached, because we still need to iterate over all files.
This PR implements long polling which avoids this. The basic idea is that the server keeps the
workspace/diagnostic
open and only responds once there are changes (e.g. new or fixed diagnostics) or the server shuts down (or cancels the request).Implementing this required adding a
process
method to the request handler in order that workspace diagnostics can omit the response when long polling.This PR implements the last optimization mentioned in astral-sh/ty#824
Closes astral-sh/ty#824
I can no longer reproduce astral-sh/ty#818 on this PR (closes astral-sh/ty#818)
Test Plan
Added integration tests
Screen.Recording.2025-08-01.at.17.38.34.mov
Screen.Recording.2025-08-01.at.17.39.13.mov