Skip to content

Commit 8fc1186

Browse files
fixup! feat(plugin): add async io for the plugin
1 parent a42bb4d commit 8fc1186

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

plugin/src/io.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ impl AsyncIO {
5555

5656
// Check if the buffer ends with double newline
5757
if buffer.ends_with("\n\n") {
58+
drop(reader);
5859
break; // Exit the loop
5960
}
6061
}
6162
let Some(resp) = async_callback(buffer.clone()) else {
6263
continue;
6364
};
64-
io::stdout().write_all(resp.as_bytes())?;
65-
io::stdout().flush()?;
65+
let mut writer = io::stdout().lock();
66+
writer.write_all(resp.as_bytes())?;
67+
writer.flush()?;
6668
}
6769
}
6870
_ => unreachable!(),

plugin/src/plugin.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ impl log::Log for Log {
6666

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

72-
let mut writer = io::stdout();
7373
let mut payload = init_payload();
7474
add_str(&mut payload, "level", &level.to_string());
7575
add_str(&mut payload, "message", &format!("{msg}"));
@@ -79,10 +79,8 @@ impl log::Log for Log {
7979
method: "log".to_owned(),
8080
params: payload,
8181
};
82-
writer
83-
.write_all(serde_json::to_string(&request).unwrap().as_bytes())
84-
.unwrap();
85-
writer.flush().unwrap();
82+
let _ = writer.write_all(serde_json::to_string(&request).unwrap().as_bytes());
83+
let _ = writer.flush();
8684
}
8785
}
8886

@@ -114,7 +112,7 @@ impl<'a, T: 'a + Clone> Plugin<T> {
114112
}
115113

116114
pub fn log(&self, level: LogLevel, msg: &str) {
117-
let mut writer = io::stdout();
115+
let mut writer = io::stdout().lock();
118116
let mut payload = init_payload();
119117
add_str(&mut payload, "level", &level.to_string());
120118
add_str(&mut payload, "message", msg);

0 commit comments

Comments
 (0)