Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit ea8943e

Browse files
committed
Remove Windows support from IPC layer
- Remove Windows-specific imports and conditional compilation - Remove Windows connection field from IPCCommunicatorInner - Remove Windows connect() and write_message() methods - Remove Windows response_reader_task() method - Simplify codebase to Unix-only for easier maintenance - All tests still pass
1 parent c38f3cb commit ea8943e

File tree

1 file changed

+2
-115
lines changed

1 file changed

+2
-115
lines changed

server/src/ipc.rs

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::collections::HashMap;
88
use std::sync::Arc;
99
use thiserror::Error;
1010
use tokio::io::{AsyncWriteExt, AsyncBufReadExt, BufReader};
11+
use tokio::net::UnixStream;
1112
use tokio::sync::{oneshot, Mutex};
1213
use tracing::{info, error, debug, warn, trace};
1314
use uuid::Uuid;
@@ -18,13 +19,6 @@ use crate::types::{
1819
};
1920
use crate::pid_discovery;
2021

21-
// Cross-platform imports
22-
#[cfg(unix)]
23-
use tokio::net::UnixStream;
24-
25-
#[cfg(windows)]
26-
use tokio::net::windows::named_pipe::ClientOptions;
27-
2822
/// Errors that can occur during IPC communication
2923
#[derive(Error, Debug)]
3024
pub enum IPCError {
@@ -71,13 +65,9 @@ pub struct IPCCommunicator {
7165
}
7266

7367
struct IPCCommunicatorInner {
74-
/// Write half of the connection to VSCode extension
75-
#[cfg(unix)]
68+
/// Write half of the Unix socket connection to VSCode extension
7669
write_half: Option<Arc<Mutex<tokio::net::unix::OwnedWriteHalf>>>,
7770

78-
#[cfg(windows)]
79-
connection: Option<Arc<Mutex<tokio::net::windows::named_pipe::NamedPipeClient>>>,
80-
8171
/// Tracks outgoing requests awaiting responses from VSCode extension
8272
/// Key: unique message ID (UUID), Value: channel to send response back to caller
8373
/// Enables concurrent request/response handling with proper correlation
@@ -92,12 +82,7 @@ impl IPCCommunicator {
9282
pub fn new() -> Self {
9383
Self {
9484
inner: Arc::new(Mutex::new(IPCCommunicatorInner {
95-
#[cfg(unix)]
9685
write_half: None,
97-
98-
#[cfg(windows)]
99-
connection: None,
100-
10186
pending_requests: HashMap::new(),
10287
reader_started: false,
10388
})),
@@ -110,12 +95,7 @@ impl IPCCommunicator {
11095
pub fn new_test() -> Self {
11196
Self {
11297
inner: Arc::new(Mutex::new(IPCCommunicatorInner {
113-
#[cfg(unix)]
11498
write_half: None,
115-
116-
#[cfg(windows)]
117-
connection: None,
118-
11999
pending_requests: HashMap::new(),
120100
reader_started: false,
121101
})),
@@ -166,7 +146,6 @@ impl IPCCommunicator {
166146
}
167147
}
168148

169-
#[cfg(unix)]
170149
async fn connect(&mut self, socket_path: &str) -> Result<()> {
171150
let stream = UnixStream::connect(socket_path).await
172151
.map_err(|e| IPCError::ConnectionFailed {
@@ -193,33 +172,6 @@ impl IPCCommunicator {
193172
Ok(())
194173
}
195174

196-
#[cfg(windows)]
197-
async fn connect(&mut self, pipe_path: &str) -> Result<()> {
198-
let client = ClientOptions::new()
199-
.open(pipe_path)
200-
.map_err(|e| IPCError::ConnectionFailed {
201-
path: pipe_path.to_string(),
202-
source: e
203-
})?;
204-
205-
let connection = Arc::new(Mutex::new(client));
206-
207-
let mut inner = self.inner.lock().await;
208-
inner.connection = Some(Arc::clone(&connection));
209-
210-
// Start the response reader task if not already started
211-
if !inner.reader_started {
212-
inner.reader_started = true;
213-
let inner_clone = Arc::clone(&self.inner);
214-
let connection_clone = Arc::clone(&connection);
215-
tokio::spawn(async move {
216-
Self::response_reader_task(connection_clone, inner_clone).await;
217-
});
218-
}
219-
220-
Ok(())
221-
}
222-
223175
pub async fn present_review(&self, params: PresentReviewParams) -> Result<PresentReviewResult> {
224176
if self.test_mode {
225177
info!("Present review called (test mode): {:?}", params);
@@ -392,7 +344,6 @@ impl IPCCommunicator {
392344
/// This is the underlying method used by both `send_message_with_reply` and
393345
/// `send_message_without_reply`. It handles the platform-specific socket writing
394346
/// and adds newline delimiters for message boundaries.
395-
#[cfg(unix)]
396347
async fn write_message(&self, data: &str) -> Result<()> {
397348
trace!("write_message called with data length: {}", data.len());
398349

@@ -419,23 +370,8 @@ impl IPCCommunicator {
419370
///
420371
/// This is the underlying method used by both `send_message_with_reply` and
421372
/// `send_message_without_reply`. It handles the platform-specific pipe writing
422-
/// and adds newline delimiters for message boundaries.
423-
#[cfg(windows)]
424-
async fn write_message(&self, data: &str) -> Result<()> {
425-
let inner = self.inner.lock().await;
426-
if let Some(ref connection) = inner.connection {
427-
let mut pipe = connection.lock().await;
428-
pipe.write_all(data.as_bytes()).await?;
429-
pipe.write_all(b"\n").await?; // Add newline delimiter
430-
Ok(())
431-
} else {
432-
Err(IPCError::NotConnected)
433-
}
434-
}
435-
436373
/// Background task that reads responses from the IPC connection
437374
/// Runs continuously to handle incoming messages from VSCode extension
438-
#[cfg(unix)]
439375
async fn response_reader_task(
440376
mut read_half: tokio::net::unix::OwnedReadHalf,
441377
inner: Arc<Mutex<IPCCommunicatorInner>>,
@@ -483,55 +419,6 @@ impl IPCCommunicator {
483419
info!("IPC response reader task terminated");
484420
}
485421

486-
/// Background task that reads responses from the IPC connection (Windows)
487-
#[cfg(windows)]
488-
async fn response_reader_task(
489-
connection: Arc<Mutex<tokio::net::windows::named_pipe::NamedPipeClient>>,
490-
inner: Arc<Mutex<IPCCommunicatorInner>>,
491-
) {
492-
info!("Starting IPC response reader task (Windows)");
493-
494-
loop {
495-
let mut buffer = Vec::new();
496-
497-
// Read a line from the connection
498-
let read_result = {
499-
let mut pipe = connection.lock().await;
500-
let mut reader = BufReader::new(&mut *pipe);
501-
reader.read_until(b'\n', &mut buffer).await
502-
};
503-
504-
match read_result {
505-
Ok(0) => {
506-
warn!("IPC connection closed by VSCode extension");
507-
break;
508-
}
509-
Ok(_) => {
510-
// Remove the newline delimiter
511-
if buffer.ends_with(&[b'\n']) {
512-
buffer.pop();
513-
}
514-
515-
let message_str = match String::from_utf8(buffer) {
516-
Ok(s) => s,
517-
Err(e) => {
518-
error!("Received invalid UTF-8 from VSCode extension: {}", e);
519-
continue;
520-
}
521-
};
522-
523-
Self::handle_response_message(&inner, &message_str).await;
524-
}
525-
Err(e) => {
526-
error!("Error reading from IPC connection: {}", e);
527-
break;
528-
}
529-
}
530-
}
531-
532-
info!("IPC response reader task terminated");
533-
}
534-
535422
/// Processes incoming response messages from VSCode extension
536423
/// Matches responses to pending requests by ID and sends results back to callers
537424
async fn handle_response_message(

0 commit comments

Comments
 (0)