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 +++++++++++++-- crates/server/src/server_world.rs | 13 ++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'crates/server/src') 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) => { diff --git a/crates/server/src/server_world.rs b/crates/server/src/server_world.rs index 95c109e10..729418eaa 100644 --- a/crates/server/src/server_world.rs +++ b/crates/server/src/server_world.rs @@ -6,7 +6,7 @@ use std::{ }; use languageserver_types::Url; -use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId}; +use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData}; use { Result, @@ -64,17 +64,20 @@ impl ServerWorldState { self.analysis_host.change_files(changes); } - pub fn add_library(&mut self, events: Vec) { + pub fn events_to_files(&mut self, events: Vec) -> Vec<(FileId, String)> { let pm = &mut self.path_map; - let files = events.into_iter() + events.into_iter() .map(|event| { let text = match event.kind { FileEventKind::Add(text) => text, }; (event.path, text) }) - .map(|(path, text)| (pm.get_or_insert(path), text)); - self.analysis_host.add_library(files); + .map(|(path, text)| (pm.get_or_insert(path), text)) + .collect() + } + pub fn add_lib(&mut self, data: LibraryData) { + self.analysis_host.add_library(data); } pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId { -- cgit v1.2.3