chore: fix formatting and clippy lints
This commit is contained in:
1 parent
8952bd5399
commit
9d9e959744
35 files changed
+1091
-582
No files matched your search
+39
-29
@@ -214,7 +214,7 @@ pub struct NvimRequest {
|
||||
pub reply: oneshot::Sender<Result<rmpv::Value, String>>,
|
||||
}
|
||||
|
||||
use std::sync::atomic::{AtomicU32, AtomicU64, AtomicU8, Ordering};
|
||||
use std::sync::atomic::{AtomicU8, AtomicU32, AtomicU64, Ordering};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CircuitState {
|
||||
@@ -275,7 +275,9 @@ impl NvimCircuitBreaker {
|
||||
|
||||
pub fn record_success(&self) {
|
||||
self.consecutive_failures.store(0, Ordering::SeqCst);
|
||||
let prev = self.state.swap(CircuitState::Closed as u8, Ordering::SeqCst);
|
||||
let prev = self
|
||||
.state
|
||||
.swap(CircuitState::Closed as u8, Ordering::SeqCst);
|
||||
if prev != CircuitState::Closed as u8 {
|
||||
tracing::info!("Neovim RPC circuit breaker transitioned to Closed (recovered)");
|
||||
}
|
||||
@@ -299,7 +301,8 @@ impl NvimCircuitBreaker {
|
||||
|
||||
pub fn reset(&self) {
|
||||
self.consecutive_failures.store(0, Ordering::SeqCst);
|
||||
self.state.store(CircuitState::Closed as u8, Ordering::SeqCst);
|
||||
self.state
|
||||
.store(CircuitState::Closed as u8, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,18 +377,15 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
// 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() {
|
||||
if let Some(sender) = conn_lock.as_ref()
|
||||
&& !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 {
|
||||
if let Some(ref current_socket) = *active_lock
|
||||
&& let Ok(target) = read_active_socket_file().await
|
||||
&& !target.is_empty() && &target == current_socket {
|
||||
return Ok(sender.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let interactive_socket = get_socket_path().await.ok();
|
||||
@@ -643,7 +643,10 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
|
||||
async fn call_nvim(req: rmpv::Value) -> Result<rmpv::Value, String> {
|
||||
if !CIRCUIT_BREAKER.can_execute() {
|
||||
return Err("Neovim RPC circuit breaker is OPEN (consecutive failures detected). Failing fast.".to_string());
|
||||
return Err(
|
||||
"Neovim RPC circuit breaker is OPEN (consecutive failures detected). Failing fast."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let msgid = if let rmpv::Value::Array(ref arr) = req {
|
||||
@@ -1749,17 +1752,18 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) {
|
||||
.to_string()
|
||||
});
|
||||
|
||||
let options_arr = match args.get("options").and_then(|v| v.as_array()) {
|
||||
Some(arr) => {
|
||||
let rmp_arr: Vec<rmpv::Value> = arr
|
||||
.iter()
|
||||
.filter_map(|item| item.as_str())
|
||||
.map(|s| rmpv::Value::String(s.into()))
|
||||
.collect();
|
||||
rmpv::Value::Array(rmp_arr)
|
||||
}
|
||||
None => rmpv::Value::Nil,
|
||||
};
|
||||
let options_arr =
|
||||
match args.get("options").and_then(|v| v.as_array()) {
|
||||
Some(arr) => {
|
||||
let rmp_arr: Vec<rmpv::Value> = arr
|
||||
.iter()
|
||||
.filter_map(|item| item.as_str())
|
||||
.map(|s| rmpv::Value::String(s.into()))
|
||||
.collect();
|
||||
rmpv::Value::Array(rmp_arr)
|
||||
}
|
||||
None => rmpv::Value::Nil,
|
||||
};
|
||||
|
||||
let lua_code = r#"
|
||||
local prompt_text, options, request_id = ...
|
||||
@@ -1782,7 +1786,8 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) {
|
||||
)
|
||||
);
|
||||
} else {
|
||||
send_error(id, -32602, "Missing 'prompt' or 'prompt_text'").await;
|
||||
send_error(id, -32602, "Missing 'prompt' or 'prompt_text'")
|
||||
.await;
|
||||
}
|
||||
}
|
||||
"extmark" => {
|
||||
@@ -1812,11 +1817,10 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) {
|
||||
}
|
||||
"highlight" | "clear_highlight" => {
|
||||
let mut modified_args = args.clone();
|
||||
if action == "clear_highlight" {
|
||||
if let Some(obj) = modified_args.as_object_mut() {
|
||||
if action == "clear_highlight"
|
||||
&& let Some(obj) = modified_args.as_object_mut() {
|
||||
obj.insert("clear_only".to_string(), json!(true));
|
||||
}
|
||||
}
|
||||
let args_rmp = json_to_rmpv(&modified_args);
|
||||
let code = "
|
||||
local args = ...
|
||||
@@ -2216,13 +2220,19 @@ mod tests {
|
||||
// 2nd failure - trips to Open
|
||||
cb.record_failure();
|
||||
assert_eq!(cb.current_state(), CircuitState::Open);
|
||||
assert!(!cb.can_execute(), "Circuit breaker should fail fast when Open");
|
||||
assert!(
|
||||
!cb.can_execute(),
|
||||
"Circuit breaker should fail fast when Open"
|
||||
);
|
||||
|
||||
// Wait for cooldown
|
||||
std::thread::sleep(std::time::Duration::from_millis(60));
|
||||
|
||||
// After cooldown, can_execute transitions to HalfOpen
|
||||
assert!(cb.can_execute(), "After cooldown, should allow HalfOpen probe");
|
||||
assert!(
|
||||
cb.can_execute(),
|
||||
"After cooldown, should allow HalfOpen probe"
|
||||
);
|
||||
assert_eq!(cb.current_state(), CircuitState::HalfOpen);
|
||||
|
||||
// Success in HalfOpen recovers back to Closed
|
||||
|
||||
Reference in new issue
Block a user