migrate all async tokio to server & swap to single-thread runtime (#149)

This commit is contained in:
Josh Thomas 2025-05-15 21:03:14 -05:00 committed by GitHub
parent c29b268326
commit def9fba2b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 45 additions and 103 deletions

View file

@ -1,9 +1,6 @@
use anyhow::Result;
use clap::Parser;
use clap::ValueEnum;
use djls_server::DjangoLanguageServer;
use tower_lsp_server::LspService;
use tower_lsp_server::Server;
use crate::args::Args;
use crate::commands::Command;
@ -23,28 +20,14 @@ enum ConnectionType {
impl Command for Serve {
fn execute(&self, _args: &Args) -> Result<Exit> {
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
djls_server::run()?;
let exit_status = runtime.block_on(async {
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
let (service, socket) = LspService::build(DjangoLanguageServer::new).finish();
Server::new(stdin, stdout, socket).serve(service).await;
// Exit here instead of returning control to the `Cli`, for ... reasons?
// If we don't exit here, ~~~ something ~~~ goes on with PyO3 (I assume)
// or the Python entrypoint wrapper to indefinitely hang the CLI and keep
// the process running
Exit::success()
.with_message("Server completed successfully")
.process_exit()
});
Ok(exit_status)
// Exit here instead of returning control to the `Cli`, for ... reasons?
// If we don't exit here, ~~~ something ~~~ goes on with PyO3 (I assume)
// or the Python entrypoint wrapper to indefinitely hang the CLI and keep
// the process running
Exit::success()
.with_message("Server completed successfully")
.process_exit()
}
}