Minor rename

This commit is contained in:
Aleksey Kladov 2020-06-25 09:19:01 +02:00
parent 0ec5d4f55c
commit 5d401092f0
3 changed files with 49 additions and 49 deletions

View file

@ -10,7 +10,6 @@ use std::{
time::Instant, time::Instant,
}; };
use cargo_metadata::Message;
use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
pub use cargo_metadata::diagnostic::{ pub use cargo_metadata::diagnostic::{
@ -51,12 +50,12 @@ impl fmt::Display for FlycheckConfig {
pub struct FlycheckHandle { pub struct FlycheckHandle {
// XXX: drop order is significant // XXX: drop order is significant
cmd_send: Sender<CheckCommand>, cmd_send: Sender<CheckCommand>,
handle: jod_thread::JoinHandle<()>, handle: jod_thread::JoinHandle,
} }
impl FlycheckHandle { impl FlycheckHandle {
pub fn spawn( pub fn spawn(
sender: Box<dyn Fn(CheckTask) + Send>, sender: Box<dyn Fn(Message) + Send>,
config: FlycheckConfig, config: FlycheckConfig,
workspace_root: PathBuf, workspace_root: PathBuf,
) -> FlycheckHandle { ) -> FlycheckHandle {
@ -74,7 +73,7 @@ impl FlycheckHandle {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum CheckTask { pub enum Message {
/// Request a clearing of all cached diagnostics from the check watcher /// Request a clearing of all cached diagnostics from the check watcher
ClearDiagnostics, ClearDiagnostics,
@ -82,23 +81,23 @@ pub enum CheckTask {
AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic },
/// Request check progress notification to client /// Request check progress notification to client
Status(Status), Progress(Progress),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Status { pub enum Progress {
Being, Being,
Progress(String), DidCheckCrate(String),
End, End,
} }
pub enum CheckCommand { enum CheckCommand {
/// Request re-start of check thread /// Request re-start of check thread
Update, Update,
} }
struct FlycheckActor { struct FlycheckActor {
sender: Box<dyn Fn(CheckTask) + Send>, sender: Box<dyn Fn(Message) + Send>,
config: FlycheckConfig, config: FlycheckConfig,
workspace_root: PathBuf, workspace_root: PathBuf,
last_update_req: Option<Instant>, last_update_req: Option<Instant>,
@ -109,12 +108,12 @@ struct FlycheckActor {
/// doesn't provide a way to read sub-process output without blocking, so we /// 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 /// have to wrap sub-processes output handling in a thread and pass messages
/// back over a channel. /// back over a channel.
check_process: Option<jod_thread::JoinHandle<()>>, check_process: Option<jod_thread::JoinHandle>,
} }
impl FlycheckActor { impl FlycheckActor {
fn new( fn new(
sender: Box<dyn Fn(CheckTask) + Send>, sender: Box<dyn Fn(Message) + Send>,
config: FlycheckConfig, config: FlycheckConfig,
workspace_root: PathBuf, workspace_root: PathBuf,
) -> FlycheckActor { ) -> FlycheckActor {
@ -154,15 +153,15 @@ impl FlycheckActor {
if self.should_recheck() { if self.should_recheck() {
self.last_update_req = None; self.last_update_req = None;
self.send(CheckTask::ClearDiagnostics); self.send(Message::ClearDiagnostics);
self.restart_check_process(); self.restart_check_process();
} }
} }
} }
fn clean_previous_results(&self) { fn clean_previous_results(&self) {
self.send(CheckTask::ClearDiagnostics); self.send(Message::ClearDiagnostics);
self.send(CheckTask::Status(Status::End)); self.send(Message::Progress(Progress::End));
} }
fn should_recheck(&mut self) -> bool { fn should_recheck(&mut self) -> bool {
@ -184,28 +183,28 @@ impl FlycheckActor {
fn handle_message(&self, msg: CheckEvent) { fn handle_message(&self, msg: CheckEvent) {
match msg { match msg {
CheckEvent::Begin => { CheckEvent::Begin => {
self.send(CheckTask::Status(Status::Being)); self.send(Message::Progress(Progress::Being));
} }
CheckEvent::End => { CheckEvent::End => {
self.send(CheckTask::Status(Status::End)); self.send(Message::Progress(Progress::End));
} }
CheckEvent::Msg(Message::CompilerArtifact(msg)) => { CheckEvent::Msg(cargo_metadata::Message::CompilerArtifact(msg)) => {
self.send(CheckTask::Status(Status::Progress(msg.target.name))); self.send(Message::Progress(Progress::DidCheckCrate(msg.target.name)));
} }
CheckEvent::Msg(Message::CompilerMessage(msg)) => { CheckEvent::Msg(cargo_metadata::Message::CompilerMessage(msg)) => {
self.send(CheckTask::AddDiagnostic { self.send(Message::AddDiagnostic {
workspace_root: self.workspace_root.clone(), workspace_root: self.workspace_root.clone(),
diagnostic: msg.message, diagnostic: msg.message,
}); });
} }
CheckEvent::Msg(Message::BuildScriptExecuted(_msg)) => {} CheckEvent::Msg(cargo_metadata::Message::BuildScriptExecuted(_))
CheckEvent::Msg(Message::BuildFinished(_)) => {} | CheckEvent::Msg(cargo_metadata::Message::BuildFinished(_))
CheckEvent::Msg(Message::TextLine(_)) => {} | CheckEvent::Msg(cargo_metadata::Message::TextLine(_))
CheckEvent::Msg(Message::Unknown) => {} | CheckEvent::Msg(cargo_metadata::Message::Unknown) => {}
} }
} }
@ -256,9 +255,11 @@ impl FlycheckActor {
let res = run_cargo(cmd, &mut |message| { let res = run_cargo(cmd, &mut |message| {
// Skip certain kinds of messages to only spend time on what's useful // Skip certain kinds of messages to only spend time on what's useful
match &message { match &message {
Message::CompilerArtifact(artifact) if artifact.fresh => return true, cargo_metadata::Message::CompilerArtifact(artifact) if artifact.fresh => {
Message::BuildScriptExecuted(_) => return true, return true
Message::Unknown => 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) (self.sender)(check_task)
} }
} }

View file

@ -6,7 +6,7 @@
use std::{convert::TryFrom, sync::Arc}; use std::{convert::TryFrom, sync::Arc};
use crossbeam_channel::{unbounded, Receiver}; use crossbeam_channel::{unbounded, Receiver};
use flycheck::{CheckTask, FlycheckConfig, FlycheckHandle}; use flycheck::{FlycheckConfig, FlycheckHandle};
use lsp_types::Url; use lsp_types::Url;
use parking_lot::RwLock; use parking_lot::RwLock;
use ra_db::{CrateId, SourceRoot, VfsPath}; use ra_db::{CrateId, SourceRoot, VfsPath};
@ -30,7 +30,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
fn create_flycheck( fn create_flycheck(
workspaces: &[ProjectWorkspace], workspaces: &[ProjectWorkspace],
config: &FlycheckConfig, config: &FlycheckConfig,
) -> Option<(FlycheckHandle, Receiver<CheckTask>)> { ) -> Option<(FlycheckHandle, Receiver<flycheck::Message>)> {
// FIXME: Figure out the multi-workspace situation // FIXME: Figure out the multi-workspace situation
workspaces.iter().find_map(move |w| match w { workspaces.iter().find_map(move |w| match w {
ProjectWorkspace::Cargo { cargo, .. } => { ProjectWorkspace::Cargo { cargo, .. } => {
@ -69,7 +69,7 @@ pub(crate) struct GlobalState {
pub(crate) analysis_host: AnalysisHost, pub(crate) analysis_host: AnalysisHost,
pub(crate) loader: Box<dyn vfs::loader::Handle>, pub(crate) loader: Box<dyn vfs::loader::Handle>,
pub(crate) task_receiver: Receiver<vfs::loader::Message>, pub(crate) task_receiver: Receiver<vfs::loader::Message>,
pub(crate) flycheck: Option<(FlycheckHandle, Receiver<CheckTask>)>, pub(crate) flycheck: Option<(FlycheckHandle, Receiver<flycheck::Message>)>,
pub(crate) diagnostics: DiagnosticCollection, pub(crate) diagnostics: DiagnosticCollection,
pub(crate) mem_docs: FxHashSet<VfsPath>, pub(crate) mem_docs: FxHashSet<VfsPath>,
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,

View file

@ -9,7 +9,6 @@ use std::{
}; };
use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
use flycheck::CheckTask;
use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
use lsp_types::{request::Request as _, NumberOrString, TextDocumentContentChangeEvent}; use lsp_types::{request::Request as _, NumberOrString, TextDocumentContentChangeEvent};
use ra_db::VfsPath; use ra_db::VfsPath;
@ -176,7 +175,7 @@ enum Event {
Msg(Message), Msg(Message),
Task(Task), Task(Task),
Vfs(vfs::loader::Message), Vfs(vfs::loader::Message),
CheckWatcher(CheckTask), CheckWatcher(flycheck::Message),
} }
impl fmt::Debug for Event { impl fmt::Debug for Event {
@ -250,14 +249,14 @@ fn loop_turn(
} }
vfs::loader::Message::Progress { n_total, n_done } => { vfs::loader::Message::Progress { n_total, n_done } => {
let state = if n_done == 0 { let state = if n_done == 0 {
ProgressState::Start Progress::Begin
} else if n_done < n_total { } else if n_done < n_total {
ProgressState::Report Progress::Report
} else { } else {
assert_eq!(n_done, n_total); assert_eq!(n_done, n_total);
global_state.status = Status::Ready; global_state.status = Status::Ready;
became_ready = true; became_ready = true;
ProgressState::End Progress::End
}; };
report_progress( report_progress(
global_state, global_state,
@ -593,17 +592,17 @@ fn apply_document_changes(
} }
fn on_check_task( fn on_check_task(
task: CheckTask, task: flycheck::Message,
global_state: &mut GlobalState, global_state: &mut GlobalState,
task_sender: &Sender<Task>, task_sender: &Sender<Task>,
msg_sender: &Sender<Message>, msg_sender: &Sender<Message>,
) -> Result<()> { ) -> Result<()> {
match task { match task {
CheckTask::ClearDiagnostics => { flycheck::Message::ClearDiagnostics => {
task_sender.send(Task::Diagnostic(DiagnosticTask::ClearCheck))?; 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( let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
&global_state.config.diagnostics, &global_state.config.diagnostics,
&diagnostic, &diagnostic,
@ -627,11 +626,11 @@ fn on_check_task(
} }
} }
CheckTask::Status(status) => { flycheck::Message::Progress(status) => {
let (state, message) = match status { let (state, message) = match status {
flycheck::Status::Being => (ProgressState::Start, None), flycheck::Progress::Being => (Progress::Begin, None),
flycheck::Status::Progress(target) => (ProgressState::Report, Some(target)), flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)),
flycheck::Status::End => (ProgressState::End, None), flycheck::Progress::End => (Progress::End, None),
}; };
report_progress(global_state, msg_sender, "cargo check", state, message, 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<Message>, state:
} }
#[derive(Eq, PartialEq)] #[derive(Eq, PartialEq)]
enum ProgressState { enum Progress {
Start, Begin,
Report, Report,
End, End,
} }
@ -668,7 +667,7 @@ fn report_progress(
global_state: &mut GlobalState, global_state: &mut GlobalState,
sender: &Sender<Message>, sender: &Sender<Message>,
title: &str, title: &str,
state: ProgressState, state: Progress,
message: Option<String>, message: Option<String>,
percentage: Option<f64>, percentage: Option<f64>,
) { ) {
@ -677,7 +676,7 @@ fn report_progress(
} }
let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title)); let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
let work_done_progress = match state { let work_done_progress = match state {
ProgressState::Start => { Progress::Begin => {
let work_done_progress_create = global_state.req_queue.outgoing.register( let work_done_progress_create = global_state.req_queue.outgoing.register(
lsp_types::request::WorkDoneProgressCreate::METHOD.to_string(), lsp_types::request::WorkDoneProgressCreate::METHOD.to_string(),
lsp_types::WorkDoneProgressCreateParams { token: token.clone() }, lsp_types::WorkDoneProgressCreateParams { token: token.clone() },
@ -692,14 +691,14 @@ fn report_progress(
percentage, percentage,
}) })
} }
ProgressState::Report => { Progress::Report => {
lsp_types::WorkDoneProgress::Report(lsp_types::WorkDoneProgressReport { lsp_types::WorkDoneProgress::Report(lsp_types::WorkDoneProgressReport {
cancellable: None, cancellable: None,
message, message,
percentage, percentage,
}) })
} }
ProgressState::End => { Progress::End => {
lsp_types::WorkDoneProgress::End(lsp_types::WorkDoneProgressEnd { message }) lsp_types::WorkDoneProgress::End(lsp_types::WorkDoneProgressEnd { message })
} }
}; };