chore: rustfmt, clippy lints and code tidying

This commit is contained in:
Riz Ashraf committed 2026-09-17 15:35:41 +01:00
1 parent 3716c3e698
commit 1752753fcc
19 files changed
+1273 -738

No files matched your search

+14 -9
View File
@@ -2,19 +2,24 @@ use std::process::Command;
fn main() {
let git_hash = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.unwrap_or_else(|| "unknown".to_string());
let git_date = Command::new("git")
.args(&["log", "-1", "--format=%cd", "--date=format:%Y.%m.%d"])
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.unwrap_or_else(|| "unknown".to_string());
let version = format!("{} ({} {})", env!("CARGO_PKG_VERSION"), git_date.trim(), git_hash.trim());
let git_date = Command::new("git")
.args(["log", "-1", "--format=%cd", "--date=format:%Y.%m.%d"])
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.unwrap_or_else(|| "unknown".to_string());
let version = format!(
"{} ({} {})",
env!("CARGO_PKG_VERSION"),
git_date.trim(),
git_hash.trim()
);
println!("cargo:rustc-env=APP_VERSION={}", version);
}
+22 -17
View File
@@ -12,7 +12,7 @@ fn send_message(stdin: &mut std::process::ChildStdin, msg: Value) {
fn read_message(stdout: &mut std::process::ChildStdout) -> Option<Value> {
let mut reader = BufReader::new(stdout);
let mut length = 0;
// Read headers
loop {
let mut line = String::new();
@@ -27,16 +27,16 @@ fn read_message(stdout: &mut std::process::ChildStdout) -> Option<Value> {
length = len_str.parse().unwrap_or(0);
}
}
if length == 0 {
return None;
}
// Read body
let mut buf = vec![0u8; length];
reader.read_exact(&mut buf).unwrap();
let body_str = String::from_utf8_lossy(&buf);
Some(serde_json::from_str(&body_str).unwrap())
}
@@ -87,12 +87,12 @@ fn test_mcp_initialization_and_tools_list() {
let s = serde_json::to_string(&init_req).unwrap();
stdin.write_all(format!("{}\n", s).as_bytes()).unwrap();
stdin.flush().unwrap();
let init_resp = read_message(&mut stdout).expect("Failed to read initialize response");
assert_eq!(init_resp["jsonrpc"], "2.0");
assert_eq!(init_resp["id"], 1);
// Verify capabilities
let capabilities = &init_resp["result"]["capabilities"];
assert_eq!(capabilities["tools"], serde_json::json!({}));
@@ -104,17 +104,19 @@ fn test_mcp_initialization_and_tools_list() {
"params": {},
"id": 2
});
send_message(&mut stdin, tools_req);
let tools_resp = read_message(&mut stdout).expect("Failed to read tools/list response");
assert_eq!(tools_resp["jsonrpc"], "2.0");
assert_eq!(tools_resp["id"], 2);
let tools = tools_resp["result"]["tools"].as_array().expect("result.tools must be an array");
let tools = tools_resp["result"]["tools"]
.as_array()
.expect("result.tools must be an array");
assert!(!tools.is_empty(), "Server must expose at least one tool");
let has_get_active_buffer = tools.iter().any(|t| t["name"] == "nvim_get_active_buffer");
assert!(has_get_active_buffer, "Missing nvim_get_active_buffer tool");
@@ -130,14 +132,17 @@ fn test_mcp_initialization_and_tools_list() {
},
"id": 3
});
send_message(&mut stdin, call_req);
let call_resp = read_message(&mut stdout).expect("Failed to read tools/call response");
assert_eq!(call_resp["jsonrpc"], "2.0");
assert_eq!(call_resp["id"], 3);
assert!(call_resp.get("error").is_some(), "Expected an error response since Neovim shouldn't be running");
assert!(
call_resp.get("error").is_some(),
"Expected an error response since Neovim shouldn't be running"
);
assert_eq!(call_resp["error"]["code"], -32603); // Internal Error
child.kill().expect("Failed to kill child");