Skip to content

Commit

Permalink
fixup! feat(plugin): add async io for the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo committed Mar 24, 2024
1 parent a42bb4d commit 8fc1186
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 4 additions & 2 deletions plugin/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ impl AsyncIO {

// Check if the buffer ends with double newline
if buffer.ends_with("\n\n") {
drop(reader);
break; // Exit the loop
}
}
let Some(resp) = async_callback(buffer.clone()) else {
continue;
};
io::stdout().write_all(resp.as_bytes())?;
io::stdout().flush()?;
let mut writer = io::stdout().lock();
writer.write_all(resp.as_bytes())?;
writer.flush()?;
}
}
_ => unreachable!(),
Expand Down
10 changes: 4 additions & 6 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ impl log::Log for Log {

fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let mut writer = io::stdout().lock();
let level: LogLevel = record.level().into();
let msg = record.args();

let mut writer = io::stdout();
let mut payload = init_payload();
add_str(&mut payload, "level", &level.to_string());
add_str(&mut payload, "message", &format!("{msg}"));
Expand All @@ -79,10 +79,8 @@ impl log::Log for Log {
method: "log".to_owned(),
params: payload,
};
writer
.write_all(serde_json::to_string(&request).unwrap().as_bytes())
.unwrap();
writer.flush().unwrap();
let _ = writer.write_all(serde_json::to_string(&request).unwrap().as_bytes());

Check failure on line 82 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on a `Result` value

error: used `unwrap()` on a `Result` value --> plugin/src/plugin.rs:82:38 | 82 | let _ = writer.write_all(serde_json::to_string(&request).unwrap().as_bytes()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if this value is an `Err`, it will panic = help: consider using `expect()` to provide a better panic message = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
let _ = writer.flush();
}
}

Expand Down Expand Up @@ -114,7 +112,7 @@ impl<'a, T: 'a + Clone> Plugin<T> {
}

pub fn log(&self, level: LogLevel, msg: &str) {
let mut writer = io::stdout();
let mut writer = io::stdout().lock();
let mut payload = init_payload();
add_str(&mut payload, "level", &level.to_string());
add_str(&mut payload, "message", msg);
Expand Down

0 comments on commit 8fc1186

Please sign in to comment.