use anyhow::Result;
use clap::Args;
use cooklang_language_server::Backend;
use tower_lsp::{LspService, Server};
use tracing::{debug, info};
use crate::Context;
#[derive(Debug, Args)]
#[command()]
pub struct LspArgs {}
#[tokio::main]
pub async fn run(ctx: &Context, _args: LspArgs) -> Result<()> {
info!("Starting Cooklang LSP server");
debug!("Base path: {}", ctx.base_path());
if let Some(aisle) = ctx.aisle().path() {
debug!("Aisle config: {}", aisle);
}
if let Some(pantry) = ctx.pantry().path() {
debug!("Pantry config: {}", pantry);
}
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
let (service, socket) = LspService::new(Backend::new);
tokio::select! {
_ = Server::new(stdin, stdout, socket).serve(service) => {
info!("LSP server stopped");
}
_ = tokio::signal::ctrl_c() => {
info!("Received shutdown signal, stopping LSP server");
}
}
Ok(())
}