Skip to content

Commit a35531b

Browse files
committed
feat: remove unnecesary select in io proxy
1 parent 7257d4f commit a35531b

File tree

1 file changed

+54
-57
lines changed

1 file changed

+54
-57
lines changed

src/proxy/io.rs

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -117,75 +117,72 @@ where
117117
Pair::Client => Some(PidHandler::new()),
118118
};
119119
loop {
120-
tokio::select! {
121-
messages = reader.read_messages() => {
122-
debug!("Messages has been read");
123-
match messages {
124-
Ok(Some(msgs)) => {
125-
trace!(msgs_len=msgs.len());
126-
trace!(?msgs);
127-
128-
// If the messages are empty, increase the counter
129-
empty_counter = if msgs.is_empty() {
130-
empty_counter + 1
131-
} else {
132-
0
133-
};
134-
135-
if empty_counter >= MAX_EMPTY_RESPONSES_THRESHOLD {
136-
info!("The empty response has reached the threshold; closing LSP connection");
137-
break;
138-
}
120+
let messages = reader.read_messages().await;
121+
debug!("Messages has been read");
122+
match messages {
123+
Ok(Some(msgs)) => {
124+
trace!(msgs_len=msgs.len());
125+
trace!(?msgs);
126+
127+
// If the messages are empty, increase the counter
128+
empty_counter = if msgs.is_empty() {
129+
empty_counter + 1
130+
} else {
131+
0
132+
};
133+
134+
if empty_counter >= MAX_EMPTY_RESPONSES_THRESHOLD {
135+
info!("The empty response has reached the threshold; closing LSP connection");
136+
break;
137+
}
139138

140-
for mut msg in msgs {
141-
if config_clone.use_docker {
142-
if !lsp_initialized && find(&msg, br#""method":"initialize""#).is_some() {
143-
lsp_initialized = true;
139+
for mut msg in msgs {
140+
if config_clone.use_docker {
141+
if !lsp_initialized && find(&msg, br#""method":"initialize""#).is_some() {
142+
lsp_initialized = true;
144143

145-
trace!("Initialize method found");
144+
trace!("Initialize method found");
146145

147-
// If it is in initialize method, capture the
148-
// colon encoding in Windows
149-
#[cfg(windows)]
150-
{
151-
debug!("Capturing colon config in windows");
152-
use crate::config::encode_path;
153-
encode_path(&msg, &mut config_clone);
154-
}
146+
// If it is in initialize method, capture the
147+
// colon encoding in Windows
148+
#[cfg(windows)]
149+
{
150+
debug!("Capturing colon config in windows");
151+
use crate::config::encode_path;
152+
encode_path(&msg, &mut config_clone);
153+
}
155154

156-
ensure_root(&mut msg, &config_clone);
155+
ensure_root(&mut msg, &config_clone);
157156

158-
if config_clone.requires_patch_pid() &&
159-
let Some(ref mut pid_handler_ref) = pid_handler {
160-
trace!("Trying to take the PID from the initialize method");
157+
if config_clone.requires_patch_pid() &&
158+
let Some(ref mut pid_handler_ref) = pid_handler {
159+
trace!("Trying to take the PID from the initialize method");
161160

162-
// The function returns true if the take succeeds
163-
pid_handler_ref.try_take_initialize_process_id(&mut msg)?;
164-
}
161+
// The function returns true if the take succeeds
162+
pid_handler_ref.try_take_initialize_process_id(&mut msg)?;
165163
}
166-
167-
redirect_uri(&mut msg, &pair, &config_clone)?;
168-
tracker_inner.check_for_methods(GOTO_METHODS, &mut msg, &pair).await?;
169164
}
170165

171-
send_message(&mut writer, &msg).await.map_err(|e| {
172-
error!("Failed to forward the request: {}", e);
173-
e
174-
})?;
166+
redirect_uri(&mut msg, &pair, &config_clone)?;
167+
tracker_inner.check_for_methods(GOTO_METHODS, &mut msg, &pair).await?;
175168
}
169+
170+
send_message(&mut writer, &msg).await.map_err(|e| {
171+
error!("Failed to forward the request: {}", e);
172+
e
173+
})?;
176174
}
177-
Ok(None) => {
178-
tokio::time::sleep(Duration::from_millis(30)).await;
179-
debug!("Empty request, connection closed");
180-
break;
181-
}
182-
Err(e) => {
183-
tokio::time::sleep(Duration::from_millis(10)).await;
184-
error!("Error reading message: {}", e);
185-
return Err(e);
186-
}
187175
}
188-
}
176+
Ok(None) => {
177+
tokio::time::sleep(Duration::from_millis(30)).await;
178+
debug!("Empty request, connection closed");
179+
break;
180+
}
181+
Err(e) => {
182+
tokio::time::sleep(Duration::from_millis(10)).await;
183+
error!("Error reading message: {}", e);
184+
return Err(e);
185+
}
189186
}
190187
}
191188
Ok(())

0 commit comments

Comments
 (0)