refactor: eradicate deprecated tools (sticky_notes, pinned_files, context_workspaces, pr_checklist, preferences) and dead code
This commit is contained in:
1 parent
d80915635f
commit
79209da711
31 files changed
+1230
-3920
No files matched your search
@@ -8,6 +8,31 @@ pub static ACTIVE_SOCKET: LazyLock<Arc<tokio::sync::Mutex<Option<String>>>> =
|
||||
pub static HEADLESS_PROC: LazyLock<Arc<tokio::sync::Mutex<Option<tokio::process::Child>>>> =
|
||||
LazyLock::new(|| Arc::new(tokio::sync::Mutex::new(None)));
|
||||
|
||||
unsafe extern "C" {
|
||||
fn atexit(f: unsafe extern "C" fn()) -> i32;
|
||||
}
|
||||
|
||||
static HEADLESS_PID: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
static ONCE_INIT: std::sync::Once = std::sync::Once::new();
|
||||
|
||||
unsafe extern "C" fn cleanup_on_exit() {
|
||||
let pid = HEADLESS_PID.swap(0, std::sync::atomic::Ordering::SeqCst);
|
||||
if pid != 0 {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = std::process::Command::new("taskkill")
|
||||
.args(["/F", "/T", "/PID", &pid.to_string()])
|
||||
.output();
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let _ = std::process::Command::new("kill")
|
||||
.args(["-9", &pid.to_string()])
|
||||
.output();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
if std::process::Command::new("nvim")
|
||||
.arg("--version")
|
||||
@@ -17,6 +42,10 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
return Err("Error: Neovim is not installed or not in PATH. Cannot execute nvim tool. Fallback to basic terminal tools.".to_string());
|
||||
}
|
||||
|
||||
ONCE_INIT.call_once(|| unsafe {
|
||||
atexit(cleanup_on_exit);
|
||||
});
|
||||
|
||||
#[cfg(windows)]
|
||||
let socket_name = format!(
|
||||
r"\\.\pipe\agy-headless-nvim-{}-{}",
|
||||
@@ -49,6 +78,10 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to spawn headless Neovim: {}", e))?;
|
||||
|
||||
if let Some(id) = child.id() {
|
||||
HEADLESS_PID.store(id, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
|
||||
if let Some(stdout) = child.stdout.take() {
|
||||
let mut reader = tokio::io::BufReader::new(stdout);
|
||||
let mut ready_line = String::new();
|
||||
@@ -60,6 +93,7 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
{
|
||||
Ok(Ok(_)) => {
|
||||
if ready_line.trim() != "READY" {
|
||||
HEADLESS_PID.store(0, std::sync::atomic::Ordering::SeqCst);
|
||||
let _ = child.kill().await;
|
||||
return Err(format!(
|
||||
"Headless Neovim child output unexpected banner: {:?}",
|
||||
@@ -68,6 +102,7 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
}
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
HEADLESS_PID.store(0, std::sync::atomic::Ordering::SeqCst);
|
||||
let _ = child.kill().await;
|
||||
return Err(format!(
|
||||
"Failed to read readiness from headless Neovim: {}",
|
||||
@@ -75,6 +110,7 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
));
|
||||
}
|
||||
Err(_) => {
|
||||
HEADLESS_PID.store(0, std::sync::atomic::Ordering::SeqCst);
|
||||
let _ = child.kill().await;
|
||||
return Err("Timeout waiting for headless Neovim to become ready".to_string());
|
||||
}
|
||||
@@ -96,6 +132,7 @@ pub async fn spawn_headless_nvim() -> Result<String, String> {
|
||||
}
|
||||
|
||||
pub async fn kill_headless_nvim() {
|
||||
HEADLESS_PID.store(0, std::sync::atomic::Ordering::SeqCst);
|
||||
let child_to_kill = {
|
||||
let mut proc_lock = HEADLESS_PROC.lock().await;
|
||||
proc_lock.take()
|
||||
|
||||
@@ -167,6 +167,43 @@ async fn get_socket_path() -> Result<String, String> {
|
||||
}
|
||||
Err("Could not find Neovim socket".to_string())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
async fn read_active_socket_file() -> Result<String, String> {
|
||||
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 {
|
||||
let p = content.trim().to_string();
|
||||
if !p.is_empty() {
|
||||
let candidate = if p.starts_with(r"\\.\pipe\") {
|
||||
p
|
||||
} else if p.starts_with("nvim.") {
|
||||
format!(r"\\.\pipe\{p}")
|
||||
} else {
|
||||
p
|
||||
};
|
||||
return Ok(candidate);
|
||||
}
|
||||
}
|
||||
Err("Missing active_nvim.txt".to_string())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
async fn read_active_socket_file() -> Result<String, String> {
|
||||
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() {
|
||||
return Ok(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err("Missing active_nvim.txt".to_string())
|
||||
}
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
@@ -222,6 +259,24 @@ fn handle_nvim_notification(params: &[rmpv::Value]) {
|
||||
}
|
||||
|
||||
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
// Fast path: If NVIM_CONN is already active and healthy, check if active_nvim.txt matches
|
||||
// without spawning any external nvim.exe child process!
|
||||
{
|
||||
let conn_lock = NVIM_CONN.lock().await;
|
||||
if let Some(sender) = conn_lock.as_ref() {
|
||||
if !sender.is_closed() {
|
||||
let active_lock = ACTIVE_SOCKET.lock().await;
|
||||
if let Some(ref current_socket) = *active_lock {
|
||||
if let Ok(target) = read_active_socket_file().await {
|
||||
if !target.is_empty() && &target == current_socket {
|
||||
return Ok(sender.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let interactive_socket = get_socket_path().await.ok();
|
||||
let mut should_kill_headless = false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user