diff --git a/.agents/notes/implemented/feature/2026-10-15-macos-settings-hierarchy.md b/.agents/notes/implemented/feature/2026-10-15-macos-settings-hierarchy.md index 077ad9dd9..d4e6acfc2 100644 --- a/.agents/notes/implemented/feature/2026-10-15-macos-settings-hierarchy.md +++ b/.agents/notes/implemented/feature/2026-10-15-macos-settings-hierarchy.md @@ -19,7 +19,7 @@ | 外观与行为 | 应用本身的外观、编辑器显示与输入、快捷键,以及应用自身网络请求的代理设置 | | 插件 | 插件的安装、启用和插件自带的选项;一级页面,不属于任何分组 | | 版本控制 | Git、SVN 等版本控制系统的配置 | -| 构建、执行、部署 | 构建工具、项目 JDK、插件声明的编译器页与模块字节码、运行配置、服务运行,以及框架和构建工具注入的配置 | +| 构建、执行、部署 | 分组本身是目录页;固定子页“工具链”(插件声明的全部工具,包括项目 JDK)和“调试器”(单步过滤等调试设置);插件声明的构建工具页、编译器页按种类排在后面,以及运行配置、服务运行和框架、构建工具注入的配置 | | 语言与框架 | 语言服务(LSP)的开关,以及 Spring Boot 等框架的配置 | | 工具 | 终端等通用工具;插件带来的专用工具可以放进对应工具页。日志与诊断不属于设置,它是独立的日志窗口 | | AI | 与 AI 有关的全部配置:MCP、Skill、全局指令、AI 提交信息、Agents、AI 服务商 | @@ -31,6 +31,8 @@ AI 分组内,Agent 可加载的资源(指令、技能、Hooks、MCP 配置)收进可折叠的“资源库”,与 AI 服务商、Agents、AI 与提交并列。二级折叠由子分组声明,页面仍归父分组所有,面包屑为“AI › 资源库 › 页面”。只有同类资源达到三个以上页面时才新增二级折叠。 +“构建、执行、部署”下插件声明的页面按种类(构建工具、编译器)折叠:同一种类不到 3 个页面时直接列在侧栏;达到 3 个时收成一个种类文件夹,展开后最多列 6 个页面,其余由最后一行“全部 N 个…”打开该种类的文件夹页。文件夹页列出全部页面和提供插件,可以按名称或插件筛选;“构建、执行、部署”目录页每个种类只写前 3 个名称并计数其余。这些插件页是额外的聚合入口:同样的设置仍然留在插件详情的「设置」标签,不从那里移走。阈值和条数只写在设置窗口的 `folderMin`、`folderLimit`、`kindNames` 常量里,不要为某个插件或种类单独改。详细结构见[构建、执行、部署设置页在大量插件注入时的结构](2026-11-18-build-execution-settings-at-scale.md)。 + ### 开发者怎么做 - 新设置页:在设置分类中增加页面,并把它加入所属分组的 `parents` 表;补充搜索词与文案。不需要再改侧栏、展开逻辑和面包屑。 @@ -62,7 +64,7 @@ AI 分组内,Agent 可加载的资源(指令、技能、Hooks、MCP 配置 ## 验证 -- `scripts/desktop/desktop-go.sh test ./internal/settingswindow -count=1`:验证侧栏、面包屑、搜索展开与“关于”排在 AI 之后。 +- `scripts/desktop/desktop-go.sh test ./internal/settingswindow -count=1`:验证侧栏、面包屑、搜索展开与“关于”排在 AI 之后;`TestBuildKindFoldsIntoAFolderThatListsSix` 等验证插件页的种类文件夹。 - 实机打开设置窗口:确认侧栏分组、面包屑,以及从其它入口跳转到某个页面时展开所属分组。 ## 适用范围 diff --git a/.agents/notes/implemented/feature/2026-11-18-build-execution-settings-at-scale.md b/.agents/notes/implemented/feature/2026-11-18-build-execution-settings-at-scale.md new file mode 100644 index 000000000..c24c8c91d --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-18-build-execution-settings-at-scale.md @@ -0,0 +1,106 @@ +# Agent 笔记:构建、执行、部署设置页在大量插件注入时的结构 + +状态:已实现 + +## 先说结论 + +「构建、执行、部署」原来一页装着作用域与保存、每个插件的工具卡片和调试器单步过滤,页面高度随插件数量线性增长。现在分组页是**目录**,宿主固定两个子页「工具链」「调试器」,插件声明的页面按种类排在后面,多了就折叠成文件夹。 + +这里是**聚合,不是搬家**:插件自己的设置位置不变,插件详情的「设置」标签照样列出该插件的全部设置(包括声明了 `page` 的那些);「构建、执行、部署」只是把各插件里和构建相关的内容额外汇到一处。两处编辑的是同一份设置、同一份草稿,宿主不按插件名写分支。界面按原型 [`docs/design/build-execution-settings.html`](../../../../docs/design/build-execution-settings.html) 复刻,偏差见下文“与原型的差异”。还没做的契约缺口见[构建设置剩余的契约缺口](../../proposed/feature/2026-11-18-build-settings-remaining-contract-gaps.md)。 + +## 问题 + +- 一页装了三件事。按旧卡片高度,每个插件约增加 150 像素,几千个插件时页面高达几十万像素。 +- 同一条路径在一张卡片里出现三次:生效行、下拉框、候选行。 +- 插件 ID 原样显示,原因码 `versionUnsatisfied` 没有翻译。 +- 每张卡片自带「保存」和「使用自动」,和窗口底部的「应用 / 好」是两套提交方式。 +- 调试器单步过滤挤在工具链下面,以后其他调试设置没有地方放。 + +## 决策 + +### 页面结构 + +| 位置 | 内容 | 谁决定 | +| --- | --- | --- | +| 「构建、执行、部署」分组页 | 目录:最上面汇总需要处理的工具,下面是子页、两个作用域的状态和插件页种类 | 宿主 | +| 「工具链」固定子页 | 所有插件声明的工具(`toolDefinitions`,API-23) | 宿主固定页面,行来自插件声明 | +| 「调试器」固定子页 | 支持单步过滤的调试器(API-30) | 宿主固定页面,行来自插件声明 | +| 插件页 | 插件用 `settings[].page`(API-19)声明的构建工具页、编译器页 | 插件声明;折叠规则见[设置页分类](2026-10-15-macos-settings-hierarchy.md) | + +插件页里的设置同时留在插件详情的「设置」标签:Core 的设置文档把全部设置放进详情的 `sections`,`page` 只额外生成一个聚合页(`pages`)。两处由同一个按插件 ID 的表单渲染,在一处改了、没应用就切到另一处,看到的是同一份草稿。 + +### 工具链页 + +- **作用域**(全局默认 / 当前项目 · 项目名)放在工具栏,两段说明收进 ⓘ。两个作用域的草稿分开保存,切换不丢草稿。 +- **列表**一行一个工具,用 Viva 的按需渲染列表,只创建看得见的行。筛选、分组和计数由 Core 的设置投影算好(Lithe-core-rust#99:Core 按筛选条件给出行列表、组和计数),宿主不自己排序计数。 +- **筛选**:文字筛选(名称、版本、路径、插件),加「全部 / 需要处理 / 已手动指定」。**分组**按类别(工具定义的 `category`)或按插件。 +- **详情**:「当前生效」只显示实际在用的程序、版本和来源标签;「为什么是这个」按 Core 的决策链(`tool.Trace`)逐层列出。下面是单选的安装列表:第一项「自动(实际生效值)」,其后是发现的安装和手动目录,各带来源标签;末尾「添加安装目录…」。单个工具用「恢复自动」。 +- 固定值是选中的那一项,不是一个来源:它的目录已经出现在其他来源里时,不再加「全局默认」之类的标签。 +- **项目信任**只在「当前项目」作用域、确实有工具来自项目内环境时出现,通知条和详情里各有「信任此项目」。 + +### 调试器页 + +左侧列出声明了单步过滤的调试器、提供插件和「已自定义」标记,可筛选;右侧编辑。「不进入的代码」是逐条列表,可以添加、删除;跳过合成方法等开关只显示调试器声明支持的。插件没有给出名称时,图标用调试器名称的字母。 + +### 提交和搜索 + +- 提交统一走窗口底部的「应用 / 好」。只有在 Build 相关页面或有草稿时才显示「应用」;没有草稿时「好」直接关闭窗口。 +- 侧栏搜索同时命中设置页、工具和调试器;只命中页面时不显示结果分组标题。 + +### 与原型的差异 + +- 宽度随窗口自适应,不用原型的固定像素宽度;侧栏行高 24、缩进按 Viva 侧栏调整。 +- 字形图标换成 Viva 的图标;选中标签页的下划线画成一条线。 +- 应用时「取消」禁用;没有 toast 提示。 +- 角标按需计算;搜索命中的页面不截断到 8 条。 +- 工具详情底部的工具 ID 一行不用等宽字体,因为等宽字体会把中文字隔开一格。 + +### 正确做法 + +- Gradle 插件声明 `toolDefinitions`(Gradle,`category` 为构建工具)。宿主在「工具链」的“构建工具”组里放一行 Gradle,插件不写页面。 +- 八个插件各声明一个构建工具页:侧栏出现“构建工具”文件夹,展开列 6 个和“全部 8 个…”。 + +### 不要这样做 + +- 不要因为某个设置聚合到了「构建、执行、部署」,就把它从插件详情的「设置」标签里拿掉;聚合入口是额外的,不替代插件自己的位置。 +- 不要在宿主里按插件名或构建工具名加专用页面、专用分组或专用折叠阈值。 +- 不要在卡片或插件页里放自己的保存按钮。 +- 不要把草稿值显示成当前生效值。 + +## 考虑过的备选方案 + +### 保留一页长列表,卡片改成可折叠 + +改动最小。但页面高度仍然随插件数量增长,问题工具只能靠用户自己往下找。不采用。 + +### 每个插件一个页面,工具放在各自插件页里 + +JDK 这类工具会被几个插件各自选一次,用户不知道哪个生效;侧栏也会有几千个入口。不采用。 + +### 宿主为常见构建工具写专用页面 + +违反“宿主不为具体语言或构建工具写专用页面”的规则,新构建工具也得等宿主发版。不采用。 + +## 后果 + +- 插件数量增加时,目录页和工具链页的高度只跟子页数量和可见行数有关。 +- 宿主依赖 Core 的设置投影;Core 固定版本必须包含 Lithe-core-rust#99。 +- 旧的「构建、执行、部署」长页消失,用户需要从目录页进入子页。 + +## 验证 + +- `scripts/desktop/desktop-go.sh test ./internal/settingswindow -count=1`:`toolchains_view_test.go`、`stepping_view_test.go` 和 `build_directory_view_test.go` 覆盖作用域、筛选、分组、信任、草稿与应用、调试器编辑和种类文件夹。 +- `LITHE_VISUAL_OUTPUT_DIR=<目录> scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' -run 'TestVisualSettings/(32|33|34|m4[4579])' ./internal/settingswindow/`:生成目录页、文件夹页、工具链、调试器和项目信任的深浅色截图,与原型对照。 +- 原生窗口与 Windows 实机验收尚未完成,功能矩阵保持 pending。 + +## 适用范围 + +- `desktop/internal/settingswindow/build_directory_view.go` +- `desktop/internal/settingswindow/toolchains_view.go` +- `desktop/internal/settingswindow/toolchains_state.go` +- `desktop/internal/settingswindow/stepping_view.go` +- `desktop/internal/settingswindow/build_apply.go` +- `desktop/internal/settingswindow/build_search.go` +- `desktop/internal/settingswindow/settings_surfaces.go` +- `desktop/internal/settingswindow/model.go` +- `docs/design/build-execution-settings.html` diff --git a/.agents/notes/proposed/architecture/2026-11-12-plugin-authored-settings-content.md b/.agents/notes/proposed/architecture/2026-11-12-plugin-authored-settings-content.md index a07a2ebd4..faceb1a3c 100644 --- a/.agents/notes/proposed/architecture/2026-11-12-plugin-authored-settings-content.md +++ b/.agents/notes/proposed/architecture/2026-11-12-plugin-authored-settings-content.md @@ -13,7 +13,7 @@ 可以操作的原型: - [`docs/design/plugin-canvas-scene.html`](../../../../docs/design/plugin-canvas-scene.html):画布节点的交互、预算、故障回退和消息计数。 -- [`docs/design/build-execution-settings.html`](../../../../docs/design/build-execution-settings.html):「构建、执行、部署」页在大量插件注入时的布局,见[构建、执行、部署设置页在大量插件注入时的结构](../feature/2026-11-18-build-execution-settings-at-scale.md)。 +- [`docs/design/build-execution-settings.html`](../../../../docs/design/build-execution-settings.html):「构建、执行、部署」页在大量插件注入时的布局,见[构建、执行、部署设置页在大量插件注入时的结构](../../implemented/feature/2026-11-18-build-execution-settings-at-scale.md)。 ## 问题 diff --git a/.agents/notes/proposed/feature/2026-11-18-build-execution-settings-at-scale.md b/.agents/notes/proposed/feature/2026-11-18-build-execution-settings-at-scale.md deleted file mode 100644 index f194c9a58..000000000 --- a/.agents/notes/proposed/feature/2026-11-18-build-execution-settings-at-scale.md +++ /dev/null @@ -1,144 +0,0 @@ -# Agent 笔记:构建、执行、部署设置页在大量插件注入时的结构 - -状态:提议中 - -## 先说结论 - -「构建、执行、部署」这一页同时装着作用域与保存、每个插件声明的工具卡片、调试器单步三件事。页面高度随插件数量线性增长。改成下面的结构: - -- 分组页本身改成**目录**:只列子页和状态摘要,最上面汇总需要处理的问题,点一下直达对应工具。 -- 宿主自带两个固定子页:**工具链**(所有插件注入的工具,一行一个,按需渲染)和**调试器**(支持单步过滤的调试器)。 -- 插件声明的页面按种类排在后面,多了就折叠,折叠里最多显示 6 项,其余进「全部 N 个」目录页。 - -插件只声明自己提供什么、属于谁,位置由宿主决定,宿主不按插件名写任何分支。插件页里的内容用[插件在设置的两块区域里自己做界面](../architecture/2026-11-12-plugin-authored-settings-content.md)的描述模式,需要时可以放画布节点。 - -可以操作的原型:[`docs/design/build-execution-settings.html`](../../../../docs/design/build-execution-settings.html)。演示栏可以把插件数量切到 5,000,看列表渲染计数和侧栏折叠。 - -## 问题 - -现状截图里的问题: - -- 一页装了三件事。按现在的卡片高度,每个插件约增加 150 像素,几千个插件时页面高达几十万像素。 -- 同一条路径在一张卡片里出现三次:生效行、下拉框、候选行。 -- 插件 ID 原样显示,原因码 `versionUnsatisfied` 没有翻译。 -- 每张卡片自带「保存」和「使用自动」按钮,和窗口底部的「应用 / 好」是两套提交方式。 -- 作用域(全局默认,或只对当前项目生效)的两段说明常驻在页面顶部;有草稿时禁止切换作用域。 -- 调试器单步过滤挤在工具链下面,以后其他调试设置没有地方放。 - -## 提案 - -### 页面结构 - -| 位置 | 内容 | 谁决定 | -| --- | --- | --- | -| 「构建、执行、部署」分组页 | 目录:子页列表、每页的状态摘要、最上面的问题汇总 | 宿主 | -| 「工具链」固定子页 | 所有插件注入的工具 | 宿主固定页面,行来自插件声明 | -| 「调试器」固定子页 | 支持单步过滤的调试器,以后其他调试设置按标签页加 | 宿主固定页面,行来自插件声明 | -| 插件页 | 构建工具、编译器等插件用 `page` 声明的页面 | 插件声明,种类和位置由宿主按[设置页分类](../../implemented/feature/2026-10-15-macos-settings-hierarchy.md)决定 | - -插件页的折叠规则:同一种类不到 3 个页面时直接列在侧栏;3 个以上才二级折叠(沿用设置页分类笔记的规则)。折叠里最多显示 6 项,其余进「全部 N 个…」目录页。目录页可以搜索、按需渲染,每行写明提供插件。分组折叠时,问题数显示在分组标题上。 - -**按需渲染**是指只创建窗口里看得见的那几十行,滚动时复用;列表有 5,000 行时,界面上始终只有二十几行。 - -### 插件怎么注入 - -| 插件声明 | 编号 | 出现在哪里 | -| --- | --- | --- | -| `toolDefinitions`(工具定义) | API-23 | 「工具链」页的一行,按类别分组 | -| `requiresTools`(插件需要的工具) | API-23 | 插件页里的工具引用:链接到「工具链」页对应的行,不自己放选择框 | -| `commandInstallers`(缺命令时用哪个工具安装) | API-23 | 工具行出问题时就地给出「用 Homebrew 安装…」这类按钮 | -| `debugAdapters[].features`(调试器支持的功能) | API-30 | 「调试器」页左侧的一项,右侧只显示它声明支持的开关 | -| `settings[]` 和 `settingActions[]` 的 `page`(设置页) | API-19 | 侧栏插件页,按种类放 | -| 页面里的界面树和画布节点 | API-13 | 插件页正文,见上面链接的笔记 | - -同一个 JDK 只在「工具链」一处选。插件页需要 JDK、Maven 这类工具时,按工具 ID 引用,点击跳到工具链并选中那一行。 - -### 工具链页 - -- **作用域**放进工具栏,常驻的两段说明收进 ⓘ。两个作用域的草稿分开保存,有修改的作用域带蓝点,可以随时切换。 -- **列表**一行一个工具,行高 46 像素,按需渲染。筛选、分组、排序和计数由 Core 算好(Core 投影,即 Core 按当前筛选条件给出结果列表和计数),平台只取可见的那一段。 -- **筛选**:文字筛选(名称、版本、路径、插件),加上「需要处理 / 已手动指定 / 未应用」。「需要处理」汇总未找到、版本不满足、检测失败、需要信任和冲突;组内也按问题优先排序。 -- **分组**默认按类别,也可以按插件。插件自用运行时(语言服务器用的 JDK、gopls、clangd 等)默认折叠;出了问题照样计入「需要处理」和组标题的角标。 -- **候选安装**用单选列表代替「下拉框加下方重复几行」。版本、路径、来源(PATH、JAVA_HOME、SDKMAN 等,由插件给出)各占一列。不满足要求的候选灰显并写明原因,原因码全部翻译。第一项写成「自动(实际生效值)」或「继承(全局默认 · 版本)」。 -- **当前生效**只显示工具实际在用的值;草稿另起一行「应用后」,不把草稿当成生效值。 -- **「为什么是这个?」**把 Core 已有的决策链(`tool.Trace`)按层展示:项目指定 → 项目环境 → 全局默认 → 自动发现。 -- **问题就地处理**:未找到时,如果插件声明了安装器,直接给安装按钮;冲突时引导到插件页。 -- **项目信任**只在「当前项目」作用域、确实有工具来自项目内环境时才出现;信任后在工具栏显示状态和「撤销」。 - -### 调试器页 - -左侧列出声明了单步过滤的调试器,右侧编辑。「不进入的类」改成逐条列表,添加、删除不用手改多行文本;标题改成通用的「不进入的代码」,写法示例由插件给出,宿主不写 Java 专用的“类”。 - -### 提交和搜索 - -- 提交统一走窗口底部的「应用 / 好」,并写明写入目标和作用域。去掉卡片里的「保存」和「使用自动」;单个工具用「恢复自动 / 恢复继承」。 -- 侧栏搜索同时命中设置页、工具、调试器和插件页声明的关键词,点结果直接跳到对应工具并选中。 - -### 契约缺口 - -下面的字段现在的契约里没有,需要在 Core 契约 PR 里补。字段名都是示意。 - -| 缺口 | 编号 | 用途 | -| --- | --- | --- | -| 工具定义加可选的 `category` | API-23 | 宿主固定的类别表,只用来分组显示;不声明时归“其他” | -| 工具定义加可选的 `audience` | API-23 | 区分用户工具和插件自用运行时 | -| `settingPage` 加 `debugAdapterID` | API-19、API-30 | 插件把调试设置挂到「调试器」页的对应调试器下;现有字段只有 `languageID`、`buildSystemID`、`compilerID` | -| 界面树加工具引用节点 | API-13,沿用 API-33 的 `type:"tool"` | 插件页按工具 ID 引用工具链 | -| 页面加 `keywords` | API-19,文字按 API-37 本地化 | 侧栏搜索命中插件页 | -| 注册表上限按 5,000 个插件定 | —(Core 内部上限,不是插件 API) | 现在 Core 的上限是 128 个插件、512 个工具定义、256 个提供者,单个插件的 `toolDefinitions` 最多 32 个 | - -「按插件」分组不需要改契约。 - -### 正确做法 - -- Gradle 插件声明 `toolDefinitions`(Gradle,`category` 为构建工具)和 `requiresTools`(JDK)。宿主在「工具链」的“构建工具”组里放一行 Gradle;Gradle 插件页里的 JDK 显示为工具引用,点一下跳到工具链里的 JDK 行。 -- lldb 插件声明 `debugAdapters[].features` 支持单步过滤,宿主在「调试器」页列出 lldb-dap;插件不需要写任何页面。 - -### 不要这样做 - -- 不要在宿主里按插件名或构建工具名加专用页面或专用分组。 -- 不要让插件页自己放 JDK 选择框,让同一个工具在几个页面各选各的。 -- 不要在卡片或插件页里放自己的保存按钮。 -- 不要把草稿值显示成当前生效值。 - -## 考虑过的备选方案 - -### 保留一页长列表,卡片改成可折叠 - -改动最小。但页面高度仍然随插件数量增长,几千个插件时滚动条失去意义;问题工具也只能靠用户自己往下找。不采用。 - -### 每个插件一个页面,工具放在各自插件页里 - -插件作者最自由。但 JDK 这类工具会被几个插件各自选一次,用户不知道哪个生效;侧栏也会有几千个入口。不采用,工具统一放「工具链」,插件页只做引用。 - -### 宿主为常见构建工具写专用页面 - -Maven、Gradle 的页面可以做得很细。但这违反“宿主不为具体语言或构建工具写专用页面”的规则,新构建工具也得等宿主发版。不采用。 - -## 验收标准 - -- 插件数量从 10 增加到 5,000 时,「构建、执行、部署」分组页和「工具链」页的高度只跟子页数量有关,列表同时存在的行数不超过可见行数加少量缓冲。 -- 「需要处理」筛选能找出未找到、版本不满足、检测失败、需要信任和冲突的工具,计数和组标题角标一致。 -- 同一个工具的路径在一行和它的详情里只出现一次;原因码全部有中英文案。 -- 草稿只显示在「应用后」;点「应用」后重新读取,「当前生效」才变化。 -- 两个作用域的草稿分开保存,切换作用域不丢草稿。 -- 插件页引用的工具能跳到「工具链」并选中对应行。 -- 侧栏搜索能命中工具、调试器和插件页关键词。 -- 宿主代码里没有按插件 ID 或工具 ID 写的分支。 -- 运行 `node scripts/i18n/verify-app-language-localization.mjs` 和 `node scripts/i18n/generate-i18n.mjs --check`。 - -## 风险 - -- Core 的注册表上限要大幅提高,插件加载、工具发现和投影计算的耗时要先测。工具发现应按需、按可见行做,不在打开页面时探测全部工具。 -- 类别表由宿主固定,新出现的工具种类只能先归“其他”,类别表需要随版本补充。 -- 实现时需要同步更新[设置页分类](../../implemented/feature/2026-10-15-macos-settings-hierarchy.md)的二级折叠规则(折叠最多 6 项、「全部 N 个」目录页),并更新跨平台功能矩阵。 - -## 适用范围 - -- `desktop/internal/settingswindow/toolchains_view.go` -- `desktop/internal/settingswindow/stepping_view.go` -- `desktop/internal/settingswindow/settings_surfaces.go` -- `desktop/internal/settingswindow/model.go` -- `desktop/internal/settingswindow/plugin_settings_view.go` -- Lithe-core-rust 的 `shared/plugins/contract/v1/plugin-manifest.schema.json`(`toolDefinitions`、`settingPage`) -- `docs/design/build-execution-settings.html` diff --git a/.agents/notes/proposed/feature/2026-11-18-build-settings-remaining-contract-gaps.md b/.agents/notes/proposed/feature/2026-11-18-build-settings-remaining-contract-gaps.md new file mode 100644 index 000000000..cdacc483b --- /dev/null +++ b/.agents/notes/proposed/feature/2026-11-18-build-settings-remaining-contract-gaps.md @@ -0,0 +1,60 @@ +# Agent 笔记:构建设置剩余的契约缺口 + +状态:提议中 + +## 先说结论 + +「构建、执行、部署」的目录页、工具链页、调试器页和插件页文件夹已经实现,见[构建、执行、部署设置页在大量插件注入时的结构](../../implemented/feature/2026-11-18-build-execution-settings-at-scale.md)。剩下的是需要先改插件契约的几项:调试设置额外聚合到调试器下、插件页引用工具、插件页搜索关键词,以及按 5,000 个插件放宽 Core 上限。它们都要先在 Lithe-core-rust 的契约 PR 里补字段。和已实现的部分一样,这些都是额外的聚合入口,插件自己的设置位置(插件详情的「设置」标签和插件声明的页面)保持不变。 + +## 问题 + +- 插件的调试设置现在只在插件自己的设置位置,不能同时聚合到「调试器」页的对应调试器下。 +- 插件页需要 JDK、Maven 时只能自己放选择框,同一个工具会在几个页面各选各的。 +- 侧栏搜索命中不了插件页里的内容。 +- Core 的注册表上限是 128 个插件、512 个工具定义、256 个提供者,单个插件的 `toolDefinitions` 最多 32 个,撑不住几千个插件。 + +## 提案 + +下面的字段名都是示意。 + +| 缺口 | 编号 | 用途 | +| --- | --- | --- | +| `settingPage` 加 `debugAdapterID` | API-19、API-30 | 插件的调试设置额外聚合到「调试器」页的对应调试器下,插件详情里照常保留;现有字段只有 `languageID`、`buildSystemID`、`compilerID` | +| 界面树加工具引用节点 | API-13,沿用 API-33 的 `type:"tool"` | 插件页按工具 ID 引用工具链,点击跳到「工具链」并选中那一行 | +| 页面加 `keywords` | API-19,文字按 API-37 本地化 | 侧栏搜索命中插件页 | +| 注册表上限按 5,000 个插件定 | —(Core 内部上限,不是插件 API) | 放宽插件、工具定义和提供者数量上限 | + +另外两项不改契约,等上面的字段落地后在宿主补: + +- 插件自用运行时(`audience` 不是用户的工具)默认折叠成一组,出了问题照样计入「需要处理」。 +- 工具未找到时,如果插件声明了 `commandInstallers`(API-23),在工具详情里就地给出安装按钮。 + +## 考虑过的备选方案 + +### 插件页自己放工具选择框 + +不用改契约。但同一个 JDK 会在几个插件页各选一次,用户不知道哪个生效。不采用,插件页只引用「工具链」里的工具。 + +### 宿主按插件 ID 把调试设置聚合到调试器页 + +不用改契约。但这是按插件名写的分支,违反宿主零依赖。不采用,由插件声明 `debugAdapterID`。 + +## 验收标准 + +- lldb 插件声明 `debugAdapterID` 后,它的调试设置同时出现在「调试器」页 lldb-dap 下和插件详情的「设置」标签,两处是同一份草稿。 +- Gradle 插件页里的 JDK 显示为工具引用,点击跳到「工具链」并选中 JDK 行。 +- 侧栏搜索能命中插件页声明的关键词。 +- 插件数量从 10 增加到 5,000 时,加载和投影计算的耗时有测量记录。 +- 宿主代码里没有按插件 ID 或工具 ID 写的分支。 + +## 风险 + +- 放宽上限前要先测插件加载、工具发现和投影计算的耗时;工具发现应按需、按可见行做,不在打开页面时探测全部工具。 +- 关键词本地化依赖 API-37 的包内语言文件,插件没有提供时只能用默认语言匹配。 + +## 适用范围 + +- Lithe-core-rust 的 `shared/plugins/contract/v1/plugin-manifest.schema.json`(`settingPage`、`toolDefinitions`) +- `desktop/internal/settingswindow/stepping_view.go` +- `desktop/internal/settingswindow/build_search.go` +- `desktop/internal/settingswindow/toolchains_view.go` diff --git a/desktop/internal/core/settings_surfaces.go b/desktop/internal/core/settings_surfaces.go index 51d399713..4f6d4f0bb 100644 --- a/desktop/internal/core/settings_surfaces.go +++ b/desktop/internal/core/settings_surfaces.go @@ -36,6 +36,9 @@ type SettingsNavigationItem struct { Group bool `json:"group"` Expanded bool `json:"expanded"` Keywords string `json:"keywords,omitempty"` + // Limit shows at most this many children outside search; the rest fold into + // one overflow row that opens the group's own directory page. Zero shows all. + Limit int `json:"limit,omitempty"` } type SettingsNavigationRow struct { @@ -44,6 +47,13 @@ type SettingsNavigationRow struct { Group bool `json:"group"` Expanded bool `json:"expanded"` Level uint8 `json:"level"` + // Matched is set when the search hit this row itself rather than a row below + // it; Path holds the ancestor titles so a hit can be listed with its place. + Matched bool `json:"matched,omitempty"` + Path []string `json:"path,omitempty"` + // Overflow is the group's whole child count on the row that stands for the + // children Limit left out; the row's ID is the group's own. + Overflow int `json:"overflow,omitempty"` } type SettingsDeliveryRequest struct { diff --git a/desktop/internal/core/toolchain.go b/desktop/internal/core/toolchain.go index c3592111c..0410b9859 100644 --- a/desktop/internal/core/toolchain.go +++ b/desktop/internal/core/toolchain.go @@ -54,8 +54,13 @@ type ToolchainRegistry struct { // ToolchainToolDefinition is the part of a tool definition the host reads. Core // remains the authority for validation and resolution. type ToolchainToolDefinition struct { - ID string `json:"id"` - DisplayName string `json:"displayName"` + ID string `json:"id"` + DisplayName string `json:"displayName"` + // Category and Audience only place the tool on the settings page + // (toolDefinitions 1): runtime, build, package, debug, lint or other, and + // user or plugin. + Category string `json:"category,omitempty"` + Audience string `json:"audience,omitempty"` ExecutableLayouts []ToolchainExecutableLayout `json:"executableLayouts"` Executables []ToolchainExecutable `json:"executables"` Version ToolchainVersionRule `json:"version"` @@ -401,6 +406,7 @@ type toolchainOutcome struct { Version *ToolchainVersion `json:"version"` Preferences json.RawMessage `json:"preferences"` Edit json.RawMessage `json:"edit"` + View *ToolchainSettingsView `json:"view"` } func (o toolchainOutcome) failure(command string) error { @@ -605,3 +611,106 @@ func (c *Client) EditToolchainPins(ctx context.Context, document json.RawMessage } return result.Edit.Document, nil } + +// ToolchainSettingsTool is one enabled tool's facts for the settings list. +// Reason is the resolver's code when no installation applies; Terms are extra +// searchable text such as versions and paths (at most 16). +type ToolchainSettingsTool struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + PluginID string `json:"pluginID"` + PluginName string `json:"pluginName,omitempty"` + Category string `json:"category,omitempty"` + Audience string `json:"audience,omitempty"` + Reason string `json:"reason,omitempty"` + Pinned bool `json:"pinned,omitempty"` + Changed bool `json:"changed,omitempty"` + Terms []string `json:"terms,omitempty"` +} + +// ToolchainSettingsQuery is what the user typed and chose above the list. +// Filter is all, problems, pinned or changed; GroupBy is category, plugin or +// none. Collapsed and Expanded hold the group keys the user folded or opened. +type ToolchainSettingsQuery struct { + Text string `json:"text"` + Filter string `json:"filter"` + GroupBy string `json:"groupBy"` + Collapsed []string `json:"collapsed"` + Expanded []string `json:"expanded"` +} + +// ToolchainSettingsViewRequest asks Core for the settings list projection. +type ToolchainSettingsViewRequest struct { + Tools []ToolchainSettingsTool `json:"tools"` + Query ToolchainSettingsQuery `json:"query"` + IssueLimit int `json:"issueLimit,omitempty"` +} + +// ToolchainSettingsRow is a group header (Kind "group") or a tool row (Kind +// "tool", Index into the request's tools). Status is error, warning or ok. +type ToolchainSettingsRow struct { + Kind string `json:"kind"` + Key string `json:"key,omitempty"` + Count int `json:"count,omitempty"` + Problems int `json:"problems,omitempty"` + Collapsed bool `json:"collapsed,omitempty"` + Category string `json:"category,omitempty"` + Audience string `json:"audience,omitempty"` + PluginID string `json:"pluginID,omitempty"` + Title string `json:"title,omitempty"` + Index int `json:"index"` + Status string `json:"status,omitempty"` +} + +// ToolchainSettingsIssue is one of the first problems over every tool. Group is the key of +// the group the tool is listed under when the query groups. +type ToolchainSettingsIssue struct { + Index int `json:"index"` + Status string `json:"status"` + Group string `json:"group,omitempty"` +} + +// ToolchainSettingsCounts always cover every tool, whatever the query. +type ToolchainSettingsCounts struct { + Total int `json:"total"` + Matched int `json:"matched"` + Problems int `json:"problems"` + Errors int `json:"errors"` + Warnings int `json:"warnings"` + Pinned int `json:"pinned"` + Changed int `json:"changed"` +} + +// ToolchainSettingsView is Core's projection of the settings list: the rows to +// show, the first problems and the counts. +type ToolchainSettingsView struct { + Rows []ToolchainSettingsRow `json:"rows"` + Issues []ToolchainSettingsIssue `json:"issues"` + Counts ToolchainSettingsCounts `json:"counts"` +} + +// ToolchainSettingsViewOf classifies, filters, groups, folds and counts the +// settings list. The host renders the rows and never re-sorts or classifies. +func (c *Client) ToolchainSettingsViewOf(ctx context.Context, request ToolchainSettingsViewRequest) (ToolchainSettingsView, error) { + const command = "toolchains.settingsView" + if request.Tools == nil { + request.Tools = []ToolchainSettingsTool{} + } + if request.Query.Collapsed == nil { + request.Query.Collapsed = []string{} + } + if request.Query.Expanded == nil { + request.Query.Expanded = []string{} + } + var result toolchainOutcome + if err := c.Execute(ctx, command, request, &result); err != nil { + return ToolchainSettingsView{}, err + } + if err := result.failure(command); err != nil { + return ToolchainSettingsView{}, err + } + if result.View == nil { + return ToolchainSettingsView{}, newParseError(command, "toolchains.settingsView returned no view", "") + } + return *result.View, nil +} diff --git a/desktop/internal/i18n/messages.go b/desktop/internal/i18n/messages.go index 0d4190635..6a6e9fe86 100644 --- a/desktop/internal/i18n/messages.go +++ b/desktop/internal/i18n/messages.go @@ -575,6 +575,8 @@ type SettingsMessages struct { Plugins string VersionControl string Build string + Toolchains string + Debuggers string Languages string Tools string AI string diff --git a/desktop/internal/i18n/settings_messages.go b/desktop/internal/i18n/settings_messages.go index 20370d274..8399564b9 100644 --- a/desktop/internal/i18n/settings_messages.go +++ b/desktop/internal/i18n/settings_messages.go @@ -17,6 +17,8 @@ func settingsMessages(language Language) SettingsMessages { Plugins: Shared(language, "settings.tabs.plugins"), VersionControl: Shared(language, "settings.groups.versionControl"), Build: Shared(language, "settings.groups.build"), + Toolchains: Shared(language, "desktop.toolchains.title"), + Debuggers: Shared(language, "desktop.buildSettings.debuggers"), Languages: Shared(language, "settings.groups.languages"), Tools: Shared(language, "settings.groups.tools"), AI: Shared(language, "native.ai"), diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index fff4b94c0..d4178f947 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -156,6 +156,132 @@ var sharedCatalogs = map[string]map[string]string{ "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.", "desktop.build.versionTooOld": "The build tool is {version}, older than the required {minimum}.", + "desktop.buildSettings.addDirectory": "+ Add Installation Directory…", + "desktop.buildSettings.addHelp": "Choose the installation root that contains the tool's programs (the JDK directory, for example, not its bin directory).\nChecking only reads the version and changes the draft; nothing is written until Apply.", + "desktop.buildSettings.addPattern": "Add a pattern", + "desktop.buildSettings.addPlaceholder": "Installation root, for example ~/.sdkman/candidates/java/21.0.5-tem", + "desktop.buildSettings.afterApply": "After Apply: ", + "desktop.buildSettings.apply": "Apply", + "desktop.buildSettings.applyFailed": "Could not apply: {reason}", + "desktop.buildSettings.applyHelp": "Apply writes the changes, then reads them back; the page shows the values read back.\nCancel discards every change and writes no file.", + "desktop.buildSettings.applying": "Applying…", + "desktop.buildSettings.autoProject": "Automatic (project environment · {version} · {source})", + "desktop.buildSettings.autoReason": "Automatic ({reason})", + "desktop.buildSettings.autoWith": "Automatic ({version} · {source})", + "desktop.buildSettings.cancel": "Cancel", + "desktop.buildSettings.categoryBuild": "Build Tools", + "desktop.buildSettings.categoryDebug": "Debuggers", + "desktop.buildSettings.categoryLint": "Linters & Formatters", + "desktop.buildSettings.categoryOther": "Other", + "desktop.buildSettings.categoryPackage": "Package Managers", + "desktop.buildSettings.categoryPlugin": "Plugin Runtimes", + "desktop.buildSettings.categoryRuntime": "Runtimes & SDKs", + "desktop.buildSettings.checkAndUse": "Check and Use", + "desktop.buildSettings.conflictReason": "Also declared by {plugins}", + "desktop.buildSettings.copyPath": "Copy Path", + "desktop.buildSettings.debuggerCount": "{count} debuggers", + "desktop.buildSettings.debuggerFilter": "Filter debuggers", + "desktop.buildSettings.debuggerNoMatches": "No matching debuggers", + "desktop.buildSettings.debuggers": "Debuggers", + "desktop.buildSettings.declaredBy": "Declared by {plugin}", + "desktop.buildSettings.directoryDebuggers": "Stepping: {count} debuggers support filters", + "desktop.buildSettings.directoryDebuggersCustomized": "Stepping: {count} debuggers support filters · {customized} customized", + "desktop.buildSettings.directoryKind": "{names} · provided by plugins", + "desktop.buildSettings.directoryKindMore": "{names} and {count} more · provided by plugins", + "desktop.buildSettings.directoryNote": "This page lists the subpages and their status only; it does not show what plugins add.", + "desktop.buildSettings.directoryScopeGlobal": "global defaults", + "desktop.buildSettings.directoryScopeProject": "the current project", + "desktop.buildSettings.directoryToolchains": "{tools} tools · from {plugins} plugins · showing {scope}", + "desktop.buildSettings.effectiveHelp": "The program the tool uses now, as Core resolves it.\nChanges are only a draft until you click Apply or OK at the bottom of the window; then they are written and read back.", + "desktop.buildSettings.effectiveTitle": "In Effect", + "desktop.buildSettings.filterAll": "All", + "desktop.buildSettings.filterChanged": "Not Applied", + "desktop.buildSettings.filterLabel": "Filter tools", + "desktop.buildSettings.filterPinned": "Set Manually", + "desktop.buildSettings.filterPlaceholder": "Filter by name, version, path or plugin", + "desktop.buildSettings.filterProblems": "Needs Attention", + "desktop.buildSettings.folderAll": "All {count}…", + "desktop.buildSettings.folderCount": "{count} pages · provided by plugins", + "desktop.buildSettings.folderEmpty": "No matching pages", + "desktop.buildSettings.folderFilter": "Filter pages or plugins", + "desktop.buildSettings.fromSource": "from {source}", + "desktop.buildSettings.groupBy": "Group", + "desktop.buildSettings.groupCategory": "By Category", + "desktop.buildSettings.groupNone": "None", + "desktop.buildSettings.groupPlugin": "By Plugin", + "desktop.buildSettings.hideFilteredFramesHelp": "Frames the rules above filter out fold into one row in the call stack; expand it to see them.", + "desktop.buildSettings.inUse": "In Use", + "desktop.buildSettings.inheritWith": "Inherit (global default · {version})", + "desktop.buildSettings.issuesAll": "View all {count} in Toolchains", + "desktop.buildSettings.issuesTitle": "{count} need attention", + "desktop.buildSettings.keywordsBuild": "build execution deployment", + "desktop.buildSettings.keywordsDebuggers": "debugger stepping filter", + "desktop.buildSettings.keywordsToolchains": "toolchain sdk jdk version", + "desktop.buildSettings.kindBuildSystem": "Build Tools", + "desktop.buildSettings.kindCompiler": "Compiler", + "desktop.buildSettings.listCount": "{matched} / {total} tools", + "desktop.buildSettings.listSeparator": ", ", + "desktop.buildSettings.noMatches": "No matching tools", + "desktop.buildSettings.noPatterns": "No rules", + "desktop.buildSettings.noProblems": "✓ No tools need attention", + "desktop.buildSettings.notSet": "not set", + "desktop.buildSettings.optionsGlobal": "Global Default", + "desktop.buildSettings.optionsGlobalHelp": "The default every project shares.\nAutomatic looks in the order the plugin declares: {order}, and takes the first installation that meets the version requirement.", + "desktop.buildSettings.optionsGlobalHelpPlain": "The default every project shares.\nAutomatic takes the first installation that meets the version requirement.", + "desktop.buildSettings.optionsProject": "This Project Uses", + "desktop.buildSettings.optionsProjectHelp": "Applies to the current project only.\nInherit follows the global default; when the project has an environment a plugin declares (a wrapper, a virtual environment), it comes first once you trust the project.", + "desktop.buildSettings.parenthesized": " ({text})", + "desktop.buildSettings.pending": "{count} not applied", + "desktop.buildSettings.pluginGroupHelp": "Runtimes plugins declare for their own language servers or background processes. You rarely change them, so the group starts collapsed; their problems still count under Needs Attention.", + "desktop.buildSettings.problemConflict": "Several plugins declare this tool: {plugins}. Their definitions may differ, so Lithe stops resolving it to avoid using the wrong one.", + "desktop.buildSettings.problemNotFound": "{tool} was not found. After installing it, click ⟳ in the toolbar to detect again, or add its installation directory below.", + "desktop.buildSettings.problemProbeFailed": "Detecting the version failed. Check the tool's installation, then detect again.", + "desktop.buildSettings.problemTrust": "This project provides {tool} through {source} ({home}). Lithe does not probe or run it until you trust the project.", + "desktop.buildSettings.problemVersion": "Every installation found is older than the minimum version {plugin} requires.", + "desktop.buildSettings.program": "Program", + "desktop.buildSettings.providedBy": "Provided by {plugin}", + "desktop.buildSettings.reasonConflict": "Several plugins declare this tool", + "desktop.buildSettings.reasonNotFound": "No installation found", + "desktop.buildSettings.redetect": "Detect again: probe every tool's installations and versions again, without writing any file.", + "desktop.buildSettings.removePattern": "Remove This Rule", + "desktop.buildSettings.restoreAutomatic": "Restore Automatic", + "desktop.buildSettings.restoreAutomaticTip": "Drop the global choice so the tool is found automatically again. Takes effect after Apply.", + "desktop.buildSettings.restoreInherited": "Restore Inherited", + "desktop.buildSettings.restoreInheritedTip": "Drop the project's choice so the tool follows the global default again. Takes effect after Apply.", + "desktop.buildSettings.revokeTrust": "Revoke", + "desktop.buildSettings.scopeHelp": "Global defaults: the choice every project shares, saved in the app's user settings.\nCurrent project: applies to this project only, saved to .lithe/toolchains/local.json (a local file, not committed).\nA tool the project does not set uses the global default. Running processes use a new version after they restart.\nChanges in the two scopes are kept apart; switching loses neither.", + "desktop.buildSettings.scopeProjectNamed": "Current Project · {project}", + "desktop.buildSettings.searchAllTools": "View all {count} in Toolchains…", + "desktop.buildSettings.searchDebuggers": "Debuggers", + "desktop.buildSettings.searchPages": "Settings Pages", + "desktop.buildSettings.searchTools": "Tools in Toolchains", + "desktop.buildSettings.selectTool": "Select a tool on the left to see its details", + "desktop.buildSettings.skipCode": "Code Not to Step Into", + "desktop.buildSettings.skipCodeHelp": "One pattern per row, written the way the debugger expects.\nMatching frames are dimmed in the call stack.", + "desktop.buildSettings.skipConstructorsHelp": "Stepping does not enter constructors.", + "desktop.buildSettings.skipStaticInitializersHelp": "Stepping into a class does not stop in its static initializer block.", + "desktop.buildSettings.skipSyntheticsHelp": "Steps straight over methods the compiler generates, such as lambda bridge methods.", + "desktop.buildSettings.source": "Source", + "desktop.buildSettings.sourceManual": "Added manually", + "desktop.buildSettings.sourceSystem": "Found automatically", + "desktop.buildSettings.status": "Status", + "desktop.buildSettings.steppingPending": "Changes not applied yet; they take effect in the next debug session.", + "desktop.buildSettings.steppingTab": "Debuggers › Stepping", + "desktop.buildSettings.tabStepping": "Stepping", + "desktop.buildSettings.targetGlobal": "global user settings", + "desktop.buildSettings.targetProject": "this project's .lithe/toolchains/local.json", + "desktop.buildSettings.targetStepping": "debugger stepping", + "desktop.buildSettings.toolFooter": "Tool ID {id} · declared by plugin {plugin}", + "desktop.buildSettings.traceCandidate": "{candidate} ({reason})", + "desktop.buildSettings.traceStep": "{layer}: {detail}", + "desktop.buildSettings.trustBanner": "{count} tools come from environments inside the project ({sources}). Lithe does not probe or run them until you trust the project.", + "desktop.buildSettings.trustProject": "Trust This Project", + "desktop.buildSettings.trustReason": "From {source}; trust the project first", + "desktop.buildSettings.trustedHelp": "This project is trusted on this Mac: Lithe may probe and run the tool environments inside it.", + "desktop.buildSettings.undoChange": "Undo Change", + "desktop.buildSettings.version": "Version", + "desktop.buildSettings.why": "Why this one?", + "desktop.buildSettings.writes": "· writes to {targets}", "desktop.changelists.moveSelected": "Move {count} Selected to Change List", "desktop.clone.busy": "Cloning…", "desktop.clone.cancel": "Cancel", @@ -3160,6 +3286,132 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.build.treeFailed": "无法显示构建树:{error}", "desktop.build.treeTruncated": "构建项太多,只列出了前面一部分。", "desktop.build.versionTooOld": "构建工具版本为 {version},低于要求的 {minimum}。", + "desktop.buildSettings.addDirectory": "+ 添加安装目录…", + "desktop.buildSettings.addHelp": "选择包含工具程序的安装根目录(例如 JDK 目录,而不是 bin 目录)。\n检查只读取版本、修改草稿;点“应用”后才写入。", + "desktop.buildSettings.addPattern": "添加模式", + "desktop.buildSettings.addPlaceholder": "安装根目录,例如 ~/.sdkman/candidates/java/21.0.5-tem", + "desktop.buildSettings.afterApply": "应用后:", + "desktop.buildSettings.apply": "应用", + "desktop.buildSettings.applyFailed": "应用失败:{reason}", + "desktop.buildSettings.applyHelp": "点“应用”写入后会重新读取,界面显示的是重新读取到的实际生效值。\n点“取消”放弃全部修改,不写任何文件。", + "desktop.buildSettings.applying": "正在应用…", + "desktop.buildSettings.autoProject": "自动(项目环境 · {version} · {source})", + "desktop.buildSettings.autoReason": "自动({reason})", + "desktop.buildSettings.autoWith": "自动({version} · {source})", + "desktop.buildSettings.cancel": "取消", + "desktop.buildSettings.categoryBuild": "构建工具", + "desktop.buildSettings.categoryDebug": "调试器", + "desktop.buildSettings.categoryLint": "检查与格式化", + "desktop.buildSettings.categoryOther": "其他", + "desktop.buildSettings.categoryPackage": "包管理器", + "desktop.buildSettings.categoryPlugin": "插件自用运行时", + "desktop.buildSettings.categoryRuntime": "运行时与 SDK", + "desktop.buildSettings.checkAndUse": "检查并选用", + "desktop.buildSettings.conflictReason": "同时由 {plugins} 声明", + "desktop.buildSettings.copyPath": "复制路径", + "desktop.buildSettings.debuggerCount": "{count} 个调试器", + "desktop.buildSettings.debuggerFilter": "筛选调试器", + "desktop.buildSettings.debuggerNoMatches": "没有匹配的调试器", + "desktop.buildSettings.debuggers": "调试器", + "desktop.buildSettings.declaredBy": "由 {plugin} 声明", + "desktop.buildSettings.directoryDebuggers": "单步:{count} 个调试器支持过滤", + "desktop.buildSettings.directoryDebuggersCustomized": "单步:{count} 个调试器支持过滤 · {customized} 个已自定义", + "desktop.buildSettings.directoryKind": "{names} · 由插件提供", + "desktop.buildSettings.directoryKindMore": "{names} 等 {count} 个 · 由插件提供", + "desktop.buildSettings.directoryNote": "这一页只列子页和状态摘要,不直接展示插件注入的内容。", + "desktop.buildSettings.directoryScopeGlobal": "全局默认", + "desktop.buildSettings.directoryScopeProject": "当前项目", + "desktop.buildSettings.directoryToolchains": "{tools} 个工具 · 来自 {plugins} 个插件 · 当前显示{scope}", + "desktop.buildSettings.effectiveHelp": "工具现在实际使用的程序,由 Core 解析得出。\n修改只是草稿,点窗口底部的“应用”或“好”之后才写入并重新读取。", + "desktop.buildSettings.effectiveTitle": "当前生效", + "desktop.buildSettings.filterAll": "全部", + "desktop.buildSettings.filterChanged": "未应用", + "desktop.buildSettings.filterLabel": "筛选工具", + "desktop.buildSettings.filterPinned": "已手动指定", + "desktop.buildSettings.filterPlaceholder": "筛选名称、版本、路径或插件", + "desktop.buildSettings.filterProblems": "需要处理", + "desktop.buildSettings.folderAll": "全部 {count} 个…", + "desktop.buildSettings.folderCount": "{count} 个页面 · 由插件提供", + "desktop.buildSettings.folderEmpty": "没有匹配的页面", + "desktop.buildSettings.folderFilter": "筛选页面或插件", + "desktop.buildSettings.fromSource": "来自 {source}", + "desktop.buildSettings.groupBy": "分组", + "desktop.buildSettings.groupCategory": "按类别", + "desktop.buildSettings.groupNone": "不分组", + "desktop.buildSettings.groupPlugin": "按插件", + "desktop.buildSettings.hideFilteredFramesHelp": "调用栈里被上面规则过滤的帧折叠成一行,展开可查看。", + "desktop.buildSettings.inUse": "生效中", + "desktop.buildSettings.inheritWith": "继承(全局默认 · {version})", + "desktop.buildSettings.issuesAll": "在工具链中查看全部 {count} 项", + "desktop.buildSettings.issuesTitle": "{count} 项需要处理", + "desktop.buildSettings.keywordsBuild": "构建 执行 部署 build", + "desktop.buildSettings.keywordsDebuggers": "调试器 单步 debugger stepping 过滤", + "desktop.buildSettings.keywordsToolchains": "工具链 sdk jdk 版本 toolchain", + "desktop.buildSettings.kindBuildSystem": "构建工具", + "desktop.buildSettings.kindCompiler": "编译器", + "desktop.buildSettings.listCount": "{matched} / {total} 个工具", + "desktop.buildSettings.listSeparator": "、", + "desktop.buildSettings.noMatches": "没有匹配的工具", + "desktop.buildSettings.noPatterns": "没有规则", + "desktop.buildSettings.noProblems": "✓ 没有需要处理的工具", + "desktop.buildSettings.notSet": "未设置", + "desktop.buildSettings.optionsGlobal": "全局默认使用", + "desktop.buildSettings.optionsGlobalHelp": "所有项目共用的默认选择。\n“自动”按插件声明的顺序查找:{order},取第一个满足版本要求的安装。", + "desktop.buildSettings.optionsGlobalHelpPlain": "所有项目共用的默认选择。\n“自动”取第一个满足版本要求的安装。", + "desktop.buildSettings.optionsProject": "本项目使用", + "desktop.buildSettings.optionsProjectHelp": "只对当前项目生效。\n“继承”沿用全局默认;项目里有插件声明的环境(Wrapper、虚拟环境等)时,信任项目后优先使用。", + "desktop.buildSettings.parenthesized": "({text})", + "desktop.buildSettings.pending": "{count} 项未应用", + "desktop.buildSettings.pluginGroupHelp": "插件为自己的语言服务器或后台进程声明的运行时。平时不用改,所以默认折叠;出了问题仍会计入“需要处理”。", + "desktop.buildSettings.problemConflict": "多个插件声明了同一工具:{plugins}。它们对这个工具的定义可能不同,Lithe 暂停解析,避免用错。", + "desktop.buildSettings.problemNotFound": "没有找到 {tool}。安装后点工具栏的 ⟳ 重新检测,或在下方添加安装目录。", + "desktop.buildSettings.problemProbeFailed": "版本检测失败。请检查工具的安装,然后重新检测。", + "desktop.buildSettings.problemTrust": "这个项目用 {source}({home})提供 {tool}。信任项目之前不会探测或运行它。", + "desktop.buildSettings.problemVersion": "找到的安装都低于 {plugin} 要求的最低版本。", + "desktop.buildSettings.program": "程序", + "desktop.buildSettings.providedBy": "由 {plugin} 提供", + "desktop.buildSettings.reasonConflict": "多个插件声明了同一工具", + "desktop.buildSettings.reasonNotFound": "没有找到安装", + "desktop.buildSettings.redetect": "重新检测:重新探测全部工具的安装与版本,不写入任何文件。", + "desktop.buildSettings.removePattern": "删除这条", + "desktop.buildSettings.restoreAutomatic": "恢复自动", + "desktop.buildSettings.restoreAutomaticTip": "去掉全局选择,重新自动查找。点“应用”后生效。", + "desktop.buildSettings.restoreInherited": "恢复继承", + "desktop.buildSettings.restoreInheritedTip": "去掉本项目的选择,重新沿用全局默认。点“应用”后生效。", + "desktop.buildSettings.revokeTrust": "撤销", + "desktop.buildSettings.scopeHelp": "全局默认:所有项目共用的选择,保存在应用的用户设置。\n当前项目:只对这个项目生效,保存到本项目的 .lithe/toolchains/local.json(本机文件,不提交)。\n项目没有指定的工具沿用全局默认。已启动的进程需要重启后才使用新版本。\n两个作用域的修改分别保留,切换不会丢失。", + "desktop.buildSettings.scopeProjectNamed": "当前项目 · {project}", + "desktop.buildSettings.searchAllTools": "在工具链中查看全部 {count} 个…", + "desktop.buildSettings.searchDebuggers": "调试器", + "desktop.buildSettings.searchPages": "设置页", + "desktop.buildSettings.searchTools": "工具链中的工具", + "desktop.buildSettings.selectTool": "选择左侧的工具查看详情", + "desktop.buildSettings.skipCode": "不进入的代码", + "desktop.buildSettings.skipCodeHelp": "每条一个模式,写法由调试器决定。\n调用栈中匹配的帧会淡化显示。", + "desktop.buildSettings.skipConstructorsHelp": "单步时不进入构造方法。", + "desktop.buildSettings.skipStaticInitializersHelp": "单步进入类时不停在静态初始化块里。", + "desktop.buildSettings.skipSyntheticsHelp": "编译器自动生成的方法(如 lambda 桥接方法)在单步时直接跳过。", + "desktop.buildSettings.source": "来源", + "desktop.buildSettings.sourceManual": "手动添加", + "desktop.buildSettings.sourceSystem": "自动发现", + "desktop.buildSettings.status": "状态", + "desktop.buildSettings.steppingPending": "有未应用的修改,下一次调试会话生效。", + "desktop.buildSettings.steppingTab": "调试器 › 单步", + "desktop.buildSettings.tabStepping": "单步", + "desktop.buildSettings.targetGlobal": "全局用户设置", + "desktop.buildSettings.targetProject": "本项目的 .lithe/toolchains/local.json", + "desktop.buildSettings.targetStepping": "调试器单步", + "desktop.buildSettings.toolFooter": "工具 ID {id} · 声明插件 {plugin}", + "desktop.buildSettings.traceCandidate": "{candidate}({reason})", + "desktop.buildSettings.traceStep": "{layer}:{detail}", + "desktop.buildSettings.trustBanner": "{count} 个工具来自项目内的环境({sources})。信任项目之前不会探测或运行它们。", + "desktop.buildSettings.trustProject": "信任此项目", + "desktop.buildSettings.trustReason": "来自 {source},需要先信任项目", + "desktop.buildSettings.trustedHelp": "本机此项目已信任:允许探测和运行项目内的工具环境。", + "desktop.buildSettings.undoChange": "撤销修改", + "desktop.buildSettings.version": "版本", + "desktop.buildSettings.why": "为什么是这个?", + "desktop.buildSettings.writes": "· 写入 {targets}", "desktop.changelists.moveSelected": "将所选 {count} 个变更移到变更列表", "desktop.clone.busy": "正在克隆…", "desktop.clone.cancel": "取消", diff --git a/desktop/internal/pluginhost/pluginhost.go b/desktop/internal/pluginhost/pluginhost.go index 22b71ca05..94ed2d9d6 100644 --- a/desktop/internal/pluginhost/pluginhost.go +++ b/desktop/internal/pluginhost/pluginhost.go @@ -112,7 +112,9 @@ type Capabilities map[string][]int // the command Core plans for the detected instance before the configuration // starts. // - toolDefinitions: settings discovery, Build/Run selection and tool -// launches use the shared Core resolver. +// launches use the shared Core resolver. Version 1 adds a definition's +// category and audience, which group the tool on the Toolchains settings +// page. // - commandInstallers: plugin management reports the commands a // systemCommand launch names but the machine lacks, and installs them with // the plugin's tool after the user confirms the command line, the network @@ -183,6 +185,9 @@ func Declared() Capabilities { declared["sourceSettings"] = []int{0, 1} // Version 1 adds entrypoint runs, which Run on Current File starts. declared["buildProviders"] = []int{0, 1} + // Version 1 adds a definition's category and audience, by which the + // Toolchains settings page groups and folds the tools. + declared["toolDefinitions"] = []int{0, 1} return declared } diff --git a/desktop/internal/pluginhost/pluginhost_test.go b/desktop/internal/pluginhost/pluginhost_test.go index ae30027ea..4e0b95e17 100644 --- a/desktop/internal/pluginhost/pluginhost_test.go +++ b/desktop/internal/pluginhost/pluginhost_test.go @@ -78,6 +78,11 @@ func TestDeclaredServesTheBaselineOfEveryWiredCapability(t *testing.T) { if name == "buildProviders" { wanted = []int{0, 1} } + // The Toolchains page groups tools by the category and audience version 1 + // adds. + if name == "toolDefinitions" { + wanted = []int{0, 1} + } if versions := declared[name]; !slices.Equal(versions, wanted) { t.Fatalf("%s = %v, want %v", name, versions, wanted) } diff --git a/desktop/internal/settingswindow/build_aggregation_test.go b/desktop/internal/settingswindow/build_aggregation_test.go new file mode 100644 index 000000000..fa7917c8b --- /dev/null +++ b/desktop/internal/settingswindow/build_aggregation_test.go @@ -0,0 +1,97 @@ +package settingswindow + +import ( + "context" + "encoding/json" + "os" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/marketplace" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings" + "github.com/vivaui/viva/app" +) + +// Build, Execution, Deployment gathers a plugin's build settings in one more place: the plugin's +// own Settings tab keeps every setting, the page placed under Build shows the placed ones, and +// both edit one draft. +func TestBuildPageGathersSettingsThePluginKeepsInItsOwnTab(t *testing.T) { + data, err := os.ReadFile(contractfixture.CoreFixture("plugins/settings-documents.json")) + if err != nil { + t.Fatal(err) + } + var fixture struct{ Manifest map[string]any } + if err := json.Unmarshal(data, &fixture); err != nil { + t.Fatal(err) + } + const pluginID = "dev.example.settings" + fixture.Manifest["id"] = pluginID + fixture.Manifest["settings"] = []any{ + map[string]any{"id": "count", "type": "integer", "title": "Count", "default": 3, "minimum": 1, "maximum": 10}, + map[string]any{"id": "flag", "type": "boolean", "title": "Flag", "default": true, "page": map[string]string{"buildSystemID": "bs"}, "section": "Options"}, + } + delete(fixture.Manifest, "settingActions") + manifest, err := json.Marshal(fixture.Manifest) + if err != nil { + t.Fatal(err) + } + client := core.NewClient() + contributions := []core.SettingsContribution{{Manifest: manifest, Owner: core.PluginSettingsOwner{PluginID: pluginID, Version: "1.0.0"}, Enabled: true}} + source := settingsFormSource{store: pluginsettings.New(client, t.TempDir()), manifest: manifest, workspace: t.TempDir()} + fetch := func(context.Context) (marketplace.Snapshot, error) { + return marketplace.Snapshot{Index: core.MarketplaceIndex{Plugins: []core.MarketplacePlugin{{ID: pluginID, Name: "Settings", LatestVersion: "1.0.0"}}}}, nil + } + w := newWindow(NewController(Options{ + Text: func() *i18n.Messages { return i18n.For(i18n.English) }, Language: func() i18n.Language { return i18n.English }, + PluginSettings: source, Marketplace: fetch, MarketplaceInstalled: fetch, + PluginState: func(string) PluginState { return PluginState{Installed: true} }, + InstalledPlugins: func() []PluginFacts { + return []PluginFacts{{ID: pluginID, Name: "Settings", Version: "1.0.0", Settings: 2}} + }, + SettingsNavigation: client.SettingsNavigation, + SettingsPages: func(ctx context.Context) ([]core.SettingsPage, error) { + return client.SettingsPages(ctx, contributions) + }, + }), Values{}) + w.sess.page = pagePlugins + w.installed.tab = installedSettings + d := openWindow(t, w, func(config *app.Config) { config.Height = 1100 }) + loaded := func(what string) { + t.Helper() + d.until(what, func() bool { + if w.pluginSettings.failed != nil { + t.Fatal(w.pluginSettings.failed) + } + return w.pluginSettings.loaded && w.dynamic.loaded + }) + d.pump() + } + loaded("the plugin's own settings") + if !d.has("Count") || !d.has("Flag") { + t.Fatal("the plugin's Settings tab must keep every setting, the one placed under Build too") + } + d.click("Count") + if err := d.driver.SelectText(0, 1); err != nil { + t.Fatal(err) + } + d.typeText("7") + d.pump() + if !w.pluginSettings.hasDraft() { + t.Fatal("editing Count in the plugin's tab made no draft") + } + + w.openContributedPage("buildSystem:bs", pluginID) + d.until("the page under Build", func() bool { return w.pluginSettings.pageKey == "buildSystem:bs" && w.dynamic.loaded }) + d.pump() + if !d.has("Flag") { + t.Fatal("the page under Build must show the setting placed there") + } + if d.has("Count") { + t.Fatal("the page under Build shows only the settings placed there") + } + if !w.pluginSettings.hasDraft() { + t.Fatal("the page under Build edits the plugin's own form, so the draft made in its tab is kept") + } +} diff --git a/desktop/internal/settingswindow/build_apply.go b/desktop/internal/settingswindow/build_apply.go new file mode 100644 index 000000000..f0d9accd9 --- /dev/null +++ b/desktop/internal/settingswindow/build_apply.go @@ -0,0 +1,148 @@ +package settingswindow + +import ( + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// 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. + +const ( + applyToolchain = "toolchain:" + applyStepping = "stepping:" +) + +// buildApply is the footer's write of the Build drafts. Only the window thread uses it. +type buildApply struct { + // steps are the writes still to start, running the one whose request is out. + steps []string + running string + // closing says OK started the write, so the window closes after it. + closing bool + // failed is the error of the write that stopped the last apply. + failed error +} + +func (a *buildApply) active() bool { return a.running != "" || len(a.steps) > 0 } + +// buildDrafts counts the Build pages' unapplied edits and names where Apply writes them. +func (w *window) buildDrafts(language i18n.Language) (count int, targets []string) { + if t := w.toolchains; t.available() { + for _, name := range t.order { + n := t.drafts(name) + if n == 0 { + continue + } + count += n + if name == scopeGlobal { + targets = append(targets, i18n.Shared(language, "desktop.buildSettings.targetGlobal")) + } else { + targets = append(targets, i18n.Shared(language, "desktop.buildSettings.targetProject")) + } + } + } + if pending := w.steppingPending(); len(pending) > 0 { + count += len(pending) + targets = append(targets, i18n.Shared(language, "desktop.buildSettings.targetStepping")) + } + return count, targets +} + +// startApply queues every Build draft for writing; close says OK asked for it. With nothing +// to write, OK closes the window at once. +func (w *window) startApply(close bool) { + a := &w.apply + if a.active() { + a.closing = a.closing || close + return + } + a.failed = nil + if t := w.toolchains; t.available() { + for _, name := range t.order { + if t.drafts(name) > 0 { + a.steps = append(a.steps, applyToolchain+name) + } + } + } + for _, id := range w.steppingPending() { + a.steps = append(a.steps, applyStepping+id) + } + if !a.active() { + // Nothing to write: OK closes at once, Apply has nothing to do. + if close && w.sess.accept() { + w.closeNative() + } + return + } + a.closing = close + w.advanceApply(nil, steppingResult{}) +} + +// steppingResult is what steppingState.take returned in this paint. +type steppingResult struct { + done bool + err error +} + +// advanceApply runs after the background work was taken: it lets the request out finish, +// stops at a failure and starts the next write. Writes wait for any read that is out. +func (w *window) advanceApply(toolchainFailed error, stepping steppingResult) { + a := &w.apply + if !a.active() { + return + } + switch { + case strings.HasPrefix(a.running, applyToolchain): + if toolchainFailed != nil { + w.stopApply(toolchainFailed) + return + } + if w.toolchains.saving { + return + } + case strings.HasPrefix(a.running, applyStepping): + if !stepping.done { + return + } + if stepping.err != nil { + w.stopApply(stepping.err) + return + } + } + a.running = "" + for len(a.steps) > 0 { + step := a.steps[0] + if name, ok := strings.CutPrefix(step, applyToolchain); ok { + if w.toolchains.busy() { + return + } + a.steps = a.steps[1:] + if w.toolchains.beginSave(name) { + a.running = step + return + } + continue + } + a.steps = a.steps[1:] + if w.beginSteppingApply(strings.TrimPrefix(step, applyStepping)) { + a.running = step + return + } + } + closing := a.closing + a.closing = false + if closing && w.sess.accept() { + w.closeNative() + } +} + +// stopApply ends the apply at a failed write: the rest stays as drafts and the window stays +// open, so the failure shows beside what caused it. +func (w *window) stopApply(err error) { + w.apply = buildApply{failed: err} +} diff --git a/desktop/internal/settingswindow/build_directory_view.go b/desktop/internal/settingswindow/build_directory_view.go new file mode 100644 index 000000000..78fba7588 --- /dev/null +++ b/desktop/internal/settingswindow/build_directory_view.go @@ -0,0 +1,428 @@ +package settingswindow + +import ( + "hash/fnv" + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// The Build, Execution, Deployment page and the page of a folder under it follow pgBuild and +// pgFolder of the prototype docs/design/build-execution-settings.html. The Build page lists its +// pages with what each holds in one line, and the tools that need attention above them; it +// shows nothing plugins put on their pages. A folder's page lists the plugin pages of one kind, +// with a filter, for the kinds the sidebar folds. + +const ( + // buildPageWidth is the widest the Build page grows, the prototype's max-width. + buildPageWidth = 860 + // directoryRowGap is the room between a row's tile, words and end, the prototype's .drow. + directoryRowGap = 12 + // folderRowHeight is a row of a folder's page, the prototype's 52 points. + folderRowHeight = 52 + // folderFilterWidth is the width of a folder page's filter. + folderFilterWidth = 260 + // kindNames is how many of a kind's pages the Build page names before it counts them. + kindNames = 3 +) + +// buildPage is the prototype's pgBuild: the title, the tools that need attention, the +// directory of the pages under Build, Execution, Deployment and a note on what it leaves out. +func (w *window) buildPage(c ui.C) { + b := &w.bp + language := w.marketLanguage() + if t := w.toolchains; t.available() { + t.ensureLoaded() + t.requestView() + } + if s := w.stepping; s.available() { + s.beginLoad() + } + ui.Scroll(c).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Background(b.surface).Children(func() { + ui.Column(c).FillWidth().MaxWidth(buildPageWidth).PadSides(buildPagePadTop, buildPagePadX, buildPagePadEnd, buildPagePadX).Children(func() { + ui.Text(c, titleOf(&w.text.Settings, pageBuild)).FontSize(buildHeading).Weight(gfx.WeightBold).Color(b.text).Ellipsis() + ui.Row(c).Height(12).Shrink(0) + w.buildIssues(c.Part("issues"), language) + w.buildDirectory(c.Part("directory"), language) + ui.Wrap(c, i18n.Shared(language, "desktop.buildSettings.directoryNote")).FontSize(11.5).Color(b.faint) + }) + }) +} + +// buildIssues is the prototype's .issues box: how many tools of the shown scope need +// attention, the first of them, and a link to all of them once there are more. Choosing a +// tool opens the Toolchains page on it. Nothing shows while nothing needs attention or before +// Core projected the list. +func (w *window) buildIssues(c ui.C, language i18n.Language) { + t := w.toolchains + if !t.available() || !t.view.ready { + return + } + view := &t.view.view + if view.Counts.Problems == 0 || len(view.Issues) == 0 { + return + } + b := &w.bp + kind := boxWarn + if view.Counts.Errors > 0 { + kind = boxErr + } + colors := b.boxes[kind] + scope := t.current() + var chosen *core.ToolchainSettingsIssue + all := false + ui.Column(c).FillWidth().MinWidth(0).Shrink(0).PadX(10).PadY(8).Radius(8). + Border(1, colors.border).Background(colors.background).Children(func() { + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.issuesTitle", map[string]string{"count": formatCount(view.Counts.Problems)})). + FontSize(buildSmall).Weight(gfx.WeightSemibold).Color(colors.text).Ellipsis() + ui.Row(c).Height(4).Shrink(0) + for i := range view.Issues { + issue := &view.Issues[i] + if issue.Index < 0 || issue.Index >= len(t.view.entries) { + continue + } + entry := &t.view.entries[issue.Index] + k := c.Key(entry.tool.ID) + name := toolchainName(&entry.tool) + row := ui.ButtonBase(k, name).FillWidth().MinWidth(0).PadX(4).PadY(5).Gap(8).Radius(6).Items(ui.Center). + Hover(ui.Look{}.Background(b.press)) + if row.Clicked() { + chosen = issue + } + row.Children(func() { + dot(k, 8, b.statusColor(issue.Status)) + ui.Text(k, name).FontSize(buildSmall).Weight(gfx.WeightSemibold).Color(colors.text).Shrink(0) + ui.Text(k, w.toolchainReasonText(language, scope, entry, toolchainReason(entry.tool))). + FontSize(buildSmall).Color(colors.text).Shrink(1).MinWidth(0).Ellipsis() + ui.Spacer(k) + ui.Text(k, "›").FontSize(buildSmall).Color(colors.text).Shrink(0) + }) + } + if view.Counts.Problems > len(view.Issues) { + label := i18n.SharedFormat(language, "desktop.buildSettings.issuesAll", map[string]string{"count": formatCount(view.Counts.Problems)}) + row := ui.ButtonBase(c.Part("all"), label).FillWidth().PadX(4).PadY(5).Radius(6).Items(ui.Center). + Hover(ui.Look{}.Background(b.press)) + if row.Clicked() { + all = true + } + row.Children(func() { + // The prototype's underlined link, in the words' color: a line under the words. + ui.Column(c).Shrink(1).MinWidth(0).Children(func() { + ui.Text(c, label).FontSize(buildSmall).Color(colors.text).Ellipsis() + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(colors.text) + }) + }) + } + }) + ui.Row(c).Height(14).Shrink(0) + switch { + case chosen != nil: + t.reveal(t.view.entries[chosen.Index].tool.ID, chosen.Group) + w.openBuildChild(pageToolchains) + case all: + t.query, t.filter, t.selected = "", "problems", "" + w.openBuildChild(pageToolchains) + } +} + +// directoryEntry is one row of the Build page's directory: what it opens and what it shows. +type directoryEntry struct { + key string + tile gfx.Color + icon gfx.Icon + title, desc string + // problems is the count of the badge at the row's end, none at zero. + problems int + open func() +} + +// buildDirectory is the prototype's .sec.dir: one row for each page under Build, Execution, +// Deployment, the host's own first and then a row for each kind of plugin page. +func (w *window) buildDirectory(c ui.C, language i18n.Language) { + entries := w.directoryEntries(language) + if len(entries) == 0 { + return + } + b := &w.bp + var open func() + ui.Column(c).FillWidth().MinWidth(0).Shrink(0).Pad(4).Radius(10).Border(1, b.line).Background(b.surface).Children(func() { + for i := range entries { + entry := &entries[i] + k := c.Key(entry.key) + if i > 0 { + // The prototype's .drow+.drow: a line between two rows, inside their margins. + ui.Row(k.Part("line")).FillWidth().Height(1).Shrink(0).Background(b.line) + } + row := ui.ButtonBase(k, entry.title).FillWidth().MinWidth(0).PadX(12).PadY(10).Gap(directoryRowGap).Radius(8).Items(ui.Center). + Hover(ui.Look{}.Background(b.hover)) + if row.Clicked() { + open = entry.open + } + row.Children(func() { + w.glyphTile(k, entry.tile, entry.icon, 28) + ui.Column(k).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Text(k, entry.title).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Ellipsis() + ui.Row(k).Height(2).Shrink(0) + ui.Text(k, entry.desc).FontSize(buildSmall).Color(b.sub).Ellipsis() + }) + if entry.problems > 0 { + w.badge(k, entry.problems, false) + } + ui.Text(k, "›").FontSize(buildFont).Color(b.faint).Shrink(0) + }) + } + }) + ui.Row(c).Height(12).Shrink(0) + if open != nil { + open() + } +} + +// directoryEntries are the rows of the Build page's directory, in the sidebar's order. +func (w *window) directoryEntries(language i18n.Language) []directoryEntry { + var entries []directoryEntry + if t := w.toolchains; t.available() { + entry := directoryEntry{ + key: "toolchains", tile: toolchainsTile, icon: icons.Wrench, title: titleOf(&w.text.Settings, pageToolchains), + desc: i18n.Shared(language, "desktop.toolchains.loading"), + open: func() { w.openBuildChild(pageToolchains) }, + } + if scope := t.current(); scope != nil && scope.loaded { + shown := i18n.Shared(language, "desktop.buildSettings.directoryScopeGlobal") + if scope.name == scopeProject { + shown = i18n.Shared(language, "desktop.buildSettings.directoryScopeProject") + } + tools, plugins := toolchainCounts(scope) + if t.view.ready { + tools = t.view.view.Counts.Total + entry.problems = t.view.view.Counts.Problems + } + entry.desc = i18n.SharedFormat(language, "desktop.buildSettings.directoryToolchains", map[string]string{ + "tools": formatCount(tools), "plugins": formatCount(plugins), "scope": shown, + }) + } + entries = append(entries, entry) + } + if s := w.stepping; s.available() { + entry := directoryEntry{ + key: "debuggers", tile: debuggersTile, icon: icons.Bug, title: titleOf(&w.text.Settings, pageDebuggers), + desc: i18n.Shared(language, "desktop.toolchains.loading"), + open: func() { w.openBuildChild(pageDebuggers) }, + } + if s.loaded { + customized := 0 + for _, adapter := range s.adapters { + if _, ok := w.sess.values.SteppingFilters[adapter.ID]; ok { + customized++ + } + } + if customized > 0 { + entry.desc = i18n.SharedFormat(language, "desktop.buildSettings.directoryDebuggersCustomized", map[string]string{ + "count": formatCount(len(s.adapters)), "customized": formatCount(customized), + }) + } else { + entry.desc = i18n.SharedFormat(language, "desktop.buildSettings.directoryDebuggers", map[string]string{"count": formatCount(len(s.adapters))}) + } + } + entries = append(entries, entry) + } + separator := i18n.Shared(language, "desktop.buildSettings.listSeparator") + for _, kind := range buildKinds { + var names []string + count, first := 0, "" + for index := range w.dynamic.pages { + page := &w.dynamic.pages[index] + if page.Kind != kind { + continue + } + if count == 0 { + first = page.Key + } + if count < kindNames { + names = append(names, page.Title) + } + count++ + } + if count == 0 { + continue + } + var desc string + if count > kindNames { + desc = i18n.SharedFormat(language, "desktop.buildSettings.directoryKindMore", map[string]string{ + "names": strings.Join(names, separator), "count": formatCount(count), + }) + } else { + desc = i18n.SharedFormat(language, "desktop.buildSettings.directoryKind", map[string]string{"names": strings.Join(names, separator)}) + } + entry := directoryEntry{key: "kind:" + kind, tile: kindTile, icon: icons.LayoutGrid, title: kindTitle(language, kind), desc: desc} + if count >= folderMin { + entry.open = func() { w.openFolder(kind) } + } else { + entry.open = func() { w.selectSettingsPage(pageBuild, first) } + } + entries = append(entries, entry) + } + return entries +} + +// toolchainCounts is how many tools the scope lists and how many plugins declare them. +func toolchainCounts(scope *toolchainScope) (tools, plugins int) { + seen := make(map[string]bool) + for _, tool := range scope.snapshot.Tools { + if tool.ID == "" || tool.PluginID == "" { + continue + } + tools++ + if !seen[tool.PluginID] { + seen[tool.PluginID] = true + plugins++ + } + } + return tools, plugins +} + +// buildFolderPage is the prototype's pgFolder: the plugin pages of the open folder's kind, +// the ones whose title or plugin the filter matches, each with its plugin and what it holds. +// Choosing one opens it with its folder open in the sidebar. +func (w *window) buildFolderPage(c ui.C) { + b := &w.bp + language := w.marketLanguage() + kind := w.folderPage + pages := w.folderPages(kind) + total := w.dynamic.kindCount(kind) + ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Background(b.surface).Children(func() { + ui.Row(c).FillWidth().Shrink(0).PadSides(10, 14, 6, 14).Gap(8).Items(ui.Center).Children(func() { + ui.Text(c, kindTitle(language, kind)).FontSize(buildHeading).Weight(gfx.WeightBold).Color(b.text).Shrink(0) + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.folderCount", map[string]string{"count": formatCount(total)})). + FontSize(buildSmall).Color(b.sub).Shrink(1).MinWidth(0).Ellipsis() + ui.Spacer(c) + ui.Row(c).Width(folderFilterWidth).Shrink(1).MinWidth(120).Children(func() { + placeholder := i18n.Shared(language, "desktop.buildSettings.folderFilter") + w.filterField(c.Part("filter"), &w.folderQuery, placeholder, placeholder, true) + }) + }) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + if len(pages) == 0 { + ui.Row(c).FillWidth().Shrink(0).PadSides(50, 20, 50, 20).Justify(ui.Center).Children(func() { + ui.Wrap(c, i18n.Shared(language, "desktop.buildSettings.folderEmpty")).FontSize(buildFont).Color(b.faint).TextCenter() + }) + return + } + w.folderList.Key = func(row int) int { + if row < 0 || row >= len(pages) { + return 0 + } + return folderRowKey(pages[row].Key) + } + w.folderList.Label = func(row int) string { + if row < 0 || row >= len(pages) { + return "" + } + return pages[row].Title + } + separator := i18n.Shared(language, "desktop.buildSettings.listSeparator") + ui.List(c, &w.folderList, len(pages), func(r ui.ListRow) { + page := pages[r.Index] + k := r.C + r.Element.Height(folderRowHeight).PadSides(0, 12, 0, 14).Gap(11).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)).Children(func() { + plugin := folderPlugins(page, separator) + w.pluginTile(k, plugin, 28) + ui.Column(k).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Text(k, page.Title).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Ellipsis() + ui.Row(k).Height(2).Shrink(0) + line := plugin + if summary := folderSummary(page, separator); summary != "" { + line += " · " + summary + } + ui.Text(k, line).FontSize(11).Color(b.faint).Ellipsis() + }) + ui.Text(k, "›").FontSize(buildFont).Color(b.faint).Shrink(0) + }) + }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(kindTitle(language, kind)) + if row, ok := w.folderList.Submitted(); ok && row >= 0 && row < len(pages) { + w.openFolderPage(pages[row]) + } else if row := w.folderList.Selected(); w.folderList.Changed() && row >= 0 && row < len(pages) { + w.openFolderPage(pages[row]) + } + }) +} + +// folderRowKey is a folder page's row identity, its page's key hashed to the list's +// non-negative 31-bit keys. +func folderRowKey(key string) int { + hash := fnv.New32a() + _, _ = hash.Write([]byte(key)) + return int(hash.Sum32() & 0x7fffffff) +} + +// folderPages are the plugin pages of kind the folder page's filter keeps: the ones whose +// title or a contributing plugin's title holds the filter, ignoring case. +func (w *window) folderPages(kind string) []*core.SettingsPage { + query := strings.ToLower(strings.TrimSpace(w.folderQuery)) + var pages []*core.SettingsPage + for index := range w.dynamic.pages { + page := &w.dynamic.pages[index] + if page.Kind != kind { + continue + } + if query != "" && !folderMatches(page, query) { + continue + } + pages = append(pages, page) + } + return pages +} + +// folderMatches reports whether a lower-case query is in page's title or a contributor's. +func folderMatches(page *core.SettingsPage, query string) bool { + if strings.Contains(strings.ToLower(page.Title), query) { + return true + } + for _, contribution := range page.Contributors { + if strings.Contains(strings.ToLower(contribution.Title), query) { + return true + } + } + return false +} + +// folderPlugins names the plugins that contribute to page. +func folderPlugins(page *core.SettingsPage, separator string) string { + names := make([]string, 0, len(page.Contributors)) + for _, contribution := range page.Contributors { + name := contribution.Title + if name == "" { + name = contribution.PluginID + } + names = append(names, name) + } + return strings.Join(names, separator) +} + +// folderSummary is what a plugin page holds, the titles of its sections. +func folderSummary(page *core.SettingsPage, separator string) string { + titles := make([]string, 0, len(page.Sections)) + for _, section := range page.Sections { + if section.Title != "" { + titles = append(titles, section.Title) + } + } + return strings.Join(titles, separator) +} + +// openFolderPage opens a plugin page from its folder's page, with the folder open in the +// sidebar so the page's row is on the screen. +func (w *window) openFolderPage(page *core.SettingsPage) { + if index := kindIndex(page.Kind); index >= 0 { + w.folders[index] = true + } + // The list forgets the row, so choosing it again the next time the folder shows opens it. + w.folderList.Select(-1) + w.folderPage = "" + w.sess.open[pageBuild] = true + w.selectSettingsPage(pageBuild, page.Key) +} diff --git a/desktop/internal/settingswindow/build_directory_view_test.go b/desktop/internal/settingswindow/build_directory_view_test.go new file mode 100644 index 000000000..e3ac4fe52 --- /dev/null +++ b/desktop/internal/settingswindow/build_directory_view_test.go @@ -0,0 +1,214 @@ +package settingswindow + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" +) + +// buildPageContributions are count enabled plugins, each with one setting on a build system +// page of its own, bs00, bs01 and so on, so the real Core projects count pages of that kind. +func buildPageContributions(t *testing.T, count int) []core.SettingsContribution { + t.Helper() + data, err := os.ReadFile(contractfixture.CoreFixture("plugins/settings-documents.json")) + if err != nil { + t.Fatal(err) + } + var fixture struct{ Manifest map[string]any } + if err := json.Unmarshal(data, &fixture); err != nil { + t.Fatal(err) + } + contributions := make([]core.SettingsContribution, 0, count) + for index := range count { + id := fmt.Sprintf("bs%02d", index) + fixture.Manifest["id"] = "dev.example." + id + fixture.Manifest["displayName"] = fmt.Sprintf("Builder %02d", index) + fixture.Manifest["settings"] = []any{map[string]any{"id": "flag", "type": "boolean", "title": "Flag", "default": true, "page": map[string]string{"buildSystemID": id}, "section": "Options"}} + manifest, err := json.Marshal(fixture.Manifest) + if err != nil { + t.Fatal(err) + } + contributions = append(contributions, core.SettingsContribution{Manifest: manifest, Owner: core.PluginSettingsOwner{PluginID: "dev.example." + id, Version: "1.0.0"}, Enabled: true}) + } + return contributions +} + +// buildPagesWindow is an English settings window whose plugins put count build system pages +// under Build, Execution, Deployment, opened on that page and loaded. +func buildPagesWindow(t *testing.T, count int) (*window, *windowDriver) { + t.Helper() + contributions := buildPageContributions(t, count) + client := core.NewClient() + w := newWindow(NewController(Options{ + Text: func() *i18n.Messages { return i18n.For(i18n.English) }, Language: func() i18n.Language { return i18n.English }, + SettingsNavigation: client.SettingsNavigation, + SettingsPages: func(ctx context.Context) ([]core.SettingsPage, error) { + return client.SettingsPages(ctx, contributions) + }, + }), Values{Theme: "dark"}) + w.sess.page = pageBuild + d := openWindow(t, w, func(config *app.Config) { config.Height = 900 }) + d.until("the plugin pages", func() bool { return w.dynamic.loaded && len(w.dynamic.pages) == count }) + return w, d +} + +// buildRows are the plugin rows below Build, Execution, Deployment: folders and their pages. +func buildRows(w *window) []row { + var rows []row + inside := false + for _, r := range w.rows { + if r.level == 0 { + inside = r.page == pageBuild && r.dynamic == "" && r.folder == "" + continue + } + if inside && (r.dynamic != "" || r.folder != "") { + rows = append(rows, r) + } + } + return rows +} + +// contentHit is the control labeled label furthest right, the page's rather than the +// sidebar's when both show the same words. +func (d *windowDriver) contentHit(label string) gfx.Hit { + d.t.Helper() + var found gfx.Hit + ok := false + for _, hit := range d.driver.Snapshot().Hits { + if hit.Label == label && !hit.IsLabel && !hit.Backdrop && !hit.ID.IsZero() && (!ok || hit.Bounds.X > found.Bounds.X) { + found, ok = hit, true + } + } + if !ok { + d.t.Fatalf("no control labeled %q", label) + } + return found +} + +// TestBuildKindWithFewPagesListsThemDirectly keeps a kind's pages below Build, Execution, +// Deployment while there are fewer than folderMin of them, as the settings hierarchy Note +// says, and the Build page's row for the kind opens its first page. +func TestBuildKindWithFewPagesListsThemDirectly(t *testing.T) { + w, d := buildPagesWindow(t, folderMin-1) + w.sess.open[pageBuild] = true + d.until("the build pages in the sidebar", func() bool { + count := 0 + for _, r := range buildRows(w) { + if r.dynamic != "" { + count++ + } + } + return count == folderMin-1 + }) + for _, r := range buildRows(w) { + if r.folder != "" { + t.Fatalf("row %+v: %d pages of a kind should not fold", r, folderMin-1) + } + if r.dynamic != "" && r.level != 1 { + t.Fatalf("row %+v should be right below Build, Execution, Deployment", r) + } + } + d.clickHit(d.contentHit(kindTitle(i18n.English, "buildSystem"))) + d.pump() + if w.dynamicPage != w.dynamic.pages[0].Key || w.folderPage != "" { + t.Fatalf("the kind's row opened page %q, folder %q; want the first page %q", w.dynamicPage, w.folderPage, w.dynamic.pages[0].Key) + } +} + +// TestBuildKindFoldsIntoAFolderThatListsSix folds folderMin or more pages of a kind into a +// folder: closed, the sidebar shows only the folder; open, it lists folderLimit pages and one +// row for all of them, which opens the folder's page. +func TestBuildKindFoldsIntoAFolderThatListsSix(t *testing.T) { + const count = folderLimit + 2 + w, d := buildPagesWindow(t, count) + w.sess.open[pageBuild] = true + d.until("the folder row", func() bool { return len(buildRows(w)) > 0 }) + var folder []row + for _, r := range buildRows(w) { + if r.dynamic != "" { + t.Fatalf("closed folder: page row %+v should be inside the folder", r) + } + if r.folder != "" { + folder = append(folder, r) + } + } + if len(folder) != 1 || folder[0].folder != "buildSystem" || !folder[0].group || folder[0].expanded || folder[0].count != count { + t.Fatalf("folder rows = %+v, want one closed build system folder of %d pages", folder, count) + } + w.folders[kindIndex("buildSystem")] = true + d.until("the folder's pages", func() bool { + rows := buildRows(w) + return len(rows) > 0 && rows[len(rows)-1].overflow > 0 + }) + rows := buildRows(w) + if len(rows) != folderLimit+2 { + t.Fatalf("rows = %+v, want the folder, %d pages and the row for all of them", rows, folderLimit) + } + for _, r := range rows[1 : folderLimit+1] { + if r.dynamic == "" || r.level != 2 { + t.Fatalf("row %+v should be a page inside the folder", r) + } + } + all := rows[len(rows)-1] + if all.overflow != count || all.folder != "buildSystem" { + t.Fatalf("the last row %+v should stand for all %d pages", all, count) + } + label := i18n.SharedFormat(i18n.English, "desktop.buildSettings.folderAll", map[string]string{"count": formatCount(count)}) + if !d.has(label) { + t.Fatalf("the sidebar does not show %q", label) + } + d.click(label) + d.pump() + if w.folderPage != "buildSystem" { + t.Fatalf("the row for all pages opened folder %q, want the build system folder (%+v)", w.folderPage, all) + } +} + +// TestBuildPageNamesAKindAndOpensItsFolder checks the Build page's row for a folded kind: it +// names the first pages and counts them, and opens the folder's page, whose filter keeps the +// pages it matches; choosing one opens it with the folder open. +func TestBuildPageNamesAKindAndOpensItsFolder(t *testing.T) { + const count = folderLimit + 2 + w, d := buildPagesWindow(t, count) + separator := i18n.Shared(i18n.English, "desktop.buildSettings.listSeparator") + var names []string + for _, page := range w.dynamic.pages[:kindNames] { + names = append(names, page.Title) + } + desc := i18n.SharedFormat(i18n.English, "desktop.buildSettings.directoryKindMore", map[string]string{"names": strings.Join(names, separator), "count": formatCount(count)}) + d.until("the kind's row", func() bool { return d.text(desc) }) + d.clickHit(d.contentHit(kindTitle(i18n.English, "buildSystem"))) + d.pump() + if w.folderPage != "buildSystem" { + t.Fatalf("the kind's row opened folder %q, want the build system folder", w.folderPage) + } + d.pump() + for index := range w.dynamic.pages { + if title := w.dynamic.pages[index].Title; !d.text(title) { + t.Fatalf("the folder's page does not list %q", title) + } + } + w.folderQuery = "Builder 05" + // The filter shows once a frame is painted: clicking a row before that would hit a row + // the filtered list no longer has. + d.until("the filtered folder", func() bool { return !d.text(w.dynamic.pages[0].Title) }) + pages := w.folderPages("buildSystem") + if len(pages) != 1 || pages[0].Contributors[0].PluginID != "dev.example.bs05" { + t.Fatalf("the filter kept %d pages, want the one Builder 05 contributes to", len(pages)) + } + key := pages[0].Key + d.click(pages[0].Title) + d.pump() + if w.dynamicPage != key || w.folderPage != "" || !w.folders[kindIndex("buildSystem")] || !w.sess.open[pageBuild] { + t.Fatalf("choosing the page opened %q (folder page %q, folder open %v), want %q with its folder open", w.dynamicPage, w.folderPage, w.folders, key) + } +} diff --git a/desktop/internal/settingswindow/build_search.go b/desktop/internal/settingswindow/build_search.go new file mode 100644 index 000000000..a083cc7bd --- /dev/null +++ b/desktop/internal/settingswindow/build_search.go @@ -0,0 +1,131 @@ +package settingswindow + +import ( + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// The sidebar's search follows the prototype docs/design/build-execution-settings.html: the +// settings pages it matched, then the tools of the Toolchains page and the debuggers whose +// names it matched, each section under its title. Choosing a tool or a debugger opens its page +// on it and ends the search. + +const ( + // searchToolLimit and searchAdapterLimit are how many tools and debuggers the prototype's + // sections list; the tools past the limit are behind a row that opens the Toolchains page + // filtered by the search. + searchToolLimit = 8 + searchAdapterLimit = 5 +) + +// searchSources asks for what the search's sections list besides the pages, and names what +// arrived: the tools' projection, and how many debuggers there are, -1 before they loaded. +func (w *window) searchSources() (toolchainWant, int) { + var tools toolchainWant + if t := w.toolchains; t.available() { + t.ensureLoaded() + t.requestSearch(w.query) + if t.searchReady(w.query) { + tools = t.search.got + } + } + adapters := -1 + if s := w.stepping; s.available() { + s.beginLoad() + if s.loaded { + adapters = len(s.adapters) + } + } + return tools, adapters +} + +// searchSections are the sidebar's rows of a search: each section that has a match under its +// title. pages are the matched settings pages, which the result does not share. +func (w *window) searchSections(pages []row) []row { + language := w.marketLanguage() + rows := make([]row, 0, len(pages)+searchToolLimit+searchAdapterLimit+4) + section := func(index int, title string) { + rows = append(rows, row{special: rowSection, hit: sectionHit + index, title: title}) + } + if len(pages) > 0 { + section(sectionPages, i18n.Shared(language, "desktop.buildSettings.searchPages")) + rows = append(rows, pages...) + } + if t := w.toolchains; t.available() && t.searchReady(w.query) { + scope := t.current() + matched := 0 + for _, projected := range t.search.view.Rows { + entry := t.search.entry(projected) + if entry == nil { + continue + } + if matched == 0 { + section(sectionTools, i18n.Shared(language, "desktop.buildSettings.searchTools")) + } + if matched < searchToolLimit { + tool := &entry.tool + rows = append(rows, row{ + special: rowTool, hit: toolHit + matched, title: toolchainName(tool), ref: tool.ID, + status: projected.Status, path: toolchainPluginName(scope, tool.PluginID, tool.PluginName), + }) + } + matched++ + } + if matched > searchToolLimit { + rows = append(rows, row{special: rowAllTools, hit: allToolsHit, overflow: matched}) + } + } + if s := w.stepping; s.available() && s.loaded { + shown := 0 + for _, adapter := range s.adapters { + if shown == searchAdapterLimit { + break + } + if !strings.Contains(strings.ToLower(adapter.Name), w.query) && !strings.Contains(strings.ToLower(steppingPluginName(adapter)), w.query) { + continue + } + if shown == 0 { + section(sectionDebuggers, i18n.Shared(language, "desktop.buildSettings.searchDebuggers")) + } + rows = append(rows, row{special: rowAdapter, hit: adapterHit + shown, title: adapter.Name, ref: adapter.ID, path: i18n.Shared(language, "desktop.buildSettings.steppingTab")}) + shown++ + } + } + // Pages alone need no heading: the search reads as it did before tools and debuggers joined. + if len(pages) > 0 && len(rows) == len(pages)+1 { + return rows[1:] + } + return rows +} + +// chooseSearchRow opens what a row of the search's sections stands for and ends the search. +// It reports whether the row was one; a page's row opens as it does outside a search. +func (w *window) chooseSearchRow(r row) bool { + switch r.special { + case rowSection: + return true + case rowTool: + t := w.toolchains + t.reveal(r.ref, t.searchGroup(r.ref)) + w.openBuildChild(pageToolchains) + case rowAllTools: + w.toolchains.showMatches(w.query) + w.openBuildChild(pageToolchains) + case rowAdapter: + w.stepping.selected, w.stepping.query, w.stepping.add = r.ref, "", "" + w.openBuildChild(pageDebuggers) + default: + return false + } + w.clearSearch() + return true +} + +// openBuildChild shows a page under Build, Execution, Deployment with Build expanded, so its +// row is on the screen once the search ends. +func (w *window) openBuildChild(page pageID) { + w.folderPage = "" + w.sess.open[pageBuild] = true + w.selectSettingsPage(page, "") +} diff --git a/desktop/internal/settingswindow/build_style.go b/desktop/internal/settingswindow/build_style.go new file mode 100644 index 000000000..04007582a --- /dev/null +++ b/desktop/internal/settingswindow/build_style.go @@ -0,0 +1,543 @@ +package settingswindow + +import ( + "strconv" + "strings" + "unicode" + "unicode/utf8" + + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// The Build, Execution, Deployment pages follow the design prototype +// docs/design/build-execution-settings.html value for value: its colors, sizes and +// spacings are the constants and the palette below. The window around them keeps the +// metrics of every other settings page. + +// buildPalette is the prototype's colors in one look. +type buildPalette struct { + // surface is the page, side the sidebar and the group headers of a list, sel a chosen + // row and hover a row under the pointer. + surface, side, sel, hover gfx.Color + // text is ordinary text, sub secondary text and faint hints and counts. + text, sub, faint gfx.Color + // line separates regions and outlines cards and controls. + line gfx.Color + // accent marks what is on, chosen or changed; ok, warn and err are the three states + // of a tool. + accent, ok, warn, err gfx.Color + // pill is the ground of a chip, a tag and the segmented control, chip the ground of + // one that is on. + pill, chip gfx.Color + // switchOff is the track of a switch that is off. + switchOff gfx.Color + // tagGreen, tagWarn and tagErr are the grounds of the colored tags. + tagGreen, tagWarn, tagErr gfx.Color + // press is a row of the issue list under the pointer. + press gfx.Color + // boxes are the notice boxes, by kind. + boxes [boxKinds]boxColors + white gfx.Color +} + +// boxColors are a notice box's outline, ground and words. +type boxColors struct { + border, background, text gfx.Color +} + +// The kinds of notice box. +const ( + boxWarn = iota + boxErr + boxNext + boxInfo + boxKinds +) + +// The kinds of tag. +const ( + tagPlain = iota + tagBlue + tagGreen + tagWarn + tagErr + tagSource +) + +func buildPaletteFor(dark bool) buildPalette { + if dark { + b := buildPalette{ + surface: gfx.RGB24(0x2b2d30), side: gfx.RGB24(0x26282b), sel: gfx.RGB24(0x2e436e), hover: gfx.RGB24(0x33363a), + text: gfx.RGB24(0xdfe1e5), sub: gfx.RGB24(0x9da0a8), faint: gfx.RGB24(0x6f737a), line: gfx.RGB24(0x3a3d41), + accent: gfx.RGB24(0x548af7), ok: gfx.RGB24(0x5fb865), warn: gfx.RGB24(0xe0a83e), err: gfx.RGB24(0xf0716a), + pill: gfx.RGB24(0x393b40), chip: gfx.RGB24(0x25324d), switchOff: gfx.RGB24(0x55585e), + tagGreen: gfx.RGB24(0x22382a), tagWarn: gfx.RGB24(0x3d3220), tagErr: gfx.RGB24(0x45282a), + press: gfx.RGBA(255, 255, 255, 0.04), white: gfx.RGB24(0xffffff), + } + b.boxes = [boxKinds]boxColors{ + boxWarn: {border: gfx.RGB24(0x5c4a24), background: gfx.RGB24(0x3a301d), text: gfx.RGB24(0xe8c47a)}, + boxErr: {border: gfx.RGB24(0x5f3532), background: gfx.RGB24(0x3d2524), text: gfx.RGB24(0xf2a39c)}, + boxNext: {border: gfx.RGB24(0x36507e), background: gfx.RGB24(0x22314d), text: gfx.RGB24(0xa9c3f5)}, + boxInfo: {border: b.line, background: b.pill, text: b.sub}, + } + return b + } + b := buildPalette{ + surface: gfx.RGB24(0xffffff), side: gfx.RGB24(0xf2f3f5), sel: gfx.RGB24(0xdfe7f8), hover: gfx.RGB24(0xeceef1), + text: gfx.RGB24(0x1f2329), sub: gfx.RGB24(0x6c707e), faint: gfx.RGB24(0x9aa0ab), line: gfx.RGB24(0xe4e6ea), + accent: gfx.RGB24(0x3574f0), ok: gfx.RGB24(0x208a3c), warn: gfx.RGB24(0xc27d00), err: gfx.RGB24(0xd1453b), + pill: gfx.RGB24(0xeef1f6), chip: gfx.RGB24(0xe8f0fe), switchOff: gfx.RGB24(0xc4c7cd), + tagGreen: gfx.RGB24(0xe6f4ea), tagWarn: gfx.RGB24(0xfff1d6), tagErr: gfx.RGB24(0xfbe5e3), + press: gfx.RGBA(0, 0, 0, 0.04), white: gfx.RGB24(0xffffff), + } + b.boxes = [boxKinds]boxColors{ + boxWarn: {border: gfx.RGB24(0xf1d29a), background: gfx.RGB24(0xfdf6e7), text: gfx.RGB24(0x7a5400)}, + boxErr: {border: gfx.RGB24(0xf0c4c0), background: gfx.RGB24(0xfdf0ef), text: gfx.RGB24(0x8a2a22)}, + boxNext: {border: gfx.RGB24(0xbcd0f7), background: gfx.RGB24(0xeef4ff), text: gfx.RGB24(0x23468f)}, + boxInfo: {border: b.line, background: b.pill, text: b.sub}, + } + return b +} + +// The prototype's sizes. +const ( + // buildFont is the page's text, buildSmall the secondary lines and buildTiny tags and + // counts. + buildFont = 13 + buildSmall = 12 + buildTiny = 10.5 + buildMono = 11.5 + // buildHeading is a page's title. + buildHeading = 17 + // buildPagePadX and buildPagePadY are the margins of a page and of a detail pane. + buildPagePadX = 20 + buildPagePadTop = 16 + buildPagePadEnd = 30 +) + +// statusColor is the color of a tool's or a dot's state: error, warning, ok or idle. +func (b *buildPalette) statusColor(status string) gfx.Color { + switch status { + case "error": + return b.err + case "warning": + return b.warn + case "idle": + return b.faint + } + return b.ok +} + +// dot is a filled circle of size in color: a state (sdot), a change (moddot) or the mark +// of a changed row. +func dot(c ui.C, size float32, color gfx.Color) { + ui.Row(c).Size(size, size).Shrink(0).Radius(size / 2).Background(color) +} + +// badge is the count of problems at the end of a row: white on the error or the warning +// color. +func (w *window) badge(c ui.C, count int, warning bool) ui.Box { + ground := w.bp.err + if warning { + ground = w.bp.warn + } + return ui.Row(c).Height(16).MinWidth(16).PadX(5).Shrink(0).Radius(8).Background(ground).Center().Children(func() { + ui.Text(c, formatCount(count)).FontSize(10).Weight(gfx.WeightSemibold).Color(w.bp.white) + }) +} + +// tag is a small rounded label of one kind. +func (w *window) tag(c ui.C, kind int, text string) ui.Box { + b := &w.bp + ground, words := b.pill, b.sub + switch kind { + case tagBlue: + ground, words = b.chip, b.accent + case tagGreen: + ground, words = b.tagGreen, b.ok + case tagWarn: + ground, words = b.tagWarn, b.warn + case tagErr: + ground, words = b.tagErr, b.err + } + box := ui.Row(c).Shrink(0).PadX(7).PadY(1).Radius(999).Items(ui.Center) + if kind == tagSource { + box = box.Border(1, b.line) + } else { + box = box.Background(ground) + } + return box.Children(func() { + ui.Text(c, text).FontSize(buildTiny).Color(words) + }) +} + +// box is a notice: a rounded box in the colors of its kind. Its sentence is a boxText, +// which takes the room the buttons after it leave and wraps inside it. +func (w *window) box(c ui.C, kind int, body func(words gfx.Color)) ui.Box { + colors := w.bp.boxes[kind] + return ui.Row(c).FillWidth().MinWidth(0).Shrink(0).PadX(10).PadY(8).Gap(8).Items(ui.Center).Radius(8). + Border(1, colors.border).Background(colors.background).Children(func() { body(colors.text) }) +} + +// boxText is the sentence of a notice box. +func boxText(c ui.C, text string, words gfx.Color) ui.Box { + return ui.Wrap(c, text).FontSize(buildSmall).LineHeight(18.5).Color(words).Grow(1).Shrink(1).MinWidth(0) +} + +// boxIcon is the glyph a notice box starts with. +func boxIcon(c ui.C, icon gfx.Icon, color gfx.Color) { + ui.Icon(c, icon).Size(14, 14).Color(color).Shrink(0) +} + +// section is a card of the detail pane: its title row, with help and trailing controls, +// over its body. The body sets its own margins, as each card of the prototype does. +func (w *window) section(c ui.C, title, help string, trailing func(), body func()) ui.Box { + b := &w.bp + return ui.Column(c).FillWidth().MinWidth(0).Shrink(0).Radius(10).Border(1, b.line).Background(b.surface).Children(func() { + ui.Row(c).FillWidth().PadSides(10, 12, 6, 12).Gap(6).Items(ui.Center).Children(func() { + ui.Text(c, title).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Shrink(1).Ellipsis() + if help != "" { + w.infoButton(c.Part("help"), help) + } + ui.Spacer(c) + if trailing != nil { + trailing() + } + }) + ui.Column(c).FillWidth().MinWidth(0).Children(body) + }) +} + +// buttonKind is how a button of the Build pages looks. +type buttonKind int + +const ( + // buttonPlain is outlined on the page's ground; buttonSmall the same, smaller. + buttonPlain buttonKind = iota + buttonSmall + // buttonLink is accent words without a frame; buttonLinkSmall the same, smaller. + buttonLink + buttonLinkSmall + // buttonPrimary is white words on the accent. + buttonPrimary +) + +// button declares a button of the Build pages and reports whether it was pressed. A +// disabled one is dimmed and never reports a press. +func (w *window) button(c ui.C, kind buttonKind, label string, disabled bool) bool { + return w.buttonTip(c, kind, label, "", disabled) +} + +// buttonTip is a button with a tip that says what it does, empty for none. +func (w *window) buttonTip(c ui.C, kind buttonKind, label, tip string, disabled bool) bool { + b := &w.bp + box := ui.ButtonBase(c, label).Shrink(0).Radius(6).Items(ui.Center).Justify(ui.Center) + if tip != "" { + box = box.Tooltip(tip) + } + words, size := b.text, float32(buildFont) + switch kind { + case buttonPlain: + box = box.PadX(12).PadY(4).Border(1, b.line).Background(b.surface).Hover(ui.Look{}.Background(b.hover)) + case buttonSmall: + box = box.PadX(9).PadY(2).Border(1, b.line).Background(b.surface).Hover(ui.Look{}.Background(b.hover)) + size = buildSmall + case buttonLink: + box = box.PadX(4).PadY(2).Hover(ui.Look{}.Background(b.hover)) + words = b.accent + case buttonLinkSmall: + box = box.PadX(4).PadY(2).Hover(ui.Look{}.Background(b.hover)) + words, size = b.accent, buildSmall + case buttonPrimary: + box = box.PadX(12).PadY(4).Border(1, b.accent).Background(b.accent).Hover(ui.Look{}.Opacity(0.92)) + words = b.white + } + if disabled { + box = box.Disabled(true).Opacity(0.45) + } + clicked := box.Clicked() + box.Children(func() { + ui.Text(c, label).FontSize(size).Color(words) + }) + return clicked && !disabled +} + +// iconButton is a 26-point square button holding a glyph, with its words as a tip. +func (w *window) iconButton(c ui.C, icon gfx.Icon, label string, disabled bool) bool { + b := &w.bp + box := ui.ButtonBase(c, label).Size(26, 26).Shrink(0).Radius(6).Center().Hover(ui.Look{}.Background(b.hover)).Tooltip(label) + if disabled { + box = box.Disabled(true).Opacity(0.45) + } + clicked := box.Clicked() + box.Children(func() { + ui.Icon(c, icon).Size(14, 14).Color(b.sub) + }) + return clicked && !disabled +} + +// filterField is a field of the prototype's look: a frame with the search glyph in front +// of the words. It returns the field's box, whose Submitted reports Enter. +func (w *window) filterField(c ui.C, value *string, label, placeholder string, glyph bool) ui.Box { + b := &w.bp + var field ui.Box + ui.Row(c).FillWidth().MinWidth(0).Height(26).PadX(8).Gap(6).Items(ui.Center).Radius(6).Border(1, b.line).Background(b.surface).Children(func() { + if glyph { + ui.Icon(c, icons.Search).Size(12, 12).Color(b.faint).Shrink(0) + } + field = ui.TextFieldBase(c, value, label, placeholder).Grow(1).Shrink(1).MinWidth(0).FillHeight().FontSize(buildFont).Color(b.text) + }) + return field +} + +// chip is a filter chip with its count: on, it takes the accent. A dot of the problems' +// color follows the count where one is given. It reports a press. +func (w *window) chip(c ui.C, label string, count int, on bool, mark *gfx.Color) bool { + b := &w.bp + ground, words, counted, border := b.pill, b.sub, b.text, gfx.Color{} + if on { + ground, words, counted, border = b.chip, b.accent, b.accent, b.accent + } + box := ui.ButtonBase(c, label).Shrink(0).PadX(9).PadY(2).Gap(5).Radius(999).Items(ui.Center).Background(ground).Border(1, border) + clicked := box.Clicked() + box.Children(func() { + ui.Text(c, label).FontSize(buildSmall).Color(words) + ui.Text(c, formatCount(count)).FontSize(buildSmall).Weight(gfx.WeightSemibold).Color(counted) + if mark != nil { + ui.Text(c, "●").FontSize(buildSmall).Color(*mark) + } + }) + return clicked +} + +// segment is one choice of a segmented control. +type segment struct { + value, label string + // changed shows the accent dot after the label. + changed bool + disabled bool + // tip is the segment's tooltip, the reason a disabled one is off. + tip string +} + +// segmented is the prototype's segmented control: the chosen segment raised on the pill. +// A press of another segment writes its value into value and reports true. +func (w *window) segmented(c ui.C, value *string, segments []segment) bool { + b := &w.bp + changed := false + ui.Row(c).Shrink(0).Pad(2).Radius(7).Background(b.pill).Items(ui.Center).Children(func() { + for _, s := range segments { + k := c.Key(s.value) + on := *value == s.value + box := ui.ButtonBase(k, s.label).Shrink(0).PadX(12).PadY(3).Radius(5).Items(ui.Center) + words := b.sub + if on { + box = box.Background(b.surface).Shadow(gfx.ShadowXS) + words = b.text + } + if s.disabled { + box = box.Disabled(true).Opacity(0.45) + } + if box.Clicked() && !on && !s.disabled { + *value, changed = s.value, true + } + box.Children(func() { + ui.Text(k, s.label).FontSize(buildFont).Color(words) + if s.changed { + ui.Row(k).Size(5, 1).Shrink(0) + dot(k, 6, b.accent) + } + }) + } + }) + return changed +} + +// tabsBar is the row of tabs over a detail: the open one underlined in the accent. A +// disabled tab is dimmed with its reason as a tip. It reports whether a press opened +// another tab. +func (w *window) tabsBar(c ui.C, tabs []segment, open *string) bool { + b := &w.bp + changed := false + ui.Column(c).FillWidth().Shrink(0).Children(func() { + ui.Row(c).FillWidth().Gap(2).Children(func() { + for _, t := range tabs { + k := c.Key(t.value) + on := t.value == *open + box := ui.ButtonBase(k, t.label).Shrink(0) + if t.disabled { + box = box.Disabled(true).Opacity(0.45) + } + if t.tip != "" { + box = box.Tooltip(t.tip) + } + if box.Clicked() && !on && !t.disabled { + *open, changed = t.value, true + } + box.Children(func() { + ui.Column(k).Children(func() { + words, weight := b.sub, float32(0) + if on { + words, weight = b.text, gfx.WeightSemibold + } + ui.Row(k).PadX(12).PadY(6).Children(func() { + ui.Text(k, t.label).FontSize(buildFont).Weight(weight).Color(words) + }) + underline := gfx.Color{} + if on { + underline = b.accent + } + ui.Row(k).FillWidth().Height(2).Background(underline) + }) + }) + } + }) + ui.Row(c).FillWidth().Height(1).Background(b.line) + }) + return changed +} + +// pluginTile is the rounded square that stands for a plugin: a short abbreviation of its +// name in white on a color derived from the name, so one plugin keeps one tile +// everywhere. size is 20, 28 or 40. +func (w *window) pluginTile(c ui.C, name string, size float32) { + w.tile(c, nameColor(name), name, size) +} + +// tile is a rounded square in color holding the abbreviation of name: a tool's tile is +// its plugin's color with the tool's own name. +func (w *window) tile(c ui.C, color gfx.Color, name string, size float32) { + radius, font := float32(7), float32(11) + switch { + case size <= 20: + radius, font = 5, 9 + case size >= 40: + radius, font = 10, 14 + } + ui.Row(c).Size(size, size).Shrink(0).Radius(radius).Background(color).Center().Children(func() { + ui.Text(c, nameAbbreviation(name)).FontSize(font).Weight(gfx.WeightBold).Color(w.bp.white) + }) +} + +// glyphTile is the rounded square of a fixed entry of the Build pages: an icon in white +// on its color. +func (w *window) glyphTile(c ui.C, color gfx.Color, icon gfx.Icon, size float32) { + radius, glyph := float32(7), float32(14) + if size <= 20 { + radius, glyph = 5, 11 + } + ui.Row(c).Size(size, size).Shrink(0).Radius(radius).Background(color).Center().Children(func() { + ui.Icon(c, icon).Size(glyph, glyph).Color(w.bp.white) + }) +} + +// The tiles of the fixed entries. +var ( + toolchainsTile = gfx.RGB24(0x30a46c) + debuggersTile = gfx.RGB24(0xe5484d) + kindTile = gfx.RGB24(0x3e7bfa) +) + +// nameColor is the hue of a name, hsl(h, 52%, 46%) with h a hash of its characters, as +// the prototype computes it. +func nameColor(name string) gfx.Color { + h := 0 + for _, r := range name { + h = (h*31 + int(r)) % 360 + } + return hsl(float64(h), 0.52, 0.46) +} + +// hsl converts a hue in degrees and a saturation and lightness from 0 to 1 to a color. +func hsl(h, s, l float64) gfx.Color { + chroma := (1 - abs(2*l-1)) * s + hp := h / 60 + x := chroma * (1 - abs(mod2(hp)-1)) + var r, g, b float64 + switch { + case hp < 1: + r, g = chroma, x + case hp < 2: + r, g = x, chroma + case hp < 3: + g, b = chroma, x + case hp < 4: + g, b = x, chroma + case hp < 5: + r, b = x, chroma + default: + r, b = chroma, x + } + m := l - chroma/2 + channel := func(v float64) uint8 { return uint8(min(max((v+m)*255+0.5, 0), 255)) } + return gfx.RGB(channel(r), channel(g), channel(b)) +} + +func abs(v float64) float64 { + if v < 0 { + return -v + } + return v +} + +// mod2 is v modulo 2 for a non-negative v. +func mod2(v float64) float64 { + for v >= 2 { + v -= 2 + } + return v +} + +// nameAbbreviation is the words on a plugin's tile: its first word without "Support", +// whole when it has at most three characters, else its capital initial and second +// letter. +func nameAbbreviation(name string) string { + cleaned := strings.Map(func(r rune) rune { + if r < unicode.MaxASCII && (unicode.IsLetter(r) || unicode.IsDigit(r) || r == '.' || r == '+' || r == ' ') { + return r + } + return ' ' + }, strings.ReplaceAll(name, "Support", "")) + words := strings.Fields(cleaned) + if len(words) == 0 { + runes := []rune(name) + return string(runes[:min(2, len(runes))]) + } + first := []rune(words[0]) + if len(first) <= 3 { + return string(first) + } + return strings.ToUpper(string(first[0])) + string(first[1]) +} + +// formatCount writes a count with a comma between each three digits, as the prototype +// does in both languages. +func formatCount(n int) string { + digits := strconv.Itoa(n) + sign := "" + if n < 0 { + sign, digits = "-", digits[1:] + } + var out strings.Builder + for i, r := range digits { + if i > 0 && (len(digits)-i)%3 == 0 { + out.WriteByte(',') + } + out.WriteRune(r) + } + return sign + out.String() +} + +// midTrim shortens s to at most limit characters by cutting its middle, so both the +// start and the end of a path stay readable. +func midTrim(s string, limit int) string { + if utf8.RuneCountInString(s) <= limit || limit < 3 { + return s + } + runes := []rune(s) + head := (limit - 1) / 2 + tail := limit - 1 - head + return string(runes[:head]) + "…" + string(runes[len(runes)-tail:]) +} diff --git a/desktop/internal/settingswindow/controller.go b/desktop/internal/settingswindow/controller.go index 0d41dfdb7..c5d81afce 100644 --- a/desktop/internal/settingswindow/controller.go +++ b/desktop/internal/settingswindow/controller.go @@ -137,9 +137,13 @@ type Values struct { // SteppingAdapter is an installed debug adapter that takes stepping filters: its ID, the // name the page shows and the defaults its plugin declares. type SteppingAdapter struct { - ID string - Name string - Defaults core.DebugSteppingFilters + ID string + Name string + // PluginID and PluginName name the plugin that declares the adapter; + // PluginName is empty when the manifest has no display name. + PluginID string + PluginName string + Defaults core.DebugSteppingFilters } // ProcessTermination is the part of Core's process termination settings this client @@ -213,6 +217,13 @@ type ToolchainInspector interface { Inspect(context.Context, toolchain.Snapshot, string, string) (core.ToolchainSelection, error) } +// ToolchainViewer asks Core for the Toolchains list projection: which rows show +// under the query, how they group and fold, the first problems and the counts. +// A loader without it shows the list unfiltered and ungrouped. +type ToolchainViewer interface { + SettingsView(context.Context, core.ToolchainSettingsViewRequest) (core.ToolchainSettingsView, error) +} + // ToolchainTrustLoader updates machine-local permission to probe and run tool // environments or wrappers inside the open project, then reloads its snapshot. type ToolchainTrustLoader interface { diff --git a/desktop/internal/settingswindow/model.go b/desktop/internal/settingswindow/model.go index db16bd889..6a12cd251 100644 --- a/desktop/internal/settingswindow/model.go +++ b/desktop/internal/settingswindow/model.go @@ -30,7 +30,12 @@ const ( // The pages on the top level of the sidebar. pagePlugins pageVersionControl + // pageBuild is the group "Build, Execution, Deployment", which also has a page of its + // own: the directory of its pages and what needs attention. The two pages after it + // belong to it, and so do the build system and compiler pages plugins contribute. pageBuild + pageToolchains + pageDebuggers pageLanguages // pageTools is the group "Tools"; the page after it belongs to it. pageTools @@ -61,6 +66,8 @@ var parents = [pageCount]pageID{ pagePlugins: noPage, pageVersionControl: noPage, pageBuild: noPage, + pageToolchains: pageBuild, + pageDebuggers: pageBuild, pageLanguages: noPage, pageTools: noPage, pageTerminal: pageTools, @@ -91,6 +98,10 @@ func isGroup(id pageID) bool { return false } +// ownsPage says whether the group id also opens a page of its own when its row is +// chosen, instead of only expanding and collapsing. +func ownsPage(id pageID) bool { return id == pageBuild } + // titleOf is the name of an entry in the language of messages. func titleOf(messages *i18n.SettingsMessages, id pageID) string { switch id { @@ -114,6 +125,10 @@ func titleOf(messages *i18n.SettingsMessages, id pageID) string { return messages.VersionControl case pageBuild: return messages.Build + case pageToolchains: + return messages.Toolchains + case pageDebuggers: + return messages.Debuggers case pageLanguages: return messages.Languages case pageTools: @@ -138,13 +153,62 @@ type row struct { title string hit int page pageID - // level is 0 on the top level and 1 for a page inside a group. + // level is 0 on the top level, 1 for a page inside a group and 2 for a page inside + // a folder of a group. level uint8 // group says the row is a group, which has a chevron and expands instead of // opening a page; expanded says its pages are listed under it. group, expanded bool + // folder is the kind of plugin pages the row is the folder of, or the folder an + // overflow row opens. A folder row has a chevron and opens the folder's page. + folder string + // overflow is how many pages the folder has when the row stands for the ones the + // sidebar leaves out; choosing it opens the folder's page. count is how many pages a + // folder's row holds. + overflow, count int + // path is where a search match lives, its ancestors' titles joined by " › ", + // shown after its title. A string keeps a row comparable. + path string + // special is what a row of the search's sections stands for other than a page: a + // section's title, a tool of the Toolchains page, a debugger, or the row that lists + // every matching tool. ref is the tool's or the debugger's ID, status the tool's state. + special rowKind + ref, status string } +// rowKind is what a sidebar row stands for besides a page. +type rowKind uint8 + +const ( + rowPage rowKind = iota + rowSection + rowTool + rowAdapter + rowAllTools +) + +// The search's sections: the settings pages, the tools of the Toolchains page and the +// debuggers, in that order. +const ( + sectionPages = iota + sectionTools + sectionDebuggers +) + +// The keys of the rows that are not a page of the table nor a plugin's page. They are past +// any count of plugin pages and stay inside the list's non-negative 31-bit keys. +const ( + // folderHit is a folder's row; the row after it, folderHit+1, is the folder's row of + // the pages the sidebar leaves out. + folderHit = 1 << 28 + // sectionHit is a section's title; allToolsHit the row listing every matching tool. + sectionHit = folderHit + 64 + allToolsHit = sectionHit + 16 + // toolHit and adapterHit are the rows of a tool and a debugger, by their place. + toolHit = 1 << 29 + adapterHit = toolHit + 1<<20 +) + // foldQuery turns what the user typed into what titles are compared with: without the // spaces around it and in lower case, so a search ignores case. An empty result lists // every page. @@ -196,13 +260,24 @@ func appendVisible(dst []row, messages *i18n.SettingsMessages, open *[pageCount] return dst } +// crumb is one title of the breadcrumb and what choosing it opens: a page, or the page of a +// folder of kind under Build, Execution, Deployment. link is set on a title before the last +// that has a page of its own to open. +type crumb struct { + title string + page pageID + folder string + link bool +} + // appendBreadcrumb appends the titles that lead to id to dst and returns it: the group and -// then the page for a page inside a group, and the title alone for any other entry. -func appendBreadcrumb(dst []string, messages *i18n.SettingsMessages, id pageID) []string { +// then the page for a page inside a group, and the title alone for any other entry. The group +// links to its page when it has one. +func appendBreadcrumb(dst []crumb, messages *i18n.SettingsMessages, id pageID) []crumb { if parent := parents[id]; parent != noPage { - dst = append(dst, titleOf(messages, parent)) + dst = append(dst, crumb{title: titleOf(messages, parent), page: parent, link: ownsPage(parent)}) } - return append(dst, titleOf(messages, id)) + return append(dst, crumb{title: titleOf(messages, id), page: id}) } // contributedParent is the entry a plugin's settings page of kind is listed under: build @@ -215,6 +290,51 @@ func contributedParent(kind string) pageID { return pageLanguages } +// buildKinds are the kinds of plugin pages under Build, Execution, Deployment, in the +// order the sidebar and the Build page list them. +var buildKinds = [...]string{"buildSystem", "compiler"} + +const ( + // folderMin is how many pages of one kind fold into a folder of their own; fewer are + // listed under Build, Execution, Deployment directly, as the settings hierarchy Note + // says. + folderMin = 3 + // folderLimit is how many of a folder's pages the sidebar lists; the rest are on the + // folder's page. + folderLimit = 6 +) + +// kindIndex is the place of kind in buildKinds, or -1 for another kind. +func kindIndex(kind string) int { + for index, k := range buildKinds { + if k == kind { + return index + } + } + return -1 +} + +// kindTitle names a kind of plugin pages: the folder's title and its page's. +func kindTitle(language i18n.Language, kind string) string { + if kind == "compiler" { + return i18n.Shared(language, "desktop.buildSettings.kindCompiler") + } + return i18n.Shared(language, "desktop.buildSettings.kindBuildSystem") +} + +// pageKeywords are the words besides its title a search finds a page by. +func pageKeywords(language i18n.Language, id pageID) string { + switch id { + case pageBuild: + return i18n.Shared(language, "desktop.buildSettings.keywordsBuild") + case pageToolchains: + return i18n.Shared(language, "desktop.buildSettings.keywordsToolchains") + case pageDebuggers: + return i18n.Shared(language, "desktop.buildSettings.keywordsDebuggers") + } + return "" +} + // toggleGroup expands a collapsed group and collapses an expanded one. It does nothing // while a search is under way, because the search has expanded every group it lists and // the row would otherwise appear to ignore the click, nor for an entry that is not a @@ -366,7 +486,7 @@ func newSession(current Values) *session { // screen. An entry that is a group or does not exist is left alone: a group has no page of // its own. func (s *session) show(page pageID) { - if page >= pageCount || isGroup(page) { + if page >= pageCount || (isGroup(page) && !ownsPage(page)) { return } s.page = page @@ -451,7 +571,7 @@ func decideKey(key keyKind, ctx keyContext) keyAction { } func (r row) hitIndex() int { - if r.dynamic != "" { + if r.dynamic != "" || r.folder != "" || r.special != rowPage { return r.hit } return int(r.page) diff --git a/desktop/internal/settingswindow/page_driver_test.go b/desktop/internal/settingswindow/page_driver_test.go index 427a4cdae..977ea9369 100644 --- a/desktop/internal/settingswindow/page_driver_test.go +++ b/desktop/internal/settingswindow/page_driver_test.go @@ -2,6 +2,7 @@ package settingswindow import ( "runtime" + "strings" "testing" "time" @@ -43,6 +44,18 @@ func (d *windowDriver) find(label string) (gfx.Hit, bool) { return gfx.Hit{}, false } +// first returns the back-most control labeled label, the one drawn first. +func (d *windowDriver) first(label string) gfx.Hit { + d.t.Helper() + for _, hit := range d.driver.Snapshot().Hits { + if hit.Label == label && !hit.IsLabel && !hit.Backdrop && !hit.ID.IsZero() { + return hit + } + } + d.t.Fatalf("no control labeled %q", label) + return gfx.Hit{} +} + func (d *windowDriver) hit(label string) gfx.Hit { d.t.Helper() hit, ok := d.find(label) @@ -101,6 +114,16 @@ func (d *windowDriver) text(value string) bool { return false } +// wrapped reports whether the frame's labels, read in order, hold value, which a wrapping +// text splits over several labels. +func (d *windowDriver) wrapped(value string) bool { + var lines []string + for _, label := range d.driver.Snapshot().Labels { + lines = append(lines, label.Value) + } + return strings.Contains(strings.Join(lines, " "), value) +} + // until pumps the window until cond holds, within a bounded time. It wakes the window each // round itself: the headless Driver binds its Invalidator after the first paint, so a request // that finished during the first paint wakes nobody. diff --git a/desktop/internal/settingswindow/settings_surfaces.go b/desktop/internal/settingswindow/settings_surfaces.go index 895f91601..2c33e47b2 100644 --- a/desktop/internal/settingswindow/settings_surfaces.go +++ b/desktop/internal/settingswindow/settings_surfaces.go @@ -4,6 +4,7 @@ import ( "context" "errors" "strconv" + "strings" "sync" "time" @@ -147,12 +148,32 @@ func (s *settingsSurfaces) run(parent context.Context) (surfacesResult, error) { value := "static:" + strconv.Itoa(int(parents[id])) parent = &value } - items = append(items, core.SettingsNavigationItem{ID: name, Title: titleOf(&key.text.Settings, id), Parent: parent, Group: isGroup(id) || contributed[id], Expanded: key.open[id]}) + items = append(items, core.SettingsNavigationItem{ID: name, Title: titleOf(&key.text.Settings, id), Parent: parent, Group: isGroup(id) || contributed[id], Expanded: key.open[id], Keywords: pageKeywords(job.language, id)}) lookup[name] = row{page: id} } + // The build system and compiler pages of one kind fold into a folder once there are + // folderMin of them: the sidebar lists its first folderLimit and the folder's own page + // lists them all (build_directory_view.go). + kinds := make(map[string]int) + for _, page := range result.pages { + kinds[page.Kind]++ + } + buildID := "static:" + strconv.Itoa(int(pageBuild)) + for index, kind := range buildKinds { + if kinds[kind] < folderMin { + continue + } + name := "folder:" + kind + title := kindTitle(job.language, kind) + items = append(items, core.SettingsNavigationItem{ID: name, Title: title, Parent: &buildID, Group: true, Expanded: key.folders[index], Limit: folderLimit}) + lookup[name] = row{page: pageBuild, folder: kind, title: title, hit: folderHit + 2*index, count: kinds[kind]} + } for index, page := range result.pages { parent := contributedParent(page.Kind) parentID := "static:" + strconv.Itoa(int(parent)) + if parent == pageBuild && kinds[page.Kind] >= folderMin { + parentID = "folder:" + page.Kind + } name := "page:" + page.Key items = append(items, core.SettingsNavigationItem{ID: name, Title: page.Title, Parent: &parentID}) lookup[name] = row{page: parent, dynamic: page.Key, title: page.Title, hit: int(pageCount) + index} @@ -164,6 +185,8 @@ func (s *settingsSurfaces) run(parent context.Context) (surfacesResult, error) { if !errors.Is(err, context.Canceled) { reportSettingsError(opts, pluginSettingsOperation, err) } + } else if key.query != "" { + result.rows = searchRows(projected, lookup) } else { for _, item := range projected { r, ok := lookup[item.ID] @@ -173,12 +196,42 @@ func (s *settingsSurfaces) run(parent context.Context) (surfacesResult, error) { r.group = item.Group r.expanded = item.Expanded r.level = item.Level + if item.Overflow > 0 { + // The row that stands for the pages the folder leaves out opens the folder. + r.group, r.expanded, r.overflow, r.hit = false, false, item.Overflow, r.hit+1 + } result.rows = append(result.rows, r) } } return result, nil } +// searchRows lists a search's hits flat, as the prototype does: every page the search matched +// or that is under a match, with the titles of its ancestors as its path. A group without a +// page of its own is only a path, since its pages are listed. +func searchRows(projected []core.SettingsNavigationRow, lookup map[string]row) []row { + var rows []row + var matched []bool + for _, item := range projected { + level := int(item.Level) + matched = append(matched[:min(level, len(matched))], item.Matched) + inside := item.Matched + for _, above := range matched[:level] { + inside = inside || above + } + r, ok := lookup[item.ID] + if !ok || !inside || item.Overflow > 0 { + continue + } + if r.dynamic == "" && r.folder == "" && isGroup(r.page) && !ownsPage(r.page) { + continue + } + r.path = strings.Join(item.Path, " › ") + rows = append(rows, r) + } + return rows +} + // take applies the finished request on the window thread at the start of a paint and // reports whether the sidebar's rows changed. func (s *settingsSurfaces) take() bool { @@ -203,6 +256,17 @@ func (s *settingsSurfaces) declare(c ui.C) { } } +// kindCount is how many plugin pages of kind the catalog has. +func (s *settingsSurfaces) kindCount(kind string) int { + count := 0 + for index := range s.pages { + if s.pages[index].Kind == kind { + count++ + } + } + return count +} + func (s *settingsSurfaces) selected(key string) *core.SettingsPage { if index, ok := s.pageIndices[key]; ok { return &s.pages[index] diff --git a/desktop/internal/settingswindow/settingswindow_test.go b/desktop/internal/settingswindow/settingswindow_test.go index ee1d042e1..3030be0d7 100644 --- a/desktop/internal/settingswindow/settingswindow_test.go +++ b/desktop/internal/settingswindow/settingswindow_test.go @@ -52,9 +52,9 @@ func TestParentsTableKeepsGroupsBesideTheirPages(t *testing.T) { } } -func TestOnlyAppearanceToolsAndAIAreGroups(t *testing.T) { +func TestOnlyAppearanceBuildToolsAndAIAreGroups(t *testing.T) { for id := pageID(0); id < pageCount; id++ { - if got, want := isGroup(id), id == pageAppearance || id == pageTools || id == pageAI; got != want { + if got, want := isGroup(id), id == pageAppearance || id == pageBuild || id == pageTools || id == pageAI; got != want { t.Errorf("isGroup(%d) = %v, want %v", id, got, want) } } @@ -119,7 +119,7 @@ func TestDefaultSidebarListsTheTopLevelWithAppearanceExpanded(t *testing.T) { {page: pageProcessTermination, level: 1}, {page: pagePlugins}, {page: pageVersionControl}, - {page: pageBuild}, + {page: pageBuild, group: true}, {page: pageLanguages}, {page: pageTools, group: true}, {page: pageAI, group: true}, @@ -134,13 +134,13 @@ func TestCollapsedGroupHidesItsPages(t *testing.T) { var open [pageCount]bool rows := appendVisible(nil, english(), &open, "") if len(rows) != 8 { - t.Fatalf("rows = %v, want the three groups and the five pages on the top level", rows) + t.Fatalf("rows = %v, want the four groups and the four pages on the top level", rows) } for _, r := range rows { if r.level != 0 || r.expanded { t.Fatalf("row %+v should be on the top level and not expanded", r) } - if want := r.page == pageAppearance || r.page == pageTools || r.page == pageAI; r.group != want { + if want := r.page == pageAppearance || r.page == pageBuild || r.page == pageTools || r.page == pageAI; r.group != want { t.Fatalf("row %+v: group = %v, want %v", r, r.group, want) } } @@ -221,10 +221,10 @@ func TestSearchOnAGroupTitleKeepsAllItsPages(t *testing.T) { func TestSearchOnATopLevelPageListsOnlyIt(t *testing.T) { open := initialOpen() - // The query is folded, so " AI " finds the group, which names the whole group and - // keeps its pages. - rows := appendVisible(nil, english(), &open, foldQuery(" AI ")) - if want := []row{{page: pageAI, group: true, expanded: true}, {page: pageAIGeneration, level: 1}, {page: pageIDEAPI, level: 1}}; !slices.Equal(rows, want) { + // The query is folded, so " Generation " finds the page inside the AI group, and only + // it: no other page's title or keywords hold the words. + rows := appendVisible(nil, english(), &open, foldQuery(" Generation ")) + if want := []row{{page: pageAI, group: true, expanded: true}, {page: pageAIGeneration, level: 1}}; !slices.Equal(rows, want) { t.Fatalf("rows = %v, want %v", rows, want) } } @@ -298,15 +298,30 @@ func TestBreadcrumb(t *testing.T) { {pageTerminal, []string{"Tools", "Terminal"}}, {pageAbout, []string{"About"}}, } + titles := func(crumbs []crumb) []string { + out := make([]string, len(crumbs)) + for i, crumb := range crumbs { + out[i] = crumb.title + } + return out + } for _, tc := range cases { - if got := appendBreadcrumb(nil, english(), tc.page); !slices.Equal(got, tc.want) { + if got := titles(appendBreadcrumb(nil, english(), tc.page)); !slices.Equal(got, tc.want) { t.Errorf("breadcrumb of %d = %q, want %q", tc.page, got, tc.want) } } // It appends, so a buffer can be reused. - got := appendBreadcrumb([]string{"x"}, english(), pageTools) - if !slices.Equal(got, []string{"x", "Tools"}) { - t.Errorf("breadcrumb appended to a buffer = %q", got) + got := appendBreadcrumb([]crumb{{title: "x"}}, english(), pageTools) + if !slices.Equal(titles(got), []string{"x", "Tools"}) { + t.Errorf("breadcrumb appended to a buffer = %q", titles(got)) + } + // Only a group with a page of its own links to it: Build opens its directory, Tools has + // no page of its own. + if build := appendBreadcrumb(nil, english(), pageToolchains); !build[0].link || build[0].page != pageBuild || build[1].link { + t.Errorf("Toolchains breadcrumb = %+v, want Build linked", build) + } + if tools := appendBreadcrumb(nil, english(), pageTerminal); tools[0].link { + t.Errorf("Terminal breadcrumb = %+v, want Tools not linked", tools) } } diff --git a/desktop/internal/settingswindow/stepping_view.go b/desktop/internal/settingswindow/stepping_view.go index 5a0ded43e..90bd333d3 100644 --- a/desktop/internal/settingswindow/stepping_view.go +++ b/desktop/internal/settingswindow/stepping_view.go @@ -8,14 +8,30 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// steppingDraft is what the stepping card shows for one adapter before Apply: the class -// patterns as the text area holds them, one per line, and the switches. +// The Debuggers page follows the prototype docs/design/build-execution-settings.html: the +// installed debug adapters that take stepping filters on the left, the chosen one's tabs on +// the right. Its edits are drafts the window footer's Apply writes, with the Toolchains +// page's, and they take effect at the next debug session. + +const ( + // debuggerListWidth is the prototype's width of the adapter list. + debuggerListWidth = 280 + // debuggerRow is the prototype's height of an adapter row. + debuggerRow = 44 + // steppingTab is the only tab of an adapter so far; the other debug settings join it. + steppingTab = "stepping" +) + +// steppingDraft is the page's working copy of one adapter's policy: the patterns as a list +// and the switches. Viva binds a switch to the address of its value, so each draft stays at +// one address for the window's life. type steppingDraft struct { - patterns string + patterns []string skipSynthetics bool skipStaticInitializers bool skipConstructors bool @@ -24,7 +40,7 @@ type steppingDraft struct { func draftOf(filters core.DebugSteppingFilters) steppingDraft { return steppingDraft{ - patterns: strings.Join(filters.ClassNameFilters, "\n"), + patterns: slices.Clone(filters.ClassNameFilters), skipSynthetics: filters.SkipSynthetics, skipStaticInitializers: filters.SkipStaticInitializers, skipConstructors: filters.SkipConstructors, @@ -32,13 +48,13 @@ func draftOf(filters core.DebugSteppingFilters) steppingDraft { } } -// filters is the draft as a policy: one pattern per non-blank line. Core trims, sorts and -// removes duplicates when the policy is applied. +// filters is the draft as a policy: its non-blank patterns. Core trims, sorts and removes +// duplicates when the policy is applied. func (d steppingDraft) filters() core.DebugSteppingFilters { patterns := []string{} - for _, line := range strings.Split(d.patterns, "\n") { - if line = strings.TrimSpace(line); line != "" { - patterns = append(patterns, line) + for _, pattern := range d.patterns { + if pattern = strings.TrimSpace(pattern); pattern != "" { + patterns = append(patterns, pattern) } } return core.DebugSteppingFilters{ @@ -63,10 +79,10 @@ type steppingSave struct { filters core.DebugSteppingFilters } -// steppingState is the Build page's stepping card: the installed adapters that take -// stepping filters, the one shown and the drafts. Only the window thread reads or writes -// the fields. The list loads the first time the page is drawn; Apply has Core check the -// draft (debug.steppingFilters) and stores what it returns. Opening the page writes nothing. +// steppingState is the Debuggers page: the installed adapters that take stepping filters, the +// one shown, the list's query and the drafts. Only the window thread reads or writes the +// fields. The list loads the first time a page needs it; Apply has Core check a draft +// (debug.steppingFilters) and stores what it returns. Opening the page writes nothing. type steppingState struct { loadEffect *ui.EffectState[[]SteppingAdapter, int] saveEffect *ui.EffectState[steppingSave, int] @@ -79,13 +95,17 @@ type steppingState struct { adapters []SteppingAdapter selected string - // drafts are the card's edits by adapter. Viva binds a switch or text area to the - // address of its value, so each draft stays at one address while it is shown. + query string + // add is the pattern field's text; it empties when another adapter is chosen. + add string + tab string + list ui.ListState + // drafts are the working copies by adapter, made when an adapter is first shown. drafts map[string]*steppingDraft } func newSteppingState(load func(context.Context) ([]SteppingAdapter, error), normalize func(context.Context, string, core.DebugSteppingFilters) (core.DebugSteppingFilters, error)) *steppingState { - s := &steppingState{drafts: make(map[string]*steppingDraft)} + s := &steppingState{drafts: make(map[string]*steppingDraft), tab: steppingTab} if load == nil || normalize == nil { return s } @@ -109,36 +129,34 @@ func (s *steppingState) beginLoad() { s.loading, s.loadErr = true, nil } -func (s *steppingState) beginSave(adapter string, filters core.DebugSteppingFilters) { +func (s *steppingState) beginSave(adapter string, filters core.DebugSteppingFilters) bool { if !s.available() || s.saving { - return + return false } s.pending = steppingSave{adapter: adapter, filters: filters} s.saveKey++ s.saving, s.saveErr = true, nil + return true } -// take applies a finished load, and returns a finished save for the window to store. -func (s *steppingState) take() (steppingSave, bool) { +// take applies a finished load, and returns a finished save for the window to store: done +// says one finished, err that Core refused it. +func (s *steppingState) take() (saved steppingSave, err error, done bool) { if !s.available() { - return steppingSave{}, false + return steppingSave{}, nil, false } if adapters, err, ok := s.loadEffect.Take(); ok { s.loading, s.loaded, s.loadErr = false, true, err s.adapters = adapters - if len(adapters) > 0 && !slices.ContainsFunc(adapters, func(a SteppingAdapter) bool { return a.ID == s.selected }) { + if len(adapters) > 0 && s.adapter(s.selected) == nil { s.selected = adapters[0].ID } } if saved, err, ok := s.saveEffect.Take(); ok { s.saving, s.saveErr = false, err - if err == nil { - draft := draftOf(saved.filters) - s.drafts[saved.adapter] = &draft - return saved, true - } + return saved, err, true } - return steppingSave{}, false + return steppingSave{}, nil, false } func (s *steppingState) declare(c ui.C) { @@ -153,6 +171,16 @@ func (s *steppingState) declare(c ui.C) { } } +// adapter is the listed adapter with the ID, or nil. +func (s *steppingState) adapter(id string) *SteppingAdapter { + for index := range s.adapters { + if s.adapters[index].ID == id { + return &s.adapters[index] + } + } + return nil +} + // effectiveFilters is the policy adapter uses now: the user's, else its declared defaults. func (w *window) effectiveFilters(adapter SteppingAdapter) (core.DebugSteppingFilters, bool) { if filters, ok := w.sess.values.SteppingFilters[adapter.ID]; ok { @@ -161,8 +189,42 @@ func (w *window) effectiveFilters(adapter SteppingAdapter) (core.DebugSteppingFi return adapter.Defaults, false } +// steppingDraftOf is the adapter's working copy, made from its stored policy when it has none. +func (w *window) steppingDraftOf(adapter SteppingAdapter) *steppingDraft { + draft := w.stepping.drafts[adapter.ID] + if draft == nil { + effective, _ := w.effectiveFilters(adapter) + fresh := draftOf(effective) + draft = &fresh + w.stepping.drafts[adapter.ID] = draft + } + return draft +} + +// steppingChanged says whether the adapter's working copy differs from what it uses now. +func (w *window) steppingChanged(adapter SteppingAdapter) bool { + draft := w.stepping.drafts[adapter.ID] + if draft == nil { + return false + } + effective, _ := w.effectiveFilters(adapter) + return !sameFilters(draft.filters(), effective) +} + +// steppingPending are the adapters with a change to apply, in the list's order. +func (w *window) steppingPending() []string { + var ids []string + for _, adapter := range w.stepping.adapters { + if w.steppingChanged(adapter) { + ids = append(ids, adapter.ID) + } + } + return ids +} + // setSteppingFilters stores the policy of one adapter, or removes it when filters is nil, -// and hands the change to the settings owner at once. +// and hands the change to the settings owner at once. The working copy becomes the stored +// policy. func (w *window) setSteppingFilters(adapter string, filters *core.DebugSteppingFilters) { if w.sess.finished.Load() { return @@ -177,109 +239,302 @@ func (w *window) setSteppingFilters(adapter string, filters *core.DebugSteppingF stored[adapter] = *filters } w.sess.values.SteppingFilters = stored + if draft := w.stepping.drafts[adapter]; draft != nil { + if listed := w.stepping.adapter(adapter); listed != nil { + effective, _ := w.effectiveFilters(*listed) + *draft = draftOf(effective) + } + } if w.ctrl.opts.SetSteppingFilters != nil { w.ctrl.opts.SetSteppingFilters(adapter, filters) } } -// resetSteppingFilters removes every stored policy, for Restore Defaults. +// resetSteppingFilters removes every stored policy and every draft, for Restore Defaults. func (w *window) resetSteppingFilters() { for _, id := range slices.Sorted(maps.Keys(w.sess.values.SteppingFilters)) { w.setSteppingFilters(id, nil) } - clear(w.stepping.drafts) + for id, draft := range w.stepping.drafts { + if adapter := w.stepping.adapter(id); adapter != nil { + *draft = draftOf(adapter.Defaults) + } + } +} + +// beginSteppingApply starts writing one adapter's draft: a draft equal to the plugin's +// defaults removes the stored policy at once, any other goes to Core first. It reports +// whether a request is out. +func (w *window) beginSteppingApply(id string) bool { + adapter := w.stepping.adapter(id) + if adapter == nil || !w.steppingChanged(*adapter) { + return false + } + filters := w.stepping.drafts[id].filters() + if sameFilters(filters, adapter.Defaults) { + w.setSteppingFilters(id, nil) + return false + } + return w.stepping.beginSave(id, filters) } -// steppingCard is the Build page's card for the stepping filters of the installed debug -// adapters that take them: the classes not to step into, the methods to step over and -// whether the call stack collapses the frames the patterns match. A change takes effect -// at the next debug session. -func (w *window) steppingCard(c ui.C, language i18n.Language) { +// steppingFeatures are the switches of a policy with their words and help. +func steppingFeatures(language i18n.Language, draft *steppingDraft) []struct { + key, label, help string + value *bool +} { + return []struct { + key, label, help string + value *bool + }{ + {"synthetics", i18n.Shared(language, "desktop.settings.stepping.skipSynthetics"), i18n.Shared(language, "desktop.buildSettings.skipSyntheticsHelp"), &draft.skipSynthetics}, + {"static", i18n.Shared(language, "desktop.settings.stepping.skipStaticInitializers"), i18n.Shared(language, "desktop.buildSettings.skipStaticInitializersHelp"), &draft.skipStaticInitializers}, + {"constructors", i18n.Shared(language, "desktop.settings.stepping.skipConstructors"), i18n.Shared(language, "desktop.buildSettings.skipConstructorsHelp"), &draft.skipConstructors}, + {"hide", i18n.Shared(language, "desktop.settings.stepping.hideFilteredFrames"), i18n.Shared(language, "desktop.buildSettings.hideFilteredFramesHelp"), &draft.hideFilteredFrames}, + } +} + +// steppingPluginName is the name of the plugin that declares the adapter. +func steppingPluginName(adapter SteppingAdapter) string { + switch { + case adapter.PluginName != "": + return adapter.PluginName + case adapter.PluginID != "": + return adapter.PluginID + default: + // The tile needs a name to draw its letters; an adapter no plugin claims has its own. + return adapter.Name + } +} + +// debuggersPage is the Debuggers page under Build, Execution, Deployment. +func (w *window) debuggersPage(c ui.C) { s := w.stepping if !s.available() { + w.unavailablePage(c) return } + language := w.marketLanguage() s.beginLoad() - c = c.Part("stepping") - w.card(c, i18n.Shared(language, "desktop.settings.stepping.title"), i18n.Shared(language, "desktop.settings.stepping.description"), func() { - ui.Column(c).FillWidth().Gap(8).Children(func() { - switch { - case s.loading: - ui.Text(c, i18n.Shared(language, "desktop.settings.stepping.loading")).FontSize(12).Color(w.pal.muted) - return - case s.loadErr != nil && len(s.adapters) == 0: - ui.Wrap(c, i18n.SharedFormat(language, "desktop.settings.stepping.loadFailed", map[string]string{"reason": s.loadErr.Error()})).FontSize(12).Color(w.pal.danger) - return - case len(s.adapters) == 0: - ui.Wrap(c, i18n.Shared(language, "desktop.settings.stepping.none")).FontSize(12).Color(w.pal.muted) - return + b := &w.bp + switch { + case !s.loaded: + w.toolchainsEmpty(c, i18n.Shared(language, "desktop.settings.stepping.loading")) + return + case s.loadErr != nil && len(s.adapters) == 0: + w.toolchainsEmpty(c, i18n.SharedFormat(language, "desktop.settings.stepping.loadFailed", map[string]string{"reason": s.loadErr.Error()})) + return + case len(s.adapters) == 0: + w.toolchainsEmpty(c, i18n.Shared(language, "desktop.settings.stepping.none")) + return + } + width := float32(debuggerListWidth) + if room := w.extent - 1 - toolchainDetailMin; room < width { + width = max(220, room) + } + ui.Row(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Background(b.surface).Children(func() { + ui.Column(c).Width(width).Shrink(0).FillHeight().MinHeight(0).Children(func() { + ui.Row(c).FillWidth().Shrink(0).PadX(10).PadY(10).Children(func() { + label := i18n.Shared(language, "desktop.buildSettings.debuggerFilter") + w.filterField(c.Part("filter"), &s.query, label, label, true) + }) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + w.debuggerList(c.Part("list"), language) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + ui.Row(c).FillWidth().Shrink(0).PadX(12).PadY(5).Children(func() { + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.debuggerCount", map[string]string{"count": formatCount(len(s.adapters))})). + FontSize(11).Color(b.faint).Ellipsis() + }) + }) + ui.Row(c).Width(1).Shrink(0).FillHeight().Background(b.line) + ui.Scroll(c.Key("debugger:"+s.selected)).Scrollbars().Grow(1).Shrink(1).MinWidth(0).FillHeight(). + PadSides(buildPagePadTop, buildPagePadX, buildPagePadEnd, buildPagePadX).Children(func() { + if adapter := s.adapter(s.selected); adapter != nil { + w.debuggerDetail(c, language, *adapter) } - w.steppingAdapter(c, language) }) }) } -func (w *window) steppingAdapter(c ui.C, language i18n.Language) { +// debuggerList is the adapters whose name or plugin holds the query. +func (w *window) debuggerList(c ui.C, language i18n.Language) { s := w.stepping - if len(s.adapters) > 1 { - ids := make([]string, len(s.adapters)) - names := make(map[string]string, len(s.adapters)) - for i, adapter := range s.adapters { - ids[i], names[adapter.ID] = adapter.ID, adapter.Name + b := &w.bp + query := strings.ToLower(strings.TrimSpace(s.query)) + var shown []SteppingAdapter + for _, adapter := range s.adapters { + if query == "" || strings.Contains(strings.ToLower(adapter.Name), query) || strings.Contains(strings.ToLower(steppingPluginName(adapter)), query) { + shown = append(shown, adapter) } - ui.Row(c).FillWidth().Height(28).Items(ui.Center).Gap(12).Children(func() { - ui.Text(c, i18n.Shared(language, "desktop.settings.stepping.adapter")).FontSize(12).Color(w.pal.text).Grow(1).MinWidth(0).Ellipsis() - ui.Select(c.Part("adapter"), &s.selected, ids, func(id string) string { return names[id] }).Width(selectWidth). - Label(i18n.Shared(language, "desktop.settings.stepping.adapter")) - }) } - i := slices.IndexFunc(s.adapters, func(a SteppingAdapter) bool { return a.ID == s.selected }) - if i < 0 { + if len(shown) == 0 { + ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).PadSides(50, 20, 50, 20).Items(ui.Center).Children(func() { + ui.Wrap(c, i18n.Shared(language, "desktop.buildSettings.debuggerNoMatches")).FontSize(buildSmall).Color(b.faint).TextCenter() + }) return } - adapter := s.adapters[i] - effective, customized := w.effectiveFilters(adapter) - draft := s.drafts[adapter.ID] - if draft == nil { - fresh := draftOf(effective) - draft = &fresh - s.drafts[adapter.ID] = draft - } - k := c.Key(adapter.ID) - if len(s.adapters) == 1 { - ui.Text(k, adapter.Name).FontSize(12).Weight(gfx.WeightSemibold).Color(w.pal.text) - } - ui.Text(k, i18n.Shared(language, "desktop.settings.stepping.classFilters")).FontSize(12).Color(w.pal.text) - ui.TextArea(k.Part("patterns"), &draft.patterns, i18n.Shared(language, "desktop.settings.stepping.classFilters"), ""). - FillWidth().Height(140).Disabled(s.saving) - ui.Wrap(k, i18n.Shared(language, "desktop.settings.stepping.classFiltersHelp")).FontSize(11).Color(w.pal.muted) - ui.Switch(k.Part("synthetics"), &draft.skipSynthetics, i18n.Shared(language, "desktop.settings.stepping.skipSynthetics")) - ui.Switch(k.Part("static"), &draft.skipStaticInitializers, i18n.Shared(language, "desktop.settings.stepping.skipStaticInitializers")) - ui.Switch(k.Part("constructors"), &draft.skipConstructors, i18n.Shared(language, "desktop.settings.stepping.skipConstructors")) - ui.Switch(k.Part("hide"), &draft.hideFilteredFrames, i18n.Shared(language, "desktop.settings.stepping.hideFilteredFrames")) - dirty := !sameFilters(draft.filters(), effective) - ui.Row(k).FillWidth().Gap(8).Items(ui.Center).Children(func() { - status := i18n.Shared(language, "desktop.settings.stepping.usingDefaults") - if customized { - status = i18n.Shared(language, "desktop.settings.stepping.customized") + s.list.Key = nil + s.list.Header = nil + s.list.Label = func(i int) string { + if i < 0 || i >= len(shown) { + return "" + } + return shown[i].Name + } + at := slices.IndexFunc(shown, func(adapter SteppingAdapter) bool { return adapter.ID == s.selected }) + if s.list.Selected() != at { + s.list.Select(at) + if at >= 0 { + s.list.ScrollIntoView(at) + } + } + ui.List(c, &s.list, len(shown), func(r ui.ListRow) { + adapter := shown[r.Index] + k := r.C + changed := w.steppingChanged(adapter) + _, stored := w.effectiveFilters(adapter) + r.Element.Height(debuggerRow).PadSides(0, 12, 0, 14).Gap(9).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)) + if r.Selected() { + r.Element.Background(b.sel) + } + r.Element.Children(func() { + if changed { + ui.Row(k).Absolute().Left(4).Top(19).Size(6, 6).Radius(3).Background(b.accent) + } + w.pluginTile(k, steppingPluginName(adapter), 20) + ui.Column(k).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Row(k).FillWidth().Gap(6).Items(ui.Center).Children(func() { + ui.Text(k, adapter.Name).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Shrink(1).Ellipsis() + ui.Spacer(k) + if stored || changed { + w.tag(k, tagBlue, i18n.Shared(language, "desktop.settings.stepping.customized")) + } + }) + ui.Row(k).FillWidth().Height(2).Shrink(0) + ui.Text(k, steppingPluginName(adapter)).FontSize(11).Color(b.faint).Ellipsis() + }) + }) + }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(i18n.Shared(language, "desktop.buildSettings.debuggers")) + if s.list.Changed() { + if at := s.list.Selected(); at >= 0 && at < len(shown) && shown[at].ID != s.selected { + s.selected, s.add = shown[at].ID, "" } - if s.saving { - status = i18n.Shared(language, "desktop.settings.stepping.saving") + } +} + +// debuggerDetail is the prototype's adapter detail: the head with the plugin's defaults or the +// user's, the tabs and the stepping tab's patterns and switches. +func (w *window) debuggerDetail(c ui.C, language i18n.Language, adapter SteppingAdapter) { + s := w.stepping + b := &w.bp + draft := w.steppingDraftOf(adapter) + changed := w.steppingChanged(adapter) + _, stored := w.effectiveFilters(adapter) + customized := stored || changed + plugin := steppingPluginName(adapter) + ui.Column(c).FillWidth().MinWidth(0).Children(func() { + ui.Row(c).FillWidth().Gap(12).Items(ui.Start).Children(func() { + w.pluginTile(c, plugin, 40) + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Text(c, adapter.Name).FontSize(buildHeading).Weight(gfx.WeightBold).Color(b.text).Ellipsis() + ui.Row(c).Height(4).Shrink(0) + ui.Row(c).FillWidth().Gap(6).Items(ui.Center).Children(func() { + if adapter.PluginName != "" || adapter.PluginID != "" { + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.providedBy", map[string]string{"plugin": plugin})). + FontSize(buildSmall).Color(b.sub).Shrink(1).Ellipsis() + ui.Text(c, "·").FontSize(buildSmall).Color(b.sub).Shrink(0) + } + if customized { + w.tag(c, tagBlue, i18n.Shared(language, "desktop.settings.stepping.customized")) + } else { + w.tag(c, tagPlain, i18n.Shared(language, "desktop.settings.stepping.usingDefaults")) + } + }) + }) + if customized && w.button(c.Part("restore"), buttonSmall, i18n.Shared(language, "desktop.settings.stepping.restoreDefaults"), s.saving) { + *draft = draftOf(adapter.Defaults) + s.saveErr = nil + } + }) + ui.Row(c).Height(14).Shrink(0) + w.tabsBar(c.Part("tabs"), []segment{{value: steppingTab, label: i18n.Shared(language, "desktop.buildSettings.tabStepping")}}, &s.tab) + ui.Row(c).Height(12).Shrink(0) + if changed { + w.box(c.Part("next"), boxNext, func(words gfx.Color) { + dot(c, 7, b.accent) + boxText(c, i18n.Shared(language, "desktop.buildSettings.steppingPending"), words) + }) + ui.Row(c).Height(12).Shrink(0) } - ui.Text(k, status).FontSize(12).Color(w.pal.muted).Grow(1).MinWidth(0).Ellipsis() - if ui.Button(k.Part("restore"), i18n.Shared(language, "desktop.settings.stepping.restoreDefaults")).Outline(). - Disabled(s.saving || (!customized && !dirty)).Clicked() { - delete(s.drafts, adapter.ID) - s.saveErr = nil - if customized { - w.setSteppingFilters(adapter.ID, nil) + if s.saveErr != nil && s.pending.adapter == adapter.ID { + message := i18n.SharedFormat(language, "desktop.settings.stepping.saveFailed", map[string]string{"reason": s.saveErr.Error()}) + w.box(c.Part("failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + }) + ui.Row(c).Height(12).Shrink(0) + } + w.section(c.Part("patterns"), i18n.Shared(language, "desktop.buildSettings.skipCode"), i18n.Shared(language, "desktop.buildSettings.skipCodeHelp"), nil, func() { + ui.Row(c).FillWidth().MinWidth(0).PadSides(0, 12, 10, 12).Children(func() { + w.patternList(c.Part("list"), language, draft) + }) + }) + ui.Row(c).Height(12).Shrink(0) + ui.Column(c).FillWidth().MinWidth(0).Shrink(0).Radius(10).Border(1, b.line).Background(b.surface).Pad(6).Children(func() { + for _, feature := range steppingFeatures(language, draft) { + k := c.Part(feature.key) + ui.Row(k).FillWidth().MinHeight(34).PadX(8).PadY(3).Gap(10).Radius(7).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)).Children(func() { + ui.Row(k).Grow(1).Shrink(1).MinWidth(0).Gap(5).Items(ui.Center).Children(func() { + ui.Text(k, feature.label).FontSize(buildFont).Color(b.text).Shrink(1).Ellipsis() + w.infoButton(k.Part("help"), feature.help) + }) + ui.Switch(k.Part("switch"), feature.value, "").Label(feature.label).Disabled(s.saving) + }) } + }) + }) +} + +// patternList is the prototype's .lst: one row per pattern with its remove button, then the +// field that adds one. +func (w *window) patternList(c ui.C, language i18n.Language, draft *steppingDraft) { + s := w.stepping + b := &w.bp + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).Radius(8).Border(1, b.line).Children(func() { + if len(draft.patterns) == 0 { + ui.Row(c).FillWidth().PadX(8).PadY(5).Children(func() { + ui.Text(c, i18n.Shared(language, "desktop.buildSettings.noPatterns")).FontSize(buildFont).Color(b.faint) + }) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) } - if ui.Button(k.Part("apply"), i18n.Shared(language, "desktop.settings.stepping.apply")).Disabled(s.saving || !dirty).Clicked() { - s.beginSave(adapter.ID, draft.filters()) + remove := -1 + for index, pattern := range draft.patterns { + k := c.KeyInt(index) + ui.Row(k).FillWidth().MinWidth(0).PadX(8).PadY(5).Gap(8).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)).Children(func() { + ui.Text(k, pattern).FontSize(buildMono).Mono().Color(b.text).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + if w.iconButton(k.Part("remove"), icons.X, i18n.Shared(language, "desktop.buildSettings.removePattern"), s.saving) { + remove = index + } + }) + ui.Row(k).FillWidth().Height(1).Shrink(0).Background(b.line) } + if remove >= 0 { + draft.patterns = slices.Delete(slices.Clone(draft.patterns), remove, remove+1) + } + ui.Row(c).FillWidth().MinWidth(0).Pad(6).Gap(6).Items(ui.Center).Children(func() { + label := i18n.Shared(language, "desktop.buildSettings.addPattern") + var field ui.Box + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Children(func() { + field = w.filterField(c.Part("field"), &s.add, label, label, false) + }) + pattern := strings.TrimSpace(s.add) + add := w.button(c.Part("add"), buttonSmall, i18n.Shared(language, "ai.add"), pattern == "" || s.saving) + if (add || field.Submitted()) && pattern != "" && !s.saving { + if !slices.Contains(draft.patterns, pattern) { + draft.patterns = append(slices.Clone(draft.patterns), pattern) + } + s.add = "" + } + }) }) - if s.saveErr != nil { - ui.Wrap(k, i18n.SharedFormat(language, "desktop.settings.stepping.saveFailed", map[string]string{"reason": s.saveErr.Error()})).FontSize(12).Color(w.pal.danger) - } } diff --git a/desktop/internal/settingswindow/stepping_view_test.go b/desktop/internal/settingswindow/stepping_view_test.go index 8edb1244c..f7d05a4c2 100644 --- a/desktop/internal/settingswindow/stepping_view_test.go +++ b/desktop/internal/settingswindow/stepping_view_test.go @@ -14,10 +14,11 @@ type steppingChange struct { filters *core.DebugSteppingFilters } -// TestSteppingCardAppliesAndRestoresAnAdaptersFilters walks the Build page's stepping card: -// it starts from the plugin's declared defaults, Apply has Core check the draft and hands -// the result to the settings owner, and Use Plugin Defaults removes the user's policy. -func TestSteppingCardAppliesAndRestoresAnAdaptersFilters(t *testing.T) { +// TestDebuggersPageAppliesAndRestoresAnAdaptersFilters walks the Debuggers page: it starts +// from the plugin's declared defaults, the footer's Apply has Core check the draft and hands +// the result to the settings owner, and Use Plugin Defaults followed by Apply removes the +// user's policy. +func TestDebuggersPageAppliesAndRestoresAnAdaptersFilters(t *testing.T) { var changes []steppingChange normalized := 0 w := newWindow(NewController(Options{ @@ -33,24 +34,29 @@ func TestSteppingCardAppliesAndRestoresAnAdaptersFilters(t *testing.T) { changes = append(changes, steppingChange{adapter, filters}) }, }), Values{}) - w.sess.page = pageBuild + w.sess.page = pageDebuggers d := openWindow(t, w) text := func(id string) string { return i18n.Shared(i18n.English, id) } d.until("the debuggers to load", func() bool { return w.stepping.loaded }) d.pump() if !d.text("Java Debugger") || !d.text(text("desktop.settings.stepping.usingDefaults")) { - t.Fatal("the card does not show the adapter and that it uses its plugin's defaults") + t.Fatal("the page does not show the adapter and that it uses its plugin's defaults") } if hit := d.hit(text("desktop.settings.stepping.skipSynthetics")); !hit.Checked { t.Fatalf("the declared default skipSynthetics is not shown: %+v", hit) } - if hit := d.hit(text("desktop.settings.stepping.apply")); !hit.Disabled { + apply := text("desktop.buildSettings.apply") + if hit := d.hit(apply); !hit.Disabled { t.Fatal("Apply is enabled before anything changed") } d.click(text("desktop.settings.stepping.skipConstructors")) - d.click(text("desktop.settings.stepping.apply")) + d.pump() + if !d.wrapped(text("desktop.buildSettings.steppingPending")) { + t.Fatal("the page does not say the change waits for Apply") + } + d.click(apply) d.until("the policy to be applied", func() bool { return len(changes) == 1 }) got := changes[0] if normalized != 1 || got.adapter != "java" || got.filters == nil || !got.filters.SkipConstructors || !got.filters.SkipSynthetics || @@ -59,16 +65,25 @@ func TestSteppingCardAppliesAndRestoresAnAdaptersFilters(t *testing.T) { } d.pump() if !d.text(text("desktop.settings.stepping.customized")) { - t.Fatal("the card does not say the policy is customized") + t.Fatal("the page does not say the policy is customized") } + // Use Plugin Defaults only resets the draft; Apply removes the stored policy. d.click(text("desktop.settings.stepping.restoreDefaults")) - if len(changes) != 2 || changes[1].adapter != "java" || changes[1].filters != nil { - t.Fatalf("Use Plugin Defaults = %+v", changes) - } d.pump() + if len(changes) != 1 { + t.Fatalf("Use Plugin Defaults wrote before Apply: %+v", changes) + } if hit := d.hit(text("desktop.settings.stepping.skipConstructors")); hit.Checked { - t.Fatal("the card kept the removed policy's switch") + t.Fatal("the page kept the removed policy's switch") + } + d.click(apply) + d.until("the policy to be removed", func() bool { return len(changes) == 2 }) + if changes[1].adapter != "java" || changes[1].filters != nil { + t.Fatalf("Use Plugin Defaults = %+v", changes) + } + if normalized != 1 { + t.Fatalf("removing the policy went to Core: normalized %d times", normalized) } } @@ -90,8 +105,9 @@ func TestRestoreDefaultsRemovesSteppingFilters(t *testing.T) { } } -func TestSteppingDraftReadsOnePatternPerLine(t *testing.T) { - draft := steppingDraft{patterns: " java.*\n\n sun.* \r\n", hideFilteredFrames: true} +// A draft's patterns are sent trimmed, without the blank ones. +func TestSteppingDraftDropsBlankPatterns(t *testing.T) { + draft := steppingDraft{patterns: []string{" java.*", "", " sun.* "}, hideFilteredFrames: true} filters := draft.filters() if !slices.Equal(filters.ClassNameFilters, []string{"java.*", "sun.*"}) || !filters.HideFilteredStackFrames { t.Fatalf("filters = %+v", filters) diff --git a/desktop/internal/settingswindow/toolchains_state.go b/desktop/internal/settingswindow/toolchains_state.go new file mode 100644 index 000000000..252f1a453 --- /dev/null +++ b/desktop/internal/settingswindow/toolchains_state.go @@ -0,0 +1,1101 @@ +package settingswindow + +import ( + "context" + "errors" + "hash/fnv" + "path/filepath" + "slices" + "strings" + "sync" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/ui" +) + +// The two scopes the Toolchains page edits: the machine's defaults and the open project's pins. +const ( + scopeGlobal = "global" + scopeProject = "project" +) + +// toolchainIssueLimit is how many problems the Build page lists before it links to the +// Toolchains list. +const toolchainIssueLimit = 5 + +// toolchainScope is one scope's half of the Toolchains page: the snapshot Core read for it and +// the user's choices that are not applied yet. Only the window thread touches it. +type toolchainScope struct { + name string + loadEffect *ui.EffectState[toolchain.Snapshot, int] + // loadKey names the read in flight or last made; zero means none was made. + loadKey int + loading bool + loaded bool + failed error + // stale asks for a re-read the next time the scope shows, after a write elsewhere changed + // what it inherits. + stale bool + snapshot toolchain.Snapshot + // draft maps a tool ID to the home the user chose; "" asks for the inherited or automatic + // layers. A tool whose choice equals the saved pin has no entry. + draft map[string]string + // custom holds the directories the user checked, by tool, in the order they were checked. + // They list as candidates until the scope's next write, which registers every one of them + // in the machine catalog. + custom map[string][]core.ToolchainPin + // inputs are the add-directory fields' bound values, one per tool. + inputs map[string]*string + // revision changes with the snapshot and the draft, so the list's projection runs again. + revision int +} + +func newToolchainScope(name string) *toolchainScope { + return &toolchainScope{name: name, draft: make(map[string]string), custom: make(map[string][]core.ToolchainPin), inputs: make(map[string]*string)} +} + +// saved is the home the scope's document pins for the tool, empty when it pins none. +func (s *toolchainScope) saved(id string) string { + if tool := s.tool(id); tool != nil && tool.Pin != nil { + return tool.Pin.Home + } + return "" +} + +// wanted is the tool's pin as it will be after the scope applies: the draft if there is one. +func (s *toolchainScope) wanted(id string) string { + if home, ok := s.draft[id]; ok { + return home + } + return s.saved(id) +} + +func (s *toolchainScope) changed(id string) bool { + _, ok := s.draft[id] + return ok +} + +func (s *toolchainScope) tool(id string) *toolchain.Tool { + for index := range s.snapshot.Tools { + if s.snapshot.Tools[index].ID == id { + return &s.snapshot.Tools[index] + } + } + return nil +} + +// choose records the user's choice of a home; choosing the saved pin drops the draft. +func (s *toolchainScope) choose(id, home string) { + if s.tool(id) == nil { + return + } + if home == s.saved(id) { + delete(s.draft, id) + } else { + s.draft[id] = home + } + s.revision++ +} + +func (s *toolchainScope) undo(id string) { + if _, ok := s.draft[id]; ok { + delete(s.draft, id) + s.revision++ + } +} + +func (s *toolchainScope) input(id string) *string { + if s.inputs[id] == nil { + s.inputs[id] = new(string) + } + return s.inputs[id] +} + +// apply takes a snapshot Core read. A read keeps the user's drafts that still differ from the +// saved pins; a write clears them, because the snapshot now holds what they asked for. +func (s *toolchainScope) apply(snapshot toolchain.Snapshot, written bool) { + s.snapshot, s.loaded, s.stale, s.failed = snapshot, true, false, nil + s.revision++ + if written { + s.draft = make(map[string]string) + s.custom = make(map[string][]core.ToolchainPin) + s.inputs = make(map[string]*string) + return + } + for id, home := range s.draft { + if s.tool(id) == nil || home == s.saved(id) { + delete(s.draft, id) + } + } +} + +// pinFor is the pin that selects home for the tool, from the candidates the scope knows. A +// candidate without a version cannot be pinned. +func (s *toolchainScope) pinFor(tool *toolchain.Tool, home string) (core.ToolchainPin, bool) { + for _, pin := range s.custom[tool.ID] { + if pin.Home == home { + return pin, true + } + } + if tool.Pin != nil && tool.Pin.Home == home && tool.Pin.Version != "" { + return *tool.Pin, true + } + for _, installation := range tool.Installations { + if installation.Home == home && installation.Version != "" { + return core.ToolchainPin{Home: installation.Home, Version: installation.Version, Provider: installation.Provider}, true + } + } + // A shell or project environment's home is a directory the user can name too; pinning it + // records it as one they chose. + for _, shell := range tool.Shell { + if shell.Home == home && shell.Version != nil && shell.Reason == "" { + return core.ToolchainPin{Home: home, Version: *shell.Version, Provider: "host:manual"}, true + } + } + if s.name == scopeProject { + for _, project := range tool.Project { + if project.Home == home && project.Version != nil && project.Reason == "" { + return core.ToolchainPin{Home: home, Version: *project.Version, Provider: "host:manual"}, true + } + } + } + if s.name == scopeGlobal && tool.Pin != nil && tool.Pin.Home == home { + // The machine default records a home only. + return *tool.Pin, true + } + return core.ToolchainPin{}, false +} + +// edits builds one pin change per tool with a draft, in the snapshot's order. +func (s *toolchainScope) edits() []toolchain.Edit { + var edits []toolchain.Edit + for index := range s.snapshot.Tools { + tool := &s.snapshot.Tools[index] + wanted, ok := s.draft[tool.ID] + if !ok { + continue + } + if wanted == "" { + edits = append(edits, toolchain.Edit{Tool: tool.ID}) + continue + } + if pin, ok := s.pinFor(tool, wanted); ok { + edits = append(edits, toolchain.Edit{Tool: tool.ID, Pin: &pin}) + } + } + return edits +} + +// saveSnapshot is the snapshot a write starts from. The machine catalog lists the homes +// discovery does not find, so the write registers every directory the user checked for an +// edited tool, the chosen one and the others, and a default on such a home in the same write. +func (s *toolchainScope) saveSnapshot(edits []toolchain.Edit) toolchain.Snapshot { + snapshot := s.snapshot + if s.name != scopeGlobal { + return snapshot + } + snapshot.Tools = slices.Clone(snapshot.Tools) + for _, edit := range edits { + for index := range snapshot.Tools { + tool := &snapshot.Tools[index] + if tool.ID != edit.Tool { + continue + } + var homes []string + for _, pin := range s.custom[tool.ID] { + homes = append(homes, pin.Home) + } + if edit.Pin != nil { + homes = append(homes, edit.Pin.Home) + } + for _, home := range homes { + known := slices.Contains(tool.CustomHomes, home) + for _, installation := range tool.Installations { + known = known || installation.Home == home + } + if !known { + tool.CustomHomes = append(slices.Clone(tool.CustomHomes), home) + } + } + } + } + return snapshot +} + +// toolchainEntry is one line of the Toolchains list: a tool Core resolved, or a tool ID two +// plugins declare, which Core does not resolve. +type toolchainEntry struct { + tool toolchain.Tool + conflict []string +} + +// toolchainWant names one projection of the list. It is comparable, so a paint asks again only +// when something it depends on changed. +type toolchainWant struct { + scope string + revision int + text string + filter string + groupBy string + folds string + issues int +} + +type toolchainProjected struct { + want toolchainWant + view core.ToolchainSettingsView + entries []toolchainEntry +} + +type toolchainProjectionJob struct { + want toolchainWant + request core.ToolchainSettingsViewRequest + entries []toolchainEntry +} + +// toolchainProjection asks Core to filter, group, fold and count the list off the window thread. +// The window writes the job under the lock before it changes the Effect's key; the run reads +// it under the same lock, so a request that replaced it never mixes with its inputs. +type toolchainProjection struct { + effect *ui.EffectState[toolchainProjected, toolchainWant] + mu sync.Mutex + job toolchainProjectionJob + want toolchainWant + requested bool + // ready is set once a projection arrived; view and entries are then the last one, which + // stays shown while the next runs, and got names it. + ready bool + got toolchainWant + view core.ToolchainSettingsView + entries []toolchainEntry + failed error +} + +func newToolchainProjection(viewer ToolchainViewer) *toolchainProjection { + p := &toolchainProjection{} + if viewer == nil { + return p + } + p.effect = ui.NewEffect[toolchainProjected, toolchainWant](func(ctx context.Context) (toolchainProjected, error) { + p.mu.Lock() + job := p.job + p.mu.Unlock() + view, err := viewer.SettingsView(ctx, job.request) + return toolchainProjected{want: job.want, view: view, entries: job.entries}, err + }) + return p +} + +// request asks for the projection want names; entries and request are built only when it changed. +func (p *toolchainProjection) request(want toolchainWant, build func() (core.ToolchainSettingsViewRequest, []toolchainEntry)) { + if p.requested && p.want == want { + return + } + request, entries := build() + p.want, p.requested = want, true + if p.effect == nil { + // Without Core's projection the list is every entry, unsorted and unclassified. + rows := make([]core.ToolchainSettingsRow, len(entries)) + for index := range entries { + rows[index] = core.ToolchainSettingsRow{Kind: "tool", Index: index} + } + p.view = core.ToolchainSettingsView{Rows: rows, Counts: core.ToolchainSettingsCounts{Total: len(entries), Matched: len(entries)}} + p.entries, p.ready, p.got, p.failed = entries, true, want, nil + return + } + p.mu.Lock() + p.job = toolchainProjectionJob{want: want, request: request, entries: entries} + p.mu.Unlock() +} + +func (p *toolchainProjection) declare(c ui.C) { + if p.effect != nil && p.requested { + ui.Effect(c, p.effect, p.want) + } +} + +func (p *toolchainProjection) take() { + if p.effect == nil { + return + } + result, err, ok := p.effect.Take() + if !ok || result.want != p.want { + return + } + if err != nil { + p.failed = err + return + } + p.view, p.entries, p.ready, p.got, p.failed = result.view, result.entries, true, result.want, nil +} + +// entry is the list entry a projected row names, or nil for a group or a row out of range. +func (p *toolchainProjection) entry(row core.ToolchainSettingsRow) *toolchainEntry { + if row.Kind != "tool" || row.Index < 0 || row.Index >= len(p.entries) { + return nil + } + return &p.entries[row.Index] +} + +// toolchainState is the Toolchains page: both scopes, the write, check and trust requests, and +// the list's query. Only the window thread reads or writes the fields; each request is a page +// Effect whose key changes when it is made, and the window takes what finished at the start of +// a paint. +type toolchainState struct { + loader ToolchainLoader + scopes map[string]*toolchainScope + // order lists the scopes the loader reads, global first. + order []string + scope string + + saveEffect *ui.EffectState[toolchain.Snapshot, int] + saveKey int + saveScope string + saveSnapshot toolchain.Snapshot + saveEdits []toolchain.Edit + saving bool + + inspectEffect *ui.EffectState[core.ToolchainSelection, int] + inspectKey int + inspectScope string + inspectSnapshot toolchain.Snapshot + inspectTool, inspectHome string + inspecting bool + + trustEffect *ui.EffectState[toolchain.Snapshot, int] + trustKey int + trustSnapshot toolchain.Snapshot + trustWanted bool + trusting bool + + // failed is the last write, check or trust request's error; a read's error is its scope's. + failed error + + // The list's query and the page's selection. + query string + filter string + groupBy string + folds map[string]bool + selected string + adding string + whyOpen bool + list ui.ListState + + view, search *toolchainProjection +} + +func newToolchainState(loader ToolchainLoader) *toolchainState { + t := &toolchainState{loader: loader, scopes: make(map[string]*toolchainScope), filter: "all", groupBy: "category", folds: make(map[string]bool)} + viewer, _ := loader.(ToolchainViewer) + t.view, t.search = newToolchainProjection(viewer), newToolchainProjection(viewer) + if loader == nil { + return t + } + scoped, ok := loader.(ToolchainScopedLoader) + if ok { + t.order = []string{scopeGlobal, scopeProject} + } else { + t.order = []string{scopeProject} + } + t.scope = t.order[0] + for _, name := range t.order { + scope := newToolchainScope(name) + scope.loadEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { + if scoped != nil { + return scoped.LoadScope(ctx, name) + } + return loader.Load(ctx) + }) + t.scopes[name] = scope + } + t.saveEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { + return loader.Save(ctx, t.saveSnapshot, t.saveEdits) + }) + if inspector, ok := loader.(ToolchainInspector); ok { + t.inspectEffect = ui.NewEffect[core.ToolchainSelection, int](func(ctx context.Context) (core.ToolchainSelection, error) { + ctx, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() + return inspector.Inspect(ctx, t.inspectSnapshot, t.inspectTool, t.inspectHome) + }) + } + if truster, ok := loader.(ToolchainTrustLoader); ok { + t.trustEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { + return truster.SetWorkspaceTrust(ctx, t.trustSnapshot, t.trustWanted) + }) + } + return t +} + +func (t *toolchainState) available() bool { + return t.loader != nil +} + +// current is the scope the page shows. +func (t *toolchainState) current() *toolchainScope { + return t.scopes[t.scope] +} + +func (t *toolchainState) busy() bool { + if t.saving || t.inspecting || t.trusting { + return true + } + for _, scope := range t.scopes { + if scope.loading { + return true + } + } + return false +} + +// ensureLoaded reads the shown scope when it has no snapshot, then the other one, so the scope +// switch and the footer know both. Reads wait for whatever request is out. +func (t *toolchainState) ensureLoaded() { + if t.loader == nil || t.busy() { + return + } + if scope := t.current(); (!scope.loaded || scope.stale) && scope.failed == nil { + t.beginLoad(scope) + return + } + for _, name := range t.order { + if scope := t.scopes[name]; !scope.loaded && scope.failed == nil { + t.beginLoad(scope) + return + } + } +} + +func (t *toolchainState) beginLoad(scope *toolchainScope) { + if scope == nil || t.busy() { + return + } + scope.loadKey++ + scope.loading, scope.failed = true, nil +} + +// reload reads the shown scope again without writing anything. +func (t *toolchainState) reload() { + t.failed = nil + t.beginLoad(t.current()) +} + +// noProject reports that the project scope read no project, so it has nothing to edit. +func (t *toolchainState) noProject() bool { + scope := t.scopes[scopeProject] + return scope != nil && scope.loaded && scope.snapshot.Root == "" +} + +// projectName is the open project's folder name, empty until the project scope read one. +func (t *toolchainState) projectName() string { + if scope := t.scopes[scopeProject]; scope != nil && scope.snapshot.Root != "" { + return filepath.Base(scope.snapshot.Root) + } + return "" +} + +// setScope shows another scope; the drafts of both stay. +func (t *toolchainState) setScope(name string) { + if t.scopes[name] == nil || name == t.scope { + return + } + t.scope, t.adding = name, "" +} + +// drafts counts the tools with an unapplied choice in the scope. +func (t *toolchainState) drafts(name string) int { + if scope := t.scopes[name]; scope != nil { + return len(scope.draft) + } + return 0 +} + +// beginSave writes the scope's drafts. Every edit goes through the same Core-validated document +// merge; a conflict keeps the drafts. +func (t *toolchainState) beginSave(name string) bool { + scope := t.scopes[name] + if scope == nil || !scope.loaded || t.busy() { + return false + } + edits := scope.edits() + if len(edits) == 0 { + return false + } + t.saveScope, t.saveSnapshot, t.saveEdits = name, scope.saveSnapshot(edits), edits + t.saveKey++ + t.saving, t.failed = true, nil + return true +} + +func (t *toolchainState) beginInspect(tool, home string) { + scope := t.current() + if t.inspectEffect == nil || t.busy() || scope == nil || !scope.loaded || home == "" { + return + } + t.inspectScope, t.inspectSnapshot, t.inspectTool, t.inspectHome = scope.name, scope.snapshot, tool, home + t.inspectKey++ + t.inspecting, t.failed = true, nil +} + +func (t *toolchainState) beginTrust(trusted bool) { + scope := t.scopes[scopeProject] + if t.trustEffect == nil || t.busy() || scope == nil || !scope.loaded || scope.snapshot.Global || scope.snapshot.Root == "" { + return + } + t.trustSnapshot, t.trustWanted = scope.snapshot, trusted + t.trustKey++ + t.trusting, t.failed = true, nil +} + +// take applies finished work on the window thread at the start of a paint. It reports a +// write that failed, so the footer's apply stops. +func (t *toolchainState) take() (saveFailed error) { + if t.loader == nil { + return nil + } + for _, scope := range t.scopes { + if snapshot, err, ok := scope.loadEffect.Take(); ok { + scope.loading = false + if err != nil { + scope.failed = err + } else { + scope.apply(snapshot, false) + } + } + } + if snapshot, err, ok := t.saveEffect.Take(); ok { + t.saving = false + scope := t.scopes[t.saveScope] + switch { + case err != nil && errors.Is(err, toolchain.ErrPinCommitted): + // The pins were written but the re-read failed: the drafts are on disk, and the + // page reads them back before it shows the scope again. + t.failed, scope.loaded, scope.stale = err, false, true + scope.draft = make(map[string]string) + scope.revision++ + saveFailed = err + case err != nil: + t.failed, saveFailed = err, err + default: + scope.apply(snapshot, true) + // A machine default is what the project scope inherits. + if t.saveScope == scopeGlobal { + if project := t.scopes[scopeProject]; project != nil && project.loaded { + project.stale = true + } + } + } + } + if t.inspectEffect != nil { + if selection, err, ok := t.inspectEffect.Take(); ok { + t.inspecting, t.failed = false, err + if err == nil && selection.Home != nil { + t.acceptInspection(t.inspectScope, t.inspectTool, selection) + } + } + } + if t.trustEffect != nil { + if snapshot, err, ok := t.trustEffect.Take(); ok { + t.trusting = false + scope := t.scopes[scopeProject] + if err != nil { + t.failed = err + if errors.Is(err, toolchain.ErrPinCommitted) { + scope.loaded, scope.stale = false, true + } + } else { + // The grant changes what the project probes; the user's choices stay. + scope.apply(snapshot, false) + } + } + } + t.view.take() + t.search.take() + return saveFailed +} + +// acceptInspection lists a checked directory as the tool's candidate and chooses it. +func (t *toolchainState) acceptInspection(name, id string, selection core.ToolchainSelection) { + scope := t.scopes[name] + if scope == nil || selection.Home == nil { + return + } + pin := core.ToolchainPin{Home: *selection.Home, Version: selection.Version, Provider: "host:manual"} + scope.custom[id] = append(slices.DeleteFunc(scope.custom[id], func(known core.ToolchainPin) bool { return known.Home == pin.Home }), pin) + if t.adding == id { + t.adding = "" + } + delete(scope.inputs, id) + scope.choose(id, pin.Home) +} + +// declare keeps the requests that are out alive. The window declares it in every paint, so +// leaving the page does not cancel a write. +func (t *toolchainState) declare(c ui.C) { + if t.loader == nil { + return + } + for _, name := range t.order { + if scope := t.scopes[name]; scope.loadKey != 0 { + ui.Effect(c.Key("toolchains:"+name), scope.loadEffect, scope.loadKey) + } + } + if t.saveKey != 0 { + ui.Effect(c, t.saveEffect, t.saveKey) + } + if t.inspectKey != 0 && t.inspectEffect != nil { + ui.Effect(c, t.inspectEffect, t.inspectKey) + } + if t.trustKey != 0 && t.trustEffect != nil { + ui.Effect(c, t.trustEffect, t.trustKey) + } + t.view.declare(c.Part("toolchain-view")) + t.search.declare(c.Part("toolchain-search")) +} + +// foldKey is the comparable form of the user's folds. +func (t *toolchainState) foldKey() string { + keys := make([]string, 0, len(t.folds)) + for key, collapsed := range t.folds { + if collapsed { + keys = append(keys, "-"+key) + } else { + keys = append(keys, "+"+key) + } + } + slices.Sort(keys) + return strings.Join(keys, "\x00") +} + +// toggleGroup folds or opens a group against what the list shows now. +func (t *toolchainState) toggleGroup(row core.ToolchainSettingsRow) { + t.folds[row.Key] = !row.Collapsed +} + +// requestView asks for the list's projection under the page's query. +func (t *toolchainState) requestView() { + scope := t.current() + if scope == nil || !scope.loaded { + return + } + want := toolchainWant{scope: scope.name, revision: scope.revision, text: strings.TrimSpace(t.query), filter: t.filter, groupBy: t.groupBy, folds: t.foldKey(), issues: toolchainIssueLimit} + t.view.request(want, func() (core.ToolchainSettingsViewRequest, []toolchainEntry) { + request, entries := t.projectionRequest(scope) + request.Query = core.ToolchainSettingsQuery{Text: want.text, Filter: want.filter, GroupBy: want.groupBy} + for key, collapsed := range t.folds { + if collapsed { + request.Query.Collapsed = append(request.Query.Collapsed, key) + } else { + request.Query.Expanded = append(request.Query.Expanded, key) + } + } + slices.Sort(request.Query.Collapsed) + slices.Sort(request.Query.Expanded) + request.IssueLimit = toolchainIssueLimit + return request, entries + }) +} + +// requestSearch asks which tools match the sidebar's search, grouped as the page groups them, +// so a match the user chooses can open its group. A search folds no group. +func (t *toolchainState) requestSearch(text string) { + scope := t.current() + if scope == nil || !scope.loaded || text == "" { + return + } + want := toolchainWant{scope: scope.name, revision: scope.revision, text: text, filter: "all", groupBy: t.groupBy, issues: 1} + t.search.request(want, func() (core.ToolchainSettingsViewRequest, []toolchainEntry) { + request, entries := t.projectionRequest(scope) + request.Query = core.ToolchainSettingsQuery{Text: text, Filter: "all", GroupBy: want.groupBy} + request.IssueLimit = 1 + return request, entries + }) +} + +// searchReady reports that the sidebar's tool matches it holds are for text. +func (t *toolchainState) searchReady(text string) bool { + return t.search.ready && t.search.got.text == text && t.search.failed == nil +} + +// searchGroup is the key of the group the sidebar's search lists the tool under, empty when +// the page does not group. +func (t *toolchainState) searchGroup(id string) string { + group := "" + for _, row := range t.search.view.Rows { + if row.Kind != "tool" { + group = row.Key + continue + } + if entry := t.search.entry(row); entry != nil && entry.tool.ID == id { + return group + } + } + return "" +} + +// reveal shows the tool on the page: its group opened, no query or filter that hides it, and +// the tool chosen. +func (t *toolchainState) reveal(id, group string) { + t.query, t.filter, t.selected, t.adding, t.whyOpen = "", "all", id, "", false + if group != "" { + t.folds[group] = false + } +} + +// showMatches opens the page on every tool the sidebar's search matched. +func (t *toolchainState) showMatches(text string) { + t.query, t.filter = text, "all" +} + +// projectionRequest lists the scope's tools as Core's projection takes them: identity, the +// resolver's reason, whether the scope pins or the draft changes it, and the versions and +// paths a search can find. +func (t *toolchainState) projectionRequest(scope *toolchainScope) (core.ToolchainSettingsViewRequest, []toolchainEntry) { + entries := make([]toolchainEntry, 0, len(scope.snapshot.Tools)+len(scope.snapshot.Conflicts)) + ids := make(map[string]bool, len(scope.snapshot.Tools)) + for _, tool := range scope.snapshot.Tools { + if tool.ID == "" || tool.PluginID == "" || ids[tool.ID] { + continue + } + ids[tool.ID] = true + entries = append(entries, toolchainEntry{tool: tool}) + } + for _, conflict := range scope.snapshot.Conflicts { + if conflict.Tool == "" || len(conflict.PluginIDs) == 0 || ids[conflict.Tool] { + continue + } + ids[conflict.Tool] = true + entries = append(entries, toolchainEntry{ + tool: toolchain.Tool{ID: conflict.Tool, DisplayName: conflict.Tool, PluginID: conflict.PluginIDs[0], Reason: "conflict"}, + conflict: conflict.PluginIDs, + }) + } + request := core.ToolchainSettingsViewRequest{Tools: make([]core.ToolchainSettingsTool, len(entries))} + for index, entry := range entries { + tool := entry.tool + name := tool.DisplayName + if name == "" { + name = tool.ID + } + request.Tools[index] = core.ToolchainSettingsTool{ + ID: tool.ID, DisplayName: name, PluginID: tool.PluginID, PluginName: tool.PluginName, + Category: tool.Category, Audience: tool.Audience, Reason: tool.Reason, + Pinned: tool.Pin != nil, Changed: scope.changed(tool.ID), Terms: toolchainTerms(scope, tool), + } + } + return request, entries +} + +// toolchainMaxTerms is Core's limit on a tool's search terms. +const toolchainMaxTerms = 16 + +// toolchainTerms are a tool's versions and paths, the text a search finds it by besides its +// names. +func toolchainTerms(scope *toolchainScope, tool toolchain.Tool) []string { + var terms []string + add := func(text string) { + if text == "" || len(terms) >= toolchainMaxTerms || len(text) > 1024 || strings.ContainsFunc(text, isControl) || slices.Contains(terms, text) { + return + } + terms = append(terms, text) + } + if tool.Effective != nil { + add(tool.Effective.Version) + if tool.Effective.Home != nil { + add(*tool.Effective.Home) + } + add(tool.Effective.Executable) + } + for _, pin := range scope.custom[tool.ID] { + add(pin.Version) + add(pin.Home) + } + for _, installation := range tool.Installations { + add(installation.Version) + add(installation.Home) + } + for _, shell := range tool.Shell { + if shell.Version != nil { + add(*shell.Version) + } + add(shell.Home) + } + for _, project := range tool.Project { + if project.Version != nil { + add(*project.Version) + } + add(project.Home) + } + return terms +} + +func isControl(r rune) bool { + return r < 0x20 || r == 0x7f || (r >= 0x80 && r < 0xa0) +} + +// rowKey is a list row's stable identity across projections: a tool's by its index in the +// entries, a group's by its key. Both fit the list's non-negative 31-bit keys. +func toolchainRowKey(row core.ToolchainSettingsRow) int { + if row.Kind != "group" { + return (row.Index & 0x3fffffff) * 2 + } + hash := fnv.New32a() + _, _ = hash.Write([]byte(row.Key)) + return int(hash.Sum32()&0x3fffffff)*2 + 1 +} + +// toolchainOption is one choice of a tool's home in the detail pane. +type toolchainOption struct { + home string + version string + sources []string + // why is what keeps the option from being chosen; empty when it can be. + why string + auto bool +} + +// options are a tool's choices in the scope: the inherited or automatic layers, then each home +// the scope knows once, with the sources that found it. +func (t *toolchainState) options(language i18n.Language, scope *toolchainScope, tool *toolchain.Tool) []toolchainOption { + options := []toolchainOption{{auto: true}} + index := make(map[string]int) + add := func(home, version, source, why string) { + if home == "" { + return + } + if at, ok := index[home]; ok { + option := &options[at] + if source != "" && !slices.Contains(option.sources, source) { + option.sources = append(option.sources, source) + } + if option.version == "" { + option.version = version + } + if why == "" && option.why != "" { + option.why = "" + } + return + } + option := toolchainOption{home: home, version: version, why: why} + if source != "" { + option.sources = []string{source} + } + index[home] = len(options) + options = append(options, option) + } + for _, installation := range tool.Installations { + why := "" + if installation.Version == "" { + why = i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") + } + add(installation.Home, installation.Version, toolchainSourceLabel(language, installation.Provider), why) + } + for _, shell := range tool.Shell { + version, why := "", "" + if shell.Version != nil { + version = *shell.Version + } + if shell.Reason != "" { + why = toolchainReasonLabel(language, shell.Reason) + } else if version == "" { + why = i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") + } + source := shell.Variable + if source == "" { + // A command found on the search path; PATH is the variable's own name. + source = "PATH" + } + add(shell.Home, version, source, why) + } + if scope.name == scopeProject { + for _, project := range tool.Project { + version, why := "", "" + if project.Version != nil { + version = *project.Version + } + switch { + case project.Reason == "projectCodeRequiresAction": + why = i18n.Shared(language, "desktop.toolchains.reasonProjectTrustRequired") + case project.Reason != "": + why = toolchainReasonLabel(language, project.Reason) + case version == "": + why = i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") + } + home := project.Home + if home == "" { + home = project.Path + } + add(home, version, project.Path, why) + } + } + for _, skipped := range tool.Skipped { + add(skipped.Home, "", toolchainSourceLabel(language, skipped.Provider), toolchainReasonLabel(language, skipped.Reason)) + } + for _, pin := range scope.custom[tool.ID] { + add(pin.Home, pin.Version, toolchainSourceLabel(language, "host:manual"), "") + } + if pin := tool.Pin; pin != nil { + // The pin is the checked choice, not a source, as in the prototype's srcTags: it names + // who found its home only when nothing above did. + source := "" + if _, known := index[pin.Home]; !known { + source = toolchainSourceLabel(language, pin.Provider) + } + add(pin.Home, pin.Version, source, "") + } + // An option that cannot be pinned is not a choice whatever found it. + for at := range options { + option := &options[at] + if option.auto || option.why != "" { + continue + } + if _, ok := scope.pinFor(tool, option.home); !ok { + option.why = i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") + } + } + return options +} + +// toolchainSourceLabel names who found a home: the host's own sources in the user's language, +// a plugin's provider by its ID. +func toolchainSourceLabel(language i18n.Language, provider string) string { + switch provider { + case "host:manual": + return i18n.Shared(language, "desktop.buildSettings.sourceManual") + case "host:system": + return i18n.Shared(language, "desktop.buildSettings.sourceSystem") + case "host:project": + return i18n.Shared(language, "desktop.toolchains.layerProject") + case "host:default": + return i18n.Shared(language, "desktop.toolchains.layerGlobal") + case "host:shell": + return "PATH" + default: + return provider + } +} + +func toolchainFailureMessage(language i18n.Language, err error) string { + var unavailable *toolchain.UnavailableError + if errors.As(err, &unavailable) { + return i18n.Shared(language, "desktop.toolchains.invalidDirectory") + } + if errors.Is(err, toolchain.ErrPinCommitted) { + return i18n.Shared(language, "desktop.toolchains.reloadAfterSave") + } + if errors.Is(err, toolchain.ErrPinConflict) { + return i18n.Shared(language, "desktop.toolchains.sourceChanged") + } + var rejection *core.MarketplaceRejection + if errors.Is(err, configfile.ErrTarget) || errors.Is(err, configfile.ErrEncoding) || errors.Is(err, configfile.ErrTooLarge) || + (errors.As(err, &rejection) && (rejection.Code == "plugin.toolchain.invalidDocument" || rejection.Code == "plugin.toolchain.invalidIgnore")) { + return i18n.Shared(language, "desktop.toolchains.sourceInvalid") + } + return i18n.SharedFormat(language, "desktop.toolchains.loadFailed", map[string]string{"reason": err.Error()}) +} + +func (w *window) pickToolchainDirectory(tool string, input *string, title string) { + path, err := app.OpenDirectory(app.OpenDirectoryOptions{Title: title}) + // log-exempt: 用户取消:关闭目录选择器不修改工具链草稿。 + if errors.Is(err, app.ErrCanceled) { + return + } + if err != nil { + w.toolchains.failed = err + if w.ctrl.opts.MarketplaceError != nil { + w.ctrl.opts.MarketplaceError(err) + } + return + } + if scope := w.toolchains.current(); path != "" && scope != nil && scope.inputs[tool] == input { + *input = path + w.toolchains.beginInspect(tool, path) + } +} + +func toolchainReason(tool toolchain.Tool) string { + if tool.Reason != "" { + return tool.Reason + } + for _, trace := range tool.Trace { + if trace.Reason != nil && trace.Reason.Code != "" { + return trace.Reason.Code + } + } + for _, project := range tool.Project { + if project.Reason != "" { + return project.Reason + } + } + return "notFound" +} + +func toolRequiresProjectTrust(tool toolchain.Tool) bool { + for _, project := range tool.Project { + if project.Reason == "projectCodeRequiresAction" { + return true + } + } + for _, trace := range tool.Trace { + if trace.Reason != nil && trace.Reason.Code == "projectCodeRequiresAction" { + return true + } + } + return false +} + +// projectSources are the project files the tools that wait for trust come from. +func projectSources(snapshot toolchain.Snapshot) (tools int, sources []string) { + for _, tool := range snapshot.Tools { + if !toolRequiresProjectTrust(tool) { + continue + } + tools++ + for _, project := range tool.Project { + if project.Reason == "projectCodeRequiresAction" && project.Path != "" && !slices.Contains(sources, project.Path) { + sources = append(sources, project.Path) + } + } + } + return tools, sources +} + +func toolchainReasonLabel(language i18n.Language, code string) string { + switch code { + case "projectCodeRequiresAction": + return i18n.Shared(language, "desktop.toolchains.reasonProjectTrustRequired") + case "notFound": + return i18n.Shared(language, "desktop.buildSettings.reasonNotFound") + case "probeFailed": + return i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") + case "versionUnsatisfied": + return i18n.Shared(language, "desktop.toolchains.reasonVersionUnsatisfied") + case "notExecutable": + return i18n.Shared(language, "desktop.toolchains.reasonNotExecutable") + case "unsafePath": + return i18n.Shared(language, "desktop.toolchains.reasonUnsafePath") + case "conflict": + return i18n.Shared(language, "desktop.buildSettings.reasonConflict") + default: + return code + } +} + +func toolchainLayerLabel(language i18n.Language, layer string) string { + switch layer { + case "pinned": + return i18n.Shared(language, "desktop.toolchains.layerPinned") + case "project": + return i18n.Shared(language, "desktop.toolchains.layerProject") + case "global": + return i18n.Shared(language, "desktop.toolchains.layerGlobal") + case "automatic": + return i18n.Shared(language, "desktop.toolchains.layerAutomatic") + default: + return layer + } +} diff --git a/desktop/internal/settingswindow/toolchains_view.go b/desktop/internal/settingswindow/toolchains_view.go index 64f75f38e..818a5d5f2 100644 --- a/desktop/internal/settingswindow/toolchains_view.go +++ b/desktop/internal/settingswindow/toolchains_view.go @@ -1,735 +1,1130 @@ package settingswindow import ( - "context" - "errors" + "slices" "strings" - "time" - "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" - "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// toolchainState is the Build settings page's draft. Only the window thread reads or -// writes the fields. A load and a save are two page Effects: a new key cancels the one -// before it, so a result of a replaced request never reaches the draft, and the window -// takes what finished with take at the start of a paint. -type toolchainState struct { - loader ToolchainLoader - loadEffect *ui.EffectState[toolchain.Snapshot, int] - saveEffect *ui.EffectState[toolchain.Snapshot, int] - inspectEffect *ui.EffectState[core.ToolchainSelection, int] - inspectKey int - inspectSnapshot toolchain.Snapshot - inspectTool, inspectHome string - inspecting bool - trustEffect *ui.EffectState[toolchain.Snapshot, int] - trustKey int - trustSnapshot toolchain.Snapshot - trustWanted bool - trusting bool - inputs map[string]*string - custom map[string]core.ToolchainPin - scope, loadScope string - registrations map[string]bool - // loadKey and saveKey name the requests; zero means none was made. The save's inputs - // are written before its key changes and are read by that one run only. - loadKey, saveKey int - saveSnapshot toolchain.Snapshot - saveEdits []toolchain.Edit - - loading bool - saving bool - loaded bool - saved bool - failed error - - snapshot toolchain.Snapshot - // draft maps a tool ID to the directory home the user selected, empty for - // the automatic layers. - draft map[string]string - // picks are the lists' bound values, one per tool, mirrored from draft in each paint. - picks map[string]*string - // customizing names the tools whose list is on Custom…: their directory field shows - // until a directory checks out or another entry is chosen. - customizing map[string]bool -} - -// toolchainCustom is the value of the entry of a tool's list that asks for a directory the -// discovery did not find. A home is a path, which never holds a NUL, so it names none. -const toolchainCustom = "\x00custom" - -func newToolchainState(loader ToolchainLoader) *toolchainState { - t := &toolchainState{loader: loader, scope: "project", draft: make(map[string]string), picks: make(map[string]*string), customizing: make(map[string]bool), inputs: make(map[string]*string), custom: make(map[string]core.ToolchainPin), registrations: make(map[string]bool)} - if _, ok := loader.(ToolchainScopedLoader); ok { - t.scope = "global" - } - if loader != nil { - t.loadEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { - if scoped, ok := loader.(ToolchainScopedLoader); ok { - return scoped.LoadScope(ctx, t.loadScope) - } - return loader.Load(ctx) - }) - t.saveEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { - return loader.Save(ctx, t.saveSnapshot, t.saveEdits) - }) - } - if inspector, ok := loader.(ToolchainInspector); ok { - t.inspectEffect = ui.NewEffect[core.ToolchainSelection, int](func(ctx context.Context) (core.ToolchainSelection, error) { - ctx, cancel := context.WithTimeout(ctx, 15*time.Second) - defer cancel() - return inspector.Inspect(ctx, t.inspectSnapshot, t.inspectTool, t.inspectHome) - }) - } - if truster, ok := loader.(ToolchainTrustLoader); ok { - t.trustEffect = ui.NewEffect[toolchain.Snapshot, int](func(ctx context.Context) (toolchain.Snapshot, error) { - return truster.SetWorkspaceTrust(ctx, t.trustSnapshot, t.trustWanted) - }) - } - return t -} +// The Toolchains page follows the prototype docs/design/build-execution-settings.html: a +// toolbar with the scope and the filter, the filter chips, the trust banner, then the tool +// list beside the chosen tool's detail. Core projects the list (toolchains.settingsView); +// this file only lays it out, and every state it changes lives in toolchains_state.go. -func (t *toolchainState) busy() bool { - return t.loading || t.saving || t.inspecting || t.trusting -} +const ( + // toolchainListWidth is the prototype's width of the tool list. A window too narrow for it + // and toolchainDetailMin beside it gives the list less, down to toolchainListMin. + toolchainListWidth = 372 + toolchainListMin = 280 + toolchainDetailMin = 380 + // toolchainToolRow and toolchainGroupRow are the prototype's row heights. + toolchainToolRow = 46 + toolchainGroupRow = 30 +) -func (t *toolchainState) beginInspect(tool, home string) { - if t.inspectEffect == nil || t.busy() || !t.loaded || home == "" { - return - } - t.inspectSnapshot, t.inspectTool, t.inspectHome = t.snapshot, tool, home - t.inspectKey++ - t.inspecting, t.saved, t.failed = true, false, nil +// toolchainResult is what a tool resolves to in a scope: an installation and the layer that +// chose it, or the reason none applies. +type toolchainResult struct { + ok bool + version, home, executable, layer string + reason string } -func (t *toolchainState) beginTrust(trusted bool) { - if t.trustEffect == nil || t.busy() || !t.loaded || t.snapshot.Global || t.snapshot.Root == "" { - return +// toolchainCurrent is what the tool uses now, as Core resolved the scope's snapshot. +func toolchainCurrent(tool *toolchain.Tool) toolchainResult { + if tool.Effective != nil && tool.Reason == "" { + result := toolchainResult{ok: true, version: tool.Effective.Version, executable: tool.Effective.Executable, layer: tool.Effective.Layer} + if tool.Effective.Home != nil { + result.home = *tool.Effective.Home + } + if result.home == "" { + result.home = result.executable + } + return result } - t.trustSnapshot, t.trustWanted = t.snapshot, trusted - t.trustKey++ - t.trusting, t.saved, t.failed = true, false, nil + return toolchainResult{reason: toolchainReason(*tool)} } -func toolchainFailureMessage(language i18n.Language, err error) string { - var unavailable *toolchain.UnavailableError - if errors.As(err, &unavailable) { - return i18n.Shared(language, "desktop.toolchains.invalidDirectory") - } - if errors.Is(err, toolchain.ErrPinCommitted) { - return i18n.Shared(language, "desktop.toolchains.reloadAfterSave") +// toolchainNext is what the tool will use once the scope's draft applies: the chosen home under +// the scope's own layer, or what the tool falls back to without a pin. +func toolchainNext(scope *toolchainScope, tool *toolchain.Tool) toolchainResult { + if wanted := scope.wanted(tool.ID); wanted != "" { + layer := "pinned" + if scope.name == scopeGlobal { + layer = "global" + } + version := "?" + if pin, ok := scope.pinFor(tool, wanted); ok && pin.Version != "" { + version = pin.Version + } + return toolchainResult{ok: true, version: version, home: wanted, layer: layer} } - if errors.Is(err, toolchain.ErrPinConflict) { - return i18n.Shared(language, "desktop.toolchains.sourceChanged") + if automatic := tool.Automatic; automatic != nil { + result := toolchainResult{ok: true, version: automatic.Version, home: tool.AutomaticHome, executable: automatic.Executable, layer: automatic.Layer} + if result.home == "" && automatic.Home != nil { + result.home = *automatic.Home + } + return result } - var rejection *core.MarketplaceRejection - if errors.Is(err, configfile.ErrTarget) || errors.Is(err, configfile.ErrEncoding) || errors.Is(err, configfile.ErrTooLarge) || - (errors.As(err, &rejection) && (rejection.Code == "plugin.toolchain.invalidDocument" || rejection.Code == "plugin.toolchain.invalidIgnore")) { - return i18n.Shared(language, "desktop.toolchains.sourceInvalid") + reason := tool.AutomaticReason + if reason == "" { + reason = "notFound" } - return i18n.SharedFormat(language, "desktop.toolchains.loadFailed", map[string]string{"reason": err.Error()}) + return toolchainResult{reason: reason} } -// beginLoad reads the project's toolchains off the window thread. -func (t *toolchainState) beginLoad() { - if t.loader == nil || t.busy() { - return +// toolchainStatus is the state Core gives a reason: the problems the user may fix in place warn, +// the rest are errors. It matches toolchains.settingsView, for a list Core did not project. +func toolchainStatus(result toolchainResult) string { + switch { + case result.ok: + return "ok" + case result.reason == "projectCodeRequiresAction" || result.reason == "ambiguousInstallation" || result.reason == "probeFailed": + return "warning" + default: + return "error" } - t.loadScope = t.scope - t.loadKey++ - t.loading = true - t.failed = nil } -// beginSave writes the draft's changed pins. Every edit goes through the same -// Core-validated document merge; a conflict keeps the draft. -func (t *toolchainState) beginSave() { - if t.loader == nil || !t.loaded || t.busy() || !t.hasDraft() { +// toolchainsPage is the Toolchains page under Build, Execution, Deployment. +func (w *window) toolchainsPage(c ui.C) { + t := w.toolchains + if !t.available() { + w.unavailablePage(c) return } - edits := t.edits() - if len(edits) == 0 { - return + language := w.marketLanguage() + t.ensureLoaded() + if t.filter == "changed" && t.drafts(t.scope) == 0 { + t.filter = "all" } - t.saveSnapshot, t.saveEdits = t.snapshot, edits - t.saveKey++ - t.saving = true - t.failed = nil + t.requestView() + scope := t.current() + b := &w.bp + ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Background(b.surface).Children(func() { + w.toolchainsToolbar(c.Part("bar"), language, scope) + w.toolchainsChips(c.Part("chips"), language) + w.toolchainsNotices(c.Part("notices"), language, scope) + switch { + case t.scope == scopeProject && t.noProject(): + w.toolchainsEmpty(c, i18n.Shared(language, "desktop.toolchains.noProject")) + case !scope.loaded || !t.view.ready: + if scope.failed == nil && t.view.failed == nil { + w.toolchainsEmpty(c, i18n.Shared(language, "desktop.toolchains.loading")) + } + default: + w.toolchainsSplit(c.Part("split"), language, scope) + } + }) } -// take applies finished work on the window thread at the start of a paint. -func (t *toolchainState) take() { - if t.loadEffect == nil { - return - } - if snapshot, err, ok := t.loadEffect.Take(); ok { - t.finish(snapshot, err, false) - } - if snapshot, err, ok := t.saveEffect.Take(); ok { - t.finish(snapshot, err, true) - } - if t.inspectEffect != nil { - if selection, err, ok := t.inspectEffect.Take(); ok { - t.inspecting, t.failed = false, err - if err == nil && selection.Home != nil { - t.acceptInspection(t.inspectTool, selection) +// toolchainsEmpty is a sentence in the middle of what is left of the page. +func (w *window) toolchainsEmpty(c ui.C, text string) { + ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Center().Children(func() { + ui.Wrap(c, text).FontSize(buildSmall).LineHeight(21.6).Color(w.bp.faint).TextCenter().MaxWidth(emptyWidth) + }) +} + +// toolchainsToolbar is the prototype's .tbar: the scope switch and its help, the project's trust, +// then the filter and the re-detect button. +func (w *window) toolchainsToolbar(c ui.C, language i18n.Language, scope *toolchainScope) { + t := w.toolchains + b := &w.bp + ui.Row(c).FillWidth().Shrink(0).PadSides(10, 14, 6, 14).Gap(8).Items(ui.Center).Children(func() { + if len(t.order) > 1 { + project := i18n.Shared(language, "desktop.toolchains.project") + if name := t.projectName(); name != "" { + project = i18n.SharedFormat(language, "desktop.buildSettings.scopeProjectNamed", map[string]string{"project": name}) + } + noProject := t.noProject() + tip := "" + if noProject { + tip = i18n.Shared(language, "desktop.toolchains.noProject") + } + value := t.scope + if w.segmented(c.Part("scope"), &value, []segment{ + {value: scopeGlobal, label: i18n.Shared(language, "desktop.toolchains.global"), changed: t.drafts(scopeGlobal) > 0}, + {value: scopeProject, label: project, changed: t.drafts(scopeProject) > 0, disabled: noProject, tip: tip}, + }) { + t.setScope(value) } + w.infoButton(c.Part("scope-help"), i18n.Shared(language, "desktop.buildSettings.scopeHelp")) } - } - if t.trustEffect != nil { - if snapshot, err, ok := t.trustEffect.Take(); ok { - t.finishTrust(snapshot, err) + if t.scope == scopeProject && scope.loaded && scope.snapshot.ProjectCodeAllowed && t.trustEffect != nil { + k := c.Part("trust") + trusted := i18n.Shared(language, "desktop.toolchains.trustStatusTrusted") + w.tag(k, tagGreen, trusted).HitWith(ui.ID(k), trusted, gfx.HitOptions{Role: gfx.RoleStatus}). + Tooltip(i18n.Shared(language, "desktop.buildSettings.trustedHelp")) + if w.button(c.Part("revoke"), buttonLinkSmall, i18n.Shared(language, "desktop.buildSettings.revokeTrust"), t.busy()) { + t.beginTrust(false) + } } - } + ui.Spacer(c) + filter := i18n.Shared(language, "desktop.buildSettings.filterLabel") + ui.Row(c).Width(260).Shrink(1).MinWidth(120).Children(func() { + w.filterField(c.Part("filter"), &t.query, filter, i18n.Shared(language, "desktop.buildSettings.filterPlaceholder"), true) + }) + if w.iconButton(c.Part("redetect"), icons.RefreshCw, i18n.Shared(language, "desktop.buildSettings.redetect"), t.busy()) { + t.reload() + } + }) + _ = b } -func (t *toolchainState) acceptInspection(id string, selection core.ToolchainSelection) { - if selection.Home == nil { - return - } - pin := core.ToolchainPin{Home: *selection.Home, Version: selection.Version, Provider: "host:manual"} - if t.snapshot.Global { - for index := range t.snapshot.Tools { - tool := &t.snapshot.Tools[index] - if tool.ID != id { - continue +// toolchainsChips is the prototype's .tbar2: the filter chips with their counts, then the +// grouping. +func (w *window) toolchainsChips(c ui.C, language i18n.Language) { + t := w.toolchains + b := &w.bp + counts := t.view.view.Counts + ui.Column(c).FillWidth().Shrink(0).Children(func() { + ui.Row(c).FillWidth().PadSides(2, 14, 8, 14).Gap(6).Items(ui.Center).Children(func() { + if w.chip(c.Part("all"), i18n.Shared(language, "desktop.buildSettings.filterAll"), counts.Total, t.filter == "all", nil) { + t.filter = "all" } - registered, installed := false, false - for _, home := range tool.CustomHomes { - registered = registered || home == pin.Home + var mark *gfx.Color + if counts.Problems > 0 { + color := b.warn + if counts.Errors > 0 { + color = b.err + } + mark = &color } - if !registered { - tool.CustomHomes = append(tool.CustomHomes, pin.Home) - t.registrations[id] = true + if w.chip(c.Part("problems"), i18n.Shared(language, "desktop.buildSettings.filterProblems"), counts.Problems, t.filter == "problems", mark) { + t.filter = "problems" } - for _, installation := range tool.Installations { - installed = installed || installation.Home == pin.Home + if w.chip(c.Part("pinned"), i18n.Shared(language, "desktop.buildSettings.filterPinned"), counts.Pinned, t.filter == "pinned", nil) { + t.filter = "pinned" } - if !installed { - tool.Installations = append(tool.Installations, core.ToolchainInstallation{Home: pin.Home, Version: pin.Version, Provider: pin.Provider}) + if counts.Changed > 0 { + if w.chip(c.Part("changed"), i18n.Shared(language, "desktop.buildSettings.filterChanged"), counts.Changed, t.filter == "changed", nil) { + t.filter = "changed" + } } - } - } else { - t.custom[id] = pin - } - // The checked directory is now an entry of the list, which shows it chosen. - delete(t.customizing, id) - t.choose(id, pin.Home) + ui.Spacer(c) + groupBy := i18n.Shared(language, "desktop.buildSettings.groupBy") + ui.Text(c, groupBy).FontSize(buildSmall).Color(b.sub).Shrink(0) + ui.Select(c.Part("group"), &t.groupBy, []string{"category", "plugin", "none"}, func(value string) string { + switch value { + case "plugin": + return i18n.Shared(language, "desktop.buildSettings.groupPlugin") + case "none": + return i18n.Shared(language, "desktop.buildSettings.groupNone") + } + return i18n.Shared(language, "desktop.buildSettings.groupCategory") + }).Label(groupBy) + }) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + }) } -func (t *toolchainState) finish(snapshot toolchain.Snapshot, err error, saved bool) { - t.loading, t.saving = false, false - if err != nil { - t.failed = err - if errors.Is(err, toolchain.ErrPinCommitted) { - t.loaded = false - } - t.saved = false +// toolchainsNotices are the banner and the messages over the list: the project's untrusted +// environments, a read or write that failed, and the request that is out. +func (w *window) toolchainsNotices(c ui.C, language i18n.Language, scope *toolchainScope) { + t := w.toolchains + banner := false + count, sources := 0, []string(nil) + if t.scope == scopeProject && scope.loaded && !scope.snapshot.ProjectCodeAllowed { + count, sources = projectSources(scope.snapshot) + banner = count > 0 + } + busy := "" + switch { + case t.saving: + busy = i18n.Shared(language, "desktop.toolchains.saving") + case t.trusting: + busy = i18n.Shared(language, "desktop.toolchains.updatingTrust") + case t.inspecting: + busy = i18n.Shared(language, "desktop.toolchains.loading") + } + if !banner && scope.failed == nil && t.failed == nil && t.view.failed == nil && busy == "" { return } - t.apply(snapshot, saved) + ui.Column(c).FillWidth().Shrink(0).PadSides(8, 14, 0, 14).Gap(8).Children(func() { + if banner { + if len(sources) > 3 { + sources = sources[:3] + } + text := i18n.SharedFormat(language, "desktop.buildSettings.trustBanner", map[string]string{ + "count": formatCount(count), + "sources": strings.Join(sources, i18n.Shared(language, "desktop.buildSettings.listSeparator")), + }) + w.box(c.Part("banner"), boxWarn, func(words gfx.Color) { + boxIcon(c, icons.CircleAlert, words) + boxText(c, text, words) + w.infoButton(c.Part("banner-help"), i18n.Shared(language, "desktop.toolchains.trustProjectHelp")) + if t.trustEffect != nil && w.button(c.Part("banner-trust"), buttonSmall, i18n.Shared(language, "desktop.buildSettings.trustProject"), t.busy()) { + t.beginTrust(true) + } + }) + } + if scope.failed != nil { + message := toolchainFailureMessage(language, scope.failed) + w.box(c.Part("load-failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + if w.button(c.Part("load-retry"), buttonSmall, i18n.Shared(language, "desktop.toolchains.reload"), t.busy()) { + scope.failed = nil + t.reload() + } + }) + } + if t.failed != nil { + message := toolchainFailureMessage(language, t.failed) + w.box(c.Part("failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + }) + } + if t.view.failed != nil { + message := toolchainFailureMessage(language, t.view.failed) + w.box(c.Part("view-failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + }) + } + if busy != "" { + w.box(c.Part("busy"), boxInfo, func(words gfx.Color) { + boxIcon(c, icons.Clock, words) + boxText(c, busy, words) + }) + } + }) +} + +// toolchainsSplit is the list beside the detail of the chosen tool. +func (w *window) toolchainsSplit(c ui.C, language i18n.Language, scope *toolchainScope) { + b := &w.bp + width := float32(toolchainListWidth) + if room := w.extent - 1 - toolchainDetailMin; room < width { + width = max(toolchainListMin, room) + } + ui.Row(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Children(func() { + ui.Column(c).Width(width).Shrink(0).FillHeight().MinHeight(0).Children(func() { + w.toolchainsList(c.Part("list"), language, scope) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + tools := 0 + for _, row := range w.toolchains.view.view.Rows { + if row.Kind == "tool" { + tools++ + } + } + ui.Row(c).FillWidth().Shrink(0).PadX(12).PadY(5).Gap(8).Children(func() { + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.listCount", map[string]string{ + "matched": formatCount(tools), + "total": formatCount(w.toolchains.view.view.Counts.Total), + })).FontSize(11).Color(b.faint).Ellipsis() + }) + }) + ui.Row(c).Width(1).Shrink(0).FillHeight().Background(b.line) + ui.Scroll(c.Key("detail:"+w.toolchains.selected)).Scrollbars().Grow(1).Shrink(1).MinWidth(0).FillHeight(). + PadSides(buildPagePadTop, buildPagePadX, buildPagePadEnd, buildPagePadX).Children(func() { + w.toolchainDetail(c, language, scope) + }) + }) } -func (t *toolchainState) finishTrust(snapshot toolchain.Snapshot, err error) { - t.trusting = false - if err != nil { - t.failed = err - if errors.Is(err, toolchain.ErrPinCommitted) { - t.loaded = false +// toolchainsList is Core's projected rows: group headers that fold, and the tools under them. +func (w *window) toolchainsList(c ui.C, language i18n.Language, scope *toolchainScope) { + t := w.toolchains + b := &w.bp + rows := t.view.view.Rows + if t.selected == "" || t.selectedRow(rows) < 0 && scope.tool(t.selected) == nil { + t.selected = "" + for _, row := range rows { + if entry := t.view.entry(row); entry != nil { + t.selected = entry.tool.ID + break + } } - t.saved = false - return } - dirtyDrafts := make(map[string]string) - for _, tool := range t.snapshot.Tools { - current := "" - if tool.Pin != nil { - current = tool.Pin.Home + if len(rows) == 0 { + empty := i18n.Shared(language, "desktop.buildSettings.noMatches") + check := t.filter == "problems" && strings.TrimSpace(t.query) == "" + if check { + empty = i18n.Shared(language, "desktop.buildSettings.noProblems") } - if wanted, ok := t.draft[tool.ID]; ok && wanted != current { - dirtyDrafts[tool.ID] = wanted + ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).PadSides(50, 20, 50, 20).Items(ui.Center).Children(func() { + ui.Row(c).Gap(6).Items(ui.Center).Children(func() { + if check { + ui.Icon(c, icons.Check).Size(12, 12).Color(b.faint).Shrink(0) + } + ui.Wrap(c, empty).FontSize(buildSmall).LineHeight(21.6).Color(b.faint).TextCenter() + }) + }) + return + } + t.list.Key = func(i int) int { + if i < 0 || i >= len(rows) { + return 0 } + return toolchainRowKey(rows[i]) } - savedCustom := make(map[string]core.ToolchainPin, len(t.custom)) - for id, pin := range t.custom { - savedCustom[id] = pin + t.list.Header = func(i int) bool { return i >= 0 && i < len(rows) && rows[i].Kind == "group" } + t.list.Label = func(i int) string { + if i < 0 || i >= len(rows) { + return "" + } + if rows[i].Kind == "group" { + return w.toolchainGroupLabel(language, rows[i]) + } + if entry := t.view.entry(rows[i]); entry != nil { + return toolchainName(&entry.tool) + } + return "" } - t.apply(snapshot, false) - for id, pin := range savedCustom { - t.custom[id] = pin + if at := t.selectedRow(rows); t.list.Selected() != at { + t.list.Select(at) + if at >= 0 { + t.list.ScrollIntoView(at) + } } - for id, wanted := range dirtyDrafts { - t.draft[id] = wanted + ui.List(c, &t.list, len(rows), func(r ui.ListRow) { + row := rows[r.Index] + if row.Kind == "group" { + w.toolchainGroupRow(r, language, row) + return + } + entry := t.view.entry(row) + if entry == nil { + return + } + w.toolchainToolRow(r, language, scope, entry, row.Status) + }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(i18n.Shared(language, "desktop.toolchains.title")) + if t.list.Changed() { + if at := t.list.Selected(); at >= 0 && at < len(rows) { + if entry := t.view.entry(rows[at]); entry != nil && entry.tool.ID != t.selected { + t.selected, t.whyOpen, t.adding = entry.tool.ID, false, "" + } + } } } -// declare keeps the requests that are out alive. The window declares it in every paint, so -// leaving the Build page does not cancel a save that is writing the pins. -func (t *toolchainState) declare(c ui.C) { - if t.loadEffect == nil { - return +// selectedRow is the row of the chosen tool, or -1 when the list does not show it. +func (t *toolchainState) selectedRow(rows []core.ToolchainSettingsRow) int { + for at, row := range rows { + if entry := t.view.entry(row); entry != nil && entry.tool.ID == t.selected { + return at + } } - if t.loadKey != 0 { - ui.Effect(c, t.loadEffect, t.loadKey) + return -1 +} + +// toolchainGroupLabel names a group: its plugin, the plugins' own runtimes, or a category. +func (w *window) toolchainGroupLabel(language i18n.Language, row core.ToolchainSettingsRow) string { + switch { + case row.PluginID != "": + if row.Title != "" { + return row.Title + } + return row.PluginID + case row.Audience == "plugin": + return i18n.Shared(language, "desktop.buildSettings.categoryPlugin") + default: + return toolchainCategoryLabel(language, row.Category, "") } - if t.saveKey != 0 { - ui.Effect(c, t.saveEffect, t.saveKey) +} + +// toolchainGroupRow is the prototype's .gh: the caret, the group's name and count and its +// problems on the sidebar's ground. A press anywhere on it folds or opens the group. +func (w *window) toolchainGroupRow(r ui.ListRow, language i18n.Language, row core.ToolchainSettingsRow) { + t := w.toolchains + b := &w.bp + c := r.C + label := w.toolchainGroupLabel(language, row) + r.Element.Height(toolchainGroupRow).Background(b.side).Children(func() { + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).FillHeight().Children(func() { + ui.Row(c).FillWidth().Grow(1).PadX(12).Gap(6).Items(ui.Center).Children(func() { + toggle := ui.ButtonBase(c.Part("toggle"), label).Shrink(1).MinWidth(0).FillHeight().Gap(6).Items(ui.Center) + if toggle.Clicked() { + t.toggleGroup(row) + } + toggle.Children(func() { + caret := icons.ChevronDown + if row.Collapsed { + caret = icons.ChevronRight + } + ui.Row(c).Width(10).Shrink(0).Center().Children(func() { + ui.Icon(c, caret).Size(10, 10).Color(b.faint) + }) + ui.Text(c, label).FontSize(11.5).Weight(gfx.WeightSemibold).Color(b.sub).Shrink(1).Ellipsis() + ui.Text(c, formatCount(row.Count)).FontSize(11.5).Color(b.faint).Shrink(0) + if row.Problems > 0 { + w.badge(c, row.Problems, t.view.view.Counts.Errors == 0).MarginLeft(4) + } + }) + if row.Key == "audience:plugin" && t.groupBy == "category" { + w.infoButton(c.Part("info"), i18n.Shared(language, "desktop.buildSettings.pluginGroupHelp")) + } + fill := ui.ButtonBase(c.Part("fill"), label).Grow(1).FillHeight() + if fill.Clicked() { + t.toggleGroup(row) + } + }) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + }) + }) +} + +// toolchainToolRow is the prototype's .trow: the state dot, the name with its version, what a +// draft changes it to and its layer, then the plugin and the home or the reason. +func (w *window) toolchainToolRow(r ui.ListRow, language i18n.Language, scope *toolchainScope, entry *toolchainEntry, status string) { + b := &w.bp + c := r.C + tool := &entry.tool + if fresh := scope.tool(tool.ID); fresh != nil { + tool = fresh } - if t.inspectKey != 0 { - ui.Effect(c, t.inspectEffect, t.inspectKey) + current := toolchainCurrent(tool) + if status == "" { + status = toolchainStatus(current) } - if t.trustKey != 0 && t.trustEffect != nil { - ui.Effect(c, t.trustEffect, t.trustKey) + changed := scope.changed(tool.ID) + r.Element.Height(toolchainToolRow).PadSides(0, 12, 0, 14).Gap(9).Items(ui.Center).Hover(ui.Look{}.Background(b.hover)) + if r.Selected() { + r.Element.Background(b.sel) } + r.Element.Children(func() { + if changed { + ui.Row(c).Absolute().Left(4).Top(20).Size(6, 6).Radius(3).Background(b.accent) + } + dot(c, 8, b.statusColor(status)) + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Row(c).FillWidth().Gap(6).Items(ui.Center).Children(func() { + ui.Text(c, toolchainName(tool)).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Shrink(1).Ellipsis() + if current.ok { + ui.Text(c, current.version).FontSize(11).Mono().Color(b.sub).Shrink(0) + } + if changed { + next := toolchainNext(scope, tool) + version := "?" + if next.ok { + version = next.version + } + ui.Text(c, "→ "+version).FontSize(11).Mono().Color(b.accent).Shrink(0) + } + ui.Spacer(c) + w.layerTag(c, language, current, status) + }) + ui.Row(c).FillWidth().Height(2).Shrink(0) + ui.Row(c).FillWidth().MinWidth(0).Items(ui.Center).Children(func() { + plugin := toolchainPluginName(scope, tool.PluginID, tool.PluginName) + if current.ok { + ui.Text(c, plugin+" · "+midTrim(current.home, 44)).FontSize(11).Color(b.faint).Shrink(1).Ellipsis() + return + } + detail := w.toolchainReasonDetail(language, scope, entry, tool) + if detail == "" { + ui.Text(c, plugin).FontSize(11).Color(b.faint).Shrink(1).Ellipsis() + return + } + ui.Text(c, plugin+" · ").FontSize(11).Color(b.faint).Shrink(0) + ui.Text(c, detail).FontSize(11).Color(b.statusColor(status)).Shrink(1).Ellipsis() + }) + }) + }) } -func (t *toolchainState) apply(snapshot toolchain.Snapshot, saved bool) { - t.snapshot = snapshot - t.loaded = true - t.saved = saved - t.failed = nil - { - t.custom = make(map[string]core.ToolchainPin) - t.registrations = make(map[string]bool) - t.customizing = make(map[string]bool) - t.inputs = make(map[string]*string) - t.draft = make(map[string]string, len(snapshot.Tools)) - for _, tool := range snapshot.Tools { - if tool.Pin != nil { - t.draft[tool.ID] = tool.Pin.Home - } +// toolchainReasonDetail is what a list row says after the plugin for a problem the row can +// name: the project file that waits for trust, or the plugins that declare the same tool. +func (w *window) toolchainReasonDetail(language i18n.Language, scope *toolchainScope, entry *toolchainEntry, tool *toolchain.Tool) string { + switch toolchainReason(*tool) { + case "projectCodeRequiresAction": + if source, _ := toolchainTrustSource(tool); source != "" { + return i18n.SharedFormat(language, "desktop.buildSettings.fromSource", map[string]string{"source": source}) } + case "conflict": + return toolchainConflictPlugins(language, scope, entry) } + return "" } -func (t *toolchainState) choose(tool, home string) { - if t.snapshot.Tools == nil { +// toolchainConflictPlugins names the plugins that declare a conflicting tool. +func toolchainConflictPlugins(language i18n.Language, scope *toolchainScope, entry *toolchainEntry) string { + names := make([]string, 0, len(entry.conflict)) + for _, id := range entry.conflict { + names = append(names, toolchainPluginName(scope, id, "")) + } + return strings.Join(names, i18n.Shared(language, "desktop.buildSettings.listSeparator")) +} + +// layerTag is the tag at the end of a tool's first line: the layer that chose its +// installation, or the reason none applies. +func (w *window) layerTag(c ui.C, language i18n.Language, result toolchainResult, status string) { + if !result.ok { + kind := tagErr + if status == "warning" { + kind = tagWarn + } + w.tag(c, kind, toolchainReasonLabel(language, result.reason)) return } - if t.draft == nil { - t.draft = make(map[string]string) + kind := tagPlain + switch result.layer { + case "pinned", "project": + kind = tagGreen + case "global": + kind = tagBlue } - t.draft[tool] = home - t.saved = false + w.tag(c, kind, toolchainLayerLabel(language, result.layer)) } -func (t *toolchainState) resetDrafts() { - for _, tool := range t.snapshot.Tools { - t.draft[tool.ID] = "" +// toolchainName is a tool's display name, its ID when it has none. +func toolchainName(tool *toolchain.Tool) string { + if tool.DisplayName != "" { + return tool.DisplayName } - clear(t.customizing) - t.saved = false + return tool.ID } -func (t *toolchainState) hasDraft() bool { - if len(t.registrations) != 0 { - return true +// toolchainPluginName is a plugin's display name as its tools carry it, else its ID. +func toolchainPluginName(scope *toolchainScope, pluginID, name string) string { + if name != "" { + return name } - for _, tool := range t.snapshot.Tools { - current := "" - if tool.Pin != nil { - current = tool.Pin.Home - } - if t.draft[tool.ID] != current { - return true + for _, tool := range scope.snapshot.Tools { + if tool.PluginID == pluginID && tool.PluginName != "" { + return tool.PluginName } } - return false + return pluginID } -// edits builds one pin change per tool whose draft differs from the saved -// document. A tool without an installed version cannot be pinned. -func (t *toolchainState) edits() []toolchain.Edit { - var edits []toolchain.Edit - for _, tool := range t.snapshot.Tools { - current := "" - if tool.Pin != nil { - current = tool.Pin.Home - } - wanted := t.draft[tool.ID] - if wanted == current && !t.registrations[tool.ID] { - continue +// toolchainCategoryLabel names a definition's display group. +func toolchainCategoryLabel(language i18n.Language, category, audience string) string { + if audience == "plugin" { + return i18n.Shared(language, "desktop.buildSettings.categoryPlugin") + } + switch category { + case "runtime": + return i18n.Shared(language, "desktop.buildSettings.categoryRuntime") + case "build": + return i18n.Shared(language, "desktop.buildSettings.categoryBuild") + case "package": + return i18n.Shared(language, "desktop.buildSettings.categoryPackage") + case "debug": + return i18n.Shared(language, "desktop.buildSettings.categoryDebug") + case "lint": + return i18n.Shared(language, "desktop.buildSettings.categoryLint") + default: + return i18n.Shared(language, "desktop.buildSettings.categoryOther") + } +} + +// toolchainTrustSource is the project file and home of the first project candidate that waits +// for trust. +func toolchainTrustSource(tool *toolchain.Tool) (source, home string) { + for _, project := range tool.Project { + if project.Reason == "projectCodeRequiresAction" { + home = project.Home + if home == "" { + home = project.Path + } + return project.Path, home } - if wanted == "" { - edits = append(edits, toolchain.Edit{Tool: tool.ID}) - continue + } + return "", "" +} + +// toolchainEntryFor is the chosen tool as the scope holds it, or the list's entry of a tool +// that several plugins declare and the snapshot leaves out. +func (t *toolchainState) toolchainEntryFor(scope *toolchainScope, id string) *toolchainEntry { + if tool := scope.tool(id); tool != nil { + return &toolchainEntry{tool: *tool} + } + for index := range t.view.entries { + if entry := &t.view.entries[index]; entry.tool.ID == id { + return entry } - if pin, ok := t.custom[tool.ID]; ok && pin.Home == wanted { - edits = append(edits, toolchain.Edit{Tool: tool.ID, Pin: &pin}) - continue + } + return nil +} + +// toolchainDetail is the prototype's .dt: the chosen tool's head, its problem, what it uses +// now and the choices of the scope. +func (w *window) toolchainDetail(c ui.C, language i18n.Language, scope *toolchainScope) { + t := w.toolchains + b := &w.bp + entry := t.toolchainEntryFor(scope, t.selected) + if entry == nil { + ui.Column(c).FillWidth().PadY(50).Items(ui.Center).Children(func() { + ui.Text(c, i18n.Shared(language, "desktop.buildSettings.selectTool")).FontSize(buildSmall).Color(b.faint) + }) + return + } + tool := &entry.tool + current := toolchainCurrent(tool) + status := toolchainStatus(current) + name := toolchainName(tool) + plugin := toolchainPluginName(scope, tool.PluginID, tool.PluginName) + ui.Column(c).FillWidth().MinWidth(0).Children(func() { + w.toolchainHead(c.Part("head"), language, scope, tool, name, plugin) + ui.Row(c).Height(14).Shrink(0) + if w.toolchainProblem(c.Part("problem"), language, scope, entry, current, status, name, plugin) { + ui.Row(c).Height(12).Shrink(0) } - for _, installation := range tool.Installations { - if installation.Home != wanted || installation.Version == "" { - continue + w.toolchainEffective(c.Part("effective"), language, scope, entry, current, status) + ui.Row(c).Height(12).Shrink(0) + w.toolchainChoices(c.Part("choices"), language, scope, tool, current) + ui.Row(c).Height(12).Shrink(0) + ui.Row(c).FillWidth().PadSides(10, 12, 0, 12).Children(func() { + // Not monospaced as in the prototype: the monospaced face sets CJK words a cell apart. + ui.Wrap(c, i18n.SharedFormat(language, "desktop.buildSettings.toolFooter", map[string]string{"id": tool.ID, "plugin": tool.PluginID})). + FontSize(11).Color(b.faint).Grow(1).Shrink(1).MinWidth(0) + }) + }) +} + +// toolchainHead is the tile, name and declaring plugin of the chosen tool, with the button that +// drops the scope's choice. +func (w *window) toolchainHead(c ui.C, language i18n.Language, scope *toolchainScope, tool *toolchain.Tool, name, plugin string) { + b := &w.bp + ui.Row(c).FillWidth().Gap(12).Items(ui.Start).Children(func() { + w.tile(c, nameColor(plugin), name, 40) + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).Children(func() { + ui.Text(c, name).FontSize(buildHeading).Weight(gfx.WeightBold).Color(b.text).Ellipsis() + ui.Row(c).Height(4).Shrink(0) + ui.Row(c).FillWidth().Gap(6).Items(ui.Center).Children(func() { + w.pluginTile(c, plugin, 20) + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.declaredBy", map[string]string{"plugin": plugin})). + FontSize(buildSmall).Color(b.sub).Shrink(1).Ellipsis() + ui.Text(c, "·").FontSize(buildSmall).Color(b.sub).Shrink(0) + ui.Text(c, toolchainCategoryLabel(language, tool.Category, tool.Audience)).FontSize(buildSmall).Color(b.sub).Shrink(1).Ellipsis() + }) + }) + if scope.wanted(tool.ID) != "" { + label := i18n.Shared(language, "desktop.buildSettings.restoreAutomatic") + tip := i18n.Shared(language, "desktop.buildSettings.restoreAutomaticTip") + if scope.name == scopeProject { + label = i18n.Shared(language, "desktop.buildSettings.restoreInherited") + tip = i18n.Shared(language, "desktop.buildSettings.restoreInheritedTip") + } + if w.buttonTip(c.Part("restore"), buttonSmall, label, tip, w.toolchains.saving) { + scope.choose(tool.ID, "") } - edits = append(edits, toolchain.Edit{Tool: tool.ID, Pin: &core.ToolchainPin{ - Home: installation.Home, Version: installation.Version, Provider: installation.Provider, - }}) - break } - } - return edits + }) } -// toolchainsPage is the Build settings page: each enabled plugin's declared -// tools, the effective layer Core selected, and an explicit local pin draft. -func (w *window) toolchainsPage(c ui.C) { - if w.ctrl.opts.Toolchains == nil && !w.stepping.available() { - w.unavailablePage(c) - return +// toolchainProblem is the box that says what keeps the tool from resolving and what fixes it. +// It reports whether it showed one. +func (w *window) toolchainProblem(c ui.C, language i18n.Language, scope *toolchainScope, entry *toolchainEntry, current toolchainResult, status, name, plugin string) bool { + if current.ok { + return false } - language := w.marketLanguage() - w.pageScroll(c, pageBuild, func() { - if w.ctrl.opts.Toolchains != nil { - w.toolchainCards(c, language) + t := w.toolchains + kind, icon := boxErr, icons.CircleX + if status == "warning" { + kind, icon = boxWarn, icons.CircleAlert + } + var text string + trust := false + switch current.reason { + case "conflict": + text = i18n.SharedFormat(language, "desktop.buildSettings.problemConflict", map[string]string{"plugins": toolchainConflictPlugins(language, scope, entry)}) + case "notFound": + kind, icon = boxWarn, icons.CircleAlert + text = i18n.SharedFormat(language, "desktop.buildSettings.problemNotFound", map[string]string{"tool": name}) + case "versionUnsatisfied": + text = i18n.SharedFormat(language, "desktop.buildSettings.problemVersion", map[string]string{"plugin": plugin}) + case "probeFailed": + text = i18n.Shared(language, "desktop.buildSettings.problemProbeFailed") + case "projectCodeRequiresAction": + source, home := toolchainTrustSource(&entry.tool) + text = i18n.SharedFormat(language, "desktop.buildSettings.problemTrust", map[string]string{"source": source, "home": home, "tool": name}) + trust = t.trustEffect != nil + default: + text = toolchainReasonLabel(language, current.reason) + } + w.box(c, kind, func(words gfx.Color) { + boxIcon(c, icon, words) + boxText(c, text, words) + if trust && w.button(c.Part("trust"), buttonSmall, i18n.Shared(language, "desktop.buildSettings.trustProject"), t.busy()) { + t.beginTrust(true) } - w.steppingCard(c, language) }) + return true } -// toolchainCards are the Build page's cards of the tools the installed plugins resolve. -func (w *window) toolchainCards(c ui.C, language i18n.Language) { +// toolchainEffective is the prototype's 当前生效 card: the program, version and source the tool +// uses now, what the draft changes it to, and the resolution steps on request. +func (w *window) toolchainEffective(c ui.C, language i18n.Language, scope *toolchainScope, entry *toolchainEntry, current toolchainResult, status string) { t := w.toolchains - if !t.loaded && !t.busy() && t.failed == nil { - t.beginLoad() - } - w.card(c, i18n.Shared(language, "desktop.toolchains.title"), i18n.Shared(language, "desktop.toolchains.description"), func() { - ui.Column(c).FillWidth().Gap(8).Children(func() { - if _, ok := t.loader.(ToolchainScopedLoader); ok { - previous := t.scope - ui.Row(c.Part("scope")).FillWidth().Gap(16).Children(func() { - disabled := t.busy() || t.hasDraft() - w.radio(c.Part("global"), &t.scope, "global", i18n.Shared(language, "desktop.toolchains.global"), disabled) - w.radio(c.Part("project"), &t.scope, "project", i18n.Shared(language, "desktop.toolchains.project"), disabled) + b := &w.bp + tool := &entry.tool + w.section(c, i18n.Shared(language, "desktop.buildSettings.effectiveTitle"), i18n.Shared(language, "desktop.buildSettings.effectiveHelp"), nil, func() { + ui.Column(c).FillWidth().MinWidth(0).PadSides(2, 12, 4, 12).Gap(6).Children(func() { + if !current.ok { + w.toolchainKV(c, i18n.Shared(language, "desktop.buildSettings.status"), func() { + dot(c, 8, b.statusColor(status)) + ui.Wrap(c, w.toolchainReasonText(language, scope, entry, current.reason)).FontSize(buildFont).Color(b.text).Grow(1).Shrink(1).MinWidth(0) }) - if t.scope != previous { - t.beginLoad() - } + return } - help := i18n.Shared(language, "desktop.toolchains.chooseHelp") - if t.scope == "global" { - help = i18n.Shared(language, "desktop.toolchains.globalHelp") + program := current.executable + if program == "" { + program = current.home } - ui.Wrap(c, help).FontSize(12).Color(w.pal.muted) - if !t.snapshot.Global && t.snapshot.Root != "" && t.loaded && t.trustEffect != nil { - trusted := t.snapshot.ProjectCodeAllowed - if t.trusting { - trusted = t.trustWanted + w.toolchainKVTop(c, i18n.Shared(language, "desktop.buildSettings.program"), func() { + ui.Wrap(c, program).FontSize(buildMono).Mono().Color(b.text).Grow(1).Shrink(1).MinWidth(0) + copyLabel := i18n.Shared(language, "desktop.buildSettings.copyPath") + copyButton := ui.ButtonBase(c.Part("copy"), copyLabel).Size(20, 20).Shrink(0).Radius(6).Center(). + Hover(ui.Look{}.Background(b.hover)).Tooltip(copyLabel) + if copyButton.Clicked() { + if err := copyText(program); err != nil { + t.failed = err + reportSettingsError(w.ctrl.opts, "settings_toolchain_copy", err) + } } - ui.Row(c.Part("trust")).FillWidth().Height(28).Items(ui.Center).Gap(6).Children(func() { - if ui.Switch(c.Part("switch"), &trusted, i18n.Shared(language, "desktop.toolchains.trustProject")).Disabled(t.busy()).Changed() { - t.beginTrust(trusted) + copyButton.Children(func() { + ui.Icon(c, icons.Copy).Size(11, 11).Color(b.sub) + }) + }) + w.toolchainKV(c, i18n.Shared(language, "desktop.buildSettings.version"), func() { + ui.Text(c, current.version).FontSize(buildMono).Mono().Color(b.text).Shrink(1).Ellipsis() + }) + w.toolchainKV(c, i18n.Shared(language, "desktop.buildSettings.source"), func() { + w.layerTag(c, language, current, status) + for _, option := range t.options(language, scope, tool) { + if !option.auto && option.home == current.home { + for _, source := range option.sources { + w.tag(c, tagSource, source) + } + break } - w.infoButton(c.Part("help"), i18n.Shared(language, "desktop.toolchains.trustProjectHelp")) - ui.Spacer(c) - statusText := i18n.Shared(language, "desktop.toolchains.trustStatusUntrusted") - if t.snapshot.ProjectCodeAllowed { - statusText = i18n.Shared(language, "desktop.toolchains.trustStatusTrusted") + } + }) + }) + if scope.changed(tool.ID) { + next := toolchainNext(scope, tool) + ui.Row(c).FillWidth().PadSides(8, 12, 2, 12).Children(func() { + w.box(c.Part("next"), boxNext, func(words gfx.Color) { + dot(c, 7, b.accent) + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Items(ui.Center).Children(func() { + ui.Text(c, i18n.Shared(language, "desktop.buildSettings.afterApply")).FontSize(buildSmall).Color(words).Shrink(0) + if !next.ok { + ui.Text(c, toolchainReasonLabel(language, next.reason)).FontSize(buildSmall).Color(words).Shrink(1).Ellipsis() + return + } + ui.Text(c, next.version).FontSize(buildSmall).Mono().Weight(gfx.WeightBold).Color(words).Shrink(0) + ui.Text(c, " · ").FontSize(buildSmall).Color(words).Shrink(0) + ui.Text(c, midTrim(next.home, 60)).FontSize(buildSmall).Mono().Color(words).Shrink(1).Ellipsis() + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.parenthesized", map[string]string{"text": toolchainLayerLabel(language, next.layer)})). + FontSize(buildSmall).Color(words).Shrink(0) + }) + if w.button(c.Part("undo"), buttonLinkSmall, i18n.Shared(language, "desktop.buildSettings.undoChange"), t.saving) { + scope.undo(tool.ID) } - ui.Text(c, statusText).FontSize(11).Color(w.pal.muted).Shrink(1).Ellipsis() }) - if !t.snapshot.ProjectCodeAllowed && snapshotRequiresProjectTrust(t.snapshot) { - ui.Wrap(c, i18n.Shared(language, "desktop.toolchains.projectTrustRequiredNotice")).FontSize(12).Color(w.pal.warning) - } - } - ui.Row(c).FillWidth().Gap(8).Items(ui.Center).Children(func() { - if ui.Button(c, i18n.Shared(language, "desktop.toolchains.reload")).Outline().Disabled(t.busy()).Clicked() { - t.beginLoad() - } - if ui.Button(c, i18n.Shared(language, "desktop.toolchains.reset")).Outline().Disabled(t.busy()).Clicked() { - t.resetDrafts() - } - ui.Spacer(c) - if ui.Button(c, i18n.Shared(language, "desktop.toolchains.save")).Disabled(!t.loaded || !t.hasDraft() || t.busy()).Clicked() { - t.beginSave() + }) + } + if len(tool.Trace) > 0 { + ui.Row(c).FillWidth().Children(func() { + why := i18n.Shared(language, "desktop.buildSettings.why") + disclose := ui.ButtonBase(c.Part("why"), why).PadX(12).PadY(4).Gap(4).Items(ui.Center).Shrink(0) + if disclose.Clicked() { + t.whyOpen = !t.whyOpen } + disclose.Children(func() { + caret := icons.ChevronRight + if t.whyOpen { + caret = icons.ChevronDown + } + ui.Icon(c, caret).Size(10, 10).Color(b.accent) + ui.Text(c, why).FontSize(buildSmall).Color(b.accent) + }) }) - switch { - case t.loading || t.inspecting: - ui.Text(c, i18n.Shared(language, "desktop.toolchains.loading")).FontSize(12).Color(w.pal.muted) - case t.trusting: - ui.Text(c, i18n.Shared(language, "desktop.toolchains.updatingTrust")).FontSize(12).Color(w.pal.muted) - case t.saving: - ui.Text(c, i18n.Shared(language, "desktop.toolchains.saving")).FontSize(12).Color(w.pal.muted) - case t.failed != nil: - ui.Text(c, toolchainFailureMessage(language, t.failed)).FontSize(12).Color(w.pal.danger) - case t.saved: - ui.Text(c, i18n.Shared(language, "desktop.toolchains.saved")).FontSize(12).Color(w.pal.muted) + if t.whyOpen { + w.toolchainTrace(c.Part("trace"), language, tool, current) } - }) + } + ui.Row(c).Height(6).Shrink(0) }) - if t.snapshot.Root == "" && !t.snapshot.Global && t.loaded { - w.card(c.Part("no-project"), i18n.Shared(language, "desktop.toolchains.title"), "", func() { - ui.Text(c, i18n.Shared(language, "desktop.toolchains.noProject")).FontSize(12).Color(w.pal.muted) - }) - return - } - for _, conflict := range t.snapshot.Conflicts { - plugins := strings.Join(conflict.PluginIDs, ", ") - w.card(c.Key("conflict:"+conflict.Tool), i18n.Shared(language, "desktop.toolchains.title"), "", func() { - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.conflict", map[string]string{"tool": conflict.Tool, "plugins": plugins})).FontSize(12).Color(w.pal.danger) - }) - } - for _, tool := range t.snapshot.Tools { - w.card(c.Key("tool:"+tool.ID), tool.DisplayName, "", func() { - w.toolchainTool(c, language, tool) +} + +// toolchainKV is one line of the 当前生效 card: the key in its 72-point column, the value after. +func (w *window) toolchainKV(c ui.C, key string, value func()) { + w.toolchainKVAt(c, key, ui.Center, value) +} + +// toolchainKVTop is a line whose value may wrap: the key stays on its first line. +func (w *window) toolchainKVTop(c ui.C, key string, value func()) { + w.toolchainKVAt(c, key, ui.Start, value) +} + +func (w *window) toolchainKVAt(c ui.C, key string, align ui.Align, value func()) { + b := &w.bp + ui.Row(c).FillWidth().MinWidth(0).Gap(10).Items(align).Children(func() { + ui.Row(c).Width(72).Shrink(0).MinHeight(20).Items(ui.Center).Children(func() { + ui.Text(c, key).FontSize(buildSmall).Color(b.sub).Ellipsis() }) - } + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).MinHeight(20).Gap(6).Items(align).Children(value) + }) } -func (w *window) toolchainTool(c ui.C, language i18n.Language, tool toolchain.Tool) { - t := w.toolchains - busy := t.busy() - ui.Column(c).FillWidth().Gap(6).Children(func() { - ui.Text(c, tool.PluginID).FontSize(11).Color(w.pal.muted) - switch { - case tool.Effective != nil: - value := tool.Effective.Executable - if tool.Effective.Version != "" { - value += " (" + tool.Effective.Version + ")" - } - if tool.Effective.Layer != "" { - value += " · " + toolchainLayerLabel(language, tool.Effective.Layer) - } - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.effective", map[string]string{"value": value})).FontSize(12).Color(w.pal.text) - default: - code := toolchainReason(tool) - color := w.pal.danger - if code == "projectCodeRequiresAction" { - color = w.pal.warning - } - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.unavailable", map[string]string{"reason": toolchainReasonLabel(language, code)})).FontSize(12).Color(color) - } - // One list holds every directory the tool can use: the automatic choice, which shows - // what discovery picks, each installation found, the saved pin, a checked directory, - // and, where directories can be checked, Custom… for one discovery did not find. - var choices []string - labels := make(map[string]string) - add := func(home, label string) { - if _, ok := labels[home]; !ok { - choices = append(choices, home) - labels[home] = label - } - } - automatic := tool.AutomaticHome - if automatic == "" { - if toolRequiresProjectTrust(tool) { - automatic = i18n.Shared(language, "desktop.toolchains.reasonProjectTrustRequired") - } else { - automatic = i18n.Shared(language, "desktop.toolchains.noInstallations") - } - } - add("", i18n.SharedFormat(language, "desktop.toolchains.automatic", map[string]string{"value": automatic})) - // An installation without a version cannot be pinned, so it is not a choice; it is - // listed under the list. - var unversioned []string - for _, installation := range tool.Installations { - label := i18n.SharedFormat(language, "desktop.toolchains.installation", map[string]string{ - "home": installation.Home, "version": installation.Version, "provider": installation.Provider, - }) - if installation.Version == "" { - unversioned = append(unversioned, label) - continue - } - add(installation.Home, label) - } - if tool.Pin != nil { - label := i18n.SharedFormat(language, "desktop.toolchains.pinSource", map[string]string{"directory": tool.PinSource}) - add(tool.Pin.Home, tool.Pin.Home+" · "+label) - } - if pin, ok := t.custom[tool.ID]; ok { - add(pin.Home, i18n.SharedFormat(language, "desktop.toolchains.installation", map[string]string{"home": pin.Home, "version": pin.Version, "provider": pin.Provider})) - } - if t.inspectEffect != nil { - add(toolchainCustom, i18n.Shared(language, "desktop.toolchains.custom")) - } - pick := t.pick(tool.ID) - *pick = t.draft[tool.ID] - if t.customizing[tool.ID] { - *pick = toolchainCustom - } - // A draft of a directory no entry names still shows as itself. - add(*pick, *pick) - label := func(home string) string { return labels[home] } - if busy { - w.readOnlyField(c.Part("choice"), tool.DisplayName, label(*pick)) - } else { - ui.Select(c.Part("choice"), pick, choices, label).FillWidth().MinWidth(0).Label(tool.DisplayName) - } - if *pick == toolchainCustom { - t.customizing[tool.ID] = true - } else { - delete(t.customizing, tool.ID) - if *pick != t.draft[tool.ID] { - t.choose(tool.ID, *pick) - } - } - for _, line := range unversioned { - ui.Text(c, line).FontSize(11).Color(w.pal.muted) +// toolchainReasonText is the 状态 line of a tool that does not resolve. +func (w *window) toolchainReasonText(language i18n.Language, scope *toolchainScope, entry *toolchainEntry, reason string) string { + switch reason { + case "conflict": + return i18n.SharedFormat(language, "desktop.buildSettings.conflictReason", map[string]string{"plugins": toolchainConflictPlugins(language, scope, entry)}) + case "projectCodeRequiresAction": + if source, _ := toolchainTrustSource(&entry.tool); source != "" { + return i18n.SharedFormat(language, "desktop.buildSettings.trustReason", map[string]string{"source": source}) } - if t.customizing[tool.ID] { - input := t.inputs[tool.ID] - if input == nil { - input = new(string) - t.inputs[tool.ID] = input - } - label := i18n.Shared(language, "desktop.toolchains.directory") - ui.Row(c.Part("manual")).FillWidth().Gap(8).Items(ui.Center).Children(func() { - if busy { - w.readOnlyField(c, label, *input) - } else { - ui.TextField(c, input, label, label).Grow(1).MinWidth(0).Height(30) + } + return toolchainReasonLabel(language, reason) +} + +// toolchainTrace is the prototype's .trace: each layer Core tried, the one it used checked and +// the ones it could not use marked. +func (w *window) toolchainTrace(c ui.C, language i18n.Language, tool *toolchain.Tool, current toolchainResult) { + b := &w.bp + ui.Column(c).FillWidth().MinWidth(0).PadSides(4, 12, 2, 12).Children(func() { + for index, step := range tool.Trace { + k := c.KeyInt(index) + layer := toolchainLayerLabel(language, step.Layer) + candidate := toolchainTraceCandidate(tool, step.CandidateID) + var text string + mark, words := "–", b.sub + markColor := b.sub + switch { + case step.State == "resolved": + mark, words, markColor = "", b.text, b.ok + detail := candidate + if current.ok { + detail = current.version + " · " + current.home } - w.infoButton(c, i18n.Shared(language, "desktop.toolchains.directoryHelp")) - if ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.browse")).Outline().Disabled(busy).Clicked() { - c.After(func() { w.pickToolchainDirectory(tool.ID, input, label) }) + text = i18n.SharedFormat(language, "desktop.buildSettings.traceStep", map[string]string{"layer": layer, "detail": detail}) + case step.State == "empty": + text = i18n.SharedFormat(language, "desktop.buildSettings.traceStep", map[string]string{ + "layer": layer, + "detail": i18n.Shared(language, "desktop.buildSettings.notSet"), + }) + default: + mark, markColor = "!", b.warn + reason := "" + if step.Reason != nil { + reason = toolchainReasonLabel(language, step.Reason.Code) } - if ui.Button(c, i18n.Shared(language, "desktop.toolchains.useDirectory")).Outline().Disabled(busy || *input == "").Clicked() { - t.beginInspect(tool.ID, *input) + detail := reason + if candidate != "" && reason != "" { + detail = i18n.SharedFormat(language, "desktop.buildSettings.traceCandidate", map[string]string{"candidate": candidate, "reason": reason}) + } else if candidate != "" { + detail = candidate } - }) - } - for _, project := range tool.Project { - display := project.Home - if display == "" { - display = project.Path - } - if project.Reason == "projectCodeRequiresAction" { - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.projectCandidateBlocked", map[string]string{"path": display})).FontSize(11).Color(w.pal.warning) - continue - } - version := "" - if project.Version != nil { - version = *project.Version - } else if project.Reason != "" { - version = toolchainReasonLabel(language, project.Reason) + text = i18n.SharedFormat(language, "desktop.buildSettings.traceStep", map[string]string{"layer": layer, "detail": detail}) } - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.installation", map[string]string{ - "home": display, "version": version, "provider": "host:project", - })).FontSize(11).Color(w.pal.muted) - } - for _, shell := range tool.Shell { - // A variable's name, or the command found on the PATH: both are the user's own words. - source := shell.Variable - if source == "" { - source = shell.Command - } - version := source - if shell.Version != nil { - version += " " + *shell.Version - } else if shell.Reason != "" { - version += " " + shell.Reason - } - ui.Text(c, i18n.SharedFormat(language, "desktop.toolchains.installation", map[string]string{ - "home": shell.Home, "version": version, "provider": source, - })).FontSize(11).Color(w.pal.muted) - } - if tool.ProviderQueriesUnsupported { - ui.Text(c, i18n.Shared(language, "desktop.toolchains.providerUnsupported")).FontSize(11).Color(w.pal.muted) + ui.Row(k).FillWidth().MinWidth(0).PadY(3).Gap(8).Items(ui.Start).Children(func() { + ui.Row(k).Width(14).Shrink(0).MinHeight(16).Center().Children(func() { + if mark == "" { + ui.Icon(k, icons.Check).Size(11, 11).Color(markColor) + return + } + ui.Text(k, mark).FontSize(buildSmall).Weight(gfx.WeightBold).Color(markColor) + }) + ui.Wrap(k, text).FontSize(buildSmall).Color(words).Grow(1).Shrink(1).MinWidth(0) + }) } }) } -func (w *window) pickToolchainDirectory(tool string, input *string, title string) { - path, err := app.OpenDirectory(app.OpenDirectoryOptions{Title: title}) - // log-exempt: 用户取消:关闭目录选择器不修改工具链草稿。 - if errors.Is(err, app.ErrCanceled) { - return +// toolchainTraceCandidate names a step's candidate by what the user can recognize: the project +// file or the variable behind it, else the ID the plugin gave it. +func toolchainTraceCandidate(tool *toolchain.Tool, id string) string { + if id == "" { + return "" } - if err != nil { - w.toolchains.failed = err - if w.ctrl.opts.MarketplaceError != nil { - w.ctrl.opts.MarketplaceError(err) + for _, project := range tool.Project { + if project.CandidateID == id && project.Path != "" { + return project.Path } - return } - if path != "" && w.toolchains.inputs[tool] == input { - *input = path - w.toolchains.beginInspect(tool, path) + for _, shell := range tool.Shell { + if shell.CandidateID == id { + if shell.Variable != "" { + return shell.Variable + } + if shell.Command != "" { + return shell.Command + } + } } + return id } -func toolchainReason(tool toolchain.Tool) string { - for _, trace := range tool.Trace { - if trace.Reason != nil && trace.Reason.Code != "" { - return trace.Reason.Code +// toolchainChoices is the prototype's 本项目使用 / 全局默认使用 card: the automatic or inherited +// choice, each home the scope knows, and the field that adds a directory. +func (w *window) toolchainChoices(c ui.C, language i18n.Language, scope *toolchainScope, tool *toolchain.Tool, current toolchainResult) { + t := w.toolchains + b := &w.bp + options := t.options(language, scope, tool) + title := i18n.Shared(language, "desktop.buildSettings.optionsGlobal") + var help string + if scope.name == scopeProject { + title = i18n.Shared(language, "desktop.buildSettings.optionsProject") + help = i18n.Shared(language, "desktop.buildSettings.optionsProjectHelp") + } else { + var order []string + for _, option := range options { + if !option.auto && len(option.sources) > 0 && !slices.Contains(order, option.sources[0]) { + order = append(order, option.sources[0]) + } } - } - for _, project := range tool.Project { - if project.Reason != "" { - return project.Reason + if len(order) > 0 { + help = i18n.SharedFormat(language, "desktop.buildSettings.optionsGlobalHelp", map[string]string{"order": strings.Join(order, " → ")}) + } else { + help = i18n.Shared(language, "desktop.buildSettings.optionsGlobalHelpPlain") } } - return "notFound" + pick := scope.wanted(tool.ID) + w.section(c, title, help, nil, func() { + ui.Column(c).FillWidth().MinWidth(0).PadX(4).Children(func() { + for _, option := range options { + w.toolchainOption(c.Key("option:"+option.home), language, scope, tool, option, option.home == pick, current) + } + }) + w.toolchainAddRow(c.Part("add"), language, scope, tool) + }) + _ = b } -func toolRequiresProjectTrust(tool toolchain.Tool) bool { - for _, project := range tool.Project { - if project.Reason == "projectCodeRequiresAction" { - return true +// toolchainAutoLabel is the first choice's words: what the tool resolves to without a pin in the +// scope, or why nothing does. +func toolchainAutoLabel(language i18n.Language, scope *toolchainScope, tool *toolchain.Tool) string { + automatic := tool.Automatic + if automatic == nil { + reason := tool.AutomaticReason + if reason == "" { + reason = "notFound" } + return i18n.SharedFormat(language, "desktop.buildSettings.autoReason", map[string]string{"reason": toolchainReasonLabel(language, reason)}) } - for _, trace := range tool.Trace { - if trace.Reason != nil && trace.Reason.Code == "projectCodeRequiresAction" { - return true - } + home := tool.AutomaticHome + if home == "" && automatic.Home != nil { + home = *automatic.Home } - return false -} - -func snapshotRequiresProjectTrust(snapshot toolchain.Snapshot) bool { - for _, tool := range snapshot.Tools { - if toolRequiresProjectTrust(tool) { - return true + source := toolchainSourceLabel(language, automatic.Provider) + if scope.name == scopeProject { + switch automatic.Layer { + case "project": + for _, project := range tool.Project { + if project.Path != "" && (project.Home == home || project.Path == home) { + source = project.Path + break + } + } + return i18n.SharedFormat(language, "desktop.buildSettings.autoProject", map[string]string{"version": automatic.Version, "source": source}) + case "global": + return i18n.SharedFormat(language, "desktop.buildSettings.inheritWith", map[string]string{"version": automatic.Version}) } } - return false + return i18n.SharedFormat(language, "desktop.buildSettings.autoWith", map[string]string{"version": automatic.Version, "source": source}) } -func toolchainReasonLabel(language i18n.Language, code string) string { - switch code { - case "projectCodeRequiresAction": - return i18n.Shared(language, "desktop.toolchains.reasonProjectTrustRequired") - case "notFound": - return i18n.Shared(language, "desktop.toolchains.noInstallations") - case "probeFailed": - return i18n.Shared(language, "desktop.toolchains.reasonProbeFailed") - case "versionUnsatisfied": - return i18n.Shared(language, "desktop.toolchains.reasonVersionUnsatisfied") - case "notExecutable": - return i18n.Shared(language, "desktop.toolchains.reasonNotExecutable") - case "unsafePath": - return i18n.Shared(language, "desktop.toolchains.reasonUnsafePath") - default: - return code +// toolchainOption is one radio row of the choices: the version, the home and its sources, or +// the reason it cannot be chosen. +func (w *window) toolchainOption(c ui.C, language i18n.Language, scope *toolchainScope, tool *toolchain.Tool, option toolchainOption, on bool, current toolchainResult) { + t := w.toolchains + b := &w.bp + label := option.home + if option.auto { + label = toolchainAutoLabel(language, scope, tool) } -} - -func toolchainLayerLabel(language i18n.Language, layer string) string { - switch layer { - case "pinned": - return i18n.Shared(language, "desktop.toolchains.layerPinned") - case "project": - return i18n.Shared(language, "desktop.toolchains.layerProject") - case "global": - return i18n.Shared(language, "desktop.toolchains.layerGlobal") - case "automatic": - return i18n.Shared(language, "desktop.toolchains.layerAutomatic") - default: - return layer + disabled := option.why != "" || t.saving + box := ui.ButtonBase(c, label).FillWidth().MinWidth(0).PadX(8).PadY(6).Gap(8).Radius(7).Items(ui.Center) + switch { + case on: + box = box.Background(b.chip) + case !disabled: + box = box.Hover(ui.Look{}.Background(b.hover)) + } + if !option.auto { + box = box.Tooltip(option.home) } + if disabled { + box = box.Disabled(true).Opacity(0.62) + } + if box.Clicked() && !disabled { + scope.choose(tool.ID, option.home) + } + box.Children(func() { + ui.Row(c).Width(18).Shrink(0).Items(ui.Center).Children(func() { + ring := b.faint + if on { + ring = b.accent + } + ui.Row(c).Size(14, 14).Shrink(0).Radius(7).Border(1.5, ring).Center().Children(func() { + if on { + dot(c, 6, b.accent) + } + }) + }) + if option.auto { + ui.Text(c, label).FontSize(12.5).Color(b.text).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + return + } + version := option.version + if version == "" { + version = "—" + } + ui.Text(c, version).FontSize(buildMono).Mono().Color(b.text).Width(92).Shrink(0).Ellipsis() + ui.Text(c, midTrim(option.home, 58)).FontSize(buildMono).Mono().Color(b.sub).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + ui.Row(c).Shrink(0).Gap(4).Items(ui.Center).Children(func() { + if option.why != "" { + kind := tagErr + if option.why == i18n.Shared(language, "desktop.toolchains.reasonProjectTrustRequired") { + kind = tagWarn + } + w.tag(c, kind, option.why) + return + } + if current.ok && option.home == current.home { + w.tag(c, tagGreen, i18n.Shared(language, "desktop.buildSettings.inUse")) + } + for _, source := range option.sources { + w.tag(c, tagSource, source) + } + }) + }) } -// pick is the bound value of one tool's radio group. It lives as long as the window, so the -// radios keep their identities. -func (t *toolchainState) pick(tool string) *string { - if t.picks[tool] == nil { - t.picks[tool] = new(string) +// toolchainAddRow is the prototype's .addrow: a link that opens the field for an installation +// directory, then the field with its browse, check and cancel. +func (w *window) toolchainAddRow(c ui.C, language i18n.Language, scope *toolchainScope, tool *toolchain.Tool) { + t := w.toolchains + if t.inspectEffect == nil { + return } - return t.picks[tool] + ui.Row(c).FillWidth().MinWidth(0).PadX(8).PadY(6).Gap(6).Items(ui.Center).Children(func() { + if t.adding != tool.ID { + if w.button(c.Part("open"), buttonLinkSmall, i18n.Shared(language, "desktop.buildSettings.addDirectory"), t.saving) { + t.adding = tool.ID + } + return + } + input := scope.input(tool.ID) + directory := i18n.Shared(language, "desktop.toolchains.directory") + var field ui.Box + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Children(func() { + field = w.filterField(c.Part("field"), input, directory, i18n.Shared(language, "desktop.buildSettings.addPlaceholder"), false) + }) + w.infoButton(c.Part("help"), i18n.Shared(language, "desktop.buildSettings.addHelp")) + if w.button(c.Part("browse"), buttonSmall, i18n.Shared(language, "desktop.pluginSettings.browse"), t.busy()) { + w.pickToolchainDirectory(tool.ID, input, directory) + } + home := strings.TrimSpace(*input) + check := w.button(c.Part("check"), buttonSmall, i18n.Shared(language, "desktop.buildSettings.checkAndUse"), home == "" || t.busy()) + if (check || field.Submitted()) && home != "" && !t.busy() { + t.beginInspect(tool.ID, home) + } + if w.button(c.Part("cancel"), buttonLinkSmall, i18n.Shared(language, "desktop.buildSettings.cancel"), false) { + t.adding = "" + } + }) } diff --git a/desktop/internal/settingswindow/toolchains_view_test.go b/desktop/internal/settingswindow/toolchains_view_test.go index 2862eb441..20b735d8a 100644 --- a/desktop/internal/settingswindow/toolchains_view_test.go +++ b/desktop/internal/settingswindow/toolchains_view_test.go @@ -2,8 +2,10 @@ package settingswindow import ( "context" + "errors" "slices" "strings" + "sync/atomic" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -13,10 +15,11 @@ import ( type fakeToolchainLoader struct { snapshot toolchain.Snapshot - loaded chan struct{} saved chan []toolchain.Edit saveErr error inspectErr error + // loads counts the reads; the window reads on an effect goroutine. + loads atomic.Int32 } func (f *fakeToolchainLoader) Inspect(_ context.Context, _ toolchain.Snapshot, _ string, home string) (core.ToolchainSelection, error) { @@ -24,9 +27,7 @@ func (f *fakeToolchainLoader) Inspect(_ context.Context, _ toolchain.Snapshot, _ } func (f *fakeToolchainLoader) Load(context.Context) (toolchain.Snapshot, error) { - if f.loaded != nil { - close(f.loaded) - } + f.loads.Add(1) return f.snapshot, nil } @@ -54,107 +55,107 @@ func (f *fakeToolchainLoader) Save(_ context.Context, snapshot toolchain.Snapsho return snapshot, nil } +const fixtureTool = "dev.example:compiler" + func fixtureSnapshot() toolchain.Snapshot { + home := "/fixture/compiler" return toolchain.Snapshot{ Root: "/fixture", Directory: ".", Tools: []toolchain.Tool{{ - ID: "dev.example:compiler", - DisplayName: "Compiler", - PluginID: "dev.example", + ID: fixtureTool, + DisplayName: "Compiler", + PluginID: "dev.example", + AutomaticHome: home, + Automatic: &core.ToolchainSelection{Home: &home, Executable: home + "/bin/compiler", Version: "1.2.3", Provider: "host:system"}, Installations: []core.ToolchainInstallation{{ - Home: "/fixture/compiler", Version: "1.2.3", Provider: "host:system", + Home: home, Version: "1.2.3", Provider: "host:system", }}, }}, } } -// toolchainWindow opens a settings window on the Build page with loader and waits for its -// first load. -func toolchainWindow(t *testing.T, loader *fakeToolchainLoader) (*window, *windowDriver) { +// toolchainWindow opens a settings window on the Toolchains page with loader and waits for the +// shown scope's first load and list. +func toolchainWindow(t *testing.T, loader ToolchainLoader) (*window, *windowDriver) { t.Helper() w := newWindow(NewController(Options{Toolchains: loader}), Values{}) - w.sess.page = pageBuild + w.sess.page = pageToolchains d := openWindow(t, w) - d.until("the toolchains to load", func() bool { return w.toolchains.loaded }) + d.until("the toolchains to load", func() bool { return w.toolchains.current().loaded && w.toolchains.view.ready }) + d.pump() return w, d } -func installationLabel() string { - return i18n.SharedFormat(i18n.English, "desktop.toolchains.installation", map[string]string{ - "home": "/fixture/compiler", "version": "1.2.3", "provider": "host:system", - }) -} +func en(id string) string { return i18n.Shared(i18n.English, id) } -// chooseToolchain chooses entry in the fixture tool's directory list, by the label the list -// shows for it. +// chooseToolchain chooses the radio row labeled entry among the chosen tool's choices. func (d *windowDriver) chooseToolchain(entry string) { d.t.Helper() - d.click("Compiler") d.click(entry) d.pump() } -// enterToolchainDirectory chooses Custom… in the fixture tool's list and checks home there. +// enterToolchainDirectory opens the chosen tool's add-directory field, types home and checks it. func (d *windowDriver) enterToolchainDirectory(home string) { d.t.Helper() - d.chooseToolchain(i18n.Shared(i18n.English, "desktop.toolchains.custom")) - d.click(i18n.Shared(i18n.English, "desktop.toolchains.directory")) + d.click(en("desktop.buildSettings.addDirectory")) + d.pump() + d.click(en("desktop.toolchains.directory")) d.typeText(home) - d.click(i18n.Shared(i18n.English, "desktop.toolchains.useDirectory")) + d.click(en("desktop.buildSettings.checkAndUse")) } -// TestToolchainListShowsAutomaticAndHidesTheDirectoryUntilCustom opens the Build page on a tool -// discovery found: its list reads the automatic entry with the directory discovery picks, offers -// the installation and Custom…, and shows the directory field only while Custom… is chosen. -func TestToolchainListShowsAutomaticAndHidesTheDirectoryUntilCustom(t *testing.T) { - snapshot := fixtureSnapshot() - snapshot.Tools[0].AutomaticHome = "/fixture/compiler" - w, d := toolchainWindow(t, &fakeToolchainLoader{snapshot: snapshot}) - automatic := i18n.SharedFormat(i18n.English, "desktop.toolchains.automatic", map[string]string{"value": "/fixture/compiler"}) - custom := i18n.Shared(i18n.English, "desktop.toolchains.custom") - directory := i18n.Shared(i18n.English, "desktop.toolchains.directory") - if !d.showsWrapped(automatic) { - t.Fatalf("the list does not read %q", automatic) +// applyBuild clicks the footer's Apply and waits for its writes to end. +func (d *windowDriver) applyBuild() { + d.t.Helper() + d.click(en("desktop.buildSettings.apply")) + d.until("the apply to end", func() bool { return !d.w.apply.active() && !d.w.toolchains.saving }) + d.pump() +} + +// The chosen tool lists what it falls back to, each installation once and the link that opens +// the directory field, which stays closed until it is asked for and writes no draft. +func TestToolchainChoicesListAutomaticAndOpenTheDirectoryOnDemand(t *testing.T) { + w, d := toolchainWindow(t, &fakeToolchainLoader{snapshot: fixtureSnapshot()}) + automatic := i18n.SharedFormat(i18n.English, "desktop.buildSettings.autoWith", map[string]string{ + "version": "1.2.3", "source": toolchainSourceLabel(i18n.English, "host:system"), + }) + if !d.has(automatic) || !d.has("/fixture/compiler") { + t.Fatalf("the choices have automatic = %v and the installation = %v, want both", d.has(automatic), d.has("/fixture/compiler")) } + directory := en("desktop.toolchains.directory") if d.has(directory) { - t.Fatal("the directory field shows before Custom… is chosen") + t.Fatal("the directory field shows before it is asked for") } - d.click("Compiler") - d.pump() - if !d.has(installationLabel()) || !d.has(custom) { - t.Fatalf("the open list has the installation = %v and Custom… = %v, want both", d.has(installationLabel()), d.has(custom)) - } - d.click(custom) + d.click(en("desktop.buildSettings.addDirectory")) d.pump() if !d.has(directory) { - t.Fatal("choosing Custom… did not show the directory field") + t.Fatal("Add directory did not open the field") } - if w.toolchains.hasDraft() { - t.Fatal("choosing Custom… made a draft before a directory was checked") + if w.toolchains.drafts(w.toolchains.scope) != 0 { + t.Fatal("opening the field made a draft before a directory was checked") } - d.chooseToolchain(automatic) + // The footer has a Cancel too; the field's is the one drawn first. + d.clickHit(d.first(en("desktop.buildSettings.cancel"))) + d.pump() if d.has(directory) { - t.Fatal("choosing another entry left the directory field") + t.Fatal("Cancel left the directory field") } } -func TestToolchainDraftSavesOnlyExplicitChanges(t *testing.T) { +func TestToolchainDraftAppliesOnlyExplicitChanges(t *testing.T) { loader := &fakeToolchainLoader{snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1)} w, d := toolchainWindow(t, loader) state := w.toolchains - if len(state.snapshot.Tools) != 1 { - t.Fatalf("load state = %+v", state) - } - if state.hasDraft() { + if state.drafts(state.scope) != 0 { t.Fatal("a freshly loaded page already had a draft") } - save := i18n.Shared(i18n.English, "desktop.toolchains.save") - if !d.hit(save).Disabled { - t.Fatal("Save is enabled without a draft") + if !d.hit(en("desktop.buildSettings.apply")).Disabled { + t.Fatal("Apply is enabled without a draft") } - d.chooseToolchain(installationLabel()) - if !state.hasDraft() { + d.chooseToolchain("/fixture/compiler") + if state.drafts(state.scope) != 1 { t.Fatal("choosing an installation did not create a draft") } select { @@ -162,40 +163,38 @@ func TestToolchainDraftSavesOnlyExplicitChanges(t *testing.T) { t.Fatalf("choosing wrote %+v", edits) default: } - d.click(save) - d.until("the save to finish", func() bool { return state.saved }) + d.applyBuild() select { case edits := <-loader.saved: if len(edits) != 1 || edits[0].Pin == nil || edits[0].Pin.Home != "/fixture/compiler" { t.Fatalf("edits = %+v", edits) } default: - t.Fatal("save was not requested") + t.Fatal("Apply did not write") } - if state.snapshot.Tools[0].Pin == nil { - t.Fatalf("saved state = %+v", state) + if state.current().snapshot.Tools[0].Pin == nil || state.drafts(state.scope) != 0 { + t.Fatalf("applied state = %+v", state.current()) } } -func TestToolchainManualDirectoryIsValidatedBeforeAnExplicitSave(t *testing.T) { +func TestToolchainManualDirectoryIsValidatedBeforeAnExplicitApply(t *testing.T) { loader := &fakeToolchainLoader{snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1)} w, d := toolchainWindow(t, loader) d.enterToolchainDirectory("/fixture/custom") - d.until("the checked directory", func() bool { return w.toolchains.draft["dev.example:compiler"] == "/fixture/custom" }) + d.until("the checked directory", func() bool { return w.toolchains.current().draft[fixtureTool] == "/fixture/custom" }) select { case edits := <-loader.saved: t.Fatalf("validating a directory wrote %+v", edits) default: } - d.click(i18n.Shared(i18n.English, "desktop.toolchains.save")) - d.until("the manual directory to save", func() bool { return w.toolchains.saved }) + d.applyBuild() select { case edits := <-loader.saved: if len(edits) != 1 || edits[0].Pin == nil || edits[0].Pin.Home != "/fixture/custom" || edits[0].Pin.Version != "9.1" { t.Fatalf("manual directory pin = %+v", edits) } default: - t.Fatal("manual directory was not saved") + t.Fatal("the manual directory was not written") } } @@ -203,59 +202,59 @@ type scopedToolchainLoader struct{ fakeToolchainLoader } func (f *scopedToolchainLoader) LoadScope(ctx context.Context, scope string) (toolchain.Snapshot, error) { result, err := f.Load(ctx) - result.Global = scope == "global" + result.Global = scope == scopeGlobal return result, err } -func TestGlobalToolchainsKeepMultipleManualSDKsWithoutAProject(t *testing.T) { +// Without a project the page opens on the machine defaults, and one Apply registers every +// directory the user checked, not only the one chosen. +func TestGlobalToolchainsRegisterEveryCheckedSDKWithoutAProject(t *testing.T) { fixture := fixtureSnapshot() fixture.Root = "" loader := &scopedToolchainLoader{fakeToolchainLoader{snapshot: fixture, saved: make(chan []toolchain.Edit, 1)}} - w := newWindow(NewController(Options{Toolchains: loader}), Values{}) - w.sess.page = pageBuild - d := openWindow(t, w) - d.until("global toolchains without a project", func() bool { return w.toolchains.loaded }) - if !w.toolchains.snapshot.Global || !d.text("Global defaults") || !d.text("Compiler") { + w, d := toolchainWindow(t, loader) + if !w.toolchains.current().snapshot.Global || !d.text("Compiler") { t.Fatal("the toolchain page requires a project or does not default to global") } + d.until("the project scope to read no project", func() bool { return w.toolchains.noProject() }) + d.pump() + if !d.hit(en("desktop.toolchains.project")).Disabled { + t.Fatal("the project scope can be chosen without a project") + } for _, home := range []string{"/fixture/sdk8", "/fixture/sdk21"} { d.enterToolchainDirectory(home) - d.until("the checked SDK", func() bool { return w.toolchains.draft["dev.example:compiler"] == home }) - // Clear the input for the next native text entry without changing its draft. - *w.toolchains.inputs["dev.example:compiler"] = "" - } - if got := w.toolchains.snapshot.Tools[0].CustomHomes; !slices.Equal(got, []string{"/fixture/sdk8", "/fixture/sdk21"}) { - t.Fatalf("manual SDK registrations = %v", got) + d.until("the checked SDK", func() bool { return w.toolchains.current().draft[fixtureTool] == home }) + d.pump() } - if !d.hit("Current project").Disabled { - t.Fatal("switching scopes could discard an unsaved registration") + if !d.has("/fixture/sdk8") || !d.has("/fixture/sdk21") { + t.Fatal("a checked SDK is not listed as a choice") } select { case <-loader.saved: t.Fatal("directory validation published settings") default: } - d.click(i18n.Shared(i18n.English, "desktop.toolchains.save")) - d.until("global SDKs saved", func() bool { return w.toolchains.saved }) - if w.toolchains.hasDraft() { - t.Fatal("saved registrations remain dirty") + d.applyBuild() + state := w.toolchains.current() + if len(state.draft) != 0 { + t.Fatal("applied registrations remain dirty") } - if len(w.toolchains.snapshot.Tools[0].CustomHomes) != 2 { - t.Fatal("saving lost a registered SDK") + if got := state.snapshot.Tools[0].CustomHomes; !slices.Equal(got, []string{"/fixture/sdk8", "/fixture/sdk21"}) { + t.Fatalf("manual SDK registrations = %v", got) } } func TestToolchainDraftCancelWritesNothing(t *testing.T) { loader := &fakeToolchainLoader{snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1)} w, d := toolchainWindow(t, loader) - d.chooseToolchain(installationLabel()) - d.click("Cancel") + d.chooseToolchain("/fixture/compiler") + d.click(en("ui.cancel")) select { case edits := <-loader.saved: t.Fatalf("cancel wrote %+v", edits) default: } - if !w.toolchains.hasDraft() { + if w.toolchains.drafts(w.toolchains.scope) != 1 { t.Fatal("cancel must keep the draft until the window is gone") } if !w.sess.finished.Load() { @@ -263,47 +262,54 @@ func TestToolchainDraftCancelWritesNothing(t *testing.T) { } } -func TestToolchainSaveConflictKeepsDraft(t *testing.T) { +func TestToolchainApplyConflictKeepsDraft(t *testing.T) { loader := &fakeToolchainLoader{ snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1), saveErr: toolchain.ErrPinConflict, } w, d := toolchainWindow(t, loader) state := w.toolchains - d.chooseToolchain(installationLabel()) - d.click(i18n.Shared(i18n.English, "desktop.toolchains.save")) - d.until("the conflict", func() bool { return state.failed != nil }) + d.chooseToolchain("/fixture/compiler") + d.applyBuild() + if state.failed == nil || w.apply.failed == nil { + t.Fatalf("the conflict did not stop the apply: page %v, footer %v", state.failed, w.apply.failed) + } message := toolchainFailureMessage(i18n.Chinese, state.failed) if !strings.Contains(message, "重新加载") || strings.Contains(message, toolchain.ErrPinConflict.Error()) { t.Fatalf("conflict did not use the selected language: %q", message) } - if !d.text(toolchainFailureMessage(i18n.English, state.failed)) { + if english := toolchainFailureMessage(i18n.English, state.failed); !d.showsWrapped(english) && !d.text(english) { t.Fatal("the conflict is not on the page") } - if state.snapshot.Tools[0].Pin != nil { + if state.current().snapshot.Tools[0].Pin != nil { t.Fatal("a conflict changed the displayed pin") } - if !state.hasDraft() { + if state.drafts(state.scope) != 1 { t.Fatal("a conflict dropped the draft") } + if w.sess.finished.Load() { + t.Fatal("a failed apply closed the window") + } } -// A completed publication with failed readback must never reuse its old byte -// baseline, even when the user's draft remains visible for recovery. -func TestToolchainCommittedSaveRequiresReloadBeforeRetry(t *testing.T) { - state := newToolchainState(&fakeToolchainLoader{}) - state.apply(fixtureSnapshot(), false) - state.choose("dev.example:compiler", "/fixture/compiler") - state.finish(toolchain.Snapshot{}, toolchain.ErrPinCommitted, true) - if state.loaded { - t.Error("failed readback left an editable source baseline") +// A write that landed but could not be read back leaves no baseline to write on: the page reads +// the scope again before anything else, and the drafts, now on disk, are gone. +func TestToolchainCommittedApplyReadsTheScopeAgain(t *testing.T) { + loader := &fakeToolchainLoader{ + snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1), + saveErr: errors.Join(toolchain.ErrPinCommitted, errors.New("readback failed")), } - if !state.hasDraft() { - t.Error("failed readback discarded the draft") + w, d := toolchainWindow(t, loader) + state := w.toolchains + d.chooseToolchain("/fixture/compiler") + before := loader.loads.Load() + d.applyBuild() + if !errors.Is(w.apply.failed, toolchain.ErrPinCommitted) { + t.Fatalf("footer failure = %v", w.apply.failed) } - state.beginSave() - if state.saving { - t.Error("retry reused a baseline from before the committed save") + d.until("the scope to be read again", func() bool { return loader.loads.Load() > before && state.current().loaded }) + if state.drafts(state.scope) != 0 { + t.Fatal("the written drafts are still shown as unapplied") } } @@ -321,16 +327,16 @@ type trustToolchainLoader struct { globalSnapshot toolchain.Snapshot untrusted toolchain.Snapshot trustedSnapshot toolchain.Snapshot - trusted bool + trusted atomic.Bool trustCalls []bool trustErr error } func (l *trustToolchainLoader) LoadScope(_ context.Context, scope string) (toolchain.Snapshot, error) { - if scope == "global" { + if scope == scopeGlobal { return l.globalSnapshot, nil } - if l.trusted { + if l.trusted.Load() { return l.trustedSnapshot, nil } return l.untrusted, nil @@ -341,7 +347,7 @@ func (l *trustToolchainLoader) SetWorkspaceTrust(_ context.Context, _ toolchain. if l.trustErr != nil { return toolchain.Snapshot{}, l.trustErr } - l.trusted = trusted + l.trusted.Store(trusted) if trusted { return l.trustedSnapshot, nil } @@ -353,11 +359,12 @@ func TestProjectToolchainTrustSwitchGrantsAndRevokesImmediately(t *testing.T) { global.Global = true global.Root = "" + const runtime = "dev.lithe.test.runtime:interp" untrusted := toolchain.Snapshot{ Root: "/fixture/project", Directory: ".", Tools: []toolchain.Tool{{ - ID: "dev.lithe.test.runtime:interp", + ID: runtime, DisplayName: "Synthetic Runtime", PluginID: "dev.lithe.test.runtime", Project: []core.ToolchainProjectCandidate{{ @@ -374,23 +381,25 @@ func TestProjectToolchainTrustSwitchGrantsAndRevokesImmediately(t *testing.T) { } venvVersion := "3.12.4" venvHome := "/fixture/project/.venv" + venv := core.ToolchainSelection{ + Home: &venvHome, + Executable: "/fixture/project/.venv/bin/interp", + Version: venvVersion, + Provider: "host:project", + Layer: "project", + ProjectCode: true, + } trusted := toolchain.Snapshot{ Root: "/fixture/project", Directory: ".", ProjectCodeAllowed: true, Tools: []toolchain.Tool{{ - ID: "dev.lithe.test.runtime:interp", + ID: runtime, DisplayName: "Synthetic Runtime", PluginID: "dev.lithe.test.runtime", AutomaticHome: venvHome, - Effective: &core.ToolchainSelection{ - Home: &venvHome, - Executable: "/fixture/project/.venv/bin/interp", - Version: venvVersion, - Provider: "host:project", - Layer: "project", - ProjectCode: true, - }, + Automatic: &venv, + Effective: &venv, Project: []core.ToolchainProjectCandidate{{ CandidateID: "project-venv", ProjectKind: "environment", @@ -411,30 +420,25 @@ func TestProjectToolchainTrustSwitchGrantsAndRevokesImmediately(t *testing.T) { untrusted: untrusted, trustedSnapshot: trusted, } - w := newWindow(NewController(Options{Toolchains: loader}), Values{}) - w.sess.page = pageBuild - d := openWindow(t, w) - d.until("global toolchains loaded", func() bool { return w.toolchains.loaded }) - - // Switch to Current project scope. - d.click(i18n.Shared(i18n.English, "desktop.toolchains.project")) - d.until("project toolchains loaded", func() bool { return w.toolchains.loaded && !w.toolchains.snapshot.Global }) + w, d := toolchainWindow(t, loader) + state := w.toolchains + d.until("the project scope to load", func() bool { return state.projectName() != "" }) + d.pump() - notice := i18n.Shared(i18n.English, "desktop.toolchains.projectTrustRequiredNotice") - blockedRow := i18n.SharedFormat(i18n.English, "desktop.toolchains.projectCandidateBlocked", map[string]string{"path": venvHome}) - autoBlocked := i18n.SharedFormat(i18n.English, "desktop.toolchains.automatic", map[string]string{ - "value": i18n.Shared(i18n.English, "desktop.toolchains.reasonProjectTrustRequired"), + // The project's segment is named after its folder. + d.click(i18n.SharedFormat(i18n.English, "desktop.buildSettings.scopeProjectNamed", map[string]string{"project": "project"})) + d.until("project toolchains shown", func() bool { + return state.scope == scopeProject && state.current().loaded && state.view.ready && state.view.got.scope == scopeProject }) - if !d.showsWrapped(notice) || !d.text(blockedRow) || !d.showsWrapped(autoBlocked) { - t.Fatalf("untrusted UI missing guidance: notice=%v blocked=%v auto=%v", - d.showsWrapped(notice), d.text(blockedRow), d.showsWrapped(autoBlocked)) - } - if !d.text(i18n.Shared(i18n.English, "desktop.toolchains.trustStatusUntrusted")) { - t.Fatal("missing untrusted status label") + d.pump() + + blocked := en("desktop.toolchains.reasonProjectTrustRequired") + if !d.has(en("desktop.buildSettings.trustProject")) || !d.text(blocked) { + t.Fatalf("untrusted page misses its guidance: trust button %v, blocked tag %v", d.has(en("desktop.buildSettings.trustProject")), d.text(blocked)) } - // Verify the ⓘ tip explains consequences and local storage scope. - help := i18n.Shared(i18n.English, "desktop.toolchains.trustProjectHelp") + // The banner's ⓘ explains what trusting does and where it is stored. + help := en("desktop.toolchains.trustProjectHelp") infoBounds := d.hintHit(help).Bounds if err := d.driver.Move(infoBounds.X+infoBounds.Width/2, infoBounds.Y+infoBounds.Height/2); err != nil { t.Fatal(err) @@ -443,47 +447,45 @@ func TestProjectToolchainTrustSwitchGrantsAndRevokesImmediately(t *testing.T) { if !d.showsHelp(help) { t.Fatal("resting on the project trust ⓘ did not show its help") } - // Leave the ⓘ before toggling the switch. + // Leave the ⓘ before trusting the project. if err := d.driver.Move(2, 2); err != nil { t.Fatal(err) } d.pump() - // Grant trust: reloads immediately without touching .lithe/toolchains/local.json Save. - d.click(i18n.Shared(i18n.English, "desktop.toolchains.trustProject")) - d.until("project trust granted", func() bool { return w.toolchains.snapshot.ProjectCodeAllowed && !w.toolchains.trusting }) + // Granting trust reloads at once, without an Apply. + d.click(en("desktop.buildSettings.trustProject")) + d.until("project trust granted", func() bool { return state.current().snapshot.ProjectCodeAllowed && !state.trusting }) + d.pump() if !slices.Equal(loader.trustCalls, []bool{true}) { t.Fatalf("trustCalls = %v, want [true]", loader.trustCalls) } - autoResolved := i18n.SharedFormat(i18n.English, "desktop.toolchains.automatic", map[string]string{"value": venvHome}) - if !d.showsWrapped(autoResolved) { - t.Fatalf("trusted UI did not update automatic effective value to %q", autoResolved) + resolved := i18n.SharedFormat(i18n.English, "desktop.buildSettings.autoProject", map[string]string{ + "version": venvVersion, "source": "/fixture/project/.venv/bin/interp", + }) + if !d.has(resolved) { + t.Fatalf("the trusted page does not fall back to %q", resolved) } - if !d.text(i18n.Shared(i18n.English, "desktop.toolchains.trustStatusTrusted")) { - t.Fatal("missing trusted status label") + if !d.has(en("desktop.toolchains.trustStatusTrusted")) { + t.Fatal("the trusted status is missing") } - // Create an unsaved pin draft, then revoke trust: the pin draft must be preserved. - d.click("Synthetic Runtime") - d.click(i18n.SharedFormat(i18n.English, "desktop.toolchains.installation", map[string]string{ - "home": "/fixture/system-runtime", "version": "3.11.0", "provider": "host:system", - })) - d.pump() - if !w.toolchains.hasDraft() { - t.Fatal("expected unsaved pin draft before revoking trust") + // An unapplied choice survives revoking trust. + d.chooseToolchain("/fixture/system-runtime") + if state.drafts(scopeProject) != 1 { + t.Fatal("expected an unapplied choice before revoking trust") } - - d.click(i18n.Shared(i18n.English, "desktop.toolchains.trustProject")) - d.until("project trust revoked", func() bool { return !w.toolchains.snapshot.ProjectCodeAllowed && !w.toolchains.trusting }) + d.click(en("desktop.buildSettings.revokeTrust")) + d.until("project trust revoked", func() bool { return !state.current().snapshot.ProjectCodeAllowed && !state.trusting }) if !slices.Equal(loader.trustCalls, []bool{true, false}) { t.Fatalf("trustCalls = %v, want [true, false]", loader.trustCalls) } - if !w.toolchains.hasDraft() { - t.Fatal("revoking trust discarded the unsaved pin draft") + if state.drafts(scopeProject) != 1 { + t.Fatal("revoking trust discarded the unapplied choice") } select { case edits := <-loader.saved: - t.Fatalf("toggling local workspace trust wrote project pin file: %+v", edits) + t.Fatalf("changing the project's trust wrote pins: %+v", edits) default: } } diff --git a/desktop/internal/settingswindow/visual_capture_test.go b/desktop/internal/settingswindow/visual_capture_test.go index fc4d40a70..12ac11ab3 100644 --- a/desktop/internal/settingswindow/visual_capture_test.go +++ b/desktop/internal/settingswindow/visual_capture_test.go @@ -47,9 +47,10 @@ func TestVisualSettings(t *testing.T) { {"25-settings-process", pageProcessTermination}, {"26-settings-git", pageVersionControl}, {"26-settings-git-console", pageVersionControl}, {"27-settings-terminal", pageTerminal}, {"28-plugins-installed", pagePlugins}, {"29-marketplace-empty", pagePlugins}, - {"33-settings-toolchains", pageBuild}, {"m44-toolchain-directory-menu", pageBuild}, {"m45-toolchain-custom-directory", pageBuild}, - {"m47-toolchain-project-untrusted", pageBuild}, {"m48-toolchain-project-trusted", pageBuild}, {"m49-toolchain-project-trust-click", pageBuild}, - {"m50-toolchain-project-trust-tip", pageBuild}, + {"32-settings-build", pageBuild}, {"32-settings-build-folder", pageBuild}, {"34-settings-debuggers", pageDebuggers}, + {"33-settings-toolchains", pageToolchains}, {"m44-toolchain-directory-menu", pageToolchains}, {"m45-toolchain-custom-directory", pageToolchains}, + {"m47-toolchain-project-untrusted", pageToolchains}, {"m48-toolchain-project-trusted", pageToolchains}, {"m49-toolchain-project-trust-click", pageToolchains}, + {"m50-toolchain-project-trust-tip", pageToolchains}, {"fonts", pageFonts}, {"21-settings-language-popup", pageGeneral}, {"30-settings-history", pageGeneral}, {"m46-history-default-rules-help", pageGeneral}, {"35-settings-search", pageEditor}, {"m35-editor-tab-layout", pageEditor}, {"m25-project-open-mode", pageGeneral}, {"m29-editor-font-menu", pageFonts}, {"m38-plugin-management-menu", pagePlugins}, @@ -83,9 +84,37 @@ func TestVisualSettings(t *testing.T) { Toolchains: visualToolchainLoader(scenario.id), // Every build can sign in to GitHub; no account is connected yet. GitHub: &GitHubAccount{Snapshot: func() GitHubState { return GitHubState{Available: true} }}, + // Two installed debuggers take stepping filters; one keeps the user's own. + SteppingAdapters: func(context.Context) ([]SteppingAdapter, error) { + return []SteppingAdapter{ + {ID: "fixture-jvm", Name: "Fixture JVM Debugger", PluginID: "dev.example.jvm", PluginName: "Fixture JVM", Defaults: core.DebugSteppingFilters{ClassNameFilters: []string{"java.*", "javax.*", "sun.*"}, SkipSynthetics: true, SkipStaticInitializers: true}}, + {ID: "fixture-native", Name: "Fixture Native Debugger", PluginID: "dev.example.native", PluginName: "Fixture Native", Defaults: core.DebugSteppingFilters{ClassNameFilters: []string{"std::*"}}}, + }, nil + }, + NormalizeSteppingFilters: func(_ context.Context, _ string, filters core.DebugSteppingFilters) (core.DebugSteppingFilters, error) { + return filters, nil + }, + SetSteppingFilters: func(string, *core.DebugSteppingFilters) {}, + } + values := Values{Theme: theme, Language: language.Code(), TerminalScrollback: 2000} + if scenario.page == pageBuild || scenario.page == pageDebuggers { + values.SteppingFilters = map[string]core.DebugSteppingFilters{"fixture-jvm": {ClassNameFilters: []string{"java.*", "javax.*", "sun.*", "com.example.generated.*"}, SkipSynthetics: true, SkipStaticInitializers: true}} + } + if scenario.page == pageBuild { + // Eight plugins each bring a build system page, so the kind folds into a folder. + contributions := buildPageContributions(t, 8) + client := core.NewClient() + opts.SettingsNavigation = client.SettingsNavigation + opts.SettingsPages = func(ctx context.Context) ([]core.SettingsPage, error) { + return client.SettingsPages(ctx, contributions) + } } - w := newWindow(NewController(opts), Values{Theme: theme, Language: language.Code(), TerminalScrollback: 2000}) + w := newWindow(NewController(opts), values) w.sess.page = scenario.page + if scenario.page == pageBuild || parents[scenario.page] == pageBuild { + // As the Build page opens its pages: with the group open in the sidebar. + w.sess.open[pageBuild] = true + } if scenario.id == "29-marketplace-empty" { w.pluginTab = pluginTabMarketplace } @@ -98,8 +127,14 @@ func TestVisualSettings(t *testing.T) { switch scenario.page { case pageTerminal: d.until("shell choices", func() bool { return w.terminal.loaded }) + case pageToolchains: + d.until("toolchain facts", func() bool { return w.toolchains.current().loaded }) case pageBuild: - d.until("toolchain facts", func() bool { return w.toolchains.loaded }) + d.until("the build page's facts", func() bool { + return w.toolchains.current().loaded && w.toolchains.view.ready && w.stepping.loaded && w.dynamic.loaded + }) + case pageDebuggers: + d.until("the debuggers", func() bool { return w.stepping.loaded }) case pagePlugins: d.until("offline index", func() bool { return w.market.status == marketReady }) case pageFonts: @@ -166,20 +201,24 @@ func TestVisualSettings(t *testing.T) { d.click(text("desktop.settings.processTermination.onQuit")) case "m43-process-orphan-policy": d.click(text("desktop.settings.processTermination.leftoverTerminals")) + case "32-settings-build-folder": + w.openFolder("buildSystem") + d.pump() case "m44-toolchain-directory-menu": d.click("Compiler") case "m45-toolchain-custom-directory": - d.click("Compiler") - d.click(text("desktop.toolchains.custom")) + d.click(text("desktop.buildSettings.addDirectory")) d.pump() case "m47-toolchain-project-untrusted", "m48-toolchain-project-trusted", "m49-toolchain-project-trust-click", "m50-toolchain-project-trust-tip": - d.click(text("desktop.toolchains.project")) + d.until("the project scope", func() bool { return w.toolchains.projectName() != "" }) + d.pump() + d.click(i18n.SharedFormat(language, "desktop.buildSettings.scopeProjectNamed", map[string]string{"project": "workspace"})) status := text("desktop.toolchains.trustStatusTrusted") - if scenario.id == "m47-toolchain-project-untrusted" { - status = text("desktop.toolchains.trustStatusUntrusted") + if scenario.id != "m48-toolchain-project-trusted" { + status = text("desktop.buildSettings.trustProject") } // The load result can arrive during painting, before the trust controls appear. - d.until("the visible project trust status", func() bool { return d.text(status) }) + d.until("the visible project trust status", func() bool { return d.has(status) }) if scenario.id != "m49-toolchain-project-trust-click" && scenario.id != "m50-toolchain-project-trust-tip" { break } @@ -290,10 +329,12 @@ func visualToolchainLoader(scenarioID string) ToolchainLoader { }}, } switch scenarioID { - case "m47-toolchain-project-untrusted": + case "m47-toolchain-project-untrusted", "m49-toolchain-project-trust-click", "m50-toolchain-project-trust-tip": return &trustToolchainLoader{globalSnapshot: global, untrusted: untrusted, trustedSnapshot: trusted} - case "m48-toolchain-project-trusted", "m49-toolchain-project-trust-click", "m50-toolchain-project-trust-tip": - return &trustToolchainLoader{globalSnapshot: global, untrusted: untrusted, trustedSnapshot: trusted, trusted: true} + case "m48-toolchain-project-trusted": + loader := &trustToolchainLoader{globalSnapshot: global, untrusted: untrusted, trustedSnapshot: trusted} + loader.trusted.Store(true) + return loader default: return &scopedToolchainLoader{fakeToolchainLoader{snapshot: global}} } diff --git a/desktop/internal/settingswindow/window.go b/desktop/internal/settingswindow/window.go index f246f2c60..9f0d6e90d 100644 --- a/desktop/internal/settingswindow/window.go +++ b/desktop/internal/settingswindow/window.go @@ -40,9 +40,17 @@ const ( tileRadius = 4 tileGlyph = 12 tileGap = 8 - // childIndent is what a row inside a group is indented by, so its title lines up with - // the title of the group. + // childIndent is where the title of a row inside a group starts, under the title of the + // group. levelIndent is the Tree's step of a level, which a row's content pads up to where + // its title starts, so a folder's chevron sits in front of the titles beside it; folderStep + // is how much further in a folder's pages start, the prototype's step from l1 to l2. childIndent = chevronSlot + tileSize + tileGap + levelIndent = childIndent / 2 + folderStep = 18 + // sectionHeight is the height of a section's title in the search, the prototype's .hd. + sectionHeight = 26 + // crumbHeight is the height of the breadcrumb, the prototype's .crumb. + crumbHeight = 42 // contentPad is the margin of the page at its sides. contentPad = 26 @@ -59,8 +67,9 @@ const ( radioDot = 6 // emptyWidth is the width the sentence of a page that is not available yet wraps at. emptyWidth = 360 - // footerHeight is the height of the bar with the buttons. - footerHeight = 52 + // footerHeight is the height of the bar with the buttons under its 1px top line, 50 in all + // as in the prototype. + footerHeight = 49 // footerPad is the margin of the bar's buttons at its sides. footerPad = 16 ) @@ -113,8 +122,17 @@ type window struct { requestedPage atomic.Uint32 pluginRegistryChanged atomic.Bool // toolchains is the Build settings page's draft and loaded snapshot. - toolchains *toolchainState - stepping *steppingState + toolchains *toolchainState + stepping *steppingState + // apply is the footer's write of the Build pages' drafts. + apply buildApply + // folders says which folders of plugin pages the sidebar lists the pages of, by their + // kind's place in buildKinds. folderPage is the kind whose folder page shows while the + // Build page is open, empty for the Build page itself; folderQuery filters it. + folders [len(buildKinds)]bool + folderPage string + folderQuery string + folderList ui.ListState pluginSettings *pluginSettingsForm pluginForms map[string]*pluginSettingsForm formLimitReported bool @@ -173,9 +191,11 @@ type window struct { marketSourceNotice string // What the current paint works from. - text *i18n.Messages - dark bool - pal palette + text *i18n.Messages + dark bool + pal palette + // bp is the look of the Build, Execution, Deployment pages (build_style.go). + bp buildPalette theme ui.Theme // background is what the page fills the window with, which follows the look. background ui.Color @@ -190,10 +210,10 @@ type window struct { // rows is the sidebar as listed for rowsFor, rebuilt only when what it depends on has // changed. nav is the Tree that shows them. rows []row - rowsFor rowsKey + rowsFor sidebarKey rowsValid bool nav ui.TreeState - crumbs []string + crumbs []crumb // The words of the two lists, built for labelsFor. themeLabels []string @@ -203,11 +223,21 @@ type window struct { labelsValid bool } -// rowsKey is everything the sidebar's rows are computed from. +// rowsKey is everything Core's projection of the sidebar is computed from. type rowsKey struct { - text *i18n.Messages - query string - open [pageCount]bool + text *i18n.Messages + query string + open [pageCount]bool + folders [len(buildKinds)]bool +} + +// sidebarKey is everything the sidebar's rows are computed from: Core's projection, and while +// searching the tools and the debuggers that match. +type sidebarKey struct { + rows rowsKey + revision uint64 + tools toolchainWant + adapters int } // labelsKey is everything the words of the two lists are computed from. @@ -250,7 +280,7 @@ func newWindow(c *Controller, current Values) *window { w.terminal = newTerminalShellState(c.opts.TerminalShells) w.fonts = newFontListState(c.opts.MonospaceFamilies) w.generation = newAIGeneration(c.opts, func() { w.inv.Invalidate() }) - w.nav.Node, w.nav.Key, w.nav.RowHeight, w.nav.Indent = w.navNode, w.navKey, rowHeight, childIndent + w.nav.Node, w.nav.Key, w.nav.RowHeight, w.nav.Indent = w.navNode, w.navKey, rowHeight, levelIndent return w } @@ -393,16 +423,18 @@ func (w *window) closed() { } } -// accept is OK: it closes the window. A second OK, such as an Enter -// that arrives with a click, does nothing. +// accept is OK: it writes the Build pages' drafts, then closes the window (build_apply.go). +// A second OK, such as an Enter that arrives with a click, joins the write that is out. func (w *window) accept() { - if w.sess.accept() { - w.closeNative() - } + w.startApply(true) } -// cancel is Cancel: it closes the window without undoing already applied settings. +// cancel is Cancel: it drops the Build pages' drafts and closes the window without undoing +// already applied settings. It waits for nothing: while a write is out, Cancel is off. func (w *window) cancel() { + if w.apply.active() { + return + } if w.sess.cancel() { w.closeNative() } @@ -425,6 +457,7 @@ func (w *window) prepare(size gfx.Size) { w.text = w.ctrl.text() w.dark = windowDark(w.sess.values.Theme, w.ctrl.systemDark()) w.pal = paletteFor(w.dark) + w.bp = buildPaletteFor(w.dark) if !w.themed || w.themedDark != w.dark { w.theme, w.themed, w.themedDark = windowTheme(w.dark, w.pal), true, w.dark } @@ -436,10 +469,12 @@ func (w *window) prepare(size gfx.Size) { // collect takes the result of each background request on the window thread. func (w *window) collect() { - w.toolchains.take() - if saved, ok := w.stepping.take(); ok { + toolchainFailed := w.toolchains.take() + saved, err, done := w.stepping.take() + if done && err == nil { w.setSteppingFilters(saved.adapter, &saved.filters) } + w.advanceApply(toolchainFailed, steppingResult{done: done, err: err}) w.terminal.take() w.fonts.take() w.takeKeymapImport() @@ -499,17 +534,30 @@ func (w *window) declareWork(c ui.C) { // refreshRows rebuilds the sidebar's rows when the language, the search or the expanded // groups have changed since they were built. func (w *window) refreshRows() { - key := rowsKey{text: w.text, query: w.query, open: w.sess.open} - if w.rowsValid && key == w.rowsFor { + key := rowsKey{text: w.text, query: w.query, open: w.sess.open, folders: w.folders} + projected := w.ctrl.opts.SettingsNavigation != nil + if projected { + w.dynamic.request(key) + } + full := sidebarKey{rows: key, revision: w.dynamic.revision} + if w.query != "" { + full.tools, full.adapters = w.searchSources() + } + if w.rowsValid && full == w.rowsFor { return } - if w.ctrl.opts.SettingsNavigation != nil { - w.dynamic.request(key) - w.rows = w.dynamic.rows + var pages []row + if projected { + pages = w.dynamic.rows + } else { + pages = appendVisible(nil, &w.text.Settings, &key.open, w.query) + } + if w.query == "" { + w.rows = pages } else { - w.rows = appendVisible(w.rows[:0], &w.text.Settings, &key.open, w.query) + w.rows = w.searchSections(pages) } - w.rowsFor, w.rowsValid = key, true + w.rowsFor, w.rowsValid = full, true } // refreshLabels rebuilds the words of the appearance choice and the language list when the diff --git a/desktop/internal/settingswindow/window_view.go b/desktop/internal/settingswindow/window_view.go index f9ebd1a7d..7a9b0996e 100644 --- a/desktop/internal/settingswindow/window_view.go +++ b/desktop/internal/settingswindow/window_view.go @@ -1,6 +1,8 @@ package settingswindow import ( + "strings" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/fontprefs" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -108,8 +110,9 @@ func (w *window) sidebar(c ui.C) { } } if len(w.rows) == 0 { - ui.Row(c).FillWidth().Shrink(0).PadX(16).PadY(8).Children(func() { - ui.Wrap(c, settings.NoMatches).FontSize(12).Color(p.muted) + // The prototype's empty search: one sentence in the middle of the column's width. + ui.Row(c).FillWidth().Shrink(0).PadSides(30, 10, 30, 10).Justify(ui.Center).Children(func() { + ui.Wrap(c, settings.NoMatches).FontSize(buildSmall).Color(w.bp.faint).TextCenter() }) return } @@ -118,19 +121,78 @@ func (w *window) sidebar(c ui.C) { w.toggleRow(w.rows[i]) } if i, ok := w.nav.Chosen(); ok && i < len(w.rows) { - // A group with a page of its own, which only plugins' pages made a group, opens its - // page; its chevron folds the plugins' pages. - if r := w.rows[i]; r.group && isGroup(r.page) { - w.toggleRow(r) - } else { - w.selectSettingsPage(r.page, r.dynamic) - } + w.chooseRow(w.rows[i]) } }) } -// toggleRow expands or collapses the group of row r. While searching every group is open. +// chooseRow opens what row r stands for. A group without a page of its own folds; one with a +// page, which Build is and plugins' pages make any entry they are under, opens it, and Build +// lists its pages as it opens. A folder opens its own page. A search ends once its row is +// chosen, with the rows above the page opened so the page's row is on the screen. +func (w *window) chooseRow(r row) { + if w.chooseSearchRow(r) { + return + } + searching := w.query != "" + switch { + case r.folder != "": + w.openFolder(r.folder) + case r.group && isGroup(r.page) && !ownsPage(r.page) && r.dynamic == "": + w.toggleRow(r) + return + default: + if r.page == pageBuild && r.dynamic == "" { + w.sess.open[pageBuild] = true + } + w.folderPage = "" + w.selectSettingsPage(r.page, r.dynamic) + } + if searching { + w.revealPage(r) + w.clearSearch() + } +} + +// openFolder shows the page of the folder of kind under Build, Execution, Deployment. +func (w *window) openFolder(kind string) { + w.folderPage, w.folderQuery = kind, "" + w.sess.open[pageBuild] = true + w.selectSettingsPage(pageBuild, "") +} + +// revealPage opens every row above the page row r opens, and the folder of a plugin's page +// in one. +func (w *window) revealPage(r row) { + for page := parents[r.page]; page != noPage; page = parents[page] { + w.sess.open[page] = true + } + if r.dynamic != "" { + w.sess.open[r.page] = true + if page := w.dynamic.selected(r.dynamic); page != nil { + if index := kindIndex(page.Kind); index >= 0 && w.dynamic.kindCount(page.Kind) >= folderMin { + w.folders[index] = true + } + } + } +} + +// clearSearch empties the sidebar's search, so it lists every page again. +func (w *window) clearSearch() { + w.searchField.SetText("") + w.query = "" + w.rowsValid = false +} + +// toggleRow expands or collapses the group of row r, or the folder r is. While searching +// every group is open. func (w *window) toggleRow(r row) { + if r.folder != "" { + if index := kindIndex(r.folder); index >= 0 && w.query == "" { + w.folders[index] = !w.folders[index] + } + return + } toggleGroup(&w.sess.open, r.page, r.group, w.query != "") } @@ -142,16 +204,36 @@ func (w *window) rowTitle(r row) string { return titleOf(&w.text.Settings, r.page) } -// navNode describes row i of the sidebar to its Tree. +// navNode describes row i of the sidebar to its Tree. A search lists its rows flat, under +// the titles of its sections, which are not rows one can choose. func (w *window) navNode(i int) ui.TreeNode { if i < 0 || i >= len(w.rows) { return ui.TreeNode{} } r := w.rows[i] - return ui.TreeNode{ - Depth: int(r.level), Branch: r.group, Expanded: r.expanded, - Selected: (!r.group || !isGroup(r.page)) && r.page == w.sess.page && r.dynamic == w.dynamicPage, + if r.special == rowSection { + return ui.TreeNode{Disabled: true, Height: sectionHeight} + } + if w.query != "" { + return ui.TreeNode{Selected: w.rowSelected(r)} + } + return ui.TreeNode{Depth: int(r.level), Branch: r.group, Expanded: r.expanded, Selected: w.rowSelected(r)} +} + +// rowSelected says whether row r stands for the page on the screen. A folder's row is chosen +// while its page shows, Build's while Build's own page does. +func (w *window) rowSelected(r row) bool { + switch { + case r.special != rowPage || r.overflow > 0: + return false + case r.folder != "": + return w.sess.page == pageBuild && w.dynamicPage == "" && w.folderPage == r.folder + case r.group && isGroup(r.page) && !ownsPage(r.page): + return false + case r.page == pageBuild && r.dynamic == "" && w.folderPage != "": + return false } + return r.page == w.sess.page && r.dynamic == w.dynamicPage } // navKey names row i by the page it opens, so a row keeps its focus as the search lists @@ -167,21 +249,74 @@ func (w *window) navLabel(i int) string { if i < 0 || i >= len(w.rows) { return "" } - return w.rowTitle(w.rows[i]) + return w.rowLabel(w.rows[i]) } -// navContent declares what row i holds after its chevron: the page's tile on the top level -// and its title. +// rowLabel is the words row r reads as: a search's page after where it lives, the row that +// lists what a folder or a search leaves out by its count, else the row's title. +func (w *window) rowLabel(r row) string { + language := w.marketLanguage() + switch { + case r.special == rowAllTools: + return i18n.SharedFormat(language, "desktop.buildSettings.searchAllTools", map[string]string{"count": formatCount(r.overflow)}) + case r.overflow > 0: + return i18n.SharedFormat(language, "desktop.buildSettings.folderAll", map[string]string{"count": formatCount(r.overflow)}) + case r.special == rowPage && r.path != "": + return r.path + " › " + w.rowTitle(r) + } + return w.rowTitle(r) +} + +// navContent declares what row i holds after its chevron: the page's tile on the top level, +// its title, then what the prototype ends it with: a count of problems, a mark of drafts, a +// folder's count of pages or where a search's match lives. func (w *window) navContent(c ui.C, i int) { if i < 0 || i >= len(w.rows) { return } r := w.rows[i] + b := &w.bp + switch { + case r.special == rowSection: + ui.Row(c).Grow(1).FillHeight().MinWidth(0).PadSides(10, 0, 3, 0).Items(ui.End).Children(func() { + ui.Text(c, r.title).FontSize(buildTiny).Weight(gfx.WeightSemibold).Color(b.faint).Ellipsis() + }) + return + case r.special == rowAllTools || r.overflow > 0: + pad := float32(0) + if w.query == "" { + pad = w.titleStart(r) - float32(r.level)*levelIndent + } + ui.Text(c, w.rowLabel(r)).FontSize(buildSmall).Color(b.accent).PadLeft(pad).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + return + case w.query != "": + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Gap(6).Items(ui.Center).Children(func() { + if r.special == rowTool { + dot(c, 8, b.statusColor(r.status)) + } + label := w.rowTitle(r) + if r.special == rowPage { + label = w.rowLabel(r) + } + ui.Text(c, label).FontSize(13).Color(w.pal.text).Shrink(1).MinWidth(0).Ellipsis() + if r.special != rowPage && r.path != "" { + ui.Spacer(c) + ui.Text(c, r.path).FontSize(buildTiny).Color(b.faint).PadLeft(6).Shrink(1).MinWidth(0).Ellipsis() + } + }) + return + } title := func() { - ui.Text(c, w.rowTitle(r)).FontSize(13).Color(w.pal.text).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + ui.Text(c, w.rowTitle(r)).FontSize(13).Color(w.pal.text).Shrink(1).MinWidth(0).Ellipsis() + ui.Spacer(c) + w.navTrailing(c, r) } if r.level != 0 { - title() + pad := w.titleStart(r) - float32(r.level)*levelIndent + if r.group { + pad -= chevronSlot + } + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).PadLeft(pad).Gap(6).Items(ui.Center).Children(title) return } // The tile and the title are in a row of their own, which spaces them by tileGap rather @@ -196,10 +331,48 @@ func (w *window) navContent(c ui.C, i int) { ui.Row(c).Size(tileSize, tileSize).Shrink(0).Radius(tileRadius).Background(t.color).Center().Children(func() { ui.Icon(c, t.icon).Size(tileGlyph, tileGlyph).Color(w.pal.white) }) - title() + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Gap(6).Items(ui.Center).Children(title) }) } +// titleStart is where the title of a row below the top level starts in the sidebar: under +// the titles of the top level, and a folder's pages a step further in. +func (w *window) titleStart(r row) float32 { + if r.level >= 2 { + return childIndent + folderStep + } + return childIndent +} + +// navTrailing ends a row as the prototype does: Build folded and the Toolchains page count the +// tools with a problem, the Debuggers page marks drafts and a folder counts its pages. +func (w *window) navTrailing(c ui.C, r row) { + if r.dynamic != "" { + return + } + switch { + case r.folder != "": + ui.Text(c, formatCount(r.count)).FontSize(buildTiny).Color(w.bp.faint).Shrink(0) + case r.page == pageBuild && !r.expanded, r.page == pageToolchains: + if problems := w.toolchainProblems(); problems > 0 { + w.badge(c, problems, false) + } + case r.page == pageDebuggers: + if len(w.steppingPending()) > 0 { + dot(c, 7, w.bp.accent) + } + } +} + +// toolchainProblems is how many tools of the scope the Toolchains page shows have a problem, +// once Core projected the list. +func (w *window) toolchainProblems() int { + if t := w.toolchains; t.available() && t.view.ready { + return t.view.view.Counts.Problems + } + return 0 +} + // content is the page beside the sidebar: the breadcrumb above the page itself. func (w *window) content(c ui.C) { if w.sess.page != pagePlugins && w.market.status == marketLoading { @@ -226,8 +399,14 @@ func (w *window) content(c ui.C) { w.editorPage(c) case w.sess.page == pageFonts: w.fontsPage(c) - case w.sess.page == pageBuild && (w.ctrl.opts.Toolchains != nil || w.stepping.available()): + case w.sess.page == pageBuild && w.folderPage != "": + w.buildFolderPage(c.Part("folder")) + case w.sess.page == pageBuild: + w.buildPage(c.Part("build")) + case w.sess.page == pageToolchains: w.toolchainsPage(c) + case w.sess.page == pageDebuggers: + w.debuggersPage(c) case w.sess.page == pageTerminal && w.ctrl.opts.TerminalShells != nil: w.terminalPage(c) case w.sess.page == pageAIGeneration: @@ -250,27 +429,80 @@ func (w *window) content(c ui.C) { }) } -// breadcrumb names where the open page is: its group, then the page. The last title is -// the page itself and is set apart by its weight; a page on the top level has only that. +// breadcrumb is the prototype's .crumb: where the open page is, its group first and the page +// last in the weight of the text. A title before the last that has a page of its own opens it: +// Build, Execution, Deployment its directory, a folder its list of pages. func (w *window) breadcrumb(c ui.C) { - p := &w.pal - w.crumbs = appendBreadcrumb(w.crumbs[:0], &w.text.Settings, w.sess.page) - if page := w.dynamic.selected(w.dynamicPage); page != nil { - w.crumbs = append(w.crumbs, page.Title) - } - ui.Row(c).FillWidth().Height(46).Shrink(0).PadX(18).Gap(6).Items(ui.Center).Background(p.card).Children(func() { - for i, crumb := range w.crumbs { + b := &w.bp + w.crumbs = w.appendCrumbs(w.crumbs[:0]) + var chosen *crumb + ui.Row(c).FillWidth().Height(crumbHeight).Shrink(0).PadX(18).Gap(8).Items(ui.Center).Background(b.surface).Children(func() { + for i := range w.crumbs { + crumb := &w.crumbs[i] + k := c.KeyInt(i) if i > 0 { - ui.Icon(c, icons.ChevronRight).Size(chevronGlyph, chevronGlyph).Color(p.subtle).Shrink(0) + ui.Text(k.Part("sep"), "›").FontSize(buildFont).Color(b.faint).Shrink(0) } - if i == len(w.crumbs)-1 { - ui.Text(c, crumb).FontSize(13).Weight(gfx.WeightSemibold).Color(p.text).Ellipsis() - } else { - ui.Text(c, crumb).FontSize(13).Color(p.muted).Ellipsis() + last := i == len(w.crumbs)-1 + switch { + case last: + ui.Text(k, crumb.title).FontSize(buildFont).Weight(gfx.WeightSemibold).Color(b.text).Shrink(1).MinWidth(0).Ellipsis() + case crumb.link: + button := ui.ButtonBase(k, crumb.title).Shrink(1).MinWidth(0).Items(ui.Center) + if button.Clicked() { + chosen = crumb + } + button.Children(func() { + ui.Text(k, crumb.title).FontSize(buildFont).Color(b.sub).Shrink(1).MinWidth(0).Ellipsis(). + StateFrom(button).Hover(ui.Look{}.Color(b.accent)) + }) + default: + ui.Text(k, crumb.title).FontSize(buildFont).Color(b.sub).Shrink(1).MinWidth(0).Ellipsis() } } }) - ui.Row(c).FillWidth().Height(1).Shrink(0).Background(p.line) + ui.Row(c).FillWidth().Height(1).Shrink(0).Background(b.line) + if chosen != nil { + w.chooseCrumb(*chosen) + } +} + +// appendCrumbs appends the titles that lead to the open page to dst: the page's group and the +// page, and for a plugin's page under Build, Execution, Deployment the folder it is in, which +// the sidebar shows once its kind has folderMin pages. +func (w *window) appendCrumbs(dst []crumb) []crumb { + language := w.marketLanguage() + dst = appendBreadcrumb(dst, &w.text.Settings, w.sess.page) + parent := &dst[len(dst)-1] + switch { + case w.dynamicPage != "": + page := w.dynamic.selected(w.dynamicPage) + if page == nil { + break + } + parent.link = ownsPage(parent.page) + if kindIndex(page.Kind) >= 0 && contributedParent(page.Kind) == w.sess.page && w.dynamic.kindCount(page.Kind) >= folderMin { + dst = append(dst, crumb{title: kindTitle(language, page.Kind), page: pageBuild, folder: page.Kind, link: true}) + } + dst = append(dst, crumb{title: page.Title, page: w.sess.page}) + case w.sess.page == pageBuild && w.folderPage != "": + parent.link = true + dst = append(dst, crumb{title: kindTitle(language, w.folderPage), page: pageBuild, folder: w.folderPage}) + } + return dst +} + +// chooseCrumb opens what a title of the breadcrumb stands for. +func (w *window) chooseCrumb(crumb crumb) { + if crumb.folder != "" { + w.openFolder(crumb.folder) + return + } + if crumb.page == pageBuild { + w.sess.open[pageBuild] = true + } + w.folderPage = "" + w.selectSettingsPage(crumb.page, "") } // unavailablePage is the body of a page the new desktop client does not offer yet: an icon @@ -506,12 +738,15 @@ func (w *window) editorPage(c ui.C) { } } -// footer is the bar along the bottom: Restore Defaults at the leading end, Cancel and OK -// at the trailing one. +// footer is the bar along the bottom, after docs/design/build-execution-settings.html: +// Restore Defaults at the leading end, then what Apply would write, then Cancel, Apply and OK. func (w *window) footer(c ui.C) { settings := &w.text.Settings - ui.Row(c).FillWidth().Height(footerHeight).Shrink(0).Background(w.pal.card).PadX(footerPad).Gap(8).Items(ui.Center).Children(func() { - if ui.Button(c, settings.RestoreDefaults).Outline().Clicked() { + language := w.marketLanguage() + applying := w.apply.active() + count, targets := w.buildDrafts(language) + ui.Row(c).FillWidth().Height(footerHeight).Shrink(0).Background(w.bp.surface).PadX(footerPad).Gap(8).Items(ui.Center).Children(func() { + if w.button(c.Part("restore"), buttonPlain, settings.RestoreDefaults, applying) { // Reset is explicit even when an unknown stored value is displayed as the // system default. Forward it so the owner's real setting is cleared. w.setLanguage("", true) @@ -531,16 +766,46 @@ func (w *window) footer(c ui.C) { w.setGitConsole(core.GitConsolePreferences{}, true) w.setGitLogLimits(DefaultGitLogLimit, DefaultGitLogMergedLimit) } - ui.Spacer(c) - if ui.Button(c, settings.Cancel).Outline().Clicked() { + w.footerMessage(c.Part("message"), language, applying, count, targets) + if w.button(c.Part("cancel"), buttonPlain, settings.Cancel, applying) { w.cancel() } - if ui.Button(c, settings.OK).Clicked() { + // Apply writes the Build pages' drafts. Other pages apply their own cards, so the + // footer offers it only on a Build page or while Build drafts wait. + onBuild := w.sess.page == pageBuild || parents[w.sess.page] == pageBuild + if (onBuild || count > 0 || applying) && w.button(c.Part("apply"), buttonPlain, i18n.Shared(language, "desktop.buildSettings.apply"), count == 0 || applying) { + w.startApply(false) + } + if w.button(c.Part("ok"), buttonPrimary, settings.OK, false) { w.accept() } }) } +// footerMessage is the footer's words between its buttons: that an apply is out, why the last +// one stopped, or how many edits Apply would write and where. +func (w *window) footerMessage(c ui.C, language i18n.Language, applying bool, count int, targets []string) { + b := &w.bp + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Gap(6).Items(ui.Center).Children(func() { + switch { + case applying: + ui.Text(c, i18n.Shared(language, "desktop.buildSettings.applying")).FontSize(buildSmall).Color(b.sub).Ellipsis() + case w.apply.failed != nil: + ui.Icon(c, icons.CircleX).Size(13, 13).Color(b.err).Shrink(0) + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.applyFailed", map[string]string{"reason": toolchainFailureMessage(language, w.apply.failed)})). + FontSize(buildSmall).Color(b.err).Shrink(1).Ellipsis() + case count > 0: + dot(c, 7, b.accent) + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.pending", map[string]string{"count": formatCount(count)})). + FontSize(buildSmall).Weight(gfx.WeightMedium).Color(b.text).Shrink(0) + separator := i18n.Shared(language, "desktop.buildSettings.listSeparator") + ui.Text(c, i18n.SharedFormat(language, "desktop.buildSettings.writes", map[string]string{"targets": strings.Join(targets, separator)})). + FontSize(buildSmall).Color(b.sub).Shrink(1).Ellipsis() + w.infoButton(c.Part("help"), i18n.Shared(language, "desktop.buildSettings.applyHelp")) + } + }) +} + // projectOpenLabel is the words of one project open destination. func projectOpenLabel(language i18n.Language, value string) string { switch value { diff --git a/desktop/internal/toolchain/load.go b/desktop/internal/toolchain/load.go index d05954abd..24a62cf98 100644 --- a/desktop/internal/toolchain/load.go +++ b/desktop/internal/toolchain/load.go @@ -44,6 +44,23 @@ func RegistryInput(manifests []json.RawMessage) (json.RawMessage, error) { }{plugins}) } +// PluginNames maps each manifest's plugin ID to its display name. Manifests +// without either field are left out; the caller then shows the plugin ID. +func PluginNames(manifests []json.RawMessage) map[string]string { + names := make(map[string]string, len(manifests)) + for _, manifest := range manifests { + var identity struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + } + if json.Unmarshal(manifest, &identity) != nil || identity.ID == "" || identity.DisplayName == "" { + continue + } + names[identity.ID] = identity.DisplayName + } + return names +} + // Load reads one project directory: declared scans, native evidence, bounded // probes, Core's candidate report and the effective layer for every definition. // It writes nothing. @@ -83,6 +100,7 @@ func Load(ctx context.Context, kernel Kernel, root, directory string, manifests if err != nil { return Snapshot{}, err } + pluginNames := PluginNames(manifests) definitions := make(map[string]core.ToolchainToolDefinition, len(registry.Definitions)) for _, entry := range registry.Definitions { definitions[entry.Definition.ID] = entry.Definition @@ -127,6 +145,9 @@ func Load(ctx context.Context, kernel Kernel, root, directory string, manifests ID: planned.Tool, DisplayName: definition.DisplayName, PluginID: planned.PluginID, + PluginName: pluginNames[planned.PluginID], + Category: definition.Category, + Audience: definition.Audience, Providers: planned.Providers, Shell: prepared.candidates.Shell, Installations: prepared.candidates.Installations, @@ -183,9 +204,20 @@ func Load(ctx context.Context, kernel Kernel, root, directory string, manifests if automatic.Outcome.Selection.Home != nil { tool.AutomaticHome = *automatic.Outcome.Selection.Home } + tool.Automatic = automatic.Outcome.Selection + } else { + tool.AutomaticReason = "notFound" + if automatic.Outcome.Reason != nil && automatic.Outcome.Reason.Code != "" { + tool.AutomaticReason = automatic.Outcome.Reason.Code + } } if resolution.Outcome.Kind == "resolved" { tool.Effective = resolution.Outcome.Selection + } else { + tool.Reason = "notFound" + if resolution.Outcome.Reason != nil && resolution.Outcome.Reason.Code != "" { + tool.Reason = resolution.Outcome.Reason.Code + } } snapshot.Tools = append(snapshot.Tools, tool) } diff --git a/desktop/internal/toolchain/toolchain.go b/desktop/internal/toolchain/toolchain.go index 24c5b0388..3567ce882 100644 --- a/desktop/internal/toolchain/toolchain.go +++ b/desktop/internal/toolchain/toolchain.go @@ -57,6 +57,16 @@ type Tool struct { ID string `json:"id"` DisplayName string `json:"displayName"` PluginID string `json:"pluginID"` + // PluginName is the declaring plugin's manifest display name, empty when the + // manifest has none; the settings page then shows PluginID. + PluginName string `json:"pluginName,omitempty"` + // Category and Audience are the definition's display group (toolDefinitions + // 1); empty means other and user. + Category string `json:"category,omitempty"` + Audience string `json:"audience,omitempty"` + // Reason is Core's stable code when no installation applies, empty when the + // tool resolved. + Reason string `json:"reason,omitempty"` // Providers are the qualified provider IDs that declared this tool. Their // answers are not queried by this client yet, so the view states it. Providers []string `json:"providers"` @@ -69,6 +79,11 @@ type Tool struct { Installations []core.ToolchainInstallation `json:"installations"` Skipped []core.ToolchainSkippedInstallation `json:"skipped"` AutomaticHome string `json:"automaticHome,omitempty"` + // Automatic is the whole selection behind AutomaticHome: what the tool falls back + // to when the scope pins nothing, with its version and layer. Nil when that + // resolution found nothing; AutomaticReason is then Core's code. + Automatic *core.ToolchainSelection `json:"automatic,omitempty"` + AutomaticReason string `json:"automaticReason,omitempty"` Effective *core.ToolchainSelection `json:"effective,omitempty"` Trace []core.ToolchainResolutionTrace `json:"trace"` diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 298a34d8d..8b557431c 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -148,6 +148,9 @@ type Kernel interface { DecodeBuildRunEntrypoints(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeRunEntrypointsRequest) ([]core.BuildRunEntrypoint, error) CreateRunEntrypointConfiguration(ctx context.Context, request core.RunEntrypointConfigurationRequest) (string, []core.RunConfigChange, error) ToolchainRegistryOf(ctx context.Context, manifests []json.RawMessage) (core.ToolchainRegistry, error) + // ToolchainSettingsViewOf lays out the Toolchains settings list + // (settings_toolchains.go). + ToolchainSettingsViewOf(ctx context.Context, request core.ToolchainSettingsViewRequest) (core.ToolchainSettingsView, error) // CommandInstallerRequirements, PlanCommandInstaller and CommandInstallerDefaultDirectory // read a plugin's commandInstallers[]: which systemCommand launches name which commands, // one installer expanded for the target the user chose, and the directory a toolDefault diff --git a/desktop/internal/workbench/debug_stepping.go b/desktop/internal/workbench/debug_stepping.go index e66d0504b..991b4decf 100644 --- a/desktop/internal/workbench/debug_stepping.go +++ b/desktop/internal/workbench/debug_stepping.go @@ -2,11 +2,13 @@ package workbench import ( "context" + "encoding/json" "slices" "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" ) // steppingAdapters lists the installed debug adapters that declare stepping filters @@ -23,6 +25,7 @@ func (a *App) steppingAdapters(ctx context.Context) ([]settingswindow.SteppingAd plugins, pluginErr := a.plugins.DebugPlugins(ctx, entries) var adapters []settingswindow.SteppingAdapter for _, plugin := range plugins { + pluginName := toolchain.PluginNames([]json.RawMessage{plugin.Manifest})[plugin.PluginID] for _, declaration := range plugin.Adapters { defaults, ok := core.DeclaredSteppingFilters(declaration.Features, declaration.Defaults) if !ok || slices.ContainsFunc(adapters, func(s settingswindow.SteppingAdapter) bool { return s.ID == declaration.AdapterID }) { @@ -32,7 +35,9 @@ func (a *App) steppingAdapters(ctx context.Context) ([]settingswindow.SteppingAd if name == "" { name = declaration.AdapterID } - adapters = append(adapters, settingswindow.SteppingAdapter{ID: declaration.AdapterID, Name: name, Defaults: defaults}) + adapters = append(adapters, settingswindow.SteppingAdapter{ + ID: declaration.AdapterID, Name: name, PluginID: plugin.PluginID, PluginName: pluginName, Defaults: defaults, + }) } } slices.SortFunc(adapters, func(x, y settingswindow.SteppingAdapter) int { diff --git a/desktop/internal/workbench/settings_toolchains.go b/desktop/internal/workbench/settings_toolchains.go index f51a2790f..c7d80291b 100644 --- a/desktop/internal/workbench/settings_toolchains.go +++ b/desktop/internal/workbench/settings_toolchains.go @@ -141,6 +141,13 @@ func (s settingsToolchains) Save(ctx context.Context, snapshot toolchain.Snapsho return updated, nil } +// SettingsView asks Core to filter, group, fold and count the Toolchains list. +// It runs on the settings worker for every query change. +func (s settingsToolchains) SettingsView(ctx context.Context, request core.ToolchainSettingsViewRequest) (view core.ToolchainSettingsView, err error) { + defer func() { s.recordFailure(ctx, "toolchain_settings_view", err) }() + return s.app.kernel.ToolchainSettingsViewOf(ctx, request) +} + // recordFailure logs a failed settings request from the settings worker that ran it, under the // user action ctx carries; it never reads the window thread's operation. func (s settingsToolchains) recordFailure(ctx context.Context, operation string, err error) { diff --git a/docs/assets/build-execution-settings/32-settings-build-dark.png b/docs/assets/build-execution-settings/32-settings-build-dark.png new file mode 100644 index 000000000..3578c558b Binary files /dev/null and b/docs/assets/build-execution-settings/32-settings-build-dark.png differ diff --git a/docs/assets/build-execution-settings/32-settings-build-folder-dark.png b/docs/assets/build-execution-settings/32-settings-build-folder-dark.png new file mode 100644 index 000000000..9b46707bb Binary files /dev/null and b/docs/assets/build-execution-settings/32-settings-build-folder-dark.png differ diff --git a/docs/assets/build-execution-settings/32-settings-build-folder-light.png b/docs/assets/build-execution-settings/32-settings-build-folder-light.png new file mode 100644 index 000000000..cc64fc096 Binary files /dev/null and b/docs/assets/build-execution-settings/32-settings-build-folder-light.png differ diff --git a/docs/assets/build-execution-settings/32-settings-build-light.png b/docs/assets/build-execution-settings/32-settings-build-light.png new file mode 100644 index 000000000..8781b9e88 Binary files /dev/null and b/docs/assets/build-execution-settings/32-settings-build-light.png differ diff --git a/docs/assets/build-execution-settings/33-settings-toolchains-dark.png b/docs/assets/build-execution-settings/33-settings-toolchains-dark.png new file mode 100644 index 000000000..be1e1b4d2 Binary files /dev/null and b/docs/assets/build-execution-settings/33-settings-toolchains-dark.png differ diff --git a/docs/assets/build-execution-settings/33-settings-toolchains-light.png b/docs/assets/build-execution-settings/33-settings-toolchains-light.png new file mode 100644 index 000000000..651b20f9b Binary files /dev/null and b/docs/assets/build-execution-settings/33-settings-toolchains-light.png differ diff --git a/docs/assets/build-execution-settings/34-settings-debuggers-dark.png b/docs/assets/build-execution-settings/34-settings-debuggers-dark.png new file mode 100644 index 000000000..49fd81751 Binary files /dev/null and b/docs/assets/build-execution-settings/34-settings-debuggers-dark.png differ diff --git a/docs/assets/build-execution-settings/34-settings-debuggers-light.png b/docs/assets/build-execution-settings/34-settings-debuggers-light.png new file mode 100644 index 000000000..7223cef90 Binary files /dev/null and b/docs/assets/build-execution-settings/34-settings-debuggers-light.png differ diff --git a/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-dark.png b/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-dark.png new file mode 100644 index 000000000..76b48e835 Binary files /dev/null and b/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-dark.png differ diff --git a/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-light.png b/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-light.png new file mode 100644 index 000000000..bb7990d0f Binary files /dev/null and b/docs/assets/build-execution-settings/m47-toolchain-project-untrusted-light.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index d51c5eea5..538c24e36 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,6 +27,13 @@ native_path() { fi } +# Lithe-core-rust branch feat/toolchain-problem-groups at 6712596 (#102, on top of fa33446 on +# main): toolchains.settingsView issues carry the key of the group their tool is listed under, +# so the Toolchains page opens that group with the tool. Main below it has #99 (2ddfae7): +# toolDefinitions 1 adds a definition's category and audience; toolchains.settingsView filters, +# groups, folds and counts the Toolchains settings list; plugins.settings.navigation takes a +# group's limit, answers each row's matched flag and ancestor path, and folds the children past +# the limit into one overflow row. Switch to main's commit once #102 is squash-merged. # Lithe-core-rust main at 0a15a98: #97, squash-merged into main on top of 7f1fc4b (#96, managed # runtime preparation and isolated resolver sessions) and c146247 (#95, docs): # buildSystems[].beforeLaunchTasks (beforeLaunchTasks 0) declare tasks a run configuration's @@ -251,7 +258,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="0a15a980108e8316ff52fc512c6603df25a06f3b" +PINNED_CORE_REVISION="6712596cd5e3d64f48b02a5779ff7116fa412c39" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/features/build-settings.json b/shared/i18n/features/build-settings.json new file mode 100644 index 000000000..eb99f5e15 --- /dev/null +++ b/shared/i18n/features/build-settings.json @@ -0,0 +1,1263 @@ +{ + "schemaVersion": 1, + "messages": [ + { + "id": "desktop.buildSettings.directoryNote", + "description": "Build, Execution, Deployment settings: directoryNote", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.issuesTitle", + "description": "Build, Execution, Deployment settings: issuesTitle", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.issuesAll", + "description": "Build, Execution, Deployment settings: issuesAll", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.directoryScopeGlobal", + "description": "Build, Execution, Deployment settings: directoryScopeGlobal", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.directoryScopeProject", + "description": "Build, Execution, Deployment settings: directoryScopeProject", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.directoryToolchains", + "description": "Build, Execution, Deployment settings: directoryToolchains", + "platforms": [ + "desktop" + ], + "parameters": { + "plugins": "string", + "scope": "string", + "tools": "string" + } + }, + { + "id": "desktop.buildSettings.directoryDebuggers", + "description": "Build, Execution, Deployment settings: directoryDebuggers", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.directoryDebuggersCustomized", + "description": "Build, Execution, Deployment settings: directoryDebuggersCustomized", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string", + "customized": "string" + } + }, + { + "id": "desktop.buildSettings.directoryKind", + "description": "Build, Execution, Deployment settings: directoryKind", + "platforms": [ + "desktop" + ], + "parameters": { + "names": "string" + } + }, + { + "id": "desktop.buildSettings.directoryKindMore", + "description": "Build, Execution, Deployment settings: directoryKindMore", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string", + "names": "string" + } + }, + { + "id": "desktop.buildSettings.folderCount", + "description": "Build, Execution, Deployment settings: folderCount", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.folderFilter", + "description": "Build, Execution, Deployment settings: folderFilter", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.folderEmpty", + "description": "Build, Execution, Deployment settings: folderEmpty", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.folderAll", + "description": "Build, Execution, Deployment settings: folderAll", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.listSeparator", + "description": "Build, Execution, Deployment settings: listSeparator", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.parenthesized", + "description": "Build, Execution, Deployment settings: parenthesized", + "platforms": [ + "desktop" + ], + "parameters": { + "text": "string" + } + }, + { + "id": "desktop.buildSettings.apply", + "description": "Build, Execution, Deployment settings: apply", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.applying", + "description": "Build, Execution, Deployment settings: applying", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.applyFailed", + "description": "Build, Execution, Deployment settings: applyFailed", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.buildSettings.pending", + "description": "Build, Execution, Deployment settings: pending", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.writes", + "description": "Build, Execution, Deployment settings: writes", + "platforms": [ + "desktop" + ], + "parameters": { + "targets": "string" + } + }, + { + "id": "desktop.buildSettings.applyHelp", + "description": "Build, Execution, Deployment settings: applyHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.targetGlobal", + "description": "Build, Execution, Deployment settings: targetGlobal", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.targetProject", + "description": "Build, Execution, Deployment settings: targetProject", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.targetStepping", + "description": "Build, Execution, Deployment settings: targetStepping", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.scopeProjectNamed", + "description": "Build, Execution, Deployment settings: scopeProjectNamed", + "platforms": [ + "desktop" + ], + "parameters": { + "project": "string" + } + }, + { + "id": "desktop.buildSettings.scopeHelp", + "description": "Build, Execution, Deployment settings: scopeHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.trustedHelp", + "description": "Build, Execution, Deployment settings: trustedHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.revokeTrust", + "description": "Build, Execution, Deployment settings: revokeTrust", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterLabel", + "description": "Build, Execution, Deployment settings: filterLabel", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterPlaceholder", + "description": "Build, Execution, Deployment settings: filterPlaceholder", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.redetect", + "description": "Build, Execution, Deployment settings: redetect", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterAll", + "description": "Build, Execution, Deployment settings: filterAll", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterProblems", + "description": "Build, Execution, Deployment settings: filterProblems", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterPinned", + "description": "Build, Execution, Deployment settings: filterPinned", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.filterChanged", + "description": "Build, Execution, Deployment settings: filterChanged", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.groupBy", + "description": "Build, Execution, Deployment settings: groupBy", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.groupCategory", + "description": "Build, Execution, Deployment settings: groupCategory", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.groupPlugin", + "description": "Build, Execution, Deployment settings: groupPlugin", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.groupNone", + "description": "Build, Execution, Deployment settings: groupNone", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.trustBanner", + "description": "Build, Execution, Deployment settings: trustBanner", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string", + "sources": "string" + } + }, + { + "id": "desktop.buildSettings.trustProject", + "description": "Build, Execution, Deployment settings: trustProject", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.listCount", + "description": "Build, Execution, Deployment settings: listCount", + "platforms": [ + "desktop" + ], + "parameters": { + "matched": "string", + "total": "string" + } + }, + { + "id": "desktop.buildSettings.noMatches", + "description": "Build, Execution, Deployment settings: noMatches", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.noProblems", + "description": "Build, Execution, Deployment settings: noProblems", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.pluginGroupHelp", + "description": "Build, Execution, Deployment settings: pluginGroupHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.fromSource", + "description": "Build, Execution, Deployment settings: fromSource", + "platforms": [ + "desktop" + ], + "parameters": { + "source": "string" + } + }, + { + "id": "desktop.buildSettings.categoryRuntime", + "description": "Build, Execution, Deployment settings: categoryRuntime", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryBuild", + "description": "Build, Execution, Deployment settings: categoryBuild", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryPackage", + "description": "Build, Execution, Deployment settings: categoryPackage", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryDebug", + "description": "Build, Execution, Deployment settings: categoryDebug", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryLint", + "description": "Build, Execution, Deployment settings: categoryLint", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryOther", + "description": "Build, Execution, Deployment settings: categoryOther", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.categoryPlugin", + "description": "Build, Execution, Deployment settings: categoryPlugin", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.selectTool", + "description": "Build, Execution, Deployment settings: selectTool", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.toolFooter", + "description": "Build, Execution, Deployment settings: toolFooter", + "platforms": [ + "desktop" + ], + "parameters": { + "id": "string", + "plugin": "string" + } + }, + { + "id": "desktop.buildSettings.declaredBy", + "description": "Build, Execution, Deployment settings: declaredBy", + "platforms": [ + "desktop" + ], + "parameters": { + "plugin": "string" + } + }, + { + "id": "desktop.buildSettings.restoreAutomatic", + "description": "Build, Execution, Deployment settings: restoreAutomatic", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.restoreAutomaticTip", + "description": "Build, Execution, Deployment settings: restoreAutomaticTip", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.restoreInherited", + "description": "Build, Execution, Deployment settings: restoreInherited", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.restoreInheritedTip", + "description": "Build, Execution, Deployment settings: restoreInheritedTip", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.problemConflict", + "description": "Build, Execution, Deployment settings: problemConflict", + "platforms": [ + "desktop" + ], + "parameters": { + "plugins": "string" + } + }, + { + "id": "desktop.buildSettings.problemNotFound", + "description": "Build, Execution, Deployment settings: problemNotFound", + "platforms": [ + "desktop" + ], + "parameters": { + "tool": "string" + } + }, + { + "id": "desktop.buildSettings.problemVersion", + "description": "Build, Execution, Deployment settings: problemVersion", + "platforms": [ + "desktop" + ], + "parameters": { + "plugin": "string" + } + }, + { + "id": "desktop.buildSettings.problemProbeFailed", + "description": "Build, Execution, Deployment settings: problemProbeFailed", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.problemTrust", + "description": "Build, Execution, Deployment settings: problemTrust", + "platforms": [ + "desktop" + ], + "parameters": { + "home": "string", + "source": "string", + "tool": "string" + } + }, + { + "id": "desktop.buildSettings.effectiveTitle", + "description": "Build, Execution, Deployment settings: effectiveTitle", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.effectiveHelp", + "description": "Build, Execution, Deployment settings: effectiveHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.status", + "description": "Build, Execution, Deployment settings: status", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.program", + "description": "Build, Execution, Deployment settings: program", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.copyPath", + "description": "Build, Execution, Deployment settings: copyPath", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.version", + "description": "Build, Execution, Deployment settings: version", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.source", + "description": "Build, Execution, Deployment settings: source", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.afterApply", + "description": "Build, Execution, Deployment settings: afterApply", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.undoChange", + "description": "Build, Execution, Deployment settings: undoChange", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.why", + "description": "Build, Execution, Deployment settings: why", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.conflictReason", + "description": "Build, Execution, Deployment settings: conflictReason", + "platforms": [ + "desktop" + ], + "parameters": { + "plugins": "string" + } + }, + { + "id": "desktop.buildSettings.trustReason", + "description": "Build, Execution, Deployment settings: trustReason", + "platforms": [ + "desktop" + ], + "parameters": { + "source": "string" + } + }, + { + "id": "desktop.buildSettings.traceStep", + "description": "Build, Execution, Deployment settings: traceStep", + "platforms": [ + "desktop" + ], + "parameters": { + "detail": "string", + "layer": "string" + } + }, + { + "id": "desktop.buildSettings.traceCandidate", + "description": "Build, Execution, Deployment settings: traceCandidate", + "platforms": [ + "desktop" + ], + "parameters": { + "candidate": "string", + "reason": "string" + } + }, + { + "id": "desktop.buildSettings.notSet", + "description": "Build, Execution, Deployment settings: notSet", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.optionsGlobal", + "description": "Build, Execution, Deployment settings: optionsGlobal", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.optionsProject", + "description": "Build, Execution, Deployment settings: optionsProject", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.optionsProjectHelp", + "description": "Build, Execution, Deployment settings: optionsProjectHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.optionsGlobalHelp", + "description": "Build, Execution, Deployment settings: optionsGlobalHelp", + "platforms": [ + "desktop" + ], + "parameters": { + "order": "string" + } + }, + { + "id": "desktop.buildSettings.optionsGlobalHelpPlain", + "description": "Build, Execution, Deployment settings: optionsGlobalHelpPlain", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.autoReason", + "description": "Build, Execution, Deployment settings: autoReason", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.buildSettings.autoWith", + "description": "Build, Execution, Deployment settings: autoWith", + "platforms": [ + "desktop" + ], + "parameters": { + "source": "string", + "version": "string" + } + }, + { + "id": "desktop.buildSettings.autoProject", + "description": "Build, Execution, Deployment settings: autoProject", + "platforms": [ + "desktop" + ], + "parameters": { + "source": "string", + "version": "string" + } + }, + { + "id": "desktop.buildSettings.inheritWith", + "description": "Build, Execution, Deployment settings: inheritWith", + "platforms": [ + "desktop" + ], + "parameters": { + "version": "string" + } + }, + { + "id": "desktop.buildSettings.inUse", + "description": "Build, Execution, Deployment settings: inUse", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.addDirectory", + "description": "Build, Execution, Deployment settings: addDirectory", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.addPlaceholder", + "description": "Build, Execution, Deployment settings: addPlaceholder", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.addHelp", + "description": "Build, Execution, Deployment settings: addHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.checkAndUse", + "description": "Build, Execution, Deployment settings: checkAndUse", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.cancel", + "description": "Build, Execution, Deployment settings: cancel", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.sourceManual", + "description": "Build, Execution, Deployment settings: sourceManual", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.sourceSystem", + "description": "Build, Execution, Deployment settings: sourceSystem", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.reasonNotFound", + "description": "Build, Execution, Deployment settings: reasonNotFound", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.reasonConflict", + "description": "Build, Execution, Deployment settings: reasonConflict", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.debuggers", + "description": "Build, Execution, Deployment settings: debuggers", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.debuggerFilter", + "description": "Build, Execution, Deployment settings: debuggerFilter", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.debuggerCount", + "description": "Build, Execution, Deployment settings: debuggerCount", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + }, + { + "id": "desktop.buildSettings.debuggerNoMatches", + "description": "Build, Execution, Deployment settings: debuggerNoMatches", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.providedBy", + "description": "Build, Execution, Deployment settings: providedBy", + "platforms": [ + "desktop" + ], + "parameters": { + "plugin": "string" + } + }, + { + "id": "desktop.buildSettings.tabStepping", + "description": "Build, Execution, Deployment settings: tabStepping", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.steppingPending", + "description": "Build, Execution, Deployment settings: steppingPending", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.skipCode", + "description": "Build, Execution, Deployment settings: skipCode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.skipCodeHelp", + "description": "Build, Execution, Deployment settings: skipCodeHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.skipSyntheticsHelp", + "description": "Build, Execution, Deployment settings: skipSyntheticsHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.skipStaticInitializersHelp", + "description": "Build, Execution, Deployment settings: skipStaticInitializersHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.skipConstructorsHelp", + "description": "Build, Execution, Deployment settings: skipConstructorsHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.hideFilteredFramesHelp", + "description": "Build, Execution, Deployment settings: hideFilteredFramesHelp", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.noPatterns", + "description": "Build, Execution, Deployment settings: noPatterns", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.removePattern", + "description": "Build, Execution, Deployment settings: removePattern", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.addPattern", + "description": "Build, Execution, Deployment settings: addPattern", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.keywordsBuild", + "description": "Build, Execution, Deployment settings: keywordsBuild", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.keywordsToolchains", + "description": "Build, Execution, Deployment settings: keywordsToolchains", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.keywordsDebuggers", + "description": "Build, Execution, Deployment settings: keywordsDebuggers", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.kindCompiler", + "description": "Build, Execution, Deployment settings: kindCompiler", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.kindBuildSystem", + "description": "Build, Execution, Deployment settings: kindBuildSystem", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.searchPages", + "description": "Build, Execution, Deployment settings: searchPages", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.searchTools", + "description": "Build, Execution, Deployment settings: searchTools", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.searchDebuggers", + "description": "Build, Execution, Deployment settings: searchDebuggers", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.steppingTab", + "description": "Build, Execution, Deployment settings: steppingTab", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.buildSettings.searchAllTools", + "description": "Build, Execution, Deployment settings: searchAllTools", + "platforms": [ + "desktop" + ], + "parameters": { + "count": "string" + } + } + ], + "locales": { + "en-US": { + "desktop.buildSettings.directoryNote": "This page lists the subpages and their status only; it does not show what plugins add.", + "desktop.buildSettings.issuesTitle": "{count} need attention", + "desktop.buildSettings.issuesAll": "View all {count} in Toolchains", + "desktop.buildSettings.directoryScopeGlobal": "global defaults", + "desktop.buildSettings.directoryScopeProject": "the current project", + "desktop.buildSettings.directoryToolchains": "{tools} tools · from {plugins} plugins · showing {scope}", + "desktop.buildSettings.directoryDebuggers": "Stepping: {count} debuggers support filters", + "desktop.buildSettings.directoryDebuggersCustomized": "Stepping: {count} debuggers support filters · {customized} customized", + "desktop.buildSettings.directoryKind": "{names} · provided by plugins", + "desktop.buildSettings.directoryKindMore": "{names} and {count} more · provided by plugins", + "desktop.buildSettings.folderCount": "{count} pages · provided by plugins", + "desktop.buildSettings.folderFilter": "Filter pages or plugins", + "desktop.buildSettings.folderEmpty": "No matching pages", + "desktop.buildSettings.folderAll": "All {count}…", + "desktop.buildSettings.listSeparator": ", ", + "desktop.buildSettings.parenthesized": " ({text})", + "desktop.buildSettings.apply": "Apply", + "desktop.buildSettings.applying": "Applying…", + "desktop.buildSettings.applyFailed": "Could not apply: {reason}", + "desktop.buildSettings.pending": "{count} not applied", + "desktop.buildSettings.writes": "· writes to {targets}", + "desktop.buildSettings.applyHelp": "Apply writes the changes, then reads them back; the page shows the values read back.\nCancel discards every change and writes no file.", + "desktop.buildSettings.targetGlobal": "global user settings", + "desktop.buildSettings.targetProject": "this project's .lithe/toolchains/local.json", + "desktop.buildSettings.targetStepping": "debugger stepping", + "desktop.buildSettings.scopeProjectNamed": "Current Project · {project}", + "desktop.buildSettings.scopeHelp": "Global defaults: the choice every project shares, saved in the app's user settings.\nCurrent project: applies to this project only, saved to .lithe/toolchains/local.json (a local file, not committed).\nA tool the project does not set uses the global default. Running processes use a new version after they restart.\nChanges in the two scopes are kept apart; switching loses neither.", + "desktop.buildSettings.trustedHelp": "This project is trusted on this Mac: Lithe may probe and run the tool environments inside it.", + "desktop.buildSettings.revokeTrust": "Revoke", + "desktop.buildSettings.filterLabel": "Filter tools", + "desktop.buildSettings.filterPlaceholder": "Filter by name, version, path or plugin", + "desktop.buildSettings.redetect": "Detect again: probe every tool's installations and versions again, without writing any file.", + "desktop.buildSettings.filterAll": "All", + "desktop.buildSettings.filterProblems": "Needs Attention", + "desktop.buildSettings.filterPinned": "Set Manually", + "desktop.buildSettings.filterChanged": "Not Applied", + "desktop.buildSettings.groupBy": "Group", + "desktop.buildSettings.groupCategory": "By Category", + "desktop.buildSettings.groupPlugin": "By Plugin", + "desktop.buildSettings.groupNone": "None", + "desktop.buildSettings.trustBanner": "{count} tools come from environments inside the project ({sources}). Lithe does not probe or run them until you trust the project.", + "desktop.buildSettings.trustProject": "Trust This Project", + "desktop.buildSettings.listCount": "{matched} / {total} tools", + "desktop.buildSettings.noMatches": "No matching tools", + "desktop.buildSettings.noProblems": "✓ No tools need attention", + "desktop.buildSettings.pluginGroupHelp": "Runtimes plugins declare for their own language servers or background processes. You rarely change them, so the group starts collapsed; their problems still count under Needs Attention.", + "desktop.buildSettings.fromSource": "from {source}", + "desktop.buildSettings.categoryRuntime": "Runtimes & SDKs", + "desktop.buildSettings.categoryBuild": "Build Tools", + "desktop.buildSettings.categoryPackage": "Package Managers", + "desktop.buildSettings.categoryDebug": "Debuggers", + "desktop.buildSettings.categoryLint": "Linters & Formatters", + "desktop.buildSettings.categoryOther": "Other", + "desktop.buildSettings.categoryPlugin": "Plugin Runtimes", + "desktop.buildSettings.selectTool": "Select a tool on the left to see its details", + "desktop.buildSettings.toolFooter": "Tool ID {id} · declared by plugin {plugin}", + "desktop.buildSettings.declaredBy": "Declared by {plugin}", + "desktop.buildSettings.restoreAutomatic": "Restore Automatic", + "desktop.buildSettings.restoreAutomaticTip": "Drop the global choice so the tool is found automatically again. Takes effect after Apply.", + "desktop.buildSettings.restoreInherited": "Restore Inherited", + "desktop.buildSettings.restoreInheritedTip": "Drop the project's choice so the tool follows the global default again. Takes effect after Apply.", + "desktop.buildSettings.problemConflict": "Several plugins declare this tool: {plugins}. Their definitions may differ, so Lithe stops resolving it to avoid using the wrong one.", + "desktop.buildSettings.problemNotFound": "{tool} was not found. After installing it, click ⟳ in the toolbar to detect again, or add its installation directory below.", + "desktop.buildSettings.problemVersion": "Every installation found is older than the minimum version {plugin} requires.", + "desktop.buildSettings.problemProbeFailed": "Detecting the version failed. Check the tool's installation, then detect again.", + "desktop.buildSettings.problemTrust": "This project provides {tool} through {source} ({home}). Lithe does not probe or run it until you trust the project.", + "desktop.buildSettings.effectiveTitle": "In Effect", + "desktop.buildSettings.effectiveHelp": "The program the tool uses now, as Core resolves it.\nChanges are only a draft until you click Apply or OK at the bottom of the window; then they are written and read back.", + "desktop.buildSettings.status": "Status", + "desktop.buildSettings.program": "Program", + "desktop.buildSettings.copyPath": "Copy Path", + "desktop.buildSettings.version": "Version", + "desktop.buildSettings.source": "Source", + "desktop.buildSettings.afterApply": "After Apply: ", + "desktop.buildSettings.undoChange": "Undo Change", + "desktop.buildSettings.why": "Why this one?", + "desktop.buildSettings.conflictReason": "Also declared by {plugins}", + "desktop.buildSettings.trustReason": "From {source}; trust the project first", + "desktop.buildSettings.traceStep": "{layer}: {detail}", + "desktop.buildSettings.traceCandidate": "{candidate} ({reason})", + "desktop.buildSettings.notSet": "not set", + "desktop.buildSettings.optionsGlobal": "Global Default", + "desktop.buildSettings.optionsProject": "This Project Uses", + "desktop.buildSettings.optionsProjectHelp": "Applies to the current project only.\nInherit follows the global default; when the project has an environment a plugin declares (a wrapper, a virtual environment), it comes first once you trust the project.", + "desktop.buildSettings.optionsGlobalHelp": "The default every project shares.\nAutomatic looks in the order the plugin declares: {order}, and takes the first installation that meets the version requirement.", + "desktop.buildSettings.optionsGlobalHelpPlain": "The default every project shares.\nAutomatic takes the first installation that meets the version requirement.", + "desktop.buildSettings.autoReason": "Automatic ({reason})", + "desktop.buildSettings.autoWith": "Automatic ({version} · {source})", + "desktop.buildSettings.autoProject": "Automatic (project environment · {version} · {source})", + "desktop.buildSettings.inheritWith": "Inherit (global default · {version})", + "desktop.buildSettings.inUse": "In Use", + "desktop.buildSettings.addDirectory": "+ Add Installation Directory…", + "desktop.buildSettings.addPlaceholder": "Installation root, for example ~/.sdkman/candidates/java/21.0.5-tem", + "desktop.buildSettings.addHelp": "Choose the installation root that contains the tool's programs (the JDK directory, for example, not its bin directory).\nChecking only reads the version and changes the draft; nothing is written until Apply.", + "desktop.buildSettings.checkAndUse": "Check and Use", + "desktop.buildSettings.cancel": "Cancel", + "desktop.buildSettings.sourceManual": "Added manually", + "desktop.buildSettings.sourceSystem": "Found automatically", + "desktop.buildSettings.reasonNotFound": "No installation found", + "desktop.buildSettings.reasonConflict": "Several plugins declare this tool", + "desktop.buildSettings.debuggers": "Debuggers", + "desktop.buildSettings.debuggerFilter": "Filter debuggers", + "desktop.buildSettings.debuggerCount": "{count} debuggers", + "desktop.buildSettings.debuggerNoMatches": "No matching debuggers", + "desktop.buildSettings.providedBy": "Provided by {plugin}", + "desktop.buildSettings.tabStepping": "Stepping", + "desktop.buildSettings.steppingPending": "Changes not applied yet; they take effect in the next debug session.", + "desktop.buildSettings.skipCode": "Code Not to Step Into", + "desktop.buildSettings.skipCodeHelp": "One pattern per row, written the way the debugger expects.\nMatching frames are dimmed in the call stack.", + "desktop.buildSettings.skipSyntheticsHelp": "Steps straight over methods the compiler generates, such as lambda bridge methods.", + "desktop.buildSettings.skipStaticInitializersHelp": "Stepping into a class does not stop in its static initializer block.", + "desktop.buildSettings.skipConstructorsHelp": "Stepping does not enter constructors.", + "desktop.buildSettings.hideFilteredFramesHelp": "Frames the rules above filter out fold into one row in the call stack; expand it to see them.", + "desktop.buildSettings.noPatterns": "No rules", + "desktop.buildSettings.removePattern": "Remove This Rule", + "desktop.buildSettings.addPattern": "Add a pattern", + "desktop.buildSettings.keywordsBuild": "build execution deployment", + "desktop.buildSettings.keywordsToolchains": "toolchain sdk jdk version", + "desktop.buildSettings.keywordsDebuggers": "debugger stepping filter", + "desktop.buildSettings.kindCompiler": "Compiler", + "desktop.buildSettings.kindBuildSystem": "Build Tools", + "desktop.buildSettings.searchPages": "Settings Pages", + "desktop.buildSettings.searchTools": "Tools in Toolchains", + "desktop.buildSettings.searchDebuggers": "Debuggers", + "desktop.buildSettings.steppingTab": "Debuggers › Stepping", + "desktop.buildSettings.searchAllTools": "View all {count} in Toolchains…" + }, + "zh-CN": { + "desktop.buildSettings.directoryNote": "这一页只列子页和状态摘要,不直接展示插件注入的内容。", + "desktop.buildSettings.issuesTitle": "{count} 项需要处理", + "desktop.buildSettings.issuesAll": "在工具链中查看全部 {count} 项", + "desktop.buildSettings.directoryScopeGlobal": "全局默认", + "desktop.buildSettings.directoryScopeProject": "当前项目", + "desktop.buildSettings.directoryToolchains": "{tools} 个工具 · 来自 {plugins} 个插件 · 当前显示{scope}", + "desktop.buildSettings.directoryDebuggers": "单步:{count} 个调试器支持过滤", + "desktop.buildSettings.directoryDebuggersCustomized": "单步:{count} 个调试器支持过滤 · {customized} 个已自定义", + "desktop.buildSettings.directoryKind": "{names} · 由插件提供", + "desktop.buildSettings.directoryKindMore": "{names} 等 {count} 个 · 由插件提供", + "desktop.buildSettings.folderCount": "{count} 个页面 · 由插件提供", + "desktop.buildSettings.folderFilter": "筛选页面或插件", + "desktop.buildSettings.folderEmpty": "没有匹配的页面", + "desktop.buildSettings.folderAll": "全部 {count} 个…", + "desktop.buildSettings.listSeparator": "、", + "desktop.buildSettings.parenthesized": "({text})", + "desktop.buildSettings.apply": "应用", + "desktop.buildSettings.applying": "正在应用…", + "desktop.buildSettings.applyFailed": "应用失败:{reason}", + "desktop.buildSettings.pending": "{count} 项未应用", + "desktop.buildSettings.writes": "· 写入 {targets}", + "desktop.buildSettings.applyHelp": "点“应用”写入后会重新读取,界面显示的是重新读取到的实际生效值。\n点“取消”放弃全部修改,不写任何文件。", + "desktop.buildSettings.targetGlobal": "全局用户设置", + "desktop.buildSettings.targetProject": "本项目的 .lithe/toolchains/local.json", + "desktop.buildSettings.targetStepping": "调试器单步", + "desktop.buildSettings.scopeProjectNamed": "当前项目 · {project}", + "desktop.buildSettings.scopeHelp": "全局默认:所有项目共用的选择,保存在应用的用户设置。\n当前项目:只对这个项目生效,保存到本项目的 .lithe/toolchains/local.json(本机文件,不提交)。\n项目没有指定的工具沿用全局默认。已启动的进程需要重启后才使用新版本。\n两个作用域的修改分别保留,切换不会丢失。", + "desktop.buildSettings.trustedHelp": "本机此项目已信任:允许探测和运行项目内的工具环境。", + "desktop.buildSettings.revokeTrust": "撤销", + "desktop.buildSettings.filterLabel": "筛选工具", + "desktop.buildSettings.filterPlaceholder": "筛选名称、版本、路径或插件", + "desktop.buildSettings.redetect": "重新检测:重新探测全部工具的安装与版本,不写入任何文件。", + "desktop.buildSettings.filterAll": "全部", + "desktop.buildSettings.filterProblems": "需要处理", + "desktop.buildSettings.filterPinned": "已手动指定", + "desktop.buildSettings.filterChanged": "未应用", + "desktop.buildSettings.groupBy": "分组", + "desktop.buildSettings.groupCategory": "按类别", + "desktop.buildSettings.groupPlugin": "按插件", + "desktop.buildSettings.groupNone": "不分组", + "desktop.buildSettings.trustBanner": "{count} 个工具来自项目内的环境({sources})。信任项目之前不会探测或运行它们。", + "desktop.buildSettings.trustProject": "信任此项目", + "desktop.buildSettings.listCount": "{matched} / {total} 个工具", + "desktop.buildSettings.noMatches": "没有匹配的工具", + "desktop.buildSettings.noProblems": "✓ 没有需要处理的工具", + "desktop.buildSettings.pluginGroupHelp": "插件为自己的语言服务器或后台进程声明的运行时。平时不用改,所以默认折叠;出了问题仍会计入“需要处理”。", + "desktop.buildSettings.fromSource": "来自 {source}", + "desktop.buildSettings.categoryRuntime": "运行时与 SDK", + "desktop.buildSettings.categoryBuild": "构建工具", + "desktop.buildSettings.categoryPackage": "包管理器", + "desktop.buildSettings.categoryDebug": "调试器", + "desktop.buildSettings.categoryLint": "检查与格式化", + "desktop.buildSettings.categoryOther": "其他", + "desktop.buildSettings.categoryPlugin": "插件自用运行时", + "desktop.buildSettings.selectTool": "选择左侧的工具查看详情", + "desktop.buildSettings.toolFooter": "工具 ID {id} · 声明插件 {plugin}", + "desktop.buildSettings.declaredBy": "由 {plugin} 声明", + "desktop.buildSettings.restoreAutomatic": "恢复自动", + "desktop.buildSettings.restoreAutomaticTip": "去掉全局选择,重新自动查找。点“应用”后生效。", + "desktop.buildSettings.restoreInherited": "恢复继承", + "desktop.buildSettings.restoreInheritedTip": "去掉本项目的选择,重新沿用全局默认。点“应用”后生效。", + "desktop.buildSettings.problemConflict": "多个插件声明了同一工具:{plugins}。它们对这个工具的定义可能不同,Lithe 暂停解析,避免用错。", + "desktop.buildSettings.problemNotFound": "没有找到 {tool}。安装后点工具栏的 ⟳ 重新检测,或在下方添加安装目录。", + "desktop.buildSettings.problemVersion": "找到的安装都低于 {plugin} 要求的最低版本。", + "desktop.buildSettings.problemProbeFailed": "版本检测失败。请检查工具的安装,然后重新检测。", + "desktop.buildSettings.problemTrust": "这个项目用 {source}({home})提供 {tool}。信任项目之前不会探测或运行它。", + "desktop.buildSettings.effectiveTitle": "当前生效", + "desktop.buildSettings.effectiveHelp": "工具现在实际使用的程序,由 Core 解析得出。\n修改只是草稿,点窗口底部的“应用”或“好”之后才写入并重新读取。", + "desktop.buildSettings.status": "状态", + "desktop.buildSettings.program": "程序", + "desktop.buildSettings.copyPath": "复制路径", + "desktop.buildSettings.version": "版本", + "desktop.buildSettings.source": "来源", + "desktop.buildSettings.afterApply": "应用后:", + "desktop.buildSettings.undoChange": "撤销修改", + "desktop.buildSettings.why": "为什么是这个?", + "desktop.buildSettings.conflictReason": "同时由 {plugins} 声明", + "desktop.buildSettings.trustReason": "来自 {source},需要先信任项目", + "desktop.buildSettings.traceStep": "{layer}:{detail}", + "desktop.buildSettings.traceCandidate": "{candidate}({reason})", + "desktop.buildSettings.notSet": "未设置", + "desktop.buildSettings.optionsGlobal": "全局默认使用", + "desktop.buildSettings.optionsProject": "本项目使用", + "desktop.buildSettings.optionsProjectHelp": "只对当前项目生效。\n“继承”沿用全局默认;项目里有插件声明的环境(Wrapper、虚拟环境等)时,信任项目后优先使用。", + "desktop.buildSettings.optionsGlobalHelp": "所有项目共用的默认选择。\n“自动”按插件声明的顺序查找:{order},取第一个满足版本要求的安装。", + "desktop.buildSettings.optionsGlobalHelpPlain": "所有项目共用的默认选择。\n“自动”取第一个满足版本要求的安装。", + "desktop.buildSettings.autoReason": "自动({reason})", + "desktop.buildSettings.autoWith": "自动({version} · {source})", + "desktop.buildSettings.autoProject": "自动(项目环境 · {version} · {source})", + "desktop.buildSettings.inheritWith": "继承(全局默认 · {version})", + "desktop.buildSettings.inUse": "生效中", + "desktop.buildSettings.addDirectory": "+ 添加安装目录…", + "desktop.buildSettings.addPlaceholder": "安装根目录,例如 ~/.sdkman/candidates/java/21.0.5-tem", + "desktop.buildSettings.addHelp": "选择包含工具程序的安装根目录(例如 JDK 目录,而不是 bin 目录)。\n检查只读取版本、修改草稿;点“应用”后才写入。", + "desktop.buildSettings.checkAndUse": "检查并选用", + "desktop.buildSettings.cancel": "取消", + "desktop.buildSettings.sourceManual": "手动添加", + "desktop.buildSettings.sourceSystem": "自动发现", + "desktop.buildSettings.reasonNotFound": "没有找到安装", + "desktop.buildSettings.reasonConflict": "多个插件声明了同一工具", + "desktop.buildSettings.debuggers": "调试器", + "desktop.buildSettings.debuggerFilter": "筛选调试器", + "desktop.buildSettings.debuggerCount": "{count} 个调试器", + "desktop.buildSettings.debuggerNoMatches": "没有匹配的调试器", + "desktop.buildSettings.providedBy": "由 {plugin} 提供", + "desktop.buildSettings.tabStepping": "单步", + "desktop.buildSettings.steppingPending": "有未应用的修改,下一次调试会话生效。", + "desktop.buildSettings.skipCode": "不进入的代码", + "desktop.buildSettings.skipCodeHelp": "每条一个模式,写法由调试器决定。\n调用栈中匹配的帧会淡化显示。", + "desktop.buildSettings.skipSyntheticsHelp": "编译器自动生成的方法(如 lambda 桥接方法)在单步时直接跳过。", + "desktop.buildSettings.skipStaticInitializersHelp": "单步进入类时不停在静态初始化块里。", + "desktop.buildSettings.skipConstructorsHelp": "单步时不进入构造方法。", + "desktop.buildSettings.hideFilteredFramesHelp": "调用栈里被上面规则过滤的帧折叠成一行,展开可查看。", + "desktop.buildSettings.noPatterns": "没有规则", + "desktop.buildSettings.removePattern": "删除这条", + "desktop.buildSettings.addPattern": "添加模式", + "desktop.buildSettings.keywordsBuild": "构建 执行 部署 build", + "desktop.buildSettings.keywordsToolchains": "工具链 sdk jdk 版本 toolchain", + "desktop.buildSettings.keywordsDebuggers": "调试器 单步 debugger stepping 过滤", + "desktop.buildSettings.kindCompiler": "编译器", + "desktop.buildSettings.kindBuildSystem": "构建工具", + "desktop.buildSettings.searchPages": "设置页", + "desktop.buildSettings.searchTools": "工具链中的工具", + "desktop.buildSettings.searchDebuggers": "调试器", + "desktop.buildSettings.steppingTab": "调试器 › 单步", + "desktop.buildSettings.searchAllTools": "在工具链中查看全部 {count} 个…" + } + } +} diff --git a/shared/platform-feature-matrix/features/application-settings.json b/shared/platform-feature-matrix/features/application-settings.json index 0c8672864..d6434708b 100644 --- a/shared/platform-feature-matrix/features/application-settings.json +++ b/shared/platform-feature-matrix/features/application-settings.json @@ -23,7 +23,11 @@ "desktop/internal/store/keep_test.go", "desktop/internal/workbench/settings_kept.go", "desktop/internal/workbench/settings_kept_test.go", - "desktop/internal/store/store_test.go" + "desktop/internal/store/store_test.go", + "desktop/internal/settingswindow/build_directory_view.go", + "desktop/internal/settingswindow/build_directory_view_test.go", + "desktop/internal/settingswindow/build_search.go", + "desktop/internal/settingswindow/build_apply.go" ] }, "windows": { @@ -50,7 +54,7 @@ ] }, "owner": "Settings", - "notes": "Viva 设置窗口的每个侧栏页都已接入:外观、常规、网络、编辑器、字体、快捷键、进程终止、插件、版本控制、构建与工具链、语言(插件贡献的动态页)、终端、AI 生成与 IDE API;外观与语言选择后立即应用。尚未完成原版界面像素级对照或跨平台实机验收。 本次按 main-macos-live-baseline(源提交 a824bd5c)校准 900×700 初始窗口、234pt 侧栏、24pt 导航行、深浅色页面/卡片/下拉层级和页边距;已检查 macOS 原生通用页及语言下拉,仍不代表所有设置页逐像素验收。 本轮全页对照将自动保存入口移回通用页,终端 Shell 改为共享下拉并保留检测/缺失/自动生效值,退出策略按原版合并同行,更新页拆开版本与操作。 编辑器标签的滚动、压缩和多行布局统一为共享下拉,选择多行时保留先前单行溢出偏好。TestVisualSettings 以离线事实采集深浅色页面和菜单;工具真实来源与未实现设置项仍按既有状态记录,不能把截图覆盖当原生验收。 正式版与 AutoBuild 共用同一份设置:读到当前版本不认识的键,或字段在、但存的形状读不了的值时,照常用默认行为运行,保存时把这些值原样写回,不删除;不认识的键每组只通知一次,形状读不了的值记 app.settings.decode_failed(编辑器会话记 editor_session_load)。当前版本改过或清空的字段以当前版本为准。 Viva 2026-11-16:侧栏“构建、执行、部署”“语言与框架”在有插件贡献子页时与“工具”一样可折叠,选中子页时自动展开所属分组。自动化:TestContributedPagesGoUnderBuildOrLanguages。原生验收仍 pending。 2026-11-16 #1943:偏好文件读取或 JSON 解码失败后,下一次 Save 先把原文件改名为 <名称>.unreadable- 另存,再写入新值,原内容不被默认值覆盖;启动时提示另存位置仍待补齐。macOS/Windows 共用 Go 实现,实机验收保持 pending。 2026-11-18:设置窗口的 ⓘ 和工作台、日志窗口一致,只用悬停提示;点击不再弹出会固定的白色说明卡片,因此 Escape 关闭卡片、键盘 Space/Return 打开说明也一并取消。键盘聚焦不显示提示(Viva ui 层未开放 ShowOnFocus),辅助技术仍能读出说明。 2026-11-18:删除外观与行为下的“更新”页,自动检查、更新渠道、发布源和立即检查整体迁入“关于”的更新卡片,侧栏少一行;自动化:TestDefaultSidebarListsTheTopLevelWithAppearanceExpanded、TestAboutPageNamesTheRunningVersionAsItIsReleased。", + "notes": "Viva 设置窗口的每个侧栏页都已接入:外观、常规、网络、编辑器、字体、快捷键、进程终止、插件、版本控制、构建与工具链、语言(插件贡献的动态页)、终端、AI 生成与 IDE API;外观与语言选择后立即应用。尚未完成原版界面像素级对照或跨平台实机验收。 本次按 main-macos-live-baseline(源提交 a824bd5c)校准 900×700 初始窗口、234pt 侧栏、24pt 导航行、深浅色页面/卡片/下拉层级和页边距;已检查 macOS 原生通用页及语言下拉,仍不代表所有设置页逐像素验收。 本轮全页对照将自动保存入口移回通用页,终端 Shell 改为共享下拉并保留检测/缺失/自动生效值,退出策略按原版合并同行,更新页拆开版本与操作。 编辑器标签的滚动、压缩和多行布局统一为共享下拉,选择多行时保留先前单行溢出偏好。TestVisualSettings 以离线事实采集深浅色页面和菜单;工具真实来源与未实现设置项仍按既有状态记录,不能把截图覆盖当原生验收。 正式版与 AutoBuild 共用同一份设置:读到当前版本不认识的键,或字段在、但存的形状读不了的值时,照常用默认行为运行,保存时把这些值原样写回,不删除;不认识的键每组只通知一次,形状读不了的值记 app.settings.decode_failed(编辑器会话记 editor_session_load)。当前版本改过或清空的字段以当前版本为准。 Viva 2026-11-16:侧栏“构建、执行、部署”“语言与框架”在有插件贡献子页时与“工具”一样可折叠,选中子页时自动展开所属分组。自动化:TestContributedPagesGoUnderBuildOrLanguages。原生验收仍 pending。 2026-11-16 #1943:偏好文件读取或 JSON 解码失败后,下一次 Save 先把原文件改名为 <名称>.unreadable- 另存,再写入新值,原内容不被默认值覆盖;启动时提示另存位置仍待补齐。macOS/Windows 共用 Go 实现,实机验收保持 pending。 2026-11-18:设置窗口的 ⓘ 和工作台、日志窗口一致,只用悬停提示;点击不再弹出会固定的白色说明卡片,因此 Escape 关闭卡片、键盘 Space/Return 打开说明也一并取消。键盘聚焦不显示提示(Viva ui 层未开放 ShowOnFocus),辅助技术仍能读出说明。 2026-11-18:删除外观与行为下的“更新”页,自动检查、更新渠道、发布源和立即检查整体迁入“关于”的更新卡片,侧栏少一行;自动化:TestDefaultSidebarListsTheTopLevelWithAppearanceExpanded、TestAboutPageNamesTheRunningVersionAsItIsReleased。 Viva 2026-11-18(构建设置重构):“构建、执行、部署”改为分组,选中时显示目录页,固定子页为“工具链”“调试器”,插件声明的页面按种类(构建工具、编译器)额外聚合到这里,插件详情的「设置」标签仍保留同一份设置和草稿;同一种类满 3 个页面折叠成侧栏文件夹,展开后列 6 个并以“全部 N 个…”打开文件夹页,文件夹页可按名称或插件筛选;目录页每个种类列出前 3 个名称并计数其余。只有 Build 页面或有草稿时页脚才显示“应用”,没有草稿时“好”直接关闭。自动化:TestBuildKindWithFewPagesListsThemDirectly、TestBuildKindFoldsIntoAFolderThatListsSix、TestBuildPageNamesAKindAndOpensItsFolder,TestVisualSettings 的 32/33/34 场景生成截图。原生与 Windows 验收仍 pending。", "verification": "无头窗口覆盖 ⓘ 说明只在指针停留时以客户端共享提示气泡显示在图标右侧(右侧放不下时换到左侧)、点击图标只收起提示而不再固定白色说明卡片、辅助技术把说明读作图标描述,窄窗口实际值,外观和语言即时应用、恢复默认、关闭不回滚,以及日志窗口重绘和跟随系统外观;分别生成常规设置截图、与原版 macOS 布局对照。完整设置页、真实窗口与真实配置读写仍待验收,Windows 尚未运行本次测试。运行 scripts/desktop/desktop-go.sh test -race ./internal/logwindow ./internal/settingswindow ./internal/workbench -run 'TestOpenWindowRepaintsWhenLanguageAndAppearanceChange|TestGeneral|TestSettingsChangesUpdateSharedStateAndPersist|TestSystemAppearanceChangesSharedStateWhenFollowingSystem' -count=3。 store 的 keep_test.go 覆盖保存保留新版本写的键、不复活当前版本清空的键、保留读不了形状的值并由 Unread 报出、键名按 encoding/json 规则匹配;workbench 的 settings_kept_test.go 覆盖新版本写的设置只通知一次并保留,标题栏布局和编辑器会话中读不了的值会记日志。运行 scripts/desktop/desktop-go.sh test -race ./internal/store ./internal/workbench -run 'TestSave|TestLoad|TestUnread|TestSettingsANewerVersion|TestALayoutPart|TestAnEditorSession'。 #1943:TestSaveAfterAFailedLoadSetsTheUnreadableFileAside、TestSaveSetsNothingAsideOnceTheUnreadableFileIsGone 与 TestSaveAfterAFailedLoadWritesWhenTheFileIsAlreadyGone 覆盖读不出的文件在保存前另存且内容不变、同一次失败只另存一次、其他文件不受影响、文件已删除或被 Remove 后不另存;运行 scripts/desktop/desktop-go.sh test ./internal/store -run 'TestSave|TestLoad|TestUnread' -count=1。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", diff --git a/shared/platform-feature-matrix/features/debug-state.json b/shared/platform-feature-matrix/features/debug-state.json index 90dde9f08..22ee85b2e 100644 --- a/shared/platform-feature-matrix/features/debug-state.json +++ b/shared/platform-feature-matrix/features/debug-state.json @@ -45,7 +45,7 @@ }, "owner": "Debug", "verification": "验证变量分页、异常信息、step filters、暂停/继续和 disconnect policy。 Windows验证DAP请求信封、初始断点先于launch入队、暂停线程与线程列表、继续后清空暂停状态、快速单步/失败回滚,以及并发Stop等待同一资源清理。 macOS验证Debug空状态的初始、活跃、无输出终止、关闭最后会话、失败重试、重置,以及明暗主题与配置/帮助链接。 macOS检查活动会话的标题与内容标签焦点、单行工具栏、控制台/变量切换、现有求值与程序输入、窄宽度及停止操作。 macOS验证明暗图标/禁用灰度、Console ANSI常规与亮色、1pt缩放及边界、嵌套折叠/展开/复制/源码链接、内容标签切换保留状态和400k字符范围性能。 检查首次启动/重新启动默认Console、暂停切换,以及13pt为22pt行高、折叠占位和字号改变后行高一致。 检查主工具栏运行/调试重启的绿色底与白色图标、停止红底、明暗主题、hover/按下与默认箭头光标,并验证原有启动/停止动作。 检查各会话状态均不在内容标签旁显示状态文字/圆点,暂停位置仍可跳转。 验证分块SGR、非法/超长CSI过滤、Logback时间/线程/级别/类名颜色及字重、折叠占位手形和展开后左侧9pt标记点击、原文复制及滚动/缩放。 检查收起标记展开、展开标记收起的完整往返及深浅主题资源。 验证内联输入的Enter/空行、发送失败保留、历史正文保护、输出追加与IME/光标保持、会话结束和切换、明暗主题、源码链接/折叠点击、求值与添加监视及历史菜单。 检查Debug标题/工具栏/线程选择/求值/变量监视/Console诊断条的共享1pt横线,线程变量及Performance拖动分隔线的深浅主题、收起恢复、hover与按住不变亮,并确认动作组短竖线和对话框保留各自共享样式。 Console六个左侧动作在明暗主题加载真实16pt SVG;上下箭头深色资源不回退浅色,禁用态只应用IDEA灰度一次,按钮hover复用Git Log共享入口。 Console折叠标记在真实NSScrollView中检查深浅主题实际像素与收起/展开往返点击;追加输出与滚动后折叠栏重绘,不能只验证锚点存在。 Threads & Variables核对线程/作用域菜单、13pt普通标题与代码内容、原始16pt明暗New UI图标、变量展开/加载/层级、求值/添加监视/刷新及灰度、占位/IME和焦点;暂停后的真实变量修改与求值保持原动作。 StatusText深浅主题像素检查居中、三分之一高度与文字行高;检查运行/暂停/终止、变量为空而监视非空、异常非空、线程切换/栈帧选择、Enter求值、添加监视/历史菜单;默认1:2与拖动后宽度、背景开关均保持。 Console上一处/下一处对相同URL的不同文字范围逐一导航、回绕及后退,替换输出后重置定位。 添加监视:空白求值输入禁用内联 Add to Watch,非空表达式点击后进入 Watches;下方+打开共享样式弹窗,检查新增/编辑初值、自动聚焦、共享输入边框和焦点环、中文输入法、空白禁存、Enter保存和Esc取消。 Watch新增和编辑不使用系统sheet;确认弹层从Watches的+锚定,无弹出动画,8pt共享外框及1pt边框,Enter保存、Esc和外部点击关闭,再次编辑显示正确初值。 Console源码导航在未定位时,首次下一处定位第一条、首次上一处定位最后一条;重复URL逐个范围遍历并回绕,输出替换且URL/范围相同时也重置位置。 主动Stop最后运行会话后保留Console日志及内容标签,停留Threads & Variables仍可切回Console;清空无错误的历史后恢复空状态。Console源码导航按钮在无链接→有链接→清空输出时正确禁用/启用,排队通知被新渲染覆盖或原生视图卸载后不得回写旧状态。 双Debug会话中A终端不可输入或绑定缺失、B终端可输入时,A Console必须禁用并拒绝发送给B;选中B后正常发送。超过400000字符时,前台及后台会话按完整SGR边界截断并恢复有效颜色和粗体,覆盖跨chunk、标准/256/真彩、重置及Unicode,缓存仍有界。 验证变量分页、异常信息、step filters、暂停/继续和 disconnect policy。 Windows验证DAP请求信封、初始断点先于launch入队、暂停线程与线程列表、继续后清空暂停状态、快速单步/失败回滚,以及并发Stop等待同一资源清理。macOS Debug 与 Run 复用 OutputTextView 的 IDEA 控制台入口,检查 13pt 字体、ANSI 明暗配色及源码链接高亮一致,不按日志级别给普通输出整行重新着色。 macOS:Run、Debug、Test 共用 OutputTextView/LitheConsoleStyle 默认字体、行高和日志等级色;纯文本及 ANSI 日志的 INFO 标签均为绿色、WARN 黄色、ERROR 红色,正文及其他 ANSI 片段保留;检查明暗主题、复制、折叠与源码链接。 macOS多会话:startDebugging 子会话带父链接且不抢provider选择、子会话启动前重放已有断点、停止父会话同时停止子会话、功能模型清理子会话快照并回退选择;线程选择器会话分组缩进、状态圆点及单会话右键停止。Windows 暂无多会话实现。 RUN-06:变量分页游标改由 Core debug.planVariablePage / debug.reduceVariablePage 决定(命名与索引子项分段、重复页丢弃、耗尽判定),macOS 删除本地分页状态机,两端共用 Core 的 rust/fixtures/debug/variable-page-plan-v1.json。Windows 现在保留 Scope 与变量的 namedVariables/indexedVariables,按需只请求非 expensive 的 Scope(expensive 作用域由用户点击加载),首页和后续页携带 filter/start/count,“加载更多”继续取下一页;Windows 前端用 bun test 的 debug-adapter-events.test.ts 验证,真实 Windows 调试会话仍 pending。RUN-07:Windows 栈帧保留 sourceReference、instructionPointerReference 与 isFiltered;带 sourceReference 的栈帧不再把 sourcePath 当磁盘文件打开或高亮,被步进策略过滤的帧在调用栈中淡化。Windows 暂未提供读取 adapter 托管源码内容(source 请求)的界面,反编译/反汇编源码内容的展示仍待后续。 Viva 单步过滤:运行 scripts/desktop/desktop-go.sh test ./internal/settingswindow -run Stepping、./internal/workbench -run 'Stepping|CallStack|DebugFrameRows|DebugLaunch' 与 ./internal/core -run Stepping。", - "notes": "Viva 的 Debug 工具窗口按选中栈帧加载作用域与变量,大容器分页由 Core 的 planVariablePage/reduceVariablePage 决定;暂停且适配器支持时可修改变量;异常断点按适配器声明的过滤器勾选,选择随项目保留并发给 Core。本轮接入 Core 的 threads 检查:停止后列线程并可切换线程重载栈;求值与监视使用 DAP watch 上下文在当前帧求值,监视表达式跨停止保留并自动重求值,拒绝的表达式显示在各自行。单步过滤:设置 > 构建、执行、部署 页的“调试器单步”卡片按适配器(声明了 features.stepFilters 的已安装插件)编辑不进入的类、跳过合成方法/静态初始化块/构造方法与调用栈折叠,起始值是插件声明的默认值,“应用”经 Core debug.steppingFilters 校验整理后存入 desktop 设置的 debugSteppingFilters,“恢复插件默认值”删除覆盖;下一次启动随 launch 的 steppingFilters 发给 Core。调用栈淡化 isFiltered 帧,开启折叠时连续被过滤的帧(顶帧与选中帧除外)合成一行,点击展开到下一次停止。线程菜单可在适配器声明 supportsSingleThreadExecutionRequests 时经 Core debug.execute(singleThread)单独继续一个线程,会话仍为暂停,被继续的线程在选择器标“运行中”且不再显示栈;Core 只在会话运行时接受暂停,所以单独继续的线程在会话暂停期间暂不能单独暂停(菜单项禁用)。监视表达式可双击或经右键“编辑”行内修改,Enter 或焦点离开保存并重新求值,Esc 取消。尚未接入异常信息、断开策略的用户设置与求值输入历史。", + "notes": "Viva 的 Debug 工具窗口按选中栈帧加载作用域与变量,大容器分页由 Core 的 planVariablePage/reduceVariablePage 决定;暂停且适配器支持时可修改变量;异常断点按适配器声明的过滤器勾选,选择随项目保留并发给 Core。本轮接入 Core 的 threads 检查:停止后列线程并可切换线程重载栈;求值与监视使用 DAP watch 上下文在当前帧求值,监视表达式跨停止保留并自动重求值,拒绝的表达式显示在各自行。单步过滤:设置 > 构建、执行、部署 页的“调试器单步”卡片按适配器(声明了 features.stepFilters 的已安装插件)编辑不进入的类、跳过合成方法/静态初始化块/构造方法与调用栈折叠,起始值是插件声明的默认值,“应用”经 Core debug.steppingFilters 校验整理后存入 desktop 设置的 debugSteppingFilters,“恢复插件默认值”删除覆盖;下一次启动随 launch 的 steppingFilters 发给 Core。调用栈淡化 isFiltered 帧,开启折叠时连续被过滤的帧(顶帧与选中帧除外)合成一行,点击展开到下一次停止。线程菜单可在适配器声明 supportsSingleThreadExecutionRequests 时经 Core debug.execute(singleThread)单独继续一个线程,会话仍为暂停,被继续的线程在选择器标“运行中”且不再显示栈;Core 只在会话运行时接受暂停,所以单独继续的线程在会话暂停期间暂不能单独暂停(菜单项禁用)。监视表达式可双击或经右键“编辑”行内修改,Enter 或焦点离开保存并重新求值,Esc 取消。尚未接入异常信息、断开策略的用户设置与求值输入历史。 Viva 2026-11-18(构建设置重构):单步过滤从 Build 页移到“构建、执行、部署 › 调试器”子页,左侧列出已安装调试器及提供插件、筛选和“已自定义”标记,右侧编辑不进入的代码与跳过选项,插件没有声明名称时以调试器名称绘制图标。自动化:stepping_view_test.go、TestVisualSettings 的 34 场景。原生与 Windows 验收仍 pending。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/plugin-injected-toolchains.json b/shared/platform-feature-matrix/features/plugin-injected-toolchains.json index 7bd104c38..ff57d72dc 100644 --- a/shared/platform-feature-matrix/features/plugin-injected-toolchains.json +++ b/shared/platform-feature-matrix/features/plugin-injected-toolchains.json @@ -30,7 +30,9 @@ "desktop/internal/core/toolchain_catalog.go", "desktop/internal/settingswindow/visual_capture_test.go", ".github/workflows/desktop-ci.yml", - "desktop/internal/toolchain/load.go" + "desktop/internal/toolchain/load.go", + "desktop/internal/settingswindow/toolchains_state.go", + "desktop/internal/settingswindow/build_style.go" ] }, "windows": { @@ -60,7 +62,7 @@ }, "owner": "Plugin Platform", "verification": "共享 Core:cargo test --manifest-path rust/Cargo.toml -p lithe-core --lib toolchain,核对定义独占与官方短 ID、第二种通用工具、旧候选边界、答案身份/代次、Windows 路径大小写、工作区排除、固定值失效不回落、最近项目要求、冲突选择、最低版本、环境隔离和纯声明扫描;按逐项计时工具生成 HTML/JUnit。macOS 继续补齐下列消费者与保存验收,Windows 须先实现对应 adapter:启动提供方并协商、取消/超时和过期结果隔离、输入新建/删除后整体重查、目录固定保存/取消/冲突回读、插件停用撤回、真实 Build/LSP/Run 消费者取得同一选择、发行目录哈希不变与子进程清理。未完成原生流程前保持 pending,不以 Core 测试代替实机验证。 提供方查询:cargo test -p lithe-core --lib toolchain(含 lsp 引擎脚本后端:只有插件后端被提供 litheToolchains、未协商的提供方不写请求、错误回复原样返回;别名链接只有链接路径事实时仍选中规范 home);MacToolchainDiscoveryTests 用真实临时目录与注入的查询验证全局与目录查询各带独立 operationID/代次、链接 home 规范化、工作区内 home 整份拒绝;ToolchainSettingsFeatureTests 验证监视文件连续变化只重载一次、外部输入观察随关闭释放。真实 mise 插件端到端尚未在应用内验证。 原生布局回归 ToolchainSettingsLayoutTests:同一设置宿主按900/1180/1400/900重复缩放,真实分隔条拖动;来源页按500/666/946/500缩放,检查AX控件边界、卡片不重叠、选择和快照不改变。此几何验证不代表提供方查询或保存功能已完成。 声明式扫描 MacToolchainDiscoveryTests:真实临时目录、注入的用户目录与探测,覆盖 homeLayouts 首个匹配、隐藏与未匹配条目、链接到工作区的条目不探测、只探测 Core 返回的可执行文件、同版本冲突、被拒声明不扫描,以及隔离预览样例清单通过 Core 准入;不运行本机安装的工具。 固定集成新增 MacToolchainDiscoveryTests 的运行前解析回归和 MacBuildToolResolverTests,验证两个目录使用各自 pin、最低版本、独立环境与失败不回落;RunLaunchEnvironmentTests 证明操作返回值不会留下共享执行许可槽。该测试不是完整应用 UI 验收。 生产准入回归 installedToolDeclarationsPassTheProductionHostAdmission 经 RustDeclarativePluginOperations 验证工具定义和提供者。Build PATH 保留声明的附加目录,拒绝空目录项。 Windows 原生解析基础:lithe-project::defined_toolchain 逐项计时覆盖两个工具、声明式扫描、固定目录、最近继承、同版本冲突、最低版本、显式 Wrapper、输入撤销及宿主秘密不进入 RPC。真实 Windows 命令包装和进程清理继续由现有 CI 验证;准入仍关闭。 本次回归另核对同目录两个 Run 独立选择、团队/本机逐项合并和显式清空、私有环境隔离、失效固定值不回落、工作区启动器被动零探测,以及未知默认值迁移失败保留源文件。 本批显式 LITHE_TEST_NODE 驱动真实 Core/Node 会话,逐项计时覆盖单次协商、多次查询、原始错误、无协商拒绝、静默超时、后端意外退出与撤销清理;原生解析验证查询与当前事实、来源在探测中变化及稳定模型摘要。安装状态按 plugin/operation/workspace 隔离且不可跨工作树复制。 #1581 最终合入回归包含固定值与未扫描目录、同轮次/上下文、冲突及提供方超时和不可用的来源展示。 通用默认增量:更改工作区工具 home 后,消费者继承读取新值,按 Run 固定值保持独立;失效明确路径不回落,来源在探测期间改变或越出工作区时拒绝。旧编辑保存保留通用偏好,显式空 v1 文档清除。矩阵保持 pending,未把手写测试文档当成设置页或旧配置迁移验收。 macOS Build 偏好编辑:ToolchainPreferencesTests 验证打开/草稿/取消/空重置不建文件、明确保存/回读与权限保留、外部冲突保留原始草稿基线、仅偏好文档不阻断旧默认迁移、缺失子目录的父链接/最终链接/只读安装目录拒绝及主动取消;原生 Save/Reset 按钮在深浅主题通过实际存储执行。ToolchainSettingsLoaderTests 验证使用方来自当前 Core invocation 并随停用撤回。运行全量 Core 与相关 macOS 逐项计时;完整产品、全局默认、旧消费者和 Windows 设置页仍待验收。 tool 引用验证:共享 fixture/Core 覆盖最近通用目录、根目录、跳过父消费者、目录与工作区默认变化、显式 Run 优先和禁止通用工具反向引用;MacToolchainDiscoveryTests 与 lithe-project::defined_toolchain 的真实临时安装/注入探测验证运行前重读,不冻结安装路径。 本机目录/重载回归覆盖仅消费者偏好、父目录连接、重置撤回、链接/非法层级拒绝、单次重试与可刷新错误、未修改表单更新、冲突草稿保留及自身保存通知不等待/撤销保存。该集成不代替完整 GUI。 运行前来源审计 missingPreferenceLeafBehindAParentAliasIsRejectedBeforeToolWork 覆盖两级父目录及存在/悬空链接,四种情况均在工具探测前拒绝。 ToolchainPluginAdmissionTests 使用正式契约 fixture 与真实 Core 验证市场可安装、完整安装审查、清单加载,以及无后端纯工具定义插件的启用模块和工厂登记;本地编译验证不代替真实 mise 与 Windows 工作流验收。 2026-11-02 本机 Swift 6.4.2:准入、后端、发现和加载器 42 项通过,新增两个准入用例分别 4/6 ms;Swift 6.3.3 在本机 Xcode 27.2 SDK 下编译依赖清单崩溃,不能作为固定工具链通过。真实 mise 0.2.1 发布包 SHA-256 与市场一致,Core 证明修复前 unsupported、修复后 available;真实后端完成协商、查询并停止销毁,当前环境未安装 mise,查询真实返回 miseNotFound,未验证安装列表和应用内工作流。 增补来源保存验收:不存在的 pin 重置不创建状态;拒绝逃出工作区的符号链接/junction;有界 UTF-8 与重复键、未知字段和 dormant pin 校验;Git 后续否定规则、换行/评论/权限保留;公开字节基线不可替代私有快照;已提交但回读失败必须重新加载后才能重试。 Viva 全局 SDK 页:运行 TestVisualSettings/33-settings-toolchains,使用 en、zh-Hans 和 dark/light 的生产无头窗口,核对无项目模式、自动实际值、多版本登记与全局默认选择。通过 run-go-tests-with-timing.mjs 记录单测试 HTML/JUnit;desktop-ci 的 macOS/Windows 每次上传四张图和计时报告。2026-11-15 本机 macOS 与 Windows 11 ARM64 来宾的 GNU x64 系统仿真均通过两个语言各 3 个计时结果,Windows 49 个 SDK/来源/诊断/资源定向用例通过;该证据不替代工具提供方与完整产品工作流验收,整体保持 partial/pending。 Windows #2042:TestToolchainCandidatesUseNativeShellPathsInUserProfiles 以真实 PATH 查找、真实有界版本进程和 Core 候选规则,覆盖 PATH-only/环境变量-only 及空格/中文用户目录;合成工具位于扫描目录之外,全局登记使用私有根。 通过现有 Windows CI 的 scripts/desktop/check.sh 运行;本机逐项计时报告覆盖这些合成场景,完整原生界面验收仍保持 pending。 2026-11-18(#2122):使用 dev.lithe.test.* 合成工具清单运行 TestUntrustedProjectEnvironmentNeverProbesWorkspaceExecutables、TestTrustedWorkspacePersistsInLocalSettingsOnlyAndResolvesSymlinkedVenv、TestTrustedWorkspaceResolvesSubdirectoryEnvironmentAndRejectsEscapingDirectories、TestProjectToolchainTrustSwitchGrantsAndRevokesImmediately 与 TestWorkbenchToolchainTrustPersistsLocallyLogsActionAndEnablesRuntimeResolution,验证未授权零探测、两跳符号链接虚拟环境字面路径保留、目录软链逃逸在探测前拒绝、本机 toolchains/global.json 原子保存与撤销(绝不写工作区 .lithe/)、performedIn 操作轨迹以及中英明暗无头截图 m47/m48;Windows 实机与完整原生 GUI 工作流保持 pending。", - "notes": "Viva:共享 Core toolchain 命令已接入 desktop/internal/core/toolchain.go;声明式扫描、文件事实、有界版本探测、toolchains.candidates/resolve 与目录 pin 保存位于 desktop/internal/toolchain/ 并有真实 Core 测试;设置窗口 Build 页可按插件声明展示工具、生效值与来源,显式 Save/Reset 写 .lithe/toolchains/local.json,Cancel 不写;Build 命令和 Provider Run 的 toolchain 候选使用 Core 解析出的可执行文件、环境导出和 PATH。提供方后端查询(toolchainProviders)未接入,因此未声明该能力;Windows 与完整 GUI/原生工作流未验收,状态保持 pending,legacy 证据不代表 Viva。 本轮通过外部 Core Draft PR #3 的精确提交接入 toolchains.editPins:平台不再编辑 pin schema;Core/Go 共用 fixture、批量保存和取消/外部并发修改回归通过。命令型 Tests 同样消费解析后的工具链环境。原生 Windows、提供方工具查询、完整 GUI 与发行验收仍 pending。 Windows 原生回归确认保存前后的文件模式以及真实访问控制描述符(所有者、组、DACL/继承保护)保留;元数据先准备到临时文件,再核对取消/冲突并原子发布。此证据不代表提供方查询或 GUI 已验收。 Viva 设置保存前核对读取项目的原生目录身份;项目关闭或切换后旧草稿拒绝写入,已确认保存的发布与回读固定捕获来源。冲突通过共享 i18n 显示并保留草稿,加载/保存失败进入目录日志;macOS 先失败后通过的回归已有计时,新增作用域行为的 Windows 验收尚未执行。 Windows 原生探测统一 Core 正斜杠路径与本机反斜杠/大小写别名,防止重复事实使目录 pin 解析遭拒绝;选择与校验规则仍由原有 Core 决定。 全局 SDK 登记与默认值可在未打开项目时编辑;项目范围保留独立覆盖,读取不创建文件,确认保存后按实际探测回显。新增合成工具原生与无头测试,不改变历史完整验收状态。 Viva 2026-11-16:Build 页每个工具改为一个下拉框,默认回显当前选择(未固定时为“自动(实际目录)”),列出识别到的其他安装、已保存固定值和已校验目录;选“自定义…”才显示目录输入、浏览和“使用此目录”,校验通过后该目录成为列表项并被选中。无版本的安装不可选,在列表下以说明文字列出。自动化:TestToolchainListShowsAutomaticAndHidesTheDirectoryUntilCustom 及原有草稿/保存/冲突用例;截图 TestVisualSettings/33-settings-toolchains、m44-toolchain-directory-menu、m45-toolchain-custom-directory。原生验收仍 pending。 Viva 2026-11-16(#2032):toolchains.candidates 改为同时接收宿主找到的 PATH 命令所在目录(commandHomes),JAVA_HOME 等声明变量和 PATH 上的安装校验通过后以 host:shell 并入安装列表并按规范目录去重,新建项目的工具选择、设置页和运行配置因此能选到只配置在 PATH 或环境变量上的 JDK;自动层的选择不变。Core 回归 toolchain_candidates_offer_shell_homes_that_no_discovery_scan_covers(Lithe-core-rust#67),宿主回归 TestShellHomesAreInstallationsWithoutADiscoveryScan;两者都确认修复前失败。Windows 0.8.0 实机复现了缺陷,修复后的完整 Windows 客户端尚未实机验收,状态保持 pending。 Viva 2026-11-18(#2122):prepareTool 沿工作区祖先链观测 discoveryPlan 返回的 projectFiles、requires、home、中间父目录、pathPrepend 及软链目标;probeAll 在 ProjectCodeAllowed 为 false 时拒绝探测任何工作区内可执行文件;本机信任记录经 Core catalogState/editCatalog 保存在应用用户设置目录 toolchains/global.json,设置页项目作用域提供带 ⓘ 说明的显式信任开关并立即回读生效值,工作台 resolveToolchainSelection 同步读取同一本机信任状态。", + "notes": "Viva:共享 Core toolchain 命令已接入 desktop/internal/core/toolchain.go;声明式扫描、文件事实、有界版本探测、toolchains.candidates/resolve 与目录 pin 保存位于 desktop/internal/toolchain/ 并有真实 Core 测试;设置窗口 Build 页可按插件声明展示工具、生效值与来源,显式 Save/Reset 写 .lithe/toolchains/local.json,Cancel 不写;Build 命令和 Provider Run 的 toolchain 候选使用 Core 解析出的可执行文件、环境导出和 PATH。提供方后端查询(toolchainProviders)未接入,因此未声明该能力;Windows 与完整 GUI/原生工作流未验收,状态保持 pending,legacy 证据不代表 Viva。 本轮通过外部 Core Draft PR #3 的精确提交接入 toolchains.editPins:平台不再编辑 pin schema;Core/Go 共用 fixture、批量保存和取消/外部并发修改回归通过。命令型 Tests 同样消费解析后的工具链环境。原生 Windows、提供方工具查询、完整 GUI 与发行验收仍 pending。 Windows 原生回归确认保存前后的文件模式以及真实访问控制描述符(所有者、组、DACL/继承保护)保留;元数据先准备到临时文件,再核对取消/冲突并原子发布。此证据不代表提供方查询或 GUI 已验收。 Viva 设置保存前核对读取项目的原生目录身份;项目关闭或切换后旧草稿拒绝写入,已确认保存的发布与回读固定捕获来源。冲突通过共享 i18n 显示并保留草稿,加载/保存失败进入目录日志;macOS 先失败后通过的回归已有计时,新增作用域行为的 Windows 验收尚未执行。 Windows 原生探测统一 Core 正斜杠路径与本机反斜杠/大小写别名,防止重复事实使目录 pin 解析遭拒绝;选择与校验规则仍由原有 Core 决定。 全局 SDK 登记与默认值可在未打开项目时编辑;项目范围保留独立覆盖,读取不创建文件,确认保存后按实际探测回显。新增合成工具原生与无头测试,不改变历史完整验收状态。 Viva 2026-11-16:Build 页每个工具改为一个下拉框,默认回显当前选择(未固定时为“自动(实际目录)”),列出识别到的其他安装、已保存固定值和已校验目录;选“自定义…”才显示目录输入、浏览和“使用此目录”,校验通过后该目录成为列表项并被选中。无版本的安装不可选,在列表下以说明文字列出。自动化:TestToolchainListShowsAutomaticAndHidesTheDirectoryUntilCustom 及原有草稿/保存/冲突用例;截图 TestVisualSettings/33-settings-toolchains、m44-toolchain-directory-menu、m45-toolchain-custom-directory。原生验收仍 pending。 Viva 2026-11-16(#2032):toolchains.candidates 改为同时接收宿主找到的 PATH 命令所在目录(commandHomes),JAVA_HOME 等声明变量和 PATH 上的安装校验通过后以 host:shell 并入安装列表并按规范目录去重,新建项目的工具选择、设置页和运行配置因此能选到只配置在 PATH 或环境变量上的 JDK;自动层的选择不变。Core 回归 toolchain_candidates_offer_shell_homes_that_no_discovery_scan_covers(Lithe-core-rust#67),宿主回归 TestShellHomesAreInstallationsWithoutADiscoveryScan;两者都确认修复前失败。Windows 0.8.0 实机复现了缺陷,修复后的完整 Windows 客户端尚未实机验收,状态保持 pending。 Viva 2026-11-18(#2122):prepareTool 沿工作区祖先链观测 discoveryPlan 返回的 projectFiles、requires、home、中间父目录、pathPrepend 及软链目标;probeAll 在 ProjectCodeAllowed 为 false 时拒绝探测任何工作区内可执行文件;本机信任记录经 Core catalogState/editCatalog 保存在应用用户设置目录 toolchains/global.json,设置页项目作用域提供带 ⓘ 说明的显式信任开关并立即回读生效值,工作台 resolveToolchainSelection 同步读取同一本机信任状态。 Viva 2026-11-18(构建设置重构):工具链页按 docs/design/build-execution-settings.html 重做为“全局默认 / 当前项目”两个作用域、按类别或插件分组、需处理与已手动指定过滤,列表与详情两栏;详情显示当前生效的程序、版本与来源标签和安装列表(自动、发现的安装、手动目录),项目作用域在未信任时显示信任提示。筛选、分组和计数由 Core 设置投影(Lithe-core-rust#99)给出,一个插件可以注册多个 SDK。固定值本身不再算一个来源标签,只有其目录不在其他来源中时才标出提供方。自动化:toolchains_view_test.go、TestVisualSettings 的 33、m44–m49 场景。原生与 Windows 验收仍 pending。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {