Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to cleanup the lock rats nest #47

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify instance timeout logic
  • Loading branch information
pr2502 committed Oct 17, 2023
commit 278c91b156e3ed28b877c1bbbc09dd0233030317
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pin-project-lite = "0.2.13"
serde = { version = "1.0.186" }
serde_derive = { version = "1.0.186" }
serde_json = "1.0.78"
time = "0.3.30"
tokio = { version = "1.15.0", features = ["fs", "io-std", "io-util", "macros", "net", "parking_lot", "process", "rt-multi-thread", "sync", "time"] }
toml = "0.5.8"
tracing = "0.1.39"
Expand Down
24 changes: 9 additions & 15 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ use tokio::sync::{mpsc, Mutex};
use tokio::{select, task};
use tracing::{debug, error, info, trace, Instrument};

use crate::instance::{
self, InitializeCache, InstanceKey, InstanceMap, RaInstance, INIT_REQUEST_ID,
};
use crate::instance::{self, Instance, InstanceKey, InstanceMap, INIT_REQUEST_ID};
use crate::lsp::jsonrpc::{Message, ResponseSuccess, Version};
use crate::lsp::transport::{LspReader, LspWriter};
use crate::proto;

pub struct Client {
port: u16,
initialize_request_id: Option<Value>,
instance: Arc<RaInstance>,
instance: Arc<Instance>,
}

impl Client {
Expand Down Expand Up @@ -96,6 +94,7 @@ impl Client {
.send(req.into())
.await
.context("forward client request")?;
self.instance.keep_alive();
} else {
// initialize request was already sent for this instance, no need to send it again
}
Expand Down Expand Up @@ -179,15 +178,7 @@ impl Client {
let instance_tx = self.instance.message_writer.clone();
task::spawn(
async move {
match read_client_socket(
socket_read,
instance_tx,
close_tx,
port,
&instance.init_cache,
)
.await
{
match read_client_socket(socket_read, instance_tx, close_tx, port, instance).await {
Ok(_) => debug!("client output closed"),
Err(err) => error!(?err, "error reading client output"),
}
Expand All @@ -212,7 +203,7 @@ async fn read_client_socket(
tx: mpsc::Sender<Message>,
close_tx: mpsc::Sender<Message>,
port: u16,
init_cache: &InitializeCache,
instance: Arc<Instance>,
) -> Result<()> {
let mut reader = LspReader::new(socket_read);

Expand All @@ -222,13 +213,14 @@ async fn read_client_socket(
match message {
Message::Request(mut req) if req.method == "initialized" => {
// initialized notification can only be sent once per server
if init_cache.attempt_send_notif() {
if instance.init_cache.attempt_send_notif() {
debug!("send InitializedNotification");

req.id = tag_id(port, &req.id)?.into();
if tx.send(req.into()).await.is_err() {
break;
}
instance.keep_alive();
} else {
// we're not the first, skip processing the message further
debug!("skip InitializedNotification");
Expand Down Expand Up @@ -257,6 +249,7 @@ async fn read_client_socket(
if tx.send(req.into()).await.is_err() {
break;
}
instance.keep_alive();
}

Message::ResponseSuccess(_) | Message::ResponseError(_) => {
Expand All @@ -267,6 +260,7 @@ async fn read_client_socket(
if tx.send(notif.into()).await.is_err() {
break;
}
instance.keep_alive();
}
}
}
Expand Down
Loading