Skip to content

Commit 4ca4627

Browse files
committed
fix: prevent comptime println crashing LSP
1 parent 34cb23f commit 4ca4627

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler/noirc_frontend/src/hir/comptime/interpreter.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,22 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
16531653
assert_eq!(arguments.len(), 2);
16541654

16551655
let print_newline = arguments[0].0 == Value::Bool(true);
1656-
if print_newline {
1657-
println!("{}", arguments[1].0.display(self.elaborator.interner));
1656+
let contents = arguments[1].0.display(self.elaborator.interner);
1657+
if self.elaborator.interner.is_in_lsp_mode() {
1658+
// If we `println!` in LSP it gets mixed with the protocol stream and leads to crashing
1659+
// the connection. If we use `eprintln!` not only it doesn't crash, but the output
1660+
// appears in the "Noir Language Server" output window in case you want to see it.
1661+
if print_newline {
1662+
eprintln!("{}", contents);
1663+
} else {
1664+
eprint!("{}", contents);
1665+
}
16581666
} else {
1659-
print!("{}", arguments[1].0.display(self.elaborator.interner));
1667+
if print_newline {
1668+
println!("{}", contents);
1669+
} else {
1670+
print!("{}", contents);
1671+
}
16601672
}
16611673

16621674
Ok(Value::Unit)

0 commit comments

Comments
 (0)