diff --git a/desktop/internal/workbench/editor_essentials_visual_test.go b/desktop/internal/workbench/editor_essentials_visual_test.go index 646fa6b5e2..bb31c43e2c 100644 --- a/desktop/internal/workbench/editor_essentials_visual_test.go +++ b/desktop/internal/workbench/editor_essentials_visual_test.go @@ -64,7 +64,7 @@ func TestVisualEditorEssentials(t *testing.T) { case "find-replace": d.find.debounce = -1 d.view.SetSelection(0, 0) - h.app.openEditorFind(true) + h.app.openEditorFind(true, surfaceButton) d.find.query.SetText("greet") d.find.replacement.SetText("welcome") h.app.refreshEditorFind(p, d) diff --git a/desktop/internal/workbench/new_project_test.go b/desktop/internal/workbench/new_project_test.go index 996c3d393a..d67e728381 100644 --- a/desktop/internal/workbench/new_project_test.go +++ b/desktop/internal/workbench/new_project_test.go @@ -98,6 +98,13 @@ func fixtureJavaTools() map[string]toolList { func newGeneratorHarness(t *testing.T, kernel Kernel, plugins ...pluginservice.GeneratorPlugin) *harness { t.Helper() h := newHarnessWithLanguages(t, kernel, []string{"en-US"}) + h.offerGenerators(plugins...) + return h +} + +// offerGenerators makes the plugins the app's project generators, with the fixture +// tools as the tool lists their requirements resolve against. +func (h *harness) offerGenerators(plugins ...pluginservice.GeneratorPlugin) { h.app.generatorPlugins = func(context.Context) ([]pluginservice.GeneratorPlugin, error) { return plugins, nil } h.app.projectToolLists = func(_ context.Context, tools []string) (map[string]toolList, error) { lists := map[string]toolList{} @@ -106,7 +113,6 @@ func newGeneratorHarness(t *testing.T, kernel Kernel, plugins ...pluginservice.G } return lists, nil } - return h } func TestWelcomeCreatesEmptyProjectWithGitThroughCore(t *testing.T) { @@ -724,6 +730,73 @@ func TestNewProjectGeneratorNeedsAValidFormAndOffersToEnableRequirements(t *test } } +// describedGeneratorPlugin declares a generator whose text, choice and checkbox +// fields describe themselves, and one field that does not. +func describedGeneratorPlugin(t *testing.T) pluginservice.GeneratorPlugin { + t.Helper() + manifest, err := json.Marshal(map[string]any{ + "schemaVersion": 0, "id": "dev.lithe.test.described", "displayName": "Described", "version": "1.0.0", + "pluginAPIVersion": 0, "requires": map[string]int{"projectGenerators": 0}, + "vendor": map[string]string{"id": "org.example", "displayName": "Example", "signatureRequirement": "publisherPackage"}, + "permissions": []string{"project.generate"}, "activationEvents": []string{}, + "projectGenerators": []map[string]any{{ + "id": "described", "displayName": "Described", "section": "generator", + "fields": []map[string]any{ + {"id": "flavor", "type": "enum", "title": "Flavor", "description": "The flavor the project starts from.", "default": "plain", + "options": []map[string]string{{"value": "plain", "title": "Plain"}, {"value": "rich", "title": "Rich"}}}, + {"id": "label", "type": "text", "title": "Label", "description": "The label written into the project.", "default": "hello"}, + {"id": "note", "type": "text", "title": "Note", "default": "none"}, + {"id": "sample", "type": "boolean", "title": "Add sample code", "description": "Adds a sample source file.", "default": true}, + }, + "steps": []map[string]any{{"kind": "command", "command": "scaffold-tool", "mayUseNetwork": false, "timeoutSeconds": 60}}, + }}, + }) + if err != nil { + t.Fatal(err) + } + return pluginservice.GeneratorPlugin{PluginID: "dev.lithe.test.described", Version: "1.0.0", Path: t.TempDir(), Enabled: true, Manifest: manifest} +} + +// A field's description is the tip of an ⓘ beside the field, each ⓘ its own +// field's; a plain label cannot carry a tip, and drawing one there broke the +// whole form. +func TestNewProjectFieldDescriptionsAreInformationTips(t *testing.T) { + h := newGeneratorHarness(t, &testKernel{Client: core.NewClient()}, describedGeneratorPlugin(t)) + h.openNewProjectSheet() + h.chooseGenerator("Described", "dev.lithe.test.described/described") + more := i18n.Shared(h.app.language(), "native.moreInformation") + var help []gfx.Hit + for _, hit := range h.driver.Snapshot().Hits { + if hit.Label == more && !hit.IsLabel { + help = append(help, hit) + } + } + want := []string{"The flavor the project starts from.", "The label written into the project.", "Adds a sample source file."} + if len(help) != len(want) { + t.Fatalf("%d ⓘ controls, want one per described field: %+v", len(help), help) + } + ids := map[gfx.ID]int{} + for i, hit := range help { + if hit.Hint != want[i] { + t.Fatalf("ⓘ %d tells assistive technology %q, want %q", i, hit.Hint, want[i]) + } + if other, taken := ids[hit.ID]; taken { + t.Fatalf("ⓘ %d and ⓘ %d are one control %v", other, i, hit.ID) + } + ids[hit.ID] = i + } + for i, hit := range help { + at := center(hit.Bounds) + if err := h.driver.Move(at.X, at.Y); err != nil { + t.Fatal(err) + } + h.settle() + if tips := h.tooltips(); len(tips) != 1 || tips[0].Value != want[i] { + t.Fatalf("resting on ⓘ %d shows the tips %+v, want only %q", i, tips, want[i]) + } + } +} + // awaitValidForm paints what the test just entered, then waits until Core has // answered for it and the form can be submitted. Checking before the paint // would trust the previous frame's button. diff --git a/desktop/internal/workbench/new_project_view.go b/desktop/internal/workbench/new_project_view.go index 2cb120e1ef..9fc56ebef9 100644 --- a/desktop/internal/workbench/new_project_view.go +++ b/desktop/internal/workbench/new_project_view.go @@ -346,20 +346,28 @@ func (a *App) generatorFields(c ui.C, language i18n.Language, form *generatorFor } } -// generatorField draws one field by its declared type. +// generatorField draws one field by its declared type. A field's description is +// the tip of an ⓘ beside its title, or beside its checkbox: a tip needs an element +// with an identity, which a plain text is not. func (a *App) generatorField(c ui.C, language i18n.Language, form *generatorForm, field *formField, locked bool) { decl := field.decl - ui.Column(c.Part("field")).FillWidth().Gap(4).Children(func() { + help := func() { + if decl.Description != "" { + ui.Button(c.Part("help"), i18n.Shared(language, "native.moreInformation")).Icon(icons.Info).IconOnly().Ghost(). + Size(18, 18).Shrink(0).Tooltip(decl.Description).TooltipOn(ui.TooltipRight) + } + } + // Core rejects a generator that declares a field ID twice, so the ID names the field + // among its siblings and keeps each field's ⓘ apart from the others'. + ui.Column(c.Key(decl.ID)).FillWidth().Gap(4).Children(func() { ui.Row(c).FillWidth().Items(ui.Center).Gap(12).Children(func() { - if decl.Type == fieldBoolean { + ui.Row(c).Width(120).Shrink(0).Items(ui.Center).Gap(4).Children(func() { // A checkbox carries its own label; keep it in the controls' column. - ui.Row(c).Width(120).Shrink(0) - } else { - label := ui.Text(c, decl.Title).Width(120).Shrink(0) - if decl.Description != "" { - label.Tooltip(decl.Description) + if decl.Type != fieldBoolean { + ui.Text(c, decl.Title).Ellipsis() + help() } - } + }) if locked { ui.Text(c, field.canonical()).Muted() return @@ -375,7 +383,11 @@ func (a *App) generatorField(c ui.C, language i18n.Language, form *generatorForm ui.Select(c, &field.text, field.values, titleOf).Width(240) } case fieldBoolean: - ui.Checkbox(c, &field.flag, decl.Title) + // The ⓘ sits as close to the checkbox's label as it does to a title. + ui.Row(c).Items(ui.Center).Gap(4).Children(func() { + ui.Checkbox(c, &field.flag, decl.Title) + help() + }) case fieldMultiSelect: a.multiSelectField(c, field) case fieldTool: diff --git a/desktop/internal/workbench/visual_capture_test.go b/desktop/internal/workbench/visual_capture_test.go index 0a127bce8d..964e792017 100644 --- a/desktop/internal/workbench/visual_capture_test.go +++ b/desktop/internal/workbench/visual_capture_test.go @@ -308,3 +308,62 @@ func TestVisualWorkbenchGradientStaysBehindPanels(t *testing.T) { t.Fatalf("project gradient covered the opaque tool panel: %v, want #191a1c", got) } } + +// TestVisualNewProjectFieldDescriptions captures a generator form whose fields describe +// themselves: each description is the tip of an ⓘ beside its field, shown here resting +// on the first one. It needs only LITHE_VISUAL_OUTPUT_DIR. +func TestVisualNewProjectFieldDescriptions(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, theme := range []string{"dark", "light"} { + for _, language := range []string{"zh-Hans", "en-US"} { + t.Run(theme+"-"+language, func(t *testing.T) { + var session *headless.Session + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, map[string]string{"theme": theme}); err != nil { + t.Fatal(err) + } + h := newHarnessWithDriver(t, Options{Kernel: &testKernel{Client: core.NewClient()}, Store: prefs, Languages: []string{language}}, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 800, 682 + config.MinWidth = 800 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + h.offerGenerators(describedGeneratorPlugin(t)) + h.openNewProjectSheet() + h.chooseGenerator("Described", "dev.lithe.test.described/described") + more := i18n.Shared(h.app.language(), "native.moreInformation") + hovered := false + for _, hit := range h.driver.Snapshot().Hits { + if hit.Label == more && !hit.IsLabel { + at := center(hit.Bounds) + if err := h.driver.Move(at.X, at.Y); err != nil { + t.Fatal(err) + } + h.settle() + hovered = true + break + } + } + if !hovered { + t.Fatal("the form has no ⓘ") + } + if tips := h.tooltips(); len(tips) != 1 || tips[0].Value != "The flavor the project starts from." { + t.Fatalf("resting on the first ⓘ shows the tips %+v", tips) + } + if err := session.Screenshot(filepath.Join(out, "new-project-field-info-"+theme+"-"+language+".png")); err != nil { + t.Fatal(err) + } + }) + } + } +} diff --git a/shared/platform-feature-matrix/features/plugin-project-generators.json b/shared/platform-feature-matrix/features/plugin-project-generators.json index bbce668992..4c4e0973d4 100644 --- a/shared/platform-feature-matrix/features/plugin-project-generators.json +++ b/shared/platform-feature-matrix/features/plugin-project-generators.json @@ -2,7 +2,7 @@ "id": "plugin-project-generators", "area": "工作区", "group": "项目", - "capability": "新建项目窗口按 IDEA 的布局列出“新建项目”和“生成器”两组条目:空项目由宿主提供,其余条目由插件通过 projectGenerators 1 注入。名称、位置、创建 Git 仓库由宿主绘制;字段、派生默认值、显示条件和生成计划由 Rust Core 计算;先在目标目录旁的临时目录生成,完成后整体移动到位,失败或取消不留残留。条目需要的语言或构建系统插件未启用时提示一键启用,未安装时跳转插件市场搜索;所选运行时写入新项目的运行时设置,模板指定的文件随项目一起打开。projectGenerators 2 增加通用的工具字段(type:tool):生成器只写工具定义 ID 和最低版本,宿主通过通用工具解析列出已安装的候选,所选工具写入新项目的工具 pin(.lithe/run/local.json),步骤可引用 ${field.} 与 ${field..executable};找不到工具时提示启用或到插件市场查找,低于最低版本的安装不可创建。只含生成器或工具定义的插件安装、更新、卸载后免重启,新建项目窗口随之刷新条目", + "capability": "新建项目窗口按 IDEA 的布局列出“新建项目”和“生成器”两组条目:空项目由宿主提供,其余条目由插件通过 projectGenerators 1 注入。名称、位置、创建 Git 仓库由宿主绘制,字段声明的说明显示为标题旁(复选框字段为复选框旁)ⓘ 的悬停提示;字段、派生默认值、显示条件和生成计划由 Rust Core 计算;先在目标目录旁的临时目录生成,完成后整体移动到位,失败或取消不留残留。条目需要的语言或构建系统插件未启用时提示一键启用,未安装时跳转插件市场搜索;所选运行时写入新项目的运行时设置,模板指定的文件随项目一起打开。projectGenerators 2 增加通用的工具字段(type:tool):生成器只写工具定义 ID 和最低版本,宿主通过通用工具解析列出已安装的候选,所选工具写入新项目的工具 pin(.lithe/run/local.json),步骤可引用 ${field.} 与 ${field..executable};找不到工具时提示启用或到插件市场查找,低于最低版本的安装不可创建。只含生成器或工具定义的插件安装、更新、卸载后免重启,新建项目窗口随之刷新条目", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -11,6 +11,7 @@ "desktop/internal/workbench/new_project_view.go", "desktop/internal/workbench/new_project_form.go", "desktop/internal/workbench/new_project_test.go", + "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/projectgen/run.go", "desktop/internal/projectgen/run_test.go", "desktop/internal/core/project_generators.go", @@ -26,6 +27,7 @@ "desktop/internal/workbench/new_project_view.go", "desktop/internal/workbench/new_project_form.go", "desktop/internal/workbench/new_project_test.go", + "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/projectgen/run.go", "desktop/internal/projectgen/run_test.go", "desktop/internal/core/project_generators.go", @@ -34,8 +36,8 @@ ] }, "owner": "Plugin Platform", - "verification": "macOS:安装测试内联的合成生成器插件(声明文件、命令、归档三类步骤),从欢迎页和项目切换器点“新建项目”,确认左栏有“新建项目”(含宿主提供的空项目)和“生成器”两组且可搜索。用文件步骤创建,确认生成声明的文件、项目打开后 openFiles 指定的文件已打开。勾选“创建 Git 仓库”时项目根目录有 .git。归档步骤从本机回环 HTTP 服务下载并解压、可执行位保留;把归档地址改成不可达地址时报错且目标目录下没有残留的 .*.lithe-creating-* 临时目录。命令步骤在 PATH 中找不到可执行文件时提示找不到命令。停用该插件后条目变灰、创建按钮不可用,只出现一条启用提示,点击后条目恢复可用;所需插件未安装时出现“在插件市场中查找”。目标目录已存在时拒绝创建且不改动原目录。工具字段:用 Lithe-core-rust 的 shared/plugins/contract/v1/fixtures/project-generators/project-generator-tool-field.plugin.json 和一个定义了同名工具的插件做本地开发安装,新建项目里该生成器的工具下拉列出本机已发现的安装(含版本),选低于最低版本的安装时创建按钮不可用并提示,选满足版本的安装创建后新项目的 .lithe/run/local.json 里有该工具的 pin,设置里的工具链页面显示同一个固定值;没有任何插件定义该工具时出现“在插件市场中查找”,插件已安装未启用时出现“启用”。在新建项目窗口保持打开时安装或卸载只含生成器的插件,条目立即出现或消失且无需重启。Windows:宿主不声明 projectGenerators,需要它的插件在市场中隐藏。", - "notes": "Viva 新建项目窗口用 Page 写法重做并接通 projectGenerators 1 与 2(宿主已声明):左栏分“新建项目”和“生成器”两组并经 Core 搜索,列出空项目和已启用插件的生成器;右栏按声明画文本、选择、复选、多选、运行时/工具安装下拉和“高级设置”,默认值、显示条件、错误码和生成计划全部来自 Core(project.generatorCatalog/generatorForm/generationPlan)。创建时先在目标目录旁的 .<名称>.lithe-creating-* 临时目录依次执行文件、命令、归档步骤:文件用同目录临时文件原子写入并拒绝越出目录和符号链接;命令用 buildprocess 执行,输出逐行显示、可取消、有超时(默认 600 秒);归档下载只允许 HTTPS(回环地址可用 HTTP)并限制 512 MiB,再交给 Core 解压。全部成功才整体移动到位,失败或取消删除临时目录不留残留;移动之后的失败(Git 初始化、工具 pin)保留已建目录并提供“打开已创建的项目”。工具与 runtime 字段通过共享工具链在空临时目录里发现安装,所选安装写入新项目的 .lithe/toolchains/local.json,generator 声明的 openFiles 在项目打开后打开。空项目行为不变。尚未完成:生成器自带图标未画;缺少所需插件时“在插件市场中查找”只打开插件设置而不预填搜索词;命令步骤只按 PATH 解析可执行文件;插件热更新只在已安装列表变化时重读条目;两端原生窗口、真实归档下载与命令步骤和 Windows 都未验证。legacy 是迁移前基线。", + "verification": "macOS:安装测试内联的合成生成器插件(声明文件、命令、归档三类步骤),从欢迎页和项目切换器点“新建项目”,确认左栏有“新建项目”(含宿主提供的空项目)和“生成器”两组且可搜索。用文件步骤创建,确认生成声明的文件、项目打开后 openFiles 指定的文件已打开。勾选“创建 Git 仓库”时项目根目录有 .git。归档步骤从本机回环 HTTP 服务下载并解压、可执行位保留;把归档地址改成不可达地址时报错且目标目录下没有残留的 .*.lithe-creating-* 临时目录。命令步骤在 PATH 中找不到可执行文件时提示找不到命令。停用该插件后条目变灰、创建按钮不可用,只出现一条启用提示,点击后条目恢复可用;所需插件未安装时出现“在插件市场中查找”。目标目录已存在时拒绝创建且不改动原目录。生成器字段声明了 description 时,选中该生成器后表单正常显示,每个带说明的字段旁各有一个 ⓘ,悬停只显示该字段自己的说明,标题过长时省略且 ⓘ 仍可见。工具字段:用 Lithe-core-rust 的 shared/plugins/contract/v1/fixtures/project-generators/project-generator-tool-field.plugin.json 和一个定义了同名工具的插件做本地开发安装,新建项目里该生成器的工具下拉列出本机已发现的安装(含版本),选低于最低版本的安装时创建按钮不可用并提示,选满足版本的安装创建后新项目的 .lithe/run/local.json 里有该工具的 pin,设置里的工具链页面显示同一个固定值;没有任何插件定义该工具时出现“在插件市场中查找”,插件已安装未启用时出现“启用”。在新建项目窗口保持打开时安装或卸载只含生成器的插件,条目立即出现或消失且无需重启。Windows:宿主不声明 projectGenerators,需要它的插件在市场中隐藏。", + "notes": "Viva 新建项目窗口用 Page 写法重做并接通 projectGenerators 1 与 2(宿主已声明):左栏分“新建项目”和“生成器”两组并经 Core 搜索,列出空项目和已启用插件的生成器;右栏按声明画文本、选择、复选、多选、运行时/工具安装下拉和“高级设置”,默认值、显示条件、错误码和生成计划全部来自 Core(project.generatorCatalog/generatorForm/generationPlan)。创建时先在目标目录旁的 .<名称>.lithe-creating-* 临时目录依次执行文件、命令、归档步骤:文件用同目录临时文件原子写入并拒绝越出目录和符号链接;命令用 buildprocess 执行,输出逐行显示、可取消、有超时(默认 600 秒);归档下载只允许 HTTPS(回环地址可用 HTTP)并限制 512 MiB,再交给 Core 解压。全部成功才整体移动到位,失败或取消删除临时目录不留残留;移动之后的失败(Git 初始化、工具 pin)保留已建目录并提供“打开已创建的项目”。工具与 runtime 字段通过共享工具链在空临时目录里发现安装,所选安装写入新项目的 .lithe/toolchains/local.json,generator 声明的 openFiles 在项目打开后打开。字段说明画成标题旁(复选框字段为复选框旁)的 ⓘ 提示:纯文本没有身份不能带提示,迁移时把提示挂在标题文字上,选中带说明的生成器会让绘制 panic、窗口转圈卡死;各字段按字段 ID 命名,ⓘ 互不混淆。空项目行为不变。尚未完成:生成器自带图标未画;缺少所需插件时“在插件市场中查找”只打开插件设置而不预填搜索词;命令步骤只按 PATH 解析可执行文件;插件热更新只在已安装列表变化时重读条目;两端原生窗口、真实归档下载与命令步骤和 Windows 都未验证。legacy 是迁移前基线。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {