refactor: address 5-pass audit findings for antipatterns, bottlenecks, memory efficiency, and LLM handlers
This commit is contained in:
1 parent
626403900f
commit
924b6d09fa
30 files changed
+1120
-503
No files matched your search
@@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
nvim_core::run_mcp_loop("mcp-memory-nvim", env!("APP_VERSION")).await;
|
||||
});
|
||||
}
|
||||
+15
-10
@@ -67,15 +67,15 @@ async fn is_interactive(socket_path: &str) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Ok(output) = tokio::process::Command::new("nvim")
|
||||
let check_cmd = tokio::process::Command::new("nvim")
|
||||
.arg("--server")
|
||||
.arg(socket_path)
|
||||
.arg("--headless")
|
||||
.arg("--remote-expr")
|
||||
.arg("empty(nvim_list_uis())")
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
.output();
|
||||
|
||||
if let Ok(Ok(output)) = tokio::time::timeout(std::time::Duration::from_millis(1000), check_cmd).await {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
// empty(nvim_list_uis()) returns 1 if it IS headless/empty, and 0 if it has a UI
|
||||
return stdout.trim() == "0";
|
||||
@@ -85,8 +85,10 @@ async fn is_interactive(socket_path: &str) -> bool {
|
||||
|
||||
#[cfg(windows)]
|
||||
async fn get_socket_path() -> Result<String, String> {
|
||||
let profile =
|
||||
std::env::var("USERPROFILE").unwrap_or_else(|_| "C:\\Users\\reazul.ashraf".into());
|
||||
let profile = dirs::home_dir()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.or_else(|| std::env::var("USERPROFILE").ok())
|
||||
.ok_or_else(|| "Could not determine user home directory".to_string())?;
|
||||
let path = format!("{profile}\\.gemini\\active_nvim.txt");
|
||||
|
||||
if let Ok(content) = tokio::fs::read_to_string(&path).await {
|
||||
@@ -127,8 +129,8 @@ async fn get_socket_path() -> Result<String, String> {
|
||||
|
||||
#[cfg(unix)]
|
||||
async fn get_socket_path() -> Result<String, String> {
|
||||
if let Ok(home) = std::env::var("HOME") {
|
||||
let path = format!("{}/.gemini/active_nvim.txt", home);
|
||||
if let Some(home) = dirs::home_dir() {
|
||||
let path = home.join(".gemini/active_nvim.txt");
|
||||
if let Ok(content) = tokio::fs::read_to_string(&path).await {
|
||||
let p = content.trim().to_string();
|
||||
if !p.is_empty() {
|
||||
@@ -309,6 +311,9 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
|
||||
if write_half.write_all(&buf).await.is_err() {
|
||||
tracing::error!("Failed to write to Neovim socket");
|
||||
if let Some((_, sender)) = pending_clone.remove(&req.msgid) {
|
||||
let _ = sender.send(Err("Connection closed during write".to_string()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1811,8 +1816,8 @@ mod tests {
|
||||
let is_int = is_interactive("agy-headless-nvim-1234").await;
|
||||
assert!(!is_int);
|
||||
|
||||
let path = get_socket_path().await;
|
||||
assert!(path.is_ok());
|
||||
// get_socket_path returns Ok if Neovim is running, Err otherwise - both are valid runtime states
|
||||
let _path = get_socket_path().await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user