From d407a7664001757c30ab4983b94404e9e29e8d2b Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sat, 14 Nov 2026 23:41:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(desktop):=20Run=20=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=8C=89=20IDEA=20=E6=A0=B7=E5=BC=8F=E4=B8=BA=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E6=89=A7=E8=A1=8C=E5=BC=80=E6=A0=87=E7=AD=BE=EF=BC=8C?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=8C=89=20ANSI=20=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E7=9D=80=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run 窗口改成 IntelliJ IDEA 的布局:标题“运行”后面是每次执行一个标签(状态图标、名称、结束后的关闭按钮), 左侧竖排工具栏是绿色的再次运行和红色的停止,执行树显示状态、粗体名称、开始时间和右对齐耗时,右侧控制台 带滚动到末尾和清空。宿主构建任务、运行配置和插件发起的运行都进 Run 窗口,Build 窗口不再内嵌运行输出。 控制台输出经 Rust Core 的 outputStyle.decode 解码为纯文本行和着色区间,在读取输出的 goroutine 上分片调用; 纯文本供复制、搜索、输出链接、快照和 IDE API,样式按终端同一套 16 色配色绘制。运行、构建和测试控制台跟随 最新输出,向上滚动后停止跟随。Core 固定到 Lithe-core-rust #44 的 cdc0258(合入后改为 main 上的 commit)。 --- desktop/internal/core/output_style.go | 77 +++++ desktop/internal/core/output_style_test.go | 78 +++++ desktop/internal/i18n/i18n_test.go | 24 ++ desktop/internal/i18n/run_messages.go | 53 +++- desktop/internal/i18n/shared.generated.go | 26 +- desktop/internal/termview/palette.go | 6 + desktop/internal/workbench/app.go | 1 + desktop/internal/workbench/build.go | 205 ++++++------ .../internal/workbench/build_menus_test.go | 4 +- .../workbench/build_panels_visual_test.go | 40 ++- desktop/internal/workbench/build_test.go | 33 +- desktop/internal/workbench/build_tree_test.go | 2 +- desktop/internal/workbench/build_view.go | 161 +--------- .../internal/workbench/context_menu_test.go | 8 +- desktop/internal/workbench/editor_view.go | 3 + .../internal/workbench/ide_api_dispatch.go | 26 +- .../workbench/ide_api_operation_test.go | 13 +- desktop/internal/workbench/output_style.go | 225 +++++++++++++ desktop/internal/workbench/outputlinks.go | 55 ---- .../internal/workbench/outputlinks_test.go | 82 +++-- .../internal/workbench/outputlinks_view.go | 251 ++++++++++++--- desktop/internal/workbench/run_panels_test.go | 14 +- desktop/internal/workbench/run_view.go | 299 ++++++++++++++++++ desktop/internal/workbench/run_view_test.go | 71 +++++ desktop/internal/workbench/runconfig.go | 8 +- desktop/internal/workbench/runpanels.go | 8 +- desktop/internal/workbench/runs.go | 256 ++++++++++----- .../workbench/settings_plugin_effects_test.go | 6 +- desktop/internal/workbench/shell_view.go | 10 +- desktop/internal/workbench/tests.go | 53 ++-- desktop/internal/workbench/tests_test.go | 15 +- desktop/internal/workbench/tests_view.go | 12 +- scripts/desktop/build-desktop-core.sh | 7 +- shared/i18n/locales/en-US.json | 12 +- shared/i18n/locales/zh-CN.json | 12 +- shared/i18n/messages.json | 95 +++++- .../features/debug-performance.json | 4 +- .../features/plugin-backend-run-start.json | 6 +- .../features/run-console-ansi-styles.json | 47 +++ .../features/run-output-snapshot.json | 4 +- .../features/run-window-execution-tabs.json | 41 +++ 41 files changed, 1767 insertions(+), 586 deletions(-) create mode 100644 desktop/internal/core/output_style.go create mode 100644 desktop/internal/core/output_style_test.go create mode 100644 desktop/internal/workbench/output_style.go create mode 100644 desktop/internal/workbench/run_view.go create mode 100644 desktop/internal/workbench/run_view_test.go create mode 100644 shared/platform-feature-matrix/features/run-console-ansi-styles.json create mode 100644 shared/platform-feature-matrix/features/run-window-execution-tabs.json diff --git a/desktop/internal/core/output_style.go b/desktop/internal/core/output_style.go new file mode 100644 index 0000000000..3cf97b9178 --- /dev/null +++ b/desktop/internal/core/output_style.go @@ -0,0 +1,77 @@ +package core + +import ( + "context" + "encoding/json" +) + +// OutputColor is one colour of a styled output range: a palette entry +// (0-15 follow the theme, 16-255 the xterm cube and grey ramp) or a +// "#rrggbb" colour. +type OutputColor struct { + Index *int `json:"index,omitempty"` + RGB string `json:"rgb,omitempty"` +} + +// OutputStyle is how a range of console output is drawn. Unset colours are the +// console's own. +type OutputStyle struct { + Foreground *OutputColor `json:"foreground,omitempty"` + Background *OutputColor `json:"background,omitempty"` + Bold bool `json:"bold,omitempty"` + Dim bool `json:"dim,omitempty"` + Italic bool `json:"italic,omitempty"` + Underline bool `json:"underline,omitempty"` + Inverse bool `json:"inverse,omitempty"` + Hidden bool `json:"hidden,omitempty"` + Strikethrough bool `json:"strikethrough,omitempty"` +} + +// OutputSpan styles Length UTF-16 code units of a line from Start. Spans are +// ascending and never overlap; text outside every span is plain. +type OutputSpan struct { + Start int `json:"start"` + Length int `json:"length"` + Style OutputStyle `json:"style"` +} + +// OutputLine is one line of console output with its escapes removed. +type OutputLine struct { + Text string `json:"text"` + Spans []OutputSpan `json:"spans,omitempty"` +} + +// OutputStyleDecoding is Core's answer for one chunk of console output. +type OutputStyleDecoding struct { + // Lines are the lines the chunk finished, oldest first; the first one + // continues the previous answer's Open line. + Lines []OutputLine + // Open is the line still being written, shown after Lines. + Open OutputLine + // State is passed back unchanged with the console's next chunk. + State json.RawMessage +} + +// DecodeOutputStyle turns one chunk of console output with ANSI escapes into +// plain lines and styled ranges. state is the State of the previous answer for +// the same console, or nil for its first chunk; chunks are at most 1 MiB. +func (c *Client) DecodeOutputStyle(ctx context.Context, text string, state json.RawMessage) (OutputStyleDecoding, error) { + request := struct { + Text string `json:"text"` + State json.RawMessage `json:"state,omitempty"` + }{Text: text, State: state} + var response struct { + Lines []OutputLine `json:"lines"` + State json.RawMessage `json:"state"` + } + if err := c.Execute(ctx, "outputStyle.decode", request, &response); err != nil { + return OutputStyleDecoding{}, err + } + var open struct { + Line OutputLine `json:"line"` + } + if err := json.Unmarshal(response.State, &open); err != nil { + return OutputStyleDecoding{}, err + } + return OutputStyleDecoding{Lines: response.Lines, Open: open.Line, State: response.State}, nil +} diff --git a/desktop/internal/core/output_style_test.go b/desktop/internal/core/output_style_test.go new file mode 100644 index 0000000000..d88472ee1d --- /dev/null +++ b/desktop/internal/core/output_style_test.go @@ -0,0 +1,78 @@ +package core + +import ( + "context" + "encoding/json" + "os" + "reflect" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" +) + +// TestDecodeOutputStyleFollowsTheCoreFixture replays every case of the shared +// fixture through the client, passing each answer's state to the next chunk: +// Core decides the text and ranges, the client only carries them. +func TestDecodeOutputStyleFollowsTheCoreFixture(t *testing.T) { + data, err := os.ReadFile(contractfixture.CoreFixture("terminal/output-style-v1.json")) + if err != nil { + t.Fatal(err) + } + var fixture struct { + Cases []struct { + Name string `json:"name"` + Chunks []string `json:"chunks"` + Lines []OutputLine `json:"lines"` + Open OutputLine `json:"open"` + } `json:"cases"` + } + if err := json.Unmarshal(data, &fixture); err != nil { + t.Fatal(err) + } + if len(fixture.Cases) == 0 { + t.Fatal("the fixture has no cases") + } + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + client := NewClient() + for _, test := range fixture.Cases { + t.Run(test.Name, func(t *testing.T) { + var state json.RawMessage + lines := []OutputLine{} + var open OutputLine + for _, chunk := range test.Chunks { + decoded, err := client.DecodeOutputStyle(ctx, chunk, state) + if err != nil { + t.Fatal(err) + } + lines = append(lines, decoded.Lines...) + open, state = decoded.Open, decoded.State + } + want := test.Lines + if want == nil { + want = []OutputLine{} + } + if !reflect.DeepEqual(lines, want) { + got, _ := json.Marshal(lines) + expected, _ := json.Marshal(want) + t.Fatalf("lines = %s, want %s", got, expected) + } + if !reflect.DeepEqual(open, test.Open) { + got, _ := json.Marshal(open) + expected, _ := json.Marshal(test.Open) + t.Fatalf("open = %s, want %s", got, expected) + } + }) + } +} + +// TestDecodeOutputStyleRejectsAForeignState: a state Core never returned is an +// invalid request, so a console cannot carry another console's or a stale state. +func TestDecodeOutputStyleRejectsAForeignState(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + if _, err := NewClient().DecodeOutputStyle(ctx, "x", json.RawMessage(`{"line":{"text":"ab","spans":[{"start":1,"length":5,"style":{"bold":true}}]}}`)); err == nil { + t.Fatal("a state whose range runs past its line was accepted") + } +} diff --git a/desktop/internal/i18n/i18n_test.go b/desktop/internal/i18n/i18n_test.go index 259421d05d..13470a529b 100644 --- a/desktop/internal/i18n/i18n_test.go +++ b/desktop/internal/i18n/i18n_test.go @@ -374,3 +374,27 @@ func TestParseRoundTrips(t *testing.T) { t.Error("Parse accepts an unsupported code") } } + +// A run's duration is milliseconds under a second, then seconds and milliseconds, then minutes +// and seconds, then hours and minutes; a clock that steps back reads as no time. +func TestRunDurationPicksTheLargestTwoUnits(t *testing.T) { + for _, test := range []struct { + language Language + milliseconds int + want string + }{ + {English, -5, "0 ms"}, + {English, 999, "999 ms"}, + {English, 1632, "1 s 632 ms"}, + {English, 61_000, "1 min 1 s"}, + {English, 3_725_000, "1 h 2 min"}, + {Chinese, 999, "999毫秒"}, + {Chinese, 1632, "1秒632毫秒"}, + {Chinese, 61_000, "1分1秒"}, + {Chinese, 3_725_000, "1小时2分"}, + } { + if got := For(test.language).Run.Duration(test.milliseconds); got != test.want { + t.Errorf("language %s, %d ms: duration %q, want %q", test.language.Code(), test.milliseconds, got, test.want) + } + } +} diff --git a/desktop/internal/i18n/run_messages.go b/desktop/internal/i18n/run_messages.go index 7244a84785..dac6fa623b 100644 --- a/desktop/internal/i18n/run_messages.go +++ b/desktop/internal/i18n/run_messages.go @@ -1,15 +1,21 @@ package i18n -import "strconv" +import ( + "strconv" + "time" +) -// RunMessages are the words of the plugin-started run entries shown beside the -// build output. +// RunMessages are the words of the Run tool window: its execution tabs, tree and console. type RunMessages struct { - Build string Rerun string Ended string LinkMissing string LinkUnresolved string + // CloseSession closes the tab of a finished execution; Empty is the window before anything ran. + CloseSession string + Empty string + // Running, Succeeded, Failed and Stopped name where an execution stands, beside its icon. + Running, Succeeded, Failed, Stopped string // Snapshot words the output snapshot of a run (run_snapshot_messages.go). Snapshot RunSnapshotMessages // Performance words the CPU and memory readings of a run (run_performance_messages.go). @@ -18,15 +24,25 @@ type RunMessages struct { Exited func(code int) string // Signalled reports a process ended by a signal. Signalled func(signal string) string + // StartedAt follows an execution's name in the tree with when it started, already formatted. + StartedAt func(time string) string + // Duration is how long an execution took, given in milliseconds: seconds and milliseconds + // under a minute, then minutes and seconds, then hours and minutes. + Duration func(milliseconds int) string } func runMessages(language Language) RunMessages { return RunMessages{ - Build: Shared(language, "desktop.run.build"), Rerun: Shared(language, "desktop.run.rerun"), Ended: Shared(language, "desktop.run.ended"), LinkMissing: Shared(language, "desktop.run.linkMissing"), LinkUnresolved: Shared(language, "desktop.run.linkUnresolved"), + CloseSession: Shared(language, "desktop.run.closeSession"), + Empty: Shared(language, "desktop.run.empty"), + Running: Shared(language, "desktop.run.statusRunning"), + Succeeded: Shared(language, "desktop.run.statusSucceeded"), + Failed: Shared(language, "desktop.run.statusFailed"), + Stopped: Shared(language, "desktop.run.statusStopped"), Snapshot: runSnapshotMessages(language), Performance: runPerformanceMessages(language), Exited: func(code int) string { @@ -35,5 +51,32 @@ func runMessages(language Language) RunMessages { Signalled: func(signal string) string { return SharedFormat(language, "desktop.run.signalled", map[string]string{"signal": signal}) }, + StartedAt: func(time string) string { + return SharedFormat(language, "desktop.run.startedAt", map[string]string{"time": time}) + }, + Duration: func(milliseconds int) string { + return runDuration(language, time.Duration(milliseconds)*time.Millisecond) + }, + } +} + +func runDuration(language Language, elapsed time.Duration) string { + elapsed = max(elapsed, 0) + count := func(value time.Duration) string { return strconv.FormatInt(int64(value), 10) } + switch { + case elapsed < time.Second: + return SharedFormat(language, "desktop.run.durationMilliseconds", map[string]string{"milliseconds": count(elapsed / time.Millisecond)}) + case elapsed < time.Minute: + return SharedFormat(language, "desktop.run.durationSeconds", map[string]string{ + "seconds": count(elapsed / time.Second), "milliseconds": count(elapsed % time.Second / time.Millisecond), + }) + case elapsed < time.Hour: + return SharedFormat(language, "desktop.run.durationMinutes", map[string]string{ + "minutes": count(elapsed / time.Minute), "seconds": count(elapsed % time.Minute / time.Second), + }) + default: + return SharedFormat(language, "desktop.run.durationHours", map[string]string{ + "hours": count(elapsed / time.Hour), "minutes": count(elapsed % time.Hour / time.Minute), + }) } } diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index a5795b26ea..70dcd1aea8 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1142,7 +1142,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.refs.rebased": "Rebased the current branch onto {branch}", "desktop.refs.trackingSet": "{branch} now tracks {upstream}", "desktop.refs.trackingStopped": "{branch} no longer tracks a remote branch", - "desktop.run.build": "Build", + "desktop.run.closeSession": "Close", + "desktop.run.durationHours": "{hours} h {minutes} min", + "desktop.run.durationMilliseconds": "{milliseconds} ms", + "desktop.run.durationMinutes": "{minutes} min {seconds} s", + "desktop.run.durationSeconds": "{seconds} s {milliseconds} ms", + "desktop.run.empty": "Output of run configurations and build tasks appears here.", "desktop.run.ended": "Process finished.", "desktop.run.exited": "Process finished with exit code {code}.", "desktop.run.linkMissing": "The linked file was not found in the workspace.", @@ -1153,6 +1158,11 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.signalled": "Process stopped by signal {signal}.", "desktop.run.snapshot.menu": "Snapshot output", "desktop.run.snapshot.tab": "{label} (snapshot)", + "desktop.run.startedAt": ": at {time}", + "desktop.run.statusFailed": "Failed", + "desktop.run.statusRunning": "Running", + "desktop.run.statusStopped": "Stopped", + "desktop.run.statusSucceeded": "Succeeded", "desktop.runConfig.arguments": "Program arguments", "desktop.runConfig.argumentsPlaceholder": "Separate with spaces; quote values that contain spaces", "desktop.runConfig.conflict": "The file changed on disk while saving. Close the editor, reopen it and try again.", @@ -1677,6 +1687,7 @@ var sharedCatalogs = map[string]map[string]string{ "git.conflictedFiles": "Stopped with {count} conflicted files. Resolve them in the changes list, then continue.", "git.conflictsResolved": "All conflicts resolved. Continue to finish, or abort to undo.", "git.console.cancel": "Cancel running operations", + "git.console.clear": "Clear", "git.console.closeSearch": "Close search", "git.console.copyCommand": "Copy command", "git.console.copyOutput": "Copy output", @@ -3684,7 +3695,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.refs.rebased": "已把当前分支变基到 {branch}", "desktop.refs.trackingSet": "{branch} 现在跟踪 {upstream}", "desktop.refs.trackingStopped": "{branch} 不再跟踪远程分支", - "desktop.run.build": "构建", + "desktop.run.closeSession": "关闭", + "desktop.run.durationHours": "{hours}小时{minutes}分", + "desktop.run.durationMilliseconds": "{milliseconds}毫秒", + "desktop.run.durationMinutes": "{minutes}分{seconds}秒", + "desktop.run.durationSeconds": "{seconds}秒{milliseconds}毫秒", + "desktop.run.empty": "运行配置和构建任务的输出将显示在这里。", "desktop.run.ended": "进程已结束。", "desktop.run.exited": "进程已结束,退出码 {code}。", "desktop.run.linkMissing": "在工作区中找不到链接指向的文件。", @@ -3695,6 +3711,11 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.signalled": "进程被信号 {signal} 终止。", "desktop.run.snapshot.menu": "快照当前输出", "desktop.run.snapshot.tab": "{label}(快照)", + "desktop.run.startedAt": ": 在 {time}", + "desktop.run.statusFailed": "失败", + "desktop.run.statusRunning": "正在运行", + "desktop.run.statusStopped": "已停止", + "desktop.run.statusSucceeded": "成功", "desktop.runConfig.arguments": "程序参数", "desktop.runConfig.argumentsPlaceholder": "以空格分隔;含空格的值请加引号", "desktop.runConfig.conflict": "保存期间文件已在磁盘上被修改,请关闭编辑器重新打开后再试。", @@ -4219,6 +4240,7 @@ var sharedCatalogs = map[string]map[string]string{ "git.conflictedFiles": "已停止,有 {count} 个冲突文件。请在更改列表中解决后继续。", "git.conflictsResolved": "所有冲突已解决。继续完成,或中止以撤销。", "git.console.cancel": "取消正在运行的操作", + "git.console.clear": "清空", "git.console.closeSearch": "关闭查找", "git.console.copyCommand": "复制完整命令", "git.console.copyOutput": "复制完整输出", diff --git a/desktop/internal/termview/palette.go b/desktop/internal/termview/palette.go index 62fd1331f5..f942a6bc47 100644 --- a/desktop/internal/termview/palette.go +++ b/desktop/internal/termview/palette.go @@ -61,6 +61,12 @@ func newPalette(look Look, epoch uint32) palette { return pal } +// ANSI is the 16 ANSI colors the terminal draws with in look, for consoles outside the terminal +// view that color their output the same way. +func (look Look) ANSI() [16][3]uint8 { + return newPalette(look, 0).ansi +} + // nativeContrast is the least contrast, by WCAG 2's ratio, a color of the system terminal's // profile needs against the background to replace the built-in one: the AA level for text. const nativeContrast = 4.5 diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index c15222fbc8..e5cff3f58a 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -89,6 +89,7 @@ type Kernel interface { processExitKernel processMemoryKernel MatchOutputLinks(context.Context, core.OutputLinkRequest) ([]core.OutputLink, error) + DecodeOutputStyle(ctx context.Context, text string, state json.RawMessage) (core.OutputStyleDecoding, error) CreateDebugSession(ctx context.Context, request core.DebugCreateSessionRequest) (core.DebugUpdate, error) LaunchDebug(ctx context.Context, sessionID, operationID string, configuration core.DebugLaunchConfiguration) (core.DebugUpdate, error) NormalizeSteppingFilters(ctx context.Context, adapterID string, filters core.DebugSteppingFilters) (core.DebugSteppingFilters, error) diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index 5f81b9555b..51e1c6f573 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -11,10 +11,10 @@ import ( "path/filepath" "runtime" "slices" + "strconv" "strings" "sync" "time" - "unicode/utf8" "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" "github.com/1lck/Lithe-IDEA/desktop/internal/buildprovider" @@ -30,7 +30,6 @@ const ( buildRequestTimeout = 30 * time.Minute buildStopTimeout = 15 * time.Second buildOutputMaxLines = 4000 - buildOutputLineSize = 16 << 10 buildOutputBytes = 4 << 20 ) @@ -47,16 +46,8 @@ type buildState struct { // reloadPending says a stored option changed while a detection was running, so the instances are // detected again when that detection ends. reloadPending bool - // status is the last result line under the output. + // status is the last result line of the current or latest execution. status string - // output is bounded and stores whole lines; the oldest lines go first. - output []string - // outputBytes is the current size of output, so trimming stays cheap. - outputBytes int - // outputStart is the sequence number of output[0] and outputSequence counts the - // lines ever appended. An IDE operation reads from the sequence it started at, so a - // trimmed console reports a reset instead of silently skipping lines. - outputStart, outputSequence int instances []buildInstance selected int @@ -65,10 +56,12 @@ type buildState struct { taskID string operation *buildOperation - // runs are the plugin-started runs the panel keeps beside the build console, - // and view is the one it shows: "" for the build console, else a run's ID. - runs []*runEntry - view string + // runs are the Run window's sessions, oldest first: the host's executions and the + // runs plugins started. view is the ID of the one it shows, and sessions numbers the + // host's executions. + runs []*runEntry + view string + sessions int // generation rejects a detection or model load that a newer one replaced. generation uint64 // dependencies are the loaded dependency trees by instance and project @@ -113,20 +106,46 @@ type buildOperation struct { stopped chan struct{} // ide is the execution's IDE API identity and state (ide_api_dispatch.go). ide *ideAPIOperation + // session is the execution's tab in the Run window, which holds its console. + session *runEntry + // decoder decodes the execution's output on the goroutines that read it. + decoder *outputDecoder } // beginBuildOperation makes a new operation the window's current one and gives it the IDE // identity of the execution. kind is "build" for a task and "run" for an application run; -// label names it in the operations list. Every path that follows ends it with -// finishBuildTask, finishBuildRun or finishBuildError for this operation. -func (a *App) beginBuildOperation(p *project, kind, label, configuration string) *buildOperation { - operation := &buildOperation{configuration: configuration, stopped: make(chan struct{})} +// label names it in the operations list and on its Run window tab, and restart starts it again +// from that tab. Every path that follows ends it with finishBuildTask, finishBuildRun or +// finishBuildError for this operation. +func (a *App) beginBuildOperation(p *project, kind, label, configuration string, restart func(*App, *project)) *buildOperation { + operation := &buildOperation{configuration: configuration, stopped: make(chan struct{}), decoder: newOutputDecoder(a.kernel)} + p.build.sessions++ + operation.session = &runEntry{ + id: "build-" + strconv.Itoa(p.build.sessions), label: label, restart: restart, operation: operation, + running: true, started: a.now(), output: newOutputBuffer(buildOutputMaxLines, buildOutputBytes), + } + a.addRunSession(p, operation.session) operation.ide = p.recordIDEOperation(kind, label, configuration) + operation.ide.output = &operation.session.output p.build.operation = operation p.build.status = a.text.Build.Preparing return operation } +// restartWithInstance is a session's restart that selects the build instance it ran under +// again, by ID, before start runs it; an instance that is gone starts nothing. +func restartWithInstance(instanceID string, start func(a *App, p *project)) func(*App, *project) { + return func(a *App, p *project) { + index := slices.IndexFunc(p.build.instances, func(instance buildInstance) bool { return instance.ID == instanceID }) + if index < 0 { + a.notifyError(a.text.Build.TargetMissing) + return + } + p.build.selected = index + start(a, p) + } +} + // bind returns ctx ending also when the operation is stopped, so the kernel and provider calls // that prepare the execution end at once. A host process is not started with it: Stop ends a // process through its own termination. The preparing goroutine calls cancel when it is done. @@ -889,7 +908,10 @@ func (a *App) runBuildTask(p *project, projectID, targetID, taskID string, userA captured := *instance kernel := a.kernel messages := a.text.Build - op := a.beginBuildOperation(p, "build", ideAPIBuildLabel(instance, taskID), "") + userArguments = append([]string(nil), userArguments...) + op := a.beginBuildOperation(p, "build", ideAPIBuildLabel(instance, taskID), "", restartWithInstance(instance.ID, func(a *App, p *project) { + _, _ = a.runBuildTask(p, projectID, targetID, taskID, userArguments) + })) a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { prepare, release := op.bind(ctx) defer release() @@ -929,7 +951,7 @@ func (a *App) runCommandTask(ctx, prepare context.Context, p *project, op *build WorkingDirectory: workingDirectory, Environment: applyToolchainSelection(plan.Environment, execution.selection()), }, func(_ buildprocess.Stream, text string) { - a.post(func(a *App) { a.appendBuildOutput(p, op, text) }) + a.streamBuildOutput(p, op, text) }) if err != nil { return err @@ -1123,7 +1145,9 @@ func (a *App) runBuildEntry(p *project, entryID string) { captured := *instance messages := a.text.Build a.emit(core.LevelInfo, "app.action.performed", map[string]any{"action": "build.runEntry", "surface": "build"}) - op := a.beginBuildOperation(p, "run", entry.Name, "") + op := a.beginBuildOperation(p, "run", entry.Name, "", restartWithInstance(instance.ID, func(a *App, p *project) { + a.runBuildEntry(p, entryID) + })) a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { prepare, release := op.bind(ctx) defer release() @@ -1146,7 +1170,9 @@ func (a *App) runBuildTarget(p *project, targetID, runID string) { a.notifyError(a.text.Build.TargetMissing) return } - op := a.beginBuildOperation(p, "run", target.Name, "") + op := a.beginBuildOperation(p, "run", target.Name, "", restartWithInstance(instance.ID, func(a *App, p *project) { + a.runBuildTarget(p, targetID, runID) + })) a.runBuildTargetWith(p, op, instance, target.ProjectID, targetID, runID, nil) } @@ -1398,7 +1424,7 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build WorkingDirectory: workingDirectory, Environment: applyToolchainSelection(launch.Environment, execution.selection()), }, func(_ buildprocess.Stream, text string) { - a.post(func(a *App) { a.appendBuildOutput(p, op, text) }) + a.streamBuildOutput(p, op, text) }) if err != nil { return func(a *App) { a.finishBuildError(p, op, err) } @@ -1447,7 +1473,7 @@ func (a *App) runProviderOperation(ctx, prepare context.Context, p *project, op } if progress.Output != "" { sawProgress = true - a.post(func(a *App) { a.appendBuildOutput(p, op, progress.Output) }) + a.streamBuildOutput(p, op, progress.Output) } if progress.Message != "" { a.post(func(a *App) { @@ -1472,24 +1498,46 @@ done: Output string `json:"output"` } if json.Unmarshal(result, &execution) == nil && execution.Output != "" { - a.post(func(a *App) { a.appendBuildOutput(p, op, execution.Output) }) + a.streamBuildOutput(p, op, execution.Output) } } a.post(func(a *App) { a.finishBuildTask(p, op, result) }) } -// endBuildOperation clears op as the window's operation and settles its IDE state. It reports -// false when op is no longer the window's operation: a closed project or a plugin change already -// detached and settled it, and its late terminal event changes nothing. -func (a *App) endBuildOperation(p *project, op *buildOperation, state string, exitCode *int, failure string) bool { +// endBuildOperation clears op as the window's operation, records how it ended in its session and +// settles its IDE state; status is the window's last line about it. It reports false when op is +// no longer the window's operation: a closed project or a plugin change already detached and +// settled it, and its late terminal event changes nothing. +func (a *App) endBuildOperation(p *project, op *buildOperation, state string, exitCode *int, failure, status string) bool { if a.project != p || p.build.operation != op { return false } p.build.operation = nil - op.ide.settle(state, exitCode, p.build.outputSequence, failure) + p.build.status = status + a.endBuildSession(op, state, status) + op.ide.settle(state, exitCode, op.session.output.sequence, failure) return true } +// endBuildSession records in op's session that the execution ended in state, the IDE API's +// "completed", "failed" or "cancelled", with status as its summary. +func (a *App) endBuildSession(op *buildOperation, state, status string) { + session := op.session + if session == nil || !session.running { + return + } + session.output.seal() + session.running, session.operation, session.ended, session.summary = false, nil, a.now(), status + switch state { + case "completed": + session.outcome = runSucceeded + case "cancelled": + session.outcome = runStopped + default: + session.outcome = runFailed + } +} + // finishBuildTask ends a provider task with its result. A stopped task is cancelled whatever // the provider answered; a result without an exit code completes with a null one. func (a *App) finishBuildTask(p *project, op *buildOperation, result json.RawMessage) { @@ -1500,17 +1548,11 @@ func (a *App) finishBuildTask(p *project, op *buildOperation, result json.RawMes code := execution.ExitCode switch { case op.cancelled: - if a.endBuildOperation(p, op, "cancelled", code, "") { - p.build.status = a.text.Build.Cancelled - } + a.endBuildOperation(p, op, "cancelled", code, "", a.text.Build.Cancelled) case code != nil && *code != 0: - if a.endBuildOperation(p, op, "failed", code, "") { - p.build.status = a.text.Build.Exited(*code) - } + a.endBuildOperation(p, op, "failed", code, "", a.text.Build.Exited(*code)) default: - if a.endBuildOperation(p, op, "completed", code, "") { - p.build.status = a.text.Build.Succeeded - } + a.endBuildOperation(p, op, "completed", code, "", a.text.Build.Succeeded) } } @@ -1520,23 +1562,15 @@ func (a *App) finishBuildRun(p *project, op *buildOperation, err error) { var exit *exec.ExitError switch { case op.cancelled: - if a.endBuildOperation(p, op, "cancelled", nil, "") { - p.build.status = a.text.Build.Cancelled - } + a.endBuildOperation(p, op, "cancelled", nil, "", a.text.Build.Cancelled) case errors.As(err, &exit) && exit.ExitCode() > 0: code := exit.ExitCode() - if a.endBuildOperation(p, op, "failed", &code, "") { - p.build.status = a.text.Build.Exited(code) - } + a.endBuildOperation(p, op, "failed", &code, "", a.text.Build.Exited(code)) case err != nil: - if a.endBuildOperation(p, op, "failed", nil, "") { - p.build.status = a.text.Build.ProcessFailed(err.Error()) - } + a.endBuildOperation(p, op, "failed", nil, "", a.text.Build.ProcessFailed(err.Error())) default: code := 0 - if a.endBuildOperation(p, op, "completed", &code, "") { - p.build.status = a.text.Build.Succeeded - } + a.endBuildOperation(p, op, "completed", &code, "", a.text.Build.Succeeded) } } @@ -1547,17 +1581,14 @@ func (a *App) finishBuildError(p *project, op *buildOperation, err error) { return } if op.cancelled || errors.Is(err, context.Canceled) { - if a.endBuildOperation(p, op, "cancelled", nil, "") { - p.build.status = a.text.Build.Cancelled - } + a.endBuildOperation(p, op, "cancelled", nil, "", a.text.Build.Cancelled) return } failure := "" if op.ide != nil && op.ide.State == "preparing" { failure = err.Error() } - if a.endBuildOperation(p, op, "failed", nil, failure) { - p.build.status = err.Error() + if a.endBuildOperation(p, op, "failed", nil, failure, err.Error()) { a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("build", err)) } } @@ -1606,7 +1637,8 @@ func (a *App) stopBuildSessions(p *project, closing bool) { if operation != nil { // Its terminal event finds the operation detached, so it settles here. operation.stop() - operation.ide.settle("cancelled", nil, p.build.outputSequence, "") + a.endBuildSession(operation, "cancelled", a.text.Build.Cancelled) + operation.ide.settle("cancelled", nil, operation.session.output.sequence, "") } clients := p.buildSessions.detach(closing) a.tasks.running.Add(1) @@ -1631,47 +1663,32 @@ func (a *App) invalidateBuild(p *project) { } a.stopTestsForProject(p) a.stopBuildSessions(p, false) - // The output is gone, but its sequence keeps counting: an IDE operation's cursor then - // reports the discontinuity instead of reading lines written after it. - sequence := p.build.outputSequence - p.build = buildState{outputStart: sequence, outputSequence: sequence} + // The Run window's sessions are what ran, not the models, so they stay. + runs, view, sessions := p.build.runs, p.build.view, p.build.sessions + p.build = buildState{runs: runs, view: view, sessions: sessions} } -// appendBuildOutput adds text op wrote to the bounded output, splitting it into lines. Output -// of an operation the window no longer runs is dropped, so it never lands in the next -// execution's output. -func (a *App) appendBuildOutput(p *project, op *buildOperation, text string) { - if p == nil || a.project != p || p.build.operation != op || text == "" { +// streamBuildOutput decodes text op wrote, on the goroutine that read it, and posts the decoded +// lines to the window thread. It never runs on the window thread. +func (a *App) streamBuildOutput(p *project, op *buildOperation, text string) { + if text == "" { return } - for len(text) > 0 { - line := text - if index := strings.IndexByte(line, '\n'); index >= 0 { - line = text[:index+1] - text = text[index+1:] - } else { - text = "" - } - if len(line) > buildOutputLineSize { - // Cut at a character boundary, so the kept text stays valid UTF-8 for the IDE output pages. - cut := buildOutputLineSize - for cut > 0 && !utf8.RuneStart(line[cut]) { - cut-- - } - line = line[:cut] + "\n" - } - p.build.output = append(p.build.output, line) - p.build.outputBytes += len(line) - p.build.outputSequence++ - } - for len(p.build.output) > buildOutputMaxLines || p.build.outputBytes > buildOutputBytes { - if len(p.build.output) == 0 { - break - } - p.build.outputBytes -= len(p.build.output[0]) - p.build.output = p.build.output[1:] - p.build.outputStart++ + op.decoder.deliver(text, func(chunk outputChunk, failure error) { + a.post(func(a *App) { + a.reportOutputStyleFailure(failure) + a.applyBuildOutput(p, op, chunk) + }) + }) +} + +// applyBuildOutput adds decoded output to op's console. Output of an operation the window no +// longer runs is dropped, so it never lands in a later execution's console. +func (a *App) applyBuildOutput(p *project, op *buildOperation, chunk outputChunk) { + if p == nil || a.project != p || p.build.operation != op { + return } + op.session.output.apply(chunk) } func buildProjectByID(model core.BuildModel, id string) (core.BuildProject, bool) { diff --git a/desktop/internal/workbench/build_menus_test.go b/desktop/internal/workbench/build_menus_test.go index 6237427a70..ac6e64874c 100644 --- a/desktop/internal/workbench/build_menus_test.go +++ b/desktop/internal/workbench/build_menus_test.go @@ -52,8 +52,8 @@ func TestBuildRowMenusRunTargetsAndOpenTheBuildFile(t *testing.T) { if p.build.targetID != "main" { t.Fatalf("the menu ran target %q without choosing it", p.build.targetID) } - // What it prints shows in the Run window's build console, beside the Build window. - if !h.app.chrome.isOpen(h.app.chrome.index[itemRun]) || !h.app.chrome.isOpen(h.app.chrome.index[itemBuild]) || p.build.view != "" { + // What it prints shows in the Run window's tab for this execution, beside the Build window. + if run := p.activeRun(); !h.app.chrome.isOpen(h.app.chrome.index[itemRun]) || !h.app.chrome.isOpen(h.app.chrome.index[itemBuild]) || run == nil || run.pluginID != "" { t.Fatalf("after a run the Run window is open %v, the Build window %v, and the Run window shows %q", h.app.chrome.isOpen(h.app.chrome.index[itemRun]), h.app.chrome.isOpen(h.app.chrome.index[itemBuild]), p.build.view) } diff --git a/desktop/internal/workbench/build_panels_visual_test.go b/desktop/internal/workbench/build_panels_visual_test.go index f192b529f4..5287535697 100644 --- a/desktop/internal/workbench/build_panels_visual_test.go +++ b/desktop/internal/workbench/build_panels_visual_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -137,24 +138,29 @@ func TestVisualBuildPanels(t *testing.T) { switch scene { case "build-and-run": h.app.post(func(a *App) { - op := a.beginBuildOperation(p, "build", "package", "") - for _, line := range []string{ - "[INFO] Scanning for projects...\n", - "[INFO] Reactor Build Order:\n", - "[INFO] shop [pom]\n", - "[INFO] shop-core [jar]\n", - "[INFO] shop-web [jar]\n", - "[INFO] --- compiler:3.13.0:compile (default-compile) @ shop-core ---\n", - "[INFO] Compiling 42 source files to core/target/classes\n", - "[INFO] --- surefire:3.2.5:test (default-test) @ shop-core ---\n", - "[INFO] Tests run: 128, Failures: 0, Errors: 0, Skipped: 2\n", - "[INFO] --- jar:3.4.1:jar (default-jar) @ shop-web ---\n", - "[INFO] Building jar: web/target/shop-web-1.4.0.jar\n", - "[INFO] BUILD SUCCESS\n", - "[INFO] Total time: 8.214 s\n", - } { - a.appendBuildOutput(p, op, line) + // A restart, so the tab offers to run it again as a real task's does. + op := a.beginBuildOperation(p, "build", "package", "", func(*App, *project) {}) + // Maven's output with -Dstyle.color=always, so the console shows its colors. + const info = "[\x1b[1;34mINFO\x1b[m] " + goal := func(plugin, execution, module string) string { + return info + "\x1b[1m--- \x1b[0;32m" + plugin + "\x1b[m \x1b[1m(" + execution + ")\x1b[m @ \x1b[36m" + module + "\x1b[0;1m ---\x1b[m\n" } + feedBuildOutput(a, p, op, strings.Join([]string{ + info + "Scanning for projects...\n", + info + "\x1b[1mReactor Build Order:\x1b[m\n", + info + " shop [pom]\n", + info + " shop-core [jar]\n", + info + " shop-web [jar]\n", + goal("compiler:3.13.0:compile", "default-compile", "shop-core"), + info + "Compiling 42 source files to core/target/classes\n", + goal("surefire:3.2.5:test", "default-test", "shop-core"), + "[\x1b[1;33mWARNING\x1b[m] \x1b[1;33mTests run: 128, Failures: 0, Errors: 0, Skipped: 2\x1b[m\n", + goal("jar:3.4.1:jar", "default-jar", "shop-web"), + info + "Building jar: web/target/shop-web-1.4.0.jar\n", + info + "\x1b[1m------------------------------------------------------------------------\x1b[m\n", + info + "\x1b[1;32mBUILD SUCCESS\x1b[m\n", + info + "Total time: 8.214 s\n", + }, "")) a.finishBuildTask(p, op, json.RawMessage(`{"exitCode":0}`)) a.showBuildConsole(p) }) diff --git a/desktop/internal/workbench/build_test.go b/desktop/internal/workbench/build_test.go index f89f94b20a..03fdb86b1e 100644 --- a/desktop/internal/workbench/build_test.go +++ b/desktop/internal/workbench/build_test.go @@ -30,25 +30,32 @@ func TestBuildOutputKeepsWholeLinesWithinTheBudget(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) h.open(t.TempDir()) p := h.app.project - op := h.app.beginBuildOperation(p, "build", "build", "") - for i := 0; i < buildOutputMaxLines+50; i++ { - h.app.appendBuildOutput(p, op, "line "+strings.Repeat("x", 8)+"\n") + op := h.app.beginBuildOperation(p, "build", "build", "", nil) + feedBuildOutput(h.app, p, op, strings.Repeat("line "+strings.Repeat("x", 8)+"\n", buildOutputMaxLines+50)) + output := &op.session.output + if len(output.lines) > buildOutputMaxLines { + t.Fatalf("output has %d lines, want at most %d", len(output.lines), buildOutputMaxLines) } - if len(p.build.output) > buildOutputMaxLines { - t.Fatalf("output has %d lines, want at most %d", len(p.build.output), buildOutputMaxLines) + if output.bytes > buildOutputBytes { + t.Fatalf("output has %d bytes, want at most %d", output.bytes, buildOutputBytes) } - if p.build.outputBytes > buildOutputBytes { - t.Fatalf("output has %d bytes, want at most %d", p.build.outputBytes, buildOutputBytes) + if output.open.text != "" || output.lines[len(output.lines)-1].text != "line xxxxxxxx" { + t.Fatalf("the last output line was cut: %q, open %q", output.lines[len(output.lines)-1].text, output.open.text) } - if !strings.HasSuffix(p.build.output[len(p.build.output)-1], "\n") { - t.Fatal("the last output line lost its terminator") - } - visible := buildVisibleOutput(p.build.output) - if len(visible) == 0 || len(visible) > buildOutputVisible { - t.Fatalf("visible lines = %d", len(visible)) + if output.sequence != buildOutputMaxLines+50 || output.start != output.sequence-len(output.lines) { + t.Fatalf("output counts %d lines from %d, holding %d", output.sequence, output.start, len(output.lines)) } } +// feedBuildOutput decodes text as op's readers do and adds it to op's console at once, where +// streamBuildOutput posts it to the window thread. +func feedBuildOutput(a *App, p *project, op *buildOperation, text string) { + op.decoder.deliver(text, func(chunk outputChunk, failure error) { + a.reportOutputStyleFailure(failure) + a.applyBuildOutput(p, op, chunk) + }) +} + func TestBuildRunAppliesToTargetTags(t *testing.T) { run := pluginservice.BuildRunDeclaration{Tags: []string{"application"}} if !buildRunApplies(run, core.BuildTarget{Tags: []string{"library", "application"}}) { diff --git a/desktop/internal/workbench/build_tree_test.go b/desktop/internal/workbench/build_tree_test.go index 351a796b42..064d6fa8c4 100644 --- a/desktop/internal/workbench/build_tree_test.go +++ b/desktop/internal/workbench/build_tree_test.go @@ -481,7 +481,7 @@ func TestBuildTreeRunMarksRunTheirRowsAtOnce(t *testing.T) { // 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.app.post(func(a *App) { operation = a.beginBuildOperation(p, "build", "vet", "", nil) }) 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") diff --git a/desktop/internal/workbench/build_view.go b/desktop/internal/workbench/build_view.go index fa0eeb4b64..8516a7bd0a 100644 --- a/desktop/internal/workbench/build_view.go +++ b/desktop/internal/workbench/build_view.go @@ -4,84 +4,11 @@ import ( "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/core" - "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" - "github.com/vivaui/viva/gfx" - "github.com/vivaui/viva/ui" ) -const ( - buildRowHeight = 24 - buildOutputVisible = 200 -) - -// runView declares the Run tool window, which shows only what runs print: the console of what -// the Build window runs, beside the runs plugins started. The build systems, with their -// projects, targets and tasks, and the run configurations are the Build window's -// (build_tree_view.go). -func (a *App) runView(c ui.C, p *project) { - ui.Column(c).Fill().Background(a.colors.Editor).Children(func() { - a.runHeader(c, p) - ui.Divider(c) - if run := p.activeRun(); run != nil { - a.runConsole(c, p, run) - return - } - a.buildOutput(c, p) - }) -} - -// runHeader declares the title row: the switcher between the build console and the runs -// plugins started, else the console's name, then the stop of the running build operation. -func (a *App) runHeader(c ui.C, p *project) { - b, t := &p.build, a.text.Build - ui.Row(c).Height(panelHeaderHeight).FillWidth().Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - if len(b.runs) == 0 { - ui.Text(c, a.text.Run.Build).Color(a.colors.Text).Weight(gfx.WeightMedium).Ellipsis().Shrink(1) - } - a.runViews(c, p) - ui.Spacer(c) - if b.operation != nil { - label := t.Stop - if b.operation.cancelled { - label = i18n.Shared(a.language(), "desktop.process.forceStop") - } - if ui.Button(c, label).Outline().Clicked() { - a.stopBuildOperation(p) - } - } - }) -} - -// runViews declares the switcher between the build console and the runs plugins -// started. It is empty until the first run. -func (a *App) runViews(c ui.C, p *project) { - b := &p.build - if len(b.runs) == 0 { - return - } - views := make([]string, 0, len(b.runs)+1) - views = append(views, "") - for _, run := range b.runs { - views = append(views, run.id) - } - if p.runEntry(b.view) == nil { - b.view = "" - } - ui.Tabs(c, &b.view, views, func(id string) string { - if id == "" { - return a.text.Run.Build - } - return p.runEntry(id).label - }).Shrink(0) -} - -// showBuildConsole brings the Run window's build console forward, for an action of the Build -// window that prints there. A run a plugin starts switches to its own tab when it starts. -func (a *App) showBuildConsole(p *project) { - p.build.view = "" - a.openToolWindow(itemRun) -} +// buildRowHeight is the height of a row of the build tree and of the Run window's tree. +const buildRowHeight = 24 // buildRowKind says what a row of the build tree is. type buildRowKind uint8 @@ -134,44 +61,6 @@ type buildRow struct { test *core.BuildDiscoveredTest } -// buildOutput declares the console of the build tasks: its header with the status of the last -// operation, then its lines. -func (a *App) buildOutput(c ui.C, p *project) { - t := a.text.Build - small := a.theme.Metrics.FontSizeS - ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Clip().Children(func() { - ui.Row(c).FillWidth().Height(buildRowHeight).Shrink(0).Items(ui.Center).Gap(8).PadX(8).Children(func() { - ui.Text(c, t.Output).FontSize(small).Weight(gfx.WeightSemibold).Color(a.colors.Subtle).Shrink(0) - ui.Spacer(c) - if status := p.build.status; status != "" { - ui.Text(c, status).FontSize(small).Color(a.colors.Subtle).Ellipsis().Shrink(1) - } - }) - lines := buildVisibleOutput(p.build.output) - if len(lines) == 0 { - ui.Row(c).FillWidth().Grow(1).Items(ui.Center).PadX(shellContentPad).Children(func() { - ui.Text(c, t.EmptyOutput).FontSize(small).Color(a.colors.Subtle).Ellipsis() - }) - return - } - menu := &outputMenu{key: "buildoutput", all: func() string { return strings.Join(p.build.output, "") }} - a.outputList(c, p, &p.panels.output, outputScopeRun, t.Output, lines, menu).Grow(1) - }) -} - -// buildVisibleOutput splits what was printed into lines and keeps the last buildOutputVisible. -func buildVisibleOutput(chunks []string) []string { - joined := strings.Join(chunks, "") - if joined == "" { - return nil - } - lines := strings.Split(joined, "\n") - if len(lines) > buildOutputVisible { - lines = lines[len(lines)-buildOutputVisible:] - } - return lines -} - // declaredTasks are the tasks the manifest names itself, command and provider alike; a fromModel // template is listed through the model tasks it stands for. func declaredTasks(instance *buildInstance) []pluginservice.BuildTaskDeclaration { @@ -215,49 +104,3 @@ func buildRunApplies(run pluginservice.BuildRunDeclaration, target core.BuildTar } return false } - -// runConsole declares one run: its controls, its output with the links the -// plugin's matchers found, and how it ended. -func (a *App) runConsole(c ui.C, p *project, run *runEntry) { - t := a.text.Build - ui.Column(c).Fill().Clip().Children(func() { - ui.Row(c).FillWidth().Height(buildRowHeight + 8).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - ui.Text(c, run.label).Color(a.colors.Text).Ellipsis().Shrink(1) - ui.Spacer(c) - if run.running { - if ui.Button(c, t.Stop).Outline().Clicked() { - a.stopRun(p, run) - } - } else if run.rerun != nil { - if ui.Button(c, a.text.Run.Rerun).Outline().Clicked() { - a.rerunRun(p, run) - } - } - }) - ui.Divider(c) - a.runPerformanceChart(c, run) - lines := buildVisibleOutput(run.output) - if len(lines) == 0 { - ui.Row(c).FillWidth().Grow(1).Items(ui.Center).PadX(shellContentPad).Children(func() { - ui.Text(c, t.EmptyOutput).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() - }) - } else { - menu := &outputMenu{ - key: "runsnapshot/" + run.id, - all: func() string { return strings.Join(run.output, "") }, - extra: func(menu *ui.MenuItems) { - if menu.Item(a.text.Run.Snapshot.Menu).Clicked() { - c.After(func() { a.snapshotRunOutput(p, run) }) - } - }, - } - a.outputList(c, p, &run.list, outputScopeRun, t.Output, lines, menu).Grow(1) - } - if run.summary != "" { - ui.Divider(c) - ui.Row(c).FillWidth().Height(28).Shrink(0).Items(ui.Center).PadX(8).Children(func() { - ui.Text(c, run.summary).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() - }) - } - }) -} diff --git a/desktop/internal/workbench/context_menu_test.go b/desktop/internal/workbench/context_menu_test.go index dcedd7324d..a130da2c8d 100644 --- a/desktop/internal/workbench/context_menu_test.go +++ b/desktop/internal/workbench/context_menu_test.go @@ -83,8 +83,12 @@ func TestRunConsoleMenuCopiesTheChosenLineAndTheWholeOutput(t *testing.T) { h := newHarnessWithLanguages(t, &testKernel{Client: core.NewClient()}, []string{"en-US"}) h.open(t.TempDir()) p := h.app.project - run := &runEntry{id: "run-1", label: "Serve"} - run.append("first line\nsecond line\n") + run := &runEntry{id: "run-1", label: "Serve", output: newOutputBuffer(runOutputMaxLines, runOutputBytes)} + chunk, err := newOutputDecoder(h.app.kernel).decode("first line\nsecond line\n") + if err != nil { + t.Fatal(err) + } + run.output.apply(chunk) p.build.runs = append(p.build.runs, run) p.build.view = run.id if !h.app.chrome.isOpen(catalogIndex[itemRun]) { diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index ff88b75c0d..2cd3060624 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -463,6 +463,9 @@ func (a *App) splitterKey(event gfx.KeyEvent) gfx.EventResult { if r := p.panels.debugSplit.Key(event); r.Handled { return r } + if r := p.panels.runSplit.Key(event); r.Handled { + return r + } } return gfx.EventResult{} } diff --git a/desktop/internal/workbench/ide_api_dispatch.go b/desktop/internal/workbench/ide_api_dispatch.go index 9b28bd38a7..fdbfa08c1e 100644 --- a/desktop/internal/workbench/ide_api_dispatch.go +++ b/desktop/internal/workbench/ide_api_dispatch.go @@ -69,9 +69,10 @@ type ideAPIOperation struct { ConfigurationID string // failure is why an execution that never launched failed; a start reports it. failure string - // startSequence and endSequence bound the execution's lines in the Build output; - // endSequence is -1 while it is active. - startSequence, endSequence int + // output is the console of the execution's Run window session. endSequence is the number + // of its lines when the execution ended, -1 while it is active. + output *outputBuffer + endSequence int // launched is closed when the execution leaves preparation, however it does. launched chan struct{} } @@ -135,7 +136,6 @@ func (p *project) recordIDEOperation(kind, label, configuration string) *ideAPIO Label: label, State: "preparing", ConfigurationID: configuration, - startSequence: p.build.outputSequence, endSequence: -1, launched: make(chan struct{}), } @@ -199,20 +199,18 @@ func (p *project) ideAPIOperationSnapshot(operation *ideAPIOperation, output boo return entry } -// ideAPIOperationText joins the execution's lines the bounded output still holds. Lines that -// were trimmed are missing from the front, so a cursor into them no longer matches and Core -// reports the discontinuity. +// ideAPIOperationText joins the execution's finished lines its bounded console still holds, +// without their escapes. Lines that were trimmed are missing from the front, so a cursor into +// them no longer matches and Core reports the discontinuity. func (p *project) ideAPIOperationText(operation *ideAPIOperation) string { - first := p.build.outputStart - start := max(operation.startSequence, first) - end := p.build.outputSequence + if operation.output == nil { + return "" + } + end := operation.output.sequence if operation.endSequence >= 0 { end = min(end, operation.endSequence) } - if start >= end { - return "" - } - return strings.Join(p.build.output[start-first:end-first], "") + return operation.output.text(0, end) } // ideAPIDispatch runs one admitted tool and returns its result. The result is either the diff --git a/desktop/internal/workbench/ide_api_operation_test.go b/desktop/internal/workbench/ide_api_operation_test.go index 56c47137ac..20861b1db0 100644 --- a/desktop/internal/workbench/ide_api_operation_test.go +++ b/desktop/internal/workbench/ide_api_operation_test.go @@ -168,13 +168,12 @@ func TestIDEBuildExecuteReservesTheWindowUntilItsExecutionEnds(t *testing.T) { func TestIDEOperationOutputIsPagedByCore(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) p, conn := ideAPIProject(t, h) - op := h.app.beginBuildOperation(p, "build", "Cargo: build", "") + op := h.app.beginBuildOperation(p, "build", "Cargo: build", "", nil) var want strings.Builder for i := 0; i < 2000; i++ { - line := fmt.Sprintf("%04d 编译 %s\n", i, strings.Repeat("é", 20)) - want.WriteString(line) - h.app.appendBuildOutput(p, op, line) + want.WriteString(fmt.Sprintf("%04d 编译 %s\n", i, strings.Repeat("é", 20))) } + feedBuildOutput(h.app, p, op, want.String()) read := func(cursor string) map[string]any { t.Helper() arguments := map[string]any{"operationID": op.ide.ID} @@ -213,14 +212,12 @@ func TestIDEOperationOutputIsPagedByCore(t *testing.T) { if end := read(cursor); end["output"] != "" || end["hasMore"] != false || end["nextCursor"] != cursor { t.Fatalf("a read at the end answered %#v", end) } - h.app.appendBuildOutput(p, op, "tail\n") + feedBuildOutput(h.app, p, op, "tail\n") if tail := read(cursor); tail["output"] != "tail\n" || tail["reset"] != false { t.Fatalf("the read after new output answered %#v", tail) } - for i := 0; i < buildOutputMaxLines; i++ { - h.app.appendBuildOutput(p, op, "x\n") - } + feedBuildOutput(h.app, p, op, strings.Repeat("x\n", buildOutputMaxLines)) trimmed := read(firstCursor) if text, _ := trimmed["output"].(string); trimmed["reset"] != true || !strings.HasPrefix(text, "x\n") { t.Fatalf("a cursor into dropped output answered reset %v with %.20q", trimmed["reset"], text) diff --git a/desktop/internal/workbench/output_style.go b/desktop/internal/workbench/output_style.go new file mode 100644 index 0000000000..359081851f --- /dev/null +++ b/desktop/internal/workbench/output_style.go @@ -0,0 +1,225 @@ +package workbench + +import ( + "context" + "encoding/json" + "strings" + "sync" + "time" + "unicode/utf8" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" +) + +const ( + // outputDecodePiece bounds the text of one Core decode, well under Core's 1 MiB chunk limit. + outputDecodePiece = 256 << 10 + // outputDecodeTimeout bounds one Core decode. + outputDecodeTimeout = 10 * time.Second +) + +// styledLine is one line of console output with its escapes removed: plain text, which copying, +// search, output links and the IDE API read, and the ranges Core styled (UTF-16 offsets). +type styledLine struct { + text string + spans []core.OutputSpan +} + +// outputChunk is what one piece of output adds to a console: the lines it finished, the first +// continuing the previous open line, and the line still being written. +type outputChunk struct { + lines []styledLine + open styledLine +} + +// outputDecoder turns one console's output into styled lines through Core's outputStyle.decode, +// carrying Core's state from chunk to chunk. It runs on the goroutines that read the output, never +// on the window thread: deliver decodes and hands the result to post while holding the decoder, so +// the chunks of a console that two streams write reach the window in the order they were decoded. +type outputDecoder struct { + kernel Kernel + mu sync.Mutex + state json.RawMessage + // carry is the start of a character the previous text ended inside. + carry string + // open is the line still being written, kept for the plain fallback. + open styledLine + // plain is set once Core failed: the rest of the console is split into lines as it is. + plain bool +} + +func newOutputDecoder(kernel Kernel) *outputDecoder { + return &outputDecoder{kernel: kernel} +} + +// deliver decodes text and passes the result to post, with failure set the first time Core could +// not decode this console's output; the window thread logs it once. +func (d *outputDecoder) deliver(text string, post func(chunk outputChunk, failure error)) { + d.mu.Lock() + defer d.mu.Unlock() + chunk, failure := d.decode(text) + post(chunk, failure) +} + +// decode is deliver without the lock and the hand-off; d.mu is held. +func (d *outputDecoder) decode(text string) (outputChunk, error) { + text = d.carry + text + d.carry = "" + if cut := completeUTF8(text); cut < len(text) { + d.carry, text = text[cut:], text[:cut] + } + chunk := outputChunk{open: d.open} + var failure error + for len(text) > 0 { + piece := text + if len(piece) > outputDecodePiece { + cut := outputDecodePiece + for cut > 0 && !utf8.RuneStart(piece[cut]) { + cut-- + } + piece = piece[:cut] + } + text = text[len(piece):] + if !d.plain { + ctx, cancel := context.WithTimeout(context.Background(), outputDecodeTimeout) + decoded, err := d.kernel.DecodeOutputStyle(ctx, piece, d.state) + cancel() + if err == nil { + d.state = decoded.State + for _, line := range decoded.Lines { + chunk.lines = append(chunk.lines, styledLine{text: line.Text, spans: line.Spans}) + } + chunk.open = styledLine{text: decoded.Open.Text, spans: decoded.Open.Spans} + continue + } + d.plain, d.state, failure = true, nil, err + } + chunk.lines, chunk.open = splitPlainOutput(chunk.lines, chunk.open, piece) + } + d.open = chunk.open + return chunk, failure +} + +// splitPlainOutput appends the lines text ends to lines, continuing open, without decoding escapes. +func splitPlainOutput(lines []styledLine, open styledLine, text string) ([]styledLine, styledLine) { + for { + index := strings.IndexByte(text, '\n') + if index < 0 { + open.text += text + return lines, open + } + open.text += strings.TrimSuffix(text[:index], "\r") + lines = append(lines, open) + open, text = styledLine{}, text[index+1:] + } +} + +// completeUTF8 returns how much of text ends on a character boundary: a character the text ends +// inside is left for the next text. +func completeUTF8(text string) int { + for back := 1; back < utf8.UTFMax && back <= len(text); back++ { + start := len(text) - back + if utf8.RuneStart(text[start]) { + if utf8.FullRuneInString(text[start:]) { + return len(text) + } + return start + } + } + return len(text) +} + +// outputBuffer is one console's bounded output: finished lines, oldest first, and the line still +// being written. The oldest lines go first when it holds more than maxLines lines or maxBytes +// bytes. start is the sequence number of lines[0] and sequence counts the lines ever finished, so +// a reader that remembers a sequence notices lines that were dropped. Window thread only. +type outputBuffer struct { + lines []styledLine + open styledLine + bytes int + start, sequence int + maxLines, maxBytes int +} + +func newOutputBuffer(maxLines, maxBytes int) outputBuffer { + return outputBuffer{maxLines: maxLines, maxBytes: maxBytes} +} + +// apply adds a decoded chunk. +func (b *outputBuffer) apply(chunk outputChunk) { + for _, line := range chunk.lines { + b.lines = append(b.lines, line) + b.bytes += len(line.text) + 1 + b.sequence++ + } + b.open = chunk.open + for len(b.lines) > 0 && (len(b.lines) > b.maxLines || b.bytes > b.maxBytes) { + b.bytes -= len(b.lines[0].text) + 1 + b.lines[0] = styledLine{} + b.lines = b.lines[1:] + b.start++ + } +} + +// seal finishes the open line of a console whose writer ended. +func (b *outputBuffer) seal() { + if b.open.text == "" { + return + } + b.apply(outputChunk{lines: []styledLine{b.open}}) +} + +// clear drops the finished lines. The line still being written stays, since its writer continues +// it; the sequence keeps counting. +func (b *outputBuffer) clear() { + b.lines, b.bytes, b.start = nil, 0, b.sequence +} + +// count is the number of rows the console shows: the finished lines and an open line with text. +func (b *outputBuffer) count() int { + if b.open.text != "" { + return len(b.lines) + 1 + } + return len(b.lines) +} + +// row is the row index of the console. +func (b *outputBuffer) row(index int) styledLine { + if index < len(b.lines) { + return b.lines[index] + } + return b.open +} + +// empty reports whether the console shows nothing. +func (b *outputBuffer) empty() bool { + return b.count() == 0 +} + +// text joins the finished lines from sequence from up to sequence to that the buffer still holds, +// each with its line ending. +func (b *outputBuffer) text(from, to int) string { + from, to = max(from, b.start), min(to, b.sequence) + if from >= to { + return "" + } + var out strings.Builder + for _, line := range b.lines[from-b.start : to-b.start] { + out.WriteString(line.text) + out.WriteByte('\n') + } + return out.String() +} + +// all is everything the console shows, for copying and snapshots. +func (b *outputBuffer) all() string { + return b.text(b.start, b.sequence) + b.open.text +} + +// reportOutputStyleFailure logs that Core could not decode a console's escapes; that console +// shows the rest of its output as it came. Each decoder reports its failure once; nil is none. +func (a *App) reportOutputStyleFailure(failure error) { + if failure != nil { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("output_style", failure)) + } +} diff --git a/desktop/internal/workbench/outputlinks.go b/desktop/internal/workbench/outputlinks.go index 0c69bfec78..32f8845fa0 100644 --- a/desktop/internal/workbench/outputlinks.go +++ b/desktop/internal/workbench/outputlinks.go @@ -166,61 +166,6 @@ func (a *App) flushOutputLinks(p *project) { }) } -// splitUTF16 cuts line at UTF-16 code unit offsets: the text from from up to the -// link, and the link's own text. ok is false for a range the line does not hold. -func splitUTF16(line string, from, start, length int) (before, linked string, ok bool) { - if from < 0 || start < from || length <= 0 { - return "", "", false - } - units, begin, end := 0, -1, -1 - fromByte := -1 - for offset, r := range line { - if units == from { - fromByte = offset - } - if units == start { - begin = offset - } - if units == start+length { - end = offset - } - if r >= 0x10000 { - units += 2 - } else { - units++ - } - } - if units == from { - fromByte = len(line) - } - if units == start { - begin = len(line) - } - if units == start+length { - end = len(line) - } - if fromByte < 0 || begin < 0 || end < 0 || end <= begin { - return "", "", false - } - return line[fromByte:begin], line[begin:end], true -} - -// utf16Tail is the text from a UTF-16 offset to the end of the line. -func utf16Tail(line string, from int) string { - units := 0 - for offset, r := range line { - if units >= from { - return line[offset:] - } - if r >= 0x10000 { - units += 2 - } else { - units++ - } - } - return "" -} - // openOutputLink opens what a clicked link points at. A location names candidate // files and opens the first that exists; a link that needs its plugin asks the // plugin's backend first. Both run off the window thread, and a file that does diff --git a/desktop/internal/workbench/outputlinks_test.go b/desktop/internal/workbench/outputlinks_test.go index 94d95964fc..e5c70a6baf 100644 --- a/desktop/internal/workbench/outputlinks_test.go +++ b/desktop/internal/workbench/outputlinks_test.go @@ -25,37 +25,71 @@ const outputLinkManifest = `{ "outputLinkMatchers": [{"id": "frame", "pattern": "at (?P[\\w/.]+\\.txt):(?P\\d+):(?P\\d+)", "scope": "run"}] }` -// startRunConsole shows a plugin-started run whose output is text, as the run -// host's events would. +// startRunConsole shows a plugin-started run whose output is text, decoded as the run +// host's observer decodes it. func (h *harness) startRunConsole(root, text string) { h.t.Helper() h.app.applyRunEvent(pluginservice.RunEvent{Type: pluginservice.RunStarted, RunID: "run-test", PluginID: "dev.lithe.test.output-links", Label: "Test run", Workspace: root}) - h.app.applyRunEvent(pluginservice.RunEvent{Type: pluginservice.RunOutput, RunID: "run-test", Text: text}) + chunk, err := newOutputDecoder(h.app.kernel).decode(text) + if err != nil { + h.t.Fatal(err) + } + h.app.applyRunOutput("run-test", chunk) } -func TestSplitUTF16CutsAtCodeUnitOffsets(t *testing.T) { - cases := []struct { - line string - from, start, length int - before, linked string - ok bool - }{ - {"ab at x.txt:3 end", 0, 3, 10, "ab ", "at x.txt:3", true}, - {"😀 at x.txt:3", 0, 3, 10, "😀 ", "at x.txt:3", true}, - {"😀 at x.txt:3", 2, 3, 10, " ", "at x.txt:3", true}, - {"abc", 0, 1, 5, "", "", false}, - {"abc", 2, 1, 1, "", "", false}, - {"abc", 0, 0, 0, "", "", false}, - {"abc", 0, 0, 3, "", "abc", true}, - } - for _, c := range cases { - before, linked, ok := splitUTF16(c.line, c.from, c.start, c.length) - if before != c.before || linked != c.linked || ok != c.ok { - t.Errorf("splitUTF16(%q,%d,%d,%d) = %q,%q,%v want %q,%q,%v", c.line, c.from, c.start, c.length, before, linked, ok, c.before, c.linked, c.ok) +func TestOutputSegmentsCutAtStyleAndLinkBoundaries(t *testing.T) { + bold := core.OutputStyle{Bold: true} + // 😀 is two UTF-16 units, so "at" starts at unit 3. + line := styledLine{text: "😀 at x.txt:3 ok", spans: []core.OutputSpan{{Start: 0, Length: 5, Style: bold}}} + links := []core.OutputLink{ + {Start: 14, Length: 9}, // runs past the line + {Start: 3, Length: 10}, + {Start: 5, Length: 2}, // overlaps the link before it + } + segments := outputSegments(line, links) + want := []struct { + text string + bold bool + linked bool + }{{"😀 ", true, false}, {"at", true, true}, {" x.txt:3", false, true}, {" ok", false, false}} + if len(segments) != len(want) { + t.Fatalf("segments = %+v, want %d", segments, len(want)) + } + for index, segment := range segments { + w := want[index] + if segment.text != w.text || segment.style.Bold != w.bold || (segment.link != nil) != w.linked { + t.Errorf("segment %d = %q bold=%v link=%v, want %q bold=%v link=%v", index, segment.text, segment.style.Bold, segment.link != nil, w.text, w.bold, w.linked) } + if segment.link != nil && segment.link.Start != 3 { + t.Errorf("segment %d links %+v, want the link at 3", index, *segment.link) + } + } + // An offset inside a character moves to its end, so no piece splits the character. + split := outputSegments(styledLine{text: "😀a", spans: []core.OutputSpan{{Start: 1, Length: 2, Style: bold}}}, nil) + if len(split) != 2 || split[0].text != "😀" || split[0].style.Bold || split[1].text != "a" || !split[1].style.Bold { + t.Fatalf("segments = %+v, want the whole emoji plain and a bold", split) + } +} + +func TestOutputInkResolvesPaletteBrightBoldAndRGB(t *testing.T) { + var ink outputInk + for index := range ink.ansi { + ink.ansi[index] = [3]uint8{uint8(index), 0, 0} + } + blue := 4 + if got, ok := ink.color(&core.OutputColor{Index: &blue}, true); !ok || got != rgbColor(12, 0, 0) { + t.Fatalf("bold blue = %+v %v, want the bright entry 12", got, ok) } - if got := utf16Tail("😀 ab", 3); got != "ab" { - t.Errorf("utf16Tail = %q", got) + if got, ok := ink.color(&core.OutputColor{Index: &blue}, false); !ok || got != rgbColor(4, 0, 0) { + t.Fatalf("blue = %+v %v, want entry 4", got, ok) + } + if got, ok := ink.color(&core.OutputColor{RGB: "#0a141e"}, false); !ok || got != rgbColor(10, 20, 30) { + t.Fatalf("rgb = %+v %v", got, ok) + } + for _, color := range []*core.OutputColor{nil, {RGB: "0a141e"}, {RGB: "#zzzzzz"}} { + if _, ok := ink.color(color, false); ok { + t.Fatalf("color %+v resolved, want the console's own", color) + } } } diff --git a/desktop/internal/workbench/outputlinks_view.go b/desktop/internal/workbench/outputlinks_view.go index 606c167ce5..d4d8f84437 100644 --- a/desktop/internal/workbench/outputlinks_view.go +++ b/desktop/internal/workbench/outputlinks_view.go @@ -1,10 +1,12 @@ package workbench import ( - "sort" - "strings" + "slices" + "strconv" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/term" "github.com/vivaui/viva/app" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" @@ -19,23 +21,22 @@ type outputMenu struct { extra func(*ui.MenuItems) } -// outputLineMenu is the menu of the console line raw, or of no line when line is false. -func (a *App) outputLineMenu(c ui.C, raw string, line bool, m *outputMenu) func(*ui.MenuItems) { +// outputLineMenu is the menu of the console line text, or of no line when line is false. +func (a *App) outputLineMenu(c ui.C, text string, line bool, m *outputMenu) func(*ui.MenuItems) { return func(menu *ui.MenuItems) { lang := a.language() menu.WidthRange(180, 260) if menu.Item(i18n.Shared(lang, "menu.copy")).Disabled(!line).Clicked() { - line := strings.TrimRight(raw, "\r\n") c.After(func() { a.performed("output.copyLine", surfaceMenu) - _ = app.SetClipboardText(line) + _ = app.SetClipboardText(text) }) } if menu.Item(i18n.Shared(lang, "git.console.copyOutput")).Clicked() { - text := m.all() + all := m.all() c.After(func() { a.performed("output.copyAll", surfaceMenu) - _ = app.SetClipboardText(text) + _ = app.SetClipboardText(all) }) } if m.extra != nil { @@ -45,21 +46,71 @@ func (a *App) outputLineMenu(c ui.C, raw string, line bool, m *outputMenu) func( } } -// outputList declares console lines as a list that holds only the rows on screen. -// A line with no link is plain text; one with links is split into text and -// clickable ranges at the UTF-16 offsets Core reported. +// outputInk is what console lines are colored with: the terminal's 16 ANSI colors in the +// current look, so a program's colors match the Terminal window, and the console's own +// text, background and link colors. It is resolved once for each list a frame declares. +type outputInk struct { + ansi [16][3]uint8 + foreground gfx.Color + background gfx.Color + link gfx.Color +} + +func (a *App) outputInk() outputInk { + return outputInk{ansi: a.terminalLook().ANSI(), foreground: a.colors.Text, background: a.colors.Ground, link: a.colors.Accent} +} + +// color resolves a styled range's color, or reports false for the console's own. Bold text +// in one of the eight base colors takes its bright variant, as the terminal draws it. +func (ink *outputInk) color(color *core.OutputColor, bold bool) (gfx.Color, bool) { + if color == nil { + return gfx.Color{}, false + } + if color.Index != nil { + index := *color.Index + if index < 0 || index > 255 { + return gfx.Color{}, false + } + if bold && index < 8 { + index += 8 + } + red, green, blue := term.Resolve(uint8(index), &ink.ansi) + return rgbColor(red, green, blue), true + } + if len(color.RGB) != 7 || color.RGB[0] != '#' { + return gfx.Color{}, false + } + value, err := strconv.ParseUint(color.RGB[1:], 16, 32) + if err != nil { + return gfx.Color{}, false + } + return rgbColor(uint8(value>>16), uint8(value>>8), uint8(value)), true +} + +func rgbColor(red, green, blue uint8) gfx.Color { + return gfx.Color{Red: float32(red) / 255, Green: float32(green) / 255, Blue: float32(blue) / 255, Alpha: 1} +} + +// outputList declares a console's lines from from on as a list that holds only the rows on +// screen. Each line is cut into the ranges Core styled from its escapes and the links Core +// matched, all at UTF-16 offsets, and every piece is drawn in its own colors. // // The lines are drawn in the run output's font (fonts.go), each line as tall as that font's -// line spacing makes it. A line right-clicked opens menu, when there is one. -func (a *App) outputList(c ui.C, p *project, state *ui.ListState, scope, label string, lines []string, menu *outputMenu) ui.Box { +// line spacing makes it. A line right-clicked opens menu, when there is one. The list keeps +// to the newest line as output arrives, until the user scrolls up, and keeps to it again once +// they scroll back down. +func (a *App) outputList(c ui.C, p *project, state *ui.ListState, scope, label string, output *outputBuffer, from int, menu *outputMenu) ui.Box { font := a.outputFont() lineH := font.lineHeight(c.Canvas()) - list := ui.List(c, state, len(lines), func(row ui.ListRow) { - a.outputLine(row, p, scope, lines[row.Index], font, lineH) + ink := a.outputInk() + from = min(max(from, 0), output.count()) + list := ui.List(c, state, output.count()-from, func(row ui.ListRow) { + line := output.row(from + row.Index) + a.outputLine(row, p, scope, line, &ink, font, lineH) if menu != nil { - ui.ContextMenu(row.C, row.Element, a.outputLineMenu(row.C, lines[row.Index], true, menu)) + ui.ContextMenu(row.C, row.Element, a.outputLineMenu(row.C, line.text, true, menu)) } - }).Label(label).FillWidth() + }).Label(label).FillWidth().Follow(true) a.flushOutputLinks(p) if menu != nil { list = list.Hit(ui.ID(c.Key(menu.key)), label) @@ -69,36 +120,160 @@ func (a *App) outputList(c ui.C, p *project, state *ui.ListState, scope, label s } // outputLine declares one console line in its row. -func (a *App) outputLine(row ui.ListRow, p *project, scope, raw string, font scopeFont, lineH float32) { +func (a *App) outputLine(row ui.ListRow, p *project, scope string, line styledLine, ink *outputInk, font scopeFont, lineH float32) { c := row.C - line := strings.TrimRight(raw, "\r\n") - text := func(value string) ui.Box { - return ui.Text(c, value).FontSize(font.Size).MonoFace(font.face).LineHeight(lineH) - } row.Element.PadX(8) - links := a.outputLinksFor(p, scope, line) - if len(links) == 0 { - text(line).Color(a.colors.Text) + links := a.outputLinksFor(p, scope, line.text) + if len(links) == 0 && len(line.spans) == 0 { + ui.Text(c, line.text).FontSize(font.Size).MonoFace(font.face).LineHeight(lineH).Color(ink.foreground) return } - sort.SliceStable(links, func(i, j int) bool { return links[i].Start < links[j].Start }) - position := 0 + for _, segment := range outputSegments(line, links) { + a.outputSegment(c, p, segment, ink, font, lineH) + } +} + +// outputSegment declares one piece of a console line in its style. A link is drawn in the +// link color whatever its range's colors, so it reads as one. +func (a *App) outputSegment(c ui.C, p *project, segment outputSegment, ink *outputInk, font scopeFont, lineH float32) { + style := segment.style + foreground, ok := ink.color(style.Foreground, style.Bold) + if !ok { + foreground = ink.foreground + } + background, filled := ink.color(style.Background, false) + if style.Inverse { + if !filled { + background = ink.background + } + foreground, background, filled = background, foreground, true + } + if segment.link != nil { + foreground = ink.link + } + if style.Dim { + foreground.Alpha *= 0.6 + } + if style.Hidden { + foreground.Alpha = 0 + } + box := ui.Text(c, segment.text).FontSize(font.Size).MonoFace(font.face).LineHeight(lineH).Color(foreground).Shrink(0) + if style.Bold { + box = box.Weight(gfx.WeightBold) + } + if filled { + box = box.Background(background) + } + if style.Underline || style.Strikethrough { + size, underline, strike := font.Size, style.Underline, style.Strikethrough + box = box.DrawOver(func(d *ui.DrawContext) { + middle := d.Rect.Y + d.Rect.Height/2 + color := d.Fade(foreground) + if underline { + d.Canvas.Fill(gfx.Rect{X: d.Rect.X, Y: middle + size*0.4, Width: d.Rect.Width, Height: 1}, color) + } + if strike { + d.Canvas.Fill(gfx.Rect{X: d.Rect.X, Y: middle + size*0.05 - 0.5, Width: d.Rect.Width, Height: 1}, color) + } + }) + } + if link := segment.link; link != nil { + box = box.HitWith(ui.ID(c), segment.text, gfx.HitOptions{Role: gfx.RoleLink, Cursor: gfx.PointerCursorHand}) + if box.Clicked() { + a.openOutputLink(p, *link) + } + } +} + +// outputSegment is a piece of one console line with one style and at most one link. +type outputSegment struct { + text string + style core.OutputStyle + link *core.OutputLink +} + +// outputSegments cuts line wherever a styled range or a link starts or ends. Ranges and links +// are at UTF-16 offsets; a link that runs past the line or overlaps an earlier one is dropped, +// and an offset inside a character moves to the character's end. +func outputSegments(line styledLine, links []core.OutputLink) []outputSegment { + length := utf16Length(line.text) + links = slices.Clone(links) + slices.SortStableFunc(links, func(x, y core.OutputLink) int { return x.Start - y.Start }) + kept, reached := links[:0], 0 for _, link := range links { - before, linked, ok := splitUTF16(line, position, link.Start, link.Length) - if !ok { + if link.Length <= 0 || link.Start < reached || link.Start+link.Length > length { continue } - if before != "" { - text(before).Color(a.colors.Text).Shrink(0) + kept = append(kept, link) + reached = link.Start + link.Length + } + cuts := []int{0, length} + for _, span := range line.spans { + cuts = append(cuts, span.Start, span.Start+span.Length) + } + for _, link := range kept { + cuts = append(cuts, link.Start, link.Start+link.Length) + } + cuts = slices.DeleteFunc(cuts, func(cut int) bool { return cut < 0 || cut > length }) + slices.Sort(cuts) + cuts = slices.Compact(cuts) + offsets := utf16ByteOffsets(line.text, cuts) + segments := make([]outputSegment, 0, len(cuts)) + span, link := 0, 0 + for index := 0; index+1 < len(cuts); index++ { + text := line.text[offsets[index]:offsets[index+1]] + if text == "" { + continue } - box := text(linked).Color(a.colors.Accent).Shrink(0). - HitWith(ui.ID(c), linked, gfx.HitOptions{Role: gfx.RoleLink, Cursor: gfx.PointerCursorHand}) - if box.Clicked() { - a.openOutputLink(p, link) + start := cuts[index] + segment := outputSegment{text: text} + for span < len(line.spans) && line.spans[span].Start+line.spans[span].Length <= start { + span++ } - position = link.Start + link.Length + if span < len(line.spans) && line.spans[span].Start <= start { + segment.style = line.spans[span].Style + } + for link < len(kept) && kept[link].Start+kept[link].Length <= start { + link++ + } + if link < len(kept) && kept[link].Start <= start { + segment.link = &kept[link] + } + segments = append(segments, segment) } - if rest := utf16Tail(line, position); rest != "" { - text(rest).Color(a.colors.Text).Shrink(0) + return segments +} + +// utf16Length is the length of text in UTF-16 code units, the unit Core's offsets count. +func utf16Length(text string) int { + units := 0 + for _, r := range text { + units += utf16Units(r) + } + return units +} + +// utf16ByteOffsets maps ascending UTF-16 offsets into text to byte offsets. An offset inside a +// character maps to that character's end, and one past the text to its length. +func utf16ByteOffsets(text string, cuts []int) []int { + offsets := make([]int, len(cuts)) + next, units := 0, 0 + for offset, r := range text { + for next < len(cuts) && cuts[next] <= units { + offsets[next] = offset + next++ + } + units += utf16Units(r) + } + for ; next < len(cuts); next++ { + offsets[next] = len(text) + } + return offsets +} + +func utf16Units(r rune) int { + if r >= 0x10000 { + return 2 } + return 1 } diff --git a/desktop/internal/workbench/run_panels_test.go b/desktop/internal/workbench/run_panels_test.go index 339241f56c..f6c27b508c 100644 --- a/desktop/internal/workbench/run_panels_test.go +++ b/desktop/internal/workbench/run_panels_test.go @@ -72,8 +72,9 @@ func TestRunConsoleDeclaresOnlyTheRowsOnScreen(t *testing.T) { root := t.TempDir() h.open(root) h.app.reduceChrome(core.ToggleChrome(itemRun)) + const lines = 200 var text strings.Builder - for line := range buildOutputVisible { + for line := range lines { text.WriteString("line " + strconv.Itoa(line) + "\n") } h.startRunConsole(root, text.String()) @@ -86,12 +87,11 @@ func TestRunConsoleDeclaresOnlyTheRowsOnScreen(t *testing.T) { rows++ } } - if rows == 0 || rows >= buildOutputVisible/2 { - t.Fatalf("the console declared %d rows for %d lines, want only the ones on screen", rows, buildOutputVisible) + if rows == 0 || rows >= lines/2 { + t.Fatalf("the console declared %d rows for %d lines, want only the ones on screen", rows, lines) } - // The console keeps the last buildOutputVisible lines of the text, which end - // in a newline, so the oldest of ours is the first it drops. - if !h.shows("line 1") { - t.Fatal("the console does not show the start of its output") + // The console follows its output, so it opens on the newest line. + if !h.shows("line 199") || h.shows("line 0") { + t.Fatal("the console does not keep to the end of its output") } } diff --git a/desktop/internal/workbench/run_view.go b/desktop/internal/workbench/run_view.go new file mode 100644 index 0000000000..d1beb7d08a --- /dev/null +++ b/desktop/internal/workbench/run_view.go @@ -0,0 +1,299 @@ +package workbench + +import ( + "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" +) + +const ( + // runTreeRatio is the share of the Run window's body the execution tree takes until the + // divider is dragged; runTreeMinWidth and runConsoleMinWidth keep both panes usable. + runTreeRatio = 0.32 + runTreeMinWidth = 180 + runConsoleMinWidth = 240 + // runStartedLayout is how the tree writes when an execution started, as IntelliJ IDEA's + // Run window does; the words around it are translated (RunMessages.StartedAt). + runStartedLayout = "2006/01/02 15:04" + // runTreeIcon is the side of the status icon in the tree, runToolIcon that of the + // toolbars' icons. + runTreeIcon = 16 + runToolIcon = 16 +) + +// runView declares the Run tool window as IntelliJ IDEA lays it out. Its header holds a tab per +// execution (runSessionTabs); the body shows the selected one: rerun and stop on the left, the +// execution's tree with how it stands and how long it took, and its console in the colors it +// printed, with the console's own actions on its right. +func (a *App) runView(c ui.C, p *project) { + run := p.activeRun() + body := ui.Column(c).Fill().Background(a.colors.Editor) + if run == nil { + body.Children(func() { a.panelMessage(c, a.text.Run.Empty, a.colors.Subtle) }) + return + } + body.Children(func() { + ui.Row(c).Fill().Clip().Children(func() { + a.runToolbar(c, p, run) + ui.Divider(c) + a.runPanes(c.Key(run.id), p, run) + }) + }) +} + +// runSessionTabs declares the header's tab of every execution the Run window keeps, oldest +// first, as IntelliJ IDEA names each: its status icon and name, and, once it ended, the × that +// closes it. A click selects one. The row takes the room a spacer would, and its tabs cut their +// names in a narrow panel before they push the hide button out. +func (a *App) runSessionTabs(c ui.C, p *project) { + runs, shown := p.build.runs, p.activeRun() + ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Height(panelHeaderHeight).Items(ui.Center).Gap(2).Clip().Children(func() { + for index, run := range runs { + k := c.Key(run.id) + on := run == shown + chip := ui.Row(k).Height(rowHeight).Shrink(1).MinWidth(0).Items(ui.Center).Gap(6).PadX(toolTabPad). + Radius(a.theme.Metrics.RadiusItem()). + HitWith(ui.ID(k), run.label, gfx.HitOptions{ + Role: gfx.RoleTab, Cursor: gfx.PointerCursorHand, Selected: on, + PosInSet: int32(index + 1), SetSize: int32(len(runs)), + }). + Tooltip(run.label). + Pressed(ui.Look{}.Background(a.colors.Active)) + if on { + chip = chip.Background(a.colors.TabIdle).Stroke(1, a.colors.TabIdleBorder).Radius(6) + } else { + chip = chip.Hover(ui.Look{}.Background(a.colors.Hover)) + } + if !run.running { + // The × sits where the padding would end the tab. + chip = chip.PadSides(0, 2, 0, toolTabPad) + } + var closeButton ui.Box + chip.Children(func() { + a.runStatusMark(k, run, terminalChipIcon) + text := ui.Text(k, run.label).Ellipsis().Shrink(1) + if on { + text.Color(a.colors.Text) + } else { + text.Color(a.colors.Subtle).StateFrom(chip).Hover(ui.Look{}.Color(a.colors.Text)) + } + if run.running { + return + } + cc := k.Part("close") + closeButton = ui.Row(cc).Size(terminalCloseSize, terminalCloseSize).Shrink(0).Center(). + Radius(a.theme.Metrics.RadiusItem()). + HitWith(ui.ID(cc), a.text.Run.CloseSession, gfx.HitOptions{Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand}). + Hover(ui.Look{}.Background(a.colors.Hover)).Pressed(ui.Look{}.Background(a.colors.Active)) + closeButton.Children(func() { + ui.Icon(cc, icons.X).Size(terminalCloseIcon, terminalCloseIcon).Color(a.colors.Subtle). + StateFrom(closeButton).Hover(ui.Look{}.Color(a.colors.Text)) + }) + }) + id := run.id + switch { + case !run.running && closeButton.Clicked(): + c.After(func() { p.closeRunSession(id) }) + case chip.Clicked(): + c.After(func() { p.build.view = id }) + } + } + ui.Spacer(c) + }) +} + +// runToolbar declares the column of the selected execution's actions left of its tree, as IDEA +// puts them: rerun, in green, which starts an ended execution again, and stop, in red, while it +// runs. A host's execution reruns only while no other one runs, since the window runs one at a +// time; a stop asked of a host's execution already stopping forces it. +func (a *App) runToolbar(c ui.C, p *project, run *runEntry) { + ui.Column(c).FillHeight().Shrink(0).Gap(2).Pad(4).Children(func() { + rerunnable := run.restart != nil && p.build.operation == nil || run.restart == nil && run.rerun != nil + if a.runToolButton(c.Part("rerun"), a.text.Run.Rerun, icons.RotateCcw, a.colors.Success, run.running || !rerunnable) { + c.After(func() { a.rerunRun(p, run) }) + } + stop := a.text.Build.Stop + if run.operation != nil && run.operation.cancelled { + stop = i18n.Shared(a.language(), "desktop.process.forceStop") + } + if a.runToolButton(c.Part("stop"), stop, icons.Square, a.theme.Danger, !run.running) { + c.After(func() { a.stopRun(p, run) }) + } + }) +} + +// runToolButton declares an action of the Run window's toolbars: its icon in tint, as IDEA tints +// rerun and stop, dimmed and inert while disabled, and naming the action when the pointer rests +// on it. It reports a click. Viva's icon buttons draw their icon in the text color, so the +// toolbars draw their own. +func (a *App) runToolButton(c ui.C, label string, icon gfx.Icon, tint gfx.Color, disabled bool) bool { + options := gfx.HitOptions{Role: gfx.RoleButton, Disabled: disabled} + if !disabled { + options.Cursor = gfx.PointerCursorHand + } + button := ui.Row(c).Size(shellHideSize, shellHideSize).Shrink(0).Center().Radius(a.theme.Metrics.RadiusItem()). + HitWith(ui.ID(c), label, options).Tooltip(label) + if !disabled { + button = button.Hover(ui.Look{}.Background(a.colors.Hover)).Pressed(ui.Look{}.Background(a.colors.Active)) + } + button.Children(func() { + mark := ui.Icon(c, icon).Size(runToolIcon, runToolIcon) + if disabled { + mark.Color(a.colors.Subtle).Opacity(0.5) + } else { + mark.Color(tint) + } + }) + return !disabled && button.Clicked() +} + +// runPanes declares the execution's tree beside its console, with the divider between them. +func (a *App) runPanes(c ui.C, p *project, run *runEntry) { + split := &p.panels.runSplit + if split.Ratio <= 0 { + split.Ratio = runTreeRatio + } + var tree, console ui.Box + ui.Row(c).Fill().Clip().Children(func() { + tree = ui.Column(c.Part("tree")).Children(func() { a.runTree(c, p, run) }) + ui.Splitter(c, split).Mins(runTreeMinWidth, runConsoleMinWidth).Label(a.text.Panel.Resize) + console = ui.Row(c.Part("console")).Children(func() { a.runConsole(c, p, run) }) + }) + tree.FillHeight().MinWidth(runTreeMinWidth).Shrink(1) + console.Fill().MinWidth(runConsoleMinWidth) +} + +// runTree declares the tree of the selected execution, as IDEA's Run window shows one: the +// execution, with its status icon, its name in bold, when it started and, once it ended, how long +// it took at the end of the row; under it how it ended, or the status line of the host's +// execution still going. When the row is too narrow, the start gives way before the name. +func (a *App) runTree(c ui.C, p *project, run *runEntry) { + status := a.runStatusText(run) + duration := "" + if !run.running { + duration = a.text.Run.Duration(int(run.ended.Sub(run.started).Milliseconds())) + } + ui.Column(c).Fill().Clip().PadY(4).Children(func() { + k := c.Part("root") + label := run.label + ", " + status + if duration != "" { + label += ", " + duration + } + ui.Row(k).FillWidth().Height(buildRowHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8). + HitWith(ui.ID(k), label, gfx.HitOptions{Role: gfx.RoleStatus, SkipFocus: true}).Tooltip(status). + Children(func() { + a.runStatusMark(k, run, runTreeIcon) + // The start follows the name with no gap, since its words begin with the separator. + ui.Row(k).Shrink(1).MinWidth(0).Items(ui.Center).Children(func() { + ui.Text(k, run.label).Color(a.colors.Text).Weight(gfx.WeightBold).Ellipsis().Shrink(1) + ui.Text(k, a.text.Run.StartedAt(run.started.Format(runStartedLayout))).Color(a.colors.Subtle). + Ellipsis().Shrink(buildDetailShrink) + }) + ui.Spacer(k) + if duration != "" { + ui.Text(k, duration).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Shrink(0) + } + }) + if detail := runDetail(p, run); detail != "" { + // Indented under the root's name, past its icon and the gap after it. + ui.Row(c).FillWidth().Height(buildRowHeight).Shrink(0).Items(ui.Center).PadSides(0, 8, 0, 8+runTreeIcon+6).Children(func() { + ui.Text(c, detail).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1) + }) + } + }) +} + +// runDetail is the line under an execution in the tree: how it ended, else, while the host's +// execution runs, the Build window's status of it; empty for a plugin's run still going. +func runDetail(p *project, run *runEntry) string { + if run.summary != "" { + return run.summary + } + if run.operation != nil && p.build.operation == run.operation { + return p.build.status + } + return "" +} + +// runStatusMark declares the icon of where an execution stands, size pixels square, as IDEA marks +// one: a spinner while it runs, a green check once it succeeded, a red cross once it failed, and +// a grey slash once the user stopped it. +func (a *App) runStatusMark(c ui.C, run *runEntry, size float32) { + k := c.Part("status") + if run.running { + ui.Spinner(k).Size(size, size).Shrink(0) + return + } + icon, tint := icons.CircleCheck, a.colors.Success + switch run.outcome { + case runFailed: + icon, tint = icons.CircleX, a.theme.Danger + case runStopped: + icon, tint = icons.CircleSlash, a.colors.Subtle + } + ui.Icon(k, icon).Size(size, size).Shrink(0).Color(tint) +} + +// runStatusText names where an execution stands, the words its status icon stands for. +func (a *App) runStatusText(run *runEntry) string { + t := a.text.Run + switch { + case run.running: + return t.Running + case run.outcome == runFailed: + return t.Failed + case run.outcome == runStopped: + return t.Stopped + default: + return t.Succeeded + } +} + +// runConsole declares the selected execution's console: the CPU and memory of a plugin's run +// above its output, which shows the colors and links it printed and keeps to its end while +// lines arrive, then the console's own actions on its right: scroll to the end and clear. A +// clear drops the lines the console holds, as trimming does, so a reader of the IDE API that +// asks past them is told of the gap. +func (a *App) runConsole(c ui.C, p *project, run *runEntry) { + ui.Column(c).Grow(1).Shrink(1).MinWidth(0).FillHeight().Clip().Children(func() { + a.runPerformanceChart(c, run) + if run.output.empty() { + ui.Row(c).FillWidth().Grow(1).Items(ui.Center).PadX(shellContentPad).Children(func() { + ui.Text(c, a.text.Build.EmptyOutput).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() + }) + return + } + menu := &outputMenu{ + key: "runsnapshot/" + run.id, + all: run.output.all, + extra: func(menu *ui.MenuItems) { + if menu.Item(a.text.Run.Snapshot.Menu).Clicked() { + c.After(func() { a.snapshotRunOutput(p, run) }) + } + }, + } + a.outputList(c, p, &run.list, outputScopeRun, a.text.Build.Output, &run.output, 0, menu).Grow(1) + }) + ui.Divider(c) + lang := a.language() + ui.Column(c).FillHeight().Shrink(0).Gap(2).Pad(4).Children(func() { + empty := run.output.empty() + if a.runToolButton(c.Part("end"), i18n.Shared(lang, "git.console.scrollToEnd"), icons.ArrowDownToLine, a.colors.Text, empty) { + c.After(func() { run.list.ScrollToEnd() }) + } + if a.runToolButton(c.Part("clear"), i18n.Shared(lang, "git.console.clear"), icons.Trash2, a.colors.Text, empty) { + c.After(func() { run.output.clear() }) + } + }) +} + +// showBuildConsole brings the Run window forward, for an action of the Build window that prints +// there, on the host's execution that runs; a run a plugin starts selects its own tab when it +// starts. +func (a *App) showBuildConsole(p *project) { + if operation := p.build.operation; operation != nil && operation.session != nil { + p.build.view = operation.session.id + } + a.openToolWindow(itemRun) +} diff --git a/desktop/internal/workbench/run_view_test.go b/desktop/internal/workbench/run_view_test.go new file mode 100644 index 0000000000..e48bd94f88 --- /dev/null +++ b/desktop/internal/workbench/run_view_test.go @@ -0,0 +1,71 @@ +package workbench + +import ( + "encoding/json" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/vivaui/viva/gfx" +) + +// The Run window gives each execution of the host its own tab, the newest selected. The tree +// beside the console says how the selected execution ended and how long it took, the console +// shows its output with the escapes decoded away, and a finished tab's × closes it and selects +// the neighbour that takes its place. +func TestRunWindowGivesEachExecutionATab(t *testing.T) { + h := newHarnessWithLanguages(t, &testKernel{Client: core.NewClient()}, []string{"en-US"}) + h.open(t.TempDir()) + p := h.app.project + text := h.app.text.Run + h.app.post(func(a *App) { + compile := a.beginBuildOperation(p, "build", "compile", "", nil) + feedBuildOutput(a, p, compile, "[\x1b[1;34mINFO\x1b[m] compiled\n") + a.finishBuildTask(p, compile, json.RawMessage(`{"exitCode":0}`)) + check := a.beginBuildOperation(p, "build", "check", "", nil) + a.finishBuildTask(p, check, json.RawMessage(`{"exitCode":1}`)) + a.reduceChrome(core.SetChromeOpen(itemRun, true)) + }) + h.settle() + h.settle() + + compileTab, checkTab := h.pageHit("compile"), h.pageHit("check") + if compileTab.Role != gfx.RoleTab || checkTab.Role != gfx.RoleTab || compileTab.Selected || !checkTab.Selected { + t.Fatalf("tabs compile %+v and check %+v, want two tabs with the newest selected", compileTab, checkTab) + } + // The virtual clock does not move inside one post, so each execution took no time. + if _, ok := h.findPageHit("check, " + text.Failed + ", " + text.Duration(0)); !ok { + t.Fatal("the tree does not say the selected execution failed and how long it took") + } + + h.clickNamed("compile") + h.settle() + if _, ok := h.findPageHit("compile, " + text.Succeeded + ", " + text.Duration(0)); !ok { + t.Fatal("choosing a tab does not show its execution in the tree") + } + // A styled line draws one label for each run of the same style. + if !h.shows("INFO") || !h.shows("] compiled") || h.shows("\x1b") || h.shows("[1;34m") { + t.Fatal("the console does not show the execution's output without its escapes") + } + + h.click(center(closeButtonIn(h, h.pageHit("compile").Bounds, text.CloseSession).Bounds)) + h.settle() + if len(p.build.runs) != 1 || p.activeRun() == nil || p.activeRun().label != "check" { + t.Fatalf("closing the shown tab left %d tabs showing %v, want the check tab alone", len(p.build.runs), p.activeRun()) + } + if _, ok := h.findPageHit("compile"); ok { + t.Fatal("the closed tab stays on screen") + } +} + +// closeButtonIn is the control named label inside the bounds of tab. +func closeButtonIn(h *harness, tab gfx.Rect, label string) gfx.Hit { + h.t.Helper() + for _, hit := range h.driver.Snapshot().Hits { + b := hit.Bounds + if hit.Label == label && !hit.IsLabel && b.X >= tab.X && b.Y >= tab.Y && b.X+b.Width <= tab.X+tab.Width && b.Y+b.Height <= tab.Y+tab.Height { + return hit + } + } + h.t.Fatalf("no %q control inside the tab at %+v", label, tab) + return gfx.Hit{} +} diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index de03c0dd39..9e41f2f69b 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -176,7 +176,9 @@ func (a *App) startRunConfiguration(p *project, id string) (*buildOperation, err return nil, refuseBuild(refusalNotReady, a.text.Build.TargetMissing) } a.emit(core.LevelInfo, "app.action.performed", map[string]any{"action": "run.configuration", "surface": "build"}) - op := a.beginBuildOperation(p, "run", configuration.Name, id) + op := a.beginBuildOperation(p, "run", configuration.Name, id, func(a *App, p *project) { + a.runConfiguration(p, id) + }) // The run starts a process on the files on disk, so unsaved documents are saved first, // as a rerun does; a failed save keeps the run from starting. The save reports its own // failure, so the window's status only drops the preparation. @@ -186,9 +188,7 @@ func (a *App) startRunConfiguration(p *project, id string) (*buildOperation, err return } if !ok { - if a.endBuildOperation(p, op, "failed", nil, "unsaved documents could not be saved") { - p.build.status = "" - } + a.endBuildOperation(p, op, "failed", nil, "unsaved documents could not be saved", "") return } root, kernel := p.root, a.kernel diff --git a/desktop/internal/workbench/runpanels.go b/desktop/internal/workbench/runpanels.go index 03169a8cbc..211297da68 100644 --- a/desktop/internal/workbench/runpanels.go +++ b/desktop/internal/workbench/runpanels.go @@ -11,9 +11,11 @@ type runPanels struct { // the text the tree's filter field edits in place. buildOpen map[string]bool buildFilter string - // choices is the Build window's tree of every build system, and output the Run window's - // console of what the Build window runs. - choices, output ui.ListState + // choices is the Build window's tree of every build system. runSplit is the Run window's + // divider between its execution tree and the selected execution's console; each + // execution keeps its own console list (runEntry.list). + choices ui.ListState + runSplit ui.SplitterState // testResults is the grouped result list, testOutput the console of a run that // failed before reporting results. testResults, testOutput ui.ListState diff --git a/desktop/internal/workbench/runs.go b/desktop/internal/workbench/runs.go index d8634a8cd0..d6116ec44c 100644 --- a/desktop/internal/workbench/runs.go +++ b/desktop/internal/workbench/runs.go @@ -4,8 +4,9 @@ import ( "context" "errors" "path/filepath" + "slices" "strconv" - "strings" + "sync" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -17,12 +18,11 @@ import ( ) const ( - // runOutputMaxLines, runOutputLineSize and runOutputBytes bound one run's - // console like the build console: whole lines, oldest dropped first. + // runOutputMaxLines and runOutputBytes bound one run's console like the build + // console: whole lines, oldest dropped first. runOutputMaxLines = 4000 - runOutputLineSize = 16 << 10 runOutputBytes = 4 << 20 - // maxRunEntries bounds the finished runs the panel keeps. + // maxRunEntries bounds the sessions the Run window keeps; the oldest finished go first. maxRunEntries = 8 // runStopWait bounds the background stop of the runs of a closing project. runStopWait = 30 * time.Second @@ -30,19 +30,38 @@ const ( runRerunTimeout = 90 * time.Second ) -// runEntry is one plugin-started run the host presents: its console, whether it is -// still going, and how it ended. The process itself belongs to the plugin -// service, which also owns stopping it. +// runOutcome is where a session's execution stands, which its status icon shows. +type runOutcome uint8 + +const ( + runActive runOutcome = iota + runSucceeded + runFailed + runStopped +) + +// runEntry is one session of the Run window: an execution the Build window, a run +// configuration or the IDE API started (operation, while it runs), or a run a plugin +// started (pluginID). It keeps the execution's console, when it started and ended, and +// how. A plugin's process belongs to the plugin service, which also owns stopping it. type runEntry struct { - id string + id string + // pluginID is the plugin that started the run, "" for an execution of the host. pluginID string label string rerun *pluginservice.RunRerun - // output holds whole lines, oldest first; outputBytes is their size. - output []string - outputBytes int - running bool - // summary is how the run ended, shown under the console. + // restart starts the host's execution again; nil for a plugin's run. + restart func(*App, *project) + // operation is the host's execution writing the session, nil once it ended. + operation *buildOperation + // output is the console, decoded from the execution's ANSI escapes. + output outputBuffer + running bool + outcome runOutcome + // stopping is set when the user stopped a plugin's run, so its end reads as stopped. + stopping bool + started, ended time.Time + // summary is how the execution ended, shown under the console. summary string // list is the console's scroll state. list ui.ListState @@ -66,11 +85,56 @@ func (a *App) wirePluginRuns() { runs.LaunchDebug = a.launchDebugForRun runs.StartDebugSession = a.startDebugForBackend runs.StopDebugSession = a.stopDebugForBackend + decoders := &runDecoders{byID: map[string]*outputDecoder{}} runs.SetObserver(func(event pluginservice.RunEvent) { + // Output is decoded here, on the goroutine that read it, so the window thread + // only adds the decoded lines. + switch event.Type { + case pluginservice.RunStarted: + decoders.start(event.RunID, newOutputDecoder(a.kernel)) + case pluginservice.RunOutput: + if decoder := decoders.get(event.RunID); decoder != nil { + id := event.RunID + decoder.deliver(event.Text, func(chunk outputChunk, failure error) { + a.post(func(a *App) { + a.reportOutputStyleFailure(failure) + a.applyRunOutput(id, chunk) + }) + }) + return + } + case pluginservice.RunExited: + decoders.end(event.RunID) + } a.post(func(a *App) { a.applyRunEvent(event) }) }) } +// runDecoders are the output decoders of the plugin runs that are going, by run ID. The +// plugin service's goroutines use them; the window thread never does. +type runDecoders struct { + mu sync.Mutex + byID map[string]*outputDecoder +} + +func (d *runDecoders) start(id string, decoder *outputDecoder) { + d.mu.Lock() + defer d.mu.Unlock() + d.byID[id] = decoder +} + +func (d *runDecoders) get(id string) *outputDecoder { + d.mu.Lock() + defer d.mu.Unlock() + return d.byID[id] +} + +func (d *runDecoders) end(id string) { + d.mu.Lock() + defer d.mu.Unlock() + delete(d.byID, id) +} + // resolveRunTool resolves a tool a run needs through the same toolchain layers // Build and Debug use: project pins, user choices, then discovery. func (a *App) resolveRunTool(ctx context.Context, workspaceRoot, tool string) (pluginservice.RunExecutable, error) { @@ -151,38 +215,22 @@ func (a *App) applyRunEvent(event pluginservice.RunEvent) { return } p.links.loaded, p.links.sources = false, nil - entry := &runEntry{id: event.RunID, pluginID: event.PluginID, label: event.Label, rerun: event.Rerun, running: true} - p.build.runs = append(p.build.runs, entry) + entry := &runEntry{ + id: event.RunID, pluginID: event.PluginID, label: event.Label, rerun: event.Rerun, running: true, + started: a.now(), output: newOutputBuffer(runOutputMaxLines, runOutputBytes), + } + a.addRunSession(p, entry) if event.PID > 0 { a.startRunSampling(entry, event.PID) } - for len(p.build.runs) > maxRunEntries { - dropped := false - for index, candidate := range p.build.runs { - if !candidate.running { - p.build.runs = append(p.build.runs[:index], p.build.runs[index+1:]...) - dropped = true - break - } - } - if !dropped { - break - } - } - p.build.view = entry.id - if !a.chrome.isOpen(catalogIndex[itemRun]) { - a.reduceChrome(core.ToggleChrome(itemRun)) - } - case pluginservice.RunOutput: - if entry := p.runEntry(event.RunID); entry != nil { - entry.append(event.Text) - } + a.openToolWindow(itemRun) case pluginservice.RunExited: entry := p.runEntry(event.RunID) - if entry == nil { + if entry == nil || !entry.running { return } - entry.running = false + entry.output.seal() + entry.running, entry.ended = false, a.now() if entry.stopSampling != nil { entry.stopSampling() entry.stopSampling = nil @@ -196,6 +244,66 @@ func (a *App) applyRunEvent(event pluginservice.RunEvent) { default: entry.summary = messages.Ended } + switch { + case entry.stopping: + entry.outcome = runStopped + case event.ExitCode != nil && *event.ExitCode != 0 || event.Signal != "": + entry.outcome = runFailed + default: + entry.outcome = runSucceeded + } + } +} + +// applyRunOutput adds decoded output to the console of a plugin's run. Output of a run +// the window does not show is dropped. +func (a *App) applyRunOutput(id string, chunk outputChunk) { + if p := a.project; p != nil { + if entry := p.runEntry(id); entry != nil && entry.running { + entry.output.apply(chunk) + } + } +} + +// addRunSession shows a new session in the Run window and selects it. A finished session +// with the same label gives its tab to the new one, as running something again replaces the +// tab of what it repeats; past maxRunEntries the oldest finished sessions go. +func (a *App) addRunSession(p *project, entry *runEntry) { + b := &p.build + replaced := false + for index, candidate := range b.runs { + if !candidate.running && candidate.label == entry.label { + b.runs[index], replaced = entry, true + break + } + } + if !replaced { + b.runs = append(b.runs, entry) + } + for len(b.runs) > maxRunEntries { + index := slices.IndexFunc(b.runs, func(candidate *runEntry) bool { return !candidate.running }) + if index < 0 { + break + } + b.runs = slices.Delete(b.runs, index, index+1) + } + b.view = entry.id +} + +// closeRunSession removes a finished session from the Run window; a session still running +// stays. The neighbour that takes its place is selected when it was the one shown. +func (p *project) closeRunSession(id string) { + b := &p.build + index := slices.IndexFunc(b.runs, func(candidate *runEntry) bool { return candidate.id == id }) + if index < 0 || b.runs[index].running { + return + } + b.runs = slices.Delete(b.runs, index, index+1) + if b.view == id { + b.view = "" + if len(b.runs) > 0 { + b.view = b.runs[min(index, len(b.runs)-1)].id + } } } @@ -208,37 +316,16 @@ func (p *project) runEntry(id string) *runEntry { return nil } -// activeRun is the run whose console the panel shows, or nil for the build console. +// activeRun is the session the Run window shows: the selected one, else the newest, or +// nil when it has none. func (p *project) activeRun() *runEntry { - if p.build.view == "" { - return nil - } - return p.runEntry(p.build.view) -} - -// append adds console text as whole lines, trimming the oldest when over budget. -func (r *runEntry) append(text string) { - for len(text) > 0 { - line := text - if index := strings.IndexByte(line, '\n'); index >= 0 { - line = text[:index+1] - text = text[index+1:] - } else { - text = "" - } - if len(line) > runOutputLineSize { - line = line[:runOutputLineSize] + "\n" - } - r.output = append(r.output, line) - r.outputBytes += len(line) + if entry := p.runEntry(p.build.view); entry != nil { + return entry } - for len(r.output) > runOutputMaxLines || r.outputBytes > runOutputBytes { - if len(r.output) == 0 { - break - } - r.outputBytes -= len(r.output[0]) - r.output = r.output[1:] + if len(p.build.runs) > 0 { + return p.build.runs[len(p.build.runs)-1] } + return nil } // snapshotRunOutput freezes the output the console holds now into a read-only tab. The @@ -246,10 +333,10 @@ func (r *runEntry) append(text string) { // tab unchanged; the tab is virtual, so it is never saved or watched and nothing closes it // on its own. func (a *App) snapshotRunOutput(p *project, entry *runEntry) { - if p == nil || entry == nil || len(entry.output) == 0 { + if p == nil || entry == nil || entry.output.empty() { return } - text := strings.Join(entry.output, "") + text := entry.output.all() entry.snapshots++ uri := "lithe-run-snapshot:" + entry.id + "/" + strconv.Itoa(entry.snapshots) content := editorview.Prepare([]byte(text)) @@ -261,12 +348,23 @@ func (a *App) snapshotRunOutput(p *project, entry *runEntry) { } } -// stopRun asks the plugin service to end a run. The process tree is stopped and -// reaped on a background goroutine, so the window never waits for it. +// stopRun ends a session: the host's execution through the Build window's stop, a +// plugin's run through the plugin service, which stops and reaps the process tree on a +// background goroutine, so the window never waits for it. func (a *App) stopRun(p *project, entry *runEntry) { - if a.plugins == nil || entry == nil || !entry.running { + if entry == nil || !entry.running { return } + if entry.pluginID == "" { + if entry.operation != nil && p.build.operation == entry.operation { + a.stopBuildOperation(p) + } + return + } + if a.plugins == nil { + return + } + entry.stopping = true runs, id := a.plugins.Runs, entry.id a.background(p, runStopWait, func(context.Context) func(*App) { runs.Stop(id) @@ -274,10 +372,18 @@ func (a *App) stopRun(p *project, entry *runEntry) { }) } -// rerunRun asks the plugin to start the run again. The plugin answers with a new -// run/start, which arrives as a new entry. +// rerunRun starts a finished session again: the host's execution through what started it, +// a plugin's run by asking the plugin, which answers with a new run/start that arrives as +// a new session in the old one's tab. func (a *App) rerunRun(p *project, entry *runEntry) { - if a.plugins == nil || entry == nil || entry.running || entry.rerun == nil { + if entry == nil || entry.running { + return + } + if entry.restart != nil { + entry.restart(a, p) + return + } + if a.plugins == nil || entry.rerun == nil { return } runs, rerun := a.plugins.Runs, *entry.rerun diff --git a/desktop/internal/workbench/settings_plugin_effects_test.go b/desktop/internal/workbench/settings_plugin_effects_test.go index fd82841586..75b29e9727 100644 --- a/desktop/internal/workbench/settings_plugin_effects_test.go +++ b/desktop/internal/workbench/settings_plugin_effects_test.go @@ -13,11 +13,11 @@ func TestPluginSettingsReloadInvalidatesOnlyOwningModelsAndKeepsRunningTask(t *t h := newHarness(t, &testKernel{Client: core.NewClient()}) h.open(t.TempDir()) p := h.app.project - running := &buildOperation{} - p.build = buildState{selected: 1, operation: running, instances: []buildInstance{ + running := h.app.beginBuildOperation(p, "build", "build", "", nil) + p.build.selected, p.build.instances = 1, []buildInstance{ {BuildInstance: core.BuildInstance{ID: "changed"}, PluginID: "changed.plugin", modelLoaded: true, modelLoading: true}, {BuildInstance: core.BuildInstance{ID: "unrelated"}, PluginID: "other.plugin", modelLoaded: true}, - }} + } h.app.reloadPluginBuildModels(p, "changed.plugin") if p.build.operation != running || p.build.operation.cancelled { t.Fatal("model reload stopped a running task") diff --git a/desktop/internal/workbench/shell_view.go b/desktop/internal/workbench/shell_view.go index ed8ddd5f1d..e539ef82d5 100644 --- a/desktop/internal/workbench/shell_view.go +++ b/desktop/internal/workbench/shell_view.go @@ -85,7 +85,7 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { p := a.project tabbed := tool.id == itemGit header := float32(toolTitleHeight) - if tabbed || tool.id == itemTerminal || tool.id == itemCommit { + if tabbed || tool.id == itemTerminal || tool.id == itemCommit || tool.id == itemRun { header = panelHeaderHeight } if tool.id == itemFind && p != nil { @@ -109,10 +109,14 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { if tabbed { a.gitTabs(c) } - if tool.id == itemTerminal && p != nil { + switch { + case tool.id == itemTerminal && p != nil: // The tabs of the open project's terminals take the room a spacer would. a.terminalTabs(c) - } else { + case tool.id == itemRun && p != nil: + // So do the tabs of the Run window's executions. + a.runSessionTabs(c, p) + default: ui.Spacer(c) } if tool.id == itemProject && p != nil { diff --git a/desktop/internal/workbench/tests.go b/desktop/internal/workbench/tests.go index 875301325e..c137f62762 100644 --- a/desktop/internal/workbench/tests.go +++ b/desktop/internal/workbench/tests.go @@ -28,7 +28,6 @@ const ( // The result console and the failure detail are bounded like build output so // a chatty test tool cannot grow the window without limit. testOutputMaxLines = 2000 - testOutputLineSize = 16 << 10 testOutputBytes = 2 << 20 // testMaxRows bounds the flattened result tree. Core already caps decoded // cases at 10 000; the tree keeps the same ceiling so a future Core change @@ -46,9 +45,8 @@ type testState struct { failed string // status is the last progress line under the toolbar. status string - // output is the bounded console, oldest lines first. - output []string - outputBytes int + // output is the bounded console, decoded from the run's ANSI escapes. + output outputBuffer results core.BuildTestResults verdict core.BuildTestVerdict @@ -212,8 +210,7 @@ func (a *App) startTests(p *project, selection testSelection) { p.tests.results = core.BuildTestResults{} p.tests.verdict = core.BuildTestVerdict{} p.tests.rows = nil - p.tests.output = nil - p.tests.outputBytes = 0 + p.tests.output = newOutputBuffer(testOutputMaxLines, testOutputBytes) p.tests.status = a.text.Tests.Preparing last := selection p.tests.last = &last @@ -256,6 +253,7 @@ func (a *App) executeTestCommand(ctx context.Context, p *project, instance build return func(a *App) { a.finishTestError(p, generation, err) } } output := &testOutput{} + decoder := newOutputDecoder(a.kernel) operation := &testOperation{} workingDirectory := filepath.Join(p.root, filepath.FromSlash(plan.WorkingDirectory)) process, err := buildprocess.Start(ctx, buildprocess.Spec{ @@ -266,7 +264,7 @@ func (a *App) executeTestCommand(ctx context.Context, p *project, instance build Environment: applyToolchainSelection(plan.Environment, executable.selection()), }, func(_ buildprocess.Stream, text string) { output.append(text) - a.post(func(a *App) { a.appendTestOutput(p, generation, text) }) + a.streamTestOutput(p, generation, decoder, text) }) if err != nil { return func(a *App) { a.finishTestError(p, generation, err) } @@ -312,6 +310,7 @@ func (a *App) executeTestProvider(ctx context.Context, p *project, instance buil p.tests.status = a.text.Tests.Running }) output := &testOutput{} + decoder := newOutputDecoder(a.kernel) var providerResult json.RawMessage for { select { @@ -321,7 +320,7 @@ func (a *App) executeTestProvider(ctx context.Context, p *project, instance buil } if progress.Output != "" { output.append(progress.Output) - a.post(func(a *App) { a.appendTestOutput(p, generation, progress.Output) }) + a.streamTestOutput(p, generation, decoder, progress.Output) } if progress.Message != "" { message := progress.Message @@ -357,7 +356,7 @@ completed: } if execution.Output != "" && output.len() == 0 { output.append(execution.Output) - a.post(func(a *App) { a.appendTestOutput(p, generation, execution.Output) }) + a.streamTestOutput(p, generation, decoder, execution.Output) } providerResult = execution.TestResults request := testResultsRequest(p, instance, selection, output.text(), providerResult, startedMillis) @@ -436,6 +435,7 @@ func (a *App) finishTestRun(p *project, generation uint64, selection testSelecti a.finishTestError(p, generation, err) return } + p.tests.output.seal() p.tests.operation = nil p.tests.running = false p.tests.stopping = false @@ -457,6 +457,7 @@ func (a *App) finishTestInterrupted(p *project, generation uint64, selection tes a.finishTestError(p, generation, err) return } + p.tests.output.seal() p.tests.operation = nil p.tests.running = false p.tests.stopping = false @@ -477,6 +478,7 @@ func (a *App) finishTestError(p *project, generation uint64, err error) { if a.project != p || p.tests.generation != generation { return } + p.tests.output.seal() p.tests.operation = nil p.tests.running = false p.tests.stopping = false @@ -565,29 +567,20 @@ func flattenTestRows(results core.BuildTestResults) []testRow { return rows } -// appendTestOutput adds one chunk to the bounded console, keeping whole lines -// where possible as the Build window does. -func (a *App) appendTestOutput(p *project, generation uint64, text string) { - if p == nil || a.project != p || p.tests.generation != generation || text == "" { +// streamTestOutput decodes text the test run of generation wrote, on the goroutine that read +// it, and posts the decoded lines to the window thread. It never runs on the window thread. +func (a *App) streamTestOutput(p *project, generation uint64, decoder *outputDecoder, text string) { + if text == "" { return } - for len(text) > 0 { - line := text - if newline := strings.IndexByte(text, '\n'); newline >= 0 { - line, text = text[:newline+1], text[newline+1:] - } else { - text = "" - } - if len(line) > testOutputLineSize { - line = line[:testOutputLineSize] - } - p.tests.output = append(p.tests.output, line) - p.tests.outputBytes += len(line) - } - for len(p.tests.output) > testOutputMaxLines || (p.tests.outputBytes > testOutputBytes && len(p.tests.output) > 1) { - p.tests.outputBytes -= len(p.tests.output[0]) - p.tests.output = p.tests.output[1:] - } + decoder.deliver(text, func(chunk outputChunk, failure error) { + a.post(func(a *App) { + a.reportOutputStyleFailure(failure) + if p != nil && a.project == p && p.tests.generation == generation { + p.tests.output.apply(chunk) + } + }) + }) } // formatTestDuration renders a decoded duration without inventing precision. diff --git a/desktop/internal/workbench/tests_test.go b/desktop/internal/workbench/tests_test.go index 3306911d63..6559b3c6b8 100644 --- a/desktop/internal/workbench/tests_test.go +++ b/desktop/internal/workbench/tests_test.go @@ -290,12 +290,17 @@ func TestTestsPanelDropsStaleResultAndBoundsOutput(t *testing.T) { } p.tests.generation = 3 - h.app.appendTestOutput(p, 3, strings.Repeat("line\n", testOutputMaxLines+50)) - if len(p.tests.output) > testOutputMaxLines { - t.Fatalf("output has %d lines, want at most %d", len(p.tests.output), testOutputMaxLines) + p.tests.output = newOutputBuffer(testOutputMaxLines, testOutputBytes) + decoder := newOutputDecoder(h.app.kernel) + h.app.streamTestOutput(p, 2, decoder, "stale\n") + h.app.streamTestOutput(p, 3, decoder, strings.Repeat("line\n", testOutputMaxLines+50)) + h.settle() + output := &p.tests.output + if len(output.lines) > testOutputMaxLines || output.lines[0].text != "line" { + t.Fatalf("output has %d lines starting %q, want at most %d of this run's", len(output.lines), output.lines[0].text, testOutputMaxLines) } - if p.tests.outputBytes > testOutputBytes { - t.Fatalf("output has %d bytes, want at most %d", p.tests.outputBytes, testOutputBytes) + if output.bytes > testOutputBytes { + t.Fatalf("output has %d bytes, want at most %d", output.bytes, testOutputBytes) } } diff --git a/desktop/internal/workbench/tests_view.go b/desktop/internal/workbench/tests_view.go index 45a61362ad..b89e197b51 100644 --- a/desktop/internal/workbench/tests_view.go +++ b/desktop/internal/workbench/tests_view.go @@ -3,7 +3,6 @@ package workbench import ( "path/filepath" "strconv" - "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/gfx" @@ -191,14 +190,11 @@ func (a *App) testStatusMark(status string) (gfx.Icon, gfx.Color) { // testOutput shows the tail of a run that failed before reporting results, // bounded to the same console budget the run kept. func (a *App) testOutput(c ui.C, p *project) { - if len(p.tests.output) == 0 { + output := &p.tests.output + if output.empty() { return } - lines := p.tests.output - if len(lines) > 12 { - lines = lines[len(lines)-12:] - } ui.Divider(c) - menu := &outputMenu{key: "testoutput", all: func() string { return strings.Join(p.tests.output, "\n") }} - a.outputList(c, p, &p.panels.testOutput, outputScopeTest, a.text.Build.Output, lines, menu).Height(140).Shrink(0) + menu := &outputMenu{key: "testoutput", all: output.all} + a.outputList(c, p, &p.panels.testOutput, outputScopeTest, a.text.Build.Output, output, output.count()-12, menu).Height(140).Shrink(0) } diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index ad70e23418..8a679a8569 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -28,7 +28,10 @@ native_path() { } PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" -# Lithe-core-rust #43 (branch feat/process-memory-summary, not yet merged): processMemory.summarize +# Lithe-core-rust #44 (branch feat/console-ansi-style, not yet merged): outputStyle.decode turns +# console output with ANSI escapes into plain lines and styled ranges, carrying each console's +# state from chunk to chunk, for the colors of the Run, Build and Test consoles. It is on top of +# #43, squash-merged into main: processMemory.summarize # sorts the native process table into the parts of a Lithe instance (main process, language # servers, plugin services, their child processes and the system helpers macOS holds the main # process responsible for) for the memory details of the status bar. It is on top of #42, @@ -85,7 +88,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="5e2a5803966c953004f4c9730d91c156b64f422e" +PINNED_CORE_REVISION="cdc025851e0b291f00415d9d4e43ce9079e1e83e" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 8054cdeea0..1fd7db45ec 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -1332,7 +1332,12 @@ "desktop.project.rootUnavailable": "The project directory is unavailable.", "desktop.project.watchUnavailable": "Project files may not update automatically.", "desktop.references.empty": "Run Find Usages (Shift+F12) to list references here.", - "desktop.run.build": "Build", + "desktop.run.closeSession": "Close", + "desktop.run.durationHours": "{hours} h {minutes} min", + "desktop.run.durationMilliseconds": "{milliseconds} ms", + "desktop.run.durationMinutes": "{minutes} min {seconds} s", + "desktop.run.durationSeconds": "{seconds} s {milliseconds} ms", + "desktop.run.empty": "Output of run configurations and build tasks appears here.", "desktop.run.ended": "Process finished.", "desktop.run.exited": "Process finished with exit code {code}.", "desktop.run.linkMissing": "The linked file was not found in the workspace.", @@ -10757,6 +10762,11 @@ "desktop.nativePanel.failed": "The plugin could not run this action.", "desktop.run.performance.cpu": "CPU {percent}%", "desktop.run.performance.memory": "Memory {megabytes} MB", + "desktop.run.startedAt": ": at {time}", + "desktop.run.statusFailed": "Failed", + "desktop.run.statusRunning": "Running", + "desktop.run.statusStopped": "Stopped", + "desktop.run.statusSucceeded": "Succeeded", "desktop.nativePanel.noInstance": "This workspace has no build system instance for this panel.", "desktop.nativePanel.multipleInstances": "This workspace has several build system instances; the panel cannot choose one.", "desktop.nativePanel.sourceFailed": "The plugin could not load this panel.", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 97b8eca96b..71eba9f101 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -1332,7 +1332,12 @@ "desktop.project.rootUnavailable": "项目目录不可用。", "desktop.project.watchUnavailable": "项目文件可能无法自动更新。", "desktop.references.empty": "使用“查找引用”(Shift+F12)后,结果显示在这里。", - "desktop.run.build": "构建", + "desktop.run.closeSession": "关闭", + "desktop.run.durationHours": "{hours}小时{minutes}分", + "desktop.run.durationMilliseconds": "{milliseconds}毫秒", + "desktop.run.durationMinutes": "{minutes}分{seconds}秒", + "desktop.run.durationSeconds": "{seconds}秒{milliseconds}毫秒", + "desktop.run.empty": "运行配置和构建任务的输出将显示在这里。", "desktop.run.ended": "进程已结束。", "desktop.run.exited": "进程已结束,退出码 {code}。", "desktop.run.linkMissing": "在工作区中找不到链接指向的文件。", @@ -10757,6 +10762,11 @@ "desktop.nativePanel.failed": "插件无法执行此操作。", "desktop.run.performance.cpu": "CPU {percent}%", "desktop.run.performance.memory": "内存 {megabytes} MB", + "desktop.run.startedAt": ": 在 {time}", + "desktop.run.statusFailed": "失败", + "desktop.run.statusRunning": "正在运行", + "desktop.run.statusStopped": "已停止", + "desktop.run.statusSucceeded": "成功", "desktop.nativePanel.noInstance": "此工作区没有该面板需要的构建系统实例。", "desktop.nativePanel.multipleInstances": "此工作区有多个构建系统实例,面板无法选择。", "desktop.nativePanel.sourceFailed": "插件无法加载此面板。", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 6e6fea4038..ecaf8a24e7 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -13997,8 +13997,58 @@ } }, { - "id": "desktop.run.build", - "description": "Name of the build output in the run output switcher", + "id": "desktop.run.closeSession", + "description": "Close button of a finished execution's tab in the Run tool window", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.durationHours", + "description": "How long an execution took, at least an hour. {hours} and {minutes} are whole numbers.", + "platforms": [ + "desktop" + ], + "parameters": { + "hours": "string", + "minutes": "string" + } + }, + { + "id": "desktop.run.durationMilliseconds", + "description": "How long an execution took, under a second. {milliseconds} is a whole number.", + "platforms": [ + "desktop" + ], + "parameters": { + "milliseconds": "string" + } + }, + { + "id": "desktop.run.durationMinutes", + "description": "How long an execution took, at least a minute. {minutes} and {seconds} are whole numbers.", + "platforms": [ + "desktop" + ], + "parameters": { + "minutes": "string", + "seconds": "string" + } + }, + { + "id": "desktop.run.durationSeconds", + "description": "How long an execution took, at least a second. {seconds} and {milliseconds} are whole numbers.", + "platforms": [ + "desktop" + ], + "parameters": { + "seconds": "string", + "milliseconds": "string" + } + }, + { + "id": "desktop.run.empty", + "description": "Run tool window before anything ran", "platforms": [ "desktop" ] @@ -14088,6 +14138,44 @@ "label": "string" } }, + { + "id": "desktop.run.startedAt", + "description": "Follows an execution's name in the Run tool window's tree. {time} is the date and time it started.", + "platforms": [ + "desktop" + ], + "parameters": { + "time": "string" + } + }, + { + "id": "desktop.run.statusFailed", + "description": "Status of an execution that failed or exited with a non-zero code", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.statusRunning", + "description": "Status of an execution that is still running", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.statusStopped", + "description": "Status of an execution the user stopped", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.statusSucceeded", + "description": "Status of an execution that finished successfully", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.runConfig.arguments", "description": "Label of the program arguments field in the run configuration editor.", @@ -22857,7 +22945,8 @@ "id": "git.console.clear", "description": "Windows UI: git.console.clear", "platforms": [ - "windows" + "windows", + "desktop" ] }, { diff --git a/shared/platform-feature-matrix/features/debug-performance.json b/shared/platform-feature-matrix/features/debug-performance.json index bd87ed8343..054e3cda50 100644 --- a/shared/platform-feature-matrix/features/debug-performance.json +++ b/shared/platform-feature-matrix/features/debug-performance.json @@ -14,7 +14,7 @@ "desktop/internal/workbench/chrome.go", "desktop/internal/workbench/run_performance.go", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go" + "desktop/internal/workbench/run_view.go" ] }, "windows": { @@ -28,7 +28,7 @@ "desktop/internal/workbench/chrome.go", "desktop/internal/workbench/run_performance.go", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go" + "desktop/internal/workbench/run_view.go" ] }, "owner": "Debug", diff --git a/shared/platform-feature-matrix/features/plugin-backend-run-start.json b/shared/platform-feature-matrix/features/plugin-backend-run-start.json index 0fd67a3fc1..62e19f7508 100644 --- a/shared/platform-feature-matrix/features/plugin-backend-run-start.json +++ b/shared/platform-feature-matrix/features/plugin-backend-run-start.json @@ -12,7 +12,7 @@ "desktop/internal/core/run_start.go", "desktop/internal/core/run_start_test.go", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go", + "desktop/internal/workbench/run_view.go", ".agents/notes/implemented/architecture/2026-11-10-viva-java-admission-run-debug-output-links.md", "desktop/internal/workbench/debug_start.go", "desktop/internal/workbench/debug_test.go", @@ -28,7 +28,7 @@ "desktop/internal/core/run_start.go", "desktop/internal/core/run_start_test.go", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go", + "desktop/internal/workbench/run_view.go", ".agents/notes/implemented/architecture/2026-11-10-viva-java-admission-run-debug-output-links.md", "desktop/internal/workbench/debug_start.go", "desktop/internal/workbench/debug_test.go", @@ -37,7 +37,7 @@ }, "owner": "Extensions / Run", "verification": "macOS:用声明 requires.serverProcess 4 与 permissions run.start 的测试插件,让后端依次发起(1)工具 ID 运行:Run 窗口出现以 label 命名的条目,进程使用用户在设置里选中的安装,参数、工作目录和环境符合请求,插件显式给出的环境变量覆盖工具导出;(2)插件包内可执行文件运行,路径逃出包目录、文件不存在或不可执行时返回 plugin.host.notFound;(3)带 temporaryFiles 的运行,进程内能读到文件内容,结束后临时目录被删除;(4)带 debug.target connection 的运行,进程监听后调试器附加并命中断点,声明 target launch 时宿主不启动进程,由适配器按 targetBindings 启动程序并命中断点,Run 窗口停止该运行会结束调试会话,会话结束后运行条目以退出码结束;(5)带 rerun 的运行,在 Run 窗口点击再次运行会调用插件函数,函数失败时用户看到提示;(6)run/stop 只停止调用方插件的运行,用户点击停止后后端收到不带 exitCode 的 lithe/host/run/didExit,进程自然退出时收到 exitCode。工具未安装时返回 plugin.host.toolUnresolved,details.reason 为 notFound,所选安装不可运行时为 unusable,两种情况都不启动进程。禁用插件或后端退出后,已启动的进程继续运行,后端不再收到通知。远程工作区返回 plugin.host.authorityUnsupported。启动后 app bundle 文件清单不变(scripts/desktop/verify/verify-runtime-bundle-immutability.sh)。Windows:宿主尚未接入 run/start,Core 校验通过不代表 Windows 能运行插件请求的进程。", - "notes": "Viva 注册 run/start、run/stop 并在进程结束时发送 run/didExit(只发给发起它的那次后端会话);Core 的 run.decodeStart 校验参数,宿主解析工具或包内可执行文件、写入临时文件、启动进程并把输出放进 Build 面板里的运行视图,支持停止与再次运行。debug.target 为 connection 时等待端口打开再附加适配器;target 为 launch 时宿主不启动进程,而是按 configurationType 找到本插件能 launch 的适配器,把解析好的程序、参数、绝对工作目录与环境作为 executable 目标事实交给 Core,经适配器的 launch targetBindings 绑定后启动调试会话;运行条目代表该会话,停止运行即停止会话,会话释放后运行以 terminated 事件的退出码结束(适配器未报时不带 exitCode),进程输出在调试控制台。没有调试能力的宿主仍返回 plugin.host.unavailable。debug/start 已实现(见 plugin-debug-start-and-adapter-features)。原生产品验收仍 pending。 2026-11-13:插件 run/start 的调试附加与启动会按需读取适配器目录,不要求用户先打开 Debug 工具窗口;目录返回后检查调用取消,关闭项目不会启动旧请求。 Run 持有的进程在附加调试会话释放后由后台有界回收,Debug 工具栏停止不再留下暂停的 Run 进程;手动附加的外部进程保持原有所有权。", + "notes": "Viva 注册 run/start、run/stop 并在进程结束时发送 run/didExit(只发给发起它的那次后端会话);Core 的 run.decodeStart 校验参数,宿主解析工具或包内可执行文件、写入临时文件、启动进程并把输出放进 Run 窗口中这次运行自己的标签,支持停止与再次运行。debug.target 为 connection 时等待端口打开再附加适配器;target 为 launch 时宿主不启动进程,而是按 configurationType 找到本插件能 launch 的适配器,把解析好的程序、参数、绝对工作目录与环境作为 executable 目标事实交给 Core,经适配器的 launch targetBindings 绑定后启动调试会话;运行条目代表该会话,停止运行即停止会话,会话释放后运行以 terminated 事件的退出码结束(适配器未报时不带 exitCode),进程输出在调试控制台。没有调试能力的宿主仍返回 plugin.host.unavailable。debug/start 已实现(见 plugin-debug-start-and-adapter-features)。原生产品验收仍 pending。 2026-11-13:插件 run/start 的调试附加与启动会按需读取适配器目录,不要求用户先打开 Debug 工具窗口;目录返回后检查调用取消,关闭项目不会启动旧请求。 Run 持有的进程在附加调试会话释放后由后台有界回收,Debug 工具栏停止不再留下暂停的 Run 进程;手动附加的外部进程保持原有所有权。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/run-console-ansi-styles.json b/shared/platform-feature-matrix/features/run-console-ansi-styles.json new file mode 100644 index 0000000000..a11b107acc --- /dev/null +++ b/shared/platform-feature-matrix/features/run-console-ansi-styles.json @@ -0,0 +1,47 @@ +{ + "id": "run-console-ansi-styles", + "area": "运行与调试", + "group": "运行输出", + "capability": "运行、构建和测试控制台按 ANSI SGR 转义着色:Rust Core 的 outputStyle.decode 把输出解码为去掉转义的纯文本行和样式区间(16 色、256 色、真彩色、粗体、暗淡、斜体、下划线、反显、隐藏、删除线),桌面端按终端同一套 16 色配色绘制", + "owner": "Run", + "notes": "Viva 共享实现。通用解码在 Rust Core(outputStyle.decode,跨块携带状态,单块不超过 1 MiB),桌面端在读取输出的 goroutine 上按 256 KiB 分片调用,不占界面线程;纯文本供复制、搜索、输出链接、快照和 IDE API 读取,样式只用于绘制。0–15 号颜色取 termview 的终端配色(含 Terminal.app 描述文件导入与对比度回退),粗体前景色按终端规则提亮。Core 解码失败时记一次日志,该控制台其余输出按原样分行显示。宿主不针对任何构建工具做特判:工具是否输出颜色,由提供该工具的插件在自己的命令参数里决定。", + "verification": "运行会输出彩色日志的程序或构建任务(例如用 printf 输出 ESC[1;32mOK ESC[m,或强制彩色输出的构建工具),确认 Run 窗口控制台显示对应颜色和粗体且没有残留的转义字符;复制、搜索、点击文件链接、快照当前输出得到的都是不含转义的文字;测试窗口的输出同样着色;切换浅色/深色主题后颜色跟随终端配色。自动化:core/output_style_test.go、outputlinks_test.go、build_test.go、tests_test.go、context_menu_test.go、build_panels_visual_test.go 的 build-and-run 场景截图(合成的彩色构建输出)。", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/core/output_style.go", + "desktop/internal/core/output_style_test.go", + "desktop/internal/workbench/output_style.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/workbench/outputlinks.go", + "desktop/internal/termview/palette.go", + "desktop/internal/workbench/runs.go", + "desktop/internal/workbench/build.go", + "desktop/internal/workbench/tests.go", + "desktop/internal/workbench/outputlinks_test.go", + "desktop/internal/workbench/build_test.go", + "desktop/internal/workbench/tests_test.go", + "desktop/internal/workbench/build_panels_visual_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/core/output_style.go", + "desktop/internal/core/output_style_test.go", + "desktop/internal/workbench/output_style.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/workbench/outputlinks.go", + "desktop/internal/termview/palette.go", + "desktop/internal/workbench/runs.go", + "desktop/internal/workbench/build.go", + "desktop/internal/workbench/tests.go", + "desktop/internal/workbench/outputlinks_test.go", + "desktop/internal/workbench/build_test.go", + "desktop/internal/workbench/tests_test.go", + "desktop/internal/workbench/build_panels_visual_test.go" + ] + } +} diff --git a/shared/platform-feature-matrix/features/run-output-snapshot.json b/shared/platform-feature-matrix/features/run-output-snapshot.json index c56720409c..0d508c18bf 100644 --- a/shared/platform-feature-matrix/features/run-output-snapshot.json +++ b/shared/platform-feature-matrix/features/run-output-snapshot.json @@ -9,7 +9,7 @@ "evidence": [ "docs/viva-migration.md", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go" + "desktop/internal/workbench/run_view.go" ] }, "windows": { @@ -18,7 +18,7 @@ "evidence": [ "docs/viva-migration.md", "desktop/internal/workbench/runs.go", - "desktop/internal/workbench/build_view.go" + "desktop/internal/workbench/run_view.go" ] }, "owner": "Run", diff --git a/shared/platform-feature-matrix/features/run-window-execution-tabs.json b/shared/platform-feature-matrix/features/run-window-execution-tabs.json new file mode 100644 index 0000000000..6c44e76b3d --- /dev/null +++ b/shared/platform-feature-matrix/features/run-window-execution-tabs.json @@ -0,0 +1,41 @@ +{ + "id": "run-window-execution-tabs", + "area": "运行与调试", + "group": "运行输出", + "capability": "Run 窗口按 IntelliJ IDEA 的样式为每次执行开一个标签:标签带状态图标和关闭按钮,左侧竖排工具栏提供再次运行(绿)与停止(红),执行树显示状态、名称、开始时间和右对齐的耗时,右侧是控制台及其滚动到末尾、清空按钮", + "owner": "Run", + "notes": "Viva 共享实现。宿主构建任务、运行配置和插件经 lithe/host/run/start 发起的运行都进入 Run 窗口,每次执行一个标签,最新的被选中;同名的已结束执行被新执行替换,运行中的标签不可关闭,关闭当前标签后选中顶替其位置的相邻标签。执行树的根行是状态图标、粗体名称、“: 在 <开始时间>”和右对齐耗时(毫秒、秒+毫秒、分+秒、时+分),下一行是结果说明。Build 窗口不再内嵌运行输出。控制台跟随最新输出,用户向上滚动后停止跟随,滚动到末尾按钮恢复。全部文案走 shared/i18n 的 desktop.run.*。", + "verification": "打开 Build 窗口依次执行两个任务(一个成功、一个失败),确认 Run 窗口标题为“运行”,出现两个标签且新任务被选中;标签图标分别为成功和失败,执行树显示名称、开始时间与右对齐耗时;切换标签时树和控制台跟着切换;再次运行按钮为绿色,运行中时停止按钮为红色、结束后变灰;运行中的标签没有关闭按钮,结束后点 × 关闭并选中相邻标签;持续输出时控制台停在末尾,向上滚动后不再跳动,点滚动到末尾恢复,点清空清除内容。浅色和深色主题各看一次。自动化:run_view_test.go 的 TestRunWindowGivesEachExecutionATab、i18n_test.go 的 TestRunDurationPicksTheLargestTwoUnits、run_panels_test.go、build_panels_visual_test.go 的 build-and-run 场景截图。", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/run_view.go", + "desktop/internal/workbench/runs.go", + "desktop/internal/workbench/build.go", + "desktop/internal/workbench/runpanels.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/i18n/run_messages.go", + "desktop/internal/workbench/run_view_test.go", + "desktop/internal/workbench/run_panels_test.go", + "desktop/internal/i18n/i18n_test.go", + "desktop/internal/workbench/build_panels_visual_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/run_view.go", + "desktop/internal/workbench/runs.go", + "desktop/internal/workbench/build.go", + "desktop/internal/workbench/runpanels.go", + "desktop/internal/workbench/outputlinks_view.go", + "desktop/internal/i18n/run_messages.go", + "desktop/internal/workbench/run_view_test.go", + "desktop/internal/workbench/run_panels_test.go", + "desktop/internal/i18n/i18n_test.go", + "desktop/internal/workbench/build_panels_visual_test.go" + ] + } +}