diff --git a/crates/ty_server/src/server/api.rs b/crates/ty_server/src/server/api.rs index 2b21500468..ce3dd2c0b5 100644 --- a/crates/ty_server/src/server/api.rs +++ b/crates/ty_server/src/server/api.rs @@ -16,7 +16,7 @@ mod traits; use self::traits::{NotificationHandler, RequestHandler}; use super::{Result, client::Responder, schedule::BackgroundSchedule}; -pub(super) fn request<'a>(req: server::Request) -> Task<'a> { +pub(super) fn request(req: server::Request) -> Task { let id = req.id.clone(); match req.method.as_str() { @@ -61,7 +61,7 @@ pub(super) fn request<'a>(req: server::Request) -> Task<'a> { }) } -pub(super) fn notification<'a>(notif: server::Notification) -> Task<'a> { +pub(super) fn notification(notif: server::Notification) -> Task { match notif.method.as_str() { notifications::DidCloseTextDocumentHandler::METHOD => { local_notification_task::(notif) @@ -100,9 +100,7 @@ pub(super) fn notification<'a>(notif: server::Notification) -> Task<'a> { }) } -fn _local_request_task<'a, R: traits::SyncRequestHandler>( - req: server::Request, -) -> super::Result> +fn _local_request_task(req: server::Request) -> super::Result where <::RequestType as lsp_types::request::Request>::Params: UnwindSafe, { @@ -114,10 +112,10 @@ where })) } -fn background_request_task<'a, R: traits::BackgroundDocumentRequestHandler>( +fn background_request_task( req: server::Request, schedule: BackgroundSchedule, -) -> super::Result> +) -> super::Result where <::RequestType as lsp_types::request::Request>::Params: UnwindSafe, { @@ -187,9 +185,9 @@ fn request_result_to_response( } } -fn local_notification_task<'a, N: traits::SyncNotificationHandler>( +fn local_notification_task( notif: server::Notification, -) -> super::Result> { +) -> super::Result { let (id, params) = cast_notification::(notif)?; Ok(Task::local(move |session, notifier, requester, _| { let _span = tracing::debug_span!("notification", method = N::METHOD).entered(); @@ -201,10 +199,10 @@ fn local_notification_task<'a, N: traits::SyncNotificationHandler>( } #[expect(dead_code)] -fn background_notification_thread<'a, N>( +fn background_notification_thread( req: server::Notification, schedule: BackgroundSchedule, -) -> super::Result> +) -> super::Result where N: traits::BackgroundDocumentNotificationHandler, <::NotificationType as lsp_types::notification::Notification>::Params: diff --git a/crates/ty_server/src/server/client.rs b/crates/ty_server/src/server/client.rs index e136bc98d4..667c0f1428 100644 --- a/crates/ty_server/src/server/client.rs +++ b/crates/ty_server/src/server/client.rs @@ -6,12 +6,12 @@ use serde_json::Value; use super::{ClientSender, schedule::Task}; -type ResponseBuilder<'s> = Box Task<'s>>; +type ResponseBuilder = Box Task>; -pub(crate) struct Client<'s> { +pub(crate) struct Client { notifier: Notifier, responder: Responder, - pub(super) requester: Requester<'s>, + pub(super) requester: Requester, } #[derive(Clone)] @@ -20,13 +20,13 @@ pub(crate) struct Notifier(ClientSender); #[derive(Clone)] pub(crate) struct Responder(ClientSender); -pub(crate) struct Requester<'s> { +pub(crate) struct Requester { sender: ClientSender, next_request_id: i32, - response_handlers: FxHashMap>, + response_handlers: FxHashMap, } -impl Client<'_> { +impl Client { pub(super) fn new(sender: ClientSender) -> Self { Self { notifier: Notifier(sender.clone()), @@ -91,14 +91,14 @@ impl Responder { } } -impl<'s> Requester<'s> { +impl Requester { /// Sends a request of kind `R` to the client, with associated parameters. /// The task provided by `response_handler` will be dispatched as soon as the response /// comes back from the client. pub(crate) fn request( &mut self, params: R::Params, - response_handler: impl Fn(R::Result) -> Task<'s> + 'static, + response_handler: impl Fn(R::Result) -> Task + 'static, ) -> crate::Result<()> where R: lsp_types::request::Request, @@ -155,7 +155,7 @@ impl<'s> Requester<'s> { Ok(()) } - pub(crate) fn pop_response_task(&mut self, response: lsp_server::Response) -> Task<'s> { + pub(crate) fn pop_response_task(&mut self, response: lsp_server::Response) -> Task { if let Some(handler) = self.response_handlers.remove(&response.id) { handler(response) } else { diff --git a/crates/ty_server/src/server/schedule.rs b/crates/ty_server/src/server/schedule.rs index 21c7168318..b77ab22abe 100644 --- a/crates/ty_server/src/server/schedule.rs +++ b/crates/ty_server/src/server/schedule.rs @@ -34,7 +34,7 @@ pub(crate) fn event_loop_thread( pub(crate) struct Scheduler<'s> { session: &'s mut Session, - client: Client<'s>, + client: Client, fmt_pool: thread::Pool, background_pool: thread::Pool, } @@ -60,7 +60,7 @@ impl<'s> Scheduler<'s> { pub(super) fn request( &mut self, params: R::Params, - response_handler: impl Fn(R::Result) -> Task<'s> + 'static, + response_handler: impl Fn(R::Result) -> Task + 'static, ) -> crate::Result<()> where R: lsp_types::request::Request, @@ -69,13 +69,13 @@ impl<'s> Scheduler<'s> { } /// Creates a task to handle a response from the client. - pub(super) fn response(&mut self, response: lsp_server::Response) -> Task<'s> { + pub(super) fn response(&mut self, response: lsp_server::Response) -> Task { self.client.requester.pop_response_task(response) } /// Dispatches a `task` by either running it as a blocking function or /// executing it on a background thread pool. - pub(super) fn dispatch(&mut self, task: task::Task<'s>) { + pub(super) fn dispatch(&mut self, task: task::Task) { match task { Task::Sync(SyncTask { func }) => { let notifier = self.client.notifier(); diff --git a/crates/ty_server/src/server/schedule/task.rs b/crates/ty_server/src/server/schedule/task.rs index d269c1edb5..22c4f2ca9c 100644 --- a/crates/ty_server/src/server/schedule/task.rs +++ b/crates/ty_server/src/server/schedule/task.rs @@ -6,11 +6,11 @@ use crate::{ session::Session, }; -type LocalFn<'s> = Box; +type LocalFn = Box; type BackgroundFn = Box; -type BackgroundFnBuilder<'s> = Box BackgroundFn + 's>; +type BackgroundFnBuilder = Box BackgroundFn>; /// Describes how the task should be run. #[derive(Clone, Copy, Debug, Default)] @@ -36,9 +36,9 @@ pub(in crate::server) enum BackgroundSchedule { /// while local tasks have exclusive access and can modify it as they please. Keep in mind that /// local tasks will **block** the main event loop, so only use local tasks if you **need** /// mutable state access or you need the absolute lowest latency possible. -pub(in crate::server) enum Task<'s> { - Background(BackgroundTaskBuilder<'s>), - Sync(SyncTask<'s>), +pub(in crate::server) enum Task { + Background(BackgroundTaskBuilder), + Sync(SyncTask), } // The reason why this isn't just a 'static background closure @@ -49,30 +49,31 @@ pub(in crate::server) enum Task<'s> { // that the inner closure can capture. This builder closure has a lifetime linked to the scheduler. // When the task is dispatched, the scheduler runs the synchronous builder, which takes the session // as a reference, to create the inner 'static closure. That closure is then moved to a background task pool. -pub(in crate::server) struct BackgroundTaskBuilder<'s> { +pub(in crate::server) struct BackgroundTaskBuilder { pub(super) schedule: BackgroundSchedule, - pub(super) builder: BackgroundFnBuilder<'s>, + pub(super) builder: BackgroundFnBuilder, } -pub(in crate::server) struct SyncTask<'s> { - pub(super) func: LocalFn<'s>, +pub(in crate::server) struct SyncTask { + pub(super) func: LocalFn, } -impl<'s> Task<'s> { +impl Task { /// Creates a new background task. - pub(crate) fn background( - schedule: BackgroundSchedule, - func: impl FnOnce(&Session) -> Box + 's, - ) -> Self { + pub(crate) fn background(schedule: BackgroundSchedule, func: F) -> Self + where + F: FnOnce(&Session) -> Box + 'static, + { Self::Background(BackgroundTaskBuilder { schedule, builder: Box::new(func), }) } /// Creates a new local task. - pub(crate) fn local( - func: impl FnOnce(&mut Session, Notifier, &mut Requester, Responder) + 's, - ) -> Self { + pub(crate) fn local(func: F) -> Self + where + F: FnOnce(&mut Session, Notifier, &mut Requester, Responder) + 'static, + { Self::Sync(SyncTask { func: Box::new(func), })