Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokenize command arguments in $NEOVIM_BIN (fix #2060) #2063

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ raw-window-handle = "0.5.0"
rmpv = "1.0.0"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
shlex = "1.1.0"
swash = "0.1.8"
time = "0.3.9"
tokio = { version = "1.25.0", features = ["full"] }
Expand All @@ -68,7 +69,6 @@ winapi = { version = "0.3.9", features = ["winuser", "wincon", "winerror"] }
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24.0"
objc = "0.2.7"
shlex = "1.1.0"

[target.'cfg(not(windows))'.dependencies]

Expand Down
37 changes: 22 additions & 15 deletions src/bridge/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@ fn set_windows_creation_flags(cmd: &mut TokioCommand) {

fn build_nvim_cmd() -> TokioCommand {
if let Some(path) = SETTINGS.get::<CmdLineSettings>().neovim_bin {
// if neovim_bin contains a path separator, then try to launch it directly
// otherwise use which to find the fully path
if path.contains('/') || path.contains('\\') {
if neovim_ok(&path) {
return build_nvim_cmd_with_args(&path);
}
} else if let Some(path) = platform_which(&path) {
if neovim_ok(&path) {
return build_nvim_cmd_with_args(&path);
if let Some(path) = shlex::split(&path) {
if let Some((bin, args)) = path.split_first() {
rhysd marked this conversation as resolved.
Show resolved Hide resolved
// if neovim_bin contains a path separator, then try to launch it directly
// otherwise use which to find the fully path
if bin.contains('/') || bin.contains('\\') {
if neovim_ok(bin, args) {
return build_nvim_cmd_with_args(bin, args);
}
} else if let Some(bin) = platform_which(bin) {
if neovim_ok(&bin, args) {
return build_nvim_cmd_with_args(&bin, args);
}
}
}
}

eprintln!("ERROR: NEOVIM_BIN='{}' was not found.", path);
std::process::exit(1);
} else if let Some(path) = platform_which("nvim") {
if neovim_ok(&path) {
return build_nvim_cmd_with_args(&path);
if neovim_ok(&path, &[]) {
return build_nvim_cmd_with_args(&path, &[]);
}
}
eprintln!("ERROR: nvim not found!");
Expand Down Expand Up @@ -87,10 +91,12 @@ fn create_platform_shell_command(command: &str, args: &[&str]) -> StdCommand {
}
}

fn neovim_ok(bin: &str) -> bool {
fn neovim_ok(bin: &str, args: &[String]) -> bool {
let is_wsl = SETTINGS.get::<CmdLineSettings>().wsl;
let mut args = args.iter().map(String::as_str).collect::<Vec<_>>();
args.push("-v");

let mut cmd = create_platform_shell_command(bin, &["-v"]);
let mut cmd = create_platform_shell_command(bin, &args);
if let Ok(output) = cmd.output() {
if output.status.success() {
// The output is not utf8 on Windows and can contain special characters.
Expand Down Expand Up @@ -176,8 +182,9 @@ fn nvim_cmd_impl(bin: &str, args: &[String]) -> TokioCommand {
}
}

fn build_nvim_cmd_with_args(bin: &str) -> TokioCommand {
let mut args = vec!["--embed".to_string()];
fn build_nvim_cmd_with_args(bin: &str, args: &[String]) -> TokioCommand {
let mut args = args.to_vec();
args.push("--embed".to_string());
args.extend(SETTINGS.get::<CmdLineSettings>().neovim_args);
nvim_cmd_impl(bin, &args)
}