From 3046ef647125d721d552fe68af2a645aa4b2b4fb Mon Sep 17 00:00:00 2001 From: Jason Wen <107383260+the-jasoney@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:30:23 -0700 Subject: [PATCH] windows: Prevent command line from opening in release mode (#9839) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Release Notes: - Prevents the terminal from opening on release mode on Windows Note: this also prevents Zed from logging to the terminal when it is launched from the terminal. Is this expected behaviour on other platforms? --------- Co-authored-by: 白山風露 --- Cargo.lock | 1 + crates/lsp/Cargo.toml | 3 +++ crates/lsp/src/lsp.rs | 13 ++++++++++--- crates/zed/src/main.rs | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93ec57c598..face9fc805 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5570,6 +5570,7 @@ dependencies = [ "serde_json", "smol", "util", + "windows 0.53.0", ] [[package]] diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.toml index 23b2f204ef..e685ddf5a2 100644 --- a/crates/lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -31,6 +31,9 @@ smol.workspace = true util.workspace = true release_channel.workspace = true +[target.'cfg(windows)'.dependencies] +windows.workspace = true + [dev-dependencies] async-pipe = { git = "https://github.com/zed-industries/async-pipe-rs", rev = "82d00a04211cf4e1236029aa03e6b6ce2a74c553" } ctor.workspace = true diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index dc3dfd0a81..7422ff5d9c 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -15,6 +15,10 @@ use smol::{ io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}, process::{self, Child}, }; + +#[cfg(target_os = "windows")] +use smol::process::windows::CommandExt; + use std::{ ffi::OsString, fmt, @@ -215,15 +219,18 @@ impl LanguageServer { &binary.arguments ); - let mut server = process::Command::new(&binary.path) + let mut command = process::Command::new(&binary.path); + command .current_dir(working_dir) .args(binary.arguments) .envs(binary.env.unwrap_or_default()) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) - .kill_on_drop(true) - .spawn()?; + .kill_on_drop(true); + #[cfg(windows)] + command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0); + let mut server = command.spawn()?; let stdin = server.stdin.take().unwrap(); let stdout = server.stdout.take().unwrap(); diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 4611b69524..ccb747f51b 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -1,5 +1,7 @@ // Allow binary to be called Zed for a nice application menu when running executable directly #![allow(non_snake_case)] +// Disable command line from opening on release mode +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] mod zed;