Abstract over channel

This commit is contained in:
Aleksey Kladov 2020-06-25 08:39:33 +02:00
parent 69e6924dd5
commit dab8808e82
3 changed files with 43 additions and 30 deletions

View file

@ -9,7 +9,7 @@ use crossbeam_channel::{unbounded, Receiver};
use lsp_types::Url;
use parking_lot::RwLock;
use ra_db::{CrateId, SourceRoot, VfsPath};
use ra_flycheck::{FlycheckConfig, FlycheckHandle};
use ra_flycheck::{CheckTask, FlycheckConfig, FlycheckHandle};
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId};
use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
use stdx::format_to;
@ -30,12 +30,15 @@ use rustc_hash::{FxHashMap, FxHashSet};
fn create_flycheck(
workspaces: &[ProjectWorkspace],
config: &FlycheckConfig,
) -> Option<FlycheckHandle> {
) -> Option<(FlycheckHandle, Receiver<CheckTask>)> {
// FIXME: Figure out the multi-workspace situation
workspaces.iter().find_map(move |w| match w {
ProjectWorkspace::Cargo { cargo, .. } => {
let (sender, receiver) = unbounded();
let sender = Box::new(move |msg| sender.send(msg).unwrap());
let cargo_project_root = cargo.workspace_root().to_path_buf();
Some(FlycheckHandle::spawn(config.clone(), cargo_project_root.into()))
let flycheck = FlycheckHandle::spawn(config.clone(), cargo_project_root.into(), sender);
Some((flycheck, receiver))
}
ProjectWorkspace::Json { .. } => {
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
@ -66,7 +69,7 @@ pub(crate) struct GlobalState {
pub(crate) analysis_host: AnalysisHost,
pub(crate) loader: Box<dyn vfs::loader::Handle>,
pub(crate) task_receiver: Receiver<vfs::loader::Message>,
pub(crate) flycheck: Option<FlycheckHandle>,
pub(crate) flycheck: Option<(FlycheckHandle, Receiver<CheckTask>)>,
pub(crate) diagnostics: DiagnosticCollection,
pub(crate) mem_docs: FxHashSet<VfsPath>,
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,