From 36200088a4b0da8ad7a36a644ebc2cb741ef3b0c Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Fri, 21 Jan 2022 19:09:44 -0800 Subject: [PATCH] don't parse version number from client info (#1166) Co-authored-by: Keith Simmons --- src/bridge/events.rs | 64 ---------------------------------------- src/bridge/mod.rs | 9 +++--- src/bridge/setup.rs | 69 +++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 101 deletions(-) diff --git a/src/bridge/events.rs b/src/bridge/events.rs index b83ed3f..61bf41b 100644 --- a/src/bridge/events.rs +++ b/src/bridge/events.rs @@ -303,37 +303,9 @@ impl Default for ChannelMode { } } -#[derive(Debug, Default)] -pub struct ClientVersion { - pub major: u64, - pub minor: Option, - pub patch: Option, - pub prerelease: Option, - pub commit: Option, -} - -#[derive(Debug)] -pub enum ClientType { - Remote, - Ui, - Embedder, - Host, - Plugin, -} - -impl Default for ClientType { - fn default() -> Self { - Self::Remote - } -} - #[derive(Debug, Default)] pub struct ClientInfo { pub name: String, - pub version: ClientVersion, - pub client_type: ClientType, - // methods - // attributes } #[derive(Debug, Default)] @@ -964,40 +936,6 @@ pub fn parse_channel_mode(channel_mode_value: Value) -> Result { } } -pub fn parse_client_version(version_value: Value) -> Result { - let version_map = parse_map(version_value)?; - - let mut version = ClientVersion::default(); - - for version_property in version_map { - if let (Value::String(name), value) = version_property { - match (name.as_str().unwrap(), value) { - ("major", major) => version.major = parse_u64(major)?, - ("minor", minor) => version.minor = Some(parse_u64(minor)?), - ("patch", patch) => version.patch = Some(parse_u64(patch)?), - ("prerelease", prerelease) => version.prerelease = Some(parse_string(prerelease)?), - ("commit", commit) => version.commit = Some(parse_string(commit)?), - _ => debug!("Ignored client version property: {}", name), - } - } else { - debug!("Invalid client version format"); - } - } - - Ok(version) -} - -pub fn parse_client_type(client_type_value: Value) -> Result { - match parse_string(client_type_value)?.as_ref() { - "remote" => Ok(ClientType::Remote), - "ui" => Ok(ClientType::Ui), - "embedder" => Ok(ClientType::Embedder), - "host" => Ok(ClientType::Host), - "plugin" => Ok(ClientType::Plugin), - client_type => Err(ParseError::Format(format!("{:?}", client_type))), - } -} - pub fn parse_client_info(client_info_value: Value) -> Result { let client_info_map = parse_map(client_info_value)?; @@ -1007,8 +945,6 @@ pub fn parse_client_info(client_info_value: Value) -> Result { if let (Value::String(name), value) = info_property { match (name.as_str().unwrap(), value) { ("name", name) => client_info.name = parse_string(name)?, - ("version", version) => client_info.version = parse_client_version(version)?, - ("type", client_type) => client_info.client_type = parse_client_type(client_type)?, _ => debug!("Ignored client type property: {}", name), } } else { diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 2724aeb..cffe233 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -60,13 +60,14 @@ async fn start_neovim_runtime() { } } + let settings = SETTINGS.get::(); + + let mut is_remote = settings.wsl; if let ConnectionMode::RemoteTcp(_) = connection_mode() { - setup_neovide_specific_state(&nvim, true).await; - } else { - setup_neovide_specific_state(&nvim, false).await; + is_remote = true; } + setup_neovide_specific_state(&nvim, is_remote).await; - let settings = SETTINGS.get::(); let geometry = settings.geometry; let mut options = UiAttachOptions::new(); options.set_linegrid_external(true); diff --git a/src/bridge/setup.rs b/src/bridge/setup.rs index c6a58ed..4f3d6d9 100644 --- a/src/bridge/setup.rs +++ b/src/bridge/setup.rs @@ -1,4 +1,4 @@ -use log::info; +use log::{info, warn}; use nvim_rs::Neovim; use rmpv::Value; @@ -83,7 +83,7 @@ pub async fn setup_neovide_specific_state(nvim: &Neovim, is_remote: b .ok(); // Retrieve the channel number for communicating with neovide - let neovide_channel: u64 = nvim + let neovide_channel: Option = nvim .list_chans() .await .ok() @@ -97,36 +97,43 @@ pub async fn setup_neovide_specific_state(nvim: &Neovim, is_remote: b } if name == "neovide" => Some(*id), _ => None, }) - }) - .unwrap_or(0); + }); - // Record the channel to the log - info!( - "Neovide registered to nvim with channel id {}", - neovide_channel - ); + if let Some(neovide_channel) = neovide_channel { + // Record the channel to the log + info!( + "Neovide registered to nvim with channel id {}", + neovide_channel + ); - // Create a command for registering right click context hooking - #[cfg(windows)] - nvim.command(&build_neovide_command( - neovide_channel, - 0, - "NeovideRegisterRightClick", - "register_right_click", - )) - .await - .ok(); + // Create a command for registering right click context hooking + #[cfg(windows)] + nvim.command(&build_neovide_command( + neovide_channel, + 0, + "NeovideRegisterRightClick", + "register_right_click", + )) + .await + .ok(); - // Create a command for unregistering the right click context hooking - #[cfg(windows)] - nvim.command(&build_neovide_command( - neovide_channel, - 0, - "NeovideUnregisterRightClick", - "unregister_right_click", - )) - .await - .ok(); + // Create a command for unregistering the right click context hooking + #[cfg(windows)] + nvim.command(&build_neovide_command( + neovide_channel, + 0, + "NeovideUnregisterRightClick", + "unregister_right_click", + )) + .await + .ok(); + + if is_remote { + setup_neovide_remote_clipboard(nvim, neovide_channel).await; + } + } else { + warn!("Neovide could not find the correct channel id. Some functionality may be disabled."); + } // Set some basic rendering options nvim.set_option("lazyredraw", Value::Boolean(false)) @@ -140,10 +147,6 @@ pub async fn setup_neovide_specific_state(nvim: &Neovim, is_remote: b nvim.command("autocmd VimLeave * call rpcnotify(1, 'neovide.quit', v:exiting)") .await .ok(); - - if is_remote { - setup_neovide_remote_clipboard(nvim, neovide_channel).await; - } } #[cfg(windows)]