Refactor: Fix clippy warnings and introduce AppError
This commit is contained in:
1 parent
3add6c3d31
commit
4e1a633dbd
13 files changed
+129
-103
No files matched your search
@@ -55,13 +55,7 @@ impl McpTool for ReadFileSkeletonHandler {
|
||||
fn extract_skeleton(node: Node, code: &str, out: &mut String, depth: usize) {
|
||||
let kind = node.kind();
|
||||
|
||||
let is_structural = match kind {
|
||||
"use_declaration" | "import_statement" | "import_from_statement" => true,
|
||||
"struct_item" | "enum_item" | "trait_item" | "impl_item" => true,
|
||||
"function_item" | "function_declaration" | "function_definition" | "method_definition" => true,
|
||||
"interface_declaration" | "type_alias_declaration" | "class_declaration" | "class_definition" => true,
|
||||
_ => false,
|
||||
};
|
||||
let is_structural = matches!(kind, "use_declaration" | "import_statement" | "import_from_statement" | "struct_item" | "enum_item" | "trait_item" | "impl_item" | "function_item" | "function_declaration" | "function_definition" | "method_definition" | "interface_declaration" | "type_alias_declaration" | "class_declaration" | "class_definition");
|
||||
|
||||
if is_structural {
|
||||
let indent = " ".repeat(depth);
|
||||
@@ -84,7 +78,7 @@ impl McpTool for ReadFileSkeletonHandler {
|
||||
}
|
||||
|
||||
out.push_str(&indent);
|
||||
out.push_str(&signature.trim());
|
||||
out.push_str(signature.trim());
|
||||
out.push('\n');
|
||||
} else if node.is_named() {
|
||||
let mut cursor = node.walk();
|
||||
|
||||
@@ -27,11 +27,10 @@ impl McpTool for GetActiveWorktreeContextHandler {
|
||||
let repo = git2::Repository::discover(&cwd).map_err(|e| format!("Not in a git repository: {}", e))?;
|
||||
|
||||
let mut branch_name = String::new();
|
||||
if let Ok(head) = repo.head() {
|
||||
if let Some(name) = head.shorthand() {
|
||||
if let Ok(head) = repo.head()
|
||||
&& let Some(name) = head.shorthand() {
|
||||
branch_name = name.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
let mut opts = git2::DiffOptions::new();
|
||||
let mut diff = None;
|
||||
|
||||
@@ -409,7 +409,7 @@ impl McpTool for OmniSearchHandler {
|
||||
));
|
||||
}
|
||||
};
|
||||
println!("OMNI SEARCH MATCHES: {:?}", matches);
|
||||
// tracing::info!("OMNI SEARCH MATCHES: {:?}", matches);
|
||||
let q = req.query.clone();
|
||||
let query_emb = crate::embedding::generate_embedding_async(q.clone()).await.unwrap_or_default();
|
||||
|
||||
@@ -846,7 +846,7 @@ mod tests {
|
||||
.execute(json!({"query": "Omni"}), state.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("OMNI RES: {}", omni_res);
|
||||
// tracing::info!("OMNI RES: {}", omni_res);
|
||||
assert!(
|
||||
omni_res.contains("omni-1"),
|
||||
"omni search should return results containing the task id"
|
||||
|
||||
@@ -32,25 +32,21 @@ impl McpTool for WriteClipboardHandler {
|
||||
let mut msgs = Vec::new();
|
||||
|
||||
// Handle clipboard_win formats (text, html, files)
|
||||
if tool_args.text.is_some() || tool_args.html.is_some() || tool_args.files.is_some() {
|
||||
if let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Some(text) = &tool_args.text {
|
||||
if clipboard_win::set_clipboard_string(text).is_ok() {
|
||||
if (tool_args.text.is_some() || tool_args.html.is_some() || tool_args.files.is_some())
|
||||
&& let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Some(text) = &tool_args.text
|
||||
&& clipboard_win::set_clipboard_string(text).is_ok() {
|
||||
msgs.push("Wrote text");
|
||||
}
|
||||
}
|
||||
if let Some(html) = &tool_args.html {
|
||||
if formats::Html::new().unwrap().write_clipboard(html).is_ok() {
|
||||
if let Some(html) = &tool_args.html
|
||||
&& formats::Html::new().unwrap().write_clipboard(html).is_ok() {
|
||||
msgs.push("Wrote HTML");
|
||||
}
|
||||
}
|
||||
if let Some(files) = &tool_args.files {
|
||||
if raw::set_file_list(files).is_ok() {
|
||||
if let Some(files) = &tool_args.files
|
||||
&& raw::set_file_list(files).is_ok() {
|
||||
msgs.push("Wrote FileList");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle arboard for image
|
||||
if let Some(image_path) = &tool_args.image_path {
|
||||
@@ -106,26 +102,23 @@ impl McpTool for ReadClipboardHandler {
|
||||
let mut out = serde_json::Map::new();
|
||||
|
||||
if let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Ok(text) = get_clipboard::<String, _>(formats::Unicode) {
|
||||
if !text.trim().is_empty() {
|
||||
if let Ok(text) = get_clipboard::<String, _>(formats::Unicode)
|
||||
&& !text.trim().is_empty() {
|
||||
out.insert("text".into(), json!(text));
|
||||
}
|
||||
}
|
||||
if let Ok(html) = get_clipboard::<String, _>(formats::Html::new().unwrap()) {
|
||||
if !html.trim().is_empty() {
|
||||
if let Ok(html) = get_clipboard::<String, _>(formats::Html::new().unwrap())
|
||||
&& !html.trim().is_empty() {
|
||||
out.insert("html".into(), json!(html));
|
||||
}
|
||||
}
|
||||
if let Ok(files) = get_clipboard::<Vec<String>, _>(formats::FileList) {
|
||||
if !files.is_empty() {
|
||||
if let Ok(files) = get_clipboard::<Vec<String>, _>(formats::FileList)
|
||||
&& !files.is_empty() {
|
||||
out.insert("files".into(), json!(files));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mut clipboard) = arboard::Clipboard::new() {
|
||||
if let Ok(image_data) = clipboard.get_image() {
|
||||
if let Some(img) = ImageBuffer::<image::Rgba<u8>, _>::from_raw(
|
||||
if let Ok(mut clipboard) = arboard::Clipboard::new()
|
||||
&& let Ok(image_data) = clipboard.get_image()
|
||||
&& let Some(img) = ImageBuffer::<image::Rgba<u8>, _>::from_raw(
|
||||
image_data.width as u32,
|
||||
image_data.height as u32,
|
||||
image_data.bytes.into_owned(),
|
||||
@@ -152,8 +145,6 @@ impl McpTool for ReadClipboardHandler {
|
||||
out.insert("image_path".into(), json!(file_path.to_string_lossy().to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Value::Object(out))
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user