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 b731abd1d9..78ea603390 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 @@ -97,6 +97,20 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) - 新的排列方式(比如按类型以外的维度分组)先在 Core 的 `Arrangement` 里定义和存储,再让宿主画;宿主不自己排序或记顺序。 - 只要改了名字或新建了配置,而列表又是手动顺序,就把配置树当前显示的顺序一起保存,否则新 ID 会掉到列表末尾。 +### 插件声明的运行类型 + +插件在清单的 `buildSystems[].runConfigurationTypes` 里为自己的构建系统声明运行类型(能力 `runConfigurationTypes` 0,对应 API-29),例如 Go 插件的 Go Build、Go Test。每个类型带标题、说明、图标、字段(`choice`、`checkbox`、`text` 等)和参数模板(`${field:}`、`${userArguments}`),文字由插件包里的翻译文件翻译。契约、校验、表单、保存和启动计划都在 Core(provider 为 `build.run-type`),宿主(`runconfig_types.go`)只做三件事: + +- 读类型:把已启用插件的清单交给 Core,Core 返回全部类型和每个插件该读哪几份翻译文件;宿主只从已安装的插件包里读这些文件(包目录只读),再问一次。翻译读不到时退回下一份或清单原文,类型照常列出。打开对话框时重新读一次,所以刚装、刚停用的插件和切换后的界面语言都能反映出来。 +- 画表单:插件字段的标题、选项名、占位符和说明直接用 Core 返回的翻译后文字,字段 ID 为 `field:`;宿主仍只画它认识的字段类型。插件声明的类型排在内置类型之后,每个类型在配置树里单独一组。图标用插件指定的宿主图标;指定包内图片的暂时显示执行方式的图标。 +- 起进程:Core 的 `build.runConfigurationPlan` 按配置的工作目录选出检测到的构建系统实例并给出参数,宿主用该实例解析出的构建工具起进程,和构建任务一样走 `buildprocess`。 + +存为项目文件的配置写进 `.lithe/run/plugin/<插件 ID>.toml`,本机配置写进 `<插件 ID>.local.toml`,和插件生成的运行同一套规则。项目里没检测到这个构建系统时,配置照常列出、可以编辑,但不能运行(`refusalNotReady`,提示找不到目标)。插件声明的类型没有调试器,调试启动返回 `refusalNotSupported`。 + +### 允许多个实例 + +所有运行配置(内置的和插件声明的)都有“允许多个实例”勾选项,字段 ID `allowMultipleInstances`,由 Core 描述、保存。不勾选时,按下运行会先停掉正在运行的那一个再重新启动(原来的行为);勾选后,新实例在旁边另开一个 Run 标签,已有的继续运行。调试只允许一个:同一配置已在运行时再按调试,返回 `errRunRunning`。 + ### 从界面按下运行时打开 Run 窗口 从编辑对话框的“运行”、构建窗口的配置列表(按钮或双击)和 Run 窗口的再次运行启动时,都走 `runConfiguration`(`runconfig.go`)。它启动后打开 Run 窗口,并选中这次运行的控制台;构建插件提供的运行从列表启动时也一样。经 IDE API(`startRunConfiguration`)启动的运行不改变窗口布局,因为调用方不一定是用户。 @@ -106,6 +120,7 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) - 给 Shell 表单加一个参数框:在 Core 的 `form.rs` 描述字段、在 `process.rs` 解释它的值,再在 `shared/i18n/` 加标题词条。宿主已认识这种类型时,不用改任何宿主代码。 - 新增一种全新的字段类型:先在宿主实现它的绘制,再让 Core 开始返回它;旧宿主跳过新字段,配置照样能保存。 - 插件运行需要新的元数据:加进插件 TOML 的 `[plugin]` 头,由 Core 读写,宿主不解析 TOML。 +- 插件要一种新的运行方式(例如 Go Test):在插件清单的 `runConfigurationTypes` 里声明,翻译放进插件包的 `l10n/`。宿主和 Core 都不按插件或工具名加分支。 - 别的字段也要从本机已安装的工具里选:在 Core 的字段上标一个属性(像 `shellFamily`),宿主按属性复用平台层已有的查找,不按字段 ID 或运行类型分支。 ### 不要这样做 @@ -115,6 +130,8 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) - 不要让内置运行等构建模型加载完、或等插件宿主就绪再出现,那正是这次要去掉的依赖。 - 不要把脚本文本写进项目目录或 app bundle。它是一次性的运行产物,只放系统临时目录。 - 不要在宿主里按运行类型(`process.shell` 等)决定列出哪类 shell,只读 `shellFamily`。 +- 不要在宿主里解析插件清单或拼插件运行的参数,也不要把插件字段的文字写进 `shared/i18n/`。标题和选项名来自插件的翻译,参数来自 Core 的计划。 +- 不要从插件包目录推导可写位置:启动计划需要的状态目录是插件在本工作区的状态目录(`buildStateDirectory`),不在插件包里。 - 不要用 `ui.C.After` 推迟 shell 查找:表单第一次画出的那一帧通常没有点击,这种帧会丢掉推迟的回调,列表就一直是空的。查找本身在后台运行,直接在绘制时发起即可。 ## 考虑过的备选方案 @@ -151,6 +168,14 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) 宿主可以完全控制布局。没有采用:每加一个字段都要同时改 Core 和两个桌面端,还要在宿主里重复 Core 的校验规则;以后 Windows 端还得再写一遍。 +### Go 插件之类的运行类型由宿主内置 + +宿主可以直接画 Go Build、Go Test 的表单,不用多一份契约。没有采用:用户要求插件自己用 API 注入运行方式;宿主内置就得按工具名加分支,Core 对具体语言和工具也不再零依赖。 + +### 多实例只在运行开始时临时决定(例如按住修饰键) + +不用多存一个字段。没有采用:IDEA 把它做成每个配置的选项,团队共享的配置(例如同时起两个服务实例)需要记住这个选择;临时修饰键也没法通过 IDE API 表达。 + ### 迁移时立即把所有旧 JSON 转成 YAML 一次转完,代码里不用再读 JSON。没有采用:打开项目就改写用户文件,会在版本控制里产生用户没做过的改动。现在只在用户真正编辑某一层时才转换。代价是旧客户端读不到被转换的那一层。 @@ -165,7 +190,8 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) ## 验证 - `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/` 的截图。 +- `runconfig_types_test.go` 用合成插件 `dev.lithe.test.run-types`(带中文翻译)覆盖插件声明类型:翻译后的标题、字段和选项名,新建、保存到 `.lithe/run/plugin/<插件 ID>.toml`、运行并检查实际参数,调试被拒;勾选“允许多个实例”后同时运行两个实例;没检测到构建系统时配置列出但不能运行。 +- `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench -run '^(TestVisualBuiltInProcessRuns|TestVisualTitleRunWithoutConfigurations|TestVisualPluginDeclaredRuns)$'`:设置 `LITHE_VISUAL_OUTPUT_DIR` 后生成 `docs/assets/builtin-process-runs/`、`docs/assets/run-config-empty/` 和 `docs/assets/plugin-declared-runs/` 的截图。 - Core 仓库的 `cargo test -p lithe-execution -p lithe-core`:覆盖表单、校验、启动计划、YAML/TOML 读写、旧 JSON、插件可用性,以及 `run_configuration_arrangement.rs` 里文件夹写入哪一层、顺序只进本机、复制保留全部选择。 - `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认运行不写发行目录。 @@ -176,6 +202,7 @@ Shell、PowerShell 和批处理表单的解释器字段(`kind: executable`) - `desktop/internal/workbench/runconfig_form.go` - `desktop/internal/workbench/runconfig_form_view.go` - `desktop/internal/workbench/runconfig_shell_view.go` +- `desktop/internal/workbench/runconfig_types.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/build.go b/desktop/internal/core/build.go index bb54adbeb3..2f01a456af 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -432,6 +432,46 @@ func (c *Client) planBuild(ctx context.Context, command string, manifest json.Ra return *result.Plan, nil } +// RunTypeInstance is one detected instance of a build system as +// `build.runConfigurationPlan` takes it: its workspace-relative root and stored options. +type RunTypeInstance struct { + Root string `json:"root"` + Options map[string]json.RawMessage `json:"options,omitempty"` +} + +// RunConfigurationPlanRequest asks for the launch of saved configuration +// ConfigurationID of a kind the build system declares. Core runs it with the +// instance whose root holds the configuration's working directory. +type RunConfigurationPlanRequest struct { + ConfigurationID string `json:"configurationId"` + Instances []RunTypeInstance `json:"instances"` + PluginDirectory string `json:"pluginDirectory,omitempty"` + WorkspaceStateDirectory string `json:"workspaceStateDirectory,omitempty"` +} + +// PlanRunConfiguration plans a saved configuration of a plugin-declared run kind +// (`build.runConfigurationPlan`): the command plan of the chosen instance, whose +// Root names it, with the configuration's environment already in Environment. +func (c *Client) PlanRunConfiguration(ctx context.Context, manifest json.RawMessage, buildSystemID, workspaceRoot string, request RunConfigurationPlanRequest) (BuildPlan, error) { + const command = "build.runConfigurationPlan" + var result buildOutcome + if err := c.Execute(ctx, command, struct { + Manifest json.RawMessage `json:"manifest"` + BuildSystemID string `json:"buildSystemID"` + WorkspaceRoot string `json:"workspaceRoot"` + Request RunConfigurationPlanRequest `json:"request"` + }{manifest, buildSystemID, workspaceRoot, request}, &result); err != nil { + return BuildPlan{}, err + } + if err := result.failure(command); err != nil { + return BuildPlan{}, err + } + if result.Plan == nil { + return BuildPlan{}, newParseError(command, "run configuration plan returned no plan", "") + } + return *result.Plan, nil +} + // DecodeBuildModel turns static/command output or a provider result into the // normalized model. func (c *Client) DecodeBuildModel(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeModelRequest) (BuildModel, error) { diff --git a/desktop/internal/core/run_config.go b/desktop/internal/core/run_config.go index df4f728969..c259c1dd6c 100644 --- a/desktop/internal/core/run_config.go +++ b/desktop/internal/core/run_config.go @@ -53,6 +53,9 @@ type RunConfiguration struct { Availability *RunAvailability `json:"availability,omitempty"` // BeforeLaunch names the built-in process runs started, in order, before this one. BeforeLaunch []RunBeforeLaunchStep `json:"beforeLaunch,omitempty"` + // AllowMultipleInstances lets a new run start beside one still running instead of + // stopping it first. + AllowMultipleInstances bool `json:"allowMultipleInstances,omitempty"` } // RunBeforeLaunchStep is one step of a configuration's beforeLaunch: the built-in @@ -139,6 +142,20 @@ func (r RunConfiguration) BuildReference() (RunProviderReference, bool) { return reference, true } +// RunTypeReference is the declared kind a `build.run-type` configuration belongs to, +// when it is one. +func (r RunConfiguration) RunTypeReference() (RunTypeKey, bool) { + raw, ok := r.Extensions["build"] + if !ok || r.Provider != RunTypeProvider { + return RunTypeKey{}, false + } + var key RunTypeKey + if json.Unmarshal(raw, &key) != nil || key.PluginID == "" || key.BuildSystemID == "" || key.Type == "" { + return RunTypeKey{}, false + } + return key, true +} + // RunConfigResolution is what `runConfig.resolve` returns: the effective // configurations, Core's findings about them and the default one. type RunConfigResolution struct { diff --git a/desktop/internal/core/run_config_test.go b/desktop/internal/core/run_config_test.go index 253d2f5057..e8f2d3326d 100644 --- a/desktop/internal/core/run_config_test.go +++ b/desktop/internal/core/run_config_test.go @@ -166,7 +166,7 @@ func TestBuiltInProcessRunRoundTrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() root := t.TempDir() - kinds, err := client.RunConfigurationTypes(ctx) + kinds, _, err := client.RunConfigurationTypes(ctx, nil) if err != nil || len(kinds) == 0 || kinds[0].Provider != "process.shell" { t.Fatalf("kinds = %+v, %v", kinds, err) } diff --git a/desktop/internal/core/run_process.go b/desktop/internal/core/run_process.go index d70de167aa..3eb3be78e0 100644 --- a/desktop/internal/core/run_process.go +++ b/desktop/internal/core/run_process.go @@ -9,13 +9,65 @@ import ( // form is refused, since its fields may mean something this host cannot show. const RunFormVersion = 1 -// RunConfigurationType is one built-in run configuration kind a user can create, -// such as `process.shell`. Availability is set when this platform cannot run the -// kind, such as a batch script outside Windows; its configurations are still -// created and edited. +// RunConfigurationType is one run configuration kind a user can create: a built-in +// one such as `process.shell`, or, with provider `build.run-type`, one an installed +// plugin declares, named by RunType and shown with the plugin's DisplayName, +// Description and Icon. Availability is set when this platform cannot run the kind, +// such as a batch script outside Windows; its configurations are still created and +// edited. type RunConfigurationType struct { Provider string `json:"provider"` Availability *RunAvailability `json:"availability,omitempty"` + RunType *RunTypeKey `json:"runType,omitempty"` + DisplayName string `json:"displayName,omitempty"` + Execution string `json:"execution,omitempty"` + Description string `json:"description,omitempty"` + Icon *RunTypeIcon `json:"icon,omitempty"` +} + +// RunTypeProvider is the provider of every configuration of a plugin-declared kind. +const RunTypeProvider = "build.run-type" + +// RunTypeKey names a plugin-declared run configuration kind: the plugin, its build +// system and the kind's ID within it. +type RunTypeKey struct { + PluginID string `json:"pluginID"` + BuildSystemID string `json:"buildSystemID"` + Type string `json:"type"` +} + +// RunTypeIcon is the icon a declared kind names: a host icon such as `run`, or a +// package image (Path, DarkPath) relative to the plugin directory. +type RunTypeIcon struct { + Host string `json:"host,omitempty"` + Path string `json:"path,omitempty"` + DarkPath string `json:"darkPath,omitempty"` + Mode string `json:"mode,omitempty"` +} + +// RunTypePlugins is the `runTypePlugins` the run configuration editor commands take: +// every enabled plugin's manifest, and the interface Language their text is +// translated to. Core lists the kinds the manifests declare; a manifest that declares +// none, or does not validate, adds nothing. +type RunTypePlugins struct { + Language string `json:"language,omitempty"` + Plugins []RunTypePlugin `json:"plugins"` +} + +// RunTypePlugin is one enabled plugin. Localizations are the translation files the +// host read from the package, by package-relative path; nil until a report asked for +// them, so Core tells which files to read. An empty map that is not nil says the +// host read the candidates and found none, so it is sent as {} and nil as null. +type RunTypePlugin struct { + Manifest json.RawMessage `json:"manifest"` + Localizations map[string]string `json:"localizations"` +} + +// RunTypeLocalization is the translation report of one plugin that declares a kind, +// the report of plugin settings with the plugin it is about. +type RunTypeLocalization struct { + PluginID string `json:"pluginID"` + PluginSettingsLocalization } // Unavailable says this platform cannot run configurations of the kind. @@ -23,14 +75,19 @@ func (t RunConfigurationType) Unavailable() bool { return t.Availability != nil && t.Availability.Status == "unavailable" } -// RunConfigurationTypes lists the built-in kinds a user can create, in display -// order. Every platform lists every kind; one it cannot run says so. -func (c *Client) RunConfigurationTypes(ctx context.Context) ([]RunConfigurationType, error) { +// RunConfigurationTypes lists the kinds a user can create, in display order: the +// built-in ones, then the kinds plugins declare. Every platform lists every built-in +// kind; one it cannot run says so. With a language, the answer reports per plugin +// which translation files to read, for a second call with them. +func (c *Client) RunConfigurationTypes(ctx context.Context, plugins *RunTypePlugins) ([]RunConfigurationType, []RunTypeLocalization, error) { var result struct { - Types []RunConfigurationType `json:"types"` + Types []RunConfigurationType `json:"types"` + Localizations []RunTypeLocalization `json:"localizations"` } - err := c.Execute(ctx, "runConfig.configurationTypes", struct{}{}, &result) - return result.Types, err + err := c.Execute(ctx, "runConfig.configurationTypes", struct { + RunTypePlugins *RunTypePlugins `json:"runTypePlugins,omitempty"` + }{plugins}, &result) + return result.Types, result.Localizations, err } // RunEditorField is one field of a run configuration editor. Kind is text, @@ -39,17 +96,23 @@ func (c *Client) RunConfigurationTypes(ctx context.Context) ([]RunConfigurationT // back. Automatic is the value used while the field is empty, shown as its // 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. +// cmd), so a host can offer the installed shells of that family. A field a +// plugin declares (ID `field:`) carries its own translated Label, +// Description, Placeholder and the titles of its Options in OptionLabels. type RunEditorField struct { - ID string `json:"id"` - Kind string `json:"kind"` - Required bool `json:"required,omitempty"` - Placement string `json:"placement,omitempty"` - Automatic *string `json:"automatic,omitempty"` - Options []string `json:"options,omitempty"` - VisibleWhen *RunFieldCondition `json:"visibleWhen,omitempty"` - Note string `json:"note,omitempty"` - ShellFamily string `json:"shellFamily,omitempty"` + ID string `json:"id"` + Kind string `json:"kind"` + Required bool `json:"required,omitempty"` + Placement string `json:"placement,omitempty"` + Automatic *string `json:"automatic,omitempty"` + Options []string `json:"options,omitempty"` + VisibleWhen *RunFieldCondition `json:"visibleWhen,omitempty"` + Note string `json:"note,omitempty"` + ShellFamily string `json:"shellFamily,omitempty"` + Label string `json:"label,omitempty"` + Description string `json:"description,omitempty"` + Placeholder string `json:"placeholder,omitempty"` + OptionLabels map[string]string `json:"optionLabels,omitempty"` // Candidates are the configurations a beforeLaunch field may name. Candidates []RunConfigurationName `json:"candidates,omitempty"` } @@ -69,7 +132,9 @@ type RunFieldCondition struct { // RunEditorForm is what `runConfig.editorForm` returns: the fields in order and // the current value of each, by field ID. Values stay raw so keys this host // does not show go back unchanged. Availability is set when this platform cannot -// run the kind; the form still edits and saves it. +// run the kind; the form still edits and saves it. RunType names the declared kind +// of a `build.run-type` form; Localizations report the translation files to read, +// as RunConfigurationTypes does. type RunEditorForm struct { FormVersion int `json:"formVersion"` Provider string `json:"provider"` @@ -77,16 +142,21 @@ type RunEditorForm struct { Values map[string]json.RawMessage `json:"values"` Fields []RunEditorField `json:"fields"` Availability *RunAvailability `json:"availability,omitempty"` + RunType *RunTypeKey `json:"runType,omitempty"` + Localizations []RunTypeLocalization `json:"localizations,omitempty"` } -// RunEditorFormRequest asks for the editor of a new configuration of Provider or -// of the saved ConfigurationID. Values are the open editor's unsaved values, so -// the automatic values follow the edit. +// RunEditorFormRequest asks for the editor of a new configuration of Provider (and +// RunType, for a declared kind) or of the saved ConfigurationID. Values are the open +// editor's unsaved values, so the automatic values follow the edit. RunTypePlugins +// list the kinds plugins declare; a declared kind's form needs them. type RunEditorFormRequest struct { Root string `json:"root"` Provider string `json:"provider,omitempty"` + RunType *RunTypeKey `json:"runType,omitempty"` ConfigurationID string `json:"configurationId,omitempty"` Values map[string]json.RawMessage `json:"values,omitempty"` + RunTypePlugins *RunTypePlugins `json:"runTypePlugins,omitempty"` } // RunEditorForm describes the editor fields and current values of a built-in run configuration. @@ -103,13 +173,17 @@ type RunFieldError struct { Code string `json:"code"` } -// RunConfigurationSave is a `runConfig.saveConfiguration` request. +// RunConfigurationSave is a `runConfig.saveConfiguration` request. RunType and +// RunTypePlugins are set for a declared kind, whose display name is the default +// configuration name. type RunConfigurationSave struct { Root string `json:"root"` Provider string `json:"provider"` + RunType *RunTypeKey `json:"runType,omitempty"` ConfigurationID string `json:"configurationId,omitempty"` Values map[string]json.RawMessage `json:"values"` Plugins []RunInstalledPlugin `json:"plugins,omitempty"` + RunTypePlugins *RunTypePlugins `json:"runTypePlugins,omitempty"` } // RunConfigurationSaved is the answer of `runConfig.saveConfiguration`: Status diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 889b91b965..ae9ab7055e 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1352,6 +1352,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.statusSucceeded": "Succeeded", "desktop.runConfig.addNew": "Add New…", "desktop.runConfig.addNewConfiguration": "Add New Run Configuration…", + "desktop.runConfig.allowMultipleInstancesHelp": "Checked, starting the configuration while it runs starts another instance beside the running one; unchecked, the running instance is stopped and started again.", "desktop.runConfig.apply": "Apply", "desktop.runConfig.arguments": "Program arguments", "desktop.runConfig.argumentsPlaceholder": "Arguments for the program, e.g. --port 8080; separate with spaces and quote one that contains spaces", @@ -1410,6 +1411,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.errorRequired": "Required", "desktop.runConfig.errorTooLong": "Too long", "desktop.runConfig.errorUnavailable": "Not available on this system", + "desktop.runConfig.fieldAllowMultipleInstances": "Allow multiple instances", "desktop.runConfig.fieldBeforeLaunch": "Before launch", "desktop.runConfig.fieldExecutionPolicyBypass": "Bypass execution policy (-ExecutionPolicy Bypass)", "desktop.runConfig.fieldInterpreter": "Interpreter path", @@ -4310,6 +4312,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.statusSucceeded": "成功", "desktop.runConfig.addNew": "添加新…", "desktop.runConfig.addNewConfiguration": "添加新的运行配置…", + "desktop.runConfig.allowMultipleInstancesHelp": "勾选后,配置运行时再次启动会另开一个实例,与正在运行的并存;不勾选则先停止正在运行的实例,再重新启动。", "desktop.runConfig.apply": "应用", "desktop.runConfig.arguments": "程序参数", "desktop.runConfig.argumentsPlaceholder": "传给程序的参数,例如 --port 8080;多个参数用空格分隔,含空格的参数用引号括起来", @@ -4368,6 +4371,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.errorRequired": "必填", "desktop.runConfig.errorTooLong": "内容太长", "desktop.runConfig.errorUnavailable": "在此系统上不可用", + "desktop.runConfig.fieldAllowMultipleInstances": "允许多个实例", "desktop.runConfig.fieldBeforeLaunch": "启动前", "desktop.runConfig.fieldExecutionPolicyBypass": "绕过执行策略(-ExecutionPolicy Bypass)", "desktop.runConfig.fieldInterpreter": "解释器路径", diff --git a/desktop/internal/pluginhost/pluginhost.go b/desktop/internal/pluginhost/pluginhost.go index 2e11bc3889..4346309503 100644 --- a/desktop/internal/pluginhost/pluginhost.go +++ b/desktop/internal/pluginhost/pluginhost.go @@ -101,6 +101,11 @@ type Capabilities map[string][]int // and discovers and runs provider tests. Run on Current File asks the // providers of version 1 for the file's entrypoints and saves the first as a // run configuration. Run sessions a backend starts are owned by the host. +// - runConfigurationTypes: the Run/Debug Configurations dialog lists the +// kinds a build system declares after the built-in ones, edits them with the +// form Core describes in the plugin's translation, saves them and runs them +// with the command Core plans for the detected instance. A declared kind has +// no debugger. // - toolDefinitions: settings discovery, Build/Run selection and tool // launches use the shared Core resolver. // - commandInstallers: plugin management reports the commands a @@ -155,6 +160,7 @@ func Declared() Capabilities { "outputLinkMatchers", "pluginFunctions", "projectGenerators", + "runConfigurationTypes", "settings", "sourceSettings", "toolDefinitions", diff --git a/desktop/internal/pluginhost/pluginhost_test.go b/desktop/internal/pluginhost/pluginhost_test.go index c0e27bba46..f068fc197c 100644 --- a/desktop/internal/pluginhost/pluginhost_test.go +++ b/desktop/internal/pluginhost/pluginhost_test.go @@ -61,7 +61,8 @@ func TestDeclaredServesTheBaselineOfEveryWiredCapability(t *testing.T) { want := []string{ "backend", "buildProviders", "buildSystems", "commandInstallers", "debugAdapters", "languageServers", "languages", "outputLinkMatchers", "pluginFunctions", - "projectGenerators", "settings", "sourceSettings", "toolDefinitions", "ui", "vcsProviders", + "projectGenerators", "runConfigurationTypes", "settings", "sourceSettings", "toolDefinitions", "ui", + "vcsProviders", } if len(declared) != len(want) { t.Fatalf("declared = %v", declared) diff --git a/desktop/internal/pluginservice/toolchains.go b/desktop/internal/pluginservice/toolchains.go index 8b83f6e748..9698136851 100644 --- a/desktop/internal/pluginservice/toolchains.go +++ b/desktop/internal/pluginservice/toolchains.go @@ -18,6 +18,9 @@ type ToolchainPlugin struct { PluginID string Version string Manifest json.RawMessage + // Directory is the installed package, read-only; files the manifest names, such as + // its translations, are read from it. + Directory string } // ToolchainPlugins reads the newest enabled version of every plugin. The @@ -37,9 +40,10 @@ func (s *Service) ToolchainPlugins(ctx context.Context, entries []pluginmanager. continue } plugins = append(plugins, ToolchainPlugin{ - PluginID: entry.Installed.ID, - Version: entry.Installed.Version, - Manifest: manifest, + PluginID: entry.Installed.ID, + Version: entry.Installed.Version, + Manifest: manifest, + Directory: entry.Installed.Path, }) } return plugins, errors.Join(failures...) diff --git a/desktop/internal/pluginsettings/store.go b/desktop/internal/pluginsettings/store.go index 39de7f688b..8a6567ca0b 100644 --- a/desktop/internal/pluginsettings/store.go +++ b/desktop/internal/pluginsettings/store.go @@ -118,7 +118,7 @@ func (s *Store) load(ctx context.Context, manifest json.RawMessage, workspace st return snapshot, nil } if translate { - localization.Files, snapshot.unreadable, err = readTranslations(ctx, presentation.Package, *policy.Localization) + localization.Files, snapshot.unreadable, err = ReadTranslations(ctx, presentation.Package, *policy.Localization) if err != nil { return Snapshot{}, err } @@ -163,9 +163,10 @@ func (s *Store) load(ctx context.Context, manifest json.RawMessage, workspace st return snapshot, nil } -// readTranslations returns every candidate present in the package. A missing -// candidate is the normal case; any other failure skips only that file. -func readTranslations(ctx context.Context, packageDirectory string, plan core.PluginSettingsLocalization) (map[string]string, []LocalizationReadFailure, error) { +// ReadTranslations returns every candidate of plan present in the package, as Core's +// localization reports name them. A missing candidate is the normal case; any other +// failure skips only that file. Only a cancelled ctx fails the whole read. +func ReadTranslations(ctx context.Context, packageDirectory string, plan core.PluginSettingsLocalization) (map[string]string, []LocalizationReadFailure, error) { files := map[string]string{} var unreadable []LocalizationReadFailure for _, candidate := range plan.Candidates { diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index c86bd34bd4..4bd9eff1b7 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -78,6 +78,7 @@ type Kernel interface { CheckBuildToolVersion(ctx context.Context, manifest json.RawMessage, buildSystemID, runtime, output string) (core.BuildToolVersion, error) PlanBuildModel(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildPlanRequest) (core.BuildPlan, error) PlanBuildTask(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildPlanRequest) (core.BuildPlan, error) + PlanRunConfiguration(ctx context.Context, manifest json.RawMessage, buildSystemID, workspaceRoot string, request core.RunConfigurationPlanRequest) (core.BuildPlan, error) PlanBuildTest(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildTestRequest) (core.BuildPlan, error) DecodeBuildTestResults(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildTestResultsRequest) (core.BuildTestResults, error) ResolveBuildTestOutcome(ctx context.Context, termination core.BuildTestTermination, project, suite, caseName string, summary *core.BuildTestSummary) (core.BuildTestVerdict, error) @@ -105,7 +106,7 @@ type Kernel interface { UpdateRunConfigurationOptions(ctx context.Context, edit core.RunOptionsEdit) ([]core.RunConfigChange, error) // RunConfigurationTypes, RunEditorForm, SaveRunConfiguration, DeleteRunConfiguration and // CreateRunLaunchPlan create, edit and start the built-in process runs (runconfig_process.go). - RunConfigurationTypes(ctx context.Context) ([]core.RunConfigurationType, error) + RunConfigurationTypes(ctx context.Context, plugins *core.RunTypePlugins) ([]core.RunConfigurationType, []core.RunTypeLocalization, error) RunEditorForm(ctx context.Context, request core.RunEditorFormRequest) (core.RunEditorForm, error) SaveRunConfiguration(ctx context.Context, request core.RunConfigurationSave) (core.RunConfigurationSaved, error) DeleteRunConfiguration(ctx context.Context, root, configurationID string, plugins []core.RunInstalledPlugin) ([]core.RunConfigChange, error) diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index 30545c4cf0..ca47e49602 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -33,11 +33,15 @@ type runConfigState struct { // release's JSON document its YAML replacement wins over. The built-in configurations // still list; the run menu names each file so its configurations do not vanish silently. ignored []string - // types are the built-in kinds a user can create, in display order, each with the reason - // this platform cannot run it, if any; read once per project; typesLoading is set while - // they are asked for. - types []core.RunConfigurationType - typesLoading bool + // types are the kinds a user can create, in display order, each with the reason this + // platform cannot run it, if any: the built-in ones, then the ones enabled plugins + // declare. typePlugins are the plugins that declare them, as requests about those kinds + // send them, nil when none does; both are replaced, never changed, by the next read. + // typesLoading is set while they are asked for, and typesStale says to read them again + // once that answers (loadRunConfigTypes). + types []core.RunConfigurationType + typePlugins *core.RunTypePlugins + typesLoading, typesStale bool // manualOrder says list is in the order the user gave it on this machine rather than by // name; Core keeps the choice locally and lists the configurations in that order. manualOrder bool @@ -157,16 +161,16 @@ func (a *App) finishRunConfigurations(p *project, generation uint64, resolved co s.loading = false defer a.settleTitleAction(p) a.loadRunConfigPins(p) - a.loadRunConfigTypes(p) + a.loadRunConfigTypes(p, false) if err != nil { s.failure = err.Error() s.reveal, s.start = "", "" return } s.failure = "" - // Built-in process runs and build provider runs start here; the host has no launcher - // for the other providers Core detects. An unavailable entry stays listed with its - // reason, so the user can fix or delete it. + // Built-in process runs, build provider runs and the kinds plugins declare start here; + // the host has no launcher for the other providers Core detects. An unavailable entry + // stays listed with its reason, so the user can fix or delete it. s.hidden = 0 var ignored []string for _, diagnostic := range resolved.Diagnostics { @@ -183,7 +187,8 @@ func (a *App) finishRunConfigurations(p *project, generation uint64, resolved co s.ignored = ignored s.list = slices.DeleteFunc(resolved.Configurations, func(c core.RunConfiguration) bool { _, ok := c.BuildReference() - ok = ok || c.IsProcess() || c.Unavailable() + _, declared := c.RunTypeReference() + ok = ok || declared || c.IsProcess() || c.Unavailable() if !ok && !c.Disabled { s.hidden++ } @@ -219,12 +224,18 @@ func (a *App) finishRunConfigurations(p *project, generation uint64, resolved co // button that is disabled; the IDE API reports it through startRunConfiguration, which // leaves the windows as they are. func (a *App) runConfiguration(p *project, id string) { - // A configuration that runs is stopped first and started again once it ended (startRun). - a.startRun(p, configurationRunKey(id), func(a *App, p *project) { + start := func(a *App, p *project) { if _, err := a.startRunConfiguration(p, id); err == nil { a.showBuildConsole(p) } - }) + } + // A configuration that allows several instances starts beside the ones that run; any + // other that runs is stopped first and started again once it ended (startRun). + if configuration := p.runConfigs.configuration(id); configuration != nil && configuration.AllowMultipleInstances { + start(a, p) + return + } + a.startRun(p, configurationRunKey(id), start) } // configurationRunKey is the run key of run configuration id. @@ -246,7 +257,8 @@ func (a *App) startRunConfigurationWith(p *project, id string, debug *connection if configuration == nil { return nil, refuseBuild(refusalNotFound, "unknown run configuration") } - if p.build.runOf(configurationRunKey(id)) != nil { + // Only a run, never a debug session, starts beside one of the same configuration. + if p.build.runOf(configurationRunKey(id)) != nil && (debug != nil || !configuration.AllowMultipleInstances) { return nil, errRunRunning } if configuration.Unavailable() { @@ -261,6 +273,17 @@ func (a *App) startRunConfigurationWith(p *project, id string, debug *connection } return a.startProcessRun(p, *configuration), nil } + if key, ok := configuration.RunTypeReference(); ok { + if debug != nil { + return nil, refuseBuild(refusalNotSupported, "a run configuration a plugin declares has no debugger") + } + if !p.hasRunTypeInstance(key) { + a.operationRejected("run_configuration", "target_missing") + a.notifyError(a.text.Build.TargetMissing) + return nil, refuseBuild(refusalNotReady, a.text.Build.TargetMissing) + } + return a.startProcessRun(p, *configuration), nil + } reference, ok := configuration.BuildReference() if !ok { return nil, refuseBuild(refusalNotSupported, "this configuration does not start through a build provider") @@ -346,8 +369,8 @@ func (p *project) buildInstanceIndex(reference core.RunProviderReference) int { } // runConfigurationReady reports whether a configuration can start now: a built-in process -// run always can unless it is unavailable; a build provider run once its build instance has -// a loaded model. +// run always can unless it is unavailable; one of a kind a plugin declares once its build +// system is detected; a build provider run once its build instance has a loaded model. func (p *project) runConfigurationReady(configuration core.RunConfiguration) bool { if configuration.Unavailable() { return false @@ -355,6 +378,9 @@ func (p *project) runConfigurationReady(configuration core.RunConfiguration) boo if configuration.IsProcess() { return true } + if key, ok := configuration.RunTypeReference(); ok { + return p.hasRunTypeInstance(key) + } reference, ok := configuration.BuildReference() if !ok { return false @@ -390,7 +416,8 @@ func (a *App) runConfigUnavailableText(configuration core.RunConfiguration) stri case "invalidConfiguration": return i18n.SharedFormat(language, "desktop.runConfig.unavailableInvalid", map[string]string{"reason": availability.Message}) case "unsupportedPlatform": - return a.runAvailabilityText(configuration.Provider, *availability) + kind, _ := runConfigKindOf(configuration) + return a.runAvailabilityText(kind, *availability) } return i18n.SharedFormat(language, "desktop.runConfig.unavailableOther", map[string]string{"reason": availability.Message}) } diff --git a/desktop/internal/workbench/runconfig_browser.go b/desktop/internal/workbench/runconfig_browser.go index 9f7549fda8..6192815285 100644 --- a/desktop/internal/workbench/runconfig_browser.go +++ b/desktop/internal/workbench/runconfig_browser.go @@ -95,12 +95,15 @@ type runConfigRow struct { const runProcessGroupKey = "\x00process" // runConfigGroupKey names the group of a configuration: the built-in runs, or the build -// system that provides it, by its plugin and build system whatever root the system was -// detected at, or the plugin a run that cannot resolve needs. +// system that provides it or declares its kind, by its plugin and build system whatever root +// the system was detected at, or the plugin a run that cannot resolve needs. func runConfigGroupKey(configuration *core.RunConfiguration) string { if configuration.IsProcess() { return runProcessGroupKey } + if key, ok := configuration.RunTypeReference(); ok { + return key.PluginID + "\x00" + key.BuildSystemID + } reference, ok := configuration.BuildReference() if !ok && configuration.Plugin != nil { return configuration.Plugin.ID + "\x00" @@ -201,6 +204,15 @@ func (p *project) runConfigGroupTitle(language i18n.Language, configuration *cor if configuration.IsProcess() { return i18n.Shared(language, "desktop.runConfig.builtInGroup") } + if key, ok := configuration.RunTypeReference(); ok { + if instances := p.runTypeInstances(key); len(instances) > 0 && instances[0].System.DisplayName != "" { + return instances[0].System.DisplayName + } + if plugin := configuration.Plugin; plugin != nil && plugin.Name != "" { + return plugin.Name + } + return key.BuildSystemID + } reference, ok := configuration.BuildReference() if plugin := configuration.Plugin; !ok && plugin != nil { return cmp.Or(plugin.Name, plugin.ID) diff --git a/desktop/internal/workbench/runconfig_dialog.go b/desktop/internal/workbench/runconfig_dialog.go index a548105343..6ba0ec73c8 100644 --- a/desktop/internal/workbench/runconfig_dialog.go +++ b/desktop/internal/workbench/runconfig_dialog.go @@ -204,7 +204,7 @@ func (a *App) openRunConfigDialog(p *project, id string) { } a.title.runConfigOpen = false a.loadTitleRunConfigs(p) - a.loadRunConfigTypes(p) + a.loadRunConfigTypes(p, true) if configuration := p.runConfigs.configuration(id); configuration != nil { a.selectRunConfigDraft(p, id) group := p.runConfigDialogGroupKey(id) @@ -277,10 +277,12 @@ func (a *App) selectRunConfigDraft(p *project, key string) { return } draft := &runConfigDraft{key: key, folder: configuration.Folder} + kind, form := runConfigKindOf(*configuration) switch { - case configuration.IsProcess(): - draft.form = a.openRunConfigForm(p, configuration.Provider, key, nil) - case runConfigEditable(*configuration): + case !runConfigEditable(*configuration): + case form: + draft.form = a.openRunConfigForm(p, kind, key, nil) + default: draft.editor = a.openRunConfigEditor(p, key) } d.drafts[key] = draft @@ -305,12 +307,12 @@ func (a *App) selectRunConfigDialogRow(p *project, row runConfigDialogRow) { } } -// addRunConfigDraft creates a new configuration of provider, seeded with values when they are -// set, opens its group and selects it. With a folder of that kind selected, or a configuration -// in one, the new configuration goes in that folder, as in IDEA. -func (a *App) addRunConfigDraft(p *project, provider string, values map[string]json.RawMessage) { +// addRunConfigDraft creates a new configuration of kind, seeded with values when they are set, +// opens its group and selects it. With a folder of that kind selected, or a configuration in +// one, the new configuration goes in that folder, as in IDEA. +func (a *App) addRunConfigDraft(p *project, kind runConfigKind, values map[string]json.RawMessage) { d := &p.runConfigs.dialog - group := runProcessKindKey(provider) + group := kind.groupKey() folder := d.node.folder if d.selected != "" { folder = p.runConfigDialogFolder(d.selected) @@ -322,7 +324,7 @@ func (a *App) addRunConfigDraft(p *project, provider string, values map[string]j } d.next++ key := runConfigNewKey + strconv.Itoa(d.next) - draft := &runConfigDraft{key: key, form: a.openRunConfigForm(p, provider, "", values)} + draft := &runConfigDraft{key: key, form: a.openRunConfigForm(p, kind, "", values)} d.drafts[key] = draft d.added = append(d.added, key) if folder != "" { @@ -364,7 +366,7 @@ func (a *App) copyRunConfigDraft(p *project) { if draft.form != nil { values := draft.form.collect() values["name"], _ = json.Marshal(name) - a.addRunConfigDraft(p, draft.form.provider, values) + a.addRunConfigDraft(p, draft.form.kind, values) d.moveToFolder(d.selected, folder) return } @@ -464,14 +466,14 @@ func (p *project) runConfigRemovable(key string) bool { // runConfigDialogGroupKey is the tree group of configuration or draft key. func (p *project) runConfigDialogGroupKey(key string) string { if configuration := p.runConfigs.configuration(key); configuration != nil { - if configuration.IsProcess() { - return runProcessKindKey(configuration.Provider) + if kind, ok := runConfigKindOf(*configuration); ok { + return kind.groupKey() } return runConfigGroupKey(configuration) } if draft := p.runConfigs.dialog.drafts[key]; draft != nil { if draft.form != nil { - return runProcessKindKey(draft.form.provider) + return draft.form.kind.groupKey() } return draft.group.key } @@ -529,16 +531,8 @@ func (p *project) collectRunConfigDialogRows(a *App) { } members[group.key] = append(members[group.key], key) } - processGroup := func(provider string) runConfigDialogGroup { - title, ok := runConfigTypeLabel(language, provider) - if !ok { - title = i18n.Shared(language, "desktop.runConfig.builtInGroup") - } - order := slices.IndexFunc(s.types, func(kind core.RunConfigurationType) bool { return kind.Provider == provider }) - if order < 0 { - order = len(s.types) - } - return runConfigDialogGroup{key: runProcessKindKey(provider), title: title, icon: runConfigTypeIcon(provider, a.colors.Dark), order: order} + kindGroup := func(kind runConfigKind) runConfigDialogGroup { + return runConfigDialogGroup{key: kind.groupKey(), title: s.kindTitle(language, kind), icon: s.kindIcon(kind, a.colors.Dark), order: s.kindOrder(kind)} } listed := map[string]bool{} for index := range s.list { @@ -547,8 +541,8 @@ func (p *project) collectRunConfigDialogRows(a *App) { if d.removed[configuration.ID] || d.hidden[configuration.ID] { continue } - if configuration.IsProcess() { - place(configuration.ID, processGroup(configuration.Provider)) + if kind, ok := runConfigKindOf(*configuration); ok { + place(configuration.ID, kindGroup(kind)) continue } place(configuration.ID, runConfigDialogGroup{ @@ -560,7 +554,7 @@ func (p *project) collectRunConfigDialogRows(a *App) { switch { case listed[key] || draft == nil: case draft.form != nil: - place(key, processGroup(draft.form.provider)) + place(key, kindGroup(draft.form.kind)) case draft.copyOf != "": place(key, draft.group) } @@ -872,7 +866,7 @@ func (a *App) runConfigDraftUnavailable(p *project, key string) string { draft := p.runConfigs.dialog.drafts[key] if draft != nil && draft.form != nil { if availability := draft.form.availability; availability != nil && availability.Status == "unavailable" { - return a.runAvailabilityText(draft.form.provider, *availability) + return a.runAvailabilityText(draft.form.kind, *availability) } if draft.form.dirty { return "" @@ -1296,19 +1290,20 @@ func (p *project) toggleRunConfigDialogNode(node runConfigDialogNode) { } } -// runAvailabilityText words why this platform cannot run a configuration of provider, from -// the availability Core gave its kind or its editor. -func (a *App) runAvailabilityText(provider string, availability core.RunAvailability) string { +// runAvailabilityText words why this platform cannot run a configuration of kind, from the +// availability Core gave its kind or its editor. Only a built-in kind is bound to a platform; +// any other reason shows Core's message. +func (a *App) runAvailabilityText(kind runConfigKind, availability core.RunAvailability) string { language := a.language() - if availability.Code == "unsupportedPlatform" { - if provider == runProviderBatch { + if availability.Code == "unsupportedPlatform" && !kind.declared() { + if kind.provider == runProviderBatch { return i18n.Shared(language, "desktop.runConfig.unavailableBatchPlatform") } - kind, ok := runConfigTypeLabel(language, provider) + title, ok := runConfigTypeLabel(language, kind.provider) if !ok { - kind = provider + title = kind.provider } - return i18n.SharedFormat(language, "desktop.runConfig.unavailablePlatform", map[string]string{"type": kind}) + return i18n.SharedFormat(language, "desktop.runConfig.unavailablePlatform", map[string]string{"type": title}) } return i18n.SharedFormat(language, "desktop.runConfig.unavailableOther", map[string]string{"reason": availability.Message}) } diff --git a/desktop/internal/workbench/runconfig_dialog_test.go b/desktop/internal/workbench/runconfig_dialog_test.go index aa74ccf7b6..b66a4e7d8d 100644 --- a/desktop/internal/workbench/runconfig_dialog_test.go +++ b/desktop/internal/workbench/runconfig_dialog_test.go @@ -81,7 +81,7 @@ func TestRunConfigDialogSavesWhatItHoldsTogether(t *testing.T) { fillScriptText(t, h, p, one, "One", "echo one\n") var two *runConfigForm h.app.post(func(a *App) { - a.addRunConfigDraft(p, runProviderShell, nil) + a.addRunConfigDraft(p, builtInKind(runProviderShell), nil) two = d.drafts[d.selected].form }) awaitStateWithin(t, h, 10*time.Second, "the second form", func() bool { return two != nil && two.ready() }) @@ -117,7 +117,7 @@ func TestRunConfigDialogSavesWhatItHoldsTogether(t *testing.T) { h.app.post(func(a *App) { a.selectRunConfigDraft(p, oneID) a.removeRunConfigDraft(p) - a.addRunConfigDraft(p, runProviderExecutable, nil) + a.addRunConfigDraft(p, builtInKind(runProviderExecutable), nil) a.closeRunConfigDialog(p) }) h.settle() @@ -218,7 +218,7 @@ func savedShellRuns(t *testing.T, h *harness, p *project, names ...string) map[s f = newRunConfigDraft(t, h, p, runProviderShell) } else { h.app.post(func(a *App) { - a.addRunConfigDraft(p, runProviderShell, nil) + a.addRunConfigDraft(p, builtInKind(runProviderShell), nil) f = d.drafts[d.selected].form }) awaitStateWithin(t, h, 10*time.Second, "the form of "+name, func() bool { return f != nil && f.ready() }) @@ -301,7 +301,7 @@ func TestRunConfigDialogEmptyStateOffersToAdd(t *testing.T) { h.click(center(h.hitLabeled(i18n.Shared(language, "desktop.runConfig.addNew")))) h.popupClick(shell) - if draft := d.drafts[d.selected]; draft == nil || draft.form == nil || draft.form.provider != runProviderShell || d.newMenu != runConfigNewMenuClosed { + if draft := d.drafts[d.selected]; draft == nil || draft.form == nil || draft.form.kind != builtInKind(runProviderShell) || d.newMenu != runConfigNewMenuClosed { t.Fatalf("selected %q, menu %v after choosing a kind", d.selected, d.newMenu) } } @@ -432,7 +432,7 @@ func TestRunConfigDialogOrdersTheListWhenNotSorted(t *testing.T) { // A configuration added while the list is ordered goes after the others and keeps its place. var added *runConfigForm h.app.post(func(a *App) { - a.addRunConfigDraft(p, runProviderShell, nil) + a.addRunConfigDraft(p, builtInKind(runProviderShell), nil) added = d.drafts[d.selected].form }) awaitStateWithin(t, h, 10*time.Second, "the new form", func() bool { return added != nil && added.ready() }) diff --git a/desktop/internal/workbench/runconfig_dialog_view.go b/desktop/internal/workbench/runconfig_dialog_view.go index 80b295d12e..6cb6aeb0d3 100644 --- a/desktop/internal/workbench/runconfig_dialog_view.go +++ b/desktop/internal/workbench/runconfig_dialog_view.go @@ -153,24 +153,26 @@ func (a *App) drawRunConfigNewMenu(c ui.C, p *project, anchor ui.Box, at runConf } } -// runConfigDialogTypeItems adds an item per built-in kind to the menu of kinds, each creating a -// new configuration of that kind. A kind this platform cannot run is still offered, saying so. +// runConfigDialogTypeItems adds an item per kind to the menu of kinds, each creating a new +// configuration of that kind: the built-in kinds, then the ones enabled plugins declare, each +// with the description its plugin gives. A kind this platform cannot run is still offered, +// saying so. func (a *App) runConfigDialogTypeItems(c ui.C, menu *ui.MenuItems, p *project) { language := a.language() - for _, kind := range p.runConfigs.types { - label, ok := runConfigTypeLabel(language, kind.Provider) - if !ok { - continue - } - provider := kind.Provider - item := menu.Item(label).Icon(runConfigTypeIcon(provider, a.colors.Dark)) - if kind.Unavailable() { - item = item.Description(runConfigTypeNote(language, kind)) + s := &p.runConfigs + for _, listed := range s.types { + kind := runConfigKindOfType(listed) + item := menu.Item(s.kindTitle(language, kind)).Icon(s.kindIcon(kind, a.colors.Dark)) + switch { + case listed.Unavailable(): + item = item.Description(runConfigTypeNote(language, listed)) + case listed.Description != "": + item = item.Description(listed.Description) } if item.Clicked() { c.After(func() { a.performed("run.configuration.new", surfaceButton) - a.addRunConfigDraft(p, provider, nil) + a.addRunConfigDraft(p, kind, nil) }) } } @@ -481,18 +483,18 @@ func (a *App) drawRunConfigNameRow(c ui.C, field func(k ui.C, label string)) { } // runConfigDraftIcon is the icon of configuration key in the tree: its kind's for a built-in -// run, its execution's for a build provider run, its original's for a copy not saved yet. +// run or a kind a plugin declares, its execution's for a build provider run, its original's for a copy not saved yet. func (a *App) runConfigDraftIcon(p *project, key string) gfx.Icon { if configuration := p.runConfigs.configuration(key); configuration != nil { - if configuration.IsProcess() { - return runConfigTypeIcon(configuration.Provider, a.colors.Dark) + if kind, ok := runConfigKindOf(*configuration); ok { + return p.runConfigs.kindIcon(kind, a.colors.Dark) } return runExecutionIcon(configuration.Execution) } if draft := p.runConfigs.dialog.drafts[key]; draft != nil { switch { case draft.form != nil: - return runConfigTypeIcon(draft.form.provider, a.colors.Dark) + return p.runConfigs.kindIcon(draft.form.kind, a.colors.Dark) case draft.copyOf != "" && draft.icon.ViewBox > 0: return draft.icon } diff --git a/desktop/internal/workbench/runconfig_form.go b/desktop/internal/workbench/runconfig_form.go index 5660864099..974aa76e68 100644 --- a/desktop/internal/workbench/runconfig_form.go +++ b/desktop/internal/workbench/runconfig_form.go @@ -14,24 +14,82 @@ import ( ) // This file holds the editor of built-in process runs, shown in the Run/Debug Configurations -// dialog: shell, PowerShell and batch scripts and programs. Core describes the editor as data (`runConfig.editorForm`): the fields in +// dialog: shell, PowerShell and batch scripts and programs, and of the kinds plugins declare +// for their build systems, such as a Go build. Core describes the editor as data (`runConfig.editorForm`): the fields in // order, their kinds and current values, and the automatic value of each empty field. Core // also checks the values and returns the file changes that save them // (`runConfig.saveConfiguration`); the host draws the fields, applies the changes and // resolves the configurations again. A field this host cannot draw (a kind it does not // know, or an ID it has no label for) is left out and its value goes back as it came, so a // later Core can add fields, options and buttons' inputs without breaking this host. A new -// field shows here once it has a label in runConfigFieldLabel and a widget for its kind. +// field shows here once it has a label in runConfigFieldLabel and a widget for its kind; a +// field a plugin declares brings its own translated label. -// runConfigForm is the editor of one built-in process run in the Run/Debug Configurations -// dialog (runconfig_dialog.go). Each configuration the dialog shows has its own, so edits to +// runConfigKind is a kind of configuration a form edits: a built-in process run by its +// provider, or, with provider `build.run-type`, the kind runType a plugin declares. +type runConfigKind struct { + provider string + runType core.RunTypeKey +} + +// builtInKind is the built-in kind of provider. +func builtInKind(provider string) runConfigKind { return runConfigKind{provider: provider} } + +// declaredKind is the kind a plugin declares, named by key. +func declaredKind(key core.RunTypeKey) runConfigKind { + return runConfigKind{provider: core.RunTypeProvider, runType: key} +} + +// declared says a plugin declares the kind. +func (k runConfigKind) declared() bool { return k.runType != core.RunTypeKey{} } + +// key is the declared kind's key as a request names it, nil for a built-in kind. +func (k runConfigKind) key() *core.RunTypeKey { + if !k.declared() { + return nil + } + key := k.runType + return &key +} + +// runConfigKindOf is the kind a form edits configuration as: a built-in process run, or a +// kind a plugin declares; ok is false for a configuration no form edits. +func runConfigKindOf(configuration core.RunConfiguration) (runConfigKind, bool) { + if configuration.IsProcess() { + return builtInKind(configuration.Provider), true + } + if key, ok := configuration.RunTypeReference(); ok { + return declaredKind(key), true + } + return runConfigKind{}, false +} + +// groupKey is the dialog group of the configurations of kind k: one per built-in kind, and one +// per declared kind, apart from the build system's other runs. +func (k runConfigKind) groupKey() string { + if !k.declared() { + return runProcessKindKey(k.provider) + } + return runProcessKindKey(k.provider) + ":" + k.runType.PluginID + "\x00" + k.runType.BuildSystemID + "\x00" + k.runType.Type +} + +// runConfigKindOfType is the kind of a kind Core lists. +func runConfigKindOfType(kind core.RunConfigurationType) runConfigKind { + if kind.RunType != nil { + return declaredKind(*kind.RunType) + } + return builtInKind(kind.Provider) +} + +// runConfigForm is the editor of one built-in process run, or of a configuration of a kind a +// plugin declares, in the Run/Debug Configurations dialog (runconfig_dialog.go). Each configuration the dialog shows has its own, so edits to // several configurations wait together for Apply or OK. type runConfigForm struct { // open is cleared when the dialog drops the form; answers still out are then ignored. open bool // generation rejects the answer of a form that was dropped or reopened since. generation uint64 - provider string + kind runConfigKind // id is the saved configuration edited; empty for a new one until a save names it. id string // name is the configuration's name as it was saved. @@ -97,45 +155,58 @@ func runFieldTextual(kind string) bool { return false } -// loadRunConfigTypes reads once per project which built-in kinds a user can create. Every -// platform lists every kind; one it cannot run carries the reason. A failure leaves them -// unread, so the next refresh asks again. -func (a *App) loadRunConfigTypes(p *project) { +// loadRunConfigTypes reads which kinds a user can create: the built-in ones, which every +// platform lists, one it cannot run with the reason, and the ones enabled plugins declare. The +// first refresh of the project reads them; reload reads them again, as opening the dialog +// does, so a plugin installed or removed since, or another interface language, shows. The +// kinds in hand stay while a read is out, and a reload asked for meanwhile reads once more +// after it. A failure keeps them, or leaves them unread, so the next refresh asks again. +func (a *App) loadRunConfigTypes(p *project, reload bool) { s := &p.runConfigs - if s.types != nil || s.typesLoading { + if s.typesLoading { + s.typesStale = s.typesStale || reload return } - s.typesLoading = true - kernel := a.kernel + if s.types != nil && !reload { + return + } + s.typesLoading, s.typesStale = true, false + kernel, language := a.kernel, a.language() a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { - types, err := kernel.RunConfigurationTypes(ctx) + kinds, err := a.readRunConfigKinds(ctx, kernel, language.Code()) return func(a *App) { s := &p.runConfigs s.typesLoading = false if err != nil { a.backgroundFailed("run_config_types", err) - return - } - // Only kinds this host can name are offered; the list is never nil once read. - s.types = make([]core.RunConfigurationType, 0, len(types)) - for _, kind := range types { - if _, ok := runConfigTypeLabel(a.language(), kind.Provider); ok { - s.types = append(s.types, kind) + } else { + // Only kinds this host can name are offered: the built-in ones it has a title + // for, and declared ones that bring theirs. The list is never nil once read. + s.types = make([]core.RunConfigurationType, 0, len(kinds.types)) + for _, kind := range kinds.types { + _, named := runConfigTypeLabel(language, kind.Provider) + if named || kind.RunType != nil && kind.DisplayName != "" { + s.types = append(s.types, kind) + } } + s.typePlugins = kinds.plugins + } + if s.typesStale { + a.loadRunConfigTypes(p, true) } } }) } -// openRunConfigForm reads the editor of a new configuration of provider, or of the saved +// openRunConfigForm reads the editor of a new configuration of kind, or of the saved // configuration id when it is set. values seed a new configuration, such as a copy of // another; nil starts from Core's defaults. -func (a *App) openRunConfigForm(p *project, provider, id string, values map[string]json.RawMessage) *runConfigForm { - f := &runConfigForm{open: true, generation: 1, provider: provider, id: id, loading: true} +func (a *App) openRunConfigForm(p *project, kind runConfigKind, id string, values map[string]json.RawMessage) *runConfigForm { + f := &runConfigForm{open: true, generation: 1, kind: kind, id: id, loading: true} if configuration := p.runConfigs.configuration(id); configuration != nil { f.name = configuration.Name } - request := core.RunEditorFormRequest{Root: p.root, Provider: provider, ConfigurationID: id, Values: values} + request := core.RunEditorFormRequest{Root: p.root, Provider: kind.provider, RunType: kind.key(), ConfigurationID: id, Values: values} a.requestRunConfigForm(p, f, f.generation, request, true) return f } @@ -154,9 +225,15 @@ func (f *runConfigForm) ready() bool { // requestRunConfigForm asks Core for the editor. The first answer fills the fields and // values; a later one, for the values being edited, only replaces the field descriptions, // so the automatic values follow the edit and nothing the user typed since is lost. +// A declared kind's request carries the plugins that declare kinds, so its fields read in +// the interface language. func (a *App) requestRunConfigForm(p *project, f *runConfigForm, generation uint64, request core.RunEditorFormRequest, initial bool) { - kernel := a.kernel + kernel, kinds, language := a.kernel, p.runConfigs.kinds(), a.language().Code() + declared := f.kind.declared() a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + if declared { + request.RunTypePlugins = a.runTypePlugins(ctx, kernel, kinds, language) + } form, err := kernel.RunEditorForm(ctx, request) return func(a *App) { if !f.open || f.generation != generation { @@ -178,7 +255,12 @@ func (a *App) requestRunConfigForm(p *project, f *runConfigForm, generation uint f.failure = i18n.Shared(language, "desktop.runConfig.formTooNew") return } - f.provider, f.fields, f.values, f.availability = form.Provider, form.Fields, form.Values, form.Availability + if !f.kind.answeredBy(form) { + a.operationRejected("run_config_form", "form_mismatch") + f.failure = i18n.Shared(language, "desktop.runConfig.formTooNew") + return + } + f.fields, f.values, f.availability = form.Fields, form.Values, form.Availability if f.values == nil { f.values = map[string]json.RawMessage{} } @@ -196,7 +278,7 @@ func (a *App) finishRunConfigFormRefresh(p *project, f *runConfigForm, form core case err != nil: // The descriptions in hand stay; only their automatic values may be out of date. a.backgroundFailed("run_config_form_refresh", err) - case form.FormVersion > core.RunFormVersion || form.Provider != f.provider: + case form.FormVersion > core.RunFormVersion || !f.kind.answeredBy(form): a.operationRejected("run_config_form_refresh", "form_mismatch") default: f.fields, f.availability = form.Fields, form.Availability @@ -293,6 +375,18 @@ func (f *runConfigForm) collect() map[string]json.RawMessage { return values } +// answeredBy says form is the editor of the kind: the provider, and for a declared kind its +// key, are the ones asked for. +func (k runConfigKind) answeredBy(form core.RunEditorForm) bool { + if form.Provider != k.provider { + return false + } + if !k.declared() { + return form.RunType == nil + } + return form.RunType != nil && *form.RunType == k.runType +} + // runConfigFormEdited marks the form changed and asks for the editor of the edited values. func (a *App) runConfigFormEdited(p *project, f *runConfigForm) { if !f.open || f.loading || f.fields == nil { @@ -314,7 +408,7 @@ func (a *App) refreshRunConfigForm(p *project, f *runConfigForm) { return } f.refreshing, f.stale = true, false - request := core.RunEditorFormRequest{Root: p.root, Provider: f.provider, ConfigurationID: f.id, Values: f.collect()} + request := core.RunEditorFormRequest{Root: p.root, Provider: f.kind.provider, RunType: f.kind.key(), ConfigurationID: f.id, Values: f.collect()} a.requestRunConfigForm(p, f, f.generation, request, false) } @@ -329,10 +423,14 @@ func (a *App) saveRunConfigForm(p *project, f *runConfigForm, done func(id strin } f.saving, f.failure = true, "" generation := f.generation - request := core.RunConfigurationSave{Root: p.root, Provider: f.provider, ConfigurationID: f.id, Values: f.collect()} - kernel := a.kernel + request := core.RunConfigurationSave{Root: p.root, Provider: f.kind.provider, RunType: f.kind.key(), ConfigurationID: f.id, Values: f.collect()} + kernel, kinds, language := a.kernel, p.runConfigs.kinds(), a.language().Code() + declared := f.kind.declared() a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { request.Plugins = a.runConfigPlugins(ctx) + if declared { + request.RunTypePlugins = a.runTypePlugins(ctx, kernel, kinds, language) + } saved, err := kernel.SaveRunConfiguration(ctx, request) if err == nil && saved.Status == "saved" { err = applyRunConfigChanges(ctx, request.Root, saved.Changes) diff --git a/desktop/internal/workbench/runconfig_form_view.go b/desktop/internal/workbench/runconfig_form_view.go index 0199f2769d..8864d1b21a 100644 --- a/desktop/internal/workbench/runconfig_form_view.go +++ b/desktop/internal/workbench/runconfig_form_view.go @@ -70,6 +70,8 @@ func runConfigFieldLabel(language i18n.Language, id string) (string, bool) { return i18n.Shared(language, "desktop.runConfig.fieldName"), true case "storeAsProjectFile": return i18n.Shared(language, "desktop.runConfig.fieldStoreAsProjectFile"), true + case "allowMultipleInstances": + return i18n.Shared(language, "desktop.runConfig.fieldAllowMultipleInstances"), true case "source": return i18n.Shared(language, "desktop.runConfig.fieldSource"), true case "script": @@ -98,14 +100,29 @@ func runConfigFieldLabel(language i18n.Language, id string) (string, bool) { return "", false } -// runConfigFieldHelp is the ⓘ tip of a field of a provider's editor: what its note means, or -// what the field does. The script's arguments say how the script of that kind reads them. +// runConfigFieldTitle is the title of field: the host's for a field it knows, else the +// translated label a plugin gives a field of its kind; ok is false for a field with neither, +// which the host then leaves out. +func runConfigFieldTitle(language i18n.Language, field core.RunEditorField) (string, bool) { + if title, ok := runConfigFieldLabel(language, field.ID); ok { + return title, true + } + return field.Label, field.Label != "" +} + +// runConfigFieldHelp is the ⓘ tip of a field of a provider's editor: what its note means, what +// the field does, or the description a plugin gives a field of its kind. The script's +// arguments say how the script of that kind reads them. func runConfigFieldHelp(language i18n.Language, provider string, field core.RunEditorField) string { switch { case field.Note == "windowsOnly": return i18n.Shared(language, "desktop.runConfig.noteWindowsOnly") case field.ID == "storeAsProjectFile": return i18n.Shared(language, "desktop.runConfig.storeAsProjectFileHelp") + case field.ID == "allowMultipleInstances": + return i18n.Shared(language, "desktop.runConfig.allowMultipleInstancesHelp") + case field.Description != "": + return field.Description case field.ID == "interpreter": return i18n.Shared(language, "desktop.runConfig.interpreterHelp") case field.ID == "beforeLaunch": @@ -125,11 +142,15 @@ func runConfigFieldHelp(language i18n.Language, provider string, field core.RunE } // runConfigFieldPlaceholder is what an empty field shows: the automatic value that applies -// while it is empty, or an example of what goes into an argument field. +// while it is empty, the placeholder a plugin gives a field of its kind, or an example of what +// goes into an argument field. func runConfigFieldPlaceholder(language i18n.Language, field core.RunEditorField) string { if field.Automatic != nil && *field.Automatic != "" { return i18n.SharedFormat(language, "desktop.runConfig.automaticValue", map[string]string{"value": *field.Automatic}) } + if field.Placeholder != "" { + return field.Placeholder + } switch field.ID { case "scriptOptions": return i18n.Shared(language, "desktop.runConfig.scriptOptionsPlaceholder") @@ -144,8 +165,19 @@ func runConfigFieldPlaceholder(language i18n.Language, field core.RunEditorField return "" } -// runConfigChoiceLabel names an option of a choice field; ok is false for one this host has -// no name for, and the field is then left out. +// runConfigOptionTitle names an option of a choice field: the host's name for an option it +// knows, else the translated label a plugin gives it; ok is false for one with neither, and +// the field is then left out. +func runConfigOptionTitle(language i18n.Language, field core.RunEditorField, option string) (string, bool) { + if title, ok := runConfigChoiceLabel(language, field.ID, option); ok { + return title, true + } + title := field.OptionLabels[option] + return title, title != "" +} + +// runConfigChoiceLabel names an option of a built-in choice field; ok is false for one this +// host has no name for. func runConfigChoiceLabel(language i18n.Language, field, option string) (string, bool) { switch field + "/" + option { case "source/file": @@ -188,7 +220,7 @@ func runConfigFieldError(language i18n.Language, code string) string { // drawable reports whether this host draws field: a kind it knows, a title it has, and for a // choice a name for every option. func (f *runConfigForm) drawable(language i18n.Language, field core.RunEditorField) bool { - if _, ok := runConfigFieldLabel(language, field.ID); !ok { + if _, ok := runConfigFieldTitle(language, field); !ok { return false } switch field.Kind { @@ -200,7 +232,7 @@ func (f *runConfigForm) drawable(language i18n.Language, field core.RunEditorFie return f.beforeLaunch != nil case runFieldChoice: for _, option := range field.Options { - if _, ok := runConfigChoiceLabel(language, field.ID, option); !ok { + if _, ok := runConfigOptionTitle(language, field, option); !ok { return false } } @@ -269,13 +301,13 @@ func (a *App) drawRunConfigFormFields(c ui.C, p *project, f *runConfigForm, read // keeps its size. func (a *App) drawRunConfigFormHeaderField(c ui.C, p *project, f *runConfigForm, field core.RunEditorField, ready bool) { language := a.language() - label, _ := runConfigFieldLabel(language, field.ID) + label, _ := runConfigFieldTitle(language, field) if field.Kind == runFieldCheckbox { ui.Row(c).Shrink(0).Items(ui.Center).Gap(4).Children(func() { if ui.Checkbox(c, f.flags[field.ID], label).Disabled(!ready).Changed() { c.After(func() { a.runConfigFormEdited(p, f) }) } - a.runConfigFormHelp(c, language, f.provider, field) + a.runConfigFormHelp(c, language, f.kind.provider, field) }) return } @@ -290,7 +322,7 @@ func (a *App) drawRunConfigFormHeaderField(c ui.C, p *project, f *runConfigForm, // carries its own title in the control column. func (a *App) drawRunConfigFormField(c ui.C, p *project, f *runConfigForm, field core.RunEditorField, ready bool) { language := a.language() - label, _ := runConfigFieldLabel(language, field.ID) + label, _ := runConfigFieldTitle(language, field) tall := field.Kind == runFieldMultilineText || field.Kind == runFieldEnvironment || field.Kind == runFieldBeforeLaunch ui.Column(c).FillWidth().Gap(4).Children(func() { row := ui.Row(c).FillWidth().Gap(12) @@ -303,7 +335,7 @@ func (a *App) drawRunConfigFormField(c ui.C, p *project, f *runConfigForm, field ui.Row(c.Part("title")).Width(runConfigFormLabelWidth).MinHeight(28).Shrink(0).Items(ui.Center).Gap(4).Children(func() { if field.Kind != runFieldCheckbox { ui.Text(c, label).Ellipsis().Shrink(1).MinWidth(0) - a.runConfigFormHelp(c, language, f.provider, field) + a.runConfigFormHelp(c, language, f.kind.provider, field) } }) if field.Kind == runFieldCheckbox { @@ -311,7 +343,7 @@ func (a *App) drawRunConfigFormField(c ui.C, p *project, f *runConfigForm, field if ui.Checkbox(c, f.flags[field.ID], label).Disabled(!ready).Changed() { c.After(func() { a.runConfigFormEdited(p, f) }) } - a.runConfigFormHelp(c, language, f.provider, field) + a.runConfigFormHelp(c, language, f.kind.provider, field) }) return } @@ -335,7 +367,7 @@ func (a *App) drawRunConfigFormControl(c ui.C, p *project, f *runConfigForm, fie case runFieldChoice: options := field.Options if ui.Choice(c, f.texts[field.ID], options, func(option string) string { - name, _ := runConfigChoiceLabel(language, field.ID, option) + name, _ := runConfigOptionTitle(language, field, option) return name }).Disabled(!ready).Changed() { edited() diff --git a/desktop/internal/workbench/runconfig_process.go b/desktop/internal/workbench/runconfig_process.go index a19ef954b9..7eefeddbf5 100644 --- a/desktop/internal/workbench/runconfig_process.go +++ b/desktop/internal/workbench/runconfig_process.go @@ -34,9 +34,9 @@ const inlineScriptDirectoryPattern = "lithe-run-script-" // errRunProgramNotFound is a planned command that no PATH directory holds. var errRunProgramNotFound = errors.New("run program not found") -// startProcessRun begins the configuration's run beside the window's other executions and -// starts it once unsaved documents are saved, so the process reads the files on disk. Rerun -// starts it again. +// startProcessRun begins the run of a built-in process configuration, or of one of a kind a +// plugin declares, beside the window's other executions and starts it once unsaved documents +// are saved, so the process reads the files on disk. Rerun starts it again. func (a *App) startProcessRun(p *project, configuration core.RunConfiguration) *buildOperation { id := configuration.ID op := a.beginRunOperation(p, configuration.Name, id, configurationRunKey(id), func(a *App, p *project) { @@ -51,7 +51,13 @@ func (a *App) startProcessRun(p *project, configuration core.RunConfiguration) * a.endBuildOperation(p, op, "failed", nil, "unsaved documents could not be saved", "") return } - a.runBeforeLaunch(p, op, id, func() { a.launchProcessRun(p, op, id) }) + a.runBeforeLaunch(p, op, id, func() { + if key, ok := configuration.RunTypeReference(); ok { + a.launchDeclaredRun(p, op, id, key) + return + } + a.launchProcessRun(p, op, id) + }) }) return op } diff --git a/desktop/internal/workbench/runconfig_process_test.go b/desktop/internal/workbench/runconfig_process_test.go index ce46832772..0b9643c12a 100644 --- a/desktop/internal/workbench/runconfig_process_test.go +++ b/desktop/internal/workbench/runconfig_process_test.go @@ -238,7 +238,7 @@ func newRunConfigDraft(t *testing.T, h *harness, p *project, provider string) *r d := &p.runConfigs.dialog h.app.post(func(a *App) { a.openRunConfigDialog(p, "") - a.addRunConfigDraft(p, provider, nil) + a.addRunConfigDraft(p, builtInKind(provider), nil) }) var f *runConfigForm awaitStateWithin(t, h, 10*time.Second, "the new configuration's form", func() bool { diff --git a/desktop/internal/workbench/runconfig_process_visual_test.go b/desktop/internal/workbench/runconfig_process_visual_test.go index e936fa47a3..cc87ef295d 100644 --- a/desktop/internal/workbench/runconfig_process_visual_test.go +++ b/desktop/internal/workbench/runconfig_process_visual_test.go @@ -95,7 +95,7 @@ func TestVisualBuiltInProcessRuns(t *testing.T) { t.Helper() var f *runConfigForm h.app.post(func(a *App) { - a.addRunConfigDraft(p, provider, nil) + a.addRunConfigDraft(p, builtInKind(provider), nil) f = d.drafts[d.selected].form }) awaitStateWithin(t, h, 10*time.Second, "the editor of "+provider, func() bool { diff --git a/desktop/internal/workbench/runconfig_types.go b/desktop/internal/workbench/runconfig_types.go new file mode 100644 index 0000000000..3153bf58c7 --- /dev/null +++ b/desktop/internal/workbench/runconfig_types.go @@ -0,0 +1,292 @@ +package workbench + +import ( + "context" + "errors" + "fmt" + "os" + "slices" + + "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" + "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/pluginservice" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings" + "github.com/1lck/Lithe-IDEA/desktop/internal/processledger" + "github.com/vivaui/viva/gfx" +) + +// This file reads the run configuration kinds a user can create: the built-in ones, and the +// ones enabled plugins declare for their build systems (buildSystems[].runConfigurationTypes). +// Core reads every manifest, lists the kinds they declare and says which translation files of +// each declaring package to read for the interface language; the host only reads those files +// from the installed package, which stays read-only, and asks again with them. The plugins that +// declare a kind, with the files read, are kept as the `runTypePlugins` the editor, the save +// and the run of those kinds send, so they show the same translated text. + +// runConfigKinds is one read of the kinds: the kinds in display order, and the plugins that +// declare one, nil when none does. Once published, neither is changed; a later read replaces +// them. +type runConfigKinds struct { + types []core.RunConfigurationType + plugins *core.RunTypePlugins +} + +// readRunConfigKinds asks Core for the kinds off the window thread, in language. A plugin +// whose manifest cannot be read adds no kind and is logged; a translation that cannot be read +// or that Core refuses falls back to the next candidate or the manifest's text, so the kinds +// still list. +func (a *App) readRunConfigKinds(ctx context.Context, kernel Kernel, language string) (runConfigKinds, error) { + enabled := a.runTypeCandidates(ctx) + if len(enabled) == 0 { + types, _, err := kernel.RunConfigurationTypes(ctx, nil) + return runConfigKinds{types: types}, err + } + request := &core.RunTypePlugins{Language: language, Plugins: make([]core.RunTypePlugin, 0, len(enabled))} + for _, plugin := range enabled { + request.Plugins = append(request.Plugins, core.RunTypePlugin{Manifest: plugin.Manifest}) + } + types, reports, err := kernel.RunConfigurationTypes(ctx, request) + if err != nil { + return runConfigKinds{}, err + } + // Only the plugins that declare a kind go on; Core lists each declared kind under its + // plugin, so the host never interprets a manifest itself. + declaring := []pluginservice.ToolchainPlugin{} + for _, plugin := range enabled { + if slices.ContainsFunc(types, func(kind core.RunConfigurationType) bool { + return kind.RunType != nil && kind.RunType.PluginID == plugin.PluginID + }) { + declaring = append(declaring, plugin) + } + } + if len(declaring) == 0 { + return runConfigKinds{types: types}, nil + } + plugins := &core.RunTypePlugins{Language: language, Plugins: make([]core.RunTypePlugin, len(declaring))} + read := false + for index, plugin := range declaring { + plugins.Plugins[index].Manifest = plugin.Manifest + report := slices.IndexFunc(reports, func(report core.RunTypeLocalization) bool { return report.PluginID == plugin.PluginID }) + if report < 0 || !reports[report].ReadRequired { + continue + } + files, unreadable, err := pluginsettings.ReadTranslations(ctx, plugin.Directory, reports[report].PluginSettingsLocalization) + if err != nil { + return runConfigKinds{}, err + } + if len(unreadable) > 0 { + a.operationRejectedIn(ctx, "run_config_types", "localization_unreadable") + } + // A read that found no file is an empty map, so Core does not ask for it again. + plugins.Plugins[index].Localizations = files + read = true + } + if read { + types, reports, err = kernel.RunConfigurationTypes(ctx, plugins) + if err != nil { + return runConfigKinds{}, err + } + if slices.ContainsFunc(reports, func(report core.RunTypeLocalization) bool { return len(report.Rejected) > 0 }) { + a.operationRejectedIn(ctx, "run_config_types", "invalid_localization") + } + } + return runConfigKinds{types: types, plugins: plugins}, nil +} + +// runTypeCandidates is every enabled plugin with its manifest and package directory, nil while +// the plugin host is not assembled. A manifest that cannot be read leaves that plugin out. +func (a *App) runTypeCandidates(ctx context.Context) []pluginservice.ToolchainPlugin { + if a.plugins == nil { + return nil + } + entries, err := a.plugins.Manager.Installed() + if err != nil { + a.backgroundFailedIn(ctx, "run_config_types", err) + return nil + } + plugins, err := a.plugins.ToolchainPlugins(ctx, entries) + if err != nil { + a.backgroundFailedIn(ctx, "run_config_types", err) + } + return plugins +} + +// runTypePlugins is the `runTypePlugins` a request about a declared kind sends: the plugins +// the last read of the kinds kept, else, before any read answered, a read of its own. It runs +// off the window thread; kinds is what the window held when the request was made. +func (a *App) runTypePlugins(ctx context.Context, kernel Kernel, kinds runConfigKinds, language string) *core.RunTypePlugins { + if kinds.plugins != nil { + return kinds.plugins + } + read, err := a.readRunConfigKinds(ctx, kernel, language) + if err != nil { + a.backgroundFailedIn(ctx, "run_config_types", err) + return nil + } + return read.plugins +} + +// runTypeKind is the declared kind key names among the kinds read, or nil. +func (s *runConfigState) runTypeKind(key core.RunTypeKey) *core.RunConfigurationType { + index := slices.IndexFunc(s.types, func(kind core.RunConfigurationType) bool { + return kind.RunType != nil && *kind.RunType == key + }) + if index < 0 { + return nil + } + return &s.types[index] +} + +// kinds is the kinds read last, for a request made off the window thread. +func (s *runConfigState) kinds() runConfigKinds { + return runConfigKinds{types: s.types, plugins: s.typePlugins} +} + +// runTypeInstances are the detected instances of the build system that declares kind key, in +// detection order, copied for a request off the window thread. +func (p *project) runTypeInstances(key core.RunTypeKey) []buildInstance { + var instances []buildInstance + for _, instance := range p.build.instances { + if instance.PluginID == key.PluginID && instance.BuildSystemID == key.BuildSystemID { + instances = append(instances, instance) + } + } + return instances +} + +// hasRunTypeInstance says the build system that declares kind key is detected, so its +// configurations can start; they need no loaded model. +func (p *project) hasRunTypeInstance(key core.RunTypeKey) bool { + return slices.ContainsFunc(p.build.instances, func(instance buildInstance) bool { + return instance.PluginID == key.PluginID && instance.BuildSystemID == key.BuildSystemID + }) +} + +// launchDeclaredRun plans the run of configuration id, of the kind key a plugin declares, and +// starts and waits for its process off the window thread, as launchProcessRun does for a +// built-in run. Core picks the instance whose root holds the configuration's working +// directory; the host starts the build tool that instance resolves, as a build task does. +func (a *App) launchDeclaredRun(p *project, op *buildOperation, id string, key core.RunTypeKey) { + instances := p.runTypeInstances(key) + if len(instances) == 0 || a.plugins == nil { + a.notifyError(a.text.Build.TargetMissing) + a.finishBuildError(p, op, errors.New(a.text.Build.TargetMissing)) + return + } + root, kernel, messages, pluginRoot := p.root, a.kernel, a.text.Build, a.plugins.Root + a.background(p, 0, func(ctx context.Context) func(*App) { + bounded, cancel := context.WithTimeout(ctx, runPreparationTimeout) + defer cancel() + prepare, release := op.bind(bounded) + defer release() + spec, err := a.declaredRunSpec(prepare, p, kernel, root, pluginRoot, id, key, instances, messages) + if err == nil { + err = prepare.Err() + } + if err != nil { + return func(a *App) { a.finishBuildError(p, op, err) } + } + process, err := buildprocess.Start(ctx, spec, func(_ buildprocess.Stream, text string) { + a.streamBuildOutput(p, op, text) + }) + if err != nil { + return func(a *App) { a.finishBuildError(p, op, err) } + } + a.post(func(a *App) { a.attachProcess(p, op, process) }) + err = process.Wait() + return func(a *App) { a.finishBuildRun(p, op, err) } + }) +} + +// declaredRunSpec is the process a configuration of a declared kind starts: Core's plan +// (`build.runConfigurationPlan`) of the build system's command, run by the build tool the +// chosen instance resolves, at the configuration's working directory under the project. The +// plugin package is read-only, so the writable state directory the plan may name is the +// plugin's per-workspace state, outside it. +func (a *App) declaredRunSpec(ctx context.Context, p *project, kernel Kernel, root, pluginRoot, id string, key core.RunTypeKey, instances []buildInstance, messages i18n.BuildMessages) (buildprocess.Spec, error) { + first := instances[0] + state := buildStateDirectory(pluginRoot, root, first) + if err := os.MkdirAll(state, 0o700); err != nil { + return buildprocess.Spec{}, err + } + request := core.RunConfigurationPlanRequest{ + ConfigurationID: id, PluginDirectory: first.PackageDirectory, WorkspaceStateDirectory: state, + Instances: make([]core.RunTypeInstance, 0, len(instances)), + } + for _, instance := range instances { + request.Instances = append(request.Instances, core.RunTypeInstance{Root: instance.Root, Options: instance.Options}) + } + plan, err := kernel.PlanRunConfiguration(ctx, first.Manifest, key.BuildSystemID, root, request) + if err != nil { + return buildprocess.Spec{}, err + } + if plan.Provider != nil { + return buildprocess.Spec{}, errors.New("the run configuration plan names a provider request") + } + index := slices.IndexFunc(instances, func(instance buildInstance) bool { return instance.Root == plan.Root }) + if index < 0 { + return buildprocess.Spec{}, fmt.Errorf("the run configuration plan names no detected instance: %s", plan.Root) + } + directory, err := projectRunDirectory(root, plan.WorkingDirectory) + if err != nil { + return buildprocess.Spec{}, err + } + execution, err := a.resolveBuildExecutable(ctx, p, instances[index], messages) + if err != nil { + return buildprocess.Spec{}, err + } + return buildprocess.Spec{ + Kind: processledger.KindRun, + Executable: execution.Executable, + Arguments: plan.Arguments, + WorkingDirectory: directory, + Environment: applyToolchainSelection(plan.Environment, execution.selection()), + }, nil +} + +// kindTitle names kind k: the host's title of a built-in kind, the translated title the plugin +// declares for one of its kinds. A kind no read lists, such as one of a plugin turned off, +// shows its ID; a built-in kind this host has no title for shows as a built-in run. +func (s *runConfigState) kindTitle(language i18n.Language, k runConfigKind) string { + if !k.declared() { + if title, ok := runConfigTypeLabel(language, k.provider); ok { + return title + } + return i18n.Shared(language, "desktop.runConfig.builtInGroup") + } + if kind := s.runTypeKind(k.runType); kind != nil && kind.DisplayName != "" { + return kind.DisplayName + } + return k.runType.Type +} + +// kindIcon is the icon of kind k: a built-in kind's file icon, the host icon a declared kind +// names, else the icon of its execution. A package image a kind names is not drawn yet, so +// such a kind shows its execution's icon too. +func (s *runConfigState) kindIcon(k runConfigKind, dark bool) gfx.Icon { + if !k.declared() { + return runConfigTypeIcon(k.provider, dark) + } + kind := s.runTypeKind(k.runType) + if kind == nil { + return icons.Play + } + if kind.Icon != nil && kind.Icon.Host != "" { + if icon := pluginToolIcon(kind.Icon.Host); icon != nil { + return *icon + } + } + return runExecutionIcon(kind.Execution) +} + +// kindOrder places kind k's group in the dialog: where Core lists the kind, after every listed +// kind when no read lists it. +func (s *runConfigState) kindOrder(k runConfigKind) int { + order := slices.IndexFunc(s.types, func(kind core.RunConfigurationType) bool { return runConfigKindOfType(kind) == k }) + if order < 0 { + return len(s.types) + } + return order +} diff --git a/desktop/internal/workbench/runconfig_types_test.go b/desktop/internal/workbench/runconfig_types_test.go new file mode 100644 index 0000000000..ff9a1be8cc --- /dev/null +++ b/desktop/internal/workbench/runconfig_types_test.go @@ -0,0 +1,417 @@ +package workbench + +import ( + "errors" + "flag" + "fmt" + "os" + "path/filepath" + "runtime" + "slices" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginstate" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" +) + +const runTypesPluginID = "dev.lithe.test.run-types" + +// runTypesManifest declares one build system, detected by build.runtypes, with one run +// configuration kind of its own: a mode choice, a checkbox that adds -v, a required target and +// the user's program arguments, run by the fixture-build tool, which is the copied test binary +// running TestRunTypeRunner. +const runTypesManifest = `{ + "schemaVersion": 0, + "id": "dev.lithe.test.run-types", + "displayName": "Run Types Fixture", + "version": "1.0.0", + "pluginAPIVersion": 0, + "requires": {"buildSystems": 0, "runConfigurationTypes": 0}, + "vendor": {"id": "dev.lithe.test", "displayName": "Test", "signatureRequirement": "publisherPackage"}, + "permissions": ["process.build"], + "activationEvents": ["onBuildSystem:fixture-runs"], + "languages": [], + "buildSystems": [{ + "id": "fixture-runs", + "displayName": "Fixture Runs", + "detection": {"markers": ["build.runtypes"]}, + "invocation": {"executables": [{"kind": "command", "command": "fixture-build"}]}, + "model": { + "source": "command", + "arguments": ["-test.run=^TestRunTypeRunner$", "--", "model"], + "decoder": "litheBuildModel", + "executesProjectCode": false, + "mayUseNetwork": false + }, + "runConfigurationTypes": [{ + "id": "fixture", + "displayName": "Fixture Run", + "description": "Runs the fixture tool.", + "icon": {"host": "run"}, + "fields": [ + {"id": "mode", "title": "Mode", "kind": "choice", "choices": [ + {"value": "slow", "title": "Slow"}, {"value": "fast", "title": "Fast"} + ], "default": "slow"}, + {"id": "verbose", "title": "Verbose", "kind": "checkbox", "arguments": ["-v"]}, + {"id": "target", "title": "Target", "kind": "text", "placeholder": "a name", "required": true} + ], + "arguments": ["-test.run=^TestRunTypeRunner$", "--", "${field:mode}", "${field:verbose}", "${field:target}", "${userArguments}"] + }] + }] +}` + +// runTypesChinese is the package's Chinese translation of the kind and its fields. +const runTypesChinese = `{ + "runConfigurationTypes": { + "fixture-runs": { + "fixture": { + "displayName": "夹具运行", + "description": "运行夹具工具。", + "fields": { + "mode": {"title": "模式", "options": {"slow": "慢速", "fast": "快速"}}, + "verbose": {"title": "详细输出"}, + "target": {"title": "目标"} + } + } + } + } +}` + +// runTypeMarker names the file in the run's working directory that tells TestRunTypeRunner to +// print its arguments ("print") or to keep running until it is stopped ("hang"). +const runTypeMarker = "run-type.marker" + +// TestRunTypeRunner is the fixture build tool a declared run starts: it prints the arguments it +// got after "--", and in the hang mode keeps running until the host stops it. +func TestRunTypeRunner(t *testing.T) { + mode, err := os.ReadFile(runTypeMarker) + if err != nil { + t.Skip("not the run type fixture workspace") + } + if arguments := flag.Args(); len(arguments) > 0 && arguments[0] == "model" { + // The build system's model, which the project's sync reads when it opens. + fmt.Print(`{"format":"litheBuildModel","version":0,"projects":[{"name":"fixture"}]}`) + os.Exit(0) + } + fmt.Println("run-type ran: " + strings.Join(flag.Args(), " ")) + if string(mode) == "hang" { + // Stop ends the process; this only outlives the test's bounded wait for it. + time.Sleep(pluginOperationWait) + } + os.Exit(0) +} + +// runTypesKey is the fixture's declared kind. +var runTypesKey = core.RunTypeKey{PluginID: runTypesPluginID, BuildSystemID: "fixture-runs", Type: "fixture"} + +// runTypesHarness installs and enables the run types fixture with its Chinese translation, +// puts the fixture build tool on PATH and opens a workspace that holds the build system's +// marker, unless detected is false, and the runner's marker in mode. It waits until the kinds +// and the configurations are read. +func runTypesHarness(t *testing.T, mode string, detected bool) (*harness, *project, string) { + t.Helper() + options, root := runTypesOptions(t, "dark", "zh-Hans", mode, detected) + h := newHarnessWithOptions(t, options) + h.open(root) + return h, awaitRunTypes(t, h, detected), root +} + +// runTypesOptions are runTypesHarness's options in theme and language, with the workspace it +// opens. +func runTypesOptions(t *testing.T, theme, language, mode string, detected bool) (Options, string) { + t.Helper() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"`+theme+`"}`), 0o600); err != nil { + t.Fatal(err) + } + preferences := store.At(dir) + pluginRoot := t.TempDir() + installed := filepath.Join(pluginRoot, runTypesPluginID, "1.0.0") + if err := os.MkdirAll(filepath.Join(installed, "l10n"), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(installed, "plugin.json"), []byte(runTypesManifest), 0o600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(installed, "l10n", "zh-Hans.json"), []byte(runTypesChinese), 0o600); err != nil { + t.Fatal(err) + } + if err := pluginstate.New(preferences).SetEnabled(runTypesPluginID, true); err != nil { + t.Fatal(err) + } + installBuildTool(t) + if runtime.GOOS == "windows" { + t.Setenv("PATHEXT", ".EXE") + } + root := filepath.Join(t.TempDir(), "RunTypesDemo") + if err := os.MkdirAll(root, 0o700); err != nil { + t.Fatal(err) + } + markers := map[string]string{runTypeMarker: mode} + if detected { + markers["build.runtypes"] = "fixture\n" + } + for name, text := range markers { + if err := os.WriteFile(filepath.Join(root, name), []byte(text), 0o600); err != nil { + t.Fatal(err) + } + } + return Options{ + Kernel: &testKernel{Client: core.NewClient()}, + PluginKernel: &testKernel{Client: core.NewClient()}, + PluginRoot: pluginRoot, + Store: preferences, + Languages: []string{language}, + }, root +} + +// awaitRunTypes reads the open project's configurations and waits until they, the kinds and +// the build system's detection, as detected says, are in. +func awaitRunTypes(t *testing.T, h *harness, detected bool) *project { + t.Helper() + p := h.app.project + h.app.post(func(a *App) { a.loadTitleRunConfigs(p) }) + awaitStateWithin(t, h, 20*time.Second, "the detected build system and the kinds", func() bool { + s := &p.runConfigs + return p.runConfigsSettled() && !s.typesLoading && s.types != nil && p.hasRunTypeInstance(runTypesKey) == detected + }) + return p +} + +// newDeclaredRunDraft opens the dialog, adds a configuration of the fixture's kind as its + +// menu does and waits for the form, which reads the kind's fields in Chinese. +func newDeclaredRunDraft(t *testing.T, h *harness, p *project) *runConfigForm { + t.Helper() + d := &p.runConfigs.dialog + h.app.post(func(a *App) { + a.openRunConfigDialog(p, "") + a.addRunConfigDraft(p, declaredKind(runTypesKey), nil) + }) + var f *runConfigForm + awaitStateWithin(t, h, 10*time.Second, "the declared kind's form", func() bool { + if draft := d.drafts[d.selected]; d.open && draft != nil && draft.form != nil { + f = draft.form + } + return f != nil && f.ready() && f.fields != nil + }) + if f.failure != "" { + t.Fatalf("form failure %q", f.failure) + } + return f +} + +// fillDeclaredRun names form f, sets the kind's fields and the program arguments and waits for +// the form to follow the edit. +func fillDeclaredRun(t *testing.T, h *harness, p *project, f *runConfigForm, name string, multiple bool) { + t.Helper() + h.app.post(func(a *App) { + *f.texts["name"] = name + *f.texts["field:mode"] = "fast" + *f.flags["field:verbose"] = true + *f.texts["field:target"] = "alpha" + *f.texts["programArguments"] = "one two" + *f.flags["storeAsProjectFile"] = true + *f.flags["allowMultipleInstances"] = multiple + a.runConfigFormEdited(p, f) + }) + awaitStateWithin(t, h, 10*time.Second, "the edited form", func() bool { return !f.refreshing }) +} + +// A plugin's declared kind lists in the plugin's translation; the + menu adds it to a dialog +// group of its own, whose form shows the kind's translated fields beside the host's. The saved +// configuration is a build.run-type entry in the project file, and Run starts the build tool +// with the arguments the kind's template makes of the fields. +func TestPluginDeclaredRunKindIsCreatedSavedAndRun(t *testing.T) { + h, p, root := runTypesHarness(t, "print", true) + s := &p.runConfigs + kind := s.runTypeKind(runTypesKey) + if kind == nil || kind.DisplayName != "夹具运行" || kind.Description != "运行夹具工具。" { + t.Fatalf("declared kind = %+v among %+v", kind, s.types) + } + if s.typePlugins == nil || len(s.typePlugins.Plugins) != 1 || s.typePlugins.Plugins[0].Localizations["l10n/zh-Hans.json"] == "" { + t.Fatalf("declaring plugins = %+v, want the fixture with its translation read", s.typePlugins) + } + if got := s.kindTitle(h.app.language(), declaredKind(runTypesKey)); got != "夹具运行" { + t.Fatalf("kind title = %q", got) + } + + f := newDeclaredRunDraft(t, h, p) + d := &s.dialog + if group := p.runConfigDialogGroupKey(d.selected); group != declaredKind(runTypesKey).groupKey() { + t.Fatalf("draft group = %q, want the declared kind's own", group) + } + labels := map[string]core.RunEditorField{} + var order []string + for _, field := range f.fields { + labels[field.ID] = field + order = append(order, field.ID) + } + if mode := labels["field:mode"]; mode.Label != "模式" || mode.OptionLabels["fast"] != "快速" { + t.Fatalf("mode field = %+v", mode) + } + if target := labels["field:target"]; target.Label != "目标" || target.Placeholder != "a name" || !target.Required { + t.Fatalf("target field = %+v", target) + } + for _, id := range []string{"name", "allowMultipleInstances", "programArguments", "workingDirectory", "environment"} { + if !slices.Contains(order, id) { + t.Fatalf("fields %v lack the host's %s", order, id) + } + } + h.settle() + for _, text := range []string{"夹具运行", "模式", "详细输出", "目标", "允许多个实例"} { + if !h.shows(text) { + t.Fatalf("the dialog does not show %q", text) + } + } + + fillDeclaredRun(t, h, p, f, "Fixture Alpha", false) + applyDialog(t, h, p, runConfigDialogRun) + if d.open { + t.Fatalf("the dialog stayed open: errors %v failure %q / %q", f.errors, f.failure, d.failure) + } + run := awaitProcessRun(t, h, p, "Fixture Alpha", nil) + if !strings.Contains(run.output.all(), "run-type ran: fast -v alpha one two") { + t.Fatalf("console:\n%s", run.output.all()) + } + if len(s.list) != 1 { + t.Fatalf("configurations = %+v", s.list) + } + if key, ok := s.list[0].RunTypeReference(); !ok || key != runTypesKey || s.list[0].AllowMultipleInstances { + t.Fatalf("saved configuration = %+v", s.list[0]) + } + // A project configuration of a declared kind is kept in its plugin's run document. + data, err := os.ReadFile(filepath.Join(root, ".lithe", "run", "plugin", runTypesPluginID+".toml")) + if err != nil || !strings.Contains(string(data), "Fixture Alpha") || !strings.Contains(string(data), "fixture-runs") { + t.Fatalf("plugin run document = %s, %v", data, err) + } + + // No declared kind has a debugger. + var refused error + id := s.list[0].ID + h.app.post(func(a *App) { _, refused = a.startRunConfigurationWith(p, id, &connectionDebug{}) }) + h.settle() + var refusal *buildRefusal + if !errors.As(refused, &refusal) || refusal.code != refusalNotSupported { + t.Fatalf("debug start = %v, want not supported", refused) + } +} + +// A declared configuration that allows several instances starts a second one beside the one +// that runs, in a tab of its own; a debug start beside them is still refused, since only a run +// starts beside one of the same configuration. Stop ends both. +func TestPluginDeclaredRunStartsSeveralInstances(t *testing.T) { + h, p, _ := runTypesHarness(t, "hang", true) + f := newDeclaredRunDraft(t, h, p) + fillDeclaredRun(t, h, p, f, "Fixture Hang", true) + applyDialog(t, h, p, runConfigDialogOK) + s := &p.runConfigs + if len(s.list) != 1 || !s.list[0].AllowMultipleInstances { + t.Fatalf("configurations = %+v failure %q", s.list, f.failure) + } + id := s.list[0].ID + running := func() []*runEntry { + var entries []*runEntry + for _, entry := range p.build.runs { + if entry.label == "Fixture Hang" && entry.running && strings.Contains(entry.output.all(), "run-type ran:") { + entries = append(entries, entry) + } + } + return entries + } + defer func() { + h.app.post(func(a *App) { + for _, op := range slices.Clone(p.build.running) { + a.stopOperation(p, op) + } + }) + awaitStateWithin(t, h, 20*time.Second, "every instance to end", func() bool { return len(p.build.running) == 0 }) + }() + h.app.post(func(a *App) { a.runConfiguration(p, id) }) + awaitStateWithin(t, h, 20*time.Second, "the first instance", func() bool { return len(running()) == 1 }) + h.app.post(func(a *App) { a.runConfiguration(p, id) }) + awaitStateWithin(t, h, 20*time.Second, "the second instance beside the first", func() bool { return len(running()) == 2 }) + if entries := running(); entries[0].id == entries[1].id { + t.Fatalf("both instances share tab %q", entries[0].id) + } + + // The hanging instances keep background work going, so the wait is for the answer alone. + var refused error + answered := false + h.app.post(func(a *App) { + _, refused = a.startRunConfigurationWith(p, id, &connectionDebug{}) + answered = true + }) + awaitStateWithin(t, h, 10*time.Second, "the debug start's answer", func() bool { return answered }) + var refusal *buildRefusal + if !errors.As(refused, &refusal) || refusal.code != refusalBusy { + t.Fatalf("debug start = %v, want busy", refused) + } + if len(running()) != 2 { + t.Fatalf("running instances = %d after the debug start, want 2", len(running())) + } +} + +// A declared configuration whose build system is not detected in the project lists, but the +// title bar says its instance is missing and a start is refused without running anything. +func TestPluginDeclaredRunWithoutItsBuildSystemDoesNotStart(t *testing.T) { + h, p, root := runTypesHarness(t, "print", false) + // The plugin's run document as the dialog saves it (TestPluginDeclaredRunKindIsCreatedSavedAndRun). + saved := `schemaVersion = 1 + +[plugin] +id = "dev.lithe.test.run-types" +name = "Run Types Fixture" +version = "1.0.0" +versionRequirement = ">=1.0.0" +pluginAPIVersion = 0 + +[plugin.capabilities] +buildSystems = 0 +runConfigurationTypes = 0 + +[[configurations]] +id = "user:fixture" +name = "Fixture" +provider = "build.run-type" +confidence = "declared" + +[configurations.extensions.build] +pluginID = "dev.lithe.test.run-types" +buildSystemID = "fixture-runs" +type = "fixture" + +[configurations.extensions.build.values] +target = "alpha" +` + documents := filepath.Join(root, ".lithe", "run", "plugin") + if err := os.MkdirAll(documents, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(documents, runTypesPluginID+".toml"), []byte(saved), 0o600); err != nil { + t.Fatal(err) + } + h.app.post(func(a *App) { a.refreshRunConfigurations(p) }) + awaitStateWithin(t, h, 10*time.Second, "the saved declared configuration", func() bool { + return p.runConfigsSettled() && len(p.runConfigs.list) == 1 + }) + configuration := p.runConfigs.list[0] + if key, ok := configuration.RunTypeReference(); !ok || key != runTypesKey { + t.Fatalf("configuration = %+v", configuration) + } + if p.runConfigurationReady(configuration) { + t.Fatal("a declared configuration without its build system reads as ready") + } + var refused error + h.app.post(func(a *App) { _, refused = a.startRunConfiguration(p, configuration.ID) }) + h.settle() + var refusal *buildRefusal + if !errors.As(refused, &refusal) || refusal.code != refusalNotReady { + t.Fatalf("start = %v, want not ready", refused) + } + if len(p.build.runs) != 0 || p.build.active() { + t.Fatalf("a run started: %d sessions", len(p.build.runs)) + } +} diff --git a/desktop/internal/workbench/runconfig_types_visual_test.go b/desktop/internal/workbench/runconfig_types_visual_test.go new file mode 100644 index 0000000000..70723c5548 --- /dev/null +++ b/desktop/internal/workbench/runconfig_types_visual_test.go @@ -0,0 +1,98 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// TestVisualPluginDeclaredRuns captures a kind a plugin declares in the Run/Debug +// Configurations dialog: the + menu that lists it after the built-in kinds, its editor with +// the plugin's fields and the multiple-instances switch, and the Run window with two +// instances of it running side by side. It needs only LITHE_VISUAL_OUTPUT_DIR; the dark +// captures read the plugin's Chinese translation and the light ones its English manifest. +func TestVisualPluginDeclaredRuns(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0o755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language string }{{"dark", "zh-Hans"}, {"light", "en-US"}} { + t.Run(look.theme, func(t *testing.T) { + options, root := runTypesOptions(t, look.theme, look.language, "hang", true) + var session *headless.Session + h := newHarnessWithDriver(t, options, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1200, 760 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + // shot draws the window as it is; the hanging instances keep background work going, + // so it pumps a few frames instead of waiting for every task. + shot := func(scene string) { + t.Helper() + for range 4 { + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + } + if err := session.Screenshot(filepath.Join(out, "declared-run-"+scene+"-"+look.theme+".png")); err != nil { + t.Fatal(err) + } + } + h.openTree(t, root) + p := awaitRunTypes(t, h, true) + d := &p.runConfigs.dialog + + h.app.post(func(a *App) { + a.openRunConfigDialog(p, "") + d.newMenu = runConfigNewMenuToolbar + }) + awaitStateWithin(t, h, 10*time.Second, "the kinds the dialog reads", func() bool { return !p.runConfigs.typesLoading }) + h.settleChain() + shot("new-menu") + h.app.post(func(*App) { d.newMenu = runConfigNewMenuClosed }) + + f := newDeclaredRunDraft(t, h, p) + fillDeclaredRun(t, h, p, f, "Fixture Alpha", true) + h.settleChain() + shot("form") + + applyDialog(t, h, p, runConfigDialogOK) + id := p.runConfigs.list[0].ID + running := func() int { + count := 0 + for _, entry := range p.build.runs { + if entry.running && entry.output.all() != "" { + count++ + } + } + return count + } + defer func() { + h.app.post(func(a *App) { + for _, op := range append([]*buildOperation(nil), p.build.running...) { + a.stopOperation(p, op) + } + }) + awaitStateWithin(t, h, 20*time.Second, "every instance to end", func() bool { return len(p.build.running) == 0 }) + }() + h.app.post(func(a *App) { a.runConfiguration(p, id) }) + awaitStateWithin(t, h, 20*time.Second, "the first instance", func() bool { return running() == 1 }) + h.app.post(func(a *App) { a.runConfiguration(p, id) }) + awaitStateWithin(t, h, 20*time.Second, "the second instance", func() bool { return running() == 2 }) + shot("two-instances") + }) + } +} diff --git a/desktop/internal/workbench/runconfig_view.go b/desktop/internal/workbench/runconfig_view.go index 8d897a6a9e..44a24e4603 100644 --- a/desktop/internal/workbench/runconfig_view.go +++ b/desktop/internal/workbench/runconfig_view.go @@ -86,9 +86,22 @@ func (a *App) editRunConfiguration(p *project, id string) { } // runConfigEditable says whether the list offers an editor for configuration: every built-in -// run, and a build provider run its plugin can still resolve. +// run, a run of a kind a plugin declares while that plugin is installed, as it needs, since +// the plugin declares the editor, and a build provider run its plugin can still resolve. func runConfigEditable(configuration core.RunConfiguration) bool { - return configuration.IsProcess() || !configuration.Unavailable() + if configuration.IsProcess() { + return true + } + if _, declared := configuration.RunTypeReference(); declared { + return configuration.Availability == nil || !runConfigPluginUnavailable(configuration.Availability.Code) + } + return !configuration.Unavailable() +} + +// runConfigPluginUnavailable says availability code is about the plugin a configuration +// needs: missing, from another repository, or of a version it does not accept. +func runConfigPluginUnavailable(code string) bool { + return code == "pluginMissing" || code == "pluginRepositoryMismatch" || code == "pluginVersionUnsupported" } // drawRunConfigRows declares the rows of the scope. Selecting a row keeps it selected; Enter @@ -178,8 +191,8 @@ func (a *App) drawRunConfigRow(p *project, row ui.ListRow, selected bool) { box.Children(func() { ui.Row(c.Part("arrow")).Size(treelist.Disclosure, treelist.Icon).Shrink(0) icon, name := runExecutionIcon(configuration.Execution), a.colors.Text - if configuration.IsProcess() { - icon = runConfigTypeIcon(configuration.Provider, a.colors.Dark) + if kind, ok := runConfigKindOf(configuration); ok { + icon = s.kindIcon(kind, a.colors.Dark) } if unavailable { icon, name = icons.CircleAlert, a.colors.Subtle diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go index 363952e6a1..ecf91fbfa8 100644 --- a/desktop/internal/workbench/title_run.go +++ b/desktop/internal/workbench/title_run.go @@ -194,6 +194,15 @@ func (a *App) decideTitleAction(p *project, action titleAction, trigger string) case configuration.IsProcess(): facts.Configuration = &core.TitleConfiguration{Kind: "process"} default: + // A kind a plugin declares starts like a built-in run once its build system is + // detected, without a model. + if key, declared := configuration.RunTypeReference(); declared { + facts.Configuration = &core.TitleConfiguration{Kind: "process"} + if !p.hasRunTypeInstance(key) { + facts.Configuration = &core.TitleConfiguration{Kind: "instanceMissing"} + } + break + } if reference, ok = configuration.BuildReference(); ok { index = p.buildInstanceIndex(reference) facts.Configuration = p.titleConfigurationFacts(index, reference) diff --git a/docs/assets/builtin-process-runs/README.md b/docs/assets/builtin-process-runs/README.md index 6f787e59b3..8a4408c7b6 100644 --- a/docs/assets/builtin-process-runs/README.md +++ b/docs/assets/builtin-process-runs/README.md @@ -11,6 +11,7 @@ Shell 脚本在系统 shell 里真实运行,控制台内容是真实输出, 对话框左侧是工具栏(+ 新建、− 删除、复制、新建文件夹、按字母顺序排序)和按类型分组的配置树,右侧是选中配置的编辑器。 配置树的图标是各类型的彩色文件图标:Shell 脚本、PowerShell 脚本、批处理脚本和程序各不相同。 底部左边是“运行”,右边是“取消 / 应用 / 确定”。 +编辑器的名称行右侧是“存为项目文件”和“允许多个实例”;勾选后者的配置再次运行时,在旁边另开一个实例,不先停掉正在运行的那个(两个实例同时运行的截图在 `docs/assets/plugin-declared-runs/`)。 | 场景 | 深色中文 | 浅色英文 | | --- | --- | --- | 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 d75b6417b8..4de4f8eaf1 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 bc4dbcfaf2..4a0c3251d1 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 2a78db686f..9cf6ea1bf9 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-copy-light.png b/docs/assets/builtin-process-runs/builtin-run-copy-light.png index 22d020296e..970317601f 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-copy-light.png and b/docs/assets/builtin-process-runs/builtin-run-copy-light.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 df384435c4..7d7327926a 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-dialog-empty-light.png b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png index bb6f4e04fd..ef2a6243d7 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png and b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.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 a35f0a3810..a70009daa3 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-executable-light.png b/docs/assets/builtin-process-runs/builtin-run-executable-light.png index 74faf32f88..b2ee6f66eb 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-executable-light.png and b/docs/assets/builtin-process-runs/builtin-run-executable-light.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 90124e46e8..0a4b289cb5 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-folder-pane-light.png b/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.png index 4252b0c0a4..50d02a711b 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.png and b/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.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 dcc81de5f0..302bc91938 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 5d7fa94e68..b34743fbf2 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 index 9ff9cd19ff..aeb050a249 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-dark.png 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 index 8315fd2f66..0b10218dad 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-interpreter-custom-light.png 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 index 87e38f1d61..f54939a39a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-interpreter-list-dark.png 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 index adf8ac2a76..8685cf67da 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-interpreter-list-light.png 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 da3da49feb..25df552cd9 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 56a12b21c6..139aebef83 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 add0958b22..5550b9e832 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 acbf76e04e..6ad86296f8 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 58fdb9f928..a4ea4906f2 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-menu-light.png b/docs/assets/builtin-process-runs/builtin-run-run-menu-light.png index 976f707e68..d4876a4ae4 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-menu-light.png and b/docs/assets/builtin-process-runs/builtin-run-run-menu-light.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 51c8af3754..cf1091248a 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-run-output-light.png b/docs/assets/builtin-process-runs/builtin-run-run-output-light.png index 67d2f983c6..78c554b0ca 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-output-light.png and b/docs/assets/builtin-process-runs/builtin-run-run-output-light.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 175f01ed3a..bee475891f 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 cbb59d31fa..dd282d6108 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 8d4387ea1a..6b3fe7bb05 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 8c02682549..91ce6fd2eb 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 6ba9e0db2d..231615db2f 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/docs/assets/builtin-process-runs/builtin-run-title-unavailable-light.png b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-light.png index cd4b310cdf..91b9ec956a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-title-unavailable-light.png and b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-light.png differ diff --git a/docs/assets/plugin-declared-runs/README.md b/docs/assets/plugin-declared-runs/README.md new file mode 100644 index 0000000000..7f72fe5f81 --- /dev/null +++ b/docs/assets/plugin-declared-runs/README.md @@ -0,0 +1,20 @@ +# 插件声明的运行类型测试截图 + +这些截图是生产 Viva Page 的无头渲染,在 macOS 上生成。项目是隔离的临时项目 RunTypesDemo,装了一个只在测试里存在的合成插件 +`dev.lithe.test.run-types`:它的构建系统 Fixture Runs 声明了运行类型 Fixture Run,字段有“模式”(慢速/快速)、“详细输出”(勾选后加 `-v`)和必填的“目标”。 +插件包里带一份中文翻译。深色界面用中文,读插件的中文翻译;浅色界面用英文,读插件清单的原文。窗口 1200×760。 +运行的是测试二进制本身,控制台内容是它真实打印的参数,日期来自测试的虚拟时钟。 +无头截图不代表 macOS/Windows 原生窗口验收。 + +| 场景 | 深色中文 | 浅色英文 | +| --- | --- | --- | +| 打开“运行/调试配置”并展开“+”菜单:四类内置运行之后列出插件声明的“夹具运行”,下方是插件写的说明“运行夹具工具。” | [截图](declared-run-new-menu-dark.png) | [截图](declared-run-new-menu-light.png) | +| 新建一条夹具运行:配置树里“夹具运行”单独一组;右侧是插件字段(模式、详细输出、目标),标题和选项名都来自插件翻译,下面是宿主统一提供的程序参数、工作目录、环境变量和启动前。名称行勾选了“存为项目文件”和“允许多个实例” | [截图](declared-run-form-dark.png) | [截图](declared-run-form-light.png) | +| 点“确定”保存后连续运行两次:Run 窗口里有两个 Fixture Alpha 标签,两个实例都在运行,控制台打印 `run-type ran: fast -v alpha one two`,即 Core 按字段值拼出的参数。旁边的“同步 Fixture Runs”是打开项目时读取构建模型的会话 | [截图](declared-run-two-instances-dark.png) | [截图](declared-run-two-instances-light.png) | + +复验:设置 `LITHE_VISUAL_OUTPUT_DIR` 后运行: + +```sh +scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench \ + -run '^TestVisualPluginDeclaredRuns$' -count=1 -timeout 300s +``` diff --git a/docs/assets/plugin-declared-runs/declared-run-form-dark.png b/docs/assets/plugin-declared-runs/declared-run-form-dark.png new file mode 100644 index 0000000000..692209a505 Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-form-dark.png differ diff --git a/docs/assets/plugin-declared-runs/declared-run-form-light.png b/docs/assets/plugin-declared-runs/declared-run-form-light.png new file mode 100644 index 0000000000..69557e0f25 Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-form-light.png differ diff --git a/docs/assets/plugin-declared-runs/declared-run-new-menu-dark.png b/docs/assets/plugin-declared-runs/declared-run-new-menu-dark.png new file mode 100644 index 0000000000..c581b53b22 Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-new-menu-dark.png differ diff --git a/docs/assets/plugin-declared-runs/declared-run-new-menu-light.png b/docs/assets/plugin-declared-runs/declared-run-new-menu-light.png new file mode 100644 index 0000000000..9407b9627e Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-new-menu-light.png differ diff --git a/docs/assets/plugin-declared-runs/declared-run-two-instances-dark.png b/docs/assets/plugin-declared-runs/declared-run-two-instances-dark.png new file mode 100644 index 0000000000..f995bef58b Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-two-instances-dark.png differ diff --git a/docs/assets/plugin-declared-runs/declared-run-two-instances-light.png b/docs/assets/plugin-declared-runs/declared-run-two-instances-light.png new file mode 100644 index 0000000000..0c50e338fa Binary files /dev/null and b/docs/assets/plugin-declared-runs/declared-run-two-instances-light.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 1bd6fc6f6e..3f8eea1609 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 661ef0f: #94, squash-merged into main on top of 8b91b32: a plugin's +# buildSystems[].runConfigurationTypes declare run configuration types, which runConfig lists, +# edits and saves (.lithe/run/plugin/.toml) and build.runConfigurationPlan turns into a +# launch plan; every editor form gains the allowMultipleInstances header checkbox (#2100). # 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 @@ -239,7 +243,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="8b91b324f0e8140cb6ca3fed3dc26fa0b59a788c" +PINNED_CORE_REVISION="661ef0fdc3a421259fb2b2fab7f8a0540ac898b7" 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 42d62501d4..ca03e87943 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11474,6 +11474,8 @@ "desktop.runConfig.fieldName": "Name", "desktop.runConfig.fieldStoreAsProjectFile": "Store as project file", "desktop.runConfig.storeAsProjectFileHelp": "Checked, the configuration is saved in .lithe/run/configurations.yaml and can be committed with the project; unchecked, it stays on this machine in .lithe/run/local.yaml.", + "desktop.runConfig.fieldAllowMultipleInstances": "Allow multiple instances", + "desktop.runConfig.allowMultipleInstancesHelp": "Checked, starting the configuration while it runs starts another instance beside the running one; unchecked, the running instance is stopped and started again.", "desktop.runConfig.fieldSource": "Execute", "desktop.runConfig.sourceFile": "Script file", "desktop.runConfig.sourceText": "Script text", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 397aefb67e..7afbd622ae 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11474,6 +11474,8 @@ "desktop.runConfig.fieldName": "名称", "desktop.runConfig.fieldStoreAsProjectFile": "存为项目文件", "desktop.runConfig.storeAsProjectFileHelp": "勾选后保存到 .lithe/run/configurations.yaml,可随项目提交共享;不勾选则只保存在本机的 .lithe/run/local.yaml。", + "desktop.runConfig.fieldAllowMultipleInstances": "允许多个实例", + "desktop.runConfig.allowMultipleInstancesHelp": "勾选后,配置运行时再次启动会另开一个实例,与正在运行的并存;不勾选则先停止正在运行的实例,再重新启动。", "desktop.runConfig.fieldSource": "执行", "desktop.runConfig.sourceFile": "脚本文件", "desktop.runConfig.sourceText": "脚本文本", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index b2777a958d..629a4f895c 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -15760,6 +15760,20 @@ "desktop" ] }, + { + "id": "desktop.runConfig.fieldAllowMultipleInstances", + "description": "Checkbox of a run configuration that lets it start again while it runs, beside the running instance.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.allowMultipleInstancesHelp", + "description": "Tooltip of the allow multiple instances checkbox: what starting a running configuration does either way.", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.runConfig.fieldSource", "description": "Label of the choice between running a script file and running script text.", diff --git a/shared/platform-feature-matrix/features/run-concurrent-executions.json b/shared/platform-feature-matrix/features/run-concurrent-executions.json index 17f2db42b7..ed224aa97e 100644 --- a/shared/platform-feature-matrix/features/run-concurrent-executions.json +++ b/shared/platform-feature-matrix/features/run-concurrent-executions.json @@ -2,10 +2,10 @@ "id": "run-concurrent-executions", "area": "运行与调试", "group": "运行输出", - "capability": "像 IntelliJ IDEA 一样同时运行多个服务:不同运行配置、不同构建目标的运行可以并行,每个运行有自己的 Run 标签、状态和停止按钮;再次运行一个正在运行的配置时先停止旧进程,结束后再启动新进程;Run 标签和执行树在准备阶段显示转圈,进程启动后显示静态的绿色运行图标", + "capability": "像 IntelliJ IDEA 一样同时运行多个服务:不同运行配置、不同构建目标的运行可以并行,每个运行有自己的 Run 标签、状态和停止按钮;再次运行一个正在运行的配置时先停止旧进程,结束后再启动新进程,勾选“允许多个实例”的配置则在旁边另开一个实例;Run 标签和执行树在准备阶段显示转圈,进程启动后显示静态的绿色运行图标", "owner": "Run", - "notes": "Viva 共享实现。运行按键区分(运行配置 config:、构建目标 target:<实例>/<目标>/<运行>、命令入口 entry:<实例>/<入口>),存在 buildState.running;构建任务、模型加载和 IDE API 的构建仍然独占 buildState.operation,一次一个。调试仍是每个项目一个会话。IDE API 对正在运行的配置再次 start 返回 BUSY。内置进程运行(Shell、PowerShell、cmd、可执行程序)同样按配置键并行。插件经 lithe/host/run/start 发起的运行一开始就显示运行图标(进程已由插件服务启动)。", - "verification": "打开含两个服务运行配置的项目,先运行 A,再运行 B,确认两个 Run 标签同时为运行状态、两个进程都在;在运行配置列表里分别点停止,只停对应的那个。运行中再次运行 A,确认旧 A 先结束(状态为已停止)再启动新 A,端口不冲突。服务准备期间标签显示转圈,进程启动后变为静态绿色三角。构建任务运行时目标的运行按钮仍可用、任务按钮不可用。自动化:build_concurrent_runs_test.go 的 TestRunsOfDifferentKeysRunTogether、TestStartRunReplacesTheRunOfItsKeyOnceItEnded、TestServiceRunShowsRunningAndRestartsInPlace,build_tree_test.go 的 TestBuildTreeRunMarksRunTheirRowsAtOnce。", + "notes": "Viva 共享实现。运行按键区分(运行配置 config:、构建目标 target:<实例>/<目标>/<运行>、命令入口 entry:<实例>/<入口>),存在 buildState.running;构建任务、模型加载和 IDE API 的构建仍然独占 buildState.operation,一次一个。调试仍是每个项目一个会话。IDE API 对正在运行的配置再次 start 返回 BUSY。内置进程运行(Shell、PowerShell、cmd、可执行程序)同样按配置键并行。插件经 lithe/host/run/start 发起的运行一开始就显示运行图标(进程已由插件服务启动)。运行配置的“允许多个实例”(allowMultipleInstances,内置运行和插件声明的类型都有)勾选后,再次运行不停止正在运行的实例,新实例有自己的 Run 标签;调试不受此开关影响,同一配置正在运行时调试启动仍返回 BUSY。", + "verification": "打开含两个服务运行配置的项目,先运行 A,再运行 B,确认两个 Run 标签同时为运行状态、两个进程都在;在运行配置列表里分别点停止,只停对应的那个。运行中再次运行 A,确认旧 A 先结束(状态为已停止)再启动新 A,端口不冲突。服务准备期间标签显示转圈,进程启动后变为静态绿色三角。构建任务运行时目标的运行按钮仍可用、任务按钮不可用。自动化:build_concurrent_runs_test.go 的 TestRunsOfDifferentKeysRunTogether、TestStartRunReplacesTheRunOfItsKeyOnceItEnded、TestServiceRunShowsRunningAndRestartsInPlace,build_tree_test.go 的 TestBuildTreeRunMarksRunTheirRowsAtOnce。勾选 A 的“允许多个实例”后再运行 A,确认旧 A 不停止、出现第二个 A 的 Run 标签,两个都能单独停止。自动化:runconfig_types_test.go 的 TestPluginDeclaredRunStartsSeveralInstances。", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -17,7 +17,8 @@ "desktop/internal/workbench/run_view.go", "desktop/internal/workbench/runs.go", "desktop/internal/workbench/build_tree_view.go", - "desktop/internal/workbench/build_concurrent_runs_test.go" + "desktop/internal/workbench/build_concurrent_runs_test.go", + "desktop/internal/workbench/runconfig_types_test.go" ] }, "windows": { @@ -31,7 +32,8 @@ "desktop/internal/workbench/run_view.go", "desktop/internal/workbench/runs.go", "desktop/internal/workbench/build_tree_view.go", - "desktop/internal/workbench/build_concurrent_runs_test.go" + "desktop/internal/workbench/build_concurrent_runs_test.go", + "desktop/internal/workbench/runconfig_types_test.go" ] } } diff --git a/shared/platform-feature-matrix/features/run-plugin-declared-types.json b/shared/platform-feature-matrix/features/run-plugin-declared-types.json new file mode 100644 index 0000000000..4aaa6a9196 --- /dev/null +++ b/shared/platform-feature-matrix/features/run-plugin-declared-types.json @@ -0,0 +1,41 @@ +{ + "id": "run-plugin-declared-types", + "area": "运行与调试", + "group": "运行配置", + "capability": "插件为自己的构建系统声明运行配置类型:运行/调试配置对话框的“+”菜单在内置类型之后列出这些类型,编辑器显示插件声明的字段(文本、选择、复选框、文件、目录、实参)和插件翻译的文字;保存后与内置运行一样从标题栏、运行配置列表和对话框启动", + "owner": "Run", + "notes": "Viva 共享实现。类型由插件清单 buildSystems[].runConfigurationTypes 声明(契约 runConfigurationTypes 0,API-29),Core 的 runConfig.configurationTypes、editorForm、saveConfiguration 和 build.runConfigurationPlan 负责列出、表单、校验保存和计划命令,宿主只读取 Core 指定的插件翻译文件(安装包只读)并绘制、启动。配置写在 .lithe/run/plugin/<插件 ID>.toml(存为项目文件时)或本机层,provider 为 build.run-type。检测到该构建系统后才能启动,未检测到时标题栏显示缺少实例、启动被拒绝;插件被停用或卸载时配置仍列出但不可编辑。插件声明的类型没有调试器,调试启动被拒绝。路径图标暂按执行类别显示宿主图标。不提供远程运行类型。", + "verification": "安装一个声明了运行配置类型的插件,打开含该构建系统标记的项目;打开“运行/调试配置”,点“+”,确认插件类型列在内置类型之后,显示插件的名称、说明和图标;新建一个,确认表单显示插件字段,中文界面显示插件的中文翻译,选择字段的选项也被翻译,必填字段留空时保存报错;填写后点“运行”,确认 Run 窗口显示插件工具的输出、参数按插件模板拼出;勾选“存为项目文件”时文件写入 .lithe/run/plugin/。删掉项目里的构建系统标记后重新打开,确认配置仍列出但不能启动。自动化:runconfig_types_test.go 的 TestPluginDeclaredRunKindIsCreatedSavedAndRun、TestPluginDeclaredRunStartsSeveralInstances、TestPluginDeclaredRunWithoutItsBuildSystemDoesNotStart;Viva 无头截图由 runconfig_types_visual_test.go 的 TestVisualPluginDeclaredRuns 生成(深色中文、浅色英文:“+”菜单、表单、两个实例),截图在 docs/assets/plugin-declared-runs/。", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/runconfig_types.go", + "desktop/internal/workbench/runconfig_form.go", + "desktop/internal/workbench/runconfig_form_view.go", + "desktop/internal/workbench/runconfig_dialog.go", + "desktop/internal/workbench/runconfig_dialog_view.go", + "desktop/internal/workbench/runconfig.go", + "desktop/internal/core/run_process.go", + "desktop/internal/core/build.go", + "desktop/internal/workbench/runconfig_types_test.go", + "desktop/internal/workbench/runconfig_types_visual_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/runconfig_types.go", + "desktop/internal/workbench/runconfig_form.go", + "desktop/internal/workbench/runconfig_form_view.go", + "desktop/internal/workbench/runconfig_dialog.go", + "desktop/internal/workbench/runconfig_dialog_view.go", + "desktop/internal/workbench/runconfig.go", + "desktop/internal/core/run_process.go", + "desktop/internal/core/build.go", + "desktop/internal/workbench/runconfig_types_test.go", + "desktop/internal/workbench/runconfig_types_visual_test.go" + ] + } +}