diff --git a/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md b/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md index 988d7a8dc8..91e1a6bef0 100644 --- a/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md +++ b/.agents/notes/implemented/architecture/2026-10-17-build-system-plugin-contract.md @@ -341,3 +341,14 @@ Maven 构建所用 JDK 与后端进程自身的 JDK 是两项独立选择。宿 `build.detect` 同时返回 Core 按作用域和实例根合并的已保存选项与被拒绝的键,平台直接 使用这份选择,不在前端再实现一遍继承链。例如 A 根显式保存空 Profiles,不能在 UI 发现列表为空时自行补回团队默认值。检测只读,不把归一化结果写回共享文档。 + +### 勾选状态来源与覆盖清理 + +工具默认激活的选项与本次模型实际激活的选项需要分别记录。例如一项来自工具设置, +另一项来自 Lithe 已保存的选项,两项都可能在本次调用中生效。插件从工具模型报告实际 +激活集合,Core 用加载模型时的选项指纹确认这份集合仍然适用。桌面将同一份结果交给 +选项编辑器和构建树。选项已变化时,Core 先按新输入计算显示状态,模型重载后再使用工具结果。 + +回到默认勾选时,只有清除覆盖后仍会继承这些选项,并且其他构建根的存储状态可保留, +才自动清除覆盖。构建计划与自动生成的运行条目使用同样的取消前缀解析规则。运行配置的自定义选项由 Core 覆盖实例的同名选项,编辑器和启动规划都按这个顺序处理。 +对应的合成样例在 Core 的 `rust/fixtures/build/option-edit-v1.json`。 diff --git a/desktop/internal/core/build.go b/desktop/internal/core/build.go index bb54adbeb3..1416f1cbc8 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -123,6 +123,8 @@ type BuildPlanRequest struct { Refresh bool `json:"refresh,omitempty"` Tool *BuildTool `json:"tool,omitempty"` WorkspaceRoot string `json:"workspaceRoot,omitempty"` + // OptionOverrides are the saved per-run build options, layered by Core. + OptionOverrides map[string]json.RawMessage `json:"optionOverrides,omitempty"` // LaunchOptions are a run configuration's choices. LaunchOptions *RunLaunchOptions `json:"launchOptions,omitempty"` // File is the workspace-relative source file build.runEntrypointsPlan asks about. @@ -201,12 +203,21 @@ type BuildTask struct { // BuildModel is the normalized model build.decodeModel returns. Run entries // are command entries only; a provider run is prepared on demand. type BuildModel struct { - Projects []BuildProject `json:"projects"` - Targets []BuildTarget `json:"targets"` - Tasks []BuildTask `json:"tasks"` - ContentRoots []json.RawMessage `json:"contentRoots"` - OptionValues map[string][]string `json:"optionValues"` - Run []BuildRunEntry `json:"run"` + Projects []BuildProject `json:"projects"` + Targets []BuildTarget `json:"targets"` + Tasks []BuildTask `json:"tasks"` + ContentRoots []json.RawMessage `json:"contentRoots"` + OptionValues map[string][]string `json:"optionValues"` + OptionDefaults map[string][]string `json:"optionDefaults,omitempty"` + OptionExcludePrefixes map[string]string `json:"optionExcludePrefixes,omitempty"` + OptionSelection *BuildModelOptionSelection `json:"optionSelection,omitempty"` + Run []BuildRunEntry `json:"run"` +} + +// BuildModelOptionSelection contains choices observed by the tool for one build configuration. +type BuildModelOptionSelection struct { + Fingerprint string `json:"fingerprint"` + ActiveChoices map[string][]string `json:"activeChoices"` } // BuildRunEntry is a command Run entry Core derived from a decoded model: one @@ -272,9 +283,10 @@ type buildOutcome struct { // Dependencies is the answer of build.decodeDependencies. Dependencies *BuildDependencyTree `json:"dependencies"` // Storage and Edit answer build.resolveStoredOptions and build.editStoredOption; build.editIgnoredPaths - // decodes its own edit. - Storage *BuildStoredOptions `json:"storage"` - Edit *BuildOptionEdit `json:"edit"` + // decodes its own edit, and Options answers build.resolveOptions. + Storage *BuildStoredOptions `json:"storage"` + Edit *BuildOptionEdit `json:"edit"` + Options *BuildResolvedOptions `json:"options"` // Discovery answers build.decodeTestDiscovery. Discovery *BuildTestDiscovery `json:"discovery"` // Tree answers build.modelTree. @@ -458,16 +470,21 @@ func (c *Client) DecodeBuildModel(ctx context.Context, manifest json.RawMessage, // narrows the tree to the nodes it matches; GroupHeadings labels the folder of each task group // in the user's language, and the query matches those labels too. type BuildModelTreeRequest struct { - Model BuildModelTreeInput `json:"model"` - Query string `json:"query,omitempty"` - GroupHeadings map[string]string `json:"groupHeadings,omitempty"` + Model BuildModelTreeInput `json:"model"` + Options map[string]json.RawMessage `json:"options,omitempty"` + Query string `json:"query,omitempty"` + GroupHeadings map[string]string `json:"groupHeadings,omitempty"` } // BuildModelTreeInput is the part of a decoded model the tree reads. type BuildModelTreeInput struct { - Projects []BuildProject `json:"projects"` - Targets []BuildTarget `json:"targets"` - Tasks []BuildTask `json:"tasks"` + Projects []BuildProject `json:"projects"` + Targets []BuildTarget `json:"targets"` + Tasks []BuildTask `json:"tasks"` + OptionValues map[string][]string `json:"optionValues,omitempty"` + OptionDefaults map[string][]string `json:"optionDefaults,omitempty"` + OptionExcludePrefixes map[string]string `json:"optionExcludePrefixes,omitempty"` + OptionSelection *BuildModelOptionSelection `json:"optionSelection,omitempty"` } // BuildModelTree is the Build tool window's tree of one instance. Project is the instance's @@ -482,6 +499,8 @@ type BuildModelTree struct { // The kinds of a BuildTreeNode. const ( + BuildTreeOption = "option" + BuildTreeOptionChoice = "optionChoice" BuildTreeProject = "project" BuildTreeFolder = "folder" BuildTreeTask = "task" @@ -493,21 +512,27 @@ const ( // BuildTreeNode is one node of a BuildModelTree. Key is unique in the instance and stable // across reloads and filters. ProjectID and TargetID are what a task runs on, empty for the -// whole instance; TaskID is a declared or a model task. Group names the task group a folder -// stands for, empty for a category folder. Matched marks a node the query matches itself. -// Targets, dependencies and tests nodes have no label: the host names them. +// whole instance; TaskID is a declared or a model task. OptionID and OptionValue name the +// option and choice an option or optionChoice node shows, with Checked and DefaultActive on +// each choice. Group names the task group a folder stands for, empty for a category folder. +// Matched marks a node the query matches itself. Targets, dependencies and tests nodes have no +// label: the host names them. type BuildTreeNode struct { - Kind string `json:"kind"` - Key string `json:"key"` - Label string `json:"label"` - Detail string `json:"detail"` - Tooltip string `json:"tooltip"` - Group string `json:"group"` - ProjectID string `json:"projectID"` - TargetID string `json:"targetID"` - TaskID string `json:"taskID"` - Matched bool `json:"matched"` - Children []BuildTreeNode `json:"children"` + Kind string `json:"kind"` + Key string `json:"key"` + Label string `json:"label"` + Detail string `json:"detail"` + Tooltip string `json:"tooltip"` + Group string `json:"group"` + ProjectID string `json:"projectID"` + TargetID string `json:"targetID"` + TaskID string `json:"taskID"` + OptionID string `json:"optionID"` + OptionValue string `json:"optionValue"` + Checked bool `json:"checked"` + DefaultActive bool `json:"defaultActive"` + Matched bool `json:"matched"` + Children []BuildTreeNode `json:"children"` } // BuildModelTree lays out the tree of one loaded model for the Build tool window. diff --git a/desktop/internal/core/build_options.go b/desktop/internal/core/build_options.go index 9d988cff53..6c053f38b0 100644 --- a/desktop/internal/core/build_options.go +++ b/desktop/internal/core/build_options.go @@ -59,15 +59,23 @@ type BuildIgnoredPathsEdit struct { IgnoredPaths BuildIgnoredPaths `json:"ignoredPaths"` } -// BuildOptionEditRequest changes one declared local preference of an instance. A nil Value removes the local -// override, so the team or declaration value applies again. A list is sent as given, an empty list being the -// explicit empty selection. +// BuildOptionEditRequest changes one declared local preference of an instance. A nil Value (when +// HasSelectedChoices is false) removes the local override, so the team or declaration value applies +// again. When HasSelectedChoices is true, Core encodes SelectedChoices against the model's defaults +// and exclusion prefix, clearing the local override when no team override exists and the checked +// choices equal the defaults. type BuildOptionEditRequest struct { - Document json.RawMessage - Local json.RawMessage - Root string - OptionID string - Value any + Document json.RawMessage + Local json.RawMessage + Root string + OptionID string + Value any + SelectedChoices []string + HasSelectedChoices bool + ModelValues map[string][]string + ModelDefaults map[string][]string + ModelExcludePrefixes map[string]string + ModelSelection *BuildModelOptionSelection } // BuildOptionEdit is the local document after an edit and the effective options Core checked against it. @@ -76,6 +84,48 @@ type BuildOptionEdit struct { Options json.RawMessage `json:"options"` } +// BuildResolveOptionsRequest asks Core (build.resolveOptions) for a build system's declared options, +// their effective values, and the choices the UI should offer. SelectedChoices, when given, encodes +// the positive choices checked in an option editor into Options before resolution. +type BuildResolveOptionsRequest struct { + Options map[string]json.RawMessage `json:"options,omitempty"` + InheritedOptions map[string]json.RawMessage `json:"inheritedOptions,omitempty"` + SelectedChoices map[string][]string `json:"selectedChoices,omitempty"` + ModelValues map[string][]string `json:"modelValues,omitempty"` + ModelDefaults map[string][]string `json:"modelDefaults,omitempty"` + ModelExcludePrefixes map[string]string `json:"modelExcludePrefixes,omitempty"` + ModelSelection *BuildModelOptionSelection `json:"modelSelection,omitempty"` +} + +// BuildResolvedOptions is Core's answer to build.resolveOptions. +type BuildResolvedOptions struct { + Options []BuildResolvedOption `json:"options"` + Dropped []string `json:"dropped"` + Fingerprint string `json:"fingerprint"` +} + +// BuildResolvedOption is one declared build option as Core resolved it for display and editing. +type BuildResolvedOption struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + Kind string `json:"kind"` + Scope string `json:"scope,omitempty"` + Value json.RawMessage `json:"value"` + SelectedChoices []string `json:"selectedChoices"` + Source string `json:"source"` + Choices []BuildResolvedChoice `json:"choices"` + AllowCustom bool `json:"allowCustom"` +} + +// BuildResolvedChoice is one choice of a single-select or multi-select build option. +type BuildResolvedChoice struct { + Value string `json:"value"` + Title string `json:"title"` + FromModel bool `json:"fromModel"` + Custom bool `json:"custom"` + DefaultActive bool `json:"defaultActive"` +} + // ResolveStoredBuildOptions checks the team document and the local document against each other. It reads // and writes no file; the host supplies both documents as they are stored. func (c *Client) ResolveStoredBuildOptions(ctx context.Context, document, local json.RawMessage) (BuildStoredOptions, error) { @@ -96,28 +146,64 @@ func (c *Client) ResolveStoredBuildOptions(ctx context.Context, document, local return *result.Storage, nil } +// ResolveBuildOptions resolves the declared options of a build system against stored values and +// optional model facts (build.resolveOptions). +func (c *Client) ResolveBuildOptions(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildResolveOptionsRequest) (BuildResolvedOptions, error) { + const command = "build.resolveOptions" + var result buildOutcome + if err := c.Execute(ctx, command, struct { + Manifest json.RawMessage `json:"manifest"` + BuildSystemID string `json:"buildSystemID"` + Request BuildResolveOptionsRequest `json:"request"` + }{manifest, buildSystemID, request}, &result); err != nil { + return BuildResolvedOptions{}, err + } + if err := result.failure(command); err != nil { + return BuildResolvedOptions{}, err + } + if result.Options == nil { + return BuildResolvedOptions{}, newParseError(command, "build.resolveOptions returned no options", "") + } + return *result.Options, nil +} + // EditStoredBuildOption applies one option edit to the local document of an instance, in the standard // manifest and build-system envelope. The host writes edit.Local itself, atomically, and reads it back. func (c *Client) EditStoredBuildOption(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildOptionEditRequest) (BuildOptionEdit, error) { const command = "build.editStoredOption" + payload := map[string]any{ + "document": request.Document, + "local": request.Local, + "root": request.Root, + "optionID": request.OptionID, + } + if request.HasSelectedChoices { + selected := request.SelectedChoices + if selected == nil { + selected = []string{} + } + payload["selectedChoices"] = selected + } else { + payload["value"] = request.Value + } + if request.ModelValues != nil { + payload["modelValues"] = request.ModelValues + } + if request.ModelDefaults != nil { + payload["modelDefaults"] = request.ModelDefaults + } + if request.ModelExcludePrefixes != nil { + payload["modelExcludePrefixes"] = request.ModelExcludePrefixes + } + if request.ModelSelection != nil { + payload["modelSelection"] = request.ModelSelection + } var result buildOutcome if err := c.Execute(ctx, command, struct { Manifest json.RawMessage `json:"manifest"` BuildSystemID string `json:"buildSystemID"` - Request struct { - Document json.RawMessage `json:"document"` - Local json.RawMessage `json:"local"` - Root string `json:"root"` - OptionID string `json:"optionID"` - Value any `json:"value"` - } `json:"request"` - }{manifest, buildSystemID, struct { - Document json.RawMessage `json:"document"` - Local json.RawMessage `json:"local"` - Root string `json:"root"` - OptionID string `json:"optionID"` - Value any `json:"value"` - }{request.Document, request.Local, request.Root, request.OptionID, request.Value}}, &result); err != nil { + Request map[string]any `json:"request"` + }{manifest, buildSystemID, payload}, &result); err != nil { return BuildOptionEdit{}, err } if err := result.failure(command); err != nil { diff --git a/desktop/internal/core/build_options_test.go b/desktop/internal/core/build_options_test.go index e744c6604d..748b6fabcc 100644 --- a/desktop/internal/core/build_options_test.go +++ b/desktop/internal/core/build_options_test.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "slices" + "strings" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" @@ -111,3 +112,171 @@ func TestBuildDetectSkipsTheIgnoredPaths(t *testing.T) { t.Fatalf("ignoring /tools detection finds %q", got) } } + +// Model-supplied multi-select options carry default-active choices and an exclusion prefix from +// the decoded model through ResolveBuildOptions, EditStoredBuildOption and BuildModelTree. +func TestBuildOptionDefaultsAndExclusionsRoundTripThroughStorageAndTree(t *testing.T) { + client, ctx := NewClient(), testContext(t) + manifest := json.RawMessage(`{ + "schemaVersion": 0, + "id": "dev.lithe.test.profiles", + "displayName": "Profiles Fixture", + "version": "1.0.0", + "pluginAPIVersion": 0, + "requires": {"buildSystems": 0}, + "vendor": {"id": "dev.lithe.test", "displayName": "Test", "signatureRequirement": "publisherPackage"}, + "permissions": ["process.build"], + "activationEvents": ["onBuildSystem:fixture-profiles"], + "languages": [], + "buildSystems": [{ + "id": "fixture-profiles", + "displayName": "Fixture Profiles", + "detection": {"markers": ["fixture.build"]}, + "invocation": { + "executables": [{"kind": "command", "command": "fixture-profiles"}], + "globalArguments": ["${optionArguments:profiles}"] + }, + "options": [{ + "id": "profiles", + "displayName": "Profiles", + "kind": "multiSelect", + "choicesFromModel": true, + "allowCustom": true, + "presentation": "tree", + "arguments": ["-P", "${value}"] + }], + "model": {"source": "command", "arguments": ["model"], "decoder": "litheBuildModel", "executesProjectCode": false, "mayUseNetwork": false}, + "tasks": [{"id": "compile", "displayName": "compile", "group": "lifecycle", "category": ["Lifecycle"], "scopes": ["workspace", "project"], "arguments": ["compile"]}] + }] + }`) + decodeRequest := BuildDecodeModelRequest{ + WorkspaceRoot: t.TempDir(), + Root: ".", + Output: `{ + "format": "litheBuildModel", + "version": 0, + "projects": [{"path": ".", "name": "shop"}], + "optionValues": {"profiles": ["dev", "local", "prod"]}, + "optionDefaults": {"profiles": ["dev"]}, + "optionExcludePrefixes": {"profiles": "-"}, + "optionActiveChoices": {"profiles": ["dev"]} + }`, + } + decoded, err := client.DecodeBuildModel(ctx, manifest, "fixture-profiles", decodeRequest) + if err != nil { + t.Fatal(err) + } + if !slices.Equal(decoded.OptionDefaults["profiles"], []string{"dev"}) || decoded.OptionExcludePrefixes["profiles"] != "-" { + t.Fatalf("decoded model facts = defaults %+v, prefixes %+v", decoded.OptionDefaults, decoded.OptionExcludePrefixes) + } + + resolved, err := client.ResolveBuildOptions(ctx, manifest, "fixture-profiles", BuildResolveOptionsRequest{ + ModelValues: decoded.OptionValues, + ModelDefaults: decoded.OptionDefaults, + ModelExcludePrefixes: decoded.OptionExcludePrefixes, + ModelSelection: decoded.OptionSelection, + }) + if err != nil { + t.Fatal(err) + } + if len(resolved.Options) != 1 || !slices.Equal(resolved.Options[0].SelectedChoices, []string{"dev"}) || !resolved.Options[0].Choices[0].DefaultActive { + t.Fatalf("initial resolved options = %+v", resolved.Options) + } + + decodeRequest.Options = map[string]json.RawMessage{"profiles": json.RawMessage(`["prod"]`)} + decodeRequest.Output = strings.Replace(decodeRequest.Output, + `"optionActiveChoices": {"profiles": ["dev"]}`, + `"optionActiveChoices": {"profiles": ["dev", "prod"]}`, 1) + observed, err := client.DecodeBuildModel(ctx, manifest, "fixture-profiles", decodeRequest) + if err != nil { + t.Fatal(err) + } + selected, err := client.ResolveBuildOptions(ctx, manifest, "fixture-profiles", BuildResolveOptionsRequest{ + Options: decodeRequest.Options, ModelValues: observed.OptionValues, + ModelDefaults: observed.OptionDefaults, ModelExcludePrefixes: observed.OptionExcludePrefixes, + ModelSelection: observed.OptionSelection, + }) + if err != nil { + t.Fatal(err) + } + if !slices.Equal(selected.Options[0].SelectedChoices, []string{"dev", "prod"}) { + t.Fatalf("checked choices after loading the stored options: %+v", selected.Options) + } + + noTeam := json.RawMessage(`{"version":1,"systems":{}}`) + switched, err := client.EditStoredBuildOption(ctx, manifest, "fixture-profiles", BuildOptionEditRequest{ + Document: noTeam, + Local: emptyBuildLocal, + Root: ".", + OptionID: "profiles", + SelectedChoices: []string{"prod"}, + HasSelectedChoices: true, + ModelValues: decoded.OptionValues, + ModelDefaults: decoded.OptionDefaults, + ModelExcludePrefixes: decoded.OptionExcludePrefixes, + ModelSelection: decoded.OptionSelection, + }) + if err != nil { + t.Fatal(err) + } + var states BuildResolvedOptions + if err := json.Unmarshal(switched.Options, &states); err != nil { + t.Fatal(err) + } + var stored []string + if err := json.Unmarshal(states.Options[0].Value, &stored); err != nil || !slices.Equal(stored, []string{"-dev", "prod"}) { + t.Fatalf("stored profile tokens = %q (err %v), want [-dev prod]", stored, err) + } + + plan, err := client.PlanBuildTask(ctx, manifest, "fixture-profiles", BuildPlanRequest{ + Root: ".", + Task: "compile", + Options: map[string]json.RawMessage{"profiles": states.Options[0].Value}, + }) + if err != nil { + t.Fatal(err) + } + if !slices.Equal(plan.Arguments, []string{"-P", "-dev,prod", "compile"}) { + t.Fatalf("task plan arguments = %q, want [-P -dev,prod compile]", plan.Arguments) + } + + tree, err := client.BuildModelTree(ctx, manifest, "fixture-profiles", BuildModelTreeRequest{ + Model: BuildModelTreeInput{ + Projects: decoded.Projects, + OptionValues: decoded.OptionValues, + OptionDefaults: decoded.OptionDefaults, + OptionExcludePrefixes: decoded.OptionExcludePrefixes, + OptionSelection: decoded.OptionSelection, + }, + Options: map[string]json.RawMessage{"profiles": states.Options[0].Value}, + }) + if err != nil { + t.Fatal(err) + } + if len(tree.Nodes) == 0 || tree.Nodes[0].Kind != BuildTreeOption || tree.Nodes[0].Detail != "prod" || len(tree.Nodes[0].Children) != 3 { + t.Fatalf("tree option node = %+v", tree.Nodes) + } + choices := tree.Nodes[0].Children + if choices[0].OptionValue != "dev" || choices[0].Checked || !choices[0].DefaultActive || choices[2].OptionValue != "prod" || !choices[2].Checked { + t.Fatalf("tree option choices = %+v", choices) + } + + restored, err := client.EditStoredBuildOption(ctx, manifest, "fixture-profiles", BuildOptionEditRequest{ + Document: noTeam, + Local: switched.Local, + Root: ".", + OptionID: "profiles", + SelectedChoices: []string{"dev"}, + HasSelectedChoices: true, + ModelValues: decoded.OptionValues, + ModelDefaults: decoded.OptionDefaults, + ModelExcludePrefixes: decoded.OptionExcludePrefixes, + ModelSelection: decoded.OptionSelection, + }) + if err != nil { + t.Fatal(err) + } + if string(restored.Local) != `{"version":1,"document":{"version":1,"systems":{}},"emptySelections":{}}` && !slices.Equal(restored.Local, emptyBuildLocal) { + t.Fatalf("restoring the default selection left local = %s", restored.Local) + } +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 889b91b965..3cf5d1b8b1 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -128,6 +128,8 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.build.noMatches": "No matching build items", "desktop.build.noOptions": "This build system declares no options.", "desktop.build.noTasks": "No build tasks", + "desktop.build.optionChoiceDefault": "default", + "desktop.build.optionChoiceDefaultLabel": "{title} (default)", "desktop.build.options": "Options", "desktop.build.optionsTitle": "Build Options", "desktop.build.output": "Build output", @@ -149,6 +151,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.build.targetMissing": "The selected target is no longer in the build model. Refresh the build system.", "desktop.build.targets": "Targets", "desktop.build.testDiscoveryFailed": "Could not discover tests: {error}", + "desktop.build.toggleOptionChoice": "Toggle {option}: {choice}", "desktop.build.toolchainGap": "The provider prepared {toolchain}. This build cannot launch a toolchain reference yet.", "desktop.build.treeFailed": "The build tree could not be shown: {error}", "desktop.build.treeTruncated": "Too many build items to list them all; only the first ones are shown.", @@ -3086,6 +3089,8 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.build.noMatches": "没有匹配的构建项", "desktop.build.noOptions": "此构建系统没有声明可配置的选项。", "desktop.build.noTasks": "没有构建任务", + "desktop.build.optionChoiceDefault": "默认", + "desktop.build.optionChoiceDefaultLabel": "{title}(默认)", "desktop.build.options": "选项", "desktop.build.optionsTitle": "构建选项", "desktop.build.output": "构建输出", @@ -3107,6 +3112,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.build.targetMissing": "所选目标已不在构建模型中,请刷新构建系统。", "desktop.build.targets": "目标", "desktop.build.testDiscoveryFailed": "无法发现测试:{error}", + "desktop.build.toggleOptionChoice": "切换 {option}:{choice}", "desktop.build.toolchainGap": "提供者准备了 {toolchain}。当前构建尚不能启动工具链引用。", "desktop.build.treeFailed": "无法显示构建树:{error}", "desktop.build.treeTruncated": "构建项太多,只列出了前面一部分。", diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index c86bd34bd4..369703e970 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -65,6 +65,7 @@ type Kernel interface { DetectBuildSystems(ctx context.Context, workspaceRoot string, manifests []json.RawMessage) (core.BuildDetection, error) DetectBuildSystemsWithOptions(ctx context.Context, workspaceRoot string, manifests []json.RawMessage, options core.BuildDetectOptions) (core.BuildDetection, error) ResolveStoredBuildOptions(ctx context.Context, document, local json.RawMessage) (core.BuildStoredOptions, error) + ResolveBuildOptions(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildResolveOptionsRequest) (core.BuildResolvedOptions, error) EditStoredBuildOption(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildOptionEditRequest) (core.BuildOptionEdit, error) EditBuildIgnoredPaths(ctx context.Context, request core.BuildIgnoredPathsEditRequest) (core.BuildIgnoredPathsEdit, error) IDEHostOpen(ctx context.Context, request core.IDEHostOpenRequest) (core.IDEHostOpenResult, error) diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index 655df9746a..e44b8c4e43 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -53,6 +53,8 @@ type buildState struct { // reloadPending says a stored option changed while a detection was running, so the instances are // detected again when that detection ends. reloadPending bool + // optionSaving says a toggle on an option choice of the tree is being saved to the local document. + optionSaving bool // status is the last result line of the current or latest execution. status string @@ -716,6 +718,7 @@ func (a *App) loadBuildModelWith(p *project, index int, refresh bool) { instance.modelLoading = true instance.modelError, instance.modelStopped = "", false captured := *instance + generation := p.build.generation kernel := a.kernel // The load is a session of the Run window, which shows what the tool prints meanwhile. feed := a.beginBuildSync(p, instance) @@ -728,6 +731,9 @@ func (a *App) loadBuildModelWith(p *project, index int, refresh bool) { } return func(a *App) { a.endBuildSync(feed.session, err) + if a.project != p || p.build.generation != generation { + return + } a.finishBuildModel(p, captured.ID, model, err) } }) @@ -1590,7 +1596,7 @@ func (a *App) beginBuildTarget(p *project, key, targetID string, run pluginservi op.debug = debug options.Debug = &debug.launch } - a.runBuildTargetWith(p, op, instance, target.ProjectID, targetID, runID, options) + a.runBuildTargetWith(p, op, instance, target.ProjectID, targetID, runID, options, nil) } // debugBuildTarget debugs one target of the Build window's selected instance and project @@ -1763,7 +1769,7 @@ func (a *App) startProviderDebug(p *project, pluginID string, preparation core.B // launch without any. A project or target the model no longer has ends op as failed. Command // run declarations do not come here: Core expands them into the model's Run entries, which // runBuildEntry runs. -func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *buildInstance, projectID, targetID, runID string, options *core.RunLaunchOptions) { +func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *buildInstance, projectID, targetID, runID string, options *core.RunLaunchOptions, overrides map[string]json.RawMessage) { project, ok := buildProjectByID(instance.Model, projectID) if !ok { a.notifyError(a.text.Build.ProjectMissing) @@ -1790,13 +1796,14 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build prepare, release := op.bind(bounded) defer release() request := core.BuildPlanRequest{ - Root: captured.Root, - Options: captured.Options, - WorkspaceRoot: p.root, - Run: runID, - Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, - Target: selectedTarget, - LaunchOptions: options, + Root: captured.Root, + Options: captured.Options, + WorkspaceRoot: p.root, + Run: runID, + Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, + Target: selectedTarget, + LaunchOptions: options, + OptionOverrides: overrides, } a.addBuildToolHint(prepare, p, captured, &request) plan, err := kernel.PlanBuildRun(prepare, captured.Manifest, captured.BuildSystemID, request) diff --git a/desktop/internal/workbench/build_ignored_paths_test.go b/desktop/internal/workbench/build_ignored_paths_test.go index b65cbae572..23c83e72f3 100644 --- a/desktop/internal/workbench/build_ignored_paths_test.go +++ b/desktop/internal/workbench/build_ignored_paths_test.go @@ -2,10 +2,12 @@ package workbench import ( "context" + "encoding/json" "os" "path/filepath" "slices" "testing" + "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -39,7 +41,7 @@ const ignoredPathsManifest = `{ // openIgnoredPathsProject installs the fixture build system, opens a project with a fixture.build file // in its root, in .claude/copy and in tools, writes team as the team Build options document when it is not // empty, and opens the Build tool window once detection has finished. -func openIgnoredPathsProject(t *testing.T, team string) (*harness, *project) { +func openIgnoredPathsProject(t *testing.T, team string, kernel Kernel) (*harness, *project) { t.Helper() dir := t.TempDir() if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil { @@ -74,8 +76,11 @@ func openIgnoredPathsProject(t *testing.T, team string) (*harness, *project) { t.Fatal(err) } } + if kernel == nil { + kernel = &testKernel{Client: core.NewClient()} + } h := newHarnessWithOptions(t, Options{ - Kernel: &testKernel{Client: core.NewClient()}, + Kernel: kernel, PluginKernel: &testKernel{Client: core.NewClient()}, PluginRoot: pluginRoot, Store: preferences, @@ -164,7 +169,7 @@ func (h *harness) typeIgnoredPaths(p *project, text string) { // opens the Build options on the ignored paths alone; a list typed there is saved on this machine and the // build systems are detected again with it, and Restore Default removes it. func TestBuildOptionsIgnoredPathsAreSavedOnThisMachineAndRestored(t *testing.T) { - h, p := openIgnoredPathsProject(t, "") + h, p := openIgnoredPathsProject(t, "", nil) if got := buildRoots(p); !slices.Equal(got, []string{".", "tools"}) { t.Fatalf("by default the build systems are at %q, want the dot-named folder skipped", got) } @@ -220,7 +225,7 @@ func TestBuildOptionsIgnoredPathsAreSavedOnThisMachineAndRestored(t *testing.T) // A build system's options open with the ignored paths above them, here the team file's list. A pattern // Core refuses keeps the dialog open, names its line in the field and stores nothing. func TestBuildOptionsNameTheLineOfARefusedIgnoredPath(t *testing.T) { - h, p := openIgnoredPathsProject(t, `{"version":1,"systems":{},"ignoredPaths":["/tools"]}`) + h, p := openIgnoredPathsProject(t, `{"version":1,"systems":{},"ignoredPaths":["/tools"]}`, nil) if got := buildRoots(p); !slices.Equal(got, []string{".", ".claude/copy"}) { t.Fatalf("with the team's list the build systems are at %q", got) } @@ -247,3 +252,78 @@ func TestBuildOptionsNameTheLineOfARefusedIgnoredPath(t *testing.T) { t.Fatalf("the refused list stored %+v", got) } } + +type buildOptionResolutionGate struct { + Kernel + started chan struct{} + release context.Context +} + +func (g *buildOptionResolutionGate) ResolveBuildOptions(ctx context.Context, manifest json.RawMessage, systemID string, request core.BuildResolveOptionsRequest) (core.BuildResolvedOptions, error) { + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + select { + case g.started <- struct{}{}: + case <-ctx.Done(): + return core.BuildResolvedOptions{}, ctx.Err() + } + select { + case <-g.release.Done(): + return g.Kernel.ResolveBuildOptions(ctx, manifest, systemID, request) + case <-ctx.Done(): + return core.BuildResolvedOptions{}, ctx.Err() + } +} + +func TestBuildOptionsWaitForResolutionBeforeEditAndSave(t *testing.T) { + release, finishResolution := context.WithCancel(t.Context()) + defer finishResolution() + gate := &buildOptionResolutionGate{ + Kernel: &testKernel{Client: core.NewClient()}, started: make(chan struct{}, 1), release: release, + } + h, p := openIgnoredPathsProject(t, "", gate) + clickWithoutSettling := func(label string) { + at := center(h.pageHit(label).Bounds) + if err := h.driver.Click(at.X, at.Y); err != nil { + t.Fatal(err) + } + } + + const option = "Release Profile" + save := h.shared("ui.save") + clickWithoutSettling(h.shared("desktop.build.options")) + awaitValueWithin(t, h, 5*time.Second, gate.started, "Build options resolution to start") + + // The frame paints the declared checkbox while Core is still resolving the editor. + clickWithoutSettling(option) + if hit := h.pageHit(option); !hit.Disabled || hit.Checked { + t.Errorf("pending checkbox: disabled %v, checked %v; want disabled and unchecked", hit.Disabled, hit.Checked) + } + if !h.pageHit(save).Disabled { + t.Error("Save is enabled while options are resolving") + } + if h.pageHit(h.shared("desktop.git.cancel")).Disabled { + t.Error("Cancel is disabled while options are resolving") + } + clickWithoutSettling(save) + if !p.build.options.open { + t.Fatal("Save closed the dialog before resolution completed") + } + + finishResolution() + h.awaitIgnoredPathsLoaded(p) + h.clickNamed(option) + if hit := h.pageHit(option); hit.Disabled || !hit.Checked { + t.Fatalf("resolved checkbox: disabled %v, checked %v; want enabled and checked", hit.Disabled, hit.Checked) + } + h.clickNamed(save) + h.settleUntil("the saved dialog to close", func() bool { return !p.build.options.open }) + h.awaitBuildDetection(p) + instance := p.selectedBuildInstance() + if instance == nil { + t.Fatal("the build instance was not detected again after saving") + } + if got := string(instance.Options["release"]); got != "true" { + t.Fatalf("release option after saving and reloading = %q, want true", got) + } +} diff --git a/desktop/internal/workbench/build_options.go b/desktop/internal/workbench/build_options.go index ba3b2459d0..ef48cd1ced 100644 --- a/desktop/internal/workbench/build_options.go +++ b/desktop/internal/workbench/build_options.go @@ -136,8 +136,10 @@ type buildOptionsEditor struct { name, root string fields []runOptionField ignored buildIgnoredPathsEditor - saving bool - failure string + // loading keeps the initial read from replacing fields that the user has started to edit. + loading bool + saving bool + failure string } // buildIgnoredPathsEditor is the ignored-paths field of the dialog, one pattern a line, filled with the list @@ -199,7 +201,7 @@ func ignoredPathLines(text string) (patterns []string, lines []int) { // on that instance's effective option values. The ignored paths are read from the stored documents now. func (a *App) openBuildOptions(p *project, instance *buildInstance) { p.build.optionsSessions++ - editor := buildOptionsEditor{open: true, session: p.build.optionsSessions} + editor := buildOptionsEditor{open: true, session: p.build.optionsSessions, loading: true} if instance != nil { editor.instance, editor.name, editor.root = instance.ID, buildSystemName(instance), buildRootDetail(instance) editor.fields = declaredOptionFields(instance.Manifest, instance.BuildSystemID, instance.Options) @@ -215,7 +217,23 @@ func (a *App) readBuildIgnoredPaths(p *project, inherit bool) { e := &p.build.options e.ignored.restoring = inherit kernel, root, session := a.kernel, p.root, e.session + var captured *buildInstance + if !inherit && e.instance != "" { + if instance := p.buildInstanceByID(e.instance); instance != nil { + copyInstance := *instance + captured = ©Instance + } + } a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + var resolvedFields []runOptionField + if captured != nil { + resolved, err := resolveInstanceOptionFields(ctx, kernel, *captured, nil) + if err != nil { + a.backgroundFailedIn(ctx, "build_options_resolve", err) + } else { + resolvedFields = resolved + } + } ignored, err := func() (core.BuildIgnoredPaths, error) { docs, err := a.readBuildOptionDocuments(ctx, root) if err != nil { @@ -233,7 +251,11 @@ func (a *App) readBuildIgnoredPaths(p *project, inherit bool) { if !e.open || e.session != session { return } + e.loading = false e.ignored.restoring = false + if len(resolvedFields) != 0 { + e.fields = resolvedFields + } if err != nil { e.failure = err.Error() return @@ -251,13 +273,19 @@ func (a *App) readBuildIgnoredPaths(p *project, inherit bool) { // detects the instances again so they show what was read back. func (a *App) saveBuildOptions(p *project) { e := &p.build.options - if !e.open || e.saving { + if !e.open || e.loading || e.saving || e.ignored.restoring { return } instance := p.buildInstanceByID(e.instance) var changes []buildOptionChange if instance != nil { for _, field := range e.fields { + if selected, changed := changedSelectedChoices(field); changed { + changes = append(changes, buildOptionChange{ + optionID: field.id, selectedChoices: selected, hasSelectedChoices: true, + }) + continue + } if value, changed := changedOptionValue(field); changed { changes = append(changes, buildOptionChange{optionID: field.id, value: value}) } @@ -300,10 +328,13 @@ func buildOptionsFailure(language i18n.Language, err error, lines []int) string return i18n.Shared(language, "desktop.build.invalidIgnoredPaths") } -// buildOptionChange is one option the user set; a nil value removes the local override. +// buildOptionChange is one option the user set; a nil value (without hasSelectedChoices) removes the local +// override, while hasSelectedChoices sends the checked choice list for Core to encode against defaults. type buildOptionChange struct { - optionID string - value any + optionID string + value any + selectedChoices []string + hasSelectedChoices bool } // saveBuildOptionChanges applies changes to one instance's options, and the ignored-path change when it is @@ -326,9 +357,22 @@ func (a *App) saveBuildOptionChanges(p *project, instance *buildInstance, change local := docs.local var options json.RawMessage for _, change := range changes { - edit, err := kernel.EditStoredBuildOption(ctx, target.Manifest, target.BuildSystemID, core.BuildOptionEditRequest{ - Document: docs.team, Local: local, Root: target.Root, OptionID: change.optionID, Value: change.value, - }) + req := core.BuildOptionEditRequest{ + Document: docs.team, + Local: local, + Root: target.Root, + OptionID: change.optionID, + Value: change.value, + SelectedChoices: change.selectedChoices, + HasSelectedChoices: change.hasSelectedChoices, + } + if target.modelLoaded { + req.ModelValues = target.Model.OptionValues + req.ModelDefaults = target.Model.OptionDefaults + req.ModelExcludePrefixes = target.Model.OptionExcludePrefixes + req.ModelSelection = target.Model.OptionSelection + } + edit, err := kernel.EditStoredBuildOption(ctx, target.Manifest, target.BuildSystemID, req) if err != nil { return func(a *App) { done(nil, err) } } @@ -349,6 +393,7 @@ func (a *App) saveBuildOptionChanges(p *project, instance *buildInstance, change return } done(options, nil) + p.reloadBuildDependencies() a.requestBuildReload(p) } }) @@ -396,7 +441,7 @@ func (a *App) buildOptionsDialog(c ui.C, p *project) { return } language := a.language() - ready := !e.saving + ready := !e.loading && !e.saving open := true closed := ui.ModalWith(c, &open, i18n.Shared(language, "desktop.build.optionsTitle"), ui.ModalSpec{Width: 460}, func() { ui.Column(c.Part("build-options")).FillWidth().Gap(10).Children(func() { @@ -409,13 +454,16 @@ func (a *App) buildOptionsDialog(c ui.C, p *project) { ui.Text(k, e.root).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) } }) - if len(e.fields) == 0 { + if len(e.fields) == 0 && !e.loading { ui.Wrap(k, i18n.Shared(language, "desktop.build.noOptions")).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) } for index := range e.fields { a.drawRunOptionField(k.KeyInt(index), language, &e.fields[index], ready) } } + if e.loading { + ui.Text(c, i18n.Shared(language, "native.loading")).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) + } if e.failure != "" { ui.Paragraph(c, e.failure, 4).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger) } diff --git a/desktop/internal/workbench/build_panels_visual_test.go b/desktop/internal/workbench/build_panels_visual_test.go index b805f4f8da..024b9e1f33 100644 --- a/desktop/internal/workbench/build_panels_visual_test.go +++ b/desktop/internal/workbench/build_panels_visual_test.go @@ -3,11 +3,13 @@ package workbench import ( + "context" "encoding/json" "os" "path/filepath" "strings" "testing" + "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" @@ -54,20 +56,39 @@ func visualBuildSystems() []buildInstance { lifecycle = append(lifecycle, task(phase, phase, "lifecycle", "Lifecycle")) } lifecycle = append(lifecycle, pluginservice.BuildTaskDeclaration{ID: "goal", DisplayName: "Plugin goal", Group: "build", FromModel: true, Source: "provider"}) + maven := system("maven", "Maven", ".", run, lifecycle, core.BuildModel{ + Projects: []core.BuildProject{ + {ID: "shop", Path: ".", Name: "shop"}, + {ID: "core", Path: "core", Name: "shop-core", ParentID: "shop"}, + {ID: "web", Path: "web", Name: "shop-web", ParentID: "shop"}, + }, + Targets: []core.BuildTarget{{ID: "web-app", ProjectID: "web", Name: "ShopApplication", Path: "web", Tags: []string{"app"}}}, + Tasks: []core.BuildTask{ + goal("shop", "clean", "clean"), goal("shop", "install", "install"), + goal("core", "compiler", "compile"), goal("core", "compiler", "testCompile"), goal("core", "surefire", "test"), goal("core", "jar", "jar"), + goal("web", "compiler", "compile"), goal("web", "spring-boot", "run"), goal("web", "spring-boot", "repackage"), + }, + OptionValues: map[string][]string{"profiles": {"ci", "dev", "prod"}}, + OptionDefaults: map[string][]string{"profiles": {"dev"}}, + OptionExcludePrefixes: map[string]string{"profiles": "-"}, + }) + maven.Options = map[string]json.RawMessage{"profiles": json.RawMessage(`["dev","prod"]`)} + maven.OptionFingerprint = "visual-profiles-dev-prod" + var mavenManifest map[string]any + if err := json.Unmarshal(maven.Manifest, &mavenManifest); err != nil { + panic(err) + } + mavenManifest["buildSystems"].([]any)[0].(map[string]any)["options"] = []any{map[string]any{ + "id": "profiles", "displayName": "Profiles", "kind": "multiSelect", + "choicesFromModel": true, "allowCustom": true, "presentation": "tree", + "arguments": []string{"-P", "${value}"}, + }} + var err error + if maven.Manifest, err = json.Marshal(mavenManifest); err != nil { + panic(err) + } return []buildInstance{ - system("maven", "Maven", ".", run, lifecycle, core.BuildModel{ - Projects: []core.BuildProject{ - {ID: "shop", Path: ".", Name: "shop"}, - {ID: "core", Path: "core", Name: "shop-core", ParentID: "shop"}, - {ID: "web", Path: "web", Name: "shop-web", ParentID: "shop"}, - }, - Targets: []core.BuildTarget{{ID: "web-app", ProjectID: "web", Name: "ShopApplication", Path: "web", Tags: []string{"app"}}}, - Tasks: []core.BuildTask{ - goal("shop", "clean", "clean"), goal("shop", "install", "install"), - goal("core", "compiler", "compile"), goal("core", "compiler", "testCompile"), goal("core", "surefire", "test"), goal("core", "jar", "jar"), - goal("web", "compiler", "compile"), goal("web", "spring-boot", "run"), goal("web", "spring-boot", "repackage"), - }, - }), + maven, system("gradle", "Gradle", "android", run, []pluginservice.BuildTaskDeclaration{ task("assemble", "assemble", "build", "Build"), task("build", "build", "build", "Build"), task("check", "check", "verification", "Verification"), }, core.BuildModel{ @@ -125,8 +146,8 @@ func visualGoModule() buildInstance { // TestVisualBuildPanels captures the Build window on the right, with the run configurations // above the aggregated build tree, beside the Run window at the bottom showing only the build // console; a Go module whose model loads, its sync session in the Run window showing what go -// downloads; the Build window filtered; and a Go module, whose runnable rows lead with the green -// triangle. +// downloads; the Build window filtered; a Go module with runnable rows; and the Build options +// dialog while it is resolving its fields and after the result arrives. func TestVisualBuildPanels(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -136,7 +157,7 @@ func TestVisualBuildPanels(t *testing.T) { t.Fatal(err) } for _, look := range []struct{ theme, language string }{{"dark", "zh-Hans"}, {"light", "en"}} { - for _, scene := range []string{"build-and-run", "concurrent-runs", "build-sync", "build-filter", "build-go-targets"} { + for _, scene := range []string{"build-and-run", "concurrent-runs", "build-sync", "build-filter", "build-go-targets", "build-options"} { t.Run(scene+"-"+look.theme, func(t *testing.T) { prefs := store.At(t.TempDir()) if err := prefs.Save(settingsFile, settings{Theme: themeChoice(look.theme), Language: look.language, DisableAutoSave: true}); err != nil { @@ -150,7 +171,17 @@ func TestVisualBuildPanels(t *testing.T) { } } var session *headless.Session - h := newHarnessWithDriver(t, Options{Kernel: &testKernel{Client: core.NewClient()}, Store: prefs, Languages: []string{look.language}}, func(config app.Config) (*app.Driver, func(), error) { + var kernel Kernel = &testKernel{Client: core.NewClient()} + var resolution *buildOptionResolutionGate + var finishResolution context.CancelFunc + if scene == "build-options" { + var release context.Context + release, finishResolution = context.WithCancel(t.Context()) + defer finishResolution() + resolution = &buildOptionResolutionGate{Kernel: kernel, started: make(chan struct{}, 1), release: release} + kernel = resolution + } + h := newHarnessWithDriver(t, Options{Kernel: kernel, Store: prefs, Languages: []string{look.language}}, func(config app.Config) (*app.Driver, func(), error) { config.Width, config.Height = 1440, 900 var err error session, err = headless.Open(config, nil, headless.Options{}) @@ -169,9 +200,9 @@ func TestVisualBuildPanels(t *testing.T) { a.refreshRunConfigurations(p) }) h.settleChain() - // The folders a user opens to reach shop-core's compiler goals and shop-web's - // lifecycle; the rest stay closed, as they start. - for _, path := range [][]string{{"shop-core", "Plugins"}, {"shop-core", "Plugins", "compiler"}, {"shop-web", "Lifecycle"}} { + // The folders a user opens to inspect active profiles, shop-core's compiler goals and + // shop-web's lifecycle; the rest stay closed, as they start. + for _, path := range [][]string{{"Profiles"}, {"shop-core", "Plugins"}, {"shop-core", "Plugins", "compiler"}, {"shop-web", "Lifecycle"}} { setBuildNodeOpen(t, p, laidOutBuildRows(t, h, p), true, path...) } switch scene { @@ -253,6 +284,13 @@ func TestVisualBuildPanels(t *testing.T) { }) h.settleChain() setBuildNodeOpen(t, p, laidOutBuildRows(t, h, p), true, h.app.text.Build.Targets) + case "build-options": + h.app.post(func(a *App) { a.openBuildOptions(p, &p.build.instances[0]) }) + awaitValueWithin(t, h, 5*time.Second, resolution.started, "Build options resolution to start") + if err := session.Screenshot(filepath.Join(out, "build-options-loading-"+look.theme+".png")); err != nil { + t.Fatal(err) + } + finishResolution() } h.settleChain() h.app.invalidator.Invalidate() diff --git a/desktop/internal/workbench/build_tree.go b/desktop/internal/workbench/build_tree.go index f33ff14a1b..c36a631bde 100644 --- a/desktop/internal/workbench/build_tree.go +++ b/desktop/internal/workbench/build_tree.go @@ -2,7 +2,9 @@ package workbench import ( "context" + "encoding/json" "hash/fnv" + "slices" "strings" "time" @@ -50,16 +52,18 @@ func buildGroupHeadings(language i18n.Language) map[string]string { } } -// buildTree is one instance's tree as Core laid it out for one filter. version is the model -// version it came from (buildInstance.modelVersion), query and language the filter and the -// language of its folder headings. targets finds a target node's target in that model by ID. +// buildTree is one instance's tree as Core laid it out for one filter. version and +// optionFingerprint are the model version and effective option digest it came from +// (buildInstance.modelVersion, buildInstance.OptionFingerprint), query and language the filter +// and the language of its folder headings. targets finds a target node's target in that model by ID. type buildTree struct { - version uint64 - query string - language i18n.Language - tree core.BuildModelTree - failed string - targets map[string]int + version uint64 + optionFingerprint string + query string + language i18n.Language + tree core.BuildModelTree + failed string + targets map[string]int } // buildTrees are the trees of one instance: the whole tree and the latest filtered one, each @@ -196,7 +200,9 @@ func (a *App) buildTreeOf(p *project, index int, query string) *buildTree { shown, out = instance.trees.filtered, &instance.trees.filteredOut } language := a.language() - current := shown != nil && shown.version == instance.modelVersion && shown.query == query && shown.language == language + current := shown != nil && shown.version == instance.modelVersion && + shown.optionFingerprint == instance.OptionFingerprint && + shown.query == query && shown.language == language if !current && !*out { *out = true a.layOutBuildTree(p, instance, query, language) @@ -210,12 +216,26 @@ func (a *App) buildTreeOf(p *project, index int, query string) *buildTree { func (a *App) layOutBuildTree(p *project, instance *buildInstance, query string, language i18n.Language) { kernel := a.kernel id, generation := instance.ID, p.build.generation - manifest, buildSystemID, version := instance.Manifest, instance.BuildSystemID, instance.modelVersion - model := core.BuildModelTreeInput{Projects: instance.Model.Projects, Targets: instance.Model.Targets, Tasks: instance.Model.Tasks} + manifest, buildSystemID, version, optionFingerprint := instance.Manifest, instance.BuildSystemID, instance.modelVersion, instance.OptionFingerprint + options := make(map[string]json.RawMessage, len(instance.Options)) + for key, value := range instance.Options { + options[key] = slices.Clone(value) + } + model := core.BuildModelTreeInput{ + Projects: instance.Model.Projects, + Targets: instance.Model.Targets, + Tasks: instance.Model.Tasks, + OptionValues: instance.Model.OptionValues, + OptionDefaults: instance.Model.OptionDefaults, + OptionExcludePrefixes: instance.Model.OptionExcludePrefixes, + OptionSelection: instance.Model.OptionSelection, + } headings := buildGroupHeadings(language) a.background(p, buildTreeTimeout, func(ctx context.Context) func(*App) { - tree := &buildTree{version: version, query: query, language: language} - laid, err := kernel.BuildModelTree(ctx, manifest, buildSystemID, core.BuildModelTreeRequest{Model: model, Query: query, GroupHeadings: headings}) + tree := &buildTree{version: version, optionFingerprint: optionFingerprint, query: query, language: language} + laid, err := kernel.BuildModelTree(ctx, manifest, buildSystemID, core.BuildModelTreeRequest{ + Model: model, Options: options, Query: query, GroupHeadings: headings, + }) if err != nil { a.backgroundFailedIn(ctx, "build_tree", err) tree.failed = err.Error() @@ -249,7 +269,7 @@ func (a *App) finishBuildTree(p *project, id string, generation uint64, tree *bu } else { trees.filteredOut = false } - if tree.version != instance.modelVersion { + if tree.version != instance.modelVersion || tree.optionFingerprint != instance.OptionFingerprint { return } if tree.query == "" { @@ -408,7 +428,7 @@ func (a *App) appendBuildTree(rows []buildRow, p *project, index int, tree *buil if tree == nil { return rows } - rows = a.appendBuildNodes(rows, p, index, tree, tree.tree.Nodes, 1, filtering) + rows = a.appendBuildNodes(rows, p, index, tree, tree.tree.Nodes, 1, filtering, "") if tree.tree.Truncated && !filtering { row := note(i18n.Shared(a.language(), "desktop.build.treeTruncated")) row.warning = true @@ -422,7 +442,7 @@ func (a *App) appendBuildTree(rows []buildRow, p *project, index int, tree *buil // filtering, a node Core kept for a match below it is open and stays so, and a match shows as // the user left it with all it holds; the discovered tests node shows only the tests that // match, and is left out when none does. -func (a *App) appendBuildNodes(rows []buildRow, p *project, index int, tree *buildTree, nodes []core.BuildTreeNode, level int, filtering bool) []buildRow { +func (a *App) appendBuildNodes(rows []buildRow, p *project, index int, tree *buildTree, nodes []core.BuildTreeNode, level int, filtering bool, optionTitle string) []buildRow { b, t, language := &p.build, a.text.Build, a.language() instance := &b.instances[index] selected := index == b.selected @@ -445,9 +465,14 @@ func (a *App) appendBuildNodes(rows []buildRow, p *project, index int, tree *bui case core.BuildTreeTask: row.kind = buildRowTask row.selected = selected && b.taskID == node.TaskID && b.projectID == node.ProjectID && b.targetID == node.TargetID - case core.BuildTreeFolder: - // Core names the folder: by its category heading, else by the group heading it was sent. + case core.BuildTreeFolder, core.BuildTreeOption: + // Core names the folder: by its category heading, option display name, or group heading. row.kind = buildRowFolder + case core.BuildTreeOptionChoice: + row.kind, row.optionTitle = buildRowOptionChoice, optionTitle + if node.DefaultActive { + row.detail = i18n.Shared(language, "desktop.build.optionChoiceDefault") + } case core.BuildTreeTargets: row.kind, row.label = buildRowFolder, t.Targets case core.BuildTreeDependencies: @@ -479,12 +504,102 @@ func (a *App) appendBuildNodes(rows []buildRow, p *project, index int, tree *bui } rows = append(rows, tests...) default: - rows = a.appendBuildNodes(rows, p, index, tree, node.Children, level+1, fixed) + childOption := optionTitle + if node.Kind == core.BuildTreeOption { + childOption = node.Label + } + rows = a.appendBuildNodes(rows, p, index, tree, node.Children, level+1, fixed, childOption) } } return rows } +// toggleBuildTreeOptionChoice flips one choice of a tree-presented multi-select option on the +// instance at index, writes the updated local option document through Core, and reloads the +// build systems so the model, tasks, dependencies and run configurations pick up the change. +func (a *App) toggleBuildTreeOptionChoice(p *project, index int, optionID, choiceValue string) { + b := &p.build + if b.optionSaving || b.loading || b.operation != nil || index < 0 || index >= len(b.instances) { + return + } + instance := &b.instances[index] + if !instance.modelLoaded || instance.modelLoading || optionID == "" || choiceValue == "" { + return + } + docs, err := a.readBuildOptionDocuments(context.Background(), p.root) + if err != nil { + a.notifyError(a.launchFailureText(err)) + return + } + b.optionSaving = true + captured := *instance + kernel, root := a.kernel, p.root + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + fields, err := resolveInstanceOptionFields(ctx, kernel, captured, nil) + if err != nil { + return func(a *App) { + p.build.optionSaving = false + a.notifyError(a.launchFailureText(err)) + } + } + var next []string + found := false + for _, field := range fields { + if field.id != optionID { + continue + } + for at, choice := range field.choices { + checked := at < len(field.picks) && field.picks[at] + if choice.value == choiceValue { + checked = !checked + found = true + } + if checked { + next = append(next, choice.value) + } + } + break + } + if !found { + return func(a *App) { p.build.optionSaving = false } + } + if next == nil { + next = []string{} + } + edit, err := kernel.EditStoredBuildOption(ctx, captured.Manifest, captured.BuildSystemID, core.BuildOptionEditRequest{ + Document: docs.team, + Local: docs.local, + Root: captured.Root, + OptionID: optionID, + SelectedChoices: next, + HasSelectedChoices: true, + ModelValues: captured.Model.OptionValues, + ModelDefaults: captured.Model.OptionDefaults, + ModelExcludePrefixes: captured.Model.OptionExcludePrefixes, + ModelSelection: captured.Model.OptionSelection, + }) + if err != nil { + return func(a *App) { + p.build.optionSaving = false + a.notifyError(a.launchFailureText(err)) + } + } + return func(a *App) { + p.build.optionSaving = false + if a.project != p { + return + } + if err := a.storeBuildLocalOptions(root, edit.Local); err != nil { + a.notifyError(a.launchFailureText(err)) + return + } + p.reloadBuildDependencies() + p.revokeBuildTests(captured.ID) + a.requestBuildReload(p) + } + }) +} + // reloadBuildSystems detects the workspace's build systems again: the instances, their models, // trees, dependency trees and discovered tests are dropped and found anew. What the user // opened and closed is kept by instance and node, so an instance found again shows as before. diff --git a/desktop/internal/workbench/build_tree_options_test.go b/desktop/internal/workbench/build_tree_options_test.go new file mode 100644 index 0000000000..c91a5de560 --- /dev/null +++ b/desktop/internal/workbench/build_tree_options_test.go @@ -0,0 +1,369 @@ +package workbench + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "slices" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginstate" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" +) + +// treeOptionsStaticManifest declares a synthetic build system whose static TOML model supplies +// choices and default-active choices for a tree-presented multi-select option with an exclusion +// prefix, plus a provider run so the Run Configuration editor also edits the option. +const treeOptionsStaticManifest = `{ + "schemaVersion": 0, + "id": "dev.lithe.test.tree-options", + "displayName": "Tree Options Fixture", + "version": "1.0.0", + "pluginAPIVersion": 0, + "requires": {"buildProviders": 0, "buildSystems": 0}, + "vendor": {"id": "dev.lithe.test", "displayName": "Test", "signatureRequirement": "publisherPackage"}, + "permissions": ["languageServer.launch", "process.build"], + "activationEvents": ["onBuildSystem:fixture-profiles"], + "languages": [], + "buildSystems": [{ + "id": "fixture-profiles", + "displayName": "Fixture Build", + "detection": {"markers": ["fixture.toml"]}, + "invocation": { + "executables": [{"kind": "command", "command": "fixture-build"}], + "globalArguments": ["${optionArguments:profiles}"] + }, + "provider": { + "launch": {"kind": "packaged", "path": "provider"}, + "arguments": [], + "executesProjectCode": false, + "mayUseNetwork": false + }, + "options": [{ + "id": "profiles", + "displayName": "Profiles", + "kind": "multiSelect", + "choicesFromModel": true, + "allowCustom": true, + "excludePrefix": "-", + "presentation": "tree", + "arguments": ["-P", "${value}"] + }], + "model": { + "source": "static", + "file": "fixture.toml", + "decoder": "toml", + "map": { + "projects": [{ + "each": "/package", + "name": "/name", + "targets": [{"each": "$/apps/*", "name": "/name", "tags": ["app"]}] + }], + "optionValues": {"profiles": {"each": "/profiles/*", "value": "@key"}}, + "optionDefaults": {"profiles": {"each": "/defaultProfiles/*", "value": "@key"}} + } + }, + "tasks": [{ + "id": "compile", + "displayName": "compile", + "group": "lifecycle", + "category": ["Lifecycle"], + "scopes": ["workspace", "project"], + "arguments": ["compile"] + }], + "run": [{ + "id": "app", + "name": "Run", + "source": "provider", + "execution": "service", + "fromTargets": {"tags": ["app"]} + }] + }] +}` + +const treeOptionsFixtureTOML = `[package] +name = "shop" + +[[apps]] +name = "ServerApp" + +[profiles] +dev = true +local = false +prod = false + +[defaultProfiles] +dev = true +` + +func openTreeOptionsProject(t *testing.T, kernel Kernel) (*harness, *project) { + t.Helper() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil { + t.Fatal(err) + } + preferences := store.At(dir) + pluginRoot := t.TempDir() + installed := filepath.Join(pluginRoot, "dev.lithe.test.tree-options", "1.0.0") + if err := os.MkdirAll(installed, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(installed, "plugin.json"), []byte(treeOptionsStaticManifest), 0o600); err != nil { + t.Fatal(err) + } + if err := pluginstate.New(preferences).SetEnabled("dev.lithe.test.tree-options", true); err != nil { + t.Fatal(err) + } + root := t.TempDir() + if err := os.WriteFile(filepath.Join(root, "fixture.toml"), []byte(treeOptionsFixtureTOML), 0o600); err != nil { + t.Fatal(err) + } + h := newHarnessWithOptions(t, Options{ + Kernel: kernel, + PluginKernel: &testKernel{Client: core.NewClient()}, + PluginRoot: pluginRoot, + Store: preferences, + Languages: []string{"en-US"}, + }) + h.open(root) + p := h.app.project + if p == nil { + t.Fatal("the project did not open") + } + h.app.reduceChrome(core.ToggleChrome(itemBuild)) + h.awaitBuildDetection(p) + h.settleUntil("initial tree and run configurations", func() bool { + return !p.runConfigs.loading && p.build.instances[0].trees.whole != nil && !p.build.instances[0].trees.wholeOut + }) + h.settle() + return h, p +} + +func storedProfileTokens(t *testing.T, h *harness, p *project) ([]string, bool) { + t.Helper() + docs, err := h.app.readBuildOptionDocuments(context.Background(), p.root) + if err != nil { + t.Fatal(err) + } + storage, err := core.NewClient().ResolveStoredBuildOptions(context.Background(), docs.team, docs.local) + if err != nil { + t.Fatal(err) + } + inputs, err := buildDetectOptions(storage) + if err != nil { + t.Fatal(err) + } + raw, ok := inputs.Options["fixture-profiles"]["profiles"] + if !ok { + return nil, false + } + var tokens []string + if err := json.Unmarshal(raw, &tokens); err != nil { + t.Fatal(err) + } + return tokens, true +} + +// A tree-presented multi-select option starts closed with its active choices in its detail, opens +// to show checkboxes with default-active markers, keeps hidden checked choices when toggled under a +// filter, encodes exclusions when a default-active choice is unchecked, and prunes the local +// override once the user returns to the default selection. +func TestBuildTreePresentsAndTogglesModelOptionChoices(t *testing.T) { + h, p := openTreeOptionsProject(t, &testKernel{Client: core.NewClient()}) + language := h.app.language() + defaultBadge := i18n.Shared(language, "desktop.build.optionChoiceDefault") + targets := h.app.text.Build.Targets + + expectBuildTree(t, h, p, "initial collapsed options", []string{ + "group Fixture Build: shop", + " folder Profiles (dev)", + " folder Lifecycle", + " folder " + targets, + }) + + // Click Profiles in the Build window to expand it and verify default-active choice is checked. + h.click(center(h.labelBounds("Profiles"))) + h.settle() + expectBuildTree(t, h, p, "expanded Profiles", []string{ + "group Fixture Build: shop", + " folder Profiles (dev)", + " choice [x] dev (" + defaultBadge + ")", + " choice [ ] local", + " choice [ ] prod", + " folder Lifecycle", + " folder " + targets, + }) + + toggleChoice := func(choice string) { + t.Helper() + h.settleUntil("tree layout before toggling "+choice, func() bool { + trees := &p.build.instances[0].trees + return !trees.wholeOut && !trees.filteredOut + }) + h.settle() + label := i18n.SharedFormat(language, "desktop.build.toggleOptionChoice", map[string]string{ + "option": "Profiles", + "choice": choice, + }) + h.clickNamed(label) + h.settleUntil("option toggle "+choice, func() bool { + return !p.build.optionSaving && p.build.loaded && !p.build.loading && !p.build.reloadPending + }) + } + + // Checking prod alongside default dev stores ["dev", "prod"] and keeps Profiles open across reload. + toggleChoice("prod") + if got, ok := storedProfileTokens(t, h, p); !ok || !slices.Equal(got, []string{"dev", "prod"}) { + t.Fatalf("stored tokens after checking prod = %q (%v), want [dev prod]", got, ok) + } + expectBuildTree(t, h, p, "after checking prod", []string{ + "group Fixture Build: shop", + " folder Profiles (dev, prod)", + " choice [x] dev (" + defaultBadge + ")", + " choice [ ] local", + " choice [x] prod", + " folder Lifecycle", + " folder " + targets, + }) + + // Filtering by "dev" hides "prod"; unchecking "dev" while filtered preserves hidden "prod" and + // encodes "-dev" so the default-active choice stays off. + h.app.post(func(*App) { p.panels.buildFilter = "dev" }) + h.settle() + expectBuildTree(t, h, p, "filtered to dev", []string{ + "group Fixture Build: shop", + " folder Profiles (dev, prod)", + " choice [x] dev (" + defaultBadge + ")", + }) + toggleChoice("dev") + if got, ok := storedProfileTokens(t, h, p); !ok || !slices.Equal(got, []string{"-dev", "prod"}) { + t.Fatalf("stored tokens after unchecking dev under filter = %q (%v), want [-dev prod]", got, ok) + } + + // Clearing the filter shows dev unchecked (still marked default) and prod checked. + h.app.post(func(*App) { p.panels.buildFilter = "" }) + h.settle() + expectBuildTree(t, h, p, "after clearing filter", []string{ + "group Fixture Build: shop", + " folder Profiles (prod)", + " choice [ ] dev (" + defaultBadge + ")", + " choice [ ] local", + " choice [x] prod", + " folder Lifecycle", + " folder " + targets, + }) + + // Unchecking prod leaves zero active choices, encoded as ["-dev"] so default dev does not come back. + toggleChoice("prod") + if got, ok := storedProfileTokens(t, h, p); !ok || !slices.Equal(got, []string{"-dev"}) { + t.Fatalf("stored tokens with all choices unchecked = %q (%v), want [-dev]", got, ok) + } + expectBuildTree(t, h, p, "all choices unchecked", []string{ + "group Fixture Build: shop", + " folder Profiles", + " choice [ ] dev (" + defaultBadge + ")", + " choice [ ] local", + " choice [ ] prod", + " folder Lifecycle", + " folder " + targets, + }) + + // Re-checking dev returns to the model's default active set and prunes the local override. + toggleChoice("dev") + if got, ok := storedProfileTokens(t, h, p); ok { + t.Fatalf("restoring default selection still stored %q, want pruned", got) + } + expectBuildTree(t, h, p, "restored default selection", []string{ + "group Fixture Build: shop", + " folder Profiles (dev)", + " choice [x] dev (" + defaultBadge + ")", + " choice [ ] local", + " choice [ ] prod", + " folder Lifecycle", + " folder " + targets, + }) +} + +// Both the Build options dialog and the Run Configuration options editor resolve model choices and +// default-active markers through Core and encode exclusions when saving changes. +func TestBuildAndRunOptionEditorsResolveAndSaveModelChoices(t *testing.T) { + gate := &captureBuildPlan{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h, p := openTreeOptionsProject(t, gate) + language := h.app.language() + + // Open the Build options dialog on the selected instance. + h.clickNamed(h.shared("desktop.build.options")) + h.settleUntil("build options dialog resolved", func() bool { + e := &p.build.options + return e.open && e.ignored.loaded && len(e.fields) == 1 && e.fields[0].kind == "multiSelect" + }) + field := p.build.options.fields[0] + if len(field.choices) != 3 || !field.choices[0].defaultActive || !slices.Equal(field.picks, []bool{true, false, false}) { + t.Fatalf("build options dialog field = %+v", field) + } + defaultLabel := i18n.SharedFormat(language, "desktop.build.optionChoiceDefaultLabel", map[string]string{"title": "dev"}) + h.clickNamed(defaultLabel) + h.clickNamed("local") + h.clickNamed(h.shared("ui.save")) + h.settleUntil("build options dialog closed", func() bool { return !p.build.options.open }) + h.awaitBuildDetection(p) + if got, ok := storedProfileTokens(t, h, p); !ok || !slices.Equal(got, []string{"-dev", "local"}) { + t.Fatalf("stored tokens after Build options save = %q (%v), want [-dev local]", got, ok) + } + + // Open the Run Configuration editor on "Run ServerApp" and override Profiles for that run alone. + awaitStateWithin(t, h, 10*time.Second, "provider run configuration", func() bool { + return !p.runConfigs.loading && len(p.runConfigs.list) == 1 + }) + configID := p.runConfigs.list[0].ID + dialog := &p.runConfigs.dialog + h.app.post(func(a *App) { a.openRunConfigDialog(p, configID) }) + awaitStateWithin(t, h, 10*time.Second, "run configuration editor resolved", func() bool { + draft := dialog.drafts[configID] + return draft != nil && draft.editor != nil && draft.editor.ready() && len(draft.editor.optionFields) == 1 + }) + editor := dialog.drafts[configID].editor + runField := &editor.optionFields[0] + if runField.kind != "multiSelect" || len(runField.choices) != 3 || !runField.choices[0].defaultActive || !slices.Equal(runField.picks, []bool{false, true, false}) { + t.Fatalf("run configuration option field = %+v", *runField) + } + if editor.dirty() { + t.Fatal("resolved choices mark an untouched run configuration dirty") + } + saveChoices := func(picks []bool, step runConfigDialogStep, want []string) { + t.Helper() + h.app.post(func(*App) { runField.picks = picks }) + applyDialog(t, h, p, step) + if dialog.open != (step == runConfigDialogApply) || editor.failure != "" { + t.Fatalf("dialog open %v, save failure %q", dialog.open, editor.failure) + } + config := p.runConfigs.configuration(configID) + if config == nil { + t.Fatal("the saved run configuration was not read back") + } + state, _ := providerRunEditorState(*config) + var tokens []string + if err := json.Unmarshal(state.options["profiles"], &tokens); err != nil || !slices.Equal(tokens, want) { + t.Fatalf("run configuration profile override = %q (err %v), want %q", tokens, err, want) + } + } + // Apply keeps the editor alive. Editing back to its original selection must replace the saved draft. + saveChoices([]bool{false, false, true}, runConfigDialogApply, []string{"-dev", "prod"}) + saveChoices([]bool{false, true, false}, runConfigDialogApply, []string{"-dev", "local"}) + saveChoices([]bool{false, false, true}, runConfigDialogOK, []string{"-dev", "prod"}) + + h.app.post(func(a *App) { a.runConfiguration(p, configID) }) + awaitStateWithin(t, h, 10*time.Second, "provider run plan", func() bool { return len(gate.requests) == 1 }) + request := <-gate.requests + var runTokens []string + if err := json.Unmarshal(request.OptionOverrides["profiles"], &runTokens); err != nil || !slices.Equal(runTokens, []string{"-dev", "prod"}) { + t.Fatalf("profiles passed to the run plan = %q (err %v), want [-dev prod]", runTokens, err) + } + if err := json.Unmarshal(request.Options["profiles"], &runTokens); err != nil || !slices.Equal(runTokens, []string{"-dev", "local"}) { + t.Fatalf("instance profiles passed to the run plan = %q (err %v), want [-dev local]", runTokens, err) + } +} diff --git a/desktop/internal/workbench/build_tree_test.go b/desktop/internal/workbench/build_tree_test.go index f7a5573b67..97de943ee1 100644 --- a/desktop/internal/workbench/build_tree_test.go +++ b/desktop/internal/workbench/build_tree_test.go @@ -98,10 +98,19 @@ func buildTreeShape(rows []buildRow) []string { kinds := map[buildRowKind]string{ buildRowGroup: "group", buildRowFolder: "folder", buildRowEmpty: "note", buildRowProject: "project", buildRowTarget: "target", buildRowTask: "task", buildRowDependency: "dependency", buildRowTest: "test", + buildRowOptionChoice: "choice", } shape := make([]string, 0, len(rows)) for _, row := range rows { - entry := strings.Repeat(" ", row.level) + kinds[row.kind] + " " + row.label + entry := strings.Repeat(" ", row.level) + kinds[row.kind] + if row.kind == buildRowOptionChoice { + if row.node != nil && row.node.Checked { + entry += " [x]" + } else { + entry += " [ ]" + } + } + entry += " " + row.label if row.kind == buildRowGroup && row.node != nil { entry += ": " + row.node.Label } diff --git a/desktop/internal/workbench/build_tree_view.go b/desktop/internal/workbench/build_tree_view.go index 80ef252ff5..4cd9962639 100644 --- a/desktop/internal/workbench/build_tree_view.go +++ b/desktop/internal/workbench/build_tree_view.go @@ -201,6 +201,8 @@ func (a *App) buildTreeRow(row ui.ListRow, p *project, spec buildRow) { a.buildDependencyRow(row, p, instance, spec) case buildRowTest: a.buildTestRow(row, p, instance, spec) + case buildRowOptionChoice: + a.buildOptionChoiceRow(row, p, instance, spec) default: a.buildItemRow(row, p, instance, spec) } @@ -359,6 +361,7 @@ func (a *App) buildGroupRow(row ui.ListRow, p *project, instance *buildInstance, // IntelliJ New UI icons of the same folders in IntelliJ's Maven and Gradle tool windows. var buildFolderIcons = map[string]fileicons.BuildNode{ core.BuildTreeFolder: fileicons.BuildTaskFolder, + core.BuildTreeOption: fileicons.BuildTaskFolder, core.BuildTreeTargets: fileicons.BuildTargets, core.BuildTreeDependencies: fileicons.BuildDependencies, core.BuildTreeTests: fileicons.BuildTests, @@ -604,3 +607,38 @@ func (a *App) buildItemRow(row ui.ListRow, p *project, instance *buildInstance, } a.buildRowMenu(c, element, p, instance, spec) } + +// buildOptionChoiceRow declares one choice of a tree-presented multi-select option: its empty +// arrow slot, its checkbox, its choice label and its default-active badge when the model marks +// it active by default. Clicking the checkbox or the row toggles the choice in the project's +// local Build options and reloads the build systems. +func (a *App) buildOptionChoiceRow(row ui.ListRow, p *project, instance *buildInstance, spec buildRow) { + c, b, node := row.C, &p.build, spec.node + element := a.buildTreeRowElement(row, spec) + if tip := buildItemTip(spec); tip != "" { + element = element.Tooltip(tip) + } + busy := b.operation != nil || b.loading || b.optionSaving || instance.modelLoading + checked := node.Checked + toggleLabel := i18n.SharedFormat(a.language(), "desktop.build.toggleOptionChoice", map[string]string{ + "option": spec.optionTitle, + "choice": spec.label, + }) + ui.Row(c.Part("arrow")).Size(treelist.Disclosure, treelist.Icon).Shrink(0) + var boxClicked bool + ui.Row(c.Part("content")).Grow(1).Shrink(1).MinWidth(0).Items(ui.Center).Gap(changeTreeGap).Children(func() { + boxClicked = a.treeCheckbox(c.Part("check"), &checked, toggleLabel).Disabled(busy).Clicked() + ui.Text(c, spec.label).FontSize(treeFontSize).Color(treelist.Text(a.colors.Dark)).Ellipsis().Shrink(1).MinWidth(0) + if spec.detail != "" { + ui.Text(c, spec.detail).FontSize(treeFontSize - 1).Color(a.colors.Subtle).Ellipsis().Shrink(buildDetailShrink).MinWidth(0) + } + }) + if !busy && (boxClicked || element.Clicked()) { + index, optionID, choiceValue := spec.instance, node.OptionID, node.OptionValue + c.After(func() { + a.performed("build.optionChoice.toggle", surfaceButton) + a.chooseBuildInstance(p, index) + a.toggleBuildTreeOptionChoice(p, index, optionID, choiceValue) + }) + } +} diff --git a/desktop/internal/workbench/build_view.go b/desktop/internal/workbench/build_view.go index 3791da4e6a..dea10d2e33 100644 --- a/desktop/internal/workbench/build_view.go +++ b/desktop/internal/workbench/build_view.go @@ -13,8 +13,8 @@ type buildRowKind uint8 const ( buildRowGroup buildRowKind = iota - // buildRowFolder heads nodes it holds: a task folder, a project's targets, dependencies or - // discovered tests. + // buildRowFolder heads nodes it holds: a task folder, a tree-presented option, a project's + // targets, dependencies or discovered tests. buildRowFolder buildRowEmpty buildRowProject @@ -22,16 +22,18 @@ const ( buildRowTask buildRowDependency buildRowTest + buildRowOptionChoice ) // buildRow is one row of the build tree (build_tree.go): a build system's group, a node of // the tree Core laid out for it, a dependency or discovered test the host loads under one, or // a note that something is empty, still loading or failed. type buildRow struct { - kind buildRowKind - label string - detail string - selected bool + kind buildRowKind + label string + detail string + optionTitle string + selected bool // tooltip is what the row shows while the pointer rests on it: the full name of a target // whose label is its path alone, or a task's description; empty for none. tooltip string diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index 30545c4cf0..e7a94c1e63 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -332,7 +332,7 @@ func (a *App) prepareConfiguredRun(p *project, op *buildOperation, id string, re if launch.Customized() { options = &launch } - a.runBuildTargetWith(p, op, &p.build.instances[index], inputs.Reference.ProjectID, inputs.Reference.TargetID, inputs.Reference.Run, options) + a.runBuildTargetWith(p, op, &p.build.instances[index], inputs.Reference.ProjectID, inputs.Reference.TargetID, inputs.Reference.Run, options, inputs.OptionOverrides) } }) } diff --git a/desktop/internal/workbench/runconfig_edit.go b/desktop/internal/workbench/runconfig_edit.go index def928b195..644849ef95 100644 --- a/desktop/internal/workbench/runconfig_edit.go +++ b/desktop/internal/workbench/runconfig_edit.go @@ -40,7 +40,7 @@ type runConfigEditor struct { provider bool runtimeArguments string entrypoint string - // options are the build option overrides, kept as they were: this editor does not edit them. + // options are the build option overrides saved for this configuration. options map[string]json.RawMessage // tools are the tool choices by qualified tool ID, with the kind of each choice ("home" or // "executable") and the path the editor shows. A cleared path sends null for that tool. @@ -120,10 +120,20 @@ func (a *App) openRunConfigEditor(p *project, id string) *runConfigEditor { e.beforeLaunch = append(e.beforeLaunch, step.Configuration) } e.savedBeforeLaunch = slices.Clone(e.beforeLaunch) + var buildInstance *buildInstance + var optionSnapshot map[string]json.RawMessage if provider, ok := providerRunEditorState(*configuration); ok { e.provider, e.runtimeArguments, e.entrypoint, e.options, e.tools = true, provider.runtimeArguments, provider.entrypoint, provider.options, provider.tools if reference, ok := configuration.BuildReference(); ok { e.optionFields = p.runOptionFields(reference, e.options) + if index := p.buildInstanceIndex(reference); index >= 0 { + captured := p.build.instances[index] + buildInstance = &captured + optionSnapshot = make(map[string]json.RawMessage, len(e.options)) + for key, value := range e.options { + optionSnapshot[key] = slices.Clone(value) + } + } } a.loadRunConfigInstalls(p, e, e.generation) } @@ -134,6 +144,15 @@ func (a *App) openRunConfigEditor(p *project, id string) *runConfigEditor { if err == nil && len(texts) != 1 { err = errors.New("runConfig.argumentText returned no text") } + var resolvedFields []runOptionField + if err == nil && buildInstance != nil { + fields, resolveErr := resolveInstanceOptionFields(ctx, kernel, *buildInstance, optionSnapshot) + if resolveErr != nil { + a.backgroundFailedIn(ctx, "build_options_resolve", resolveErr) + } else { + resolvedFields = fields + } + } return func(a *App) { if !e.open || e.generation != generation { return @@ -144,6 +163,9 @@ func (a *App) openRunConfigEditor(p *project, id string) *runConfigEditor { } else { e.failure = i18n.SharedFormat(a.language(), "desktop.runConfig.saveFailed", map[string]string{"reason": err.Error()}) } + if len(resolvedFields) != 0 { + e.optionFields = resolvedFields + } e.baseline = e.fingerprint() } }) @@ -202,20 +224,36 @@ func (a *App) saveRunConfigEditor(p *project, e *runConfigEditor, done func(ok b steps = append([]string{}, e.beforeLaunch...) edit.BeforeLaunch = &steps } + var multiSelectEdits map[string][]string + var multiSelectInstance *buildInstance + var editorSnapshot runConfigEditor if e.provider { - applyRunOptionFields(e) - raw, err := providerRunOptionsJSON(e) - if err != nil { - e.failure = i18n.SharedFormat(a.language(), "desktop.runConfig.saveFailed", map[string]string{"reason": err.Error()}) - done(false) - return + for _, field := range e.optionFields { + if selected, changed := changedSelectedChoices(field); changed { + if multiSelectEdits == nil { + multiSelectEdits = map[string][]string{} + } + multiSelectEdits[field.id] = selected + } + } + if len(multiSelectEdits) != 0 { + if configuration := p.runConfigs.configuration(e.id); configuration != nil { + if reference, ok := configuration.BuildReference(); ok { + if index := p.buildInstanceIndex(reference); index >= 0 { + captured := p.build.instances[index] + multiSelectInstance = &captured + } + } + } } - edit.ProviderRunOptions = raw + editorSnapshot = *e + editorSnapshot.options = maps.Clone(e.options) + editorSnapshot.tools = slices.Clone(e.tools) + applyRunOptionFields(&editorSnapshot) } e.saving, e.failure = true, "" - generation := e.generation - a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { - err := a.saveRunConfigOptions(ctx, edit) + generation, kernel := e.generation, a.kernel + finish := func(err error) func(*App) { return func(a *App) { current := e.open && e.generation == generation if current { @@ -229,10 +267,55 @@ func (a *App) saveRunConfigEditor(p *project, e *runConfigEditor, done func(ok b return } if current { + e.options = editorSnapshot.options + for i := range e.optionFields { + field := &e.optionFields[i] + field.initFlag, field.initText, field.initPick = field.flag, field.text, slices.Clone(field.picks) + } e.baseline, e.savedBeforeLaunch = e.fingerprint(), slices.Clone(steps) } done(true) } + } + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + if len(multiSelectEdits) != 0 && multiSelectInstance != nil { + request := core.BuildResolveOptionsRequest{ + Options: editorSnapshot.options, + SelectedChoices: multiSelectEdits, + InheritedOptions: multiSelectInstance.Options, + } + if multiSelectInstance.modelLoaded { + request.ModelValues = multiSelectInstance.Model.OptionValues + request.ModelDefaults = multiSelectInstance.Model.OptionDefaults + request.ModelExcludePrefixes = multiSelectInstance.Model.OptionExcludePrefixes + request.ModelSelection = multiSelectInstance.Model.OptionSelection + } + resolved, err := kernel.ResolveBuildOptions(ctx, multiSelectInstance.Manifest, multiSelectInstance.BuildSystemID, request) + if err != nil { + return finish(err) + } + if editorSnapshot.options == nil { + editorSnapshot.options = map[string]json.RawMessage{} + } + for _, option := range resolved.Options { + if _, edited := multiSelectEdits[option.ID]; !edited { + continue + } + if option.Source == "user" { + editorSnapshot.options[option.ID] = option.Value + } else { + delete(editorSnapshot.options, option.ID) + } + } + } + if editorSnapshot.provider { + raw, err := providerRunOptionsJSON(&editorSnapshot) + if err != nil { + return finish(err) + } + edit.ProviderRunOptions = raw + } + return finish(a.saveRunConfigOptions(ctx, edit)) }) } diff --git a/desktop/internal/workbench/runconfig_options.go b/desktop/internal/workbench/runconfig_options.go index 0ed8ace0c8..e66ff7801f 100644 --- a/desktop/internal/workbench/runconfig_options.go +++ b/desktop/internal/workbench/runconfig_options.go @@ -1,21 +1,24 @@ package workbench import ( + "context" "encoding/json" "slices" "github.com/1lck/Lithe-IDEA/desktop/internal/core" ) -// The run configuration editor and the Build options editor show the build options a plugin declares, from -// the plugin manifest of the detected instance. A value is kept as the stored JSON; only a field the user -// changed is written back, through the same Core edit that the caller uses. A boolean is a checkbox, a single -// choice a picker, a text, file or directory a text field, and a multi-choice with declared choices a list of -// checkboxes. Options whose choices come from the model, and kinds the editor cannot edit, show read-only. +// The run configuration editor and the Build options editor show the build options a plugin declares, +// resolved by Core against the instance's loaded model when one is present. A value is kept as the stored +// JSON; only a field the user changed is written back, through the same Core edit that the caller uses. A +// boolean is a checkbox, a single choice a picker, a text, file or directory a text field, and a +// multi-choice with declared or model choices a list of checkboxes. Options whose model choices have not +// been loaded yet, and kinds the editor cannot edit, show read-only. -// runOptionChoice is one declared choice of a single or multi choice option. +// runOptionChoice is one choice of a single or multi choice option. type runOptionChoice struct { - value, title string + value, title string + defaultActive bool } // runOptionField is one declared option as the editor shows it. The init fields are what the value was when @@ -108,6 +111,94 @@ func declaredOptionFields(manifest json.RawMessage, buildSystemID string, values return fields } +// resolvedOptionFields turns Core's build.resolveOptions answer into editor fields, including choices +// supplied by the loaded model and their default-active state. +func resolvedOptionFields(resolved core.BuildResolvedOptions) []runOptionField { + fields := make([]runOptionField, 0, len(resolved.Options)) + for _, option := range resolved.Options { + field := runOptionField{id: option.ID, title: option.DisplayName, kind: option.Kind} + if field.title == "" { + field.title = option.ID + } + for _, choice := range option.Choices { + title := choice.Title + if title == "" { + title = choice.Value + } + field.choices = append(field.choices, runOptionChoice{ + value: choice.Value, title: title, defaultActive: choice.DefaultActive, + }) + } + stored := option.Source == "user" || option.Source == "default" + switch { + case option.Kind == "boolean" && stored: + _ = json.Unmarshal(option.Value, &field.flag) + field.initFlag = field.flag + case (option.Kind == "text" || option.Kind == "file" || option.Kind == "directory") && option.Source == "user": + _ = json.Unmarshal(option.Value, &field.text) + field.initText = field.text + case option.Kind == "singleSelect" && option.Source == "user": + _ = json.Unmarshal(option.Value, &field.text) + field.initText = field.text + } + if option.Kind == "multiSelect" && len(field.choices) > 0 { + selected := option.SelectedChoices + if selected == nil && stored { + _ = json.Unmarshal(option.Value, &selected) + } + field.picks = make([]bool, len(field.choices)) + for index, choice := range field.choices { + field.picks[index] = slices.Contains(selected, choice.value) + } + field.initPick = slices.Clone(field.picks) + } + if (option.Kind == "singleSelect" && len(field.choices) == 0) || (option.Kind == "multiSelect" && len(field.choices) == 0) { + field.kind = "readonly" + } + if option.Kind == "multiSelect" && len(field.choices) == 0 && option.Source == "user" { + field.raw = option.Value + } + if !slices.Contains([]string{"boolean", "singleSelect", "text", "file", "directory", "multiSelect"}, option.Kind) { + field.kind = "readonly" + if option.Source == "user" { + field.raw = option.Value + } + } + fields = append(fields, field) + } + return fields +} + +// resolveInstanceOptionFields asks Core to resolve instance's options against values and its loaded model. +func resolveInstanceOptionFields(ctx context.Context, kernel Kernel, instance buildInstance, values map[string]json.RawMessage) ([]runOptionField, error) { + request := core.BuildResolveOptionsRequest{Options: values, InheritedOptions: instance.Options} + if instance.modelLoaded { + request.ModelValues = instance.Model.OptionValues + request.ModelDefaults = instance.Model.OptionDefaults + request.ModelExcludePrefixes = instance.Model.OptionExcludePrefixes + request.ModelSelection = instance.Model.OptionSelection + } + resolved, err := kernel.ResolveBuildOptions(ctx, instance.Manifest, instance.BuildSystemID, request) + if err != nil { + return nil, err + } + return resolvedOptionFields(resolved), nil +} + +// changedSelectedChoices reports the checked choice values of a multi-select field when the user changed it. +func changedSelectedChoices(field runOptionField) ([]string, bool) { + if field.kind != "multiSelect" || slices.Equal(field.picks, field.initPick) { + return nil, false + } + selected := []string{} + for index, choice := range field.choices { + if field.picks[index] { + selected = append(selected, choice.value) + } + } + return selected, true +} + // changedOptionValue reports the value a field's change sends, and whether the field changed. A cleared text // or choice sends nil, which removes the override; a multi choice sends the selected values, an empty list // being an explicit empty selection. diff --git a/desktop/internal/workbench/runconfig_view.go b/desktop/internal/workbench/runconfig_view.go index 8d897a6a9e..c1ebf1e717 100644 --- a/desktop/internal/workbench/runconfig_view.go +++ b/desktop/internal/workbench/runconfig_view.go @@ -367,7 +367,11 @@ func (a *App) drawRunOptionField(c ui.C, language i18n.Language, field *runOptio case "multiSelect": ui.Text(c, field.title).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) for index := range field.choices { - ui.Checkbox(c.KeyInt(index), &field.picks[index], field.choices[index].title).Disabled(!ready) + title := field.choices[index].title + if field.choices[index].defaultActive { + title = i18n.SharedFormat(language, "desktop.build.optionChoiceDefaultLabel", map[string]string{"title": title}) + } + ui.Checkbox(c.KeyInt(index), &field.picks[index], title).Disabled(!ready) } default: text := field.title + ": " + i18n.Shared(language, "desktop.runConfig.optionReadOnly") diff --git a/docs/assets/build-panels/README.md b/docs/assets/build-panels/README.md index ae27ead198..06eee2d9ac 100644 --- a/docs/assets/build-panels/README.md +++ b/docs/assets/build-panels/README.md @@ -8,11 +8,13 @@ | 场景 | 深色中文 | 浅色英文 | | --- | --- | --- | -| 右侧构建窗口(运行配置列表和按父子项目嵌套的构建树)与底部运行窗口(只显示构建控制台):Maven 的唯一根项目 shop 由构建系统行代表,子模块 shop-core、shop-web 嵌套在它下面,各自列出 Lifecycle、Plugins 和依赖;展开了 shop-core 的 Plugins / compiler 和 shop-web 的 Lifecycle,其余文件夹保持默认折叠 | [截图](build-and-run-dark.png) | [截图](build-and-run-light.png) | +| 右侧构建窗口(运行配置列表和按父子项目嵌套的构建树)与底部运行窗口(只显示构建控制台):Maven 的唯一根项目 shop 由构建系统行代表,树顶展开了 Profiles 多选清单(显示已勾选、默认激活标记与未勾选项),子模块 shop-core、shop-web 嵌套在它下面,各自列出 Lifecycle、Plugins 和依赖;展开了 shop-core 的 Plugins / compiler 和 shop-web 的 Lifecycle,其余文件夹保持默认折叠 | [截图](build-and-run-dark.png) | [截图](build-and-run-light.png) | | Go 模块的模型正在加载:运行窗口为这次加载开了“同步 Go Modules (desktop)”标签,执行树显示运行中状态、开始时间和最新一行输出,控制台是 go 下载模块时打印的日志,左侧有再次运行和停止;构建窗口里正在加载的那一行在说明后显示最新一行输出,点击打开这个标签 | [截图](build-sync-dark.png) | [截图](build-sync-light.png) | | 构建窗口按名称筛选:只保留命中的节点和通往它的项目与文件夹,没有命中的构建系统不显示 | [截图](build-filter-dark.png) | [截图](build-filter-light.png) | | Go 模块的 Targets 文件夹展开:目标以完整导入路径命名,行上只显示所在目录;可运行的目标和任务行首是绿色运行按钮,依赖标题旁有 ⓘ | [截图](build-go-targets-dark.png) | [截图](build-go-targets-light.png) | +| 构建选项加载中,编辑和保存不可用 | [截图](build-options-loading-dark.png) | [截图](build-options-loading-light.png) | +| 构建选项加载完成,可以勾选和保存 | [截图](build-options-dark.png) | [截图](build-options-light.png) | -复验:设置 `LITHE_VISUAL_OUTPUT_DIR`,通过 `scripts/desktop/desktop-go.sh test +设置 `LITHE_VISUAL_OUTPUT_DIR` 后,运行 `scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/workbench -run '^TestVisualBuildPanels' -count=1 -timeout 180s` 生成。 diff --git a/docs/assets/build-panels/build-and-run-dark.png b/docs/assets/build-panels/build-and-run-dark.png index ab9cf5758c..b498efcf2d 100644 Binary files a/docs/assets/build-panels/build-and-run-dark.png and b/docs/assets/build-panels/build-and-run-dark.png differ diff --git a/docs/assets/build-panels/build-and-run-light.png b/docs/assets/build-panels/build-and-run-light.png index 58705f1c53..f02a11e1a6 100644 Binary files a/docs/assets/build-panels/build-and-run-light.png and b/docs/assets/build-panels/build-and-run-light.png differ diff --git a/docs/assets/build-panels/build-filter-dark.png b/docs/assets/build-panels/build-filter-dark.png index abb9990773..36e946dd78 100644 Binary files a/docs/assets/build-panels/build-filter-dark.png and b/docs/assets/build-panels/build-filter-dark.png differ diff --git a/docs/assets/build-panels/build-filter-light.png b/docs/assets/build-panels/build-filter-light.png index 44fc35400c..b7a1249c11 100644 Binary files a/docs/assets/build-panels/build-filter-light.png and b/docs/assets/build-panels/build-filter-light.png differ diff --git a/docs/assets/build-panels/build-go-targets-dark.png b/docs/assets/build-panels/build-go-targets-dark.png index e0c0c04c37..f10f58ae4e 100644 Binary files a/docs/assets/build-panels/build-go-targets-dark.png and b/docs/assets/build-panels/build-go-targets-dark.png differ diff --git a/docs/assets/build-panels/build-go-targets-light.png b/docs/assets/build-panels/build-go-targets-light.png index c2ceade7ce..686b590bed 100644 Binary files a/docs/assets/build-panels/build-go-targets-light.png and b/docs/assets/build-panels/build-go-targets-light.png differ diff --git a/docs/assets/build-panels/build-options-dark.png b/docs/assets/build-panels/build-options-dark.png new file mode 100644 index 0000000000..eee95ec410 Binary files /dev/null and b/docs/assets/build-panels/build-options-dark.png differ diff --git a/docs/assets/build-panels/build-options-light.png b/docs/assets/build-panels/build-options-light.png new file mode 100644 index 0000000000..4e189e00dd Binary files /dev/null and b/docs/assets/build-panels/build-options-light.png differ diff --git a/docs/assets/build-panels/build-options-loading-dark.png b/docs/assets/build-panels/build-options-loading-dark.png new file mode 100644 index 0000000000..aecc4fc6b2 Binary files /dev/null and b/docs/assets/build-panels/build-options-loading-dark.png differ diff --git a/docs/assets/build-panels/build-options-loading-light.png b/docs/assets/build-panels/build-options-loading-light.png new file mode 100644 index 0000000000..769de439c1 Binary files /dev/null and b/docs/assets/build-panels/build-options-loading-light.png differ diff --git a/docs/assets/build-panels/build-sync-dark.png b/docs/assets/build-panels/build-sync-dark.png index b1e063f715..bd72a5ecae 100644 Binary files a/docs/assets/build-panels/build-sync-dark.png and b/docs/assets/build-panels/build-sync-dark.png differ diff --git a/docs/assets/build-panels/build-sync-light.png b/docs/assets/build-panels/build-sync-light.png index 0dd6200e9a..f1d2273fe9 100644 Binary files a/docs/assets/build-panels/build-sync-light.png and b/docs/assets/build-panels/build-sync-light.png differ diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 42d62501d4..e1fc0f3118 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11464,6 +11464,9 @@ "desktop.toolchains.global": "Global defaults", "desktop.toolchains.globalHelp": "Manage detected and manually added SDKs for all projects. Save writes to the application’s user settings; projects can override the default. Existing processes use the new SDK after restarting.", "desktop.toolchains.project": "Current project", + "desktop.build.optionChoiceDefault": "default", + "desktop.build.optionChoiceDefaultLabel": "{title} (default)", + "desktop.build.toggleOptionChoice": "Toggle {option}: {choice}", "desktop.runConfig.typeShell": "Shell Script", "desktop.runConfig.typePowerShell": "PowerShell Script", "desktop.runConfig.typeBatch": "Batch Script (cmd)", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 397aefb67e..c2e9c08bd9 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11464,6 +11464,9 @@ "desktop.toolchains.global": "全局默认", "desktop.toolchains.globalHelp": "统一管理自动识别和手动添加的 SDK,保存到应用的用户设置。项目可单独覆盖默认版本;已启动的进程需重启后使用新版本。", "desktop.toolchains.project": "当前项目", + "desktop.build.optionChoiceDefault": "默认", + "desktop.build.optionChoiceDefaultLabel": "{title}(默认)", + "desktop.build.toggleOptionChoice": "切换 {option}:{choice}", "desktop.runConfig.typeShell": "Shell 脚本", "desktop.runConfig.typePowerShell": "PowerShell 脚本", "desktop.runConfig.typeBatch": "批处理脚本(cmd)", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index b2777a958d..b5c8532cab 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -109368,6 +109368,34 @@ "platforms": [ "desktop" ] + }, + { + "id": "desktop.build.optionChoiceDefault", + "description": "Detail shown beside a build option choice in the Build tree that is active by default.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.build.optionChoiceDefaultLabel", + "description": "Label of a default-active build option choice in an option editor: {title}", + "platforms": [ + "desktop" + ], + "parameters": { + "title": "string" + } + }, + { + "id": "desktop.build.toggleOptionChoice", + "description": "Accessibility label of a checkbox that toggles one choice of a build option in the Build tree: {option}, {choice}", + "platforms": [ + "desktop" + ], + "parameters": { + "option": "string", + "choice": "string" + } } ] } diff --git a/shared/platform-feature-matrix/features/build-system-plugins.json b/shared/platform-feature-matrix/features/build-system-plugins.json index a980b71486..5f380cff03 100644 --- a/shared/platform-feature-matrix/features/build-system-plugins.json +++ b/shared/platform-feature-matrix/features/build-system-plugins.json @@ -34,6 +34,8 @@ "desktop/internal/core/build_options.go", "desktop/internal/workbench/build_options.go", "desktop/internal/workbench/build_ignored_paths_test.go", + "desktop/internal/workbench/build_tree_options_test.go", + "desktop/internal/core/build_options_test.go", "desktop/internal/buildprocess/batch.go", "desktop/internal/buildprocess/batch_test.go", "desktop/internal/workbench/build_command_output_test.go" @@ -70,6 +72,8 @@ "desktop/internal/core/build_options.go", "desktop/internal/workbench/build_options.go", "desktop/internal/workbench/build_ignored_paths_test.go", + "desktop/internal/workbench/build_tree_options_test.go", + "desktop/internal/core/build_options_test.go", "desktop/internal/buildprocess/batch.go", "desktop/internal/buildprocess/batch_test.go", "desktop/internal/workbench/build_command_output_test.go", @@ -78,7 +82,7 @@ ] }, "owner": "Extensions", - "verification": "macOS 已接入 static、command、hostIntegration、provider 四种模型来源:宿主向 Core 声明 buildSystems 与 buildProviders 能力,插件市场因此列出兼容的 API 3 声明式和 Provider 版本;Provider 进程按插件、构建系统和工作区各自独立,经各自 stdio 用 JSON-RPC(LSP 基础协议)与宿主通信,initialize 协商 capabilities.experimental.litheBuild 后宿主才经 lsp.buildRequest 发送 lithe/build/model、lithe/build/dependencies,回复交给 Core 解码;共享写法只复用同一插件的语言服务器会话;进程只在用户加载模型或依赖时启动,切换工作区、关闭项目窗口、停止执行模块、停用或更新插件、退出应用时停止;ExecutionFeatureGraph.stop 经 BuildSystemService.stop 同时回收已就绪和初始化中的 Provider,停止后的初始化完成也不得重新登记会话;状态写入插件状态目录;每个已启用的构建系统插件在打开工作区后各有一个右侧工具窗口(标题为 displayName、图标为 icon),不依赖识别结果,工作区没有对应工程时窗口内显示未检测到该构建系统,工具栏放运行、参数任务、刷新和 presentation=toolbar 的开关,树顶部是 presentation=tree 的勾选选项,工程下按 category(缺省按 group)分级列出任务,再列测试、目标和依赖;旧客户端内置的构建窗口与共享 Build 窗口已删除,Build Output 显示输出、诊断与测试结果。窗口恢复先激活所属插件模块,激活中的命令面板项禁用;参数任务遵守 workspace/project/target 作用范围与目标标签,模型或工作区变化后清除旧选择。隔离回归覆盖这些边界、窗口布局恢复及包内图标读取前后文件清单与字节不变;多实例的根目录选择器保留每个实例的模型候选和生效值,编辑多选时保留兄弟实例独有的已选值;显式清空按实例根持久化为空覆盖,检测、同步指纹、任务计划和语言服务器导入使用同一覆盖,兄弟编辑或重开不会恢复非空默认值,非空编辑清当前实例标记而共享编辑/重置清该选项全部标记;真实 Core、生产存储与服务回归核对最终 argv 和导入值;列表单选与多选支持 allowCustom 原生输入和移除已选自定义值,文本/文件/目录清空提交显式空字符串,只有重置删除覆盖。运行时准备后再等一次,覆盖等待期间失效。命令模型 run 配置尚未接入;buildProviders 2 已接入原生任务 lithe/build/execute,复用工作区进程并校验协议版本、进度/结果、取消/超时和旧结果隔离,真实安装包/工具工作流仍待验收,Provider 无操作系统级沙盒;Windows 宿主尚未调用 build.* 命令。自动化:cargo test -p lithe-core --lib build_systems、cargo test -p lithe-core --lib lsp、scripts/architecture/verify-shared-contracts.sh、./scripts/macos/test/test-macos.sh --filter 'BuildSystemToolWindowTests|RustBuildSystemOperationsTests|BuildSystemServiceTests|PluginMarketplaceServiceTests'。手动验证:安装 fixtures 中 build-static-file、build-command-stdout 形态的插件包,确认每个构建系统各出现一个工具窗口,列出工程、分级任务、选项和依赖,停用插件后窗口消失;执行任务与测试的 argv 与 build-plans.json 一致,停止与输出上限生效;JUnit 报告与 lineMatcher 诊断可跳转到源码;命令模型和项目内 Wrapper 只在用户点击加载或运行后启动;禁用插件后实例消失;Windows 接入后另需验证未信任工作区不启动任何模型命令或 Wrapper;build-provider 形态的自有 Provider 只在用户操作或工作区信任后启动、停用插件时停止,build-provider-language-server 形态复用语言服务器会话而不启动第二个进程;运行前后 app bundle 文件清单不变(scripts/desktop/verify/verify-runtime-bundle-immutability.sh)。;新路径选择使用 executableResolution 1 + settings 2,已发布 buildSystems 2 旧字段只作统一候选输入适配:MacBuildToolResolverTests 验证带空格绝对路径、权限与版本失败不回退,BuildSystemServiceTests 验证 Provider 失败不独立发现,RustBuildSystemOperationsTests 验证全局值接入。发布前需把独立仓库 sdk.lock.json 的宿主 pin 更新到包含该能力的已发布提交。;回归增加非法存储值不回默认、数组/priority/插入顺序与拒绝循环、宿主注入发现、空设置跳过和被动选择不探测;Language Server/Execution Provider 新清单语法尚未开放,Windows 不声明 executableResolution。;真实 Core + macOS resolver + BuildSystemService 组合回归覆盖前置 Runtime 缺失/版本不足时保留工具或后置 Runtime 的非空 setting 约束,Provider 不发送独立发现请求;全部设置为空时仍可回退。自定义 Runtime 先构造含所选目录的 PATH,再以同一环境探测与执行,同目录 helper 的带空格路径回归通过。;buildProviders 3 增加原生测试执行 lithe/build/test,筛选参数保持类型化,报告复用 JUnit/标准结果解析;旧协议明确拒绝测试,报告解析期间配置失效会取消操作并丢弃迟到结果。原生树已接入按需测试发现,Core 校验完整清单并保留模块身份,运行前重查当前清单;配置/源码/包变化、停用/重开使缓存或进行中的发现失效。Windows 工作流仍待验收。;buildProviders 4 应用目标准备接入原生 Build 树,构建进度在 Build Output 展示,验证后转交 RunService 解析工具与启动/停止应用;准备期间源码、选项、工作区或停用变化拒绝迟到启动,旧操作 ID 不得停止替换进程;Core 拒绝绝对可执行路径、越界目录/符号链接及超限参数环境。服务编排与调试尚未完成;真实插件/发行包和 Windows 工作流仍待验收。;Run v2 本地层显式保存 Provider 选择器,参数保持原始数组;无 generated.json 也能读回/显示,重复保存保留 ID/其他配置/项目环境;重启重新进入当前 Provider,停止与晚到结果按身份隔离。原生入口保存工作区文档后再准备,Run 窗口在未生成旧配置时仍显示 Provider 输出。;Agent 入口回归从真实本地配置启动,验证准备到进程退出保持公开操作 ID、准备中停止与重启重新准备,旧 ID 不能停止替换操作;Provider 与进程为可控替身,真实插件端到端验收仍待完成。;Core 的 Node/Java SDK 补齐协议 2/3/4 的处理器、版本准入与进度;无页面示例经真实 Core 验证非零构建退出码、精确筛选、运行前构建及准备计划、并行工作区、取消工具清理和完整包不变,另保留锁定旧契约的兼容场景与 TypeScript 调用方编译检查。SDK 尚未发布,Windows 验收仍待完成。 原生 Debug:运行声明引用同包适配器,点击 Build 树 Debug 或保存配置的 Debug 后先保存并构建,验证程序路径/参数/环境交给注册表;停止、源码或配置变化、模型重载、插件停用与工作区切换均丢弃过期结果,解码后的文件别名变化和不可执行文件在平台交接前拒绝。Node/Java SDK 进程的准备协议与 Core 解码有端到端覆盖;真实适配器、跨插件协作和 Windows 尚未验收。 正式包、完整 macOS UI 与 Windows 验收未完成,保持 partial/pending。 真实原生调试集成:公开 Node SDK Provider 用 Clang 编译 C 程序,经生产 macOS 会话、Core 准备、Registry 明确身份、生产 stdio 传输和 LLDB 命中源码断点、读取 main 栈帧、保留空格参数后继续并退出码 0;包 SHA-256/权限不变,所有本次进程回收。测试显式选择 SDK/工具,完整 UI、正式发行与 Windows 尚未验收,verification 保持 pending。 Build 树应用从文档保存阶段起持有同一可取消运行 ID;保存 gate 下启动新任务/测试或停止、切换工作区、选项/源码/模型/插件失效后,旧保存返回不得启动 Provider、替换新运行或清空新输出;保存失败不启动,成功后才准备。 原生视图隔离回归用真实 Core 与受控 Provider 数据检查深浅主题的测试发现、Debug 入口和 Run 输出;截图仅验证该视图状态,不代替完整发行包或 Windows 实机验收。 实例作用域:用同一工作区的两个独立根验证 Profiles、文件/目录、布尔与文本值独立持久化;编辑、清空或重置 A 不影响 B,重开后任务、静态运行入口、同步和语言导入读取相同根的配置;未声明作用域的插件保留共享行为。Windows 运行验收另行完成,保持 partial/pending。 作用域变更的旧 Build 偏好先复制并验证目标,再删除共享源;写入失败阻止默认配置发布并允许重试,已有实例值优先,暂未检测到根的空标记也迁移保留。 工具链候选通过真实 Core 与生产本地文档验证按实例选择工具,Provider 环境保留选中工具的环境变量与 PATH 且不转发无关测试凭据;被动导入不探测版本或运行 Wrapper,显式路径失败不能独立发现。Windows 不声明 executableResolution 2。 共享 Build 文档验证工作区/实例默认值、逐根覆盖和本机差异合并;重开和检测不改共享字节,重置本机值恢复继承,外部修改冲突或文档损坏明确失败并保留原始数据。 未选中的自定义候选仅在 allowCustom 选项中展示,不改变选择和模型;真实 Core、生产存储和服务回归通过,新增实例静态入口继承团队默认值。 协议 8 回归覆盖协商拒绝、随执行返回的报告、缺失/损坏失败、模块同名测试隔离、取消/配置变更后拒绝晚到解码,以及普通任务中的测试结果。Java/Node SDK 同步,正式发布尚未完成。 本机选项、逐根映射和空多选标记中存在非 Data 存储值时,检测失败并保留原始偏好,不得当缺失键发布默认值。 本机实例默认值继承、逐根覆盖与重置通过真实 Core 和生产存储验证,团队文档字节不变;本机默认值不进入资源复用。 正式发行组合仍待验证。 协议 10 接通带版本协商的类型化运行选项与服务/任务准备(Core、Swift、Node/Java SDK)。原生 Run/Start All 为每个 Provider 服务独立准备,配置 ABA/Stop/重置拒绝旧回复,已停进程输出不能覆盖新会话;Build 树按服务/任务类型发请求;停用和包更新在删除包前停止准备及进程,旧启动注册更新后不可再次使用。macOS 无调用者的旧内置构建桥和工程模型已删除;Windows 当前旧命令消费者、Core 旧实现和正式发行/完整 UI 验收仍待完成。 保存 Provider service/task 引用保留执行类型、稳定配置 ID 和参数,重开后按当前声明重验;独立准备至进程交接保留 Agent 操作身份。 服务所有者使用完整插件包身份;停用其中一个插件不会停止同名构建系统下另一插件的进程。preview 内存检测层保留 Provider 模型摘要,自动识别不写工作区。 Windows Build 选项编辑与 Agent 共用原生本机存储:开页只读,修改草稿后显式保存/恢复继承;隐藏重开保留草稿。团队/本机两层版本同时检查,冲突、关闭、插件撤销拒绝迟到写入。实例选择独立,工作区多选保留兄弟实例值和显式空选择;无关系统/根/记忆选项与团队文件字节保持。保存后重新检测并使旧模型失效。长选项/模型选择使用有界视口,不启动工具或 Provider。产品能力准入仍关闭,不能据此认定 Windows 迁移完成。 Viva 2026-11-09:Tests 工具窗口经 build.testPlan 计划工作区测试,宿主只启动 Core 展开的命令或 Provider 请求;报告由 Core build.decodeTestResults 解码,最终判定由 build.resolveTestRunOutcome 归约,宿主不解析报告格式、不按退出码自行判定。结果树按 suite/case 分组并有界虚拟化,失败项按解码出的 workspace-relative path/line 打开;停止、工作区关闭和过期结果按 run generation 丢弃。desktop/internal/workbench/tests_test.go 以隔离 fixture 插件、真实测试进程和 JUnit fixture 覆盖运行→解码→结果树→失败定位、停止取消和关闭项目停止运行;desktop/internal/workbench/tests_provider_test.go 用真实 Provider 进程(lithe/build/test 返回规范报告)覆盖 Provider 运行→Core 解码→结果树、Provider 取消和关闭项目停止 Provider 会话;原生窗口与 Windows 实机仍 pending。 Viva 聚合 Build 窗口:build_tree_test.go 的 TestBuildTreeNestsProjectsWithTheirFolders 覆盖父子项目按 parentID 嵌套、每个项目各自列出任务文件夹/依赖/Targets、单一根项目并入构建系统行、默认只展开选中实例且项目展开而文件夹/Targets/依赖折叠、用户展开/折叠的记忆、全部展开时依赖保持折叠、重新加载后保留展开状态;TestBuildTreeFilterKeepsMatchesUnderTheirProjects 覆盖筛选保留命中节点和通往它的项目与文件夹、构建系统名称/根目录/根项目命中时保留整棵树、筛选不触发加载、新筛选结果到达前沿用上一次结果;TestBuildTreeLoadsOpenModelsAFewAtATime 覆盖同时最多加载 4 个模型、失败和折叠的分组不加载;TestBuildTreeRowsChooseTheirBuildSystem 覆盖点击其他分组的行切换构建系统并能运行选中的目标;build_menus_test.go 覆盖从右键菜单运行目标后打开 Run 窗口的构建控制台;runconfig_browser_test.go 覆盖 Build 窗口中的运行配置列表:范围与计数、固定写入客户端存储而不写项目、分组折叠展开、双击运行和行内停止。运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestBuild|TestRunConfiguration' -count=1。真实插件组合与 Windows 实机仍待验收。 Viva 2026-11-14 任务范围:构建树的任务行不带项目,从树里运行时按任务声明的范围推断,不再把只能在项目上运行的任务当作工作区请求(Core 会报 plugin.build.invalidSelection)。模型任务用它所属的项目;声明任务依次用选中的目标、选中的项目(或目标所在的项目)、工作区;什么都没选时取构建根目录的项目或唯一的项目、唯一适用的目标;推断不出时提示先选择项目或目标,不发请求。选中项目时,任务分组只列出这个项目的模型任务。IDE API 仍按请求原样交给 Core 校验。build_tree_test.go 的 TestBuildTaskSelectionFitsDeclaredScopes、TestBuildTreeTasksRunOnTheScopeTheyDeclare 覆盖这些规则,后者在修复前失败(Project 为空);真实插件组合与 Windows 实机仍待验收。 Windows #2042:TestBuildModelLoadsFromPathOnlyBatchToolInUserProfiles 从带空格安装目录的 PATH-only .cmd 启动合成构建工具,校验空格/中文用户目录和参数完整性,经生产 commandModel 解码模型并记录完成终态。 通过现有 Windows CI 的 scripts/desktop/check.sh 运行;本机逐项计时报告覆盖这些合成场景,完整原生界面验收仍保持 pending。", + "verification": "macOS 已接入 static、command、hostIntegration、provider 四种模型来源:宿主向 Core 声明 buildSystems 与 buildProviders 能力,插件市场因此列出兼容的 API 3 声明式和 Provider 版本;Provider 进程按插件、构建系统和工作区各自独立,经各自 stdio 用 JSON-RPC(LSP 基础协议)与宿主通信,initialize 协商 capabilities.experimental.litheBuild 后宿主才经 lsp.buildRequest 发送 lithe/build/model、lithe/build/dependencies,回复交给 Core 解码;共享写法只复用同一插件的语言服务器会话;进程只在用户加载模型或依赖时启动,切换工作区、关闭项目窗口、停止执行模块、停用或更新插件、退出应用时停止;ExecutionFeatureGraph.stop 经 BuildSystemService.stop 同时回收已就绪和初始化中的 Provider,停止后的初始化完成也不得重新登记会话;状态写入插件状态目录;每个已启用的构建系统插件在打开工作区后各有一个右侧工具窗口(标题为 displayName、图标为 icon),不依赖识别结果,工作区没有对应工程时窗口内显示未检测到该构建系统,工具栏放运行、参数任务、刷新和 presentation=toolbar 的开关,树顶部是 presentation=tree 的勾选选项,工程下按 category(缺省按 group)分级列出任务,再列测试、目标和依赖;旧客户端内置的构建窗口与共享 Build 窗口已删除,Build Output 显示输出、诊断与测试结果。窗口恢复先激活所属插件模块,激活中的命令面板项禁用;参数任务遵守 workspace/project/target 作用范围与目标标签,模型或工作区变化后清除旧选择。隔离回归覆盖这些边界、窗口布局恢复及包内图标读取前后文件清单与字节不变;多实例的根目录选择器保留每个实例的模型候选和生效值,编辑多选时保留兄弟实例独有的已选值;显式清空按实例根持久化为空覆盖,检测、同步指纹、任务计划和语言服务器导入使用同一覆盖,兄弟编辑或重开不会恢复非空默认值,非空编辑清当前实例标记而共享编辑/重置清该选项全部标记;真实 Core、生产存储与服务回归核对最终 argv 和导入值;列表单选与多选支持 allowCustom 原生输入和移除已选自定义值,文本/文件/目录清空提交显式空字符串,只有重置删除覆盖。运行时准备后再等一次,覆盖等待期间失效。命令模型 run 配置尚未接入;buildProviders 2 已接入原生任务 lithe/build/execute,复用工作区进程并校验协议版本、进度/结果、取消/超时和旧结果隔离,真实安装包/工具工作流仍待验收,Provider 无操作系统级沙盒;Windows 宿主尚未调用 build.* 命令。自动化:cargo test -p lithe-core --lib build_systems、cargo test -p lithe-core --lib lsp、scripts/architecture/verify-shared-contracts.sh、./scripts/macos/test/test-macos.sh --filter 'BuildSystemToolWindowTests|RustBuildSystemOperationsTests|BuildSystemServiceTests|PluginMarketplaceServiceTests'。手动验证:安装 fixtures 中 build-static-file、build-command-stdout 形态的插件包,确认每个构建系统各出现一个工具窗口,列出工程、分级任务、选项和依赖,停用插件后窗口消失;执行任务与测试的 argv 与 build-plans.json 一致,停止与输出上限生效;JUnit 报告与 lineMatcher 诊断可跳转到源码;命令模型和项目内 Wrapper 只在用户点击加载或运行后启动;禁用插件后实例消失;Windows 接入后另需验证未信任工作区不启动任何模型命令或 Wrapper;build-provider 形态的自有 Provider 只在用户操作或工作区信任后启动、停用插件时停止,build-provider-language-server 形态复用语言服务器会话而不启动第二个进程;运行前后 app bundle 文件清单不变(scripts/desktop/verify/verify-runtime-bundle-immutability.sh)。;新路径选择使用 executableResolution 1 + settings 2,已发布 buildSystems 2 旧字段只作统一候选输入适配:MacBuildToolResolverTests 验证带空格绝对路径、权限与版本失败不回退,BuildSystemServiceTests 验证 Provider 失败不独立发现,RustBuildSystemOperationsTests 验证全局值接入。发布前需把独立仓库 sdk.lock.json 的宿主 pin 更新到包含该能力的已发布提交。;回归增加非法存储值不回默认、数组/priority/插入顺序与拒绝循环、宿主注入发现、空设置跳过和被动选择不探测;Language Server/Execution Provider 新清单语法尚未开放,Windows 不声明 executableResolution。;真实 Core + macOS resolver + BuildSystemService 组合回归覆盖前置 Runtime 缺失/版本不足时保留工具或后置 Runtime 的非空 setting 约束,Provider 不发送独立发现请求;全部设置为空时仍可回退。自定义 Runtime 先构造含所选目录的 PATH,再以同一环境探测与执行,同目录 helper 的带空格路径回归通过。;buildProviders 3 增加原生测试执行 lithe/build/test,筛选参数保持类型化,报告复用 JUnit/标准结果解析;旧协议明确拒绝测试,报告解析期间配置失效会取消操作并丢弃迟到结果。原生树已接入按需测试发现,Core 校验完整清单并保留模块身份,运行前重查当前清单;配置/源码/包变化、停用/重开使缓存或进行中的发现失效。Windows 工作流仍待验收。;buildProviders 4 应用目标准备接入原生 Build 树,构建进度在 Build Output 展示,验证后转交 RunService 解析工具与启动/停止应用;准备期间源码、选项、工作区或停用变化拒绝迟到启动,旧操作 ID 不得停止替换进程;Core 拒绝绝对可执行路径、越界目录/符号链接及超限参数环境。服务编排与调试尚未完成;真实插件/发行包和 Windows 工作流仍待验收。;Run v2 本地层显式保存 Provider 选择器,参数保持原始数组;无 generated.json 也能读回/显示,重复保存保留 ID/其他配置/项目环境;重启重新进入当前 Provider,停止与晚到结果按身份隔离。原生入口保存工作区文档后再准备,Run 窗口在未生成旧配置时仍显示 Provider 输出。;Agent 入口回归从真实本地配置启动,验证准备到进程退出保持公开操作 ID、准备中停止与重启重新准备,旧 ID 不能停止替换操作;Provider 与进程为可控替身,真实插件端到端验收仍待完成。;Core 的 Node/Java SDK 补齐协议 2/3/4 的处理器、版本准入与进度;无页面示例经真实 Core 验证非零构建退出码、精确筛选、运行前构建及准备计划、并行工作区、取消工具清理和完整包不变,另保留锁定旧契约的兼容场景与 TypeScript 调用方编译检查。SDK 尚未发布,Windows 验收仍待完成。 原生 Debug:运行声明引用同包适配器,点击 Build 树 Debug 或保存配置的 Debug 后先保存并构建,验证程序路径/参数/环境交给注册表;停止、源码或配置变化、模型重载、插件停用与工作区切换均丢弃过期结果,解码后的文件别名变化和不可执行文件在平台交接前拒绝。Node/Java SDK 进程的准备协议与 Core 解码有端到端覆盖;真实适配器、跨插件协作和 Windows 尚未验收。 正式包、完整 macOS UI 与 Windows 验收未完成,保持 partial/pending。 真实原生调试集成:公开 Node SDK Provider 用 Clang 编译 C 程序,经生产 macOS 会话、Core 准备、Registry 明确身份、生产 stdio 传输和 LLDB 命中源码断点、读取 main 栈帧、保留空格参数后继续并退出码 0;包 SHA-256/权限不变,所有本次进程回收。测试显式选择 SDK/工具,完整 UI、正式发行与 Windows 尚未验收,verification 保持 pending。 Build 树应用从文档保存阶段起持有同一可取消运行 ID;保存 gate 下启动新任务/测试或停止、切换工作区、选项/源码/模型/插件失效后,旧保存返回不得启动 Provider、替换新运行或清空新输出;保存失败不启动,成功后才准备。 原生视图隔离回归用真实 Core 与受控 Provider 数据检查深浅主题的测试发现、Debug 入口和 Run 输出;截图仅验证该视图状态,不代替完整发行包或 Windows 实机验收。 实例作用域:用同一工作区的两个独立根验证 Profiles、文件/目录、布尔与文本值独立持久化;编辑、清空或重置 A 不影响 B,重开后任务、静态运行入口、同步和语言导入读取相同根的配置;未声明作用域的插件保留共享行为。Windows 运行验收另行完成,保持 partial/pending。 作用域变更的旧 Build 偏好先复制并验证目标,再删除共享源;写入失败阻止默认配置发布并允许重试,已有实例值优先,暂未检测到根的空标记也迁移保留。 工具链候选通过真实 Core 与生产本地文档验证按实例选择工具,Provider 环境保留选中工具的环境变量与 PATH 且不转发无关测试凭据;被动导入不探测版本或运行 Wrapper,显式路径失败不能独立发现。Windows 不声明 executableResolution 2。 共享 Build 文档验证工作区/实例默认值、逐根覆盖和本机差异合并;重开和检测不改共享字节,重置本机值恢复继承,外部修改冲突或文档损坏明确失败并保留原始数据。 未选中的自定义候选仅在 allowCustom 选项中展示,不改变选择和模型;真实 Core、生产存储和服务回归通过,新增实例静态入口继承团队默认值。 协议 8 回归覆盖协商拒绝、随执行返回的报告、缺失/损坏失败、模块同名测试隔离、取消/配置变更后拒绝晚到解码,以及普通任务中的测试结果。Java/Node SDK 同步,正式发布尚未完成。 本机选项、逐根映射和空多选标记中存在非 Data 存储值时,检测失败并保留原始偏好,不得当缺失键发布默认值。 本机实例默认值继承、逐根覆盖与重置通过真实 Core 和生产存储验证,团队文档字节不变;本机默认值不进入资源复用。 正式发行组合仍待验证。 协议 10 接通带版本协商的类型化运行选项与服务/任务准备(Core、Swift、Node/Java SDK)。原生 Run/Start All 为每个 Provider 服务独立准备,配置 ABA/Stop/重置拒绝旧回复,已停进程输出不能覆盖新会话;Build 树按服务/任务类型发请求;停用和包更新在删除包前停止准备及进程,旧启动注册更新后不可再次使用。macOS 无调用者的旧内置构建桥和工程模型已删除;Windows 当前旧命令消费者、Core 旧实现和正式发行/完整 UI 验收仍待完成。 保存 Provider service/task 引用保留执行类型、稳定配置 ID 和参数,重开后按当前声明重验;独立准备至进程交接保留 Agent 操作身份。 服务所有者使用完整插件包身份;停用其中一个插件不会停止同名构建系统下另一插件的进程。preview 内存检测层保留 Provider 模型摘要,自动识别不写工作区。 Windows Build 选项编辑与 Agent 共用原生本机存储:开页只读,修改草稿后显式保存/恢复继承;隐藏重开保留草稿。团队/本机两层版本同时检查,冲突、关闭、插件撤销拒绝迟到写入。实例选择独立,工作区多选保留兄弟实例值和显式空选择;无关系统/根/记忆选项与团队文件字节保持。保存后重新检测并使旧模型失效。长选项/模型选择使用有界视口,不启动工具或 Provider。产品能力准入仍关闭,不能据此认定 Windows 迁移完成。 Viva 2026-11-09:Tests 工具窗口经 build.testPlan 计划工作区测试,宿主只启动 Core 展开的命令或 Provider 请求;报告由 Core build.decodeTestResults 解码,最终判定由 build.resolveTestRunOutcome 归约,宿主不解析报告格式、不按退出码自行判定。结果树按 suite/case 分组并有界虚拟化,失败项按解码出的 workspace-relative path/line 打开;停止、工作区关闭和过期结果按 run generation 丢弃。desktop/internal/workbench/tests_test.go 以隔离 fixture 插件、真实测试进程和 JUnit fixture 覆盖运行→解码→结果树→失败定位、停止取消和关闭项目停止运行;desktop/internal/workbench/tests_provider_test.go 用真实 Provider 进程(lithe/build/test 返回规范报告)覆盖 Provider 运行→Core 解码→结果树、Provider 取消和关闭项目停止 Provider 会话;原生窗口与 Windows 实机仍 pending。 Viva 聚合 Build 窗口:build_tree_test.go 的 TestBuildTreeNestsProjectsWithTheirFolders 覆盖父子项目按 parentID 嵌套、每个项目各自列出任务文件夹/依赖/Targets、单一根项目并入构建系统行、默认只展开选中实例且项目展开而文件夹/Targets/依赖折叠、用户展开/折叠的记忆、全部展开时依赖保持折叠、重新加载后保留展开状态;TestBuildTreeFilterKeepsMatchesUnderTheirProjects 覆盖筛选保留命中节点和通往它的项目与文件夹、构建系统名称/根目录/根项目命中时保留整棵树、筛选不触发加载、新筛选结果到达前沿用上一次结果;TestBuildTreeLoadsOpenModelsAFewAtATime 覆盖同时最多加载 4 个模型、失败和折叠的分组不加载;TestBuildTreeRowsChooseTheirBuildSystem 覆盖点击其他分组的行切换构建系统并能运行选中的目标;build_menus_test.go 覆盖从右键菜单运行目标后打开 Run 窗口的构建控制台;runconfig_browser_test.go 覆盖 Build 窗口中的运行配置列表:范围与计数、固定写入客户端存储而不写项目、分组折叠展开、双击运行和行内停止。运行 scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestBuild|TestRunConfiguration' -count=1。真实插件组合与 Windows 实机仍待验收。 Viva 2026-11-14 任务范围:构建树的任务行不带项目,从树里运行时按任务声明的范围推断,不再把只能在项目上运行的任务当作工作区请求(Core 会报 plugin.build.invalidSelection)。模型任务用它所属的项目;声明任务依次用选中的目标、选中的项目(或目标所在的项目)、工作区;什么都没选时取构建根目录的项目或唯一的项目、唯一适用的目标;推断不出时提示先选择项目或目标,不发请求。选中项目时,任务分组只列出这个项目的模型任务。IDE API 仍按请求原样交给 Core 校验。build_tree_test.go 的 TestBuildTaskSelectionFitsDeclaredScopes、TestBuildTreeTasksRunOnTheScopeTheyDeclare 覆盖这些规则,后者在修复前失败(Project 为空);真实插件组合与 Windows 实机仍待验收。 Windows #2042:TestBuildModelLoadsFromPathOnlyBatchToolInUserProfiles 从带空格安装目录的 PATH-only .cmd 启动合成构建工具,校验空格/中文用户目录和参数完整性,经生产 commandModel 解码模型并记录完成终态。 通过现有 Windows CI 的 scripts/desktop/check.sh 运行;本机逐项计时报告覆盖这些合成场景,完整原生界面验收仍保持 pending。 Viva 2026-11-18 树上构建选项:模型报告本次实际激活的选项时,Core 按加载模型使用的选项指纹回显勾选;恢复默认会保留其他构建根的值及明确清空状态,也会考虑本机实例默认值。运行配置编辑器继承构建实例的选项,显式保存的选项在启动规划时覆盖实例对应的键。presentation=tree 的多选选项由 Core build.modelTree 排布在构建系统树顶部,折叠时显示当前生效候选摘要,展开后列出复选框与模型的默认激活标记(defaultActive);模型通过 optionDefaults 与 optionExcludePrefixes(或声明的 excludePrefix)报告默认激活项与取消前缀,勾选或取消经 Core 编码为本机构建选项(含取消默认激活项的前缀项、回到默认集合时清空覆盖)并触发重新检测,筛选状态下切换仍保留隐藏的已勾选项;构建选项对话框与运行配置编辑器通过 build.resolveOptions 共用同一模型候选与默认状态。自动化:core 包 TestBuildOptionDefaultsAndExclusionsRoundTripThroughStorageAndTree、workbench 包 TestBuildTreePresentsAndTogglesModelOptionChoices 与 TestBuildAndRunOptionEditorsResolveAndSaveModelChoices。 构建选项初次读取时显示加载状态,禁用字段和保存,仍可取消;读取完成后才允许修改并保存。macOS 的 TestBuildOptionsWaitForResolutionBeforeEditAndSave 使用可控解析请求验证加载前后的实际操作及保存回读。", "notes": "Viva 已接入 buildSystems 1 / buildProviders 1–2 的纵向切片:Build 工具窗口用 Core 检测实例、加载 provider 模型或执行 command 模型,列出项目、目标、command/provider 任务;command 任务按 build.invocationPlan 的候选顺序解析并做版本检查,provider 任务经 lsp.buildRequest 执行,共享 provider 复用同插件语言服务器;输出有界、支持停止,关闭项目回收 provider 与进程树。GitHub Release 原始包按契约 / 目录布局发布,当前 pluginpkg 只接受解压根目录的 plugin.json,安装器布局问题单独记录。未声明 buildProviders 4、settings、executableResolution、测试与 Debug:工具链运行引用、需设置插件、测试/诊断面板仍缺失。Windows Job Object 已实现并交叉编译,但无实机验证,保持 pending。Viva 客户端尚未逐项盘点;legacy 是迁移前基线,不代表当前实现。 Viva 运行设置接线:build.invocationPlan 携带真实全局插件层,显式无效工具路径直接失败并保留自动候选顺序;有效显式工具父目录进入 PATH。Provider 启动携带独立全局/项目层,工作区 URI 由 Core 生成。此接线不表示通用设置界面、原生配置页或完整 Build 协议迁移已验收。 Viva 2026-11-14:构建系统改为一个聚合的 Build 工具窗口,放在右侧工具栏上方(与 IDEA 的位置一致),不再为每个实例开标签页。窗口里是一棵树,每个检测到的构建系统实例是一个分组,显示构建系统名称、徽标和相对根目录;分组下是项目、目标、任务、测试和依赖。默认只展开当前选中的实例,用户手动展开或折叠过的分组保持该状态;依赖分组默认折叠,因为加载依赖要运行构建工具。筛选框按分组名称、根目录和行名称过滤,匹配的行固定展开在所属分组下;筛选只读已加载的模型,不会触发加载。展开的分组按需加载模型,同时最多加载 4 个,加载失败的不会自动重试,折叠的分组不加载。点击其他分组的行会切换到该构建系统并选中这一行,工具栏的运行按钮会执行选中的目标或任务。运行配置列表放在右侧 Build 窗口顶部,和下面的构建树之间有可拖动的分隔条,按范围、固定和执行类型筛选,双击运行、行内按钮停止。目标的名称以其路径结尾时(如包的导入路径以所在目录结尾),目标行只显示路径,鼠标悬停显示完整名称;其他目标仍显示名称并在旁边显示路径,筛选仍按名称和路径匹配。底部原先的 Build 窗口改为 Run 窗口,只显示运行输出:构建控制台,以及插件启动的运行各自的标签页;Build 窗口发起的任务或运行会打开 Run 窗口并切到构建控制台。 Viva 2026-11-14:参照 IDEA 的 Make 窗口,每个任务和有运行入口的目标行首常驻绿色运行按钮,不必先选中,点一下就选中该行并运行,构建进行中按钮变暗不可点;没有运行入口的目标和项目保留类型图标,调试按钮仍只在选中的行上。名称与路径放不下时路径先省略、名称以省略号结尾,悬停提示显示完整名称和路径(只显示路径的目标显示完整名称);依赖标题旁的 ⓘ 说明依赖树在第一次展开时才由构建工具读取,以及何时重新读取。自动化:TestBuildTreeRunMarksRunTheirRowsAtOnce;截图 docs/assets/build-panels/build-go-targets-*.png。 Viva 2026-11-14:Core 固定版本升到 Lithe-core-rust#33,构建检测和自动运行项发现跳过被 Git 忽略的目录(工作区内的 .gitignore 与仓库的 info/exclude),代理工作树、生成目录和本地副本不再被列成构建系统,同一模块不再出现两遍;Core 自动化:tests::build_systems::detection_skips_directories_git_ignores。 Viva 2026-11-14:Core 固定版本升到 Lithe-core-rust#35,构建选项新增“检测”分区的忽略路径:一行一条 .gitignore 写法的规则,相对项目根目录、只匹配文件夹,默认忽略所有以 . 开头的文件夹(如 .claude/worktrees),以 ! 开头的规则可以让文件夹(包括被 Git 忽略的)重新参与检测。列表按本机、团队文件 .lithe/build/options.json、默认值的顺序取第一个,对话框写明当前来源;修改只保存在本机,恢复默认删除本机列表,保存后重新检测。Build 窗口标题栏的齿轮打开只含忽略路径的构建选项,构建系统行的齿轮和右键菜单在忽略路径下方显示该构建系统的选项;Core 拒绝的规则标出所在行,对话框保持打开、不写入。自动化:TestBuildOptionsIgnoredPathsAreSavedOnThisMachineAndRestored、TestBuildOptionsNameTheLineOfARefusedIgnoredPath、core 包 TestBuildIgnoredPathsResolveFromTheLayersAndEditTheLocalList、TestBuildDetectSkipsTheIgnoredPaths。 Viva 2026-11-16(#2032):Windows 上由宿主启动的 .cmd/.bat(构建工具、版本探测、Run、Tests 共用 buildprocess)改为宿主自己构造 cmd.exe /d /c \"\"脚本\" 参数\" 命令行,参数按 BatBadBut 修复后的规则转义;此前脚本目录和参数都含空格时 cmd 去掉首尾引号,Maven 模型加载报 C:\\Program 不是命令并以 exit 1 失败。模型和依赖命令失败时,错误附带工具最后 12 行输出(去掉终端控制符),构建树行悬停显示全文。Windows 11 ARM64 来宾(x64 仿真)实机:TestBatchFileUnderASpacedDirectoryReceivesItsArguments 修复前失败、修复后通过,buildprocess 全部用例通过;同一来宾用真实 mvn.cmd 跑模型命令,修复前 exit 1,修复后写出模型。完整客户端界面验收尚未执行,状态保持 pending。 Viva 2026-11-16:Build 窗口的树参照 IntelliJ IDEA 的 Maven 工具窗口改为按父子项目嵌套,对所有构建工具一致:树由 Core 新增的 build.modelTree 按清单和模型排布(Lithe-core-rust feat/build-model-tree),宿主只负责展开状态、绘制和交互。每个项目依次列出按 category(没有时按 group)分好的任务文件夹、依赖节点、带目标级任务的 Targets 文件夹,然后是子项目;子项目按模型的 parentID 嵌套(模型没写父项目时,Core 解码模型已按路径包含关系补上)。有 project 作用域的声明任务出现在每个项目里,只有 workspace 作用域或需要用户参数的任务、工作区依赖和 Discovered Tests 只在构建系统下出现一次。模型只有一个根项目时,构建系统行直接代表这个项目(行上显示项目名,右键是项目菜单)。默认展开项目,任务文件夹、Targets、Discovered Tests 和依赖折叠;全部展开不会打开依赖。筛选由 Core 标出命中节点,保留命中节点的全部内容和通往它的项目与文件夹,构建系统名称、根目录或根项目命中时保留整棵树;排布在后台进行,模型、筛选或语言变化时重新排布,旧结果按模型版本和检测代次丢弃。多仓库工作区不再把上百个任务平铺在一层。文件夹标题来自插件声明的 category,由插件负责翻译;宿主只翻译 group 的 7 个标题。行图标改用 IntelliJ New UI 中同类节点的图标(Apache-2.0,深浅两套,与 Project 树一样是 16 点):任务文件夹是带齿轮的文件夹(IDEA Maven/Gradle 任务文件夹的 taskGroup),依赖是带书的文件夹、依赖项是书,项目是模块文件夹,没有运行入口的任务是齿轮、目标是构件,Targets 是普通文件夹,Discovered Tests 是测试文件夹。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",