From e3a974e2b24195d5ec2fde906f5721d385b13d36 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Wed, 18 Nov 2026 13:18:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(run-config):=20=E8=A7=A3=E9=87=8A=E5=99=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=A0=87=E5=87=BA=20shell=20=E5=AE=B6?= =?UTF-8?q?=E6=97=8F=EF=BC=88shellFamily=EF=BC=89=EF=BC=8C=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E5=8F=AF=E5=88=97=E5=87=BA=E5=B7=B2=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=9A=84=E5=90=8C=E7=B1=BB=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 脚本类运行配置(shell、PowerShell、批处理)的 interpreter 字段带上 shellFamily:posix、powershell 或 cmd。宿主按这个值筛选自己找到的已安装 shell,作为解释器的可选项,和“自动”、自定义路径并列;保存的值仍是程序名 或路径。程序类配置没有解释器,也就没有这个属性。 --- rust/contracts/rust-core-api.md | 3 ++- .../core/src/tests/run_configuration.rs | 26 +++++++++++++++++++ .../execution/src/configuration/form.rs | 12 ++++++++- .../execution/src/configuration/process.rs | 13 ++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index b5a886e7..49c31947 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -3928,7 +3928,7 @@ when this platform cannot run the kind, as in `runConfig.configurationTypes`; the form still edits and saves it. `formVersion` is `1`; a host refuses a newer one. `values` maps field IDs to the current values. `fields` is the ordered list of `{id, kind, required?, placement?, automatic?, options?, visibleWhen?, -note?}`: +note?, shellFamily?}`: | Attribute | Meaning | | --- | --- | @@ -3937,6 +3937,7 @@ note?}`: | `automatic` | The value used while the field is empty, shown as its placeholder | | `visibleWhen` | `{field, equals}`: shown only while that field has that value | | `note` | An explanation key; `windowsOnly` says the field matters only on Windows | +| `shellFamily` | On an `executable` field, the family of shell it takes: `posix` (sh, bash, zsh and the like), `powershell` (Windows PowerShell and `pwsh`) or `cmd`. A host that finds the installed shells may offer those of the family as choices beside the automatic value and a path of the user's own; the value is still a program name or path. The `interpreter` field of each script kind has it | Hosts draw the fields in order, skip a field whose `kind` they do not know and send back every value they received, including keys they do not show, so a diff --git a/rust/crates/core/src/tests/run_configuration.rs b/rust/crates/core/src/tests/run_configuration.rs index 9df1fe5e..ae456b3d 100644 --- a/rust/crates/core/src/tests/run_configuration.rs +++ b/rust/crates/core/src/tests/run_configuration.rs @@ -1787,6 +1787,32 @@ fn built_in_process_runs_are_created_edited_moved_and_deleted_through_the_editor assert!(field(&form, "executionPolicyBypass").is_null()); assert!(field(&form, "program").is_null()); + // The interpreter field names the family of shell that runs the kind, so a + // host can offer the installed shells of it; a program has no interpreter. + for (provider, family) in [ + ("process.shell", "posix"), + ("process.powershell", "powershell"), + ("process.batch", "cmd"), + ] { + let form = call( + "runConfig.editorForm", + serde_json::json!({"root":root,"provider":provider}), + ); + assert_eq!(form["ok"], true, "{form}"); + assert_eq!( + field(&form, "interpreter")["shellFamily"], + family, + "{provider}" + ); + } + let program = call( + "runConfig.editorForm", + serde_json::json!({"root":root,"provider":"process.executable"}), + ); + assert_eq!(program["ok"], true, "{program}"); + assert!(field(&program, "interpreter").is_null()); + assert!(field(&program, "program")["shellFamily"].is_null()); + // Wrong values come back by field and change nothing. let invalid = call( "runConfig.saveConfiguration", diff --git a/rust/crates/execution/src/configuration/form.rs b/rust/crates/execution/src/configuration/form.rs index 27c823ab..baaf8184 100644 --- a/rust/crates/execution/src/configuration/form.rs +++ b/rust/crates/execution/src/configuration/form.rs @@ -506,7 +506,8 @@ fn fields(kind: Kind, root: &Path, draft: &Draft, candidates: Vec) -> Vec field("workingDirectory", "directory"), field("environment", "environment"), field("interpreter", "executable") - .automatic(Some(automatic.executable.text().to_string())), + .automatic(Some(automatic.executable.text().to_string())) + .shell_family(kind.shell_family()), field("interpreterArguments", "arguments") .automatic(Some(argument_text(&effective.arguments))), ]); @@ -552,6 +553,15 @@ impl Field { self } + /// The family of shell an `executable` field takes, such as `posix`, so + /// a host can offer the installed shells of that family as choices. + fn shell_family(mut self, family: Option<&str>) -> Self { + if let Some(family) = family { + self.0["shellFamily"] = json!(family); + } + self + } + fn options(mut self, options: &[&str]) -> Self { self.0["options"] = json!(options); self diff --git a/rust/crates/execution/src/configuration/process.rs b/rust/crates/execution/src/configuration/process.rs index 3b3fcf88..6771ec28 100644 --- a/rust/crates/execution/src/configuration/process.rs +++ b/rust/crates/execution/src/configuration/process.rs @@ -86,6 +86,19 @@ impl Kind { } } + /// The family of shell that runs scripts of the kind, which an editor's + /// interpreter field names so a host can offer the installed shells of + /// that family: `posix` (sh, bash, zsh and the like), `powershell` + /// (Windows PowerShell and `pwsh`) or `cmd`. A program has no interpreter. + pub(crate) fn shell_family(self) -> Option<&'static str> { + match self { + Self::Shell => Some("posix"), + Self::PowerShell => Some("powershell"), + Self::Batch => Some("cmd"), + Self::Executable => None, + } + } + /// File name suffix of the temporary file an inline script is run from; /// PowerShell runs only `.ps1` files and `cmd` only `.cmd` or `.bat`. fn script_suffix(self) -> &'static str {