From 99dc674a3676a5b97bd03f647bdb19aec8890efd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 22 Jun 2021 21:48:01 -0400 Subject: [PATCH] chore: use lsp to get parent process id (#11083) Removes the previously added internal `--parent-pid` flag. This solution is better. --- cli/flags.rs | 47 +++----------------------------------- cli/lsp/language_server.rs | 6 +++++ cli/lsp/mod.rs | 6 +---- cli/main.rs | 6 ++--- 4 files changed, 13 insertions(+), 52 deletions(-) diff --git a/cli/flags.rs b/cli/flags.rs index 9fc3103b41..c5742af6fd 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -84,9 +84,7 @@ pub enum DenoSubcommand { root: Option, force: bool, }, - Lsp { - parent_pid: Option, - }, + Lsp, Lint { files: Vec, ignore: Vec, @@ -878,16 +876,6 @@ go-to-definition support and automatic code formatting. How to connect various editors and IDEs to 'deno lsp': https://deno.land/manual/getting_started/setup_your_environment#editors-and-ides") - .arg( - Arg::with_name("parent-pid") - .long("parent-pid") - .help("The parent process id to periodically check for the existence of or exit") - .takes_value(true) - .validator(|val: String| match val.parse::() { - Ok(_) => Ok(()), - Err(_) => Err("parent-pid should be a number".to_string()), - }), - ) } fn lint_subcommand<'a, 'b>() -> App<'a, 'b> { @@ -1633,11 +1621,8 @@ fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) { }; } -fn lsp_parse(flags: &mut Flags, matches: &clap::ArgMatches) { - let parent_pid = matches - .value_of("parent-pid") - .map(|val| val.parse().unwrap()); - flags.subcommand = DenoSubcommand::Lsp { parent_pid }; +fn lsp_parse(flags: &mut Flags, _matches: &clap::ArgMatches) { + flags.subcommand = DenoSubcommand::Lsp; } fn lint_parse(flags: &mut Flags, matches: &clap::ArgMatches) { @@ -2317,32 +2302,6 @@ mod tests { ); } - #[test] - fn lsp() { - let r = flags_from_vec(svec!["deno", "lsp"]); - assert_eq!( - r.unwrap(), - Flags { - subcommand: DenoSubcommand::Lsp { parent_pid: None }, - ..Flags::default() - } - ); - - let r = flags_from_vec(svec!["deno", "lsp", "--parent-pid", "5"]); - assert_eq!( - r.unwrap(), - Flags { - subcommand: DenoSubcommand::Lsp { - parent_pid: Some(5), - }, - ..Flags::default() - } - ); - - let r = flags_from_vec(svec!["deno", "lsp", "--parent-pid", "invalid-arg"]); - assert!(r.is_err()); - } - #[test] fn lint() { let r = flags_from_vec(svec!["deno", "lint", "script_1.ts", "script_2.ts"]); diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 491e402ad3..354ad919e0 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -39,6 +39,7 @@ use super::diagnostics::DiagnosticSource; use super::documents::DocumentCache; use super::documents::LanguageId; use super::lsp_custom; +use super::parent_process_checker; use super::performance::Performance; use super::registries; use super::sources; @@ -523,6 +524,11 @@ impl Inner { info!("Starting Deno language server..."); let mark = self.performance.mark("initialize", Some(¶ms)); + // exit this process when the parent is lost + if let Some(parent_pid) = params.process_id { + parent_process_checker::start(parent_pid) + } + let capabilities = capabilities::server_capabilities(¶ms.capabilities); let version = format!( diff --git a/cli/lsp/mod.rs b/cli/lsp/mod.rs index 4723f8b561..c05241ae12 100644 --- a/cli/lsp/mod.rs +++ b/cli/lsp/mod.rs @@ -23,14 +23,10 @@ mod text; mod tsc; mod urls; -pub async fn start(parent_pid: Option) -> Result<(), AnyError> { +pub async fn start() -> Result<(), AnyError> { let stdin = tokio::io::stdin(); let stdout = tokio::io::stdout(); - if let Some(parent_pid) = parent_pid { - parent_process_checker::start(parent_pid); - } - let (service, messages) = LspService::new(language_server::LanguageServer::new); Server::new(stdin, stdout) diff --git a/cli/main.rs b/cli/main.rs index 950234a722..16fc76444f 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -470,8 +470,8 @@ async fn install_command( tools::installer::install(flags, &module_url, args, name, root, force) } -async fn lsp_command(parent_pid: Option) -> Result<(), AnyError> { - lsp::start(parent_pid).await +async fn lsp_command() -> Result<(), AnyError> { + lsp::start().await } async fn lint_command( @@ -1265,7 +1265,7 @@ fn get_subcommand( } => { install_command(flags, module_url, args, name, root, force).boxed_local() } - DenoSubcommand::Lsp { parent_pid } => lsp_command(parent_pid).boxed_local(), + DenoSubcommand::Lsp => lsp_command().boxed_local(), DenoSubcommand::Lint { files, rules,