Skip to content

Commit f65cf99

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

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,20 @@ 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+
}
1666+
} else if print_newline {
1667+
println!("{}", contents);
16581668
} else {
1659-
print!("{}", arguments[1].0.display(self.elaborator.interner));
1669+
print!("{}", contents);
16601670
}
16611671

16621672
Ok(Value::Unit)

0 commit comments

Comments
 (0)