diff --git a/Cargo.toml b/Cargo.toml index 95d3c21..ecef6fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,8 @@ members = ["crates/*"] resolver = "2" [workspace.dependencies] +djls = { path = "crates/djls" } djls-ast = { path = "crates/djls-ast" } -djls-cli = { path = "crates/djls-cli" } djls-django = { path = "crates/djls-django" } djls-ipc = { path = "crates/djls-ipc" } djls-python = { path = "crates/djls-python" } diff --git a/crates/djls-cli/src/main.rs b/crates/djls-cli/src/main.rs deleted file mode 100644 index 1cda885..0000000 --- a/crates/djls-cli/src/main.rs +++ /dev/null @@ -1,57 +0,0 @@ -use clap::{Args, Parser, Subcommand}; -use djls_ipc::PythonProcess; -use std::ffi::OsStr; -use std::time::Duration; - -#[derive(Debug, Parser)] -struct Cli { - #[command(subcommand)] - command: Commands, -} - -#[derive(Debug, Args)] -struct CommonOpts { - /// Disable periodic health checks - #[arg(long)] - no_health_check: bool, - - /// Health check interval in seconds - #[arg(long, default_value = "30")] - health_interval: u64, -} - -impl CommonOpts { - fn health_check_interval(&self) -> Option { - if self.no_health_check { - None - } else { - Some(Duration::from_secs(self.health_interval)) - } - } -} - -#[derive(Debug, Subcommand)] -enum Commands { - /// Start the LSP server - Serve(CommonOpts), -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - let cli = Cli::parse(); - - match cli.command { - Commands::Serve(opts) => { - println!("Starting LSP server..."); - let python = PythonProcess::new::, &OsStr>( - "djls.agent", - None, - opts.health_check_interval(), - )?; - println!("LSP server started, beginning to serve..."); - djls_server::serve(python).await? - } - } - - Ok(()) -} diff --git a/crates/djls-cli/Cargo.toml b/crates/djls/Cargo.toml similarity index 88% rename from crates/djls-cli/Cargo.toml rename to crates/djls/Cargo.toml index 257e6c9..5e7493a 100644 --- a/crates/djls-cli/Cargo.toml +++ b/crates/djls/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "djls-cli" +name = "djls" version = "0.1.0" edition = "2021" @@ -14,7 +14,3 @@ tokio = { workspace = true } clap = { version = "4.5", features = ["derive"] } tower-lsp = { version = "0.20", features = ["proposed"] } - -[[bin]] -name = "djls" -path = "src/main.rs" diff --git a/crates/djls/src/commands.rs b/crates/djls/src/commands.rs new file mode 100644 index 0000000..a25858a --- /dev/null +++ b/crates/djls/src/commands.rs @@ -0,0 +1,13 @@ +use clap::{Parser, ValueEnum}; + +#[derive(Debug, Parser)] +pub struct Serve { + #[arg(short, long, default_value_t = ConnectionType::Stdio, value_enum)] + connection_type: ConnectionType, +} + +#[derive(Clone, Debug, ValueEnum)] +enum ConnectionType { + Stdio, + Tcp, +} diff --git a/crates/djls/src/main.rs b/crates/djls/src/main.rs new file mode 100644 index 0000000..6b3e2c2 --- /dev/null +++ b/crates/djls/src/main.rs @@ -0,0 +1,54 @@ +mod commands; + +use crate::commands::Serve; +use anyhow::Result; +use clap::{Parser, Subcommand}; +use djls_ipc::PythonProcess; +use std::ffi::OsStr; +use std::process::ExitCode; + +#[derive(Parser)] +#[command(name = "djls")] +#[command(version, about, long_about = None)] +pub struct Cli { + #[command(subcommand)] + command: Command, + + #[command(flatten)] + args: Args, +} + +#[derive(Debug, Subcommand)] +enum Command { + /// Start the LSP server + Serve(Serve), +} + +#[derive(Parser)] +pub struct Args { + #[command(flatten)] + global: GlobalArgs, +} + +#[derive(Parser, Debug, Clone)] +struct GlobalArgs { + /// Do not print any output. + #[arg(global = true, long, short, conflicts_with = "verbose")] + pub quiet: bool, + + /// Use verbose output. + #[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")] + pub verbose: u8, +} + +#[tokio::main] +async fn main() -> Result { + let cli = Cli::parse(); + match cli.command { + Command::Serve(_serve) => { + let python = PythonProcess::new::, &OsStr>("djls.agent", None, None)?; + djls_server::serve(python).await? + } + } + Ok(ExitCode::SUCCESS) +}