From 6fe92b9e8effe44728409aa2f70a00a5ed7cae1e Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 20 Apr 2023 04:26:59 +0200 Subject: [PATCH] chore: better logging of workers stopping --- src/client/nvim/main.rs | 9 ++++++--- src/lib/client.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/client/nvim/main.rs b/src/client/nvim/main.rs index 4043fc1..58b5d12 100644 --- a/src/client/nvim/main.rs +++ b/src/client/nvim/main.rs @@ -147,7 +147,7 @@ impl Handler for NeovimHandler { Ok(()) => { tokio::spawn(async move { loop { - if !_controller.run() { break } + if !_controller.run() { break debug!("buffer updater clean exit") } let _span = _controller.wait().await; // TODO only change lines affected! let lines : Vec = _controller.content().split("\n").map(|x| x.to_string()).collect(); @@ -199,9 +199,9 @@ impl Handler for NeovimHandler { debug!("spawning cursor processing worker"); tokio::spawn(async move { loop { - if !controller.run() { break } + if !controller.run() { break debug!("cursor worker clean exit") } match sub.recv().await { - Err(e) => return error!("error receiving cursor update from controller: {}", e), + Err(e) => break error!("error receiving cursor update from controller: {}", e), Ok((_usr, cur)) => { if let Err(e) = buf.clear_namespace(ns, 0, -1).await { error!("could not clear previous cursor highlight: {}", e); @@ -212,6 +212,9 @@ impl Handler for NeovimHandler { } } } + if let Err(e) = buf.clear_namespace(ns, 0, -1).await { + error!("could not clear previous cursor highlight: {}", e); + } }); Ok(Value::Nil) }, diff --git a/src/lib/client.rs b/src/lib/client.rs index 53e79e1..1ad72f0 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use operational_transform::OperationSeq; use tonic::{transport::Channel, Status}; -use tracing::{error, warn, info}; +use tracing::{error, warn, debug}; use uuid::Uuid; use crate::{ @@ -51,7 +51,7 @@ impl CodempClient { loop { match stream.message().await { Err(e) => break error!("error receiving cursor: {}", e), - Ok(None) => break, + Ok(None) => break debug!("cursor worker clean exit"), Ok(Some(x)) => { _controller.update(x); }, } } @@ -77,12 +77,13 @@ impl CodempClient { let factory = Arc::new(OperationController::new(content.unwrap_or("".into()))); let _factory = factory.clone(); + let _path = path.clone(); tokio::spawn(async move { loop { - if !_factory.run() { break } + if !_factory.run() { break debug!("downstream worker clean exit") } match stream.message().await { Err(e) => break error!("error receiving update: {}", e), - Ok(None) => break, // clean exit + Ok(None) => break warn!("stream closed for buffer {}", _path), Ok(Some(x)) => match serde_json::from_str::(&x.opseq) { Err(e) => error!("error deserializing opseq: {}", e), Ok(v) => match _factory.process(v).await { @@ -118,6 +119,7 @@ impl CodempClient { Err(e) => error!("could not send edit: {}", e), } } + debug!("upstream worker clean exit"); }); Ok(factory)