Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Terminal/
LocalPTYCreateProcess.rs

1//! Wire method: `localPty:createProcess`.
2//! VS Code's `IPtyService.createProcess` is typed `Promise<number>`.
3//! The workbench does `new LocalPty(id, …)` and keys `_ptys` by that integer;
4//! returning the full `{ id, name, pid }` object causes every subsequent
5//! `_ptys.get(<integer>)` lookup to return `undefined` and xterm to receive
6//! zero bytes. This handler strips down to the integer id.
7
8use std::sync::Arc;
9
10use serde_json::Value;
11
12use crate::{
13	IPC::WindServiceHandlers::Terminal::TerminalCreate::Fn as TerminalCreate,
14	RunTime::ApplicationRunTime::ApplicationRunTime,
15};
16
17pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
18	match TerminalCreate(RunTime, Arguments).await {
19		Ok(Response) => {
20			let TerminalIdOption = Response.get("id").and_then(serde_json::Value::as_u64);
21
22			match TerminalIdOption {
23				Some(TerminalId) if TerminalId > 0 => Ok(serde_json::json!(TerminalId)),
24
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
36					Err(format!(
37						"localPty:createProcess: CreateTerminal returned no terminal id (response={})",
38						Response
39					))
40				},
41			}
42		},
43
44		Err(Error) => Err(Error),
45	}
46}