chore: update major dependencies and fix API breakages
This commit is contained in:
1 parent
05672cc884
commit
c8f8ff8997
7 files changed
+518
-387
No files matched your search
+15
-11
@@ -111,7 +111,7 @@ use std::sync::LazyLock;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
pub struct NvimRequest {
|
||||
pub msgid_str: String,
|
||||
pub msgid: u64,
|
||||
pub req: rmpv::Value,
|
||||
pub reply: oneshot::Sender<Result<rmpv::Value, String>>,
|
||||
}
|
||||
@@ -153,7 +153,7 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
let (mut read_half, mut write_half) = tokio::io::split(stream);
|
||||
let (tx, mut rx) = mpsc::channel::<NvimRequest>(32);
|
||||
type PendingRequestsMap =
|
||||
Arc<std::sync::Mutex<HashMap<String, oneshot::Sender<Result<rmpv::Value, String>>>>>;
|
||||
Arc<std::sync::Mutex<HashMap<u64, oneshot::Sender<Result<rmpv::Value, String>>>>>;
|
||||
let pending_requests: PendingRequestsMap = Arc::new(std::sync::Mutex::new(HashMap::new()));
|
||||
|
||||
// Write task
|
||||
@@ -169,7 +169,7 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
pending_clone
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(req.msgid_str.clone(), req.reply);
|
||||
.insert(req.msgid, req.reply);
|
||||
|
||||
if write_half.write_all(&buf).await.is_err() {
|
||||
tracing::error!("Failed to write to Neovim socket");
|
||||
@@ -193,13 +193,15 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
|
||||
if let rmpv::Value::Array(ref arr) = val {
|
||||
if arr.len() >= 4 && arr[0] == rmpv::Value::Integer(1.into()) {
|
||||
let msgid = &arr[1];
|
||||
let msgid_str = format!("{msgid:?}");
|
||||
let msgid = match &arr[1] {
|
||||
rmpv::Value::Integer(i) => i.as_u64().unwrap_or(0),
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
if let Some(reply_sender) = pending_clone2
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.remove(&msgid_str)
|
||||
.remove(&msgid)
|
||||
{
|
||||
let _ = reply_sender.send(Ok(val));
|
||||
}
|
||||
@@ -279,20 +281,22 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||
async fn call_nvim(req: rmpv::Value) -> Result<rmpv::Value, String> {
|
||||
let msgid = if let rmpv::Value::Array(ref arr) = req {
|
||||
if arr.len() > 1 {
|
||||
arr[1].clone()
|
||||
match &arr[1] {
|
||||
rmpv::Value::Integer(i) => i.as_u64().unwrap_or(0),
|
||||
_ => 0,
|
||||
}
|
||||
} else {
|
||||
rmpv::Value::Nil
|
||||
0
|
||||
}
|
||||
} else {
|
||||
rmpv::Value::Nil
|
||||
0
|
||||
};
|
||||
|
||||
let msgid_str = format!("{msgid:?}");
|
||||
let tx = get_nvim_connection().await?;
|
||||
let (reply_tx, reply_rx) = oneshot::channel();
|
||||
|
||||
tx.send(NvimRequest {
|
||||
msgid_str,
|
||||
msgid,
|
||||
req,
|
||||
reply: reply_tx,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user