From 5ba645c0094c79d9aab527f0396fdad3e99bef3b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 3 Sep 2018 21:26:59 +0300 Subject: index libraies off the main thread --- crates/server/src/main_loop/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'crates/server/src/main_loop') diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index ce61265a2..3d131274f 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs @@ -10,7 +10,7 @@ use threadpool::ThreadPool; use serde::{Serialize, de::DeserializeOwned}; use crossbeam_channel::{bounded, Sender, Receiver}; use languageserver_types::{NumberOrString}; -use libanalysis::{FileId, JobHandle, JobToken}; +use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; use gen_lsp_server::{ RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode, handle_shutdown, @@ -94,6 +94,7 @@ fn main_loop_inner( pending_requests: &mut HashMap, subs: &mut Subscriptions, ) -> Result<()> { + let (libdata_sender, libdata_receiver) = bounded(1024); ws_sender.send(ws_root.clone()); fs_sender.send(ws_root.clone()); loop { @@ -103,6 +104,7 @@ fn main_loop_inner( Task(Task), Fs(PathBuf, Vec), Ws(Result), + Lib(LibraryData), } trace!("selecting"); let event = select! { @@ -119,6 +121,7 @@ fn main_loop_inner( None => bail!("workspace watcher died"), Some(ws) => Event::Ws(ws), } + recv(libdata_receiver, data) => Event::Lib(data.unwrap()) }; trace!("selected {:?}", event); let mut state_changed = false; @@ -129,7 +132,12 @@ fn main_loop_inner( if root == ws_root { state.apply_fs_changes(events); } else { - state.add_library(events); + let files = state.events_to_files(events); + let sender = libdata_sender.clone(); + pool.execute(move || { + let data = LibraryData::prepare(files); + sender.send(data); + }); } state_changed = true; } @@ -152,6 +160,9 @@ fn main_loop_inner( Err(e) => warn!("loading workspace failed: {}", e), } } + Event::Lib(lib) => { + state.add_lib(lib); + } Event::Msg(msg) => { match msg { RawMessage::Request(req) => { -- cgit v1.2.3