Skip to content

Commit 7f9e749

Browse files
authored
ban println to prevent lsp crashes, since it uses stdio to communicate (#2659)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Enforces no-stdout across the workspace (Clippy + stderr), updates LSP capabilities, and includes minor refactors and tooling tweaks. > > - **Lint/CI**: > - Enforce `clippy::print_stdout` across the workspace in CI (`cargo clippy --workspace -- -D clippy::print_stdout`). > - Add `#![deny(clippy::print_stdout)]` to `engine/language_server`. > - **Stdout → Stderr changes**: > - Replace `println!` with `eprintln!` in numerous modules (compiler lowering, runtimes, VM debug, CLI tools, tracing publisher, language clients) to avoid polluting stdio. > - Add targeted `#[allow(clippy::print_stdout)]` on intentional user-facing stdout paths (CLI outputs, REPL, formatter, test renderer, auth, etc.). > - **Language Server**: > - Disable `codeActionProvider` and `documentFormattingProvider` (set to `None`). > - Misc logging tweaks and startup messages moved to stderr. > - **Tools/Dev UX**: > - Hot-reload utility: replay stdin without holding locks across awaits; simplify child status polling. > - Playground: minor type signature cleanups (`&'static str` → `&str`). > - **Core/Lib changes**: > - Rename `LLMProvider::from_str` to `try_from_str`. > - Minor log message punctuation and additional allowances. > - **Env/Tooling**: > - Update `mise.toml` (add cargo ripgrep, node/python tool notes and settings). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit abb4a01. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 12e3825 commit 7f9e749

35 files changed

Lines changed: 85 additions & 68 deletions

File tree

‎.github/workflows/primary.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686

8787
- name: Run Rust lint (Clippy)
8888
if: matrix.check == 'rust-lint'
89-
run: RUSTFLAGS="-A unused -D warnings" cargo clippy
89+
run: RUSTFLAGS="-A unused -D warnings" cargo clippy --workspace -- -D clippy::print_stdout
9090
working-directory: engine
9191

9292
- name: Run Rust lint WASM (Clippy)

‎engine/baml-compiler/src/hir/lowering.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl Block {
414414
.map(Box::new);
415415

416416
if !block.expr_headers.is_empty() {
417-
println!(
417+
eprintln!(
418418
"Annotated!: {}",
419419
trailing_expr
420420
.as_ref()
@@ -446,7 +446,7 @@ fn maybe_annotated_statement(
446446
if annotated_comments.is_empty() {
447447
stmt
448448
} else {
449-
println!("Annotated!: {}", stmt.to_doc().pretty(80));
449+
eprintln!("Annotated!: {}", stmt.to_doc().pretty(80));
450450
Statement::AnnotatedStatement {
451451
headers: annotated_comments
452452
.iter()

‎engine/baml-lib/baml-log/src/logger.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ impl ConfigSetting<Level> for LogLevel {
468468
}
469469
}
470470

471+
#[allow(clippy::print_stdout)]
471472
fn set(value: Level) -> Result<(), LogError> {
472473
match CONFIG.write() {
473474
Ok(mut config) => {

‎engine/baml-lib/llm-client/src/clients/helpers.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
7272
}
7373

7474
pub fn print_options(&self) {
75-
println!(
75+
eprintln!(
7676
"options: {:#?}",
7777
self.options
7878
.iter()

‎engine/baml-runtime/src/async_interpreter_runtime.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl BamlAsyncInterpreterRuntime {
102102
.iter()
103103
.find(|f| f.name == function_name)
104104
{
105-
println!("THIR for expression function '{function_name}':");
106-
println!("{}", expr_fn.body.dump_str());
105+
eprintln!("THIR for expression function '{function_name}':");
106+
eprintln!("{}", expr_fn.body.dump_str());
107107
} else {
108-
println!("Function '{function_name}' not found or is not an expression function");
108+
eprintln!("Function '{function_name}' not found or is not an expression function");
109109
}
110110
}
111111

‎engine/baml-runtime/src/async_vm_runtime.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ impl BamlAsyncVmRuntime {
9292
.get(function_name)
9393
.map(|(index, _)| *index)
9494
else {
95-
return println!("function not found: {function_name}");
95+
return eprintln!("function not found: {function_name}");
9696
};
9797

9898
let baml_vm::Object::Function(function) = &self.program.objects[index] else {
99-
return println!("not a function: {function_name}");
99+
return eprintln!("not a function: {function_name}");
100100
};
101101

102102
baml_vm::debug::disassemble(

‎engine/baml-runtime/src/cli/check.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl CheckArgs {
4040
Ok(())
4141
}
4242

43+
#[allow(clippy::print_stdout)]
4344
fn check(
4445
&self,
4546
defaults: super::RuntimeCliDefaults,

‎engine/baml-runtime/src/cli/dump_intermediate.rs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ impl DumpIntermediateArgs {
3333

3434
match dump_type {
3535
DumpType::HIR => {
36-
println!("=== HIGH-LEVEL INTERMEDIATE REPRESENTATION (HIR) ===");
37-
println!("Source directory: {:?}", self.from);
38-
println!();
36+
eprintln!("=== HIGH-LEVEL INTERMEDIATE REPRESENTATION (HIR) ===");
37+
eprintln!("Source directory: {:?}", self.from);
38+
eprintln!();
3939

4040
self.dump_hir(&validated_schema)?;
4141
}
4242
DumpType::Bytecode => {
43-
println!("=== BYTECODE ===");
44-
println!("Source directory: {:?}", self.from);
45-
println!();
43+
eprintln!("=== BYTECODE ===");
44+
eprintln!("Source directory: {:?}", self.from);
45+
eprintln!();
4646

4747
self.dump_bytecode(&validated_schema)?;
4848
}
@@ -98,7 +98,7 @@ impl DumpIntermediateArgs {
9898
hir.to_doc()
9999
.render(78, &mut w)
100100
.expect("Rendering should succeed");
101-
println!(
101+
eprintln!(
102102
"{}",
103103
String::from_utf8(w).expect("UTF-8 conversion should succeed")
104104
);
@@ -117,8 +117,8 @@ impl DumpIntermediateArgs {
117117
if baml_compiler::builtin::is_builtin_identifier(&f.name) {
118118
continue;
119119
}
120-
println!("{}", f.name);
121-
println!(
120+
eprintln!("{}", f.name);
121+
eprintln!(
122122
"{}",
123123
baml_vm::debug::display_bytecode(
124124
f,
@@ -131,12 +131,12 @@ impl DumpIntermediateArgs {
131131
}
132132
Object::Class(c) => {
133133
if !baml_compiler::builtin::is_builtin_class(&c.name) {
134-
println!("Class: {} with {} fields", c.name, c.field_names.len());
134+
eprintln!("Class: {} with {} fields", c.name, c.field_names.len());
135135
}
136136
}
137137
Object::Enum(e) => {
138138
if !baml_compiler::builtin::is_builtin_enum(&e.name) {
139-
println!("Enum {}", e.name);
139+
eprintln!("Enum {}", e.name);
140140
}
141141
}
142142
_ => {

‎engine/baml-runtime/src/cli/init_ui.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ impl InitUIContext {
285285
}
286286
}
287287

288+
#[allow(clippy::print_stdout)]
288289
pub fn finish(self) -> Result<()> {
289290
if let Some(ui) = self.ui {
290291
// Show final state for a moment

‎engine/baml-runtime/src/cli/repl.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl ReplState {
256256
}
257257
}
258258

259+
#[allow(clippy::print_stdout)]
259260
fn load_baml_sources(&mut self, path: PathBuf) -> Result<()> {
260261
let runtime =
261262
BamlRuntime::from_directory(&path, self.env_vars.clone(), Default::default()).context(
@@ -395,6 +396,7 @@ impl ReplState {
395396
Ok(output)
396397
}
397398

399+
#[allow(clippy::print_stdout)]
398400
fn reset(&mut self) {
399401
self.variables.clear();
400402
println!("✓ Reset interpreter environment");
@@ -842,6 +844,7 @@ impl ReplState {
842844
}
843845

844846
impl ReplArgs {
847+
#[allow(clippy::print_stdout)]
845848
pub async fn run(&self) -> Result<()> {
846849
// Suppress logging while TUI is active so logs don't corrupt the UI
847850
let _ = baml_log::set_log_level(baml_log::Level::Off);
@@ -1629,6 +1632,7 @@ impl ReplArgs {
16291632
Ok(())
16301633
}
16311634

1635+
#[allow(clippy::print_stdout)]
16321636
fn handle_command(&self, state: &mut ReplState, input: &str) -> Result<Option<String>> {
16331637
let parts: Vec<&str> = input[1..].split_whitespace().collect();
16341638
if parts.is_empty() {

0 commit comments

Comments
 (0)