aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/server/src/main.rs53
1 files changed, 33 insertions, 20 deletions
diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs
index 6018350e3..f521271fb 100644
--- a/crates/server/src/main.rs
+++ b/crates/server/src/main.rs
@@ -27,11 +27,13 @@ use std::path::PathBuf;
27use threadpool::ThreadPool; 27use threadpool::ThreadPool;
28use crossbeam_channel::{bounded, Sender, Receiver}; 28use crossbeam_channel::{bounded, Sender, Receiver};
29use flexi_logger::Logger; 29use flexi_logger::Logger;
30use libanalysis::WorldState;
31use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier}; 30use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier};
31use serde::{ser::Serialize, de::DeserializeOwned};
32use libanalysis::{WorldState, World};
32 33
33use ::{ 34use ::{
34 io::{Io, RawMsg}, 35 io::{Io, RawMsg, RawRequest},
36 req::Request,
35 handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics}, 37 handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics},
36}; 38};
37 39
@@ -171,24 +173,12 @@ fn main_loop(
171 match msg { 173 match msg {
172 RawMsg::Request(req) => { 174 RawMsg::Request(req) => {
173 let mut req = Some(req); 175 let mut req = Some(req);
174 dispatch::handle_request::<req::SyntaxTree, _>(&mut req, |params, resp| { 176 handle_request_on_threadpool::<req::SyntaxTree>(
175 let world = world.snapshot(); 177 &mut req, pool, world, &sender, handle_syntax_tree
176 let sender = sender.clone(); 178 )?;
177 pool.execute(move || { 179 handle_request_on_threadpool::<req::ExtendSelection>(
178 let res = handle_syntax_tree(world, params); 180 &mut req, pool, world, &sender, handle_extend_selection
179 sender.send(Box::new(|io: &mut Io| resp.response(io, res))) 181 )?;
180 });
181 Ok(())
182 })?;
183 dispatch::handle_request::<req::ExtendSelection, _>(&mut req, |params, resp| {
184 let world = world.snapshot();
185 let sender = sender.clone();
186 pool.execute(move || {
187 let res = handle_extend_selection(world, params);
188 sender.send(Box::new(|io: &mut Io| resp.response(io, res)))
189 });
190 Ok(())
191 })?;
192 let mut shutdown = false; 182 let mut shutdown = false;
193 dispatch::handle_request::<req::Shutdown, _>(&mut req, |(), resp| { 183 dispatch::handle_request::<req::Shutdown, _>(&mut req, |(), resp| {
194 resp.result(io, ())?; 184 resp.result(io, ())?;
@@ -271,6 +261,29 @@ fn main_loop(
271 } 261 }
272} 262}
273 263
264fn handle_request_on_threadpool<R>(
265 req: &mut Option<RawRequest>,
266 pool: &ThreadPool,
267 world: &WorldState,
268 sender: &Sender<Thunk>,
269 f: fn(World, R::Params) -> Result<R::Result>,
270) -> Result<()>
271 where
272 R: Request + Send + 'static,
273 R::Params: DeserializeOwned + Send + 'static,
274 R::Result: Serialize + Send + 'static,
275{
276 dispatch::handle_request::<R, _>(req, |params, resp| {
277 let world = world.snapshot();
278 let sender = sender.clone();
279 pool.execute(move || {
280 let res = f(world, params);
281 sender.send(Box::new(|io: &mut Io| resp.response(io, res)))
282 });
283 Ok(())
284 })
285}
286
274trait FnBox<A, R>: Send { 287trait FnBox<A, R>: Send {
275 fn call_box(self: Box<Self>, a: A) -> R; 288 fn call_box(self: Box<Self>, a: A) -> R;
276} 289}