mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-08 03:10:34 +00:00
rename binary crate to djls
(#32)
This commit is contained in:
parent
340cd7a1c0
commit
19b2566c8f
5 changed files with 69 additions and 63 deletions
|
@ -3,8 +3,8 @@ members = ["crates/*"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
djls = { path = "crates/djls" }
|
||||||
djls-ast = { path = "crates/djls-ast" }
|
djls-ast = { path = "crates/djls-ast" }
|
||||||
djls-cli = { path = "crates/djls-cli" }
|
|
||||||
djls-django = { path = "crates/djls-django" }
|
djls-django = { path = "crates/djls-django" }
|
||||||
djls-ipc = { path = "crates/djls-ipc" }
|
djls-ipc = { path = "crates/djls-ipc" }
|
||||||
djls-python = { path = "crates/djls-python" }
|
djls-python = { path = "crates/djls-python" }
|
||||||
|
|
|
@ -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(())
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "djls-cli"
|
name = "djls"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -14,7 +14,3 @@ tokio = { workspace = true }
|
||||||
|
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
tower-lsp = { version = "0.20", features = ["proposed"] }
|
tower-lsp = { version = "0.20", features = ["proposed"] }
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "djls"
|
|
||||||
path = "src/main.rs"
|
|
13
crates/djls/src/commands.rs
Normal file
13
crates/djls/src/commands.rs
Normal 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
54
crates/djls/src/main.rs
Normal 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)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue