Skip to content

Commit

Permalink
Ensure documents are synced before calculating completions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Jan 11, 2024
1 parent 1384f89 commit 01dcf08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions compiler/crates/relay-lsp/src/server/lsp_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,11 @@ pub(crate) fn handle_lsp_state_tasks<
}
}
}

struct Guard<'a>(&'a mut bool);

impl<'a> Drop for Guard<'a> {
fn drop(&mut self) {
*self.0 = false;
}
}
15 changes: 15 additions & 0 deletions compiler/crates/relay-lsp/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ fn next_task(
}
}

static SERIAL_NOTIFICATIONS: [&str; 3] = [
"textDocument/didChange",
"textDocument/didOpen",
"textDocument/didClose",
];

struct LSPTaskProcessor;

impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentation + 'static>
Expand All @@ -210,6 +216,15 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
}
}
}

fn requires_serial_execution(&self, task: &Task) -> bool {
match task {
Task::InboundMessage(Message::Notification(notification)) => {
SERIAL_NOTIFICATIONS.contains(&notification.method.as_str())
}
_ => false,
}
}
}

fn handle_request<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentation>(
Expand Down
18 changes: 15 additions & 3 deletions compiler/crates/relay-lsp/src/server/task_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct TaskQueue<S, T> {

pub trait TaskProcessor<S, T>: Send + Sync + 'static {
fn process(&self, state: Arc<S>, task: T);

fn requires_serial_execution(&self, task: &T) -> bool;
}

pub struct TaskScheduler<T> {
Expand Down Expand Up @@ -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()
);
});
}
}
}

0 comments on commit 01dcf08

Please sign in to comment.