From c3ac6031f672d0d87bb5108b43209e8a86de115a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 26 Dec 2024 13:33:47 +0100 Subject: [PATCH] renames --- cli/tools/lint/linter.rs | 8 ++--- cli/tools/lint/plugins.rs | 71 ++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index f3abf2d984..18ea51fd32 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -25,7 +25,7 @@ use crate::util::fs::atomic_write_file_with_retries; use crate::util::fs::specifier_from_file_path; use super::plugins; -use super::plugins::PluginRunnerProxy; +use super::plugins::PluginHostProxy; use super::rules::FileOrPackageLintRule; use super::rules::PackageLintRule; use super::ConfiguredRules; @@ -34,7 +34,7 @@ pub struct CliLinterOptions { pub configured_rules: ConfiguredRules, pub fix: bool, pub deno_lint_config: DenoLintConfig, - pub maybe_plugin_runner: Option>>, + pub maybe_plugin_runner: Option>>, } #[derive(Debug)] @@ -43,7 +43,7 @@ pub struct CliLinter { package_rules: Vec>, linter: DenoLintLinter, deno_lint_config: DenoLintConfig, - maybe_plugin_runner: Option>>, + maybe_plugin_runner: Option>>, } impl CliLinter { @@ -306,7 +306,7 @@ fn apply_lint_fixes( } fn run_plugins( - plugin_runner: Arc>, + plugin_runner: Arc>, parsed_source: ParsedSource, file_path: PathBuf, ) -> Result, AnyError> { diff --git a/cli/tools/lint/plugins.rs b/cli/tools/lint/plugins.rs index c3e6182ac5..31ad65f5fd 100644 --- a/cli/tools/lint/plugins.rs +++ b/cli/tools/lint/plugins.rs @@ -31,17 +31,17 @@ use crate::ops::lint::LintPluginContainer; use crate::tools::lint::serialize_ast_to_buffer; #[derive(Debug)] -pub enum PluginRunnerRequest { +pub enum PluginHostRequest { LoadPlugins(Vec), Run(Vec, PathBuf, SourceTextInfo), } -pub enum PluginRunnerResponse { +pub enum PluginHostResponse { LoadPlugin(Result<(), AnyError>), Run(Result, AnyError>), } -impl std::fmt::Debug for PluginRunnerResponse { +impl std::fmt::Debug for PluginHostResponse { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::LoadPlugin(_arg0) => f.debug_tuple("LoadPlugin").finish(), @@ -96,28 +96,28 @@ v8_static_strings! { } #[derive(Debug)] -pub struct PluginRunnerProxy { - tx: Sender, - rx: Arc>>, +pub struct PluginHostProxy { + tx: Sender, + rx: Arc>>, #[allow(unused)] join_handle: std::thread::JoinHandle>, logger: PluginLogger, } -pub struct PluginRunner { +pub struct PluginHost { worker: MainWorker, install_plugin_fn: Rc>, run_plugins_for_file_fn: Rc>, - tx: Sender, - rx: Receiver, + tx: Sender, + rx: Receiver, logger: PluginLogger, } async fn create_plugin_runner_inner( logger: PluginLogger, - rx_req: Receiver, - tx_res: Sender, -) -> Result { + rx_req: Receiver, + tx_res: Sender, +) -> Result { let flags = Flags { subcommand: DenoSubcommand::Lint(LintFlags::default()), ..Default::default() @@ -183,7 +183,7 @@ async fn create_plugin_runner_inner( ) }; - Ok(PluginRunner { + Ok(PluginHost { worker, install_plugin_fn, run_plugins_for_file_fn, @@ -193,8 +193,8 @@ async fn create_plugin_runner_inner( }) } -impl PluginRunner { - fn create(logger: PluginLogger) -> Result { +impl PluginHost { + fn create(logger: PluginLogger) -> Result { let (tx_req, rx_req) = channel(10); let (tx_res, rx_res) = channel(10); @@ -202,7 +202,7 @@ impl PluginRunner { let logger_ = logger.clone(); let join_handle = std::thread::spawn(move || { let logger = logger_; - logger.log("PluginRunner thread spawned"); + logger.log("PluginHost thread spawned"); let start = std::time::Instant::now(); let fut = async move { let runner = @@ -211,7 +211,7 @@ impl PluginRunner { logger.log("running host loop"); runner.run_loop().await?; logger.log(&format!( - "PluginRunner thread finished, took {:?}", + "PluginHost thread finished, took {:?}", std::time::Instant::now() - start )); Ok(()) @@ -221,7 +221,7 @@ impl PluginRunner { }); logger.log(&format!("is thread finished {}", join_handle.is_finished())); - let proxy = PluginRunnerProxy { + let proxy = PluginHostProxy { tx: tx_req, rx: Arc::new(tokio::sync::Mutex::new(rx_res)), join_handle, @@ -236,15 +236,11 @@ impl PluginRunner { while let Some(req) = self.rx.recv().await { self.logger.log("received message"); match req { - PluginRunnerRequest::LoadPlugins(specifiers) => { + PluginHostRequest::LoadPlugins(specifiers) => { let r = self.load_plugins(specifiers).await; - let _ = self.tx.send(PluginRunnerResponse::LoadPlugin(r)).await; + let _ = self.tx.send(PluginHostResponse::LoadPlugin(r)).await; } - PluginRunnerRequest::Run( - serialized_ast, - specifier, - source_text_info, - ) => { + PluginHostRequest::Run(serialized_ast, specifier, source_text_info) => { let start = std::time::Instant::now(); let r = match self .run_plugins(&specifier, serialized_ast, source_text_info) @@ -257,7 +253,7 @@ impl PluginRunner { "Running rules took {:?}", std::time::Instant::now() - start )); - let _ = self.tx.send(PluginRunnerResponse::Run(r)).await; + let _ = self.tx.send(PluginHostResponse::Run(r)).await; } } } @@ -370,19 +366,19 @@ impl PluginRunner { } } -impl PluginRunnerProxy { +impl PluginHostProxy { pub async fn load_plugins( &self, plugin_specifiers: Vec, ) -> Result<(), AnyError> { self .tx - .send(PluginRunnerRequest::LoadPlugins(plugin_specifiers)) + .send(PluginHostRequest::LoadPlugins(plugin_specifiers)) .await?; let mut rx = self.rx.lock().await; self.logger.log("receiving load plugins"); if let Some(val) = rx.recv().await { - let PluginRunnerResponse::LoadPlugin(result) = val else { + let PluginHostResponse::LoadPlugin(result) = val else { unreachable!() }; self @@ -401,7 +397,7 @@ impl PluginRunnerProxy { ) -> Result, AnyError> { self .tx - .send(PluginRunnerRequest::Run( + .send(PluginHostRequest::Run( serialized_ast, specifier.to_path_buf(), source_text_info, @@ -409,8 +405,7 @@ impl PluginRunnerProxy { .await?; let mut rx = self.rx.lock().await; self.logger.log("receiving diagnostics"); - if let Some(PluginRunnerResponse::Run(diagnostics_result)) = rx.recv().await - { + if let Some(PluginHostResponse::Run(diagnostics_result)) = rx.recv().await { return diagnostics_result; } Err(custom_error("AlreadyClosed", "Plugin host has closed")) @@ -433,19 +428,19 @@ impl PluginRunnerProxy { pub async fn create_runner_and_load_plugins( plugin_specifiers: Vec, logger: PluginLogger, -) -> Result { - let runner_proxy = PluginRunner::create(logger)?; - runner_proxy.load_plugins(plugin_specifiers).await?; - Ok(runner_proxy) +) -> Result { + let host_proxy = PluginHost::create(logger)?; + host_proxy.load_plugins(plugin_specifiers).await?; + Ok(host_proxy) } pub async fn run_rules_for_ast( - runner_proxy: &mut PluginRunnerProxy, + host_proxy: &mut PluginHostProxy, specifier: &Path, serialized_ast: Vec, source_text_info: SourceTextInfo, ) -> Result, AnyError> { - let d = runner_proxy + let d = host_proxy .run_rules(specifier, serialized_ast, source_text_info) .await?; Ok(d)