From dca01e0b596f65f0bd12d825b43e80db7496f97b Mon Sep 17 00:00:00 2001 From: Omar Jair Purata Funes Date: Fri, 17 Dec 2021 22:04:20 -0600 Subject: [PATCH] Correctness fixes --- src/config/server_command.rs | 8 ++++---- src/language_client.rs | 14 +++++++------- src/lsp/text_document.rs | 8 ++++---- src/types.rs | 4 ++-- src/utils.rs | 2 +- src/watcher.rs | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/config/server_command.rs b/src/config/server_command.rs index 6d12f2d85..7754df6ad 100644 --- a/src/config/server_command.rs +++ b/src/config/server_command.rs @@ -23,7 +23,7 @@ pub enum ServerCommand { impl ServerCommand { pub fn get_command(&self) -> &[String] { match self { - ServerCommand::Simple(cmd) => &cmd, + ServerCommand::Simple(cmd) => cmd, ServerCommand::Detailed(cmd) => &cmd.command, } } @@ -36,7 +36,7 @@ impl ServerCommand { /// guess the name of the server. pub fn name(&self) -> String { match self { - ServerCommand::Simple(cmd) => ServerCommand::name_from_command(&cmd), + ServerCommand::Simple(cmd) => ServerCommand::name_from_command(cmd), ServerCommand::Detailed(cmd) => cmd.name.clone(), } } @@ -81,14 +81,14 @@ mod test { #[test] fn test_name_from_command_handles_binary_name() { - let name = ServerCommand::name_from_command(&vec!["gopls".into()]); + let name = ServerCommand::name_from_command(&["gopls".into()]); assert_eq!(name.as_str(), "gopls"); } #[test] #[cfg(not(target_os = "windows"))] fn test_name_from_command_handles_binary_path() { - let name = ServerCommand::name_from_command(&vec!["/path/to/gopls".into()]); + let name = ServerCommand::name_from_command(&["/path/to/gopls".into()]); assert_eq!(name.as_str(), "gopls"); } } diff --git a/src/language_client.rs b/src/language_client.rs index 0204c7cf7..60c62cb56 100644 --- a/src/language_client.rs +++ b/src/language_client.rs @@ -136,7 +136,7 @@ impl LanguageClient { pub fn update_state(&self, f: impl FnOnce(&mut State) -> Result) -> Result { let mut state = self.lock()?; - let mut state = state.deref_mut(); + let state = state.deref_mut(); let v = if log_enabled!(log::Level::Debug) { let s = serde_json::to_string(&state)?; @@ -145,7 +145,7 @@ impl LanguageClient { Value::default() }; - let result = f(&mut state); + let result = f(state); let next_v = if log_enabled!(log::Level::Debug) { let s = serde_json::to_string(&state)?; @@ -803,7 +803,7 @@ impl LanguageClient { self.java_class_file_contents(&json!({ "gotoCmd": goto_cmd, "uri": path }))?; Ok(()) } else { - self.vim()?.edit(&goto_cmd, path.into_owned()) + self.vim()?.edit(goto_cmd, path.into_owned()) } } @@ -1166,7 +1166,7 @@ impl LanguageClient { } if let Some(command) = &action.command { - if !self.try_handle_command_by_client(&command)? { + if !self.try_handle_command_by_client(command)? { let params = json!({ "command": command.command, "arguments": command.arguments, @@ -1674,7 +1674,7 @@ impl LanguageClient { self.vim()? .set_highlights(&highlights, "__LCN_DIAGNOSTIC_HIGHLIGHT__")?; - self.draw_virtual_texts(¶ms)?; + self.draw_virtual_texts(params)?; Ok(()) } @@ -1687,7 +1687,7 @@ impl LanguageClient { let filename = self.vim()?.get_filename(params)?; let filename = filename.as_str(); let viewport = self.vim()?.get_viewport(params)?; - let bufnr = self.vim()?.get_bufnr(&filename, params)?; + let bufnr = self.vim()?.get_bufnr(filename, params)?; let namespace_id = self.get_or_create_namespace(&LanguageClientNamespace::VirtualText)?; let is_insert_mode = self.vim()?.get_mode()? == Mode::Insert; if self.get_config(|c| c.hide_virtual_texts_on_insert)? && is_insert_mode { @@ -1978,7 +1978,7 @@ impl LanguageClient { let actions = self.get_state(|state| state.stashed_code_action_actions.clone())?; let idx = actions .iter() - .position(|it| code_action_kind_as_str(&it) == kind && it.title == title); + .position(|it| code_action_kind_as_str(it) == kind && it.title == title); match idx { Some(idx) => self.handle_code_action_selection(&actions, idx)?, diff --git a/src/lsp/text_document.rs b/src/lsp/text_document.rs index a934ba4d6..4ac5b6239 100644 --- a/src/lsp/text_document.rs +++ b/src/lsp/text_document.rs @@ -456,7 +456,7 @@ pub fn document_symbol(lc: &LanguageClient, params: &Value) -> Result { if let Some(children) = &ds.children { for child in children { - walk_document_symbol(buffer, Some(&ds), child); + walk_document_symbol(buffer, Some(ds), child); } } } @@ -766,7 +766,7 @@ pub fn code_lens(lc: &LanguageClient, params: &Value) -> Result { } } - lc.draw_virtual_texts(¶ms)?; + lc.draw_virtual_texts(params)?; Ok(Value::Null) } @@ -881,8 +881,8 @@ fn semantic_tokens_to_highlights( .iter() .enumerate() .filter_map(|(idx, d)| { - let token_modifiers = resolve_token_modifiers(&legend, d.token_modifiers_bitset); - let mapping = resolve_token_mapping(&legend, &mappings, &token_modifiers, d); + let token_modifiers = resolve_token_modifiers(legend, d.token_modifiers_bitset); + let mapping = resolve_token_mapping(legend, &mappings, &token_modifiers, d); let line: u32 = tokens.iter().take(idx + 1).map(|i| i.delta_line).sum(); let mut character_start = d.delta_start; // loop backwards over the results for as long as we find that the previous token also diff --git a/src/types.rs b/src/types.rs index 05ee4168a..7475e6c94 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1082,7 +1082,7 @@ impl ListItem for CodeAction { fn quickfix_item(&self, _: &LanguageClient) -> Result { let text = Some(format!( "{}: {}", - code_action_kind_as_str(&self), + code_action_kind_as_str(self), self.title )); @@ -1099,7 +1099,7 @@ impl ListItem for CodeAction { fn string_item(&self, _: &LanguageClient, _: &str) -> Result { Ok(format!( "{}: {}", - code_action_kind_as_str(&self), + code_action_kind_as_str(self), self.title )) } diff --git a/src/utils.rs b/src/utils.rs index 7e1f07e3c..41999b2c4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -231,7 +231,7 @@ pub fn apply_text_edits( } let mut text = lines.join("\n"); - let mut offset = position_to_offset(&lines, &position); + let mut offset = position_to_offset(lines, position); for (start, end, new_text) in edits_by_index { let start = std::cmp::min(start, text.len()); let end = std::cmp::min(end, text.len()); diff --git a/src/watcher.rs b/src/watcher.rs index 4c021c151..3b2f55745 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -298,7 +298,7 @@ impl FsWatch { }; let (key, filename): (&Path, Option<&str>) = match info { - UnwatchInfo::File(key, filename) => (&key, Some(filename)), + UnwatchInfo::File(key, filename) => (key, Some(filename)), UnwatchInfo::Directory(RecursiveMode::NonRecursive) => (path.as_ref(), None), UnwatchInfo::Directory(RecursiveMode::Recursive) => { self.recursive_watcher