From 5d401092f004f7f61e622b6c1d19a32799cbe31f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 25 Jun 2020 09:19:01 +0200 Subject: [PATCH] Minor rename --- crates/flycheck/src/lib.rs | 57 ++++++++++++------------ crates/rust-analyzer/src/global_state.rs | 6 +-- crates/rust-analyzer/src/main_loop.rs | 35 +++++++-------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index af75adbe22..0f23e97f78 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -10,7 +10,6 @@ use std::{ time::Instant, }; -use cargo_metadata::Message; use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; pub use cargo_metadata::diagnostic::{ @@ -51,12 +50,12 @@ impl fmt::Display for FlycheckConfig { pub struct FlycheckHandle { // XXX: drop order is significant cmd_send: Sender, - handle: jod_thread::JoinHandle<()>, + handle: jod_thread::JoinHandle, } impl FlycheckHandle { pub fn spawn( - sender: Box, + sender: Box, config: FlycheckConfig, workspace_root: PathBuf, ) -> FlycheckHandle { @@ -74,7 +73,7 @@ impl FlycheckHandle { } #[derive(Debug)] -pub enum CheckTask { +pub enum Message { /// Request a clearing of all cached diagnostics from the check watcher ClearDiagnostics, @@ -82,23 +81,23 @@ pub enum CheckTask { AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, /// Request check progress notification to client - Status(Status), + Progress(Progress), } #[derive(Debug)] -pub enum Status { +pub enum Progress { Being, - Progress(String), + DidCheckCrate(String), End, } -pub enum CheckCommand { +enum CheckCommand { /// Request re-start of check thread Update, } struct FlycheckActor { - sender: Box, + sender: Box, config: FlycheckConfig, workspace_root: PathBuf, last_update_req: Option, @@ -109,12 +108,12 @@ struct FlycheckActor { /// doesn't provide a way to read sub-process output without blocking, so we /// have to wrap sub-processes output handling in a thread and pass messages /// back over a channel. - check_process: Option>, + check_process: Option, } impl FlycheckActor { fn new( - sender: Box, + sender: Box, config: FlycheckConfig, workspace_root: PathBuf, ) -> FlycheckActor { @@ -154,15 +153,15 @@ impl FlycheckActor { if self.should_recheck() { self.last_update_req = None; - self.send(CheckTask::ClearDiagnostics); + self.send(Message::ClearDiagnostics); self.restart_check_process(); } } } fn clean_previous_results(&self) { - self.send(CheckTask::ClearDiagnostics); - self.send(CheckTask::Status(Status::End)); + self.send(Message::ClearDiagnostics); + self.send(Message::Progress(Progress::End)); } fn should_recheck(&mut self) -> bool { @@ -184,28 +183,28 @@ impl FlycheckActor { fn handle_message(&self, msg: CheckEvent) { match msg { CheckEvent::Begin => { - self.send(CheckTask::Status(Status::Being)); + self.send(Message::Progress(Progress::Being)); } CheckEvent::End => { - self.send(CheckTask::Status(Status::End)); + self.send(Message::Progress(Progress::End)); } - CheckEvent::Msg(Message::CompilerArtifact(msg)) => { - self.send(CheckTask::Status(Status::Progress(msg.target.name))); + CheckEvent::Msg(cargo_metadata::Message::CompilerArtifact(msg)) => { + self.send(Message::Progress(Progress::DidCheckCrate(msg.target.name))); } - CheckEvent::Msg(Message::CompilerMessage(msg)) => { - self.send(CheckTask::AddDiagnostic { + CheckEvent::Msg(cargo_metadata::Message::CompilerMessage(msg)) => { + self.send(Message::AddDiagnostic { workspace_root: self.workspace_root.clone(), diagnostic: msg.message, }); } - CheckEvent::Msg(Message::BuildScriptExecuted(_msg)) => {} - CheckEvent::Msg(Message::BuildFinished(_)) => {} - CheckEvent::Msg(Message::TextLine(_)) => {} - CheckEvent::Msg(Message::Unknown) => {} + CheckEvent::Msg(cargo_metadata::Message::BuildScriptExecuted(_)) + | CheckEvent::Msg(cargo_metadata::Message::BuildFinished(_)) + | CheckEvent::Msg(cargo_metadata::Message::TextLine(_)) + | CheckEvent::Msg(cargo_metadata::Message::Unknown) => {} } } @@ -256,9 +255,11 @@ impl FlycheckActor { let res = run_cargo(cmd, &mut |message| { // Skip certain kinds of messages to only spend time on what's useful match &message { - Message::CompilerArtifact(artifact) if artifact.fresh => return true, - Message::BuildScriptExecuted(_) => return true, - Message::Unknown => return true, + cargo_metadata::Message::CompilerArtifact(artifact) if artifact.fresh => { + return true + } + cargo_metadata::Message::BuildScriptExecuted(_) + | cargo_metadata::Message::Unknown => return true, _ => {} } @@ -278,7 +279,7 @@ impl FlycheckActor { })) } - fn send(&self, check_task: CheckTask) { + fn send(&self, check_task: Message) { (self.sender)(check_task) } } diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 6038bf664f..446207e9e5 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -6,7 +6,7 @@ use std::{convert::TryFrom, sync::Arc}; use crossbeam_channel::{unbounded, Receiver}; -use flycheck::{CheckTask, FlycheckConfig, FlycheckHandle}; +use flycheck::{FlycheckConfig, FlycheckHandle}; use lsp_types::Url; use parking_lot::RwLock; use ra_db::{CrateId, SourceRoot, VfsPath}; @@ -30,7 +30,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; fn create_flycheck( workspaces: &[ProjectWorkspace], config: &FlycheckConfig, -) -> Option<(FlycheckHandle, Receiver)> { +) -> Option<(FlycheckHandle, Receiver)> { // FIXME: Figure out the multi-workspace situation workspaces.iter().find_map(move |w| match w { ProjectWorkspace::Cargo { cargo, .. } => { @@ -69,7 +69,7 @@ pub(crate) struct GlobalState { pub(crate) analysis_host: AnalysisHost, pub(crate) loader: Box, pub(crate) task_receiver: Receiver, - pub(crate) flycheck: Option<(FlycheckHandle, Receiver)>, + pub(crate) flycheck: Option<(FlycheckHandle, Receiver)>, pub(crate) diagnostics: DiagnosticCollection, pub(crate) mem_docs: FxHashSet, pub(crate) vfs: Arc)>>, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0664e4a5a4..200641cd57 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -9,7 +9,6 @@ use std::{ }; use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; -use flycheck::CheckTask; use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; use lsp_types::{request::Request as _, NumberOrString, TextDocumentContentChangeEvent}; use ra_db::VfsPath; @@ -176,7 +175,7 @@ enum Event { Msg(Message), Task(Task), Vfs(vfs::loader::Message), - CheckWatcher(CheckTask), + CheckWatcher(flycheck::Message), } impl fmt::Debug for Event { @@ -250,14 +249,14 @@ fn loop_turn( } vfs::loader::Message::Progress { n_total, n_done } => { let state = if n_done == 0 { - ProgressState::Start + Progress::Begin } else if n_done < n_total { - ProgressState::Report + Progress::Report } else { assert_eq!(n_done, n_total); global_state.status = Status::Ready; became_ready = true; - ProgressState::End + Progress::End }; report_progress( global_state, @@ -593,17 +592,17 @@ fn apply_document_changes( } fn on_check_task( - task: CheckTask, + task: flycheck::Message, global_state: &mut GlobalState, task_sender: &Sender, msg_sender: &Sender, ) -> Result<()> { match task { - CheckTask::ClearDiagnostics => { + flycheck::Message::ClearDiagnostics => { task_sender.send(Task::Diagnostic(DiagnosticTask::ClearCheck))?; } - CheckTask::AddDiagnostic { workspace_root, diagnostic } => { + flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => { let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp( &global_state.config.diagnostics, &diagnostic, @@ -627,11 +626,11 @@ fn on_check_task( } } - CheckTask::Status(status) => { + flycheck::Message::Progress(status) => { let (state, message) = match status { - flycheck::Status::Being => (ProgressState::Start, None), - flycheck::Status::Progress(target) => (ProgressState::Report, Some(target)), - flycheck::Status::End => (ProgressState::End, None), + flycheck::Progress::Being => (Progress::Begin, None), + flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)), + flycheck::Progress::End => (Progress::End, None), }; report_progress(global_state, msg_sender, "cargo check", state, message, None); @@ -654,8 +653,8 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender, state: } #[derive(Eq, PartialEq)] -enum ProgressState { - Start, +enum Progress { + Begin, Report, End, } @@ -668,7 +667,7 @@ fn report_progress( global_state: &mut GlobalState, sender: &Sender, title: &str, - state: ProgressState, + state: Progress, message: Option, percentage: Option, ) { @@ -677,7 +676,7 @@ fn report_progress( } let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title)); let work_done_progress = match state { - ProgressState::Start => { + Progress::Begin => { let work_done_progress_create = global_state.req_queue.outgoing.register( lsp_types::request::WorkDoneProgressCreate::METHOD.to_string(), lsp_types::WorkDoneProgressCreateParams { token: token.clone() }, @@ -692,14 +691,14 @@ fn report_progress( percentage, }) } - ProgressState::Report => { + Progress::Report => { lsp_types::WorkDoneProgress::Report(lsp_types::WorkDoneProgressReport { cancellable: None, message, percentage, }) } - ProgressState::End => { + Progress::End => { lsp_types::WorkDoneProgress::End(lsp_types::WorkDoneProgressEnd { message }) } };