From 47cbaeba6f21e59ee8735bfe8bcbf06300767b57 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 3 Sep 2018 21:03:37 +0300 Subject: Index deps --- crates/server/src/main_loop/handlers.rs | 6 +++- crates/server/src/main_loop/mod.rs | 62 ++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 25 deletions(-) (limited to 'crates/server/src/main_loop') diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 898195f6d..323d4e95e 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs @@ -141,14 +141,18 @@ pub fn handle_workspace_symbol( token: JobToken, ) -> Result>> { let all_symbols = params.query.contains("#"); + let libs = params.query.contains("*"); let query = { let query: String = params.query.chars() - .filter(|&c| c != '#') + .filter(|&c| c != '#' && c != '*') .collect(); let mut q = Query::new(query); if !all_symbols { q.only_types(); } + if libs { + q.libs(); + } q.limit(128); q }; diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index bb1d638e0..ce61265a2 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs @@ -38,9 +38,8 @@ pub fn main_loop( ) -> Result<()> { let pool = ThreadPool::new(4); let (task_sender, task_receiver) = bounded::(16); - let (fs_events_receiver, watcher) = vfs::watch(vec![root.clone()]); - let (ws_root_sender, ws_receiver, ws_watcher) = workspace_loader(); - ws_root_sender.send(root); + let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); + let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); info!("server initialized, serving requests"); let mut state = ServerWorldState::new(); @@ -48,13 +47,15 @@ pub fn main_loop( let mut pending_requests = HashMap::new(); let mut subs = Subscriptions::new(); let main_res = main_loop_inner( + root, &pool, - msg_receriver, msg_sender, - task_receiver.clone(), + msg_receriver, task_sender, - fs_events_receiver, - ws_root_sender, + task_receiver.clone(), + fs_sender, + fs_receiver, + ws_sender, ws_receiver, &mut state, &mut pending_requests, @@ -68,38 +69,40 @@ pub fn main_loop( pool.join(); info!("...threadpool has finished"); - let vfs_res = watcher.stop(); + let fs_res = fs_watcher.stop(); let ws_res = ws_watcher.stop(); main_res?; - vfs_res?; + fs_res?; ws_res?; Ok(()) } fn main_loop_inner( + ws_root: PathBuf, pool: &ThreadPool, - msg_receiver: &mut Receiver, msg_sender: &mut Sender, - task_receiver: Receiver, + msg_receiver: &mut Receiver, task_sender: Sender, - fs_receiver: Receiver>, - _ws_roots_sender: Sender, + task_receiver: Receiver, + fs_sender: Sender, + fs_receiver: Receiver<(PathBuf, Vec)>, + ws_sender: Sender, ws_receiver: Receiver>, state: &mut ServerWorldState, pending_requests: &mut HashMap, subs: &mut Subscriptions, ) -> Result<()> { - let mut fs_receiver = Some(fs_receiver); + ws_sender.send(ws_root.clone()); + fs_sender.send(ws_root.clone()); loop { #[derive(Debug)] enum Event { Msg(RawMessage), Task(Task), - Fs(Vec), + Fs(PathBuf, Vec), Ws(Result), - FsWatcherDead, } trace!("selecting"); let event = select! { @@ -109,8 +112,8 @@ fn main_loop_inner( }, recv(task_receiver, task) => Event::Task(task.unwrap()), recv(fs_receiver, events) => match events { - Some(events) => Event::Fs(events), - None => Event::FsWatcherDead, + None => bail!("roots watcher died"), + Some((pb, events)) => Event::Fs(pb, events), } recv(ws_receiver, ws) => match ws { None => bail!("workspace watcher died"), @@ -120,19 +123,30 @@ fn main_loop_inner( trace!("selected {:?}", event); let mut state_changed = false; match event { - Event::FsWatcherDead => fs_receiver = None, Event::Task(task) => on_task(task, msg_sender, pending_requests), - Event::Fs(events) => { - trace!("fs change, {} events", events.len()); - state.apply_fs_changes(events); + Event::Fs(root, events) => { + info!("fs change, {}, {} events", root.display(), events.len()); + if root == ws_root { + state.apply_fs_changes(events); + } else { + state.add_library(events); + } state_changed = true; } Event::Ws(ws) => { match ws { Ok(ws) => { - let not = RawNotification::new::(&vec![ws.clone()]); + let workspaces = vec![ws]; + let not = RawNotification::new::(&workspaces); msg_sender.send(RawMessage::Notification(not)); - state.set_workspaces(vec![ws]); + for ws in workspaces.iter() { + for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { + debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); + // deadlocky :-( + fs_sender.send(pkg.root(ws).to_path_buf()); + } + } + state.set_workspaces(workspaces); state_changed = true; } Err(e) => warn!("loading workspace failed: {}", e), -- cgit v1.2.3