Skip to content

Commit 5cfeac9

Browse files
committed
add write_discovery function
1 parent e23c61b commit 5cfeac9

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

tools/rust_analyzer/bin/discover_rust_project.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,20 @@ fn project_discovery() -> anyhow::Result<DiscoverProject<'static>> {
8282
Ok(DiscoverProject::Finished { buildfile, project })
8383
}
8484

85+
fn write_discovery<W>(mut writer: W, discovery: DiscoverProject) -> std::io::Result<()>
86+
where
87+
W: Write,
88+
{
89+
serde_json::to_writer(&mut writer, &discovery)?;
90+
// `rust-analyzer` reads messages line by line, so we must add a newline after each
91+
writeln!(writer, "")
92+
}
93+
8594
fn main() -> anyhow::Result<()> {
8695
let log_format_fn = |fmt: &mut Formatter, rec: &Record| {
8796
let message = rec.args();
8897
let discovery = DiscoverProject::Progress { message };
89-
serde_json::to_writer(&mut *fmt, &discovery)?;
90-
// `rust-analyzer` reads messages line by line
91-
writeln!(fmt, "");
92-
Ok(())
98+
write_discovery(fmt, discovery)
9399
};
94100

95101
// Treat logs as progress messages.
@@ -111,10 +117,7 @@ fn main() -> anyhow::Result<()> {
111117
},
112118
};
113119

114-
serde_json::to_writer(io::stdout(), &discovery)?;
115-
// `rust-analyzer` reads messages line by line
116-
println!("");
117-
120+
write_discovery(io::stdout(), discovery)?;
118121
Ok(())
119122
}
120123

0 commit comments

Comments
 (0)