Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --- | --- |
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions rust/crates/core/src/tests/run_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion rust/crates/execution/src/configuration/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ fn fields(kind: Kind, root: &Path, draft: &Draft, candidates: Vec<Value>) -> 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))),
]);
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions rust/crates/execution/src/configuration/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading