-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Runtime configuration of clipboard providers #1827
Conversation
#[cfg(unix)] | ||
"wl-clipboard" { | ||
copy: "wl-copy", "--type", "text/plain"; | ||
paste: "wl-paste", "--no-newline"; | ||
primary_copy: "wl-copy", "-p", "--type", "text/plain"; | ||
primary_paste: "wl-paste", "-p", "--no-newline"; | ||
env: "WAYLAND_DISPLAY"; | ||
} |
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.
Do we really need a macro for this?
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 mean, there was a macro before, and it didn't reduce boilerplate by nearly as much as these two macros.
This approach handles:
- Converting every argument into a
String
so that the presets can coexist with deserialized config data. - Building a map of providers, for by-name lookup.
- Building a list based on order of appearance, for specifying precedence.
- Implicit defaults for
env
,primary
, andtest
, which are each relatively rare among the presets.
macro_rules! check { | ||
($cond:expr) => { | ||
if !$cond { | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
check!(!self.copy.is_empty() && exists(&self.copy[0])); | ||
check!(!self.paste.is_empty() && exists(&self.paste[0])); |
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 think this macro is unnecessary, it's just a couple of lines.
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 generally follow the rule of three for avoiding repetitive code. This is five (or four, without test_commands
), and I'm not a fan of how it looks without the macro:
pub fn is_available(&self) -> bool {
if !self.copy.is_empty() && !exists(&self.copy[0]) {
return false;
}
if !self.paste.is_empty() && !exists(&self.paste[0]) {
return false;
}
if let Some(copy) = &self.primary_copy {
if !copy.is_empty() && !exists(©[0]) {
return false;
}
}
if let Some(paste) = &self.primary_paste {
if !paste.is_empty() && !exists(&paste[0]) {
return false;
}
}
for var in &self.env_vars {
if !env_var_is_set(var) {
return false;
}
}
for cmd in &self.test_commands {
// FIXME: check performance of is_exit_success
if !cmd.is_empty() && !is_exit_success(&cmd[0], &cmd[1..]) {
return false;
}
}
true
}
I think this is a bit of overkill. We either want to automatically detect a suitable provider and use it, or we want the user to manually specify |
#[cfg(any(windows, target_os = "linux"))] // this is a godsend on WSL | ||
"win32yank" { | ||
copy: "win32yank.exe", "-i"; | ||
paste: "win32yank.exe", "-o"; | ||
} |
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.
Looking at what the code was before, you want to always use the WindowsProvider
on windows
, and win32yank
on linux
which will cover 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.
Sure, my particular use case doesn't need anything other than clipboard-win
on cfg(windows)
, but I believe the lemonade
client also works on Windows.
This approach makes it easier to have a single portable configuration. I personally use helix primarily in two Linux environments, one of which should use |
The auto-detection ideally should cover all these cases, the user should only override it to a single specific config. In your case, if the auto-detection is done correctly then it should work without manual config, ideally we don't want users to do any config for this. |
clsoing this one out as stale. We would still like to add the ability to do this but this has siginificant conflicts and open review comments so it makes more sense to start over with a new PR if somebody wants to pick this up. Thank you for contributing! |
Commit adf97e0 is mostly reasonable, but as a WSL user, it broke my workflow. The win32yank provider does work on WSL, and it's great.
Rather than simply revert the changes (or specifically the removal of win32yank on Linux), I took the opportunity to make the system more flexible. The majority of providers are already command-based, which really shouldn't require the whole WASM plugin system, hence this implementation. All of Neovim's presets are available, and the user can specify in config.toml which ones should be tried and in what order, as well as defining their own.