diff --git a/mcp-stdio/src/lib.rs b/mcp-stdio/src/lib.rs index 77d968e..f09bebb 100644 --- a/mcp-stdio/src/lib.rs +++ b/mcp-stdio/src/lib.rs @@ -14,7 +14,9 @@ pub async fn read_mcp_message( } if line.starts_with('{') { - return Some(line.trim_end().to_string()); + let len = line.trim_end().len(); + line.truncate(len); + return Some(line); } let line = line.trim_end(); diff --git a/nvim-core/src/lib.rs b/nvim-core/src/lib.rs index 05de299..fdcfb44 100644 --- a/nvim-core/src/lib.rs +++ b/nvim-core/src/lib.rs @@ -25,7 +25,7 @@ pub async fn send_response(response: JsonRpcResponse) { tracing::info!( "Sending JSON-RPC response (id: {:?}): {}{}", response.id, - &msg[..std::cmp::min(msg.len(), 500)], + &msg[..msg.floor_char_boundary(500)], if msg.len() > 500 { "..." } else { "" } ); // CRITICAL ARCHITECTURAL DECISION: @@ -182,7 +182,7 @@ async fn get_nvim_connection() -> Result, String> { let pending_clone2 = Arc::clone(&pending_requests); tokio::spawn(async move { let mut resp_buf = Vec::new(); - let mut chunk = vec![0u8; 8192]; + let mut chunk = vec![0u8; 65536]; let mut offset = 0; loop { @@ -957,7 +957,7 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { local first = vim.fn.line('w0') local last = vim.fn.line('w$') local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, false) - local res = {{}} + local res = {} for i, line in ipairs(lines) do table.insert(res, tostring(first + i - 1) .. ': ' .. line) end diff --git a/stub/src/main.rs b/stub/src/main.rs index ccfed51..e533873 100644 --- a/stub/src/main.rs +++ b/stub/src/main.rs @@ -98,7 +98,7 @@ fn main() -> Result<(), Box> { ">>> [Stub] Forwarding {} to server (length: {}): {}{}", log_prefix, msg.len(), - &msg[..std::cmp::min(msg.len(), 1000)], + &msg[..msg.floor_char_boundary(1000)], if msg.len() > 1000 { "..." } else { "" } ); if write @@ -120,7 +120,7 @@ fn main() -> Result<(), Box> { "<<< [Stub] Received {} from server (length: {}): {}{}", log_prefix, text.len(), - &text[..std::cmp::min(text.len(), 1000)], + &text[..text.floor_char_boundary(1000)], if text.len() > 1000 { "..." } else { "" } ); use tokio::io::AsyncWriteExt;