camel_cli/commands/lsp.rs
1//! `camel lsp` — start the LSP server over stdio.
2//!
3//! Builds the production lint engine, constructs a tower-lsp `LspService` backed
4//! by [`camel_lsp::Backend`], and runs the server on stdin/stdout.
5
6/// Start the LSP server over stdio.
7///
8/// Returns the exit code: 0 on clean shutdown, 2 on engine init failure.
9pub async fn run() -> i32 {
10 let engine = match crate::commands::lint::production_engine().await {
11 Ok(engine) => engine,
12 Err(e) => {
13 eprintln!("error: {e}");
14 return 2;
15 }
16 };
17 let (service, socket) =
18 tower_lsp::LspService::new(move |client| camel_lsp::Backend::new(client, engine));
19 let stdin = tokio::io::stdin();
20 let stdout = tokio::io::stdout();
21 tower_lsp::Server::new(stdin, stdout, socket)
22 .serve(service)
23 .await;
24 0
25}