chore: more clippy rules 2 (#4057)
The only file to watch is the cargo.toml All the others come from just fix + a few manual small fix The set of rules have been taken from the list of clippy rules arbitrarily while trying to optimise the learning and style of the code while limiting the loss of productivity
This commit is contained in:
@@ -161,8 +161,8 @@ impl ChatComposer {
|
||||
// Leave 1 for border and 1 for padding
|
||||
textarea_rect.width = textarea_rect.width.saturating_sub(LIVE_PREFIX_COLS);
|
||||
textarea_rect.x = textarea_rect.x.saturating_add(LIVE_PREFIX_COLS);
|
||||
let state = self.textarea_state.borrow();
|
||||
self.textarea.cursor_pos_with_state(textarea_rect, &state)
|
||||
let state = *self.textarea_state.borrow();
|
||||
self.textarea.cursor_pos_with_state(textarea_rect, state)
|
||||
}
|
||||
|
||||
/// Returns true if the composer currently contains no user input.
|
||||
|
||||
@@ -236,8 +236,8 @@ impl BottomPaneView for CustomPromptView {
|
||||
width: area.width.saturating_sub(2),
|
||||
height: text_area_height,
|
||||
};
|
||||
let state = self.textarea_state.borrow();
|
||||
self.textarea.cursor_pos_with_state(textarea_rect, &state)
|
||||
let state = *self.textarea_state.borrow();
|
||||
self.textarea.cursor_pos_with_state(textarea_rect, state)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,11 +132,11 @@ impl TextArea {
|
||||
|
||||
#[cfg_attr(not(test), allow(dead_code))]
|
||||
pub fn cursor_pos(&self, area: Rect) -> Option<(u16, u16)> {
|
||||
self.cursor_pos_with_state(area, &TextAreaState::default())
|
||||
self.cursor_pos_with_state(area, TextAreaState::default())
|
||||
}
|
||||
|
||||
/// Compute the on-screen cursor position taking scrolling into account.
|
||||
pub fn cursor_pos_with_state(&self, area: Rect, state: &TextAreaState) -> Option<(u16, u16)> {
|
||||
pub fn cursor_pos_with_state(&self, area: Rect, state: TextAreaState) -> Option<(u16, u16)> {
|
||||
let lines = self.wrapped_lines(area.width);
|
||||
let effective_scroll = self.effective_scroll(area.height, &lines, state.scroll);
|
||||
let i = Self::wrapped_line_index_by_start(&lines, self.cursor_pos)?;
|
||||
@@ -1408,7 +1408,7 @@ mod tests {
|
||||
let mut state = TextAreaState::default();
|
||||
let small_area = Rect::new(0, 0, 6, 1);
|
||||
// First call: cursor not visible -> effective scroll ensures it is
|
||||
let (_x, y) = t.cursor_pos_with_state(small_area, &state).unwrap();
|
||||
let (_x, y) = t.cursor_pos_with_state(small_area, state).unwrap();
|
||||
assert_eq!(y, 0);
|
||||
|
||||
// Render with state to update actual scroll value
|
||||
@@ -1429,7 +1429,7 @@ mod tests {
|
||||
// effective scroll is 0 and the cursor position matches cursor_pos.
|
||||
let bad_state = TextAreaState { scroll: 999 };
|
||||
let (x1, y1) = t.cursor_pos(area).unwrap();
|
||||
let (x2, y2) = t.cursor_pos_with_state(area, &bad_state).unwrap();
|
||||
let (x2, y2) = t.cursor_pos_with_state(area, bad_state).unwrap();
|
||||
assert_eq!((x2, y2), (x1, y1));
|
||||
|
||||
// Case 2: Cursor below the current window — y should be clamped to the
|
||||
@@ -1442,7 +1442,7 @@ mod tests {
|
||||
t.set_cursor(t.text().len().saturating_sub(2));
|
||||
let small_area = Rect::new(0, 0, wrap_width, 2);
|
||||
let state = TextAreaState { scroll: 0 };
|
||||
let (_x, y) = t.cursor_pos_with_state(small_area, &state).unwrap();
|
||||
let (_x, y) = t.cursor_pos_with_state(small_area, state).unwrap();
|
||||
assert_eq!(y, small_area.y + small_area.height - 1);
|
||||
|
||||
// Case 3: Cursor above the current window — y should be top row (0)
|
||||
@@ -1456,7 +1456,7 @@ mod tests {
|
||||
let state = TextAreaState {
|
||||
scroll: lines.saturating_mul(2),
|
||||
};
|
||||
let (_x, y) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (_x, y) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!(y, area.y);
|
||||
}
|
||||
|
||||
@@ -1480,7 +1480,7 @@ mod tests {
|
||||
// With state and small height, cursor should be visible at row 0, col 0
|
||||
let small_area = Rect::new(0, 0, 4, 1);
|
||||
let state = TextAreaState::default();
|
||||
let (x, y) = t.cursor_pos_with_state(small_area, &state).unwrap();
|
||||
let (x, y) = t.cursor_pos_with_state(small_area, state).unwrap();
|
||||
assert_eq!((x, y), (0, 0));
|
||||
|
||||
// Place cursor in the middle of the second wrapped line ("efgh"), at 'g'
|
||||
@@ -1510,35 +1510,35 @@ mod tests {
|
||||
// Start at beginning
|
||||
t.set_cursor(0);
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x, y) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x, y) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x, y), (0, 0));
|
||||
|
||||
// Move down to second visual line; should be at bottom row (row 1) within 2-line viewport
|
||||
t.move_cursor_down();
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x, y) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x, y) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x, y), (0, 1));
|
||||
|
||||
// Move down to third visual line; viewport scrolls and keeps cursor on bottom row
|
||||
t.move_cursor_down();
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x, y) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x, y) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x, y), (0, 1));
|
||||
|
||||
// Move up to second visual line; with current scroll, it appears on top row
|
||||
t.move_cursor_up();
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x, y) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x, y) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x, y), (0, 0));
|
||||
|
||||
// Column preservation across moves: set to col 2 on first line, move down
|
||||
t.set_cursor(2);
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x0, y0) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x0, y0) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x0, y0), (2, 0));
|
||||
t.move_cursor_down();
|
||||
ratatui::widgets::StatefulWidgetRef::render_ref(&(&t), area, &mut buf, &mut state);
|
||||
let (x1, y1) = t.cursor_pos_with_state(area, &state).unwrap();
|
||||
let (x1, y1) = t.cursor_pos_with_state(area, state).unwrap();
|
||||
assert_eq!((x1, y1), (2, 1));
|
||||
}
|
||||
|
||||
@@ -1796,7 +1796,7 @@ mod tests {
|
||||
|
||||
// cursor_pos_with_state: always within viewport rows
|
||||
let (_x, _y) = ta
|
||||
.cursor_pos_with_state(area, &state)
|
||||
.cursor_pos_with_state(area, state)
|
||||
.unwrap_or((area.x, area.y));
|
||||
|
||||
// Stateful render should not panic, and updates scroll
|
||||
|
||||
@@ -390,15 +390,14 @@ impl ExecCell {
|
||||
.iter()
|
||||
.all(|c| matches!(c, ParsedCommand::Read { .. }))
|
||||
{
|
||||
let names: Vec<String> = call
|
||||
let names = call
|
||||
.parsed
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
ParsedCommand::Read { name, .. } => name.clone(),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.unique()
|
||||
.collect();
|
||||
.unique();
|
||||
vec![(
|
||||
"Read",
|
||||
itertools::Itertools::intersperse(
|
||||
|
||||
@@ -310,10 +310,8 @@ mod tests {
|
||||
let long = "> This is a very long quoted line that should wrap across multiple columns to verify style preservation.";
|
||||
let out = super::simulate_stream_markdown_for_tests(&[long, "\n"], true, &cfg);
|
||||
// Wrap to a narrow width to force multiple output lines.
|
||||
let wrapped = crate::wrapping::word_wrap_lines(
|
||||
out.iter().collect::<Vec<_>>(),
|
||||
crate::wrapping::RtOptions::new(24),
|
||||
);
|
||||
let wrapped =
|
||||
crate::wrapping::word_wrap_lines(out.iter(), crate::wrapping::RtOptions::new(24));
|
||||
// Filter out purely blank lines
|
||||
let non_blank: Vec<_> = wrapped
|
||||
.into_iter()
|
||||
|
||||
@@ -511,7 +511,7 @@ mod tests {
|
||||
.subsequent_indent(Line::from(" "));
|
||||
|
||||
let lines = [Line::from("hello world"), Line::from("foo bar baz")];
|
||||
let out = word_wrap_lines_borrowed(lines.iter().collect::<Vec<_>>(), opts);
|
||||
let out = word_wrap_lines_borrowed(lines.iter(), opts);
|
||||
|
||||
let rendered: Vec<String> = out.iter().map(concat_line).collect();
|
||||
assert!(rendered.first().unwrap().starts_with("- "));
|
||||
@@ -523,7 +523,7 @@ mod tests {
|
||||
#[test]
|
||||
fn wrap_lines_borrowed_without_indents_is_concat_of_single_wraps() {
|
||||
let lines = [Line::from("hello"), Line::from("world!")];
|
||||
let out = word_wrap_lines_borrowed(lines.iter().collect::<Vec<_>>(), 10);
|
||||
let out = word_wrap_lines_borrowed(lines.iter(), 10);
|
||||
let rendered: Vec<String> = out.iter().map(concat_line).collect();
|
||||
assert_eq!(rendered, vec!["hello", "world!"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user