1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Handler for the `server` command.
use colored::*;
use rumdl_lib::exit_codes::exit;
/// Handle the server command: start the LSP server.
pub fn handle_server(port: Option<u16>, stdio: bool, verbose: bool, config: Option<String>) {
// If verbose flag is set, increase log level to Debug
// (logging is already initialized in main() via RUST_LOG)
if verbose {
log::set_max_level(log::LevelFilter::Debug);
}
// Start the LSP server
let runtime = tokio::runtime::Runtime::new().unwrap_or_else(|e| {
eprintln!("{}: Failed to create Tokio runtime: {}", "Error".red().bold(), e);
exit::tool_error();
});
runtime.block_on(async {
if let Some(port) = port {
// TCP mode for debugging
if let Err(e) = rumdl_lib::lsp::start_tcp_server(port, config.as_deref()).await {
eprintln!("Failed to start LSP server on port {port}: {e}");
exit::tool_error();
}
} else {
// Standard LSP mode over stdio (default behavior)
// Note: stdio flag is for explicit documentation, behavior is the same
let _ = stdio; // Suppress unused variable warning
if let Err(e) = rumdl_lib::lsp::start_server(config.as_deref()).await {
eprintln!("Failed to start LSP server: {e}");
exit::tool_error();
}
}
});
}