chore: rustfmt, clippy lints and code tidying
This commit is contained in:
1 parent
3716c3e698
commit
1752753fcc
19 files changed
+1273
-738
No files matched your search
@@ -1,6 +1,5 @@
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::Value;
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
fn send_message(stdin: &mut std::process::ChildStdin, msg: Value) {
|
||||
let s = serde_json::to_string(&msg).unwrap();
|
||||
@@ -12,7 +11,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 +26,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())
|
||||
}
|
||||
|
||||
@@ -46,7 +45,10 @@ fn test_mcp_initialization_and_tools_list() {
|
||||
let mut nvim_exe = std::env::current_exe().unwrap();
|
||||
nvim_exe.pop();
|
||||
nvim_exe.pop();
|
||||
nvim_exe.push(format!("mcp-memory-linux-nvim{}", std::env::consts::EXE_SUFFIX));
|
||||
nvim_exe.push(format!(
|
||||
"mcp-memory-linux-nvim{}",
|
||||
std::env::consts::EXE_SUFFIX
|
||||
));
|
||||
|
||||
let mut child = Command::new(&nvim_exe)
|
||||
.stdin(Stdio::piped())
|
||||
@@ -88,12 +90,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!({}));
|
||||
@@ -105,17 +107,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");
|
||||
|
||||
|
||||
Reference in new issue
Block a user