Skip to content

Commit

Permalink
Correctness fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VentGrey committed Dec 18, 2021
1 parent c8955c6 commit dca01e0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/config/server_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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");
}
}
14 changes: 7 additions & 7 deletions src/language_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl LanguageClient {

pub fn update_state<T>(&self, f: impl FnOnce(&mut State) -> Result<T>) -> Result<T> {
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)?;
Expand All @@ -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)?;
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1674,7 +1674,7 @@ impl LanguageClient {

self.vim()?
.set_highlights(&highlights, "__LCN_DIAGNOSTIC_HIGHLIGHT__")?;
self.draw_virtual_texts(&params)?;
self.draw_virtual_texts(params)?;

Ok(())
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)?,
Expand Down
8 changes: 4 additions & 4 deletions src/lsp/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ pub fn document_symbol(lc: &LanguageClient, params: &Value) -> Result<Value> {

if let Some(children) = &ds.children {
for child in children {
walk_document_symbol(buffer, Some(&ds), child);
walk_document_symbol(buffer, Some(ds), child);
}
}
}
Expand Down Expand Up @@ -766,7 +766,7 @@ pub fn code_lens(lc: &LanguageClient, params: &Value) -> Result<Value> {
}
}

lc.draw_virtual_texts(&params)?;
lc.draw_virtual_texts(params)?;

Ok(Value::Null)
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ impl ListItem for CodeAction {
fn quickfix_item(&self, _: &LanguageClient) -> Result<QuickfixEntry> {
let text = Some(format!(
"{}: {}",
code_action_kind_as_str(&self),
code_action_kind_as_str(self),
self.title
));

Expand All @@ -1099,7 +1099,7 @@ impl ListItem for CodeAction {
fn string_item(&self, _: &LanguageClient, _: &str) -> Result<String> {
Ok(format!(
"{}: {}",
code_action_kind_as_str(&self),
code_action_kind_as_str(self),
self.title
))
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dca01e0

Please sign in to comment.