From d1d0b5a88c666048c21fd225a08170fcc06060e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 18 Jun 2020 08:29:34 +0200 Subject: Remove special casing for library symbols We might as well handle them internally, via queries. I am not sure, but it looks like the current LibraryData setup might even predate salsa? It's not really needed and creates a bunch of complexity. --- crates/rust-analyzer/src/global_state.rs | 37 ++++---------------- crates/rust-analyzer/src/main_loop.rs | 58 +++----------------------------- 2 files changed, 11 insertions(+), 84 deletions(-) (limited to 'crates/rust-analyzer') diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index ef6c7d44d..ee1d37ea2 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -12,12 +12,9 @@ use crossbeam_channel::{unbounded, Receiver}; use lsp_types::Url; use parking_lot::RwLock; use ra_flycheck::{Flycheck, FlycheckConfig}; -use ra_ide::{ - Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, -}; +use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, SourceRootId}; use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsTask, Watch}; -use relative_path::RelativePathBuf; use stdx::format_to; use crate::{ @@ -195,32 +192,18 @@ impl GlobalState { /// Returns a vec of libraries /// FIXME: better API here - pub fn process_changes( - &mut self, - roots_scanned: &mut usize, - ) -> Option)>)>> { + pub fn process_changes(&mut self, roots_scanned: &mut usize) -> bool { let changes = self.vfs.write().commit_changes(); if changes.is_empty() { - return None; + return false; } - let mut libs = Vec::new(); let mut change = AnalysisChange::new(); for c in changes { match c { VfsChange::AddRoot { root, files } => { - let root_path = self.vfs.read().root2path(root); - let is_local = self.local_roots.iter().any(|r| root_path.starts_with(r)); - if is_local { - *roots_scanned += 1; - for (file, path, text) in files { - change.add_file(SourceRootId(root.0), FileId(file.0), path, text); - } - } else { - let files = files - .into_iter() - .map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text)) - .collect(); - libs.push((SourceRootId(root.0), files)); + *roots_scanned += 1; + for (file, path, text) in files { + change.add_file(SourceRootId(root.0), FileId(file.0), path, text); } } VfsChange::AddFile { root, file, path, text } => { @@ -235,13 +218,7 @@ impl GlobalState { } } self.analysis_host.apply_change(change); - Some(libs) - } - - pub fn add_lib(&mut self, data: LibraryData) { - let mut change = AnalysisChange::new(); - change.add_library(data); - self.analysis_host.apply_change(change); + true } pub fn snapshot(&self) -> GlobalStateSnapshot { diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 80cfd3c28..08b0a5a16 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -24,11 +24,10 @@ use lsp_types::{ WorkDoneProgressReport, }; use ra_flycheck::{CheckTask, Status}; -use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId}; +use ra_ide::{Canceled, FileId, LineIndex}; use ra_prof::profile; use ra_project_model::{PackageRoot, ProjectWorkspace}; use ra_vfs::{VfsTask, Watch}; -use relative_path::RelativePathBuf; use rustc_hash::FxHashSet; use serde::{de::DeserializeOwned, Serialize}; use threadpool::ThreadPool; @@ -174,12 +173,10 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { let pool = ThreadPool::default(); let (task_sender, task_receiver) = unbounded::(); - let (libdata_sender, libdata_receiver) = unbounded::(); log::info!("server initialized, serving requests"); { let task_sender = task_sender; - let libdata_sender = libdata_sender; loop { log::trace!("selecting"); let event = select! { @@ -192,7 +189,6 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { Ok(task) => Event::Vfs(task), Err(RecvError) => return Err("vfs died".into()), }, - recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), recv(global_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { Ok(task) => Event::CheckWatcher(task), Err(RecvError) => return Err("check watcher died".into()), @@ -203,15 +199,7 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { break; }; } - loop_turn( - &pool, - &task_sender, - &libdata_sender, - &connection, - &mut global_state, - &mut loop_state, - event, - )?; + loop_turn(&pool, &task_sender, &connection, &mut global_state, &mut loop_state, event)?; } } global_state.analysis_host.request_cancellation(); @@ -219,7 +207,6 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { task_receiver.into_iter().for_each(|task| { on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut global_state) }); - libdata_receiver.into_iter().for_each(drop); log::info!("...tasks have finished"); log::info!("joining threadpool..."); pool.join(); @@ -243,7 +230,6 @@ enum Event { Msg(Message), Task(Task), Vfs(VfsTask), - Lib(LibraryData), CheckWatcher(CheckTask), } @@ -279,7 +265,6 @@ impl fmt::Debug for Event { Event::Msg(it) => fmt::Debug::fmt(it, f), Event::Task(it) => fmt::Debug::fmt(it, f), Event::Vfs(it) => fmt::Debug::fmt(it, f), - Event::Lib(it) => fmt::Debug::fmt(it, f), Event::CheckWatcher(it) => fmt::Debug::fmt(it, f), } } @@ -291,10 +276,6 @@ struct LoopState { pending_responses: FxHashSet, pending_requests: PendingRequests, subscriptions: Subscriptions, - // We try not to index more than MAX_IN_FLIGHT_LIBS libraries at the same - // time to always have a thread ready to react to input. - in_flight_libraries: usize, - pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc)>)>, workspace_loaded: bool, roots_progress_reported: Option, roots_scanned: usize, @@ -315,7 +296,6 @@ impl LoopState { fn loop_turn( pool: &ThreadPool, task_sender: &Sender, - libdata_sender: &Sender, connection: &Connection, global_state: &mut GlobalState, loop_state: &mut LoopState, @@ -339,12 +319,6 @@ fn loop_turn( Event::Vfs(task) => { global_state.vfs.write().handle_task(task); } - Event::Lib(lib) => { - global_state.add_lib(lib); - global_state.maybe_collect_garbage(); - loop_state.in_flight_libraries -= 1; - loop_state.roots_scanned += 1; - } Event::CheckWatcher(task) => on_check_task(task, global_state, task_sender)?, Event::Msg(msg) => match msg { Message::Request(req) => on_request( @@ -390,36 +364,12 @@ fn loop_turn( }, }; - let mut state_changed = false; - if let Some(changes) = global_state.process_changes(&mut loop_state.roots_scanned) { - state_changed = true; - loop_state.pending_libraries.extend(changes); - } - - let max_in_flight_libs = pool.max_count().saturating_sub(2).max(1); - while loop_state.in_flight_libraries < max_in_flight_libs { - let (root, files) = match loop_state.pending_libraries.pop() { - Some(it) => it, - None => break, - }; - - loop_state.in_flight_libraries += 1; - let sender = libdata_sender.clone(); - pool.execute(move || { - log::info!("indexing {:?} ... ", root); - let data = LibraryData::prepare(root, files); - sender.send(data).unwrap(); - }); - } + let mut state_changed = global_state.process_changes(&mut loop_state.roots_scanned); let show_progress = !loop_state.workspace_loaded && global_state.config.client_caps.work_done_progress; - if !loop_state.workspace_loaded - && loop_state.roots_scanned == loop_state.roots_total - && loop_state.pending_libraries.is_empty() - && loop_state.in_flight_libraries == 0 - { + if !loop_state.workspace_loaded && loop_state.roots_scanned == loop_state.roots_total { state_changed = true; loop_state.workspace_loaded = true; if let Some(flycheck) = &global_state.flycheck { -- cgit v1.2.3