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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredizzimo Thanks for your review. I simplified my changes and removed 4 redundant clones. Would you review again?
@fredizzimo BTW I got interested in why it wraps the command execution with a shell on macOS though it doesn't do it on Linux. Does executing the command directly on macOS cause any issue? Lines 149 to 164 in a8cec7e
|
@fredizzimo I have another idea to split off the logic to lex Neovim command and args into a new function. Thanks to early returns with diff --git a/src/bridge/command.rs b/src/bridge/command.rs
index 0ec0cff..38996a8 100644
--- a/src/bridge/command.rs
+++ b/src/bridge/command.rs
@@ -32,21 +32,8 @@ fn set_windows_creation_flags(cmd: &mut TokioCommand) {
fn build_nvim_cmd() -> TokioCommand {
if let Some(cmdline) = SETTINGS.get::<CmdLineSettings>().neovim_bin {
- if let Some((bin, args)) = shlex::split(&cmdline)
- .filter(|tokens| !tokens.is_empty())
- .map(|mut tokens| (tokens.remove(0), tokens))
- {
- // 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);
- }
- }
+ if let Some((bin, args)) = lex_nvim_cmdline(&cmdline) {
+ return build_nvim_cmd_with_args(bin, args);
}
eprintln!("ERROR: NEOVIM_BIN='{}' was not found.", cmdline);
@@ -127,6 +114,19 @@ fn neovim_ok(bin: &str, args: &[String]) -> bool {
false
}
+fn lex_nvim_cmdline(cmdline: &str) -> Option<(String, Vec<String>)> {
+ let mut tokens = shlex::split(cmdline).filter(|t| !t.is_empty())?;
+ let (mut bin, args) = (tokens.remove(0), tokens);
+
+ // 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('\\') {
+ bin = platform_which(&bin)?;
+ }
+
+ neovim_ok(&bin, &args).then_some((bin, args))
+}
+
fn platform_which(bin: &str) -> Option<String> {
let is_wsl = SETTINGS.get::<CmdLineSettings>().wsl;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with the code now, but I have not tested it yet, so I'm not merging until that's done.
macOS does some strange things when not launched from a shell. and that were multiple attempts to fix it, but I don't think it's enough, because people still report problems like #1859. We need a better solution for this, but unfortunately, I don't own a mac, so I have no idea how it's supposed to work, and what's the correct way to fix it is. Here are some of those attempts: |
@fredizzimo Thank you for the answer. I understood the reason. When starting an application by clicking Users need to set |
@fredizzimo I applied the patch at c4b8eea and confirmed the behavior manually.
For each above OS, I confirmed the following cases:
|
Thank you. I did some additional tests with WSL on Windows and everything seems to work fine. |
@fredizzimo Thank you. It's very helpful since I don't have those environments. |
What kind of change does this PR introduce?
Did this PR introduce a breaking change?
A breaking change includes anything that breaks backwards compatibility either at compile or run time.
I confirmed this fix on Ubuntu 22.04 and macOS 13.6.