rename binary crate to djls (#32)
Some checks are pending
test / test (macos-latest) (push) Waiting to run
test / test (ubuntu-latest) (push) Waiting to run
test / test (windows-latest) (push) Waiting to run

This commit is contained in:
Josh Thomas 2024-12-15 15:18:54 -06:00 committed by GitHub
parent 340cd7a1c0
commit 19b2566c8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 69 additions and 63 deletions

View file

@ -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" }

View file

@ -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<Duration> {
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<dyn std::error::Error>> {
let cli = Cli::parse();
match cli.command {
Commands::Serve(opts) => {
println!("Starting LSP server...");
let python = PythonProcess::new::<Vec<&OsStr>, &OsStr>(
"djls.agent",
None,
opts.health_check_interval(),
)?;
println!("LSP server started, beginning to serve...");
djls_server::serve(python).await?
}
}
Ok(())
}

View file

@ -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"

View file

@ -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,
}

54
crates/djls/src/main.rs Normal file
View file

@ -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<ExitCode> {
let cli = Cli::parse();
match cli.command {
Command::Serve(_serve) => {
let python = PythonProcess::new::<Vec<&OsStr>, &OsStr>("djls.agent", None, None)?;
djls_server::serve(python).await?
}
}
Ok(ExitCode::SUCCESS)
}