-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[ty] Add background request task support #19041
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
|
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.
Nice! My only comments are requesting docs, probably because I'm somewhat unfamiliar with this part of the LSP. :-)
@@ -135,7 +135,52 @@ where | |||
})) | |||
} | |||
|
|||
fn background_request_task<R: traits::BackgroundDocumentRequestHandler>( | |||
#[expect(dead_code)] |
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.
Could you add a comment saying why this code is kept around even though it isn't used?
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 split the workspace diagnostics work into two PRs to ease up the review process. This is going to be used in the follow-up PR (#18939). Sorry, I should've highlighted this as a review comment!
snapshot: WorkspaceSnapshot, | ||
client: &Client, | ||
params: <<Self as RequestHandler>::RequestType as Request>::Params, | ||
) -> super::Result<<<Self as RequestHandler>::RequestType as Request>::Result>; |
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.
One thing I'd find helpful here is some prose (perhaps on the module doc) that briefly explains the traits here and how they're connected.
If you think this code is going to be heavily refactored soon, then it might not make sense to add docs.
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.
Definitely! Most of this stuff is currently in my and Micha's mind but it would be useful to have it written down. I'll prioritize it soon as there are now more people who'll be working on the server.
0e72155
to
1252436
Compare
CodSpeed WallTime Performance ReportMerging #19041 will degrade performances by 4.82%Comparing Summary
Benchmarks breakdown
|
/// A request handler that can be run on a background thread. | ||
pub(super) trait BackgroundRequestHandler: RetriableRequestHandler { | ||
fn run( | ||
snapshot: WorkspaceSnapshot, |
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 wonder if we should call this SessionSnapshot
instead. It's unfortunate that the LSP specification made such a mess of the term workspace (which can refer to an open folder, or all open foldlers).
@@ -223,6 +224,14 @@ impl Session { | |||
self.index().key_from_url(url) | |||
} | |||
|
|||
pub(crate) fn take_workspace_snapshot(&self) -> WorkspaceSnapshot { | |||
WorkspaceSnapshot { | |||
projects: AssertUnwindSafe(self.projects.values().cloned().collect()), |
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'd suggest removing the AssertUnwindSafe
here and insteaed wrap the entire snapshot in crates/ty_server/src/server/api.rs
in an AssertUnwindSafe
and add a comment saying that it's safe to move it across unwind boundaries because the value isn't used after unwinding.
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.
That would mean that the snapshot
parameter type of BackgroundRequestHandler::run
would need to be AssertUnwindSafe<SessionSnapshot>
. Or, are you suggesting to wrap the AssertUnwindSafe
on the entire closure that is the first argument to catch_unwind
?
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.
The former doesn't seems to work as the compiler still errors stating that some reference may not be safe to be transferred across the catch_unwind boundary.
Edit: Nevermind, it works.
Nice! |
Addressed these review comments in #19177. |
This PR addresses the post-merge review comments from #19041, specifically it: - Rename `WorkspaceSnapshot` to `SessionSnapshot` - Rename `take_workspace_snapshot` to `take_session_snapshot` - Rename `take_snapshot` to `take_document_snapshot` - Move `AssertUnwindSafe` closer to the `catch_unwind` call which requires the assertion
Summary
This PR adds a new trait to support running a request in the background.
Currently, there exists a
BackgroundDocumentRequestHandler
trait which is similar but is scoped to a specific document (file in an editor context). The new traitBackgroundRequestHandler
is not tied to a specific document nor a specific project but it's for the entire workspace.This is added to support running workspace wide requests like computing the workspace diagnostics or workspace symbols.
Note: There's a slight difference with what a "workspace" means between the server and ty. Currently, there's a 1-1 relationship between a workspace in an editor and the project database corresponding to that workspace in ty but this could change in the future when Micha adds support for multiple workspaces or multi-root workspaces.
The data that would be required by the request handler (based on implementing workspace diagnostics) is the list of databases (
ProjectDatabse
) corresponding to the projects in the workspace and the index (Index
) that contains the open documents. TheWorkspaceSnapshot
represents this and is passed to the handler similar toDocumentSnapshot
.Test Plan
This is used in implementing the workspace diagnostics which is where this is tested.