feat(tui): implement agent turn engine for background processing and enhance input handling
This commit is contained in:
@@ -32,8 +32,8 @@ impl LspClient {
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let stdin = child.stdin.take().unwrap();
|
||||
let stdout = BufReader::new(child.stdout.take().unwrap());
|
||||
let stdin = child.stdin.take().ok_or_else(|| anyhow::anyhow!("no stdin on LSP process"))?;
|
||||
let stdout = BufReader::new(child.stdout.take().ok_or_else(|| anyhow::anyhow!("no stdout on LSP process"))?);
|
||||
|
||||
info!("LSP client spawned: {command}");
|
||||
Ok(LspClient {
|
||||
@@ -48,7 +48,13 @@ impl LspClient {
|
||||
|
||||
/// Send a JSON-RPC request and read the response.
|
||||
pub fn send_request(&self, method: &str, params: &Value) -> Result<Value> {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let mut inner = match self.inner.lock() {
|
||||
Ok(g) => g,
|
||||
Err(poisoned) => {
|
||||
tracing::error!("LSP client mutex poisoned, recovering");
|
||||
poisoned.into_inner()
|
||||
}
|
||||
};
|
||||
inner.request_id += 1;
|
||||
let request = serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
@@ -92,8 +98,12 @@ impl LspClient {
|
||||
/// Gracefully shut down the server.
|
||||
pub fn shutdown(&self) -> Result<()> {
|
||||
let null = Value::Null;
|
||||
let _ = self.send_request("shutdown", &null);
|
||||
let _ = self.send_request("exit", &null);
|
||||
if let Err(e) = self.send_request("shutdown", &null) {
|
||||
tracing::warn!("LSP shutdown error: {e}");
|
||||
}
|
||||
if let Err(e) = self.send_request("exit", &null) {
|
||||
tracing::warn!("LSP exit error: {e}");
|
||||
}
|
||||
if let Ok(mut inner) = self.inner.lock() {
|
||||
let _ = inner.process.wait();
|
||||
}
|
||||
@@ -105,7 +115,9 @@ impl LspClient {
|
||||
impl Drop for LspClient {
|
||||
fn drop(&mut self) {
|
||||
if let Ok(mut inner) = self.inner.lock() {
|
||||
let _ = inner.process.kill();
|
||||
if let Err(e) = inner.process.kill() {
|
||||
tracing::warn!("LSP process kill error: {e}");
|
||||
}
|
||||
let _ = inner.process.wait();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user