Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Terminal/
LocalPTYCreateProcess.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `localPty:createProcess`.
4//! VS Code's `IPtyService.createProcess` is typed `Promise<number>`.
5//! The workbench does `new LocalPty(id, …)` and keys `_ptys` by that integer;
6//! returning the full `{ id, name, pid }` object causes every subsequent
7//! `_ptys.get(<integer>)` lookup to return `undefined` and xterm to receive
8//! zero bytes. This handler strips down to the integer id.
9
10use std::sync::Arc;
11
12use serde_json::Value;
13
14use crate::{
15	IPC::WindServiceHandlers::Terminal::TerminalCreate::TerminalCreate,
16	RunTime::ApplicationRunTime::ApplicationRunTime,
17};
18
19pub async fn LocalPTYCreateProcess(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
20	match TerminalCreate(RunTime, Arguments).await {
21		Ok(Response) => {
22			let TerminalIdOption = Response.get("id").and_then(serde_json::Value::as_u64);
23			match TerminalIdOption {
24				Some(TerminalId) if TerminalId > 0 => Ok(serde_json::json!(TerminalId)),
25				Some(_) | None => {
26					// Defensive: if `CreateTerminal` returned without a usable id
27					// (shape drift or `GetNextTerminalIdentifier` regression),
28					// surface an error so the workbench binds `LocalPty(0, …)`
29					// and every subsequent `_proxy.input(0, data)` fails loudly.
30					crate::dev_log!(
31						"terminal",
32						"error: [localPty:createProcess] CreateTerminal returned no usable id; response={:?}",
33						Response
34					);
35					Err(format!(
36						"localPty:createProcess: CreateTerminal returned no terminal id (response={})",
37						Response
38					))
39				},
40			}
41		},
42		Err(Error) => Err(Error),
43	}
44}