0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-09 05:36:49 -04:00

fix printer

This commit is contained in:
Bartek Iwańczuk 2025-01-10 02:00:55 +01:00
parent 31473ca292
commit ebaf18e8ef
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 19 additions and 19 deletions

View file

@ -313,11 +313,10 @@ impl WorkspaceLinter {
#[allow(clippy::print_stdout)] #[allow(clippy::print_stdout)]
#[allow(clippy::print_stderr)] #[allow(clippy::print_stderr)]
fn logger_printer(msg: &str, is_err: bool) { fn logger_printer(msg: &str, is_err: bool) {
// TODO(bartlomieju): fix newlines
if is_err { if is_err {
eprintln!("{}", msg); eprint!("{}", msg);
} else { } else {
println!("{}", msg); print!("{}", msg);
} }
} }

View file

@ -86,6 +86,7 @@ impl PluginLogger {
pub fn debug(&self, msg: &str) { pub fn debug(&self, msg: &str) {
if self.debug { if self.debug {
(self.print)(msg, false); (self.print)(msg, false);
(self.print)("\n", false);
} }
} }
} }
@ -181,11 +182,11 @@ async fn create_plugin_runner_inner(
let mut worker = worker.into_main_worker(); let mut worker = worker.into_main_worker();
let runtime = &mut worker.js_runtime; let runtime = &mut worker.js_runtime;
logger.log("before loaded"); logger.debug("before loaded");
let obj = runtime.execute_script("lint.js", "Deno[Deno.internal]")?; let obj = runtime.execute_script("lint.js", "Deno[Deno.internal]")?;
logger.log("After plugin loaded, capturing exports"); logger.debug("After plugin loaded, capturing exports");
let (install_plugins_fn, run_plugins_for_file_fn) = { let (install_plugins_fn, run_plugins_for_file_fn) = {
let scope = &mut runtime.handle_scope(); let scope = &mut runtime.handle_scope();
let module_exports: v8::Local<v8::Object> = let module_exports: v8::Local<v8::Object> =
@ -246,19 +247,19 @@ impl PluginHost {
let (tx_req, rx_req) = channel(10); let (tx_req, rx_req) = channel(10);
let (tx_res, rx_res) = channel(10); let (tx_res, rx_res) = channel(10);
logger.log("spawning thread"); logger.debug("spawning thread");
let logger_ = logger.clone(); let logger_ = logger.clone();
let join_handle = std::thread::spawn(move || { let join_handle = std::thread::spawn(move || {
let logger = logger_; let logger = logger_;
logger.log("PluginHost thread spawned"); logger.debug("PluginHost thread spawned");
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let fut = async move { let fut = async move {
let runner = let runner =
create_plugin_runner_inner(logger.clone(), rx_req, tx_res).await?; create_plugin_runner_inner(logger.clone(), rx_req, tx_res).await?;
// TODO(bartlomieju): send "host ready" message to the proxy // TODO(bartlomieju): send "host ready" message to the proxy
logger.log("running host loop"); logger.debug("running host loop");
runner.run_loop().await?; runner.run_loop().await?;
logger.log(&format!( logger.debug(&format!(
"PluginHost thread finished, took {:?}", "PluginHost thread finished, took {:?}",
std::time::Instant::now() - start std::time::Instant::now() - start
)); ));
@ -268,7 +269,7 @@ impl PluginHost {
tokio_util::create_and_run_current_thread(fut) tokio_util::create_and_run_current_thread(fut)
}); });
logger.log(&format!("is thread finished {}", join_handle.is_finished())); logger.debug(&format!("is thread finished {}", join_handle.is_finished()));
let proxy = PluginHostProxy { let proxy = PluginHostProxy {
tx: tx_req, tx: tx_req,
rx: Arc::new(tokio::sync::Mutex::new(rx_res)), rx: Arc::new(tokio::sync::Mutex::new(rx_res)),
@ -281,9 +282,9 @@ impl PluginHost {
} }
async fn run_loop(mut self) -> Result<(), AnyError> { async fn run_loop(mut self) -> Result<(), AnyError> {
self.logger.log("waiting for message"); self.logger.debug("waiting for message");
while let Some(req) = self.rx.recv().await { while let Some(req) = self.rx.recv().await {
self.logger.log("received message"); self.logger.debug("received message");
match req { match req {
PluginHostRequest::LoadPlugins { PluginHostRequest::LoadPlugins {
specifiers, specifiers,
@ -311,7 +312,7 @@ impl PluginHost {
Ok(()) => Ok(self.take_diagnostics()), Ok(()) => Ok(self.take_diagnostics()),
Err(err) => Err(err), Err(err) => Err(err),
}; };
self.logger.log(&format!( self.logger.debug(&format!(
"Running rules took {:?}", "Running rules took {:?}",
std::time::Instant::now() - start std::time::Instant::now() - start
)); ));
@ -319,7 +320,7 @@ impl PluginHost {
} }
} }
} }
self.logger.log("breaking loop"); self.logger.debug("breaking loop");
Ok(()) Ok(())
} }
@ -374,13 +375,13 @@ impl PluginHost {
if let Some(exception) = tc_scope.exception() { if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(&mut tc_scope, exception); let error = JsError::from_v8_exception(&mut tc_scope, exception);
self.logger.log("error running plugins"); self.logger.debug("error running plugins");
let core_err = CoreError::Js(error); let core_err = CoreError::Js(error);
return Err(core_err.into()); return Err(core_err.into());
} }
drop(tc_scope); drop(tc_scope);
self.logger.log("plugins finished"); self.logger.debug("plugins finished");
Ok(()) Ok(())
} }
@ -448,7 +449,7 @@ impl PluginHost {
}; };
let args = &[local_handles.into(), exclude_v8]; let args = &[local_handles.into(), exclude_v8];
self.logger.log("Installing plugins..."); self.logger.debug("Installing plugins...");
let mut tc_scope = v8::TryCatch::new(scope); let mut tc_scope = v8::TryCatch::new(scope);
let plugins_info_result = let plugins_info_result =
@ -483,7 +484,7 @@ impl PluginHostProxy {
}) })
.await?; .await?;
let mut rx = self.rx.lock().await; let mut rx = self.rx.lock().await;
self.logger.log("receiving load plugins"); self.logger.debug("receiving load plugins");
if let Some(val) = rx.recv().await { if let Some(val) = rx.recv().await {
let PluginHostResponse::LoadPlugin(result) = val else { let PluginHostResponse::LoadPlugin(result) = val else {
unreachable!() unreachable!()
@ -515,7 +516,7 @@ impl PluginHostProxy {
}) })
.await?; .await?;
let mut rx = self.rx.lock().await; let mut rx = self.rx.lock().await;
self.logger.log("receiving diagnostics"); self.logger.debug("receiving diagnostics");
if let Some(PluginHostResponse::Run(diagnostics_result)) = rx.recv().await { if let Some(PluginHostResponse::Run(diagnostics_result)) = rx.recv().await {
return diagnostics_result; return diagnostics_result;
} }