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 @@ -19,7 +19,7 @@
| 外观与行为 | 应用本身的外观、编辑器显示与输入、快捷键,以及应用自身网络请求的代理设置 |
| 插件 | 插件的安装、启用和插件自带的选项;一级页面,不属于任何分组 |
| 版本控制 | Git、SVN 等版本控制系统的配置 |
| 构建、执行、部署 | 分组本身是目录页;固定子页“工具链”(插件声明的全部工具,包括项目 JDK)、“调试器”(单步过滤等调试设置)和“控制台”(程序输出编码);插件声明的构建工具页、编译器页按种类排在后面,以及运行配置、服务运行和框架、构建工具注入的配置 |
| 构建、执行、部署 | 分组本身是目录页;固定子页“工具链”(插件声明的全部工具,包括项目 JDK)、“调试器”(单步过滤等调试设置)和“控制台”(程序输出编码)和“可信位置”(本机可信文件夹列表,与工具链共用偏好目录的 toolchains/global.json,2026-11-21 由 #2207 加入);插件声明的构建工具页、编译器页按种类排在后面,以及运行配置、服务运行和框架、构建工具注入的配置 |
| 语言与框架 | 没有固定子页;插件声明的语言页、框架页(语言服务开关、Spring Boot 等框架配置)排在下面,有子页时它成为分组,分组本身是目录页 |
| 工具 | 终端、搜索(搜索和替换文件大小预算)等通用工具;插件带来的专用工具可以放进对应工具页。日志与诊断不属于设置,它是独立的日志窗口 |
| AI | 与 AI 有关的全部配置:MCP、Skill、全局指令、AI 提交信息、Agents、AI 服务商 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Maven 这类命令来源的模型会运行 `mvn`,pom 里的扩展和插件就
- **先问再打开。** `openProjectHere` 先读信任(`toolchain.ReadWorkspaceTrust`),再决定直接打开、以安全模式打开或提问;选“不打开”时当前项目原样保留,新开的项目页签直接关掉。“以安全模式预览”记成不信任,下次打开不再问,和 IDEA 的 `setProjectTrusted(false)` 相同。
- **安全模式下的动作先问。** `startRun`、`runBuildTask`、`startTests`、运行当前文件和重新加载模型前,安全模式会弹出“信任项目?/ 保持安全模式”。信任保存成功后才执行原动作;保存失败按未信任处理。自动加载的模型不运行,构建窗口在模型位置显示安全模式说明。
- **设置页和对话框是同一份记录。** 构建设置里撤销或授予工作区信任后,工作台重新读取信任并应用;离开安全模式时重新加载被跳过的模型和失败的语言服务器。
- **可信位置有自己的设置页(#2207)。** 设置 › 构建、执行、部署 › 可信位置列出 Core 读出的 `trustedLocations`。增删都是草稿:每项改动单独交给 Core 的 `toolchains.editCatalog`(字段 `trustedLocations`)预演,页面显示 Core 算出的结果;Core 拒绝根目录(`plugin.toolchain.rootLocation`)和超过 256 项(`plugin.toolchain.trustListFull`),拒绝只丢掉这一项改动。“撤销修改”去掉该文件夹的全部改动,而不是追加一项反向改动,否则恢复的文件夹会跑到列表末尾。底栏应用时先写工具链、再写可信位置;两边共用偏好目录的 `toolchains/global.json`,任一方写入后把另一方读到的内容标记为过期,过期的列表在写入前先重新读取,改动相互抵消时不写文件。写入成功后工作台重试失败的语言服务器并重新判定当前项目的信任。

## 考虑过的备选方案

Expand All @@ -28,16 +29,18 @@ Maven 这类命令来源的模型会运行 `mvn`,pom 里的扩展和插件就
## 后果

- 测试 harness 默认把所有工作区当作信任(`Options.trustEveryWorkspace`,相当于 IDEA 单元测试模式关闭信任检查);测试信任流程的用例要显式关掉。
- 语言服务器和 Git 在安全模式下仍照常启动(#2208),可信位置也还没有独立的设置页(#2207)。
- 安全模式下不启动会运行项目代码的语言服务器和 Git 由 #2208 处理;远程工作区的可信条目(#2231 的 S04)还没有界面,等远程连接界面一起做。
- 通过 IDE API 发起的构建任务在安全模式下会被拒绝,同时提示用户信任。

## 验证

- `desktop/internal/workbench/workspace_trust_test.go`:信任后打开并记住、勾选父文件夹后同级项目也被信任、不打开不留下任何状态、安全模式不加载模型且动作先问、提示条信任后消失。
- Core 的 `rust/crates/toolchain` 和 `rust/crates/build` 测试,以及 `build-plans.json`、`toolchain-global-catalog.json` 两份 fixture 覆盖状态判定和计划拒绝。
- `desktop/internal/toolchain/trusted_locations_test.go`(真实 Core):预演不写文件、保存后嵌套项目被信任、过期列表写入被拒、相互抵消的改动不写文件、根目录被拒并指出是哪一项。`desktop/internal/settingswindow/trusted_locations_view_test.go`:草稿标记与撤销、拒绝只丢一项、应用前重读过期列表、写入后回读失败时重新读取。截图见 `docs/assets/trusted-locations/`。

```bash
scripts/desktop/desktop-go.sh test ./internal/workbench/ -run 'TestTrusting|TestDontOpen|TestSafeMode'
scripts/desktop/desktop-go.sh test ./internal/toolchain ./internal/settingswindow -run 'TrustedLocations'
```

## 适用范围
Expand Down
30 changes: 27 additions & 3 deletions desktop/internal/core/toolchain_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import (
)

// ToolchainCatalog contains registrations and workspace trust owned by this machine, independent of project pins.
// DistrustedWorkspaces are the workspaces the user chose to keep in safe mode, and
// TrustedLocations the folders whose every workspace is trusted unless distrusted itself; Core
// normalizes both for the platform and never lists a filesystem root as a location.
type ToolchainCatalog struct {
Version int `json:"version"`
Tools map[string]ToolchainCatalogEntry `json:"tools"`
TrustedWorkspaces []string `json:"trustedWorkspaces,omitempty"`
Version int `json:"version"`
Tools map[string]ToolchainCatalogEntry `json:"tools"`
TrustedWorkspaces []string `json:"trustedWorkspaces,omitempty"`
DistrustedWorkspaces []string `json:"distrustedWorkspaces,omitempty"`
TrustedLocations []string `json:"trustedLocations,omitempty"`
}

type ToolchainCatalogEntry struct {
Expand Down Expand Up @@ -91,3 +96,22 @@ func (c *Client) EditToolchainWorkspaceTrust(ctx context.Context, document *stri
WorkspaceTrust ToolchainWorkspaceTrustEdit `json:"workspaceTrust"`
}{document, platform, trust})
}

// ToolchainTrustedLocationsEdit adds folders to the trusted locations and removes others. Core
// matches folders by the platform's path identity and refuses a filesystem root
// (plugin.toolchain.rootLocation), a folder both added and removed (invalidDocument) and a
// list past its bound (plugin.toolchain.trustListFull).
type ToolchainTrustedLocationsEdit struct {
Add []string `json:"add,omitempty"`
Remove []string `json:"remove,omitempty"`
}

// EditToolchainTrustedLocations applies edit to document and returns the result. It writes
// nothing: the caller publishes the document against the bytes it read.
func (c *Client) EditToolchainTrustedLocations(ctx context.Context, document *string, platform string, edit ToolchainTrustedLocationsEdit) (ToolchainCatalogPublication, error) {
return settingsSurfaceResult[ToolchainCatalogPublication](ctx, c, "toolchains.editCatalog", "edit", struct {
Document *string `json:"document"`
Platform string `json:"platform"`
TrustedLocations ToolchainTrustedLocationsEdit `json:"trustedLocations"`
}{document, platform, edit})
}
1 change: 1 addition & 0 deletions desktop/internal/i18n/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ type SettingsMessages struct {
Toolchains string
Debuggers string
Console string
TrustedLocations string
Languages string
Tools string
SearchPage string
Expand Down
1 change: 1 addition & 0 deletions desktop/internal/i18n/settings_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func settingsMessages(language Language) SettingsMessages {
Toolchains: Shared(language, "desktop.toolchains.title"),
Debuggers: Shared(language, "desktop.buildSettings.debuggers"),
Console: Shared(language, "desktop.consoleSettings.title"),
TrustedLocations: Shared(language, "desktop.trustedLocations.title"),
Languages: Shared(language, "settings.groups.languages"),
Tools: Shared(language, "settings.groups.tools"),
SearchPage: Shared(language, "desktop.search.settings.title"),
Expand Down
30 changes: 30 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions desktop/internal/settingswindow/build_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (

// The Build pages keep their edits as drafts until the footer's Apply or OK writes them, as
// in docs/design/build-execution-settings.html: the machine's toolchain defaults, then the
// project's, then each debugger's stepping policy. One request is out at a time, because the
// toolchain scopes share one writer and every write is read back before the next. A failed
// write stops the rest and keeps the window open with its drafts; Cancel writes nothing.
// project's, then the trusted locations, then each debugger's stepping policy. One request is
// out at a time, because the toolchain scopes and the trusted locations share one writer and
// every write is read back before the next. A failed write stops the rest and keeps the window
// open with its drafts; Cancel writes nothing.

const (
applyToolchain = "toolchain:"
applyLocations = "locations:"
applyStepping = "stepping:"
)

Expand Down Expand Up @@ -45,6 +47,10 @@ func (w *window) buildDrafts(language i18n.Language) (count int, targets []strin
targets = append(targets, i18n.Shared(language, "desktop.buildSettings.targetProject"))
}
}
if n := t.locations.drafts(); n > 0 {
count += n
targets = append(targets, i18n.Shared(language, "desktop.trustedLocations.target"))
}
}
if pending := w.steppingPending(); len(pending) > 0 {
count += len(pending)
Expand All @@ -68,6 +74,12 @@ func (w *window) startApply(close bool) {
a.steps = append(a.steps, applyToolchain+name)
}
}
if t.locations.drafts() > 0 {
// The apply reads a stale list again before it writes; a failed read stops it, and
// the next apply tries the read again.
t.locations.readFailed = nil
a.steps = append(a.steps, applyLocations)
}
}
for _, id := range w.steppingPending() {
a.steps = append(a.steps, applyStepping+id)
Expand Down Expand Up @@ -105,6 +117,14 @@ func (w *window) advanceApply(toolchainFailed error, stepping steppingResult) {
if w.toolchains.saving {
return
}
case a.running == applyLocations:
if toolchainFailed != nil {
w.stopApply(toolchainFailed)
return
}
if w.toolchains.locations.saving {
return
}
case strings.HasPrefix(a.running, applyStepping):
if !stepping.done {
return
Expand All @@ -128,6 +148,28 @@ func (w *window) advanceApply(toolchainFailed error, stepping steppingResult) {
}
continue
}
if step == applyLocations {
locations := w.toolchains.locations
if w.toolchains.busy() {
return
}
if !locations.loaded || locations.stale {
// An earlier write in this apply changed the catalog file: read it again and
// write the changes against what it holds now.
if locations.readFailed != nil {
w.stopApply(locations.readFailed)
return
}
locations.beginLoad()
return
}
a.steps = a.steps[1:]
if locations.beginSave() {
a.running = step
return
}
continue
}
a.steps = a.steps[1:]
if w.beginSteppingApply(strings.TrimPrefix(step, applyStepping)) {
a.running = step
Expand Down
16 changes: 16 additions & 0 deletions desktop/internal/settingswindow/build_directory_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (w *window) buildPage(c ui.C) {
if t := w.toolchains; t.available() {
t.ensureLoaded()
t.requestView()
t.locations.ensureLoaded()
}
if s := w.stepping; s.available() {
s.beginLoad()
Expand Down Expand Up @@ -230,6 +231,21 @@ func (w *window) directoryEntries(language i18n.Language) []directoryEntry {
desc: i18n.SharedFormat(language, "desktop.consoleSettings.directory", map[string]string{"encoding": w.consoleEncodingLabel(w.sess.values.ConsoleEncoding)}),
open: func() { w.openBuildChild(pageConsole) },
})
if l := w.toolchains.locations; l.available() {
entry := directoryEntry{
key: "trusted-locations", tile: locationsTile, icon: icons.ShieldCheck, title: titleOf(&w.text.Settings, pageTrustedLocations),
desc: i18n.Shared(language, "desktop.toolchains.loading"),
open: func() { w.openBuildChild(pageTrustedLocations) },
}
if l.loaded {
if count := len(l.source.Locations); count > 0 {
entry.desc = i18n.SharedFormat(language, "desktop.trustedLocations.directory", map[string]string{"count": formatCount(count)})
} else {
entry.desc = i18n.Shared(language, "desktop.trustedLocations.directoryNone")
}
}
entries = append(entries, entry)
}
for _, kind := range buildKinds {
var names []string
count := 0
Expand Down
1 change: 1 addition & 0 deletions desktop/internal/settingswindow/build_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ var (
toolchainsTile = gfx.RGB24(0x30a46c)
debuggersTile = gfx.RGB24(0xe5484d)
consoleTile = gfx.RGB24(0x6e56cf)
locationsTile = gfx.RGB24(0xd97706)
kindTile = gfx.RGB24(0x3e7bfa)
)

Expand Down
9 changes: 9 additions & 0 deletions desktop/internal/settingswindow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ type ToolchainTrustLoader interface {
SetWorkspaceTrust(context.Context, toolchain.Snapshot, bool) (toolchain.Snapshot, error)
}

// TrustedLocationsLoader reads and writes the folders whose every workspace this machine
// trusts. Preview asks Core what draft changes lead to without writing; Save writes them
// against the bytes the list was read from and re-reads it. All calls run off the window thread.
type TrustedLocationsLoader interface {
LoadTrustedLocations(context.Context) (toolchain.TrustedLocations, error)
PreviewTrustedLocations(context.Context, toolchain.TrustedLocations, []toolchain.LocationChange) ([]string, error)
SaveTrustedLocations(context.Context, toolchain.TrustedLocations, []toolchain.LocationChange) (toolchain.TrustedLocations, error)
}

// ToolchainRuntimePreparer downloads or repairs a plugin's managed runtimes
// from the Toolchains settings page, then reloads its snapshot.
type ToolchainRuntimePreparer interface {
Expand Down
Loading
Loading