mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
ruff server
sets worker thread pool size based on the user's available cores (#10399)
## Summary Fixes #10369. ## Test Plan N/A
This commit is contained in:
parent
1a2f9f082d
commit
d9f1cdbea1
9 changed files with 62 additions and 17 deletions
|
@ -1,5 +1,7 @@
|
|||
//! Scheduling, I/O, and API endpoints.
|
||||
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
use lsp::Connection;
|
||||
use lsp_server as lsp;
|
||||
use lsp_types as types;
|
||||
|
@ -27,11 +29,12 @@ pub(crate) type Result<T> = std::result::Result<T, api::Error>;
|
|||
pub struct Server {
|
||||
conn: lsp::Connection,
|
||||
threads: lsp::IoThreads,
|
||||
worker_threads: NonZeroUsize,
|
||||
session: Session,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub fn new() -> crate::Result<Self> {
|
||||
pub fn new(worker_threads: NonZeroUsize) -> crate::Result<Self> {
|
||||
let (conn, threads) = lsp::Connection::stdio();
|
||||
|
||||
let (id, params) = conn.initialize_start()?;
|
||||
|
@ -66,19 +69,27 @@ impl Server {
|
|||
Ok(Self {
|
||||
conn,
|
||||
threads,
|
||||
worker_threads,
|
||||
session: Session::new(&server_capabilities, &workspaces)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn run(self) -> crate::Result<()> {
|
||||
let result = event_loop_thread(move || Self::event_loop(&self.conn, self.session))?.join();
|
||||
let result = event_loop_thread(move || {
|
||||
Self::event_loop(&self.conn, self.session, self.worker_threads)
|
||||
})?
|
||||
.join();
|
||||
self.threads.join()?;
|
||||
result
|
||||
}
|
||||
|
||||
fn event_loop(connection: &Connection, session: Session) -> crate::Result<()> {
|
||||
fn event_loop(
|
||||
connection: &Connection,
|
||||
session: Session,
|
||||
worker_threads: NonZeroUsize,
|
||||
) -> crate::Result<()> {
|
||||
// TODO(jane): Make thread count configurable
|
||||
let mut scheduler = schedule::Scheduler::new(session, 4, &connection.sender);
|
||||
let mut scheduler = schedule::Scheduler::new(session, worker_threads, &connection.sender);
|
||||
for msg in &connection.receiver {
|
||||
let task = match msg {
|
||||
lsp::Message::Request(req) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue