diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 6089be869..f83b0d867 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -1392,6 +1392,7 @@ dependencies = [ "anyhow", "chrono", "chumsky", + "clap 4.3.19", "compiler_base_session", "crossbeam-channel", "dashmap", @@ -1407,6 +1408,7 @@ dependencies = [ "kclvm-sema", "kclvm-tools", "kclvm-utils", + "kclvm-version", "log", "lsp-server", "lsp-types", diff --git a/kclvm/tools/src/LSP/Cargo.toml b/kclvm/tools/src/LSP/Cargo.toml index 7784630ae..f78291226 100644 --- a/kclvm/tools/src/LSP/Cargo.toml +++ b/kclvm/tools/src/LSP/Cargo.toml @@ -18,20 +18,22 @@ dashmap = "5.1.0" log = "0.4.14" im-rc = "15.0.0" rustc_lexer = "0.1.0" +clap = "4.3.0" -kclvm-tools = {path = "../../../tools"} -kclvm-error = {path = "../../../error"} -kclvm-config ={ path = "../../../config"} -kclvm-driver = {path = "../../../driver"} -kclvm-parser = {path = "../../../parser"} -kclvm-sema = {path = "../../../sema"} -kclvm-ast = {path = "../../../ast"} -kclvm-utils = {path = "../../../utils"} -kclvm-compiler = {path = "../../../compiler"} -compiler_base_session = {path = "../../../../compiler_base/session"} +kclvm-tools = { path = "../../../tools" } +kclvm-error = { path = "../../../error" } +kclvm-config = { path = "../../../config" } +kclvm-driver = { path = "../../../driver" } +kclvm-parser = { path = "../../../parser" } +kclvm-sema = { path = "../../../sema" } +kclvm-ast = { path = "../../../ast" } +kclvm-utils = { path = "../../../utils" } +kclvm-compiler = { path = "../../../compiler" } +kclvm-version = { path = "../../../version" } +compiler_base_session = { path = "../../../../compiler_base/session" } lsp-server = { version = "0.6.0", default-features = false } -anyhow = { version = "1.0", default-features = false, features=["std"] } +anyhow = { version = "1.0", default-features = false, features = ["std"] } crossbeam-channel = { version = "0.5.7", default-features = false } ra_ap_vfs = "0.0.149" ra_ap_vfs-notify = "0.0.149" @@ -41,4 +43,4 @@ salsa = { version = "0.16.1", default-features = false } serde_json = { version = "1.0", default-features = false } parking_lot = { version = "0.12.0", default-features = false } rustc-hash = { version = "1.1.0", default-features = false } -proc_macro_crate = {path = "../../benches/proc_macro_crate"} +proc_macro_crate = { path = "../../benches/proc_macro_crate" } diff --git a/kclvm/tools/src/LSP/src/main.rs b/kclvm/tools/src/LSP/src/main.rs index 70a499820..74c328799 100644 --- a/kclvm/tools/src/LSP/src/main.rs +++ b/kclvm/tools/src/LSP/src/main.rs @@ -17,6 +17,7 @@ mod request; mod state; mod to_lsp; mod util; +use clap::Command; mod formatting; #[cfg(test)] @@ -61,13 +62,31 @@ pub enum ExitStatus { /// Main entry point for the `kcl-language-server` executable. fn main() -> Result<(), anyhow::Error> { - let status: Result = { - run_server().map_err(|e| anyhow::anyhow!("{}", e))?; - Ok(ExitStatus::Success) - }; - match status.unwrap() { - ExitStatus::Success => {} - ExitStatus::Error => std::process::exit(1), - }; - Ok(()) + let args: Vec = std::env::args().collect(); + let matches = app().arg_required_else_help(true).get_matches_from(args); + match matches.subcommand() { + Some(("version", _)) => { + println!("{}", kclvm_version::get_version_info()); + Ok(()) + } + _ => { + let status: Result = { + run_server().map_err(|e| anyhow::anyhow!("{}", e))?; + Ok(ExitStatus::Success) + }; + match status.unwrap() { + ExitStatus::Success => {} + ExitStatus::Error => std::process::exit(1), + }; + Ok(()) + } + } +} + +/// Get the kcl language server CLI application. +pub fn app() -> Command { + Command::new("kcl-language-server") + .version(kclvm_version::VERSION) + .about("KCL language server CLI.") + .subcommand(Command::new("version").about("Show the KCL language server version")) }