use colored::*;
use rumdl_lib::exit_codes::exit;
pub fn handle_server(port: Option<u16>, stdio: bool, verbose: bool, config: Option<String>) {
if verbose {
log::set_max_level(log::LevelFilter::Debug);
}
if let Some(config_path) = &config
&& !std::path::Path::new(config_path).exists()
{
eprintln!(
"{}: Configuration file not found: {}",
"Error".red().bold(),
config_path
);
exit::tool_error();
}
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 {
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 {
let _ = stdio; if let Err(e) = rumdl_lib::lsp::start_server(config.as_deref()).await {
eprintln!("Failed to start LSP server: {e}");
exit::tool_error();
}
}
});
}