From 68ea842821a8afd91cfd6557548f5309b0308cb4 Mon Sep 17 00:00:00 2001 From: Josh Thomas Date: Mon, 19 May 2025 12:03:20 -0500 Subject: [PATCH] print warning when trying to run serve command in TTY (#155) --- crates/djls-server/src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/djls-server/src/lib.rs b/crates/djls-server/src/lib.rs index acb1d6c..584de60 100644 --- a/crates/djls-server/src/lib.rs +++ b/crates/djls-server/src/lib.rs @@ -6,6 +6,8 @@ mod server; mod session; mod workspace; +use std::io::IsTerminal; + use anyhow::Result; use tower_lsp_server::LspService; use tower_lsp_server::Server; @@ -13,6 +15,28 @@ use tower_lsp_server::Server; use crate::server::DjangoLanguageServer; pub fn run() -> Result<()> { + if std::io::stdin().is_terminal() { + eprintln!( + "---------------------------------------------------------------------------------" + ); + eprintln!("Django Language Server is running directly in a terminal."); + eprintln!( + "This server is designed to communicate over stdin/stdout with a language client." + ); + eprintln!("It is not intended to be used directly in a terminal."); + eprintln!(); + eprintln!( + "Note: The server is now waiting for LSP messages, but since you're in a terminal," + ); + eprintln!("no editor is connected and the server won't do anything."); + eprintln!(); + eprintln!("To exit: Press ENTER to send invalid input and trigger an error exit."); + eprintln!("Ctrl+C will not work as expected due to LSP stdio communication."); + eprintln!( + "---------------------------------------------------------------------------------" + ); + } + let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build()?;