#[derive(Debug, Deserialize)]
struct ComplexityArgs {
paths: Vec<String>,
#[serde(default)]
top_files: Option<usize>,
#[serde(default)]
threshold: Option<u64>,
}
pub struct ComplexityTool;
impl ComplexityTool {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for ComplexityTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for ComplexityTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.complexity with args: {}", args);
let params: ComplexityArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results =
tool_functions::analyze_complexity(&paths, params.top_files, params.threshold)
.await
.map_err(|e| Error::internal(format!("Complexity analysis failed: {e}")))?;
Ok(results)
}
}