diff --git a/compiler/crates/relay-lsp/src/server/mod.rs b/compiler/crates/relay-lsp/src/server/mod.rs index a5fa3abf6d47..d36335022cc5 100644 --- a/compiler/crates/relay-lsp/src/server/mod.rs +++ b/compiler/crates/relay-lsp/src/server/mod.rs @@ -191,6 +191,12 @@ fn next_task( } } +static SERIAL_NOTIFICATIONS: [&str; 3] = [ + "textDocument/didChange", + "textDocument/didOpen", + "textDocument/didClose", +]; + struct LSPTaskProcessor; impl @@ -210,6 +216,15 @@ impl bool { + match task { + Task::InboundMessage(Message::Notification(notification)) => { + SERIAL_NOTIFICATIONS.contains(¬ification.method.as_str()) + } + _ => false, + } + } } fn handle_request( diff --git a/compiler/crates/relay-lsp/src/server/task_queue.rs b/compiler/crates/relay-lsp/src/server/task_queue.rs index 1378f6e3d724..c407cb3972f5 100644 --- a/compiler/crates/relay-lsp/src/server/task_queue.rs +++ b/compiler/crates/relay-lsp/src/server/task_queue.rs @@ -22,6 +22,8 @@ pub struct TaskQueue { pub trait TaskProcessor: Send + Sync + 'static { fn process(&self, state: Arc, task: T); + + fn requires_serial_execution(&self, task: &T) -> bool; } pub struct TaskScheduler { @@ -60,13 +62,23 @@ where let now = Instant::now(); debug!("Processing task {:?}", &task_str); let processor = Arc::clone(&self.processor); - thread::spawn(move || { + + if processor.requires_serial_execution(&task) { processor.process(state, task); debug!( - "task {} completed in {}ms", + "task {} completed serially in {}ms", task_str, now.elapsed().as_millis() ); - }); + } else { + thread::spawn(move || { + processor.process(state, task); + debug!( + "task {} completed in {}ms", + task_str, + now.elapsed().as_millis() + ); + }); + } } }