mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
dedupe
This commit is contained in:
parent
36d922c87d
commit
bf42a75f1e
1 changed files with 33 additions and 20 deletions
|
@ -27,11 +27,13 @@ use std::path::PathBuf;
|
||||||
use threadpool::ThreadPool;
|
use threadpool::ThreadPool;
|
||||||
use crossbeam_channel::{bounded, Sender, Receiver};
|
use crossbeam_channel::{bounded, Sender, Receiver};
|
||||||
use flexi_logger::Logger;
|
use flexi_logger::Logger;
|
||||||
use libanalysis::WorldState;
|
|
||||||
use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier};
|
use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier};
|
||||||
|
use serde::{ser::Serialize, de::DeserializeOwned};
|
||||||
|
use libanalysis::{WorldState, World};
|
||||||
|
|
||||||
use ::{
|
use ::{
|
||||||
io::{Io, RawMsg},
|
io::{Io, RawMsg, RawRequest},
|
||||||
|
req::Request,
|
||||||
handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics},
|
handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -171,24 +173,12 @@ fn main_loop(
|
||||||
match msg {
|
match msg {
|
||||||
RawMsg::Request(req) => {
|
RawMsg::Request(req) => {
|
||||||
let mut req = Some(req);
|
let mut req = Some(req);
|
||||||
dispatch::handle_request::<req::SyntaxTree, _>(&mut req, |params, resp| {
|
handle_request_on_threadpool::<req::SyntaxTree>(
|
||||||
let world = world.snapshot();
|
&mut req, pool, world, &sender, handle_syntax_tree
|
||||||
let sender = sender.clone();
|
)?;
|
||||||
pool.execute(move || {
|
handle_request_on_threadpool::<req::ExtendSelection>(
|
||||||
let res = handle_syntax_tree(world, params);
|
&mut req, pool, world, &sender, handle_extend_selection
|
||||||
sender.send(Box::new(|io: &mut Io| resp.response(io, res)))
|
)?;
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
})?;
|
|
||||||
dispatch::handle_request::<req::ExtendSelection, _>(&mut req, |params, resp| {
|
|
||||||
let world = world.snapshot();
|
|
||||||
let sender = sender.clone();
|
|
||||||
pool.execute(move || {
|
|
||||||
let res = handle_extend_selection(world, params);
|
|
||||||
sender.send(Box::new(|io: &mut Io| resp.response(io, res)))
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
})?;
|
|
||||||
let mut shutdown = false;
|
let mut shutdown = false;
|
||||||
dispatch::handle_request::<req::Shutdown, _>(&mut req, |(), resp| {
|
dispatch::handle_request::<req::Shutdown, _>(&mut req, |(), resp| {
|
||||||
resp.result(io, ())?;
|
resp.result(io, ())?;
|
||||||
|
@ -271,6 +261,29 @@ fn main_loop(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_request_on_threadpool<R>(
|
||||||
|
req: &mut Option<RawRequest>,
|
||||||
|
pool: &ThreadPool,
|
||||||
|
world: &WorldState,
|
||||||
|
sender: &Sender<Thunk>,
|
||||||
|
f: fn(World, R::Params) -> Result<R::Result>,
|
||||||
|
) -> Result<()>
|
||||||
|
where
|
||||||
|
R: Request + Send + 'static,
|
||||||
|
R::Params: DeserializeOwned + Send + 'static,
|
||||||
|
R::Result: Serialize + Send + 'static,
|
||||||
|
{
|
||||||
|
dispatch::handle_request::<R, _>(req, |params, resp| {
|
||||||
|
let world = world.snapshot();
|
||||||
|
let sender = sender.clone();
|
||||||
|
pool.execute(move || {
|
||||||
|
let res = f(world, params);
|
||||||
|
sender.send(Box::new(|io: &mut Io| resp.response(io, res)))
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
trait FnBox<A, R>: Send {
|
trait FnBox<A, R>: Send {
|
||||||
fn call_box(self: Box<Self>, a: A) -> R;
|
fn call_box(self: Box<Self>, a: A) -> R;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue