Skip to content

Commit 01d4536

Browse files
authored
Merge f45f478 into 779e013
2 parents 779e013 + f45f478 commit 01d4536

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
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)

tooling/nargo_cli/src/cli/lsp_cmd.rs

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub(crate) fn run(_args: LspCommand, _config: NargoConfig) -> Result<(), CliErro
3535
.service(router)
3636
});
3737

38-
eprintln!("LSP starting...");
39-
4038
// Prefer truly asynchronous piped stdin/stdout without blocking tasks.
4139
#[cfg(unix)]
4240
let (stdin, stdout) = (

0 commit comments

Comments
 (0)