fix: remove unused imports and fix tail filter errors
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -29,19 +29,21 @@ impl FilterPlugin for GrepFilter {
|
||||
// Split into lines
|
||||
for (i, &byte) in self.buffer.iter().enumerate() {
|
||||
if byte == b'\n' {
|
||||
lines.push(&self.buffer[start..=i]);
|
||||
let line = &self.buffer[start..=i];
|
||||
lines.push(line.to_vec());
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the remaining data in buffer
|
||||
self.buffer.drain(0..start);
|
||||
let remaining = self.buffer.split_off(start);
|
||||
self.buffer = remaining;
|
||||
|
||||
// Filter lines that match the regex
|
||||
for line in lines {
|
||||
if let Ok(line_str) = std::str::from_utf8(line) {
|
||||
if let Ok(line_str) = std::str::from_utf8(&line) {
|
||||
if self.regex.is_match(line_str) {
|
||||
result.extend_from_slice(line);
|
||||
result.extend_from_slice(&line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use std::io::{Read, Result};
|
||||
use regex::Regex;
|
||||
use ringbuf::HeapRb;
|
||||
use std::io::Result;
|
||||
|
||||
pub mod head;
|
||||
pub mod tail;
|
||||
@@ -43,7 +41,7 @@ impl FilterChain {
|
||||
Ok(current_data)
|
||||
}
|
||||
|
||||
pub fn finish(&mut self) -> Result<Vec<u8>> {
|
||||
fn finish(&mut self) -> Result<Vec<u8>> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
// Process each plugin's finish method and collect results
|
||||
@@ -73,7 +71,7 @@ pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
|
||||
($prefix:expr, $suffix:expr, $constructor:expr) => {{
|
||||
if let Some(stripped) = part.strip_prefix($prefix).and_then(|s| s.strip_suffix($suffix)) {
|
||||
let count = utils::parse_number(stripped)?;
|
||||
chain.add_plugin($constructor(count));
|
||||
chain.add_plugin(Box::new($constructor(count)));
|
||||
continue;
|
||||
}
|
||||
}};
|
||||
@@ -88,12 +86,12 @@ pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
|
||||
}
|
||||
|
||||
// Handle other filters using the macro
|
||||
parse_filter!("head_bytes(", ")", |count| Box::new(head::HeadBytesFilter::new(count)));
|
||||
parse_filter!("head_lines(", ")", |count| Box::new(head::HeadLinesFilter::new(count)));
|
||||
parse_filter!("tail_bytes(", ")", |count| Box::new(tail::TailBytesFilter::new(count)));
|
||||
parse_filter!("tail_lines(", ")", |count| Box::new(tail::TailLinesFilter::new(count)));
|
||||
parse_filter!("skip_bytes(", ")", |count| Box::new(skip::SkipBytesFilter::new(count)));
|
||||
parse_filter!("skip_lines(", ")", |count| Box::new(skip::SkipLinesFilter::new(count)));
|
||||
parse_filter!("head_bytes(", ")", head::HeadBytesFilter::new);
|
||||
parse_filter!("head_lines(", ")", head::HeadLinesFilter::new);
|
||||
parse_filter!("tail_bytes(", ")", tail::TailBytesFilter::new);
|
||||
parse_filter!("tail_lines(", ")", tail::TailLinesFilter::new);
|
||||
parse_filter!("skip_bytes(", ")", skip::SkipBytesFilter::new);
|
||||
parse_filter!("skip_lines(", ")", skip::SkipLinesFilter::new);
|
||||
|
||||
// If we get here, the filter wasn't recognized
|
||||
return Err(std::io::Error::new(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::FilterPlugin;
|
||||
use std::io::Result;
|
||||
use ringbuf::HeapRb;
|
||||
use ringbuf::{HeapRb, Rb};
|
||||
|
||||
pub struct TailBytesFilter {
|
||||
ring_buffer: HeapRb<u8>,
|
||||
@@ -8,11 +8,11 @@ pub struct TailBytesFilter {
|
||||
}
|
||||
|
||||
impl TailBytesFilter {
|
||||
pub fn new(count: usize) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pub fn new(count: usize) -> Self {
|
||||
Self {
|
||||
ring_buffer: HeapRb::new(count),
|
||||
count,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ pub struct TailLinesFilter {
|
||||
}
|
||||
|
||||
impl TailLinesFilter {
|
||||
pub fn new(count: usize) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pub fn new(count: usize) -> Self {
|
||||
Self {
|
||||
ring_buffer: HeapRb::new(count * 256), // Estimate 256 bytes per line
|
||||
count,
|
||||
lines_found: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,5 +31,5 @@ pub fn create_filter_chain(filter_str: &str) -> Result<Option<super::FilterChain
|
||||
/// Helper function to parse a number from a string with error handling
|
||||
pub fn parse_number<T: std::str::FromStr>(s: &str) -> Result<T> {
|
||||
s.parse::<T>()
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))
|
||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid number"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user