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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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`。
83 changes: 54 additions & 29 deletions desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -482,6 +499,8 @@ type BuildModelTree struct {

// The kinds of a BuildTreeNode.
const (
BuildTreeOption = "option"
BuildTreeOptionChoice = "optionChoice"
BuildTreeProject = "project"
BuildTreeFolder = "folder"
BuildTreeTask = "task"
Expand All @@ -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.
Expand Down
130 changes: 108 additions & 22 deletions desktop/internal/core/build_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
Loading
Loading