Skip to content

Commit

Permalink
feat: add sub command version to lsp (#730)
Browse files Browse the repository at this point in the history
Signed-off-by: He1pa <18012015693@163.com>
  • Loading branch information
He1pa authored Oct 7, 2023
1 parent 5642bb1 commit bea9f06
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
2 changes: 2 additions & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions kclvm/tools/src/LSP/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
37 changes: 28 additions & 9 deletions kclvm/tools/src/LSP/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod request;
mod state;
mod to_lsp;
mod util;
use clap::Command;

mod formatting;
#[cfg(test)]
Expand Down Expand Up @@ -61,13 +62,31 @@ pub enum ExitStatus {

/// Main entry point for the `kcl-language-server` executable.
fn main() -> Result<(), anyhow::Error> {
let status: Result<ExitStatus, anyhow::Error> = {
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<String> = 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<ExitStatus, anyhow::Error> = {
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"))
}

0 comments on commit bea9f06

Please sign in to comment.