chore: Fix several style lints (#17488)

It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-06 11:58:39 +02:00 committed by GitHub
parent 93249fc82b
commit e6c1c51b37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
361 changed files with 3530 additions and 3587 deletions

View file

@ -633,7 +633,7 @@ pub fn command_interceptor(mut input: &str, cx: &AppContext) -> Option<CommandIn
let range_prefix = input[0..(input.len() - query.len())].to_string();
let query = query.as_str().trim();
let action = if range.is_some() && query == "" {
let action = if range.is_some() && query.is_empty() {
Some(
GoToLine {
range: range.clone().unwrap(),
@ -681,7 +681,7 @@ pub fn command_interceptor(mut input: &str, cx: &AppContext) -> Option<CommandIn
}
for command in commands(cx).iter() {
if let Some(action) = command.parse(&query, cx) {
if let Some(action) = command.parse(query, cx) {
let string = ":".to_owned() + &range_prefix + command.prefix + command.suffix;
let positions = generate_positions(&string, &(range_prefix + query));
@ -847,7 +847,7 @@ mod test {
cx.simulate_keystrokes("i @ escape");
cx.simulate_keystrokes(": w enter");
assert_eq!(fs.load(&path).await.unwrap(), "@\n");
assert_eq!(fs.load(path).await.unwrap(), "@\n");
fs.as_fake().insert_file(path, b"oops\n".to_vec()).await;
@ -857,12 +857,12 @@ mod test {
assert!(cx.has_pending_prompt());
// "Cancel"
cx.simulate_prompt_answer(0);
assert_eq!(fs.load(&path).await.unwrap(), "oops\n");
assert_eq!(fs.load(path).await.unwrap(), "oops\n");
assert!(!cx.has_pending_prompt());
// force overwrite
cx.simulate_keystrokes(": w ! enter");
assert!(!cx.has_pending_prompt());
assert_eq!(fs.load(&path).await.unwrap(), "@@\n");
assert_eq!(fs.load(path).await.unwrap(), "@@\n");
}
#[gpui::test]

View file

@ -41,7 +41,7 @@ impl Vim {
second_char: char,
cx: &mut ViewContext<Self>,
) {
let text = lookup_digraph(first_char, second_char, &cx);
let text = lookup_digraph(first_char, second_char, cx);
self.pop_operator(cx);
if self.editor_input_enabled() {

View file

@ -634,16 +634,16 @@ impl Motion {
Backspace => (backspace(map, point, times), SelectionGoal::None),
Down {
display_lines: false,
} => up_down_buffer_rows(map, point, goal, times as isize, &text_layout_details),
} => up_down_buffer_rows(map, point, goal, times as isize, text_layout_details),
Down {
display_lines: true,
} => down_display(map, point, goal, times, &text_layout_details),
} => down_display(map, point, goal, times, text_layout_details),
Up {
display_lines: false,
} => up_down_buffer_rows(map, point, goal, 0 - times as isize, &text_layout_details),
} => up_down_buffer_rows(map, point, goal, 0 - times as isize, text_layout_details),
Up {
display_lines: true,
} => up_display(map, point, goal, times, &text_layout_details),
} => up_display(map, point, goal, times, text_layout_details),
Right => (right(map, point, times), SelectionGoal::None),
Space => (space(map, point, times), SelectionGoal::None),
NextWordStart { ignore_punctuation } => (
@ -802,9 +802,9 @@ impl Motion {
StartOfLineDownward => (next_line_start(map, point, times - 1), SelectionGoal::None),
EndOfLineDownward => (last_non_whitespace(map, point, times), SelectionGoal::None),
GoToColumn => (go_to_column(map, point, times), SelectionGoal::None),
WindowTop => window_top(map, point, &text_layout_details, times - 1),
WindowMiddle => window_middle(map, point, &text_layout_details),
WindowBottom => window_bottom(map, point, &text_layout_details, times - 1),
WindowTop => window_top(map, point, text_layout_details, times - 1),
WindowMiddle => window_middle(map, point, text_layout_details),
WindowBottom => window_bottom(map, point, text_layout_details, times - 1),
Jump { line, anchor } => mark::jump_motion(map, *anchor, *line),
ZedSearchResult { new_selections, .. } => {
// There will be only one selection, as
@ -864,7 +864,7 @@ impl Motion {
selection.head(),
selection.goal,
times,
&text_layout_details,
text_layout_details,
) {
let mut selection = selection.clone();
selection.set_head(new_head, goal);
@ -896,11 +896,11 @@ impl Motion {
ignore_punctuation: _,
} = self
{
let start_row = MultiBufferRow(selection.start.to_point(&map).row);
if selection.end.to_point(&map).row > start_row.0 {
let start_row = MultiBufferRow(selection.start.to_point(map).row);
if selection.end.to_point(map).row > start_row.0 {
selection.end =
Point::new(start_row.0, map.buffer_snapshot.line_len(start_row))
.to_display_point(&map)
.to_display_point(map)
}
}
@ -909,8 +909,8 @@ impl Motion {
// becomes inclusive. Example: "}" moves to the first line after a paragraph,
// but "d}" will not include that line.
let mut inclusive = self.inclusive();
let start_point = selection.start.to_point(&map);
let mut end_point = selection.end.to_point(&map);
let start_point = selection.start.to_point(map);
let mut end_point = selection.end.to_point(map);
// DisplayPoint
@ -1108,7 +1108,7 @@ fn up_display(
text_layout_details: &TextLayoutDetails,
) -> (DisplayPoint, SelectionGoal) {
for _ in 0..times {
(point, goal) = movement::up(map, point, goal, true, &text_layout_details);
(point, goal) = movement::up(map, point, goal, true, text_layout_details);
}
(point, goal)
@ -1558,7 +1558,7 @@ fn sentence_backwards(
point: DisplayPoint,
mut times: usize,
) -> DisplayPoint {
let mut start = point.to_point(&map).to_offset(&map.buffer_snapshot);
let mut start = point.to_point(map).to_offset(&map.buffer_snapshot);
let mut chars = map.reverse_buffer_chars_at(start).peekable();
let mut was_newline = map
@ -1585,7 +1585,7 @@ fn sentence_backwards(
return map.clip_point(
start_of_next_sentence
.to_offset(&map.buffer_snapshot)
.to_display_point(&map),
.to_display_point(map),
Bias::Left,
);
}
@ -1596,11 +1596,11 @@ fn sentence_backwards(
was_newline = ch == '\n';
}
return DisplayPoint::zero();
DisplayPoint::zero()
}
fn sentence_forwards(map: &DisplaySnapshot, point: DisplayPoint, mut times: usize) -> DisplayPoint {
let start = point.to_point(&map).to_offset(&map.buffer_snapshot);
let start = point.to_point(map).to_offset(&map.buffer_snapshot);
let mut chars = map.buffer_chars_at(start).peekable();
let mut was_newline = map
@ -1629,7 +1629,7 @@ fn sentence_forwards(map: &DisplaySnapshot, point: DisplayPoint, mut times: usiz
return map.clip_point(
start_of_next_sentence
.to_offset(&map.buffer_snapshot)
.to_display_point(&map),
.to_display_point(map),
Bias::Right,
);
}
@ -1638,7 +1638,7 @@ fn sentence_forwards(map: &DisplaySnapshot, point: DisplayPoint, mut times: usiz
was_newline = ch == '\n' && chars.peek().is_some_and(|(c, _)| *c == '\n');
}
return map.max_point();
map.max_point()
}
fn next_non_blank(map: &DisplaySnapshot, start: usize) -> usize {
@ -1648,16 +1648,16 @@ fn next_non_blank(map: &DisplaySnapshot, start: usize) -> usize {
}
}
return map.buffer_snapshot.len();
map.buffer_snapshot.len()
}
// given the offset after a ., !, or ? find the start of the next sentence.
// if this is not a sentence boundary, returns None.
fn start_of_next_sentence(map: &DisplaySnapshot, end_of_sentence: usize) -> Option<usize> {
let mut chars = map.buffer_chars_at(end_of_sentence);
let chars = map.buffer_chars_at(end_of_sentence);
let mut seen_space = false;
while let Some((char, offset)) = chars.next() {
for (char, offset) in chars {
if !seen_space && (char == ')' || char == ']' || char == '"' || char == '\'') {
continue;
}
@ -1673,7 +1673,7 @@ fn start_of_next_sentence(map: &DisplaySnapshot, end_of_sentence: usize) -> Opti
}
}
return Some(map.buffer_snapshot.len());
Some(map.buffer_snapshot.len())
}
fn start_of_document(map: &DisplaySnapshot, point: DisplayPoint, line: usize) -> DisplayPoint {
@ -1839,7 +1839,7 @@ fn next_line_start(map: &DisplaySnapshot, point: DisplayPoint, times: usize) ->
}
fn previous_line_start(map: &DisplaySnapshot, point: DisplayPoint, times: usize) -> DisplayPoint {
let correct_line = start_of_relative_buffer_row(map, point, (times as isize) * -1);
let correct_line = start_of_relative_buffer_row(map, point, -(times as isize));
first_non_whitespace(map, false, correct_line)
}

View file

@ -139,7 +139,7 @@ impl Vim {
}
Mode::VisualBlock => {
ranges.push(selection.start..selection.end);
if cursor_positions.len() == 0 {
if cursor_positions.is_empty() {
cursor_positions.push(selection.start..selection.start);
}
}
@ -165,7 +165,7 @@ impl Vim {
let text = snapshot
.text_for_range(range.start..range.end)
.flat_map(|s| s.chars())
.flat_map(|c| transform(c))
.flat_map(transform)
.collect::<String>();
buffer.edit([(range, text)], None, cx)

View file

@ -61,7 +61,7 @@ impl Vim {
selection.start.to_offset(map, Bias::Left);
let classifier = map
.buffer_snapshot
.char_classifier_at(selection.start.to_point(&map));
.char_classifier_at(selection.start.to_point(map));
for (ch, offset) in map.buffer_chars_at(start_offset) {
if ch == '\n' || !classifier.is_whitespace(ch) {
break;
@ -136,7 +136,7 @@ fn expand_changed_word_selection(
.next()
.map(|(c, _)| !classifier.is_whitespace(c))
.unwrap_or_default();
return in_word;
in_word
};
if (times.is_none() || times.unwrap() == 1) && is_in_word() {
let next_char = map
@ -164,7 +164,7 @@ fn expand_changed_word_selection(
} else {
Motion::NextWordStart { ignore_punctuation }
};
motion.expand_selection(map, selection, times, false, &text_layout_details)
motion.expand_selection(map, selection, times, false, text_layout_details)
}
}

View file

@ -36,13 +36,13 @@ impl Vim {
if selection.is_empty()
&& map
.buffer_snapshot
.line_len(MultiBufferRow(selection.start.to_point(&map).row))
.line_len(MultiBufferRow(selection.start.to_point(map).row))
== 0
{
selection.end = map
.buffer_snapshot
.clip_point(
Point::new(selection.start.to_point(&map).row + 1, 0),
Point::new(selection.start.to_point(map).row + 1, 0),
Bias::Left,
)
.to_display_point(map)

View file

@ -34,7 +34,7 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let step = if action.step { -1 } else { 0 };
vim.increment(count as i32 * -1, step, cx)
vim.increment(-(count as i32), step, cx)
});
}
@ -47,10 +47,10 @@ impl Vim {
let snapshot = editor.buffer().read(cx).snapshot(cx);
for selection in editor.selections.all_adjusted(cx) {
if !selection.is_empty() {
if vim.mode != Mode::VisualBlock || new_anchors.is_empty() {
new_anchors.push((true, snapshot.anchor_before(selection.start)))
}
if !selection.is_empty()
&& (vim.mode != Mode::VisualBlock || new_anchors.is_empty())
{
new_anchors.push((true, snapshot.anchor_before(selection.start)))
}
for row in selection.start.row..=selection.end.row {
let start = if row == selection.start.row {
@ -80,10 +80,8 @@ impl Vim {
if selection.is_empty() {
new_anchors.push((false, snapshot.anchor_after(range.end)))
}
} else {
if selection.is_empty() {
new_anchors.push((true, snapshot.anchor_after(start)))
}
} else if selection.is_empty() {
new_anchors.push((true, snapshot.anchor_after(start)))
}
}
}
@ -140,7 +138,11 @@ fn find_number(
begin = None;
num = String::new();
}
if num == "0" && ch == 'x' && chars.peek().is_some() && chars.peek().unwrap().is_digit(16) {
if num == "0"
&& ch == 'x'
&& chars.peek().is_some()
&& chars.peek().unwrap().is_ascii_hexdigit()
{
radix = 16;
begin = None;
num = String::new();
@ -156,13 +158,11 @@ fn find_number(
begin = Some(offset);
}
num.push(ch);
} else {
if begin.is_some() {
end = Some(offset);
break;
} else if ch == '\n' {
break;
}
} else if begin.is_some() {
end = Some(offset);
break;
} else if ch == '\n' {
break;
}
offset += ch.len_utf8();
}

View file

@ -102,7 +102,6 @@ impl Vim {
cx,
)
}
return;
} else {
self.update_editor(cx, |_, editor, cx| {
let map = editor.snapshot(cx);

View file

@ -117,7 +117,7 @@ impl Vim {
to_insert = "\n".to_owned() + &to_insert;
}
} else if !line_mode && vim.mode == Mode::VisualLine {
to_insert = to_insert + "\n";
to_insert += "\n";
}
let display_range = if !selection.is_empty() {
@ -432,7 +432,7 @@ mod test {
the laˇzy dog"});
// paste in visual mode
cx.simulate_shared_keystrokes("v i w p").await;
cx.shared_state().await.assert_eq(&indoc! {"
cx.shared_state().await.assert_eq(indoc! {"
The quick brown
the
ˇfox jumps over

View file

@ -178,10 +178,7 @@ impl Vim {
}
globals.last_replayed_register = Some(register);
let mut replayer = globals
.replayer
.get_or_insert_with(|| Replayer::new())
.clone();
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
replayer.replay(repeated_actions, cx);
}
@ -313,10 +310,7 @@ impl Vim {
let globals = Vim::globals(cx);
globals.dot_replaying = true;
let mut replayer = globals
.replayer
.get_or_insert_with(|| Replayer::new())
.clone();
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
replayer.replay(actions, cx);
}
}

View file

@ -298,7 +298,7 @@ impl Vim {
return None;
}
let mut query = action.query.clone();
if query == "" {
if query.is_empty() {
query = search_bar.query(cx);
};
@ -365,7 +365,7 @@ impl Vim {
if replacement.is_case_sensitive {
options.set(SearchOptions::CASE_SENSITIVE, true)
}
let search = if replacement.search == "" {
let search = if replacement.search.is_empty() {
search_bar.query(cx)
} else {
replacement.search
@ -442,7 +442,7 @@ impl Replacement {
for c in chars {
if escaped {
escaped = false;
if phase == 1 && c.is_digit(10) {
if phase == 1 && c.is_ascii_digit() {
buffer.push('$')
// unescape escaped parens
} else if phase == 0 && c == '(' || c == ')' {

View file

@ -121,7 +121,7 @@ impl Vim {
if is_first {
is_first = false;
} else {
text.push_str("\n");
text.push('\n');
}
let initial_len = text.len();
@ -147,7 +147,7 @@ impl Vim {
text.push_str(chunk);
}
if is_last_line {
text.push_str("\n");
text.push('\n');
}
clipboard_selections.push(ClipboardSelection {
len: text.len() - initial_len,

View file

@ -452,10 +452,10 @@ fn argument(
// TODO: Is there any better way to filter out string brackets?
// Used to filter out string brackets
return matches!(
matches!(
buffer.chars_at(open.start).next(),
Some('(' | '[' | '{' | '<' | '|')
);
)
};
// Find the brackets containing the cursor
@ -481,9 +481,7 @@ fn argument(
parent_covers_bracket_range = covers_bracket_range;
// Unable to find a child node with a parent that covers the bracket range, so no argument to select
if cursor.goto_first_child_for_byte(offset).is_none() {
return None;
}
cursor.goto_first_child_for_byte(offset)?;
}
let mut argument_node = cursor.node();
@ -656,7 +654,7 @@ fn is_sentence_end(map: &DisplaySnapshot, offset: usize) -> bool {
}
}
return false;
false
}
/// Expands the passed range to include whitespace on one side or the other in a line. Attempts to add the
@ -669,8 +667,8 @@ fn expand_to_include_whitespace(
let mut range = range.start.to_offset(map, Bias::Left)..range.end.to_offset(map, Bias::Right);
let mut whitespace_included = false;
let mut chars = map.buffer_chars_at(range.end).peekable();
while let Some((char, offset)) = chars.next() {
let chars = map.buffer_chars_at(range.end).peekable();
for (char, offset) in chars {
if char == '\n' && stop_at_newline {
break;
}
@ -1053,7 +1051,7 @@ mod test {
.assert_matches();
}
const PARAGRAPH_EXAMPLES: &[&'static str] = &[
const PARAGRAPH_EXAMPLES: &[&str] = &[
// Single line
"ˇThe quick brown fox jumpˇs over the lazy dogˇ.ˇ",
// Multiple lines without empty lines
@ -1140,7 +1138,7 @@ mod test {
async fn test_visual_paragraph_object(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
const EXAMPLES: &[&'static str] = &[
const EXAMPLES: &[&str] = &[
indoc! {"
ˇThe quick brown
fox jumps over

View file

@ -255,7 +255,7 @@ mod test {
async fn test_replace_mode_undo(cx: &mut gpui::TestAppContext) {
let mut cx: NeovimBackedTestContext = NeovimBackedTestContext::new(cx).await;
const UNDO_REPLACE_EXAMPLES: &[&'static str] = &[
const UNDO_REPLACE_EXAMPLES: &[&str] = &[
// replace undo with single line
"ˇThe quick brown fox jumps over the lazy dog.",
// replace undo with ending line

View file

@ -63,7 +63,7 @@ impl Vim {
object.range(&display_map, selection.clone(), false)
}
SurroundsType::Motion(motion) => {
let range = motion
motion
.range(
&display_map,
selection.clone(),
@ -89,8 +89,7 @@ impl Vim {
);
}
range
});
range
})
}
SurroundsType::Selection => Some(selection.range()),
};
@ -270,17 +269,14 @@ impl Vim {
let mut open_str = pair.start.clone();
let start = offset;
let mut end = start + 1;
match chars_and_offset.peek() {
Some((next_ch, _)) => {
// If the next position is already a space or line break,
// we don't need to splice another space even under around
if surround && !next_ch.is_whitespace() {
open_str.push_str(" ");
} else if !surround && next_ch.to_string() == " " {
end += 1;
}
if let Some((next_ch, _)) = chars_and_offset.peek() {
// If the next position is already a space or line break,
// we don't need to splice another space even under around
if surround && !next_ch.is_whitespace() {
open_str.push(' ');
} else if !surround && next_ch.to_string() == " " {
end += 1;
}
None => {}
}
edits.push((start..end, open_str));
anchors.push(start..start);
@ -300,7 +296,7 @@ impl Vim {
let end = start + 1;
if let Some((next_ch, _)) = reverse_chars_and_offsets.peek() {
if surround && !next_ch.is_whitespace() {
close_str.insert_str(0, " ")
close_str.insert(0, ' ')
} else if !surround && next_ch.to_string() == " " {
start -= 1;
}
@ -317,7 +313,7 @@ impl Vim {
let stable_anchors = editor
.selections
.disjoint_anchors()
.into_iter()
.iter()
.map(|selection| {
let start = selection.start.bias_left(&display_map.buffer_snapshot);
start..start
@ -367,12 +363,12 @@ impl Vim {
&& selection.end.row() == range.end.row())
{
valid = true;
let mut chars_and_offset = display_map
let chars_and_offset = display_map
.buffer_chars_at(
range.start.to_offset(&display_map, Bias::Left),
)
.peekable();
while let Some((ch, offset)) = chars_and_offset.next() {
for (ch, offset) in chars_and_offset {
if ch.to_string() == pair.start {
anchors.push(offset..offset);
break;
@ -392,7 +388,7 @@ impl Vim {
});
});
}
return valid;
valid
}
}
@ -401,7 +397,7 @@ fn find_surround_pair<'a>(pairs: &'a [BracketPair], ch: &str) -> Option<&'a Brac
}
fn all_support_surround_pair() -> Vec<BracketPair> {
return vec![
vec![
BracketPair {
start: "{".into(),
end: "}".into(),
@ -465,7 +461,7 @@ fn all_support_surround_pair() -> Vec<BracketPair> {
surround: true,
newline: false,
},
];
]
}
fn pair_to_object(pair: &BracketPair) -> Option<Object> {

View file

@ -443,15 +443,14 @@ impl Vim {
// Sync editor settings like clip mode
self.sync_vim_settings(cx);
if VimSettings::get_global(cx).toggle_relative_line_numbers {
if self.mode != self.last_mode {
if self.mode == Mode::Insert || self.last_mode == Mode::Insert {
self.update_editor(cx, |vim, editor, cx| {
let is_relative = vim.mode != Mode::Insert;
editor.set_relative_line_number(Some(is_relative), cx)
});
}
}
if VimSettings::get_global(cx).toggle_relative_line_numbers
&& self.mode != self.last_mode
&& (self.mode == Mode::Insert || self.last_mode == Mode::Insert)
{
self.update_editor(cx, |vim, editor, cx| {
let is_relative = vim.mode != Mode::Insert;
editor.set_relative_line_number(Some(is_relative), cx)
});
}
if leave_selections {
@ -510,10 +509,8 @@ impl Vim {
point = movement::left(map, selection.head());
}
selection.collapse_to(point, selection.goal)
} else if !last_mode.is_visual() && mode.is_visual() {
if selection.is_empty() {
selection.end = movement::right(map, selection.start);
}
} else if !last_mode.is_visual() && mode.is_visual() && selection.is_empty() {
selection.end = movement::right(map, selection.start);
}
});
})
@ -526,7 +523,7 @@ impl Vim {
return global_state.recorded_count;
}
let count = if self.post_count == None && self.pre_count == None {
let count = if self.post_count.is_none() && self.pre_count.is_none() {
return None;
} else {
Some(self.post_count.take().unwrap_or(1) * self.pre_count.take().unwrap_or(1))
@ -1046,10 +1043,11 @@ impl Vim {
}
},
Some(Operator::Jump { line }) => self.jump(text, line, cx),
_ => match self.mode {
Mode::Replace => self.multi_replace(text, cx),
_ => {}
},
_ => {
if self.mode == Mode::Replace {
self.multi_replace(text, cx)
}
}
}
}

View file

@ -83,7 +83,7 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
return;
};
let ranges = start
.into_iter()
.iter()
.zip(end)
.zip(reversed)
.map(|((start, end), reversed)| (*start, *end, reversed))
@ -229,7 +229,7 @@ impl Vim {
head = movement::saturating_left(map, head);
}
let Some((new_head, _)) = move_selection(&map, head, goal) else {
let Some((new_head, _)) = move_selection(map, head, goal) else {
return;
};
head = new_head;
@ -479,7 +479,7 @@ impl Vim {
let stable_anchors = editor
.selections
.disjoint_anchors()
.into_iter()
.iter()
.map(|selection| {
let start = selection.start.bias_left(&display_map.buffer_snapshot);
start..start