One big cleanup pass of clippy lints

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
ForLoveOfCats 2022-08-10 17:39:24 -04:00 committed by K Simmons
parent e7540d2833
commit 8ba2f77148
138 changed files with 1328 additions and 1366 deletions

View file

@ -216,7 +216,7 @@ impl BufferSearchBar {
fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) {
self.dismissed = true;
for (editor, _) in &self.editors_with_matches {
for editor in self.editors_with_matches.keys() {
if let Some(editor) = editor.upgrade(cx) {
editor.update(cx, |editor, cx| {
editor.clear_background_highlights::<Self>(cx)
@ -450,14 +450,11 @@ impl BufferSearchBar {
event: &editor::Event,
cx: &mut ViewContext<Self>,
) {
match event {
editor::Event::BufferEdited { .. } => {
self.query_contains_error = false;
self.clear_matches(cx);
self.update_matches(true, cx);
cx.notify();
}
_ => {}
if let editor::Event::BufferEdited { .. } = event {
self.query_contains_error = false;
self.clear_matches(cx);
self.update_matches(true, cx);
cx.notify();
}
}
@ -586,7 +583,7 @@ impl BufferSearchBar {
let ranges = self.editors_with_matches.get(&editor.downgrade())?;
let editor = editor.read(cx);
active_match_index(
&ranges,
ranges,
&editor.selections.newest_anchor().head(),
&editor.buffer().read(cx).snapshot(cx),
)
@ -610,7 +607,7 @@ mod tests {
#[gpui::test]
async fn test_search_simple(cx: &mut TestAppContext) {
let fonts = cx.font_cache();
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), theme::Theme::default);
theme.search.match_background = Color::red();
cx.update(|cx| {
let mut settings = Settings::test(cx);
@ -649,7 +646,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.set_query("us", cx);
});
editor.next_notification(&cx).await;
editor.next_notification(cx).await;
editor.update(cx, |editor, cx| {
assert_eq!(
editor.all_background_highlights(cx),
@ -670,7 +667,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.toggle_search_option(SearchOption::CaseSensitive, cx);
});
editor.next_notification(&cx).await;
editor.next_notification(cx).await;
editor.update(cx, |editor, cx| {
assert_eq!(
editor.all_background_highlights(cx),
@ -686,7 +683,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.set_query("or", cx);
});
editor.next_notification(&cx).await;
editor.next_notification(cx).await;
editor.update(cx, |editor, cx| {
assert_eq!(
editor.all_background_highlights(cx),
@ -727,7 +724,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.toggle_search_option(SearchOption::WholeWord, cx);
});
editor.next_notification(&cx).await;
editor.next_notification(cx).await;
editor.update(cx, |editor, cx| {
assert_eq!(
editor.all_background_highlights(cx),

View file

@ -367,7 +367,7 @@ impl ProjectSearchView {
});
// Subcribe to query_editor in order to reraise editor events for workspace item activation purposes
cx.subscribe(&query_editor, |_, _, event, cx| {
cx.emit(ViewEvent::EditorEvent(event.clone()))
cx.emit(ViewEvent::EditorEvent(*event))
})
.detach();
@ -384,7 +384,7 @@ impl ProjectSearchView {
this.update_match_index(cx);
}
// Reraise editor events for workspace item activation purposes
cx.emit(ViewEvent::EditorEvent(event.clone()));
cx.emit(ViewEvent::EditorEvent(*event));
})
.detach();
@ -567,6 +567,12 @@ impl ProjectSearchView {
}
}
impl Default for ProjectSearchBar {
fn default() -> Self {
Self::new()
}
}
impl ProjectSearchBar {
pub fn new() -> Self {
Self {
@ -903,7 +909,7 @@ mod tests {
#[gpui::test]
async fn test_project_search(cx: &mut TestAppContext) {
let fonts = cx.font_cache();
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), theme::Theme::default);
theme.search.match_background = Color::red();
cx.update(|cx| {
let mut settings = Settings::test(cx);
@ -933,7 +939,7 @@ mod tests {
.update(cx, |query_editor, cx| query_editor.set_text("TWO", cx));
search_view.search(cx);
});
search_view.next_notification(&cx).await;
search_view.next_notification(cx).await;
search_view.update(cx, |search_view, cx| {
assert_eq!(
search_view

View file

@ -66,9 +66,9 @@ pub(crate) fn active_match_index(
None
} else {
match ranges.binary_search_by(|probe| {
if probe.end.cmp(&cursor, &*buffer).is_lt() {
if probe.end.cmp(cursor, &*buffer).is_lt() {
Ordering::Less
} else if probe.start.cmp(&cursor, &*buffer).is_gt() {
} else if probe.start.cmp(cursor, &*buffer).is_gt() {
Ordering::Greater
} else {
Ordering::Equal
@ -86,7 +86,7 @@ pub(crate) fn match_index_for_direction(
direction: Direction,
buffer: &MultiBufferSnapshot,
) -> usize {
if ranges[index].start.cmp(&cursor, &buffer).is_gt() {
if ranges[index].start.cmp(cursor, buffer).is_gt() {
if direction == Direction::Prev {
if index == 0 {
index = ranges.len() - 1;
@ -94,7 +94,7 @@ pub(crate) fn match_index_for_direction(
index -= 1;
}
}
} else if ranges[index].end.cmp(&cursor, &buffer).is_lt() {
} else if ranges[index].end.cmp(cursor, buffer).is_lt() {
if direction == Direction::Next {
index = 0;
}