Allow cli to accept --dev-server-token (#10944)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-04-24 13:15:19 -06:00 committed by GitHub
parent bd77232f65
commit 048fc7ad09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 4 deletions

1
Cargo.lock generated
View File

@ -4724,6 +4724,7 @@ dependencies = [
"project", "project",
"rpc", "rpc",
"settings", "settings",
"shellexpand",
"util", "util",
] ]

View File

@ -36,6 +36,9 @@ struct Args {
/// Custom Zed.app path /// Custom Zed.app path
#[arg(short, long)] #[arg(short, long)]
bundle_path: Option<PathBuf>, bundle_path: Option<PathBuf>,
/// Run zed in dev-server mode
#[arg(long)]
dev_server_token: Option<String>,
} }
fn parse_path_with_position( fn parse_path_with_position(
@ -67,6 +70,10 @@ fn main() -> Result<()> {
let bundle = Bundle::detect(args.bundle_path.as_deref()).context("Bundle detection")?; let bundle = Bundle::detect(args.bundle_path.as_deref()).context("Bundle detection")?;
if let Some(dev_server_token) = args.dev_server_token {
return bundle.spawn(vec!["--dev-server-token".into(), dev_server_token]);
}
if args.version { if args.version {
println!("{}", bundle.zed_version_string()); println!("{}", bundle.zed_version_string());
return Ok(()); return Ok(());
@ -169,6 +176,10 @@ mod linux {
unimplemented!() unimplemented!()
} }
pub fn spawn(&self, _args: Vec<String>) -> anyhow::Result<()> {
unimplemented!()
}
pub fn zed_version_string(&self) -> String { pub fn zed_version_string(&self) -> String {
unimplemented!() unimplemented!()
} }
@ -202,6 +213,10 @@ mod windows {
unimplemented!() unimplemented!()
} }
pub fn spawn(&self, _args: Vec<String>) -> anyhow::Result<()> {
unimplemented!()
}
pub fn zed_version_string(&self) -> String { pub fn zed_version_string(&self) -> String {
unimplemented!() unimplemented!()
} }
@ -217,7 +232,7 @@ mod mac_os {
url::{CFURLCreateWithBytes, CFURL}, url::{CFURLCreateWithBytes, CFURL},
}; };
use core_services::{kLSLaunchDefaults, LSLaunchURLSpec, LSOpenFromURLSpec, TCFType}; use core_services::{kLSLaunchDefaults, LSLaunchURLSpec, LSOpenFromURLSpec, TCFType};
use std::{fs, path::Path, ptr}; use std::{fs, path::Path, process::Command, ptr};
use cli::{CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME}; use cli::{CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME};
use ipc_channel::ipc::{IpcOneShotServer, IpcReceiver, IpcSender}; use ipc_channel::ipc::{IpcOneShotServer, IpcReceiver, IpcSender};
@ -278,6 +293,15 @@ mod mac_os {
} }
} }
pub fn spawn(&self, args: Vec<String>) -> Result<()> {
let path = match self {
Self::App { app_bundle, .. } => app_bundle.join("Contents/MacOS/zed"),
Self::LocalPath { executable, .. } => executable.clone(),
};
Command::new(path).args(args).status()?;
Ok(())
}
pub fn launch(&self) -> anyhow::Result<(IpcSender<CliRequest>, IpcReceiver<CliResponse>)> { pub fn launch(&self) -> anyhow::Result<(IpcSender<CliRequest>, IpcReceiver<CliResponse>)> {
let (server, server_name) = let (server, server_name) =
IpcOneShotServer::<IpcHandshake>::new().context("Handshake before Zed spawn")?; IpcOneShotServer::<IpcHandshake>::new().context("Handshake before Zed spawn")?;
@ -358,12 +382,12 @@ mod mac_os {
) )
} }
} }
pub(super) fn spawn_channel_cli( pub(super) fn spawn_channel_cli(
channel: release_channel::ReleaseChannel, channel: release_channel::ReleaseChannel,
leftover_args: Vec<String>, leftover_args: Vec<String>,
) -> Result<()> { ) -> Result<()> {
use anyhow::bail; use anyhow::bail;
use std::process::Command;
let app_id_prompt = format!("id of app \"{}\"", channel.display_name()); let app_id_prompt = format!("id of app \"{}\"", channel.display_name());
let app_id_output = Command::new("osascript") let app_id_output = Command::new("osascript")

View File

@ -26,6 +26,7 @@ project.workspace = true
fs.workspace = true fs.workspace = true
futures.workspace = true futures.workspace = true
settings.workspace = true settings.workspace = true
shellexpand.workspace = true
postage.workspace = true postage.workspace = true
[dev-dependencies] [dev-dependencies]

View File

@ -180,7 +180,8 @@ impl DevServer {
_: Arc<Client>, _: Arc<Client>,
cx: AsyncAppContext, cx: AsyncAppContext,
) -> Result<proto::Ack> { ) -> Result<proto::Ack> {
let path = std::path::Path::new(&envelope.payload.path); let expanded = shellexpand::tilde(&envelope.payload.path).to_string();
let path = std::path::Path::new(&expanded);
let fs = cx.read_model(&this, |this, _| this.app_state.fs.clone())?; let fs = cx.read_model(&this, |this, _| this.app_state.fs.clone())?;
let path_exists = fs.is_dir(path).await; let path_exists = fs.is_dir(path).await;
@ -232,9 +233,11 @@ impl DevServer {
(this.client.clone(), project) (this.client.clone(), project)
})?; })?;
let path = shellexpand::tilde(&remote_project.path).to_string();
project project
.update(cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree(&remote_project.path, true, cx) project.find_or_create_local_worktree(&path, true, cx)
})? })?
.await?; .await?;