fix: remove unused parameter prefixes and update tail filter implementation

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-29 10:20:15 -03:00
parent 1a4e9d531a
commit 625236f8df
2 changed files with 29 additions and 29 deletions

View File

@@ -25,6 +25,7 @@ impl FilterPlugin for TailBytesFilter {
} }
fn finish(&mut self) -> Result<Vec<u8>> { fn finish(&mut self) -> Result<Vec<u8>> {
// Collect all bytes from the ring buffer
let mut result = Vec::with_capacity(self.ring_buffer.len()); let mut result = Vec::with_capacity(self.ring_buffer.len());
for byte in self.ring_buffer.iter() { for byte in self.ring_buffer.iter() {
result.push(*byte); result.push(*byte);
@@ -61,35 +62,34 @@ impl FilterPlugin for TailLinesFilter {
} }
fn finish(&mut self) -> Result<Vec<u8>> { fn finish(&mut self) -> Result<Vec<u8>> {
// Count lines in the buffer to find where to start // For ring buffer, we can use the iter() method to get all elements
let mut lines_to_keep = std::cmp::min(self.count, self.lines_found); // Since it's a circular buffer, we need to handle the wrap-around
let mut bytes_to_keep = 0; let mut result = Vec::with_capacity(self.ring_buffer.len());
let mut lines_seen = 0;
// Iterate backwards to find the starting point // The ring buffer maintains elements in insertion order
for i in (0..self.ring_buffer.len()).rev() { for byte in self.ring_buffer.iter() {
let index = (self.ring_buffer.write_pos() as isize - 1 - i as isize) result.push(*byte);
.rem_euclid(self.ring_buffer.capacity() as isize) as usize;
let byte = self.ring_buffer[index];
if byte == b'\n' {
lines_seen += 1;
if lines_seen > lines_to_keep {
break;
}
}
bytes_to_keep += 1;
} }
// Extract the relevant bytes // Now, we need to find the last 'count' lines
let start_index = self.ring_buffer.len() - bytes_to_keep; if self.count == 0 {
let mut result = Vec::with_capacity(bytes_to_keep); return Ok(Vec::new());
for i in start_index..self.ring_buffer.len() {
let index = (self.ring_buffer.write_pos() as isize - (self.ring_buffer.len() - i) as isize)
.rem_euclid(self.ring_buffer.capacity() as isize) as usize;
result.push(self.ring_buffer[index]);
} }
Ok(result) // Split into lines and take the last 'count' lines
let text = String::from_utf8_lossy(&result);
let lines: Vec<&str> = text.split('\n').collect();
// Take the last 'count' lines
let start_index = if lines.len() > self.count {
lines.len() - self.count
} else {
0
};
let selected_lines = &lines[start_index..];
let result_text = selected_lines.join("\n");
Ok(result_text.into_bytes())
} }
} }

View File

@@ -147,13 +147,13 @@ impl ItemService {
conn: &Connection, conn: &Connection,
id: i64, id: i64,
head_bytes: Option<usize>, head_bytes: Option<usize>,
_head_words: Option<usize>, head_words: Option<usize>,
head_lines: Option<usize>, head_lines: Option<usize>,
tail_bytes: Option<usize>, tail_bytes: Option<usize>,
_tail_words: Option<usize>, tail_words: Option<usize>,
tail_lines: Option<usize>, tail_lines: Option<usize>,
_line_start: Option<usize>, line_start: Option<usize>,
_line_end: Option<usize>, line_end: Option<usize>,
grep: Option<String>, grep: Option<String>,
) -> Result<(Vec<u8>, String, bool), CoreError> { ) -> Result<(Vec<u8>, String, bool), CoreError> {
// Use streaming approach to handle all filtering options consistently // Use streaming approach to handle all filtering options consistently