style: fix clippy collapsible_if warnings in nvim-core
This commit is contained in:
1 parent
148025c5a7
commit
b2f15de58c
8 files changed
+74
-58
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#![cfg(unix)]
|
||||
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
|
||||
+62
-44
@@ -1,5 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -133,12 +133,12 @@ static NVIM_CONN: LazyLock<Arc<std::sync::Mutex<Option<mpsc::Sender<NvimRequest>
|
||||
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
{
|
||||
let conn_lock = NVIM_CONN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(sender) = conn_lock.as_ref() {
|
||||
if !sender.is_closed() {
|
||||
if let Some(sender) = conn_lock.as_ref()
|
||||
&& !sender.is_closed()
|
||||
{
|
||||
return Ok(sender.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!("Establishing new persistent connection to Neovim");
|
||||
let socket_path = get_socket_path().await?;
|
||||
@@ -200,8 +200,10 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
Ok(val) => {
|
||||
offset += cursor.position() as usize;
|
||||
|
||||
if let rmpv::Value::Array(ref arr) = val {
|
||||
if arr.len() >= 4 && arr[0] == rmpv::Value::Integer(1.into()) {
|
||||
if let rmpv::Value::Array(ref arr) = val
|
||||
&& arr.len() >= 4
|
||||
&& arr[0] == rmpv::Value::Integer(1.into())
|
||||
{
|
||||
let msgid = match &arr[1] {
|
||||
rmpv::Value::Integer(i) => i.as_u64().unwrap_or(0),
|
||||
_ => 0,
|
||||
@@ -215,7 +217,6 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
let _ = reply_sender.send(Ok(val));
|
||||
}
|
||||
}
|
||||
}
|
||||
if offset == resp_buf.len() {
|
||||
resp_buf.clear();
|
||||
offset = 0;
|
||||
@@ -225,11 +226,17 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Err(e) if match &e {
|
||||
rmpv::decode::Error::InvalidMarkerRead(io_err) => io_err.kind() == std::io::ErrorKind::UnexpectedEof,
|
||||
rmpv::decode::Error::InvalidDataRead(io_err) => io_err.kind() == std::io::ErrorKind::UnexpectedEof,
|
||||
Err(e)
|
||||
if match &e {
|
||||
rmpv::decode::Error::InvalidMarkerRead(io_err) => {
|
||||
io_err.kind() == std::io::ErrorKind::UnexpectedEof
|
||||
}
|
||||
rmpv::decode::Error::InvalidDataRead(io_err) => {
|
||||
io_err.kind() == std::io::ErrorKind::UnexpectedEof
|
||||
}
|
||||
_ => false,
|
||||
} => {
|
||||
} =>
|
||||
{
|
||||
resp_buf.drain(..offset);
|
||||
offset = 0;
|
||||
|
||||
@@ -277,12 +284,12 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
});
|
||||
|
||||
let mut conn_lock = NVIM_CONN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(existing_sender) = conn_lock.as_ref() {
|
||||
if !existing_sender.is_closed() {
|
||||
if let Some(existing_sender) = conn_lock.as_ref()
|
||||
&& !existing_sender.is_closed()
|
||||
{
|
||||
// Another task established the connection while we were waiting
|
||||
return Ok(existing_sender.clone());
|
||||
}
|
||||
}
|
||||
*conn_lock = Some(tx.clone());
|
||||
Ok(tx)
|
||||
}
|
||||
@@ -348,38 +355,42 @@ async fn send_nvim_command(cmd: &str) -> Result<(), String> {
|
||||
}
|
||||
|
||||
async fn get_nvim_active_buffer() -> Result<String, String> {
|
||||
let result = call_nvim_method("nvim_buf_get_lines", vec![
|
||||
let result = call_nvim_method(
|
||||
"nvim_buf_get_lines",
|
||||
vec![
|
||||
rmpv::Value::Integer(0.into()),
|
||||
rmpv::Value::Integer(0.into()),
|
||||
rmpv::Value::Integer((-1).into()),
|
||||
rmpv::Value::Boolean(true),
|
||||
]).await?;
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let rmpv::Value::Array(lines) = result {
|
||||
let mut text = String::new();
|
||||
for line in lines {
|
||||
if let rmpv::Value::String(s) = line {
|
||||
if let Some(s) = s.as_str() {
|
||||
if let rmpv::Value::String(s) = line
|
||||
&& let Some(s) = s.as_str()
|
||||
{
|
||||
text.push_str(s);
|
||||
text.push('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(text);
|
||||
}
|
||||
Err("Invalid response format".to_string())
|
||||
}
|
||||
|
||||
async fn get_nvim_cursor() -> Result<String, String> {
|
||||
let result = call_nvim_method("nvim_win_get_cursor", vec![rmpv::Value::Integer(0.into())]).await?;
|
||||
let result =
|
||||
call_nvim_method("nvim_win_get_cursor", vec![rmpv::Value::Integer(0.into())]).await?;
|
||||
|
||||
if let rmpv::Value::Array(pos) = result {
|
||||
if pos.len() == 2 {
|
||||
if let (rmpv::Value::Integer(row), rmpv::Value::Integer(col)) = (&pos[0], &pos[1]) {
|
||||
if let rmpv::Value::Array(pos) = result
|
||||
&& pos.len() == 2
|
||||
&& let (rmpv::Value::Integer(row), rmpv::Value::Integer(col)) = (&pos[0], &pos[1])
|
||||
{
|
||||
return Ok(format!("Line: {row}, Column: {col}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err("Invalid response format".to_string())
|
||||
}
|
||||
|
||||
@@ -395,16 +406,20 @@ async fn get_nvim_visual_selection() -> Result<String, String> {
|
||||
end
|
||||
"#;
|
||||
|
||||
let result = call_nvim_method("nvim_exec_lua", vec![
|
||||
let result = call_nvim_method(
|
||||
"nvim_exec_lua",
|
||||
vec![
|
||||
rmpv::Value::String(lua_script.into()),
|
||||
rmpv::Value::Array(vec![]),
|
||||
]).await?;
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let rmpv::Value::String(s) = result {
|
||||
if let Some(text) = s.as_str() {
|
||||
if let rmpv::Value::String(s) = result
|
||||
&& let Some(text) = s.as_str()
|
||||
{
|
||||
return Ok(text.to_string());
|
||||
}
|
||||
}
|
||||
Err("Invalid response format".to_string())
|
||||
}
|
||||
|
||||
@@ -423,10 +438,14 @@ async fn set_nvim_diagnostics(line: i64, message: &str) -> Result<(), String> {
|
||||
"#
|
||||
);
|
||||
|
||||
call_nvim_method("nvim_exec_lua", vec![
|
||||
call_nvim_method(
|
||||
"nvim_exec_lua",
|
||||
vec![
|
||||
rmpv::Value::String(lua_script.into()),
|
||||
rmpv::Value::Array(vec![]),
|
||||
]).await?;
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -489,22 +508,21 @@ fn json_to_rmpv(val: &serde_json::Value) -> rmpv::Value {
|
||||
}
|
||||
}
|
||||
serde_json::Value::String(s) => rmpv::Value::String(s.as_str().into()),
|
||||
serde_json::Value::Array(arr) => {
|
||||
rmpv::Value::Array(arr.iter().map(json_to_rmpv).collect())
|
||||
}
|
||||
serde_json::Value::Object(obj) => {
|
||||
rmpv::Value::Map(obj.iter().map(|(k, v)| {
|
||||
(rmpv::Value::String(k.as_str().into()), json_to_rmpv(v))
|
||||
}).collect())
|
||||
}
|
||||
serde_json::Value::Array(arr) => rmpv::Value::Array(arr.iter().map(json_to_rmpv).collect()),
|
||||
serde_json::Value::Object(obj) => rmpv::Value::Map(
|
||||
obj.iter()
|
||||
.map(|(k, v)| (rmpv::Value::String(k.as_str().into()), json_to_rmpv(v)))
|
||||
.collect(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
async fn execute_nvim_lua_with_args(code: &str, args: Vec<rmpv::Value>) -> Result<String, String> {
|
||||
let result = call_nvim_method("nvim_exec_lua", vec![
|
||||
rmpv::Value::String(code.into()),
|
||||
rmpv::Value::Array(args),
|
||||
]).await?;
|
||||
let result = call_nvim_method(
|
||||
"nvim_exec_lua",
|
||||
vec![rmpv::Value::String(code.into()), rmpv::Value::Array(args)],
|
||||
)
|
||||
.await?;
|
||||
let json_res = rmpv_to_json(&result);
|
||||
// If it's a simple string, return it unquoted, otherwise format it pretty
|
||||
if let serde_json::Value::String(s) = json_res {
|
||||
|
||||
@@ -68,7 +68,9 @@ pub async fn gate_verify_handler(
|
||||
Err(AppError::Forbidden(msg))
|
||||
}
|
||||
}
|
||||
None => Err(AppError::NotFound("Action not yet authorized (no gate record found).".to_string())),
|
||||
None => Err(AppError::NotFound(
|
||||
"Action not yet authorized (no gate record found).".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -1,7 +1,7 @@
|
||||
use crate::store::STORE_TABLE;
|
||||
use redb::{Database, ReadableTable};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use redb::{Database, ReadableTable};
|
||||
use crate::store::STORE_TABLE;
|
||||
|
||||
pub fn init_redb(base: &Path) -> Arc<Database> {
|
||||
let redb_path = base.join("mcp_store.redb");
|
||||
@@ -50,10 +50,7 @@ pub fn init_redb(base: &Path) -> Arc<Database> {
|
||||
table
|
||||
.insert(*key, data.as_slice())
|
||||
.expect("Failed to insert migrated data");
|
||||
let _ = std::fs::rename(
|
||||
&json_path,
|
||||
json_path.with_extension("json.migrated"),
|
||||
);
|
||||
let _ = std::fs::rename(&json_path, json_path.with_extension("json.migrated"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use axum::{
|
||||
Json,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
Json,
|
||||
};
|
||||
use serde_json::json;
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -244,8 +244,7 @@ impl McpTool for GenerateStandupReportHandler {
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: GenerateStandupReportTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let cutoff =
|
||||
crate::handlers::utils::now_secs().saturating_sub(req.hours_lookback * 3600);
|
||||
let cutoff = crate::handlers::utils::now_secs().saturating_sub(req.hours_lookback * 3600);
|
||||
|
||||
let report_str = state.tasks.read_with(|items| {
|
||||
state.ledger.read_with(|changes| {
|
||||
|
||||
+2
-2
@@ -4,13 +4,13 @@
|
||||
)]
|
||||
|
||||
mod api;
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
mod handlers;
|
||||
mod mcp;
|
||||
mod models;
|
||||
mod router;
|
||||
mod search;
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
mod state;
|
||||
mod store;
|
||||
mod tools;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
|
||||
Reference in new issue
Block a user