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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions desktop/internal/i18n/shared.generated.go

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

40 changes: 38 additions & 2 deletions desktop/internal/workbench/build_panels_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,39 @@ func visualBuildSystems() []buildInstance {
}
}

// visualGoModule is one Go module whose targets are named by their whole import path, under
// the folder each is in, which their rows show alone. Two of its packages are commands, which
// run; the others are packages with tests.
func visualGoModule() buildInstance {
const module = "github.com/example/shop/desktop"
pkg := func(dir, tag string) core.BuildTarget {
return core.BuildTarget{ID: dir, ProjectID: "desktop", Name: module + "/" + dir, Path: dir, Tags: []string{tag}}
}
return buildInstance{
BuildInstance: core.BuildInstance{ID: "go@desktop", PluginID: "dev.example.go", BuildSystemID: "go", Root: "desktop"},
PluginID: "dev.example.go",
System: pluginservice.BuildSystemDeclaration{
DisplayName: "Go Modules",
Runs: []pluginservice.BuildRunDeclaration{{ID: "main", Name: "Run", Tags: []string{"application"}}},
Tasks: []pluginservice.BuildTaskDeclaration{{ID: "build", DisplayName: "Build", Source: "provider"}, {ID: "vet", DisplayName: "Vet", Source: "provider"}},
Dependencies: &pluginservice.BuildDependenciesDeclaration{Scopes: []string{"project"}},
},
Model: core.BuildModel{
Projects: []core.BuildProject{{ID: "desktop", Path: ".", Name: module}},
Targets: []core.BuildTarget{
pkg("cmd/shop", "application"), pkg("cmd/shop-perf", "application"),
pkg("internal/checkout", "test"), pkg("internal/catalog", "test"), pkg("internal/catalog/search", "test"),
pkg("internal/payments", "test"), pkg("internal/storage", "test"), pkg("internal/i18n", "test"),
},
},
modelLoaded: true,
}
}

// TestVisualBuildPanels captures the Build window on the right, with the run configurations
// above the aggregated build tree, beside the Run window at the bottom showing only the build
// console, and the Build window filtered.
// console; the Build window filtered; and a Go module, whose runnable rows lead with the green
// triangle.
func TestVisualBuildPanels(t *testing.T) {
out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR")
if out == "" {
Expand All @@ -71,7 +101,7 @@ func TestVisualBuildPanels(t *testing.T) {
t.Fatal(err)
}
for _, look := range []struct{ theme, language string }{{"dark", "zh-Hans"}, {"light", "en"}} {
for _, scene := range []string{"build-and-run", "build-filter"} {
for _, scene := range []string{"build-and-run", "build-filter", "build-go-targets"} {
t.Run(scene+"-"+look.theme, func(t *testing.T) {
prefs := store.At(t.TempDir())
if err := prefs.Save(settingsFile, settings{Theme: themeChoice(look.theme), Language: look.language, DisableAutoSave: true}); err != nil {
Expand Down Expand Up @@ -130,6 +160,12 @@ func TestVisualBuildPanels(t *testing.T) {
})
case "build-filter":
h.app.post(func(*App) { p.panels.buildFilter = "app" })
case "build-go-targets":
h.app.post(func(a *App) {
p.build.instances, p.build.selected = []buildInstance{visualGoModule()}, 0
p.build.projectID, p.build.targetID, p.build.taskID = "desktop", "internal/catalog", ""
a.refreshRunConfigurations(p)
})
}
h.settleChain()
h.app.invalidator.Invalidate()
Expand Down
65 changes: 65 additions & 0 deletions desktop/internal/workbench/build_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,71 @@ func (k *captureBuildTask) PlanBuildTask(_ context.Context, _ json.RawMessage, _
return core.BuildPlan{}, errors.New("captured")
}

// A task, and a target that has a run, lead with the green triangle that runs them whether
// they are chosen or not, as IntelliJ's Make window marks its targets: one click on it chooses
// the row and runs it. A target with nothing to run keeps the icon of its kind, a build
// operation in flight leaves no triangle to click, a row's hover hint holds its whole name and
// path, and the Dependencies heading has the ⓘ that says when its tree is read.
func TestBuildTreeRunMarksRunTheirRowsAtOnce(t *testing.T) {
instance := runConfigInstance("app")
instance.System.Tasks = []pluginservice.BuildTaskDeclaration{{ID: "vet", DisplayName: "Vet verification", Scopes: []string{"project"}, Source: "provider"}}
instance.System.Dependencies = &pluginservice.BuildDependenciesDeclaration{Scopes: []string{"project"}}
instance.Model.Targets[0].Path = "server/cmd/main"
kernel := &captureBuildTask{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)}
h, p := openBuildTree(t, kernel, []buildInstance{instance})
h.app.reduceChrome(core.SetChromeOpen(itemBuild, true))
if err := h.driver.Resize(1280, 1400); err != nil {
t.Fatal(err)
}
h.settle()
h.settle()
text, language := h.app.text.Build, h.app.language()
controls := func(label string) []gfx.Hit {
var found []gfx.Hit
for _, hit := range h.driver.Snapshot().Hits {
if hit.Label == label && !hit.IsLabel {
found = append(found, hit)
}
}
return found
}
if marks := controls(text.RunTarget("Run")); len(marks) != 1 {
t.Fatalf("%d target triangles, want only the one of the target that has a run", len(marks))
}
task := controls(text.RunTarget("Vet verification"))
if len(task) != 1 || task[0].Hint != text.RunTarget("Vet verification") {
t.Fatalf("the task's triangle is %+v", task)
}
if rows := controls("Main"); len(rows) != 1 || rows[0].Hint != "Main\nserver/cmd/main" {
t.Fatalf("the target row's hover hint is %+v", rows)
}
help := controls(i18n.Shared(language, "native.moreInformation"))
if len(help) != 1 || help[0].Hint != i18n.Shared(language, "desktop.build.dependenciesHelp") {
t.Fatalf("the Dependencies heading's ⓘ is %+v", help)
}

// One click on the triangle of a task nothing chose chooses it and runs it.
if p.build.taskID != "" || p.build.targetID != "" {
t.Fatalf("task %q and target %q chosen before the click", p.build.taskID, p.build.targetID)
}
h.click(center(task[0].Bounds))
awaitStateWithin(t, h, 10*time.Second, "the task plan request", func() bool { return len(kernel.requests) == 1 })
if request := <-kernel.requests; request.Task != "vet" || p.build.taskID != "vet" {
t.Fatalf("the triangle asked for %+v with task %q chosen", request, p.build.taskID)
}
awaitStateWithin(t, h, 10*time.Second, "the refused plan", func() bool { return p.build.operation == nil })

// While a build operation runs, no triangle takes a click.
var operation *buildOperation
h.app.post(func(a *App) { operation = a.beginBuildOperation(p, "build", "vet", "") })
h.settle()
if len(controls(text.RunTarget("Vet verification"))) != 0 || len(controls(text.RunTarget("Run"))) != 0 {
t.Fatal("a triangle took clicks while a build operation ran")
}
h.app.post(func(a *App) { a.finishBuildTask(p, operation, json.RawMessage(`{"exitCode":0}`)) })
h.settle()
}

// A task row of the tree carries no project, so the run fits the selection to the task: a
// project task runs on the build system's only project instead of the workspace, a model task
// on its own project, and a project task with no project to infer asks for one.
Expand Down
103 changes: 77 additions & 26 deletions desktop/internal/workbench/build_tree_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ var buildSectionIcons = map[string]*gfx.Icon{

// buildSectionRow declares the heading of one section of a group: its arrow, icon, name and
// how many rows it holds, once that is known. A click opens or closes it, unless a filter
// keeps it open. The Dependencies and Discovered Tests headings have the menu of their rows.
// keeps it open. The Dependencies and Discovered Tests headings have the menu of their rows,
// and the Dependencies heading the ⓘ that says when its tree is read.
func (a *App) buildSectionRow(row ui.ListRow, p *project, instance *buildInstance, spec buildRow) {
c := row.C
element := a.buildTreeRowElement(row, spec)
Expand All @@ -337,6 +338,13 @@ func (a *App) buildSectionRow(row ui.ListRow, p *project, instance *buildInstanc
if spec.count >= 0 {
ui.Text(c, strconv.Itoa(spec.count)).FontSize(treeFontSize - 1).Color(a.colors.Subtle).Shrink(0)
}
if spec.section == buildSectionDependencies {
// The heading shows no count until the tree is read, and opening it runs the build
// tool, so the ⓘ says when that happens and how to read it again.
language := a.language()
ui.Button(c.Part("help"), i18n.Shared(language, "native.moreInformation")).Icon(icons.Info).IconOnly().Ghost().Size(18, 18).
Tooltip(i18n.Shared(language, "desktop.build.dependenciesHelp")).TooltipOn(ui.TooltipRight)
}
ui.Spacer(c)
if !spec.fixed && (toggled || element.Clicked()) {
key, open := buildOpenKey(instance.ID, spec.section), spec.open
Expand Down Expand Up @@ -398,33 +406,65 @@ func (a *App) buildNoteRow(row ui.ListRow, p *project, instance *buildInstance,
}
}

// buildItemIcons are the icons of the rows a user chooses or runs.
// buildItemIcons are the icons of the rows a user chooses or runs that have nothing to run.
var buildItemIcons = map[buildRowKind]*gfx.Icon{
buildRowProject: &icons.Folder,
buildRowTarget: &icons.CircleDot,
buildRowTask: &icons.SquareTerminal,
}

// buildItemRow declares a project, target or task: its icon, name and detail. A click chooses
// it, in its build system, which it selects first, and a click on the row already chosen lets
// it go; a double click runs a task or a target's first run, and opens a project's build file.
// The chosen target or task has the button that runs it, and a target whose first run debugs
// the button that debugs it.
func (a *App) buildItemRow(row ui.ListRow, p *project, instance *buildInstance, spec buildRow) {
c, b := row.C, &p.build
element := a.buildTreeRowElement(row, spec)
// buildDetailShrink is how much faster than its name a row's detail gives way when the row is
// too narrow for both: the path goes first, and the name gives way only once the path is gone.
const buildDetailShrink = 1000

// buildRunMark declares the green triangle that leads a row that runs, in the place of its
// kind's icon, as IntelliJ's Make window marks every target it runs, and reports a click on
// it. label names what the click starts, for its hover hint and for assistive technology.
// While a build operation runs or the model loads, the triangle is dimmed and takes no click,
// and a click there falls to the row.
func (a *App) buildRunMark(c ui.C, label string, disabled bool) bool {
k := c.Part("run")
// As wide as the icons of the rows beside it, so the names line up.
slot := ui.Row(k).Size(14, treelist.Icon).Shrink(0).Center()
if disabled {
slot.Children(func() {
ui.Icon(k, icons.Play).Size(14, 14).Color(a.colors.Subtle).Opacity(0.5)
})
return false
}
slot = slot.HitWith(ui.ID(k), label, gfx.HitOptions{Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand, SkipFocus: true}).Tooltip(label)
slot.Children(func() {
ui.Icon(k, icons.Play).Size(14, 14).Color(a.colors.Success)
})
return slot.Clicked()
}

// buildItemTip is the hover hint of a project, target or task row: its whole name and, under
// it, its whole detail, which a narrow window cuts short; or the row's own tooltip, the full
// name of a target that shows only its path (buildTargetLabel).
func buildItemTip(spec buildRow) string {
if spec.tooltip != "" {
element = element.Tooltip(spec.tooltip)
return spec.tooltip
}
ui.Row(c.Part("arrow")).Size(treelist.Disclosure, treelist.Icon).Shrink(0)
if icon := buildItemIcons[spec.kind]; icon != nil {
ui.Icon(c, *icon).Size(14, 14).Shrink(0).Color(a.colors.Subtle)
if spec.detail == "" || spec.detail == spec.label {
return spec.label
}
ui.Text(c, spec.label).FontSize(treeFontSize).Color(treelist.Text(a.colors.Dark)).Ellipsis().Shrink(0).MaxWidth(320)
if spec.detail != "" {
ui.Text(c, spec.detail).FontSize(treeFontSize - 1).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0)
return spec.label + "\n" + spec.detail
}

// buildItemRow declares a project, target or task: its icon, name and detail. A task, and a
// target that has a run, lead with the green triangle that runs it; the others lead with the
// icon of their kind. A click chooses the row, in its build system, which it selects first,
// and a click on the row already chosen lets it go; a double click runs a task or a target's
// first run, and opens a project's build file. The chosen target whose first run debugs has
// the button that debugs it. When the row is too narrow, the detail gives way before the
// name, and the hover hint shows both whole.
func (a *App) buildItemRow(row ui.ListRow, p *project, instance *buildInstance, spec buildRow) {
c, b := row.C, &p.build
element := a.buildTreeRowElement(row, spec)
if tip := buildItemTip(spec); tip != "" {
element = element.Tooltip(tip)
}
ui.Spacer(c)
busy := b.operation != nil || instance.modelLoading
index := spec.instance
// choose makes the row the window's choice; run, when set, then starts what it runs.
Expand All @@ -444,7 +484,8 @@ func (a *App) buildItemRow(row ui.ListRow, p *project, instance *buildInstance,
runLabel := ""
switch spec.kind {
case buildRowTask:
runLabel = i18n.Shared(a.language(), "desktop.runConfig.run")
// Every task row has its triangle, so each names its own task.
runLabel = a.text.Build.RunTarget(spec.label)
run = func() { a.runSelectedBuildTask(p) }
case buildRowTarget:
if action, ok := buildPrimaryAction(instance, spec.target); ok {
Expand All @@ -456,14 +497,24 @@ func (a *App) buildItemRow(row ui.ListRow, p *project, instance *buildInstance,
}
}
}
if spec.selected && run != nil && a.gitIconButton(c.Part("run"), runLabel, icons.Play, false, busy) {
c.After(func() {
a.performed("build.item.run", surfaceButton)
choose()
run()
a.showBuildConsole(p)
})
ui.Row(c.Part("arrow")).Size(treelist.Disclosure, treelist.Icon).Shrink(0)
if run != nil {
if a.buildRunMark(c, runLabel, busy) {
c.After(func() {
a.performed("build.item.run", surfaceButton)
choose()
run()
a.showBuildConsole(p)
})
}
} else if icon := buildItemIcons[spec.kind]; icon != nil {
ui.Icon(c, *icon).Size(14, 14).Shrink(0).Color(a.colors.Subtle)
}
ui.Text(c, spec.label).FontSize(treeFontSize).Color(treelist.Text(a.colors.Dark)).Ellipsis().Shrink(1).MinWidth(0)
if spec.detail != "" {
ui.Text(c, spec.detail).FontSize(treeFontSize - 1).Color(a.colors.Subtle).Ellipsis().Shrink(buildDetailShrink).MinWidth(0)
}
ui.Spacer(c)
if spec.selected && debug != nil && a.gitIconButton(c.Part("debug"), i18n.Shared(a.language(), "desktop.build.debugTarget"), icons.Bug, false, busy || p.debug.preparing) {
c.After(func() {
a.performed("build.target.debug", surfaceButton)
Expand Down
4 changes: 4 additions & 0 deletions desktop/internal/workbench/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestRepeatedNoticesAreOneEntryWithACount(t *testing.T) {
h.app.notify("Index ready")
clock = clock.Add(time.Minute)
h.app.notify("Build failed")
// The notices came outside a frame: ask for the repaint the window would make.
h.app.invalidator.Invalidate()
h.settle()

list := h.app.notifications.list
Expand All @@ -46,6 +48,7 @@ func TestNotificationBellOpensReadsAndClearsTheHistory(t *testing.T) {
h.open(t.TempDir())
h.app.notify("Plugin updated")
h.app.notify("Index ready")
h.app.invalidator.Invalidate()
h.settle()

h.clickNamed("Notifications, 2 unread")
Expand Down Expand Up @@ -88,6 +91,7 @@ func TestNoticesKeepTheirKindAndShowAtMostThreeToasts(t *testing.T) {
h.app.notifySuccess("Sync")
h.app.notifyInfo("Index ready")
h.app.notify("Disk almost full")
h.app.invalidator.Invalidate()
h.settle()

list := h.app.notifications.list
Expand Down
1 change: 1 addition & 0 deletions docs/assets/build-panels/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| --- | --- | --- |
| 右侧构建窗口(运行配置列表和聚合构建树)与底部运行窗口(只显示构建控制台) | [截图](build-and-run-dark.png) | [截图](build-and-run-light.png) |
| 构建窗口按名称筛选 | [截图](build-filter-dark.png) | [截图](build-filter-light.png) |
| Go 模块的目标以完整导入路径命名,行上只显示所在目录:可运行的目标和任务行首是绿色运行按钮,依赖标题旁有 ⓘ | [截图](build-go-targets-dark.png) | [截图](build-go-targets-light.png) |

复验:设置 `LITHE_VISUAL_OUTPUT_DIR`,通过 `scripts/desktop/desktop-go.sh test
-tags vivahead,lithevisual ./internal/workbench -run '^TestVisualBuildPanels'
Expand Down
Binary file modified docs/assets/build-panels/build-and-run-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/build-panels/build-and-run-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/build-panels/build-filter-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/build-panels/build-filter-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions shared/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -10997,6 +10997,7 @@
"desktop.terminal.runSelection": "Run Selection in Terminal",
"desktop.build.debugTarget": "Debug",
"desktop.build.filter": "Filter build systems, tasks and targets",
"desktop.build.dependenciesHelp": "The build tool reads the dependency tree only when this is first opened, which can take a while as the tool runs. The tree is then kept until the build systems are detected again or Reload is chosen on the build system or on Dependencies.",
"desktop.build.noMatches": "No matching build items",
"desktop.build.noDebugAdapter": "The build provider's own plugin declares no debug adapter that can start a prepared program.",
"desktop.debug.consoleEmpty": "The debug session's output appears here.",
Expand Down
1 change: 1 addition & 0 deletions shared/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -10997,6 +10997,7 @@
"desktop.terminal.runSelection": "在终端运行选中内容",
"desktop.build.debugTarget": "调试",
"desktop.build.filter": "筛选构建系统、任务与目标",
"desktop.build.dependenciesHelp": "第一次展开时才让构建工具读取依赖树,构建工具运行期间可能要等一会儿。读到的依赖会一直保留,直到重新检测构建系统,或在构建系统或“依赖”上选“重新加载”。",
"desktop.build.noMatches": "没有匹配的构建项",
"desktop.build.noDebugAdapter": "该构建插件所属的插件没有声明可以启动已准备程序的调试适配器。",
"desktop.debug.consoleEmpty": "调试会话的输出会显示在这里。",
Expand Down
7 changes: 7 additions & 0 deletions shared/i18n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6610,6 +6610,13 @@
"desktop"
]
},
{
"id": "desktop.build.dependenciesHelp",
"description": "Hover hint of the information button on the Build window's Dependencies heading: when the dependency tree is read and how to read it again",
"platforms": [
"desktop"
]
},
{
"id": "desktop.build.noMatches",
"description": "Build tool window text when no build system, project, target, task or test matches the filter",
Expand Down

Large diffs are not rendered by default.

Loading