diff --git a/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md b/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md index 564c9bf098..b731abd1d9 100644 --- a/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md +++ b/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md @@ -56,6 +56,19 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 `runConfig.editorForm` 返回字段列表(类型、是否必填、位置、自动值、可选项、`visibleWhen` 条件、说明)和当前值,`formVersion` 为 1。宿主(`runconfig_form.go`、`runconfig_form_view.go`)只画同时满足两个条件的字段:类型是它认识的,`shared/i18n` 里有这个字段 ID 的标题。其余字段跳过不画,值原样回传。Core 返回的 `formVersion` 比宿主新时,宿主不打开表单,提示升级。 +### 解释器路径从终端检测到的 shell 里选 + +Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`)带 `shellFamily`,值是 `posix`、`powershell` 或 `cmd`,由 Core 的 `Kind::shell_family`(`process.rs`)给出;二进制程序的 `program` 字段不带。哪种运行用哪类 shell 是运行规则,放在 Core。本机装了哪些 shell、某个程序属于哪类,是平台层的事:宿主复用终端“新建终端”菜单的查找(`localshell.InstalledShells`)和分类(`shellkind.FromProgram`)。 + +宿主(`runconfig_shell_view.go`)把带 `shellFamily` 的字段画成和工具链设置一样的下拉: + +- “自动(实际生效值)”:字段为空,Core 按自动值运行; +- 同类的已安装 shell,显示名字和路径,选中后字段写入该路径;WSL 发行版的登录 shell 没有能直接启动的程序路径,不列出; +- 字段里已有、但不在列表中的值,原样显示; +- “自定义…”:下面出现输入框和浏览按钮,可以填命令名(按 PATH 查找)或路径;改选其他项之前一直显示。 + +表单第一次画出时,宿主在后台重新查找一次 shell,所以刚装的 shell 也能列出;查找结束前,列表里只有自动、当前值和自定义。保存的值仍是命令名或路径,YAML、校验和启动计划都不变。宿主不认识的 `shellFamily` 按普通程序字段画。 + ### 在“运行/调试配置”对话框里新建和编辑 对话框参照 IDEA 的同名窗口(`runconfig_dialog.go`、`runconfig_dialog_view.go`),在应用窗口内以模态层显示,不开系统窗口。入口有三个:标题栏运行下拉的“新建运行配置…”和“编辑运行配置…”,以及构建窗口配置列表表头的“+”。列表里的编辑按钮也打开它,并选中那一条。 @@ -93,6 +106,7 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 - 给 Shell 表单加一个参数框:在 Core 的 `form.rs` 描述字段、在 `process.rs` 解释它的值,再在 `shared/i18n/` 加标题词条。宿主已认识这种类型时,不用改任何宿主代码。 - 新增一种全新的字段类型:先在宿主实现它的绘制,再让 Core 开始返回它;旧宿主跳过新字段,配置照样能保存。 - 插件运行需要新的元数据:加进插件 TOML 的 `[plugin]` 头,由 Core 读写,宿主不解析 TOML。 +- 别的字段也要从本机已安装的工具里选:在 Core 的字段上标一个属性(像 `shellFamily`),宿主按属性复用平台层已有的查找,不按字段 ID 或运行类型分支。 ### 不要这样做 @@ -100,6 +114,8 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 - 不要在宿主或 Core 里直接写 `.lithe/run/` 下的文件,绕过 `changes` 和哈希检查会覆盖别人刚做的修改。 - 不要让内置运行等构建模型加载完、或等插件宿主就绪再出现,那正是这次要去掉的依赖。 - 不要把脚本文本写进项目目录或 app bundle。它是一次性的运行产物,只放系统临时目录。 +- 不要在宿主里按运行类型(`process.shell` 等)决定列出哪类 shell,只读 `shellFamily`。 +- 不要用 `ui.C.After` 推迟 shell 查找:表单第一次画出的那一帧通常没有点击,这种帧会丢掉推迟的回调,列表就一直是空的。查找本身在后台运行,直接在绘制时发起即可。 ## 考虑过的备选方案 @@ -143,12 +159,12 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 - 收益:不装插件也能运行脚本和程序;运行配置可以按团队和本机分开提交;插件配置能说明自己依赖哪个插件;以后加字段时,通常只需改 Core 和词条。 - 代价:多了一种文件格式和一套插件元数据要维护;脚本文本运行要在临时目录写文件,进程崩溃时留下的目录由系统清理;旧 macOS 客户端读不到 Viva 已转换的那一层配置。 -- Windows 上裸写的 `bash` 可能解析到 WSL 的启动器,需要 Git Bash 时要在解释器路径里填完整路径。批处理的 `commandLine` 只按 cmd 的规则加引号,不转义 `%`。 +- Windows 上裸写的 `bash` 可能解析到 WSL 的启动器,需要 Git Bash 时从解释器下拉选终端检测到的 Git Bash,或在“自定义…”里填完整路径。批处理的 `commandLine` 只按 cmd 的规则加引号,不转义 `%`。 - 需要重新评估:Windows 或 Linux 实机验收发现的解释器或引号问题;插件需要在 TOML 里放自定义字段时;`formVersion` 需要升到 2 时。 ## 验证 -- `scripts/desktop/desktop-go.sh test ./internal/core/... ./internal/buildprocess/... ./internal/workbench/...`:`runconfig_process_test.go` 用系统 shell 真实运行脚本,并断言 Run 窗口打开、输出进入控制台;`runconfig_dialog_test.go` 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 `<插件 ID>.local.toml`)、文件夹的新建、重命名和解散、手动顺序与排序开关、IDEA 式空白页和 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑、能保存、不能运行;`runconfig_browser_test.go`、`title_run_test.go`、`runconfig_edit_test.go` 覆盖列表、标题栏和插件运行的编辑。 +- `scripts/desktop/desktop-go.sh test ./internal/core/... ./internal/buildprocess/... ./internal/workbench/...`:`runconfig_process_test.go` 用系统 shell 真实运行脚本,并断言 Run 窗口打开、输出进入控制台;`runconfig_dialog_test.go` 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 `<插件 ID>.local.toml`)、文件夹的新建、重命名和解散、手动顺序与排序开关、IDEA 式空白页和 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑、能保存、不能运行;`runconfig_shell_test.go` 覆盖解释器下拉只列同类 shell、选中 shell 写入路径、“自定义…”输入、改回自动和保存;`runconfig_browser_test.go`、`title_run_test.go`、`runconfig_edit_test.go` 覆盖列表、标题栏和插件运行的编辑。 - `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench -run '^(TestVisualBuiltInProcessRuns|TestVisualTitleRunWithoutConfigurations)$'`:设置 `LITHE_VISUAL_OUTPUT_DIR` 后生成 `docs/assets/builtin-process-runs/` 和 `docs/assets/run-config-empty/` 的截图。 - Core 仓库的 `cargo test -p lithe-execution -p lithe-core`:覆盖表单、校验、启动计划、YAML/TOML 读写、旧 JSON、插件可用性,以及 `run_configuration_arrangement.rs` 里文件夹写入哪一层、顺序只进本机、复制保留全部选择。 - `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认运行不写发行目录。 @@ -159,6 +175,7 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 - `desktop/internal/workbench/runconfig_changes.go` - `desktop/internal/workbench/runconfig_form.go` - `desktop/internal/workbench/runconfig_form_view.go` +- `desktop/internal/workbench/runconfig_shell_view.go` - `desktop/internal/workbench/runconfig_dialog.go` - `desktop/internal/workbench/runconfig_dialog_view.go` - `desktop/internal/workbench/title_run_view.go` diff --git a/desktop/internal/core/run_process.go b/desktop/internal/core/run_process.go index a54e309353..d70de167aa 100644 --- a/desktop/internal/core/run_process.go +++ b/desktop/internal/core/run_process.go @@ -37,7 +37,9 @@ func (c *Client) RunConfigurationTypes(ctx context.Context) ([]RunConfigurationT // checkbox, choice, file, multilineText, arguments, directory, environment or // executable; a host skips a kind it does not know and still sends its value // back. Automatic is the value used while the field is empty, shown as its -// placeholder. Note is an explanation key, such as windowsOnly. +// placeholder. Note is an explanation key, such as windowsOnly. ShellFamily, on +// an executable field, is the family of shell it takes (posix, powershell or +// cmd), so a host can offer the installed shells of that family. type RunEditorField struct { ID string `json:"id"` Kind string `json:"kind"` @@ -47,6 +49,7 @@ type RunEditorField struct { Options []string `json:"options,omitempty"` VisibleWhen *RunFieldCondition `json:"visibleWhen,omitempty"` Note string `json:"note,omitempty"` + ShellFamily string `json:"shellFamily,omitempty"` // Candidates are the configurations a beforeLaunch field may name. Candidates []RunConfigurationName `json:"candidates,omitempty"` } diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 02ba2011e7..889b91b965 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1428,7 +1428,11 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.formTooNew": "Editing this run configuration needs a newer version of Lithe.", "desktop.runConfig.interpreterArgumentsHelp": "Options placed before the script path and handled by the interpreter itself, such as bash's -x, which prints each command as it runs. The script does not see them. Left empty, the automatic options shown in brackets are used.", "desktop.runConfig.interpreterArgumentsPlaceholder": "Options for the interpreter, e.g. -x", - "desktop.runConfig.interpreterHelp": "Left empty, the automatic interpreter shown in brackets is used. You can also enter a command name, found on PATH, or the path of an executable.", + "desktop.runConfig.interpreterAutomatic": "Automatic", + "desktop.runConfig.interpreterCustom": "Custom…", + "desktop.runConfig.interpreterCustomField": "Custom interpreter", + "desktop.runConfig.interpreterHelp": "Automatic uses the interpreter shown in brackets. You can also pick a shell of this kind that the terminal found, or choose Custom… to enter a command name, found on PATH, or the path of an executable.", + "desktop.runConfig.interpreterShell": "{name} ({path})", "desktop.runConfig.loadFailed": "Run configurations are unavailable: {reason}", "desktop.runConfig.newConfiguration": "New Configuration", "desktop.runConfig.newConfigurationEllipsis": "New Run Configuration…", @@ -4382,7 +4386,11 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.formTooNew": "这个运行配置需要更新版本的 Lithe 才能编辑。", "desktop.runConfig.interpreterArgumentsHelp": "写在脚本路径前面、交给解释器本身的选项,例如 bash 的 -x(逐行打印执行的命令);脚本读不到这些值。留空时使用括号里显示的自动选项。", "desktop.runConfig.interpreterArgumentsPlaceholder": "传给解释器的选项,例如 -x", - "desktop.runConfig.interpreterHelp": "留空时使用括号里显示的自动解释器;也可以填命令名(按 PATH 查找)或可执行文件路径。", + "desktop.runConfig.interpreterAutomatic": "自动", + "desktop.runConfig.interpreterCustom": "自定义…", + "desktop.runConfig.interpreterCustomField": "自定义解释器", + "desktop.runConfig.interpreterHelp": "选“自动”时使用括号里的解释器;也可以选终端检测到的同类 shell,或选“自定义…”填写命令名(按 PATH 查找)或可执行文件路径。", + "desktop.runConfig.interpreterShell": "{name}({path})", "desktop.runConfig.loadFailed": "无法读取运行配置:{reason}", "desktop.runConfig.newConfiguration": "新建运行配置", "desktop.runConfig.newConfigurationEllipsis": "新建运行配置…", diff --git a/desktop/internal/workbench/runconfig_form.go b/desktop/internal/workbench/runconfig_form.go index a1c5673341..5660864099 100644 --- a/desktop/internal/workbench/runconfig_form.go +++ b/desktop/internal/workbench/runconfig_form.go @@ -63,6 +63,10 @@ type runConfigForm struct { // refreshing says an editorForm request for the edited values is out, so the automatic // values follow the edit; stale says a value changed since it was sent. refreshing, stale bool + // shellPicks are the interpreter lists by field ID; shellsAsked says the installed shells + // were looked for since the form opened. + shellPicks map[string]*runConfigShellPick + shellsAsked bool } // runConfigVariable is one environment variable row of the editor. diff --git a/desktop/internal/workbench/runconfig_form_view.go b/desktop/internal/workbench/runconfig_form_view.go index 2d2abf73bf..0199f2769d 100644 --- a/desktop/internal/workbench/runconfig_form_view.go +++ b/desktop/internal/workbench/runconfig_form_view.go @@ -345,6 +345,10 @@ func (a *App) drawRunConfigFormControl(c ui.C, p *project, f *runConfigForm, fie edited() } case runFieldFile, runFieldExecutable, runFieldDirectory: + // A program Core names a shell family for is chosen from the installed shells. + if field.Kind == runFieldExecutable && a.drawRunConfigShellPicker(c, p, f, field, label, ready) { + return + } box := ui.TextField(c, f.texts[field.ID], label, placeholder).Grow(1).MinWidth(0).Disabled(!ready). Action(icons.FolderOpen, i18n.Shared(language, "desktop.runConfig.browse")) if box.Changed() { diff --git a/desktop/internal/workbench/runconfig_process_visual_test.go b/desktop/internal/workbench/runconfig_process_visual_test.go index a8dba90b4b..e936fa47a3 100644 --- a/desktop/internal/workbench/runconfig_process_visual_test.go +++ b/desktop/internal/workbench/runconfig_process_visual_test.go @@ -10,6 +10,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" "github.com/1lck/Lithe-IDEA/desktop/internal/store" "github.com/vivaui/viva/app" "github.com/vivaui/viva/headless" @@ -17,7 +18,8 @@ import ( // TestVisualBuiltInProcessRuns captures the built-in runs of a project without any plugin in // the Run/Debug Configurations dialog: the dialog with nothing yet, the editor of a shell -// script with a script file and with script text, the Run window after the script ran, the + +// script with a script file and with script text, its interpreter list of the terminal's shells +// and its custom interpreter field, the Run window after the script ran, the + // menu of every kind, the editors of a PowerShell script, an executable and a batch script // this platform cannot run, the title bar with that batch script chosen, the shell script in a // folder of the unsorted list, that folder's pane, a copy of the executable, and the title bar's @@ -76,6 +78,10 @@ func TestVisualBuiltInProcessRuns(t *testing.T) { t.Fatal(err) } } + // The interpreter lists show the same shells on every machine. + h.app.listShells = func() []localshell.Choice { + return []localshell.Choice{{Name: "zsh", Path: "/bin/zsh", Default: true}, {Name: "bash", Path: "/bin/bash"}, {Name: "pwsh", Path: "/usr/local/bin/pwsh"}} + } p := h.openTree(t, root) h.app.post(func(a *App) { a.refreshRunConfigurations(p) }) awaitStateWithin(t, h, 10*time.Second, "the run kinds", func() bool { @@ -141,6 +147,25 @@ func TestVisualBuiltInProcessRuns(t *testing.T) { h.app.post(func(a *App) { *f.texts["text"] = "echo \"$GREETING from $(pwd)\"\nuname -s\n" }) shot("shell-text") + // The interpreter list: automatic, the terminal's POSIX shells and Custom…, then + // Custom… with its field. + awaitStateWithin(t, h, 10*time.Second, "the terminal's shells", func() bool { return len(h.app.term.shells.list) == 3 }) + interpreter, _ := runConfigFieldLabel(h.app.language(), "interpreter") + h.click(center(h.hitLabeled(interpreter))) + shot("interpreter-list") + h.click(center(h.popupHit(i18n.Shared(h.app.language(), "desktop.runConfig.interpreterCustom")))) + h.app.post(func(a *App) { + *f.texts["interpreter"] = "/opt/homebrew/bin/bash" + a.runConfigFormEdited(p, f) + }) + awaitStateWithin(t, h, 10*time.Second, "the custom interpreter", func() bool { return !f.refreshing }) + shot("interpreter-custom") + h.app.post(func(a *App) { + *f.texts["interpreter"] = "" + a.runConfigFormEdited(p, f) + }) + awaitStateWithin(t, h, 10*time.Second, "the automatic interpreter", func() bool { return !f.refreshing }) + apply(runConfigDialogRun) awaitProcessRun(t, h, p, "Greet", nil) shot("run-output") diff --git a/desktop/internal/workbench/runconfig_shell_test.go b/desktop/internal/workbench/runconfig_shell_test.go new file mode 100644 index 0000000000..ee57a0326c --- /dev/null +++ b/desktop/internal/workbench/runconfig_shell_test.go @@ -0,0 +1,152 @@ +package workbench + +import ( + "os" + "path/filepath" + "slices" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" + "github.com/1lck/Lithe-IDEA/desktop/internal/shellkind" +) + +// testTerminalShells is what the new-terminal menu finds on a machine with two POSIX shells, +// PowerShell, fish and a WSL distribution, so the interpreter lists do not depend on the shells +// the machine running the test has. +func testTerminalShells() []localshell.Choice { + return []localshell.Choice{ + {Name: "zsh", Path: "/bin/zsh", Default: true}, + {Name: "bash", Path: "/bin/bash"}, + {Name: "pwsh", Path: "/usr/local/bin/pwsh"}, + {Name: "fish", Path: "/opt/homebrew/bin/fish"}, + {Name: "Ubuntu", Path: "wsl:Ubuntu"}, + } +} + +// An interpreter list holds automatic, naming the program Core runs while the field is empty, +// the installed shells of the field's family in the terminal's order, the field's own value +// when it is none of them, and Custom… last. A family this host does not know is no list. +func TestRunConfigShellChoicesListTheFamilyAndCustom(t *testing.T) { + language := i18n.English + if _, ok := runConfigShellKind("fish"); ok { + t.Fatal("an unknown family is drawn as a list") + } + kind, ok := runConfigShellKind("posix") + if !ok || kind != shellkind.POSIX { + t.Fatalf("posix = %v, %v", kind, ok) + } + shells := runConfigFamilyShells(testTerminalShells(), kind) + if paths := []string{}; len(shells) != 2 || shells[0].Path != "/bin/zsh" || shells[1].Path != "/bin/bash" { + for _, shell := range shells { + paths = append(paths, shell.Path) + } + t.Fatalf("POSIX shells = %v", paths) + } + if shells := runConfigFamilyShells(testTerminalShells(), shellkind.PowerShell); len(shells) != 1 || shells[0].Name != "pwsh" { + t.Fatalf("PowerShell shells = %+v", shells) + } + + automatic := "/bin/sh" + choices, labels, current := runConfigShellChoices(language, &automatic, shells, "/bin/bash") + if want := []string{"", "/bin/zsh", "/bin/bash", runConfigShellCustom}; !slices.Equal(choices, want) || current != "/bin/bash" { + t.Fatalf("choices = %q current %q, want %q", choices, current, want) + } + if labels[""] != "Automatic (/bin/sh)" || labels["/bin/bash"] != "bash (/bin/bash)" || labels[runConfigShellCustom] != "Custom…" { + t.Fatalf("labels = %q", labels) + } + + choices, labels, current = runConfigShellChoices(language, nil, shells, "tools/sh") + if want := []string{"", "/bin/zsh", "/bin/bash", "tools/sh", runConfigShellCustom}; !slices.Equal(choices, want) || current != "tools/sh" { + t.Fatalf("choices of a value of the user's own = %q current %q", choices, current) + } + if labels[""] != "Automatic" || labels["tools/sh"] != "tools/sh" { + t.Fatalf("labels without an automatic value = %q", labels) + } + if _, _, current := runConfigShellChoices(language, &automatic, shells, ""); current != "" { + t.Fatalf("an empty field stands for %q, want automatic", current) + } +} + +// The interpreter of a shell script run is chosen from the shells the new-terminal menu finds: +// picking one writes its path into the field and saves it, Custom… shows a field for a program +// of the user's own that keeps the value until another entry is picked, and automatic empties +// the field again. +func TestRunConfigInterpreterListsTheTerminalShells(t *testing.T) { + h, p, root := emptyProcessRunHarness(t) + h.app.listShells = testTerminalShells + f := newRunConfigDraft(t, h, p, runProviderShell) + fillScriptText(t, h, p, f, "Greet", "echo hi\n") + awaitStateWithin(t, h, 10*time.Second, "the terminal's shells", func() bool { return len(h.app.term.shells.list) == len(testTerminalShells()) }) + h.settle() + interpreter := f.texts["interpreter"] + if interpreter == nil { + t.Fatal("the shell script form has no interpreter field") + } + for _, field := range f.fields { + if field.ID == "interpreter" && field.ShellFamily != "posix" { + t.Fatalf("the interpreter field takes the %q family", field.ShellFamily) + } + } + + language := h.app.language() + label, _ := runConfigFieldLabel(language, "interpreter") + custom := i18n.Shared(language, "desktop.runConfig.interpreterCustomField") + shell := func(name, path string) string { + return i18n.SharedFormat(language, "desktop.runConfig.interpreterShell", map[string]string{"name": name, "path": path}) + } + choose := func(entry string) { + t.Helper() + h.click(center(h.hitLabeled(label))) + if h.hasPopupItem(shell("pwsh", "/usr/local/bin/pwsh")) || h.hasPopupItem(shell("fish", "/opt/homebrew/bin/fish")) { + t.Fatal("the list offers a shell of another family") + } + h.click(center(h.popupHit(entry))) + } + + choose(shell("bash", "/bin/bash")) + if *interpreter != "/bin/bash" || h.hasPopupItem(custom) { + t.Fatalf("interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom)) + } + + choose(i18n.Shared(language, "desktop.runConfig.interpreterCustom")) + if *interpreter != "/bin/bash" || !h.hasPopupItem(custom) { + t.Fatalf("Custom…: interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom)) + } + h.typeInto(custom, func() { *interpreter = "" }, "tools/sh") + if *interpreter != "tools/sh" || !h.hasPopupItem(custom) { + t.Fatalf("typed interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom)) + } + + choose(shell("bash", "/bin/bash")) + if *interpreter != "/bin/bash" || h.hasPopupItem(custom) { + t.Fatalf("back to bash: interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom)) + } + applyDialog(t, h, p, runConfigDialogApply) + saved, err := os.ReadFile(filepath.Join(root, ".lithe", "run", "local.yaml")) + if err != nil || !strings.Contains(string(saved), "/bin/bash") { + t.Fatalf("local.yaml = %s, %v", saved, err) + } + + f = p.runConfigs.dialog.drafts[p.runConfigs.dialog.selected].form + awaitStateWithin(t, h, 10*time.Second, "the saved configuration's form", func() bool { return f != nil && f.ready() }) + interpreter = f.texts["interpreter"] + choose(i18n.SharedFormat(language, "desktop.runConfig.automaticValue", map[string]string{"value": automaticInterpreter(t, f)})) + if *interpreter != "" || h.hasPopupItem(custom) { + t.Fatalf("automatic: interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom)) + } +} + +// automaticInterpreter is the program Core runs while the interpreter field of f is empty. +func automaticInterpreter(t *testing.T, f *runConfigForm) string { + t.Helper() + for _, field := range f.fields { + if field.ID == "interpreter" && field.Automatic != nil { + return *field.Automatic + } + } + t.Fatal("the interpreter field names no automatic program") + return "" +} diff --git a/desktop/internal/workbench/runconfig_shell_view.go b/desktop/internal/workbench/runconfig_shell_view.go new file mode 100644 index 0000000000..cc8a0d48d4 --- /dev/null +++ b/desktop/internal/workbench/runconfig_shell_view.go @@ -0,0 +1,158 @@ +package workbench + +import ( + "runtime" + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" + "github.com/1lck/Lithe-IDEA/desktop/internal/shellkind" + "github.com/vivaui/viva/ui" +) + +// runConfigShellCustom is the entry of an interpreter list that asks for a program of the +// user's own. It cannot be a path, so it never stands for a value. +const runConfigShellCustom = "\x00custom" + +// runConfigShellPick is the state of one interpreter list. choice is the entry shown, bound by +// its address, so the list keeps its identity across paints; custom says Custom… is chosen, +// which shows the field for a program of the user's own until another entry is chosen. +type runConfigShellPick struct { + choice string + custom bool +} + +// shellPick is the state of field's interpreter list, made the first time it is drawn. +func (f *runConfigForm) shellPick(field string) *runConfigShellPick { + if f.shellPicks == nil { + f.shellPicks = map[string]*runConfigShellPick{} + } + if f.shellPicks[field] == nil { + f.shellPicks[field] = &runConfigShellPick{} + } + return f.shellPicks[field] +} + +// runConfigShellKind is the shell family Core names on an interpreter field; ok is false for a +// family this host does not know, whose field is then drawn as a plain program field. +func runConfigShellKind(family string) (shellkind.Kind, bool) { + switch family { + case "posix": + return shellkind.POSIX, true + case "powershell": + return shellkind.PowerShell, true + case "cmd": + return shellkind.Cmd, true + } + return shellkind.Unknown, false +} + +// runConfigFamilyShells is the installed shells of kind, in the order the terminal lists them. +// A WSL distribution's login shell has no program path a run could start, so it is left out. +func runConfigFamilyShells(shells []localshell.Choice, kind shellkind.Kind) []localshell.Choice { + var kept []localshell.Choice + for _, shell := range shells { + if !strings.HasPrefix(shell.Path, "wsl:") && shellkind.FromProgram(shell.Path) == kind { + kept = append(kept, shell) + } + } + return kept +} + +// sameRunConfigProgram says whether two paths name the same program; Windows ignores case. +func sameRunConfigProgram(a, b string) bool { + if runtime.GOOS == "windows" { + return strings.EqualFold(a, b) + } + return a == b +} + +// runConfigShellChoices is the entries of an interpreter list for value, the field's text, and +// the words of each: automatic, which names the program Core runs while the field is empty; +// each installed shell of the family, with its path; value itself when it is none of them; and +// Custom…. current is the entry value stands for. +func runConfigShellChoices(language i18n.Language, automatic *string, shells []localshell.Choice, value string) (choices []string, labels map[string]string, current string) { + labels = map[string]string{} + add := func(choice, label string) { + if _, ok := labels[choice]; !ok { + choices = append(choices, choice) + labels[choice] = label + } + } + if automatic != nil && *automatic != "" { + add("", i18n.SharedFormat(language, "desktop.runConfig.automaticValue", map[string]string{"value": *automatic})) + } else { + add("", i18n.Shared(language, "desktop.runConfig.interpreterAutomatic")) + } + current = value + for _, shell := range shells { + add(shell.Path, i18n.SharedFormat(language, "desktop.runConfig.interpreterShell", map[string]string{"name": shell.Name, "path": shell.Path})) + if value != "" && sameRunConfigProgram(shell.Path, value) { + current = shell.Path + } + } + add(current, current) + add(runConfigShellCustom, i18n.Shared(language, "desktop.runConfig.interpreterCustom")) + return choices, labels, current +} + +// drawRunConfigShellPicker declares an interpreter field Core names a shell family for, as the +// toolchain settings choose a tool: one list of the automatic interpreter, the installed shells +// of the family the new-terminal menu finds, and Custom…, which shows a field for a command +// name or a path, with a button that picks a file. It reports false, drawing nothing, for a +// family this host does not know. The installed shells are looked for again once per form, +// off the window thread, so a shell installed since the menu last looked is listed, and the +// list fills in when they are found. +func (a *App) drawRunConfigShellPicker(c ui.C, p *project, f *runConfigForm, field core.RunEditorField, label string, ready bool) bool { + kind, ok := runConfigShellKind(field.ShellFamily) + text := f.texts[field.ID] + if !ok || text == nil { + return false + } + // Asked on this paint, not through ui.C.After: the form first shows in a paint that may + // deliver no click, and such a paint drops what is deferred. The search runs in the + // background, so asking here does not hold the paint. + if !f.shellsAsked { + f.shellsAsked = true + a.findShells() + } + language := a.language() + pick := f.shellPick(field.ID) + choices, labels, current := runConfigShellChoices(language, field.Automatic, runConfigFamilyShells(a.term.shells.list, kind), *text) + if pick.custom { + pick.choice = runConfigShellCustom + } else { + pick.choice = current + } + shown := pick.choice + ui.Column(c.Part("shell")).Grow(1).MinWidth(0).Gap(6).Children(func() { + ui.Select(c.Part("choice"), &pick.choice, choices, func(choice string) string { return labels[choice] }). + FillWidth().MinWidth(0).Label(label).Disabled(!ready) + if pick.choice != shown { + pick.custom = pick.choice == runConfigShellCustom + if !pick.custom && pick.choice != *text { + *text = pick.choice + c.After(func() { + a.performed("run.configuration.form.interpreter.choose", surfaceMenu) + a.runConfigFormEdited(p, f) + }) + } + } + if !pick.custom { + return + } + // The field is named apart from the list above it, as the toolchain settings name theirs. + named := i18n.Shared(language, "desktop.runConfig.interpreterCustomField") + box := ui.TextField(c.Part("custom"), text, named, runConfigFieldPlaceholder(language, field)).FillWidth().MinWidth(0).Disabled(!ready). + Action(icons.FolderOpen, i18n.Shared(language, "desktop.runConfig.browse")) + if box.Changed() { + c.After(func() { a.runConfigFormEdited(p, f) }) + } + if box.ActionClicked() { + c.After(func() { a.browseRunConfigField(p, f, field, label) }) + } + }) + return true +} diff --git a/docs/assets/builtin-process-runs/README.md b/docs/assets/builtin-process-runs/README.md index 5864d7164a..6f787e59b3 100644 --- a/docs/assets/builtin-process-runs/README.md +++ b/docs/assets/builtin-process-runs/README.md @@ -15,8 +15,10 @@ Shell 脚本在系统 shell 里真实运行,控制台内容是真实输出, | 场景 | 深色中文 | 浅色英文 | | --- | --- | --- | | 还没有配置时打开对话框,和 IDEA 一样:左侧是“未添加运行配置。”和链接“添加新… ⌃N”,右侧是链接“添加新的运行配置…”和“或选择要编辑的运行配置”。两个链接和 ⌃N 都打开类型菜单 | [截图](builtin-run-dialog-empty-dark.png) | [截图](builtin-run-dialog-empty-light.png) | -| 新建 Shell 脚本,执行方式为脚本文件:勾选了“存为项目文件”,填了脚本路径、脚本选项、项目内的工作目录和一个环境变量。解释器路径没填,自动值取自脚本首行的 `#!/bin/bash`。脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁 | [截图](builtin-run-shell-file-dark.png) | [截图](builtin-run-shell-file-light.png) | +| 新建 Shell 脚本,执行方式为脚本文件:勾选了“存为项目文件”,填了脚本路径、脚本选项、项目内的工作目录和一个环境变量。解释器路径选的是“自动”,下拉框显示自动值,取自脚本首行的 `#!/bin/bash`。脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁 | [截图](builtin-run-shell-file-dark.png) | [截图](builtin-run-shell-file-light.png) | | 同一配置换成脚本文本,出现多行文本框。文本没有首行 `#!`,解释器自动值变为 `/bin/sh` | [截图](builtin-run-shell-text-dark.png) | [截图](builtin-run-shell-text-light.png) | +| 展开解释器路径下拉:第一项是“自动(/bin/sh)”,然后是终端检测到的 POSIX shell(zsh、bash),最后是“自定义…”。截图用固定的 shell 列表(zsh、bash、pwsh),pwsh 不属于 Shell 脚本这一类,所以不列出 | [截图](builtin-run-interpreter-list-dark.png) | [截图](builtin-run-interpreter-list-light.png) | +| 选“自定义…”后,下拉下方出现“自定义解释器”输入框,可以填命令名(按 PATH 查找)或路径,右侧按钮用来选择文件。这里填了 `/opt/homebrew/bin/bash`;改回“自动”或选某个 shell 后,输入框收起 | [截图](builtin-run-interpreter-custom-dark.png) | [截图](builtin-run-interpreter-custom-light.png) | | 点击对话框的“运行”后:配置写入 `.lithe/run/configurations.yaml`,对话框关闭,Run 窗口打开并选中这次运行。控制台打印脚本输出,执行树以“进程已结束,退出码 0。”结束;标题栏改选 Greet | [截图](builtin-run-run-output-dark.png) | [截图](builtin-run-run-output-light.png) | | 再次打开对话框并展开“+”菜单:列出四类内置运行,批处理脚本下注明“仅 Windows” | [截图](builtin-run-new-menu-dark.png) | [截图](builtin-run-new-menu-light.png) | | 新建 PowerShell 脚本:macOS 上的解释器自动值是 pwsh,解释器选项自动值是 `-NoLogo -NoProfile`。“绕过执行策略(-ExecutionPolicy Bypass)”默认勾选,ⓘ 说明只在 Windows 生效 | [截图](builtin-run-powershell-dark.png) | [截图](builtin-run-powershell-light.png) | diff --git a/docs/assets/builtin-process-runs/builtin-run-batch-dark.png b/docs/assets/builtin-process-runs/builtin-run-batch-dark.png index 335068bd74..d75b6417b8 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-batch-dark.png and b/docs/assets/builtin-process-runs/builtin-run-batch-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-batch-light.png b/docs/assets/builtin-process-runs/builtin-run-batch-light.png index 883de20c27..bc4dbcfaf2 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-batch-light.png and b/docs/assets/builtin-process-runs/builtin-run-batch-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-copy-dark.png b/docs/assets/builtin-process-runs/builtin-run-copy-dark.png index 577c4ff505..2a78db686f 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-copy-dark.png and b/docs/assets/builtin-process-runs/builtin-run-copy-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png index 2774e2ca4c..df384435c4 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png and b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-executable-dark.png b/docs/assets/builtin-process-runs/builtin-run-executable-dark.png index 86df2749dd..a35f0a3810 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-executable-dark.png and b/docs/assets/builtin-process-runs/builtin-run-executable-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png b/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png index e8bbe73001..90124e46e8 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png and b/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folders-dark.png b/docs/assets/builtin-process-runs/builtin-run-folders-dark.png index 0510912a17..dcc81de5f0 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-folders-dark.png and b/docs/assets/builtin-process-runs/builtin-run-folders-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folders-light.png b/docs/assets/builtin-process-runs/builtin-run-folders-light.png index 7dc1b6cee5..5d7fa94e68 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-folders-light.png and b/docs/assets/builtin-process-runs/builtin-run-folders-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-dark.png b/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-dark.png new file mode 100644 index 0000000000..9ff9cd19ff Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-light.png b/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-light.png new file mode 100644 index 0000000000..8315fd2f66 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-interpreter-list-dark.png b/docs/assets/builtin-process-runs/builtin-run-interpreter-list-dark.png new file mode 100644 index 0000000000..87e38f1d61 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-interpreter-list-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-interpreter-list-light.png b/docs/assets/builtin-process-runs/builtin-run-interpreter-list-light.png new file mode 100644 index 0000000000..adf8ac2a76 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-interpreter-list-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png b/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png index 121db54523..da3da49feb 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png and b/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png b/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png index 67340b247a..56a12b21c6 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png and b/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png b/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png index c211c18e11..add0958b22 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png and b/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-powershell-light.png b/docs/assets/builtin-process-runs/builtin-run-powershell-light.png index 30124f3c1f..acbf76e04e 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-powershell-light.png and b/docs/assets/builtin-process-runs/builtin-run-powershell-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png b/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png index 78224581e9..58fdb9f928 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png and b/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png b/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png index 7ba3124d5b..51c8af3754 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png and b/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png b/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png index 47af8c6fc0..175f01ed3a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png and b/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png b/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png index ed26e7beaf..cbb59d31fa 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png and b/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png b/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png index 1459e019ff..8d4387ea1a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png and b/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png b/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png index f30d65579a..8c02682549 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png and b/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png index 2d5d489e0d..6ba9e0db2d 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png and b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 46763a7231..1bd6fc6f6e 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,6 +27,10 @@ native_path() { fi } +# Lithe-core-rust main at 8b91b32: #92, squash-merged into main on top of 5204e81, makes the +# interpreter field of the shell script, PowerShell and cmd editor forms name the shellFamily it +# takes (posix, powershell, cmd), so the run configuration dialog lists the installed shells of +# that family beside automatic and a custom path (#2100). # Lithe-core-rust main at 5204e81 (#91 squash-merged on top of 16176c1): a run configuration # names the folder it is listed in, runConfig.resolve returns the list in the order the local layer # saves (by name by default) with sortAlphabetically, runConfig.arrange moves configurations between @@ -235,7 +239,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="5204e81635378425505c592575f251eeff640ee7" +PINNED_CORE_REVISION="8b91b324f0e8140cb6ca3fed3dc26fa0b59a788c" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 576a140f8f..42d62501d4 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11481,7 +11481,11 @@ "desktop.runConfig.fieldText": "Script text", "desktop.runConfig.fieldScriptOptions": "Script options", "desktop.runConfig.fieldInterpreter": "Interpreter path", - "desktop.runConfig.interpreterHelp": "Left empty, the automatic interpreter shown in brackets is used. You can also enter a command name, found on PATH, or the path of an executable.", + "desktop.runConfig.interpreterHelp": "Automatic uses the interpreter shown in brackets. You can also pick a shell of this kind that the terminal found, or choose Custom… to enter a command name, found on PATH, or the path of an executable.", + "desktop.runConfig.interpreterAutomatic": "Automatic", + "desktop.runConfig.interpreterShell": "{name} ({path})", + "desktop.runConfig.interpreterCustom": "Custom…", + "desktop.runConfig.interpreterCustomField": "Custom interpreter", "desktop.runConfig.fieldInterpreterArguments": "Interpreter options", "desktop.runConfig.fieldExecutionPolicyBypass": "Bypass execution policy (-ExecutionPolicy Bypass)", "desktop.runConfig.noteWindowsOnly": "Takes effect on Windows only; other systems ignore it.", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 8ec94cd706..397aefb67e 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11481,7 +11481,11 @@ "desktop.runConfig.fieldText": "脚本文本", "desktop.runConfig.fieldScriptOptions": "脚本选项", "desktop.runConfig.fieldInterpreter": "解释器路径", - "desktop.runConfig.interpreterHelp": "留空时使用括号里显示的自动解释器;也可以填命令名(按 PATH 查找)或可执行文件路径。", + "desktop.runConfig.interpreterHelp": "选“自动”时使用括号里的解释器;也可以选终端检测到的同类 shell,或选“自定义…”填写命令名(按 PATH 查找)或可执行文件路径。", + "desktop.runConfig.interpreterAutomatic": "自动", + "desktop.runConfig.interpreterShell": "{name}({path})", + "desktop.runConfig.interpreterCustom": "自定义…", + "desktop.runConfig.interpreterCustomField": "自定义解释器", "desktop.runConfig.fieldInterpreterArguments": "解释器选项", "desktop.runConfig.fieldExecutionPolicyBypass": "绕过执行策略(-ExecutionPolicy Bypass)", "desktop.runConfig.noteWindowsOnly": "只在 Windows 上生效,其他系统会忽略。", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 0cdd1c31ff..b2777a958d 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -15811,7 +15811,39 @@ }, { "id": "desktop.runConfig.interpreterHelp", - "description": "Tooltip of the interpreter path field: an empty field uses the automatic interpreter shown.", + "description": "Tooltip of the interpreter path field: Automatic uses the interpreter shown, a shell the terminal found can be picked, and Custom… takes a command name or path.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.interpreterAutomatic", + "description": "Entry of the interpreter list that uses the automatic interpreter, when Core names no automatic program to show.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.interpreterShell", + "description": "Entry of the interpreter list for an installed shell the terminal found. {name} is the shell's name, {path} its executable.", + "platforms": [ + "desktop" + ], + "parameters": { + "name": "string", + "path": "string" + } + }, + { + "id": "desktop.runConfig.interpreterCustom", + "description": "Entry of the interpreter list that shows a field for a command name or path of the user's own.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.interpreterCustomField", + "description": "Accessible name of the field shown under the interpreter list after Custom… is chosen, where the user enters a command name or path.", "platforms": [ "desktop" ] diff --git a/shared/platform-feature-matrix/features/builtin-process-runs.json b/shared/platform-feature-matrix/features/builtin-process-runs.json index c0c8518f6f..0a8eb1d3db 100644 --- a/shared/platform-feature-matrix/features/builtin-process-runs.json +++ b/shared/platform-feature-matrix/features/builtin-process-runs.json @@ -2,7 +2,7 @@ "id": "builtin-process-runs", "area": "运行与调试", "group": "运行配置", - "capability": "内置脚本与程序运行:不装任何插件也能新建、编辑、删除并运行 Shell 脚本、PowerShell 脚本、cmd 批处理和可执行程序四类运行配置。新建和编辑都在参照 IDEA 的“运行/调试配置”对话框里:标题栏运行下拉的“新建运行配置…”“编辑运行配置…”和构建窗口配置列表的“+”打开它,左侧工具栏是“+”“−”、复制、新建文件夹和“按字母顺序排序”开关,下面是按类型分组、可折叠的配置树(类型下先列文件夹,再列其余配置),右侧是选中配置的编辑器,底部有运行、取消、应用、确定;几条配置的新建、修改、复制、删除、文件夹和顺序在“应用”或“确定”时一起保存,“取消”全部丢弃。焦点在配置树上时 macOS 按 ⌫/⌦、Windows 按 Delete 删除选中的配置,macOS 按 ⌃N、Windows 按 Alt+Insert 打开新建菜单。没有配置时和 IDEA 一样,左侧显示“未添加运行配置。”和“添加新… ⌃N”链接,右侧显示“添加新的运行配置…”链接和“或选择要编辑的运行配置”。复制对所有配置可用:内置运行按表单值复制成“<原名>(副本)”,构建插件生成的运行在应用时由 Core 复制并保留全部选择,副本存进 .lithe/run/plugin/<插件>.local.toml,原配置照常列出。文件夹存在配置自己的 folder 字段(项目配置进 configurations.yaml、本机和生成的配置进 local.yaml),可以新建、重命名(名称不能为空、不能重名、不能含控制字符)和解散,拖动配置可以换文件夹;关掉排序后可以拖动调整顺序,顺序和排序开关只存在 .lithe/run/local.yaml,标题栏下拉和构建窗口的列表顺序与对话框一致。批处理只能在 Windows 上运行:macOS/Linux 上仍可新建、编辑和保存(和 Windows 同事共享的配置不会消失),类型旁注明“仅 Windows”,编辑器顶部说明原因,配置树和标题栏下拉的这一行带警告图标,对话框的“运行”和标题栏运行按钮置灰,按下时只提示原因。内置运行的编辑器参照 IDEA 的 Shell Script 配置,有名称、“存为项目文件”、脚本文件或脚本文本、脚本选项、工作目录、环境变量、解释器路径、解释器选项(留空时显示自动值:Shell 按脚本首行 #! 选解释器,没有时 macOS/Linux 用 /bin/sh、Windows 用 bash;PowerShell 用 Windows 的 powershell 或 pwsh;cmd 用 cmd /d),脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁;PowerShell 的“绕过执行策略”默认勾选、只在 Windows 生效;可执行程序有程序路径、参数、工作目录和环境变量。字段、默认值、显示条件和校验错误全部来自 Core(runConfig.configurationTypes、runConfig.editorForm),新增字段不改宿主绘制代码。存为项目文件时写 .lithe/run/configurations.yaml,否则写 .lithe/run/local.yaml;插件运行另存 .lithe/run/plugin/<插件>.toml 与 <插件>.local.toml,并记下插件的作者/仓库、版本、版本要求、插件 API 版本和所需能力;旧版 configurations.json、local.json 在没有对应 YAML 时仍读取,第一次编辑该层时改写为 YAML 并删除 JSON。编辑对话框的“运行”、构建窗口的运行配置列表、标题栏的运行按钮和 Run 窗口的再次运行都能启动,启动时 Run 窗口自动打开并选中这次运行,输出进入它的控制台,以“进程已结束,退出码 N。”结束;脚本文本写到系统临时目录(不写安装目录),运行结束后删除。插件出错、未装或项目尚未加载构建模型时,内置运行照常列出和运行;某个运行配置文件没有读取(插件 TOML 写坏、同一配置存了两次、旧版 JSON 已被 YAML 取代)时,标题栏运行下拉按文件名列出它,点击在编辑器中打开", + "capability": "内置脚本与程序运行:不装任何插件也能新建、编辑、删除并运行 Shell 脚本、PowerShell 脚本、cmd 批处理和可执行程序四类运行配置。新建和编辑都在参照 IDEA 的“运行/调试配置”对话框里:标题栏运行下拉的“新建运行配置…”“编辑运行配置…”和构建窗口配置列表的“+”打开它,左侧工具栏是“+”“−”、复制、新建文件夹和“按字母顺序排序”开关,下面是按类型分组、可折叠的配置树(类型下先列文件夹,再列其余配置),右侧是选中配置的编辑器,底部有运行、取消、应用、确定;几条配置的新建、修改、复制、删除、文件夹和顺序在“应用”或“确定”时一起保存,“取消”全部丢弃。焦点在配置树上时 macOS 按 ⌫/⌦、Windows 按 Delete 删除选中的配置,macOS 按 ⌃N、Windows 按 Alt+Insert 打开新建菜单。没有配置时和 IDEA 一样,左侧显示“未添加运行配置。”和“添加新… ⌃N”链接,右侧显示“添加新的运行配置…”链接和“或选择要编辑的运行配置”。复制对所有配置可用:内置运行按表单值复制成“<原名>(副本)”,构建插件生成的运行在应用时由 Core 复制并保留全部选择,副本存进 .lithe/run/plugin/<插件>.local.toml,原配置照常列出。文件夹存在配置自己的 folder 字段(项目配置进 configurations.yaml、本机和生成的配置进 local.yaml),可以新建、重命名(名称不能为空、不能重名、不能含控制字符)和解散,拖动配置可以换文件夹;关掉排序后可以拖动调整顺序,顺序和排序开关只存在 .lithe/run/local.yaml,标题栏下拉和构建窗口的列表顺序与对话框一致。批处理只能在 Windows 上运行:macOS/Linux 上仍可新建、编辑和保存(和 Windows 同事共享的配置不会消失),类型旁注明“仅 Windows”,编辑器顶部说明原因,配置树和标题栏下拉的这一行带警告图标,对话框的“运行”和标题栏运行按钮置灰,按下时只提示原因。内置运行的编辑器参照 IDEA 的 Shell Script 配置,有名称、“存为项目文件”、脚本文件或脚本文本、脚本选项、工作目录、环境变量、解释器路径、解释器选项(留空时显示自动值:Shell 按脚本首行 #! 选解释器,没有时 macOS/Linux 用 /bin/sh、Windows 用 bash;PowerShell 用 Windows 的 powershell 或 pwsh;cmd 用 cmd /d),脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁;解释器路径参照工具链设置做成下拉:“自动(实际生效值)”、终端新建菜单检测到的同类 shell(Shell 列 POSIX shell,PowerShell 列 pwsh/powershell,批处理列 cmd,显示名字和路径,不列 WSL 发行版)、字段里已有的其他值和“自定义…”,选“自定义…”后出现可填命令名或路径的输入框和浏览按钮,哪类 shell 由 Core 在字段上标出(shellFamily);PowerShell 的“绕过执行策略”默认勾选、只在 Windows 生效;可执行程序有程序路径、参数、工作目录和环境变量。字段、默认值、显示条件和校验错误全部来自 Core(runConfig.configurationTypes、runConfig.editorForm),新增字段不改宿主绘制代码。存为项目文件时写 .lithe/run/configurations.yaml,否则写 .lithe/run/local.yaml;插件运行另存 .lithe/run/plugin/<插件>.toml 与 <插件>.local.toml,并记下插件的作者/仓库、版本、版本要求、插件 API 版本和所需能力;旧版 configurations.json、local.json 在没有对应 YAML 时仍读取,第一次编辑该层时改写为 YAML 并删除 JSON。编辑对话框的“运行”、构建窗口的运行配置列表、标题栏的运行按钮和 Run 窗口的再次运行都能启动,启动时 Run 窗口自动打开并选中这次运行,输出进入它的控制台,以“进程已结束,退出码 N。”结束;脚本文本写到系统临时目录(不写安装目录),运行结束后删除。插件出错、未装或项目尚未加载构建模型时,内置运行照常列出和运行;某个运行配置文件没有读取(插件 TOML 写坏、同一配置存了两次、旧版 JSON 已被 YAML 取代)时,标题栏运行下拉按文件名列出它,点击在编辑器中打开", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -23,6 +23,8 @@ "desktop/internal/workbench/runconfig_form_view.go", "desktop/internal/workbench/runconfig_process.go", "desktop/internal/workbench/runconfig_process_test.go", + "desktop/internal/workbench/runconfig_shell_view.go", + "desktop/internal/workbench/runconfig_shell_test.go", "desktop/internal/workbench/runconfig_edit_test.go", "desktop/internal/workbench/runconfig_dialog_test.go", "desktop/internal/workbench/runconfig_process_visual_test.go", @@ -53,6 +55,8 @@ "desktop/internal/workbench/runconfig_form_view.go", "desktop/internal/workbench/runconfig_process.go", "desktop/internal/workbench/runconfig_process_test.go", + "desktop/internal/workbench/runconfig_shell_view.go", + "desktop/internal/workbench/runconfig_shell_test.go", "desktop/internal/workbench/runconfig_edit_test.go", "desktop/internal/workbench/runconfig_dialog_test.go", "desktop/internal/workbench/title_run.go", @@ -62,6 +66,6 @@ ] }, "owner": "Run", - "verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致;有构建插件生成的运行时复制它,点“应用”后确认 .lithe/run/plugin/<插件>.local.toml 出现副本、原配置仍在。删掉全部配置后重开对话框,确认左右两侧的 IDEA 式空白页,点两个链接和按 ⌃N(Windows 为 Alt+Insert)都弹出类型菜单。选中配置按 ⌫(Windows 为 Delete)删除,“取消”后恢复。选中配置点“新建文件夹”,在右侧把它改名(空名、重名、含 Tab 时提示原因),“应用”后确认配置文件里写入 folder;把另一条配置拖进这个文件夹;选中文件夹点“−”解散。关掉“按字母顺序排序”后拖动调整顺序,“应用”后确认只有 .lithe/run/local.yaml 的 arrangement 变化、标题栏下拉顺序一致,重新打开排序后恢复按名称。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 <插件>.local.toml)、文件夹新建/重命名/解散、手动顺序与排序开关、IDEA 式空白页与 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。", - "notes": "Issue #2100。只内置平台自带的脚本和二进制程序,Python、Node 等其他运行交给插件注入。Windows 上未指定解释器的 Shell 脚本按 PATH 找 bash,可能找到 WSL 的 bash;cmd 参数转义不处理 %(cmd 会展开环境变量);Core 拆分脚本选项、程序参数和解释器选项时把反斜杠当转义符(只在单引号内按原样保留),Windows 路径要用单引号括起来或把 \\ 写成 \\\\。对话框在应用窗口内以模态层显示。空文件夹只在对话框打开期间存在,不会保存(和 IDEA 一样,文件夹记在配置上)。配置树的行不显示悬停提示(Viva 的树行没有标识),不可运行的原因写在编辑器顶部和无障碍标签里。macOS 原生窗口验收、Windows 与 Linux 实机验证待做。" + "verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;展开解释器路径下拉,确认列出终端新建菜单里的同类 shell,选中一个后保存写入其路径,选“自定义…”填 PATH 上的命令名或用浏览选文件后能运行,改回“自动”后字段清空;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致;有构建插件生成的运行时复制它,点“应用”后确认 .lithe/run/plugin/<插件>.local.toml 出现副本、原配置仍在。删掉全部配置后重开对话框,确认左右两侧的 IDEA 式空白页,点两个链接和按 ⌃N(Windows 为 Alt+Insert)都弹出类型菜单。选中配置按 ⌫(Windows 为 Delete)删除,“取消”后恢复。选中配置点“新建文件夹”,在右侧把它改名(空名、重名、含 Tab 时提示原因),“应用”后确认配置文件里写入 folder;把另一条配置拖进这个文件夹;选中文件夹点“−”解散。关掉“按字母顺序排序”后拖动调整顺序,“应用”后确认只有 .lithe/run/local.yaml 的 arrangement 变化、标题栏下拉顺序一致,重新打开排序后恢复按名称。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 <插件>.local.toml)、文件夹新建/重命名/解散、手动顺序与排序开关、IDEA 式空白页与 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_shell_test.go 覆盖解释器下拉只列同类 shell、选中 shell、自定义输入、改回自动和保存;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。", + "notes": "Issue #2100。只内置平台自带的脚本和二进制程序,Python、Node 等其他运行交给插件注入。Windows 上未指定解释器的 Shell 脚本按 PATH 找 bash,可能找到 WSL 的 bash,需要 Git Bash 时从解释器下拉选终端检测到的 Git Bash 或自定义完整路径;cmd 参数转义不处理 %(cmd 会展开环境变量);Core 拆分脚本选项、程序参数和解释器选项时把反斜杠当转义符(只在单引号内按原样保留),Windows 路径要用单引号括起来或把 \\ 写成 \\\\。对话框在应用窗口内以模态层显示。空文件夹只在对话框打开期间存在,不会保存(和 IDEA 一样,文件夹记在配置上)。配置树的行不显示悬停提示(Viva 的树行没有标识),不可运行的原因写在编辑器顶部和无障碍标签里。macOS 原生窗口验收、Windows 与 Linux 实机验证待做。" }