perf: fix slice boundary panics, eliminate string allocation in stdio reader, fix lua table nesting bug, and optimize nvim socket chunk size
This commit is contained in:
1 parent
e215720416
commit
02f40604e1
3 files changed
+8
-6
No files matched your search
@@ -14,7 +14,9 @@ pub async fn read_mcp_message<R: tokio::io::AsyncRead + Unpin>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if line.starts_with('{') {
|
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();
|
let line = line.trim_end();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub async fn send_response(response: JsonRpcResponse) {
|
|||||||
tracing::info!(
|
tracing::info!(
|
||||||
"Sending JSON-RPC response (id: {:?}): {}{}",
|
"Sending JSON-RPC response (id: {:?}): {}{}",
|
||||||
response.id,
|
response.id,
|
||||||
&msg[..std::cmp::min(msg.len(), 500)],
|
&msg[..msg.floor_char_boundary(500)],
|
||||||
if msg.len() > 500 { "..." } else { "" }
|
if msg.len() > 500 { "..." } else { "" }
|
||||||
);
|
);
|
||||||
// CRITICAL ARCHITECTURAL DECISION:
|
// CRITICAL ARCHITECTURAL DECISION:
|
||||||
@@ -182,7 +182,7 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
|||||||
let pending_clone2 = Arc::clone(&pending_requests);
|
let pending_clone2 = Arc::clone(&pending_requests);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut resp_buf = Vec::new();
|
let mut resp_buf = Vec::new();
|
||||||
let mut chunk = vec![0u8; 8192];
|
let mut chunk = vec![0u8; 65536];
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@@ -957,7 +957,7 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) {
|
|||||||
local first = vim.fn.line('w0')
|
local first = vim.fn.line('w0')
|
||||||
local last = vim.fn.line('w$')
|
local last = vim.fn.line('w$')
|
||||||
local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, false)
|
local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, false)
|
||||||
local res = {{}}
|
local res = {}
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
table.insert(res, tostring(first + i - 1) .. ': ' .. line)
|
table.insert(res, tostring(first + i - 1) .. ': ' .. line)
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -98,7 +98,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
">>> [Stub] Forwarding {} to server (length: {}): {}{}",
|
">>> [Stub] Forwarding {} to server (length: {}): {}{}",
|
||||||
log_prefix,
|
log_prefix,
|
||||||
msg.len(),
|
msg.len(),
|
||||||
&msg[..std::cmp::min(msg.len(), 1000)],
|
&msg[..msg.floor_char_boundary(1000)],
|
||||||
if msg.len() > 1000 { "..." } else { "" }
|
if msg.len() > 1000 { "..." } else { "" }
|
||||||
);
|
);
|
||||||
if write
|
if write
|
||||||
@@ -120,7 +120,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
"<<< [Stub] Received {} from server (length: {}): {}{}",
|
"<<< [Stub] Received {} from server (length: {}): {}{}",
|
||||||
log_prefix,
|
log_prefix,
|
||||||
text.len(),
|
text.len(),
|
||||||
&text[..std::cmp::min(text.len(), 1000)],
|
&text[..text.floor_char_boundary(1000)],
|
||||||
if text.len() > 1000 { "..." } else { "" }
|
if text.len() > 1000 { "..." } else { "" }
|
||||||
);
|
);
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|||||||
Reference in new issue
Block a user