docs: Add Rustdoc comments for info and mcp modules and grep plugin

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 14:30:54 -03:00
parent 7ee8ef6ce6
commit f3a4894699
4 changed files with 207 additions and 98 deletions

View File

@@ -4,22 +4,39 @@ use regex::Regex;
/// A filter that matches lines against a regular expression pattern.
///
/// Outputs only lines that match the given regex.
/// Outputs only lines that match the given regex. Uses BufRead for line-by-line processing
/// and preserves original line endings.
///
/// # Fields
///
/// * `regex` - Compiled regex for matching.
#[derive(Debug, Clone)]
pub struct GrepFilter {
regex: Regex,
}
/// Creates a new `GrepFilter` with the specified regex pattern.
///
/// Compiles the pattern using regex crate.
///
/// # Arguments
///
/// * `pattern` - The regular expression pattern (string) used to match lines.
///
/// # Returns
///
/// `Ok(Self)` on success.
///
/// # Errors
///
/// Returns `Err(io::Error::InvalidInput)` if pattern compilation fails (invalid regex).
///
/// # Examples
///
/// ```
/// let filter = GrepFilter::new("error|warn".to_string())?;
/// ```
impl GrepFilter {
/// Creates a new `GrepFilter` with the specified regex pattern.
///
/// # Arguments
///
/// * `pattern` - The regular expression pattern used to match lines.
///
/// # Errors
///
/// Returns an `io::Error` with `InvalidInput` if the regex pattern is invalid.
pub fn new(pattern: String) -> Result<Self> {
let regex = Regex::new(&pattern)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
@@ -29,23 +46,30 @@ impl GrepFilter {
}
}
/// Filters the input by writing only lines that match the regex pattern.
///
/// Reads lines from the input and writes matching lines to the output, preserving newlines.
/// Uses BufReader for efficient line iteration.
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where matching lines are sent.
///
/// # Returns
///
/// `Ok(())` on success.
///
/// # Errors
///
/// Propagates `io::Error` from BufRead lines() or writeln! (e.g., read/write failures, UTF-8 issues).
///
/// # Examples
///
/// ```
/// filter.filter(Box::new(&mut input), Box::new(&mut output))?;
/// ```
impl FilterPlugin for GrepFilter {
/// Filters the input by writing only lines that match the regex pattern.
///
/// Reads lines from the input and writes matching lines to the output, preserving newlines.
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where matching lines are sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
///
/// # Errors
///
/// Propagates `io::Error` from reading lines or writing output.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(&mut *reader);
for line in buf_reader.by_ref().lines() {
@@ -58,12 +82,18 @@ impl FilterPlugin for GrepFilter {
}
/// Clones this filter into a new boxed instance.
///
/// Creates a new GrepFilter with the same regex pattern.
///
/// # Returns
///
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
///
/// Creates a new GrepFilter with the same regex pattern.
///
/// # Returns
///
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
///
/// # Examples
///
/// ```
/// let cloned = filter.clone_box();
/// ```
fn clone_box(&self) -> Box<dyn FilterPlugin> {
Box::new(Self {
regex: self.regex.clone(),
@@ -71,12 +101,20 @@ impl FilterPlugin for GrepFilter {
}
/// Returns the configuration options for this filter.
///
/// The only option is the required "pattern" for the regex.
///
/// # Returns
///
/// A vector of `FilterOption` describing the filter's configurable parameters.
///
/// The only option is the required "pattern" for the regex.
///
/// # Returns
///
/// A vector containing one `FilterOption` for "pattern" (required, no default).
///
/// # Examples
///
/// ```
/// let opts = filter.options();
/// assert_eq!(opts.len(), 1);
/// assert!(opts[0].required);
/// ```
fn options(&self) -> Vec<FilterOption> {
vec![
FilterOption {