From 380cfebe3c59ca3f59b9de154784f500a30701c8 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Fri, 13 Nov 2026 11:49:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(desktop):=20#1794=20=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E6=A0=8F=E8=BF=90=E8=A1=8C/=E8=B0=83=E8=AF=95=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=8E=A5=E5=85=A5=EF=BC=8C=E8=B0=83=E8=AF=95=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=AA=97=E5=8F=A3=E6=8C=89=20IntelliJ=20IDEA=20?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E9=87=8D=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 标题栏:运行配置下拉、运行、调试按钮接入当前运行配置;会话进行中显示停止与重新运行 - 调试工具栏改为图标按钮:重新运行、停止 | 继续、暂停、单步跳过/进入/跳出 | 查看断点、静音断点 | 更多; 未开始会话时适配器选择器收在工具栏右端 - 线程和变量:线程下拉、“函数 (文件:行)”栈帧、求值/添加监视输入框、带类型图标的变量树; 断点与异常断点移到“查看断点”对话框 - 反汇编:去掉自带按钮行,工具栏单步按指令执行,行首红点增删指令断点,打开时以当前指令居中, 滚动到两端加载更多代码 - 内存:可输入地址跳转(十六进制或十进制),每行 8/16/32/64 字节,十六/十/八/二进制切换, 高亮目标字节 - 补齐中英词条与功能矩阵条目 --- desktop/internal/core/build.go | 55 ++- desktop/internal/core/build_test.go | 37 ++ .../i18n/debug_breakpoint_messages.go | 15 +- desktop/internal/i18n/debug_messages.go | 6 - desktop/internal/i18n/messages.go | 2 - desktop/internal/i18n/shared.generated.go | 62 ++- desktop/internal/i18n/title_messages.go | 1 - desktop/internal/icons/icons.go | 200 +++++++++ desktop/internal/pluginservice/builds.go | 14 +- desktop/internal/workbench/app.go | 26 +- desktop/internal/workbench/branch.go | 1 + desktop/internal/workbench/build.go | 208 ++++++---- desktop/internal/workbench/build_menus.go | 6 +- desktop/internal/workbench/chrome.go | 3 + desktop/internal/workbench/chrome_view.go | 16 +- desktop/internal/workbench/debug.go | 58 ++- .../internal/workbench/debug_adapter_test.go | 43 +- .../internal/workbench/debug_breakpoints.go | 5 +- .../internal/workbench/debug_disassembly.go | 47 ++- desktop/internal/workbench/debug_gutter.go | 2 +- desktop/internal/workbench/debug_memory.go | 325 ++++++++++++--- .../internal/workbench/debug_memory_test.go | 62 ++- desktop/internal/workbench/debug_menus.go | 82 ++-- .../internal/workbench/debug_menus_test.go | 33 +- desktop/internal/workbench/debug_mute.go | 56 +++ .../internal/workbench/debug_sections_view.go | 262 +++++++----- desktop/internal/workbench/debug_start.go | 55 ++- .../internal/workbench/debug_state_test.go | 3 +- desktop/internal/workbench/debug_tcp_test.go | 4 +- desktop/internal/workbench/debug_test.go | 20 +- desktop/internal/workbench/debug_threads.go | 15 +- .../internal/workbench/debug_threads_test.go | 51 ++- .../internal/workbench/debug_toolbar_test.go | 222 ++++++++++ desktop/internal/workbench/debug_view.go | 385 ++++++++++++------ desktop/internal/workbench/debug_watch.go | 212 +++++++--- desktop/internal/workbench/drag.go | 2 +- desktop/internal/workbench/editor_view.go | 5 + desktop/internal/workbench/runconfig.go | 9 + desktop/internal/workbench/runpanels.go | 13 +- desktop/internal/workbench/shell_view.go | 10 +- desktop/internal/workbench/title_run.go | 218 ++++++++++ desktop/internal/workbench/title_run_test.go | 191 +++++++++ desktop/internal/workbench/title_run_view.go | 61 +++ scripts/desktop/generate-desktop-icons.sh | 3 +- shared/i18n/locales/en-US.json | 24 +- shared/i18n/locales/zh-CN.json | 24 +- shared/i18n/messages.json | 175 ++++++-- .../features/debug-variable-json-view.json | 2 +- .../viva-debug-tool-window-layout.json | 47 +++ .../features/viva-title-run-debug.json | 35 ++ 50 files changed, 2742 insertions(+), 671 deletions(-) create mode 100644 desktop/internal/workbench/debug_mute.go create mode 100644 desktop/internal/workbench/debug_toolbar_test.go create mode 100644 desktop/internal/workbench/title_run.go create mode 100644 desktop/internal/workbench/title_run_test.go create mode 100644 desktop/internal/workbench/title_run_view.go create mode 100644 shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json create mode 100644 shared/platform-feature-matrix/features/viva-title-run-debug.json diff --git a/desktop/internal/core/build.go b/desktop/internal/core/build.go index d430e86d66..bdf8665842 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -256,15 +256,17 @@ type BuildDecodeRunRequest struct { } type buildOutcome struct { - Status string `json:"status"` - Error *MarketplaceRejection `json:"error"` - Detection *BuildDetection `json:"detection"` - Plan *BuildPlan `json:"plan"` - Model *BuildModel `json:"model"` - Launch *BuildLaunch `json:"launch"` - Results *BuildTestResults `json:"results"` - Invocation *BuildInvocation `json:"invocation"` - Version *BuildToolVersion `json:"version"` + Status string `json:"status"` + Error *MarketplaceRejection `json:"error"` + Detection *BuildDetection `json:"detection"` + Plan *BuildPlan `json:"plan"` + Model *BuildModel `json:"model"` + Launch *BuildLaunch `json:"launch"` + // Preparation answers build.decodeDebugPreparation. + Preparation *BuildDebugPreparation `json:"preparation"` + Results *BuildTestResults `json:"results"` + Invocation *BuildInvocation `json:"invocation"` + Version *BuildToolVersion `json:"version"` // Dependencies is the answer of build.decodeDependencies. Dependencies *BuildDependencyTree `json:"dependencies"` // Storage and Edit answer build.resolveStoredOptions and build.editStoredOption. @@ -443,18 +445,31 @@ func (c *Client) DecodeBuildModel(ctx context.Context, manifest json.RawMessage, return *result.Model, nil } -// BuildDecodeDebugRequest validates the raw result of a provider's debug preparation. Native -// debug preparation takes no launch options, so the request carries none. +// BuildDecodeDebugRequest validates the raw result of a provider's debug preparation. Run is +// the run declaration the preparation was planned for, whose `debug.adapter` Core answers. +// Native debug preparation takes no launch options, so the request carries none. type BuildDecodeDebugRequest struct { WorkspaceRoot string `json:"workspaceRoot"` Root string `json:"root"` + Run string `json:"run"` Result json.RawMessage `json:"result"` } -// DecodeBuildDebug validates the native debug program a provider prepared, with the process -// facts the host starts it from. It answers the same launch shape as DecodeBuildRun, which the -// Debug host already knows how to start. -func (c *Client) DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeDebugRequest) (BuildLaunch, error) { +// BuildDebugPreparation is the native debug program a provider prepared, as Core validated it: +// the local ID of the plugin's own adapter the run declares, and the program with its process +// facts. Program and WorkingDirectory are relative to the workspace root. +type BuildDebugPreparation struct { + Adapter string `json:"adapter"` + Root string `json:"root"` + Program string `json:"program"` + Arguments []string `json:"arguments"` + WorkingDirectory string `json:"workingDirectory"` + Environment map[string]string `json:"environment"` +} + +// DecodeBuildDebug validates the native debug program a provider prepared +// (`build.decodeDebugPreparation`). +func (c *Client) DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeDebugRequest) (BuildDebugPreparation, error) { const command = "build.decodeDebugPreparation" var result buildOutcome if err := c.Execute(ctx, command, struct { @@ -462,15 +477,15 @@ func (c *Client) DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, BuildSystemID string `json:"buildSystemID"` Request BuildDecodeDebugRequest `json:"request"` }{manifest, buildSystemID, request}, &result); err != nil { - return BuildLaunch{}, err + return BuildDebugPreparation{}, err } if err := result.failure(command); err != nil { - return BuildLaunch{}, err + return BuildDebugPreparation{}, err } - if result.Launch == nil { - return BuildLaunch{}, newParseError(command, "build debug preparation returned no launch", "") + if result.Preparation == nil { + return BuildDebugPreparation{}, newParseError(command, "build debug preparation returned no preparation", "") } - return *result.Launch, nil + return *result.Preparation, nil } func (c *Client) DecodeBuildRun(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeRunRequest) (BuildLaunch, error) { const command = "build.decodeRunPreparation" diff --git a/desktop/internal/core/build_test.go b/desktop/internal/core/build_test.go index cd6a48d104..d419542010 100644 --- a/desktop/internal/core/build_test.go +++ b/desktop/internal/core/build_test.go @@ -216,3 +216,40 @@ func TestBuildProviderRequestNeedsAnOpenSession(t *testing.T) { t.Fatal("a build request to a missing session succeeded") } } + +// A native debug preparation decodes with the run it was planned for: Core answers the adapter +// that run declares and the workspace-relative program the provider prepared. +func TestBuildDecodeDebugAnswersTheDeclaredAdapter(t *testing.T) { + client, ctx := NewClient(), testContext(t) + root := t.TempDir() + if err := os.MkdirAll(filepath.Join(root, "app", "bin"), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(root, "app", "bin", "sample"), []byte("#!/bin/sh\n"), 0o700); err != nil { + t.Fatal(err) + } + manifest := readBuildFixture(t, "build-provider-debug-preparation.plugin.json") + raw, err := os.ReadFile(contractfixture.Path("fixtures/build-providers/build-debug-preparation.json")) + if err != nil { + t.Fatal(err) + } + var fixture struct { + Result json.RawMessage `json:"result"` + } + if err := json.Unmarshal(raw, &fixture); err != nil { + t.Fatal(err) + } + preparation, err := client.DecodeBuildDebug(ctx, manifest, "gradle", BuildDecodeDebugRequest{ + WorkspaceRoot: root, + Root: ".", + Run: "application", + Result: fixture.Result, + }) + if err != nil { + t.Fatal(err) + } + if preparation.Adapter != "native" || preparation.Program != "app/bin/sample" || preparation.WorkingDirectory != "app" || + len(preparation.Arguments) != 2 || preparation.Environment["SAMPLE"] != "debug" { + t.Fatalf("preparation = %+v", preparation) + } +} diff --git a/desktop/internal/i18n/debug_breakpoint_messages.go b/desktop/internal/i18n/debug_breakpoint_messages.go index a2a45311ce..991b14cd4c 100644 --- a/desktop/internal/i18n/debug_breakpoint_messages.go +++ b/desktop/internal/i18n/debug_breakpoint_messages.go @@ -3,14 +3,12 @@ package i18n // DebugBreakpointMessages are the words of the breakpoint editor: the condition, // hit count and log message a source breakpoint may carry. type DebugBreakpointMessages struct { - Edit string - FunctionName string - FunctionPlaceholder string - AddFunction string - FunctionRow func(name string) string - RemoveFunction string - // Instruction labels the button that toggles a machine-instruction breakpoint on a row. - Instruction string + Edit string + FunctionName string + FunctionPlaceholder string + AddFunction string + FunctionRow func(name string) string + RemoveFunction string BreakOnChange string DataRow func(label string) string RemoveData string @@ -39,7 +37,6 @@ func debugBreakpointMessages(language Language) DebugBreakpointMessages { return SharedFormat(language, "desktop.debug.breakpoint.functionRow", map[string]string{"name": name}) }, RemoveFunction: Shared(language, "desktop.debug.breakpoint.removeFunction"), - Instruction: Shared(language, "desktop.debug.breakpoint.instruction"), BreakOnChange: Shared(language, "desktop.debug.breakpoint.breakOnChange"), DataRow: func(label string) string { return SharedFormat(language, "desktop.debug.breakpoint.dataRow", map[string]string{"label": label}) diff --git a/desktop/internal/i18n/debug_messages.go b/desktop/internal/i18n/debug_messages.go index 6e31e3d411..3871b6aac2 100644 --- a/desktop/internal/i18n/debug_messages.go +++ b/desktop/internal/i18n/debug_messages.go @@ -52,10 +52,7 @@ type DebugMessages struct { SetValue string NoExceptionFilters string NoDisassembly string - LoadBefore string - LoadAfter string Reload string - EndOfCode string BufferLimit string InvalidEndpoint string // RemotePrompt asks whether to attach to a debuggee that is not local. @@ -131,10 +128,7 @@ func debugMessages(language Language) DebugMessages { SetValue: Shared(language, "desktop.debug.setValue"), NoExceptionFilters: Shared(language, "desktop.debug.noExceptionFilters"), NoDisassembly: Shared(language, "desktop.debug.noDisassembly"), - LoadBefore: Shared(language, "desktop.debug.loadBefore"), - LoadAfter: Shared(language, "desktop.debug.loadAfter"), Reload: Shared(language, "desktop.debug.reload"), - EndOfCode: Shared(language, "desktop.debug.endOfCode"), BufferLimit: Shared(language, "desktop.debug.bufferLimit"), InvalidEndpoint: Shared(language, "desktop.debug.invalidEndpoint"), RemotePrompt: func(endpoint string) string { diff --git a/desktop/internal/i18n/messages.go b/desktop/internal/i18n/messages.go index 6228494a64..0f48d0ede2 100644 --- a/desktop/internal/i18n/messages.go +++ b/desktop/internal/i18n/messages.go @@ -99,8 +99,6 @@ type TitleMessages struct { Debug string Search string Settings string - // RunLater explains that running needs a build provider that is not connected yet. - RunLater string // The settings button's menu. Preferences string Plugins string diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 41bd27c94f..850b6e14d6 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -4,6 +4,7 @@ package i18n var sharedCatalogs = map[string]map[string]string{ "en-US": { "ai.add": "Add", + "debugger.console": "Console", "debugger.disableBreakpoint": "Disable breakpoint", "debugger.disassembly.copyAddress": "Copy Address", "debugger.disassembly.copyInstruction": "Copy Instruction", @@ -13,6 +14,8 @@ var sharedCatalogs = map[string]map[string]string{ "debugger.disassembly.showDisassembly": "Show Disassembly", "debugger.enableBreakpoint": "Enable breakpoint", "debugger.removeBreakpoint": "Remove breakpoint", + "debugger.stackEmpty": "Start a session to see frames.", + "debugger.threadsAndVariables": "Threads & Variables", "desktop.ai.inlineEdit.editCurrentLine": "Editing the current line", "desktop.ai.inlineEdit.editSelection": "Editing the selection", "desktop.aiCommit.cancel": "Cancel generation", @@ -240,7 +243,6 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.breakpoint.functionRow": "ƒ {name}", "desktop.debug.breakpoint.hitCondition": "Hit count", "desktop.debug.breakpoint.hitConditionPlaceholder": "For example >= 5", - "desktop.debug.breakpoint.instruction": "Breakpoint", "desktop.debug.breakpoint.logMessage": "Log message", "desktop.debug.breakpoint.logMessagePlaceholder": "Text to log; {expression} is evaluated", "desktop.debug.breakpoint.logPoint": "log", @@ -255,11 +257,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.child.unavailable": "Lithe could not start the child debug session.", "desktop.debug.connectFailed": "Could not connect to the debug adapter at {endpoint}.", "desktop.debug.connectionClosed": "The debug connection closed.", + "desktop.debug.consoleEmpty": "The debug session's output appears here.", "desktop.debug.continue": "Continue", "desktop.debug.disassembly": "Disassembly", "desktop.debug.editValue": "New value", - "desktop.debug.endOfCode": "No more instructions.", "desktop.debug.evaluateFailed": "The expression could not be evaluated", + "desktop.debug.evaluatePlaceholder": "Evaluate expression ({evaluate}) or add a watch ({watch})", "desktop.debug.exceptionInfo": "Exception info", "desktop.debug.exceptions": "Exception Breakpoints", "desktop.debug.failed": "Debug session failed", @@ -267,11 +270,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.frames": "Call stack", "desktop.debug.initialized": "Debug adapter initialized", "desktop.debug.invalidEndpoint": "The debug adapter endpoint is not valid.", - "desktop.debug.loadAfter": "Load later", - "desktop.debug.loadBefore": "Load earlier", "desktop.debug.loadMore": "Load more", "desktop.debug.loadingVariables": "Loading…", "desktop.debug.memory": "Memory", + "desktop.debug.memoryAddress": "Memory address", + "desktop.debug.memoryAddressPlaceholder": "Address, e.g. 0x1000", + "desktop.debug.memoryBytesPerRow": "Bytes per row", + "desktop.debug.memoryGoToAddress": "Go to Address", + "desktop.debug.memoryRadix": "Number base", + "desktop.debug.memoryRadixBinary": "Binary", + "desktop.debug.memoryRadixDecimal": "Decimal", + "desktop.debug.memoryRadixHex": "Hexadecimal", + "desktop.debug.memoryRadixOctal": "Octal", + "desktop.debug.memoryRowBytes": "{bytes} bytes per row", "desktop.debug.memoryUnreadableBytes": "Unreadable bytes: {bytes}", "desktop.debug.noAdapters": "The installed plugins declare no debug adapter this client can start.", "desktop.debug.noBreakpoints": "No breakpoints", @@ -311,6 +322,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.threads": "Threads", "desktop.debug.timedOut": "The debug adapter did not answer in time.", "desktop.debug.toggleBreakpoint": "Toggle breakpoint at caret", + "desktop.debug.unmuteBreakpoints": "Unmute breakpoints", "desktop.debug.variables": "Variables", "desktop.debug.viewJson": "JSON", "desktop.debug.viewTree": "Tree", @@ -1377,13 +1389,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tests.timedOut": "Tests timed out", "desktop.title.branchMenu": "Branch menu", "desktop.title.cloneLater": "Cloning repositories comes later", + "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", "desktop.title.keymapLater": "The keymap page comes later", "desktop.title.logsUnavailable": "The log could not be opened when Lithe started", "desktop.title.newProjectLater": "Creating projects comes later", "desktop.title.noRecentProjects": "No recent projects", + "desktop.title.noRunConfigurations": "No run configurations", + "desktop.title.notDebuggable": "{name} cannot be debugged: its plugin declares no debug adapter for this run.", "desktop.title.pluginsLater": "The plugins page comes later", "desktop.title.projectMenu": "Project menu", - "desktop.title.runLater": "Running needs a build plugin, which comes later", + "desktop.title.runBusy": "The Run window is still running another operation. Wait for it to finish or stop it first.", "desktop.toolchains.automatic": "Automatic ({value})", "desktop.toolchains.chooseHelp": "Selecting a row only changes the draft. Save writes the choice to this project's .lithe/toolchains/local.json; Cancel leaves the file unchanged.", "desktop.toolchains.conflict": "{tool} is defined by {plugins}; disable all but one of those plugins.", @@ -1871,6 +1886,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.closeTabsToTheRight": "Close Tabs to the Right", "native.closeUnmodifiedTabs": "Close Unmodified Tabs", "native.collapseDirectory": "Collapse directory", + "native.collapseFilteredFrames": "Collapse filtered frames", "native.collapseSection": "Collapse section", "native.collapseUnchangedFragments": "Collapse unchanged fragments", "native.commaSeparatedGlobPatternsEGJavaKt": "Comma-separated glob patterns, e.g. *.java, *.kt", @@ -1968,6 +1984,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.languageServices": "Language Services", "native.license": "License", "native.limitPerProject": "Limit per project", + "native.lineBreakpoints": "Line Breakpoints", "native.lineLldIsNotAValidRegularExpressionAndIsSkipped": "Line {arg1} is not a valid regular expression and is skipped.", "native.linkedWorktree": "Linked worktree", "native.lithe": "Lithe", @@ -2018,6 +2035,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.moveToRightTop": "Move to Right Top", "native.moved": "Moved", "native.movedFromArg1": "Moved from {arg1}", + "native.muteBreakpoints": "Mute breakpoints", "native.name": "Name", "native.needsNoExtraPermissions": "Needs no extra permissions.", "native.newChangeList": "New ChangeList", @@ -2100,6 +2118,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.refreshDiscoveredTests": "Refresh discovered tests", "native.refreshHistory": "Refresh history", "native.refreshPluginRepositories": "Refresh Plugin Repositories", + "native.refreshWatches": "Refresh watches", "native.refreshWorktrees": "Refresh worktrees", "native.registersTheWorktreeAndPreparesItsHEADWhileLeavingItsFilesUncheckedOut": "Registers the worktree and prepares its HEAD while leaving its files unchecked out.", "native.registration": "Registration", @@ -2121,6 +2140,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.repairedWorktreeRecords": "Repaired worktree records", "native.replaced": "Replaced", "native.repository": "Repository", + "native.rerun": "Rerun", "native.reset": "Reset", "native.resetCurrentBranchToHere": "Reset Current Branch to Here…", "native.restart": "Restart", @@ -2240,6 +2260,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.versionIsInstalled": "Version {arg1} is installed.", "native.versionsSource": "Versions & Source", "native.view": "View", + "native.viewBreakpoints": "View Breakpoints", "native.waitForTheRunningVersionControlActionToFinish": "Wait for the running version control action to finish.", "native.whenTheLimitIsReachedTheOldestVersionsAreRemovedFirst": "When the limit is reached, the oldest versions are removed first.", "native.whereWouldYouLikeToOpenTheProject": "Where would you like to open the project ‘{arg1}’?", @@ -2326,6 +2347,7 @@ var sharedCatalogs = map[string]map[string]string{ }, "zh-CN": { "ai.add": "添加", + "debugger.console": "控制台", "debugger.disableBreakpoint": "禁用断点", "debugger.disassembly.copyAddress": "复制地址", "debugger.disassembly.copyInstruction": "复制指令", @@ -2335,6 +2357,8 @@ var sharedCatalogs = map[string]map[string]string{ "debugger.disassembly.showDisassembly": "显示反汇编", "debugger.enableBreakpoint": "启用断点", "debugger.removeBreakpoint": "移除断点", + "debugger.stackEmpty": "启动会话后可查看栈帧。", + "debugger.threadsAndVariables": "线程和变量", "desktop.ai.inlineEdit.editCurrentLine": "编辑当前行", "desktop.ai.inlineEdit.editSelection": "编辑选中内容", "desktop.aiCommit.cancel": "取消生成", @@ -2562,7 +2586,6 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.breakpoint.functionRow": "ƒ {name}", "desktop.debug.breakpoint.hitCondition": "命中次数", "desktop.debug.breakpoint.hitConditionPlaceholder": "例如 >= 5", - "desktop.debug.breakpoint.instruction": "断点", "desktop.debug.breakpoint.logMessage": "日志消息", "desktop.debug.breakpoint.logMessagePlaceholder": "要记录的文本,{表达式} 会被求值", "desktop.debug.breakpoint.logPoint": "日志点", @@ -2577,11 +2600,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.child.unavailable": "Lithe 无法启动子调试会话。", "desktop.debug.connectFailed": "无法连接到 {endpoint} 的调试适配器。", "desktop.debug.connectionClosed": "调试连接已断开。", + "desktop.debug.consoleEmpty": "调试会话的输出会显示在这里。", "desktop.debug.continue": "继续", "desktop.debug.disassembly": "反汇编", "desktop.debug.editValue": "新值", - "desktop.debug.endOfCode": "没有更多指令。", "desktop.debug.evaluateFailed": "无法对该表达式求值", + "desktop.debug.evaluatePlaceholder": "对表达式求值({evaluate})或添加监视({watch})", "desktop.debug.exceptionInfo": "异常信息", "desktop.debug.exceptions": "异常断点", "desktop.debug.failed": "调试会话失败", @@ -2589,11 +2613,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.frames": "调用栈", "desktop.debug.initialized": "调试适配器已初始化", "desktop.debug.invalidEndpoint": "调试适配器的端点无效。", - "desktop.debug.loadAfter": "向下加载", - "desktop.debug.loadBefore": "向上加载", "desktop.debug.loadMore": "加载更多", "desktop.debug.loadingVariables": "正在加载…", "desktop.debug.memory": "内存", + "desktop.debug.memoryAddress": "内存地址", + "desktop.debug.memoryAddressPlaceholder": "地址,如 0x1000", + "desktop.debug.memoryBytesPerRow": "每行字节数", + "desktop.debug.memoryGoToAddress": "跳转到地址", + "desktop.debug.memoryRadix": "显示进制", + "desktop.debug.memoryRadixBinary": "二进制", + "desktop.debug.memoryRadixDecimal": "十进制", + "desktop.debug.memoryRadixHex": "十六进制", + "desktop.debug.memoryRadixOctal": "八进制", + "desktop.debug.memoryRowBytes": "每行 {bytes} 字节", "desktop.debug.memoryUnreadableBytes": "无法读取的字节:{bytes}", "desktop.debug.noAdapters": "已安装的插件没有声明此客户端能启动的调试适配器。", "desktop.debug.noBreakpoints": "没有断点", @@ -2633,6 +2665,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.threads": "线程", "desktop.debug.timedOut": "调试适配器没有及时响应。", "desktop.debug.toggleBreakpoint": "在当前行切换断点", + "desktop.debug.unmuteBreakpoints": "恢复断点", "desktop.debug.variables": "变量", "desktop.debug.viewJson": "JSON", "desktop.debug.viewTree": "树", @@ -3699,13 +3732,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tests.timedOut": "测试超时", "desktop.title.branchMenu": "分支菜单", "desktop.title.cloneLater": "克隆仓库稍后提供", + "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", "desktop.title.keymapLater": "快捷键页稍后提供", "desktop.title.logsUnavailable": "Lithe 启动时未能打开日志", "desktop.title.newProjectLater": "新建项目稍后提供", "desktop.title.noRecentProjects": "无最近项目", + "desktop.title.noRunConfigurations": "没有运行配置", + "desktop.title.notDebuggable": "无法调试 {name}:它所属的插件没有为这个运行声明调试适配器。", "desktop.title.pluginsLater": "插件页稍后提供", "desktop.title.projectMenu": "项目菜单", - "desktop.title.runLater": "运行需要接入构建插件,稍后提供", + "desktop.title.runBusy": "运行窗口还在执行其他操作。请等它结束,或者先停止它。", "desktop.toolchains.automatic": "自动({value})", "desktop.toolchains.chooseHelp": "选择一行只修改草稿。保存会写入本项目的 .lithe/toolchains/local.json;取消不会改动文件。", "desktop.toolchains.conflict": "{tool} 同时由 {plugins} 定义;请只保留其中一个插件。", @@ -4193,6 +4229,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.closeTabsToTheRight": "关闭右侧标签页", "native.closeUnmodifiedTabs": "关闭未修改的标签页", "native.collapseDirectory": "折叠目录", + "native.collapseFilteredFrames": "折叠已过滤的栈帧", "native.collapseSection": "折叠分组", "native.collapseUnchangedFragments": "折叠未更改的片段", "native.commaSeparatedGlobPatternsEGJavaKt": "以逗号分隔的 glob 模式,例如 *.java、*.kt", @@ -4290,6 +4327,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.languageServices": "语言服务", "native.license": "许可证", "native.limitPerProject": "每个项目上限", + "native.lineBreakpoints": "行断点", "native.lineLldIsNotAValidRegularExpressionAndIsSkipped": "第 {arg1} 行不是有效的正则表达式,已跳过。", "native.linkedWorktree": "关联工作树", "native.lithe": "Lithe", @@ -4340,6 +4378,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.moveToRightTop": "移到右侧上方", "native.moved": "移动", "native.movedFromArg1": "从 {arg1} 移动", + "native.muteBreakpoints": "暂停断点", "native.name": "名称", "native.needsNoExtraPermissions": "不需要额外权限。", "native.newChangeList": "新建更改列表", @@ -4422,6 +4461,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.refreshDiscoveredTests": "刷新已发现的测试", "native.refreshHistory": "刷新历史", "native.refreshPluginRepositories": "刷新插件仓库", + "native.refreshWatches": "刷新监视", "native.refreshWorktrees": "刷新工作树", "native.registersTheWorktreeAndPreparesItsHEADWhileLeavingItsFilesUncheckedOut": "注册工作树并设置 HEAD,但不检出文件。", "native.registration": "注册状态", @@ -4443,6 +4483,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.repairedWorktreeRecords": "已修复工作树记录", "native.replaced": "已替换", "native.repository": "仓库", + "native.rerun": "重新运行", "native.reset": "重置", "native.resetCurrentBranchToHere": "将当前分支重置到这里…", "native.restart": "重新启动", @@ -4562,6 +4603,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.versionIsInstalled": "已安装版本 {arg1}。", "native.versionsSource": "版本与来源", "native.view": "查看", + "native.viewBreakpoints": "查看断点", "native.waitForTheRunningVersionControlActionToFinish": "请等待正在执行的版本控制操作完成。", "native.whenTheLimitIsReachedTheOldestVersionsAreRemovedFirst": "达到上限时,最早的版本会先被删除。", "native.whereWouldYouLikeToOpenTheProject": "你想在哪里打开项目“{arg1}”?", diff --git a/desktop/internal/i18n/title_messages.go b/desktop/internal/i18n/title_messages.go index 87ad72149e..ca65945acd 100644 --- a/desktop/internal/i18n/title_messages.go +++ b/desktop/internal/i18n/title_messages.go @@ -14,7 +14,6 @@ func titleMessages(language Language) TitleMessages { Debug: Shared(language, "native.debug"), Search: Shared(language, "workbench.search"), Settings: Shared(language, "menu.settings"), - RunLater: Shared(language, "desktop.title.runLater"), Preferences: Shared(language, "native.settings"), Plugins: Shared(language, "native.plugins"), LogsAndDiagnostics: Shared(language, "logs.window.logsAndDiagnostics"), diff --git a/desktop/internal/icons/icons.go b/desktop/internal/icons/icons.go index 0c0baff6f4..4c3627d104 100644 --- a/desktop/internal/icons/icons.go +++ b/desktop/internal/icons/icons.go @@ -100,6 +100,27 @@ var ArrowDownLeft = gfx.Icon{ }, } +// arrow-down-to-dot is a compiled vector icon. +var ArrowDownToDot = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(12.0, 2.0), + gfx.LineTo(12.0, 16.0), + gfx.MoveTo(19.0, 9.0), + gfx.LineTo(12.0, 16.0), + gfx.LineTo(5.0, 9.0), + gfx.MoveTo(13.0, 21.0), + gfx.CubicTo(13.0, 21.5523, 12.5523, 22.0, 12.0, 22.0), + gfx.CubicTo(11.4477, 22.0, 11.0, 21.5523, 11.0, 21.0), + gfx.CubicTo(11.0, 20.4477, 11.4477, 20.0, 12.0, 20.0), + gfx.CubicTo(12.5523, 20.0, 13.0, 20.4477, 13.0, 21.0), + gfx.ClosePath(), + }, +} + // arrow-down-to-line is a compiled vector icon. var ArrowDownToLine = gfx.Icon{ ViewBox: 24.0, @@ -172,6 +193,27 @@ var ArrowUpDown = gfx.Icon{ }, } +// arrow-up-from-dot is a compiled vector icon. +var ArrowUpFromDot = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(5.0, 9.0), + gfx.LineTo(12.0, 2.0), + gfx.LineTo(19.0, 9.0), + gfx.MoveTo(12.0, 16.0), + gfx.LineTo(12.0, 2.0), + gfx.MoveTo(13.0, 21.0), + gfx.CubicTo(13.0, 21.5523, 12.5523, 22.0, 12.0, 22.0), + gfx.CubicTo(11.4477, 22.0, 11.0, 21.5523, 11.0, 21.0), + gfx.CubicTo(11.0, 20.4477, 11.4477, 20.0, 12.0, 20.0), + gfx.CubicTo(12.5523, 20.0, 13.0, 20.4477, 13.0, 21.0), + gfx.ClosePath(), + }, +} + // bell is a compiled vector icon. var Bell = gfx.Icon{ ViewBox: 24.0, @@ -195,6 +237,34 @@ var Bell = gfx.Icon{ }, } +// braces is a compiled vector icon. +var Braces = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(8.0, 3.0), + gfx.LineTo(7.0, 3.0), + gfx.CubicTo(5.89543, 3.0, 5.0, 3.89543, 5.0, 5.0), + gfx.LineTo(5.0, 10.0), + gfx.CubicTo(5.0, 11.1046, 4.10457, 12.0, 3.0, 12.0), + gfx.CubicTo(4.10457, 12.0, 5.0, 12.8954, 5.0, 14.0), + gfx.LineTo(5.0, 19.0), + gfx.CubicTo(5.0, 20.1, 5.9, 21.0, 7.0, 21.0), + gfx.LineTo(8.0, 21.0), + gfx.MoveTo(16.0, 21.0), + gfx.LineTo(17.0, 21.0), + gfx.CubicTo(18.1046, 21.0, 19.0, 20.1046, 19.0, 19.0), + gfx.LineTo(19.0, 14.0), + gfx.CubicTo(19.0, 12.9, 19.9, 12.0, 21.0, 12.0), + gfx.CubicTo(19.8954, 12.0, 19.0, 11.1046, 19.0, 10.0), + gfx.LineTo(19.0, 5.0), + gfx.CubicTo(19.0, 3.89543, 18.1046, 3.0, 17.0, 3.0), + gfx.LineTo(16.0, 3.0), + }, +} + // bug is a compiled vector icon. var Bug = gfx.Icon{ ViewBox: 24.0, @@ -373,6 +443,46 @@ var CircleCheck = gfx.Icon{ }, } +// circle-dot is a compiled vector icon. +var CircleDot = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(22.0, 12.0), + gfx.CubicTo(22.0, 17.5228, 17.5228, 22.0, 12.0, 22.0), + gfx.CubicTo(6.47715, 22.0, 2.0, 17.5228, 2.0, 12.0), + gfx.CubicTo(2.0, 6.47715, 6.47715, 2.0, 12.0, 2.0), + gfx.CubicTo(17.5228, 2.0, 22.0, 6.47715, 22.0, 12.0), + gfx.ClosePath(), + gfx.MoveTo(13.0, 12.0), + gfx.CubicTo(13.0, 12.5523, 12.5523, 13.0, 12.0, 13.0), + gfx.CubicTo(11.4477, 13.0, 11.0, 12.5523, 11.0, 12.0), + gfx.CubicTo(11.0, 11.4477, 11.4477, 11.0, 12.0, 11.0), + gfx.CubicTo(12.5523, 11.0, 13.0, 11.4477, 13.0, 12.0), + gfx.ClosePath(), + }, +} + +// circle-slash is a compiled vector icon. +var CircleSlash = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(22.0, 12.0), + gfx.CubicTo(22.0, 17.5228, 17.5228, 22.0, 12.0, 22.0), + gfx.CubicTo(6.47715, 22.0, 2.0, 17.5228, 2.0, 12.0), + gfx.CubicTo(2.0, 6.47715, 6.47715, 2.0, 12.0, 2.0), + gfx.CubicTo(17.5228, 2.0, 22.0, 6.47715, 22.0, 12.0), + gfx.ClosePath(), + gfx.MoveTo(9.0, 15.0), + gfx.LineTo(15.0, 9.0), + }, +} + // circle-x is a compiled vector icon. var CircleX = gfx.Icon{ ViewBox: 24.0, @@ -1229,6 +1339,34 @@ var PanelRight = gfx.Icon{ }, } +// pause is a compiled vector icon. +var Pause = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(17.0, 4.0), + gfx.CubicTo(17.5523, 4.0, 18.0, 4.44772, 18.0, 5.0), + gfx.LineTo(18.0, 19.0), + gfx.CubicTo(18.0, 19.5523, 17.5523, 20.0, 17.0, 20.0), + gfx.LineTo(15.0, 20.0), + gfx.CubicTo(14.4477, 20.0, 14.0, 19.5523, 14.0, 19.0), + gfx.LineTo(14.0, 5.0), + gfx.CubicTo(14.0, 4.44772, 14.4477, 4.0, 15.0, 4.0), + gfx.ClosePath(), + gfx.MoveTo(9.0, 4.0), + gfx.CubicTo(9.55229, 4.0, 10.0, 4.44772, 10.0, 5.0), + gfx.LineTo(10.0, 19.0), + gfx.CubicTo(10.0, 19.5523, 9.55229, 20.0, 9.0, 20.0), + gfx.LineTo(7.0, 20.0), + gfx.CubicTo(6.44772, 20.0, 6.0, 19.5523, 6.0, 19.0), + gfx.LineTo(6.0, 5.0), + gfx.CubicTo(6.0, 4.44772, 6.44772, 4.0, 7.0, 4.0), + gfx.ClosePath(), + }, +} + // pencil is a compiled vector icon. var Pencil = gfx.Icon{ ViewBox: 24.0, @@ -1342,6 +1480,29 @@ var Plus = gfx.Icon{ }, } +// redo-dot is a compiled vector icon. +var RedoDot = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(13.0, 17.0), + gfx.CubicTo(13.0, 17.5523, 12.5523, 18.0, 12.0, 18.0), + gfx.CubicTo(11.4477, 18.0, 11.0, 17.5523, 11.0, 17.0), + gfx.CubicTo(11.0, 16.4477, 11.4477, 16.0, 12.0, 16.0), + gfx.CubicTo(12.5523, 16.0, 13.0, 16.4477, 13.0, 17.0), + gfx.ClosePath(), + gfx.MoveTo(21.0, 7.0), + gfx.LineTo(21.0, 13.0), + gfx.LineTo(15.0, 13.0), + gfx.MoveTo(3.0, 17.0), + gfx.CubicTo(3.0, 12.0294, 7.02944, 8.0, 12.0, 8.0), + gfx.CubicTo(14.2149, 8.00226, 16.3511, 8.82116, 18.0, 10.3), + gfx.LineTo(21.0, 13.0), + }, +} + // refresh-cw is a compiled vector icon. var RefreshCw = gfx.Icon{ ViewBox: 24.0, @@ -1366,6 +1527,25 @@ var RefreshCw = gfx.Icon{ }, } +// rotate-ccw is a compiled vector icon. +var RotateCcw = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 12.0), + gfx.CubicTo(3.0, 16.9706, 7.02944, 21.0, 12.0, 21.0), + gfx.CubicTo(16.9706, 21.0, 21.0, 16.9706, 21.0, 12.0), + gfx.CubicTo(21.0, 7.02944, 16.9706, 3.0, 12.0, 3.0), + gfx.CubicTo(9.48395, 3.00947, 7.06897, 3.99122, 5.26, 5.74), + gfx.LineTo(3.0, 8.0), + gfx.MoveTo(3.0, 3.0), + gfx.LineTo(3.0, 8.0), + gfx.LineTo(8.0, 8.0), + }, +} + // search is a compiled vector icon. var Search = gfx.Icon{ ViewBox: 24.0, @@ -1689,6 +1869,26 @@ var UnfoldVertical = gfx.Icon{ }, } +// variable is a compiled vector icon. +var Variable = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(8.0, 21.0), + gfx.CubicTo(8.0, 21.0, 4.0, 18.0, 4.0, 12.0), + gfx.CubicTo(4.0, 12.0, 8.0, 3.0, 8.0, 3.0), + gfx.MoveTo(16.0, 3.0), + gfx.CubicTo(16.0, 3.0, 20.0, 6.0, 20.0, 12.0), + gfx.CubicTo(20.0, 12.0, 16.0, 21.0, 16.0, 21.0), + gfx.MoveTo(15.0, 9.0), + gfx.LineTo(9.0, 15.0), + gfx.MoveTo(9.0, 9.0), + gfx.LineTo(15.0, 15.0), + }, +} + // wrap-text is a compiled vector icon. var WrapText = gfx.Icon{ ViewBox: 24.0, diff --git a/desktop/internal/pluginservice/builds.go b/desktop/internal/pluginservice/builds.go index 6ad5fd6fd3..64580e32e5 100644 --- a/desktop/internal/pluginservice/builds.go +++ b/desktop/internal/pluginservice/builds.go @@ -67,6 +67,9 @@ type BuildRunDeclaration struct { Name string Execution string Tags []string + // DebugAdapter is the local ID of the plugin's own adapter the run declares for native + // debug preparation (`debug.adapter`), empty when the run cannot be debugged. + DebugAdapter string } // BuildPlugins reads the newest enabled version of every plugin that declares @@ -125,6 +128,9 @@ type rawBuildManifest struct { FromTargets *struct { Tags []string `json:"tags"` } `json:"fromTargets"` + Debug *struct { + Adapter string `json:"adapter"` + } `json:"debug"` } `json:"run"` Test *struct { Scopes []string `json:"scopes"` @@ -172,12 +178,16 @@ func parseBuildSystems(manifest json.RawMessage) (map[string]BuildSystemDeclarat if name == "" { name = run.ID } - system.Runs = append(system.Runs, BuildRunDeclaration{ + declaration := BuildRunDeclaration{ ID: run.ID, Name: name, Execution: run.Execution, Tags: append([]string(nil), run.FromTargets.Tags...), - }) + } + if run.Debug != nil { + declaration.DebugAdapter = run.Debug.Adapter + } + system.Runs = append(system.Runs, declaration) } if raw.Test != nil { system.Test = &BuildTestDeclaration{ diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index c7e50eef40..0c425831c5 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -105,9 +105,10 @@ type Kernel interface { DestroyDebugSession(ctx context.Context, sessionID string) ([]string, error) PlanBuildRun(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildPlanRequest) (core.BuildPlan, error) // PlanBuildDebug plans the native debug program a provider owns for one target, and - // DecodeBuildDebug validates it into the launch the Debug host starts. + // DecodeBuildDebug validates the answer into the preparation the run's declared adapter + // starts: the adapter's local ID and workspace-relative program, arguments and directory. PlanBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildPlanRequest) (core.BuildPlan, error) - DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeDebugRequest) (core.BuildLaunch, error) + DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeDebugRequest) (core.BuildDebugPreparation, error) DecodeBuildModel(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeModelRequest) (core.BuildModel, error) DecodeBuildRun(ctx context.Context, manifest json.RawMessage, buildSystemID string, request core.BuildDecodeRunRequest) (core.BuildLaunch, error) ToolchainRegistryOf(ctx context.Context, manifests []json.RawMessage) (core.ToolchainRegistry, error) @@ -933,19 +934,18 @@ func (a *App) activate(index int) { } case it.id == itemTitleSettings: a.title.gearOpen = !a.title.gearOpen - a.title.projectOpen = false + a.title.projectOpen, a.title.runConfigOpen = false, false a.closeBranches() - case it.id == itemTitleRun: - if a.project != nil { - if !a.chrome.isOpen(catalogIndex[itemRun]) { - a.reduceChrome(core.ToggleChrome(itemRun)) - } - a.runSelectedBuildTask(a.project) - return + case it.id == itemRunConfig: + if a.title.runConfigOpen { + a.title.runConfigOpen = false + } else if a.project != nil { + a.openRunConfigMenu() } - a.notifyInfo(a.text.Title.RunLater) - case it.id == itemRunConfig || it.id == itemTitleDebug: - a.notifyInfo(a.text.Title.RunLater) + case it.id == itemTitleRun: + a.titleRun(a.project) + case it.id == itemTitleDebug: + a.titleDebug(a.project) case it.id == itemTitleSearch: if a.project != nil { a.performed("workspace.searchEverywhere.open", surfaceButton) diff --git a/desktop/internal/workbench/branch.go b/desktop/internal/workbench/branch.go index 855c8493cb..cd11fbe855 100644 --- a/desktop/internal/workbench/branch.go +++ b/desktop/internal/workbench/branch.go @@ -104,6 +104,7 @@ func (a *App) openBranches() { } a.title.projectOpen = false a.title.gearOpen = false + a.title.runConfigOpen = false b := &a.branch b.open, b.menu, b.dialog = true, "", branchDialogNone b.repo, b.repoOpen = p.logBranchRepo(), false diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index 492daa4ae6..d74c1cfd30 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -512,6 +512,8 @@ func (a *App) finishBuildDetection(p *project, generation uint64, instances []bu if p.build.reloadPending { p.build.reloadPending = false defer a.loadBuildSystems(p) + } else { + defer a.settleTitleAction(p) } p.build.loaded = true p.build.instances = instances @@ -529,6 +531,14 @@ func (a *App) finishBuildDetection(p *project, generation uint64, instances []bu return } a.loadBuildModel(p, p.build.selected) + if p.runConfigs.wanted { + a.loadTitleRunConfigs(p) + } + // A model that came with detection is loaded already, so no model answer turns its runs + // into configurations; they are resolved here instead. + if _, loaded := providerRuns(p.build.instances); loaded { + a.refreshRunConfigurations(p) + } } // loadBuildModel loads the model of an instance whose detection did not carry one (a @@ -691,14 +701,16 @@ func (a *App) finishBuildModel(p *project, id string, model core.BuildModel, err if err != nil { a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("plugin_model_superseded", err)) } - if index == p.build.selected { + if index == p.build.selected || p.runConfigs.wanted { a.loadBuildModel(p, index) } + a.settleTitleAction(p) return } if err != nil { p.build.instances[index].modelError = err.Error() p.build.status = err.Error() + a.settleTitleAction(p) return } p.build.instances[index].Model = model @@ -1049,15 +1061,28 @@ func (a *App) runBuildTarget(p *project, targetID, runID string) { a.runBuildTargetWith(p, op, instance, target.ProjectID, targetID, runID, nil) } -// debugBuildTarget prepares one provider application target for debugging and starts the -// plugin's own debug adapter on the program the provider prepared. The adapter comes from the -// same plugin as the build system: the first one that serves launch. +// debugBuildTarget debugs one target of the Build window's selected instance and project +// through the provider's run declaration runID. func (a *App) debugBuildTarget(p *project, targetID, runID string) { - instance := p.selectedBuildInstance() - if instance == nil || p.build.operation != nil { + a.debugProviderTarget(p, p.build.selected, p.build.projectID, targetID, runID) +} + +// debugProviderTarget prepares one target of the instance at index for debugging through the +// run declaration runID and starts the adapter that run names on the program the provider +// prepared. Unsaved documents are saved first, since the provider builds the files on disk. A +// run that declares no adapter, or a preparation already in flight, starts nothing. +func (a *App) debugProviderTarget(p *project, index int, projectID, targetID, runID string) { + if p == nil || index < 0 || index >= len(p.build.instances) || p.debug.preparing { + return + } + instance := &p.build.instances[index] + run, ok := buildRunDeclaration(instance.System, runID) + if !ok || run.DebugAdapter == "" { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("build_debug_prepare", errors.New("the run declares no debug adapter"))) + a.notifyError(i18n.Shared(a.language(), "desktop.build.noDebugAdapter")) return } - project, ok := buildProjectByID(instance.Model, p.build.projectID) + project, ok := buildProjectByID(instance.Model, projectID) if !ok { a.notifyError(a.text.Build.ProjectMissing) return @@ -1070,81 +1095,124 @@ func (a *App) debugBuildTarget(p *project, targetID, runID string) { captured := *instance kernel := a.kernel messages := a.text.Build + // Rerun prepares the same target again, through the instance detection names the same way, + // so it debugs the program built from the files as they are then. + reference := core.RunProviderReference{PluginID: captured.PluginID, BuildSystemID: captured.BuildSystemID, Root: captured.Root} + rerun := func() { a.redebugProviderTarget(p, reference, projectID, targetID, runID) } + request := core.BuildPlanRequest{ + Root: captured.Root, + Options: captured.Options, + WorkspaceRoot: p.root, + Run: runID, + Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, + Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties}, + } a.emit(core.LevelInfo, "app.action.performed", map[string]any{"action": "build.debugTarget", "surface": "build"}) - a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { - plan, err := kernel.PlanBuildDebug(ctx, captured.Manifest, captured.BuildSystemID, core.BuildPlanRequest{ - Root: captured.Root, - Options: captured.Options, - WorkspaceRoot: p.root, - Run: runID, - Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, - Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties}, - }) - if err != nil { - return func(a *App) { a.notifyError(err.Error()) } - } - if plan.Provider == nil { - return func(a *App) { a.notifyError(messages.CommandUnsupported) } - } - client, err := a.buildProvider(ctx, p, captured) - if err != nil { - return func(a *App) { a.notifyError(err.Error()) } - } - operation, err := client.Execute(ctx, plan.Provider.Method, plan.Provider.Params, int(buildRequestTimeout/time.Millisecond)) - if err != nil { - return func(a *App) { a.notifyError(err.Error()) } + p.debug.preparing = true + fail := func(err error) func(*App) { + return func(a *App) { + p.debug.preparing = false + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("build_debug_prepare", err)) + a.notifyError(err.Error()) } - result, err := operation.Wait(ctx) - if err != nil { - return func(a *App) { a.notifyError(err.Error()) } + } + a.saveProjectDocuments(p, func(saved bool) { + if !saved { + p.debug.preparing = false + return } - launch, err := kernel.DecodeBuildDebug(ctx, captured.Manifest, captured.BuildSystemID, core.BuildDecodeDebugRequest{ - WorkspaceRoot: p.root, - Root: captured.Root, - Result: result, + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + plan, err := kernel.PlanBuildDebug(ctx, captured.Manifest, captured.BuildSystemID, request) + if err != nil { + return fail(err) + } + if plan.Provider == nil { + return fail(errors.New(messages.CommandUnsupported)) + } + client, err := a.buildProvider(ctx, p, captured) + if err != nil { + return fail(err) + } + operation, err := client.Execute(ctx, plan.Provider.Method, plan.Provider.Params, int(buildRequestTimeout/time.Millisecond)) + if err != nil { + return fail(err) + } + result, err := operation.Wait(ctx) + if err != nil { + return fail(err) + } + preparation, err := kernel.DecodeBuildDebug(ctx, captured.Manifest, captured.BuildSystemID, core.BuildDecodeDebugRequest{ + WorkspaceRoot: p.root, + Root: captured.Root, + Run: runID, + Result: result, + }) + if err != nil { + return fail(err) + } + return func(a *App) { + p.debug.preparing = false + a.startProviderDebug(p, captured.PluginID, preparation, rerun) + } }) - if err != nil { - return func(a *App) { a.notifyError(err.Error()) } - } - return func(a *App) { a.startProviderDebug(p, captured.PluginID, launch) } }) } -// startProviderDebug starts the prepared program under the first adapter its own plugin -// declares for launch, and reports it when the plugin declares none. -func (a *App) startProviderDebug(p *project, pluginID string, launch core.BuildLaunch) { - if launch.Executable.Value == "" { +// redebugProviderTarget prepares a provider's target for debugging again. The instance is found +// again by its plugin, build system and root, since detection may have run since; an instance +// that is gone says so. +func (a *App) redebugProviderTarget(p *project, reference core.RunProviderReference, projectID, targetID, runID string) { + index := p.buildInstanceIndex(reference) + if index < 0 { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("debug_rerun", errors.New("the debugged build instance is no longer detected"))) + a.notifyError(a.text.Build.TargetMissing) return } - for _, adapter := range p.debug.adapters { - if adapter.PluginID != pluginID || !adapter.Declaration.Serves("launch") { - continue + a.debugProviderTarget(p, index, projectID, targetID, runID) +} + +// buildRunDeclaration is the run declaration id of system. +func buildRunDeclaration(system pluginservice.BuildSystemDeclaration, id string) (pluginservice.BuildRunDeclaration, bool) { + for _, run := range system.Runs { + if run.ID == id { + return run, true } - executable := launch.Executable.Value - if launch.Executable.Kind == "command" { - if resolved, err := exec.LookPath(executable); err == nil { - executable = resolved + } + return pluginservice.BuildRunDeclaration{}, false +} + +// startProviderDebug starts the prepared program under the adapter the preparation names, which +// Core checked belongs to the same plugin. The installed adapters are read first when the Debug +// window has not read them yet. Core answers workspace-relative paths; the adapter gets them +// absolute. rerun prepares the program again for the Debug window's Rerun. +func (a *App) startProviderDebug(p *project, pluginID string, preparation core.BuildDebugPreparation, rerun func()) { + a.whenDebugAdaptersLoaded(p, func() { + for _, adapter := range p.debug.adapters { + if adapter.PluginID != pluginID || adapter.Declaration.ID != preparation.Adapter || !adapter.Declaration.Serves("launch") { + continue } + program := filepath.Join(p.root, filepath.FromSlash(preparation.Program)) + arguments := preparation.Arguments + if arguments == nil { + arguments = []string{} + } + environment := preparation.Environment + if environment == nil { + environment = map[string]string{} + } + a.beginDebug(p, debugStart{ + adapter: adapter, request: "launch", ended: make(chan *int, 1), rerun: rerun, + launchTarget: &core.DebugTargetFacts{ + Kind: "executable", Path: program, Executable: program, + WorkingDirectory: filepath.Join(p.root, filepath.FromSlash(preparation.WorkingDirectory)), + Arguments: arguments, Environment: environment, + }, + }) + return } - arguments := launch.Arguments - if arguments == nil { - arguments = []string{} - } - environment := launch.Environment - if environment == nil { - environment = map[string]string{} - } - a.beginDebug(p, debugStart{ - adapter: adapter, request: "launch", ended: make(chan *int, 1), - launchTarget: &core.DebugTargetFacts{ - Kind: "executable", Path: executable, Executable: executable, - WorkingDirectory: filepath.Join(p.root, filepath.FromSlash(launch.WorkingDirectory)), - Arguments: arguments, Environment: environment, - }, - }) - return - } - a.notifyError(i18n.Shared(a.language(), "desktop.build.noDebugAdapter")) + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("build_debug_start", errors.New("the plugin does not install the adapter its run names"))) + a.notifyError(i18n.Shared(a.language(), "desktop.build.noDebugAdapter")) + }) } // runBuildTargetWith runs one target of instance through the provider's run declaration runID diff --git a/desktop/internal/workbench/build_menus.go b/desktop/internal/workbench/build_menus.go index c95c92add0..66ee41db7a 100644 --- a/desktop/internal/workbench/build_menus.go +++ b/desktop/internal/workbench/build_menus.go @@ -42,9 +42,9 @@ func (a *App) buildRowMenu(c ui.C, row ui.Box, p *project, instance *buildInstan a.runBuildTarget(p, spec.id, runID) }) } - // The same target under the debugger: the provider prepares the native debug - // program and its own plugin's adapter starts it. - if menu.Item(i18n.Shared(lang, "desktop.build.debugTarget")).Disabled(b.operation != nil || instance.modelLoading).Clicked() { + // The same target under the debugger, when the run names an adapter of its own + // plugin: the provider prepares the native debug program and that adapter starts it. + if run.DebugAdapter != "" && menu.Item(i18n.Shared(lang, "desktop.build.debugTarget")).Disabled(b.operation != nil || instance.modelLoading || p.debug.preparing).Clicked() { c.After(func() { a.performed("build.target.debug", surfaceMenu) b.projectID, b.targetID = spec.project, spec.id diff --git a/desktop/internal/workbench/chrome.go b/desktop/internal/workbench/chrome.go index 5383cfe95a..c65f4abfad 100644 --- a/desktop/internal/workbench/chrome.go +++ b/desktop/internal/workbench/chrome.go @@ -79,6 +79,8 @@ type titleState struct { projectOpen bool // gearOpen says the settings button's menu is open. gearOpen bool + // runConfigOpen says the run configuration menu is open (title_run.go). + runConfigOpen bool // menuOpen says the compact menu of the title bar is open (compact_menu.go). menuOpen bool // branches is the branch of each recent project the project menu has read, by path. The @@ -167,6 +169,7 @@ func (a *App) selectedEditorDocument() *document { // while the menu is shut; the ones read before are shown until the new answer arrives. func (a *App) openProjectMenu() { a.title.projectOpen = true + a.title.runConfigOpen = false a.closeBranches() var buf [chromeMenuRecents]int for _, i := range a.menuRecents(&buf) { diff --git a/desktop/internal/workbench/chrome_view.go b/desktop/internal/workbench/chrome_view.go index 1193d68e06..a17c6a4ee0 100644 --- a/desktop/internal/workbench/chrome_view.go +++ b/desktop/internal/workbench/chrome_view.go @@ -149,13 +149,21 @@ func (a *App) chromeTitleButton(c ui.C, i int) bool { switch a.chrome.catalog[i].id { case itemRunConfig: k := c.KeyInt(i) - box := a.chromeBox(ui.Row(k).Height(chromeIconButton).Shrink(0).Items(ui.Center).Gap(chromeGap).PadX(chromeEdge), ui.ID(k), i, false, "") + wasOpen := a.title.runConfigOpen + box := a.chromeBox(ui.Row(k).Height(chromeIconButton).Shrink(0).Items(ui.Center).Gap(chromeGap).PadX(chromeEdge), ui.ID(k), i, wasOpen, "") box.Children(func() { ui.Icon(k, *a.chrome.catalog[i].icon).Size(chromeIconSize, chromeIconSize).Color(a.colors.Subtle) - ui.Text(k, a.text.Title.CurrentFile).Color(a.colors.Text).LineHeight(chromeLineHeight) + ui.Text(k, a.titleRunLabel()).Color(a.colors.Text).LineHeight(chromeLineHeight).Ellipsis().MaxWidth(chromeProjectMax) ui.Icon(k, icons.ChevronDown).Size(chromeMarkSize, chromeMarkSize).Color(a.colors.Subtle) }) - return box.Clicked() + clicked := box.Clicked() + if wasOpen { + a.titleRunConfigMenu(c, box) + } + if clicked && !wasOpen { + c.After(a.openRunConfigMenu) + } + return false case itemTitleRun: // Run is the one button that keeps its color at rest: green says what it does. _, clicked := a.chromeGlyph(c, i, chromeIconButton, a.colors.Success, a.colors.Success, false) @@ -168,7 +176,7 @@ func (a *App) chromeTitleButton(c ui.C, i int) bool { } if clicked && !wasOpen { a.title.gearOpen = true - a.title.projectOpen = false + a.title.projectOpen, a.title.runConfigOpen = false, false c.After(a.closeBranches) } return false diff --git a/desktop/internal/workbench/debug.go b/desktop/internal/workbench/debug.go index 9d9583922f..3c7c2e5e84 100644 --- a/desktop/internal/workbench/debug.go +++ b/desktop/internal/workbench/debug.go @@ -53,6 +53,10 @@ type debugState struct { loading bool adapters []debugAdapter selectedAdapter int + // afterLoad are the starts waiting for the installed adapters, run once they are read. + afterLoad []func() + // preparing is set while a build provider prepares a program for debugging. + preparing bool // breakpoints maps an absolute source path to its breakpoints, sorted by line, and // breakpointEdit is the open editor of one of them (debug_breakpoints.go). breakpoints map[string][]debugBreakpoint @@ -75,6 +79,11 @@ type debugState struct { // pendingRemote is the start in flight, kept so a remote endpoint can be // confirmed and the same start repeated. pendingRemote *debugStart + // muted keeps the breakpoints but sends the sessions none of them (debug_mute.go), and + // rerun starts the shown session again the way it was first started; nil before a start + // the window can repeat. + muted bool + rerun func() // debugSessionView is what the window shows for the current session. debugSessionView } @@ -85,10 +94,12 @@ type debugSessionView struct { state string status string failure string - // output is the adapter's bounded stderr and console text. - output []string - exception *core.DebugExceptionInfo - frames []core.DebugStackFrame + // output is the adapter's bounded stderr and console text, and outputCount the additions + // to it, which tell the console new lines from a list that only dropped its oldest ones. + output []string + outputCount int + exception *core.DebugExceptionInfo + frames []core.DebugStackFrame // hideFiltered collapses the frames the session's stepping filters match into one // row per run; framesExpanded shows them again until the next stack arrives. hideFiltered bool @@ -360,6 +371,15 @@ func (s *debugSession) closeTransport() { } } +// addOutput appends text to the bounded output and counts the addition. +func (v *debugSessionView) addOutput(text string) { + if text == "" { + return + } + v.output = appendDebugOutput(v.output, text) + v.outputCount++ +} + // appendDebugOutput keeps the adapter's diagnostics bounded and whole-line. func appendDebugOutput(lines []string, text string) []string { if text == "" { @@ -420,6 +440,30 @@ func (a *App) finishDebugAdapters(p *project, adapters []debugAdapter, err error if err != nil && len(adapters) == 0 { p.debug.failure = err.Error() } + a.flushDebugAdapterWaiters(p) +} + +// whenDebugAdaptersLoaded runs start on the window thread once the installed adapters are +// read: now when they are, or after loadDebugAdapters answers. A project that closes before +// the answer drops start with it. +func (a *App) whenDebugAdaptersLoaded(p *project, start func()) { + if p == nil { + return + } + p.debug.afterLoad = append(p.debug.afterLoad, start) + a.loadDebugAdapters(p) + if p.debug.loaded && !p.debug.loading { + a.flushDebugAdapterWaiters(p) + } +} + +// flushDebugAdapterWaiters runs the starts that waited for the installed adapters. +func (a *App) flushDebugAdapterWaiters(p *project) { + waiting := p.debug.afterLoad + p.debug.afterLoad = nil + for _, start := range waiting { + start() + } } // receiveDebug feeds one stdout chunk to Core and publishes what it answered. @@ -563,7 +607,7 @@ func (a *App) applyDebugUpdate(p *project, session *debugSession, update core.De // Opening the child changes the sessions, so it runs after this update. a.post(func(a *App) { a.startChildDebug(p, session, event) }) case "output": - p.debug.output = appendDebugOutput(p.debug.output, event.Output) + p.debug.addOutput(event.Output) } } } @@ -689,7 +733,7 @@ func (a *App) sendSessionBreakpoints(p *project, session *debugSession, path str if session == nil || session.stopped.Load() { return } - points := sourceBreakpoints(p.debug.breakpoints[path]) + points := sessionSourceBreakpoints(p.debug.breakpoints[path], p.debug.muted) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { // A session still starting takes the change once Core has it; one that never // got that far has no breakpoints to replace. @@ -905,7 +949,7 @@ func (a *App) appendDebugOutput(p *project, session *debugSession, text string) return } defer p.debug.bindSession(session)() - p.debug.output = appendDebugOutput(p.debug.output, text) + p.debug.addOutput(text) } // debugFileName is the label of a breakpoint row. diff --git a/desktop/internal/workbench/debug_adapter_test.go b/desktop/internal/workbench/debug_adapter_test.go index f3aa981ae1..6ad0beb330 100644 --- a/desktop/internal/workbench/debug_adapter_test.go +++ b/desktop/internal/workbench/debug_adapter_test.go @@ -102,6 +102,7 @@ func serveFixtureAdapter(input io.Reader, output io.Writer, workspace string) in "supportsSteppingGranularity": true, "supportsReadMemoryRequest": true, "supportsSingleThreadExecutionRequests": true, + "supportsInstructionBreakpoints": true, "exceptionBreakpointFilters": []any{ map[string]any{"filter": "uncaught", "label": "Uncaught Exceptions", "default": true}, map[string]any{"filter": "caught", "label": "Caught Exceptions", "default": false}, @@ -116,6 +117,16 @@ func serveFixtureAdapter(input io.Reader, output io.Writer, workspace string) in if request.Command == "disconnect" { return 0 } + case "setInstructionBreakpoints": + var arguments struct { + Breakpoints []any `json:"breakpoints"` + } + _ = json.Unmarshal(request.Body, &arguments) + verified := make([]any, len(arguments.Breakpoints)) + for index := range verified { + verified[index] = map[string]any{"verified": true} + } + respond(map[string]any{"breakpoints": verified}) case "setBreakpoints": respond(map[string]any{"breakpoints": []any{map[string]any{"verified": true, "line": 3}}}) case "stackTrace": @@ -181,10 +192,36 @@ func serveFixtureAdapter(input io.Reader, output io.Writer, workspace string) in map[string]any{"id": 8, "name": "worker"}, }}) case "readMemory": + var arguments struct { + Reference string `json:"memoryReference"` + Offset int64 `json:"offset"` + Count int `json:"count"` + } + _ = json.Unmarshal(request.Body, &arguments) + if arguments.Reference == "0x1000" && arguments.Offset == 0 { + // The instruction pointer: four readable bytes, then two that are not. + respond(map[string]any{ + "address": "0x1000", + "unreadableBytes": 2, + "data": base64.StdEncoding.EncodeToString([]byte{0x48, 0x8b, 0x05, 0x10}), + }) + continue + } + // Any other numeric address reads as bytes that are the low byte of their address. + start, err := strconv.ParseUint(strings.TrimPrefix(arguments.Reference, "0x"), 16, 64) + if err != nil { + write(map[string]any{"type": "response", "request_seq": request.Seq, "success": false, + "command": request.Command, "message": "unknown memory reference"}) + continue + } + start = uint64(int64(start) + arguments.Offset) + data := make([]byte, arguments.Count) + for index := range data { + data[index] = byte(start + uint64(index)) + } respond(map[string]any{ - "address": "0x1000", - "unreadableBytes": 2, - "data": base64.StdEncoding.EncodeToString([]byte{0x48, 0x8b, 0x05, 0x10}), + "address": fmt.Sprintf("0x%x", start), + "data": base64.StdEncoding.EncodeToString(data), }) case "next", "stepIn", "stepOut": var arguments struct { diff --git a/desktop/internal/workbench/debug_breakpoints.go b/desktop/internal/workbench/debug_breakpoints.go index dec9295402..b5745aedb1 100644 --- a/desktop/internal/workbench/debug_breakpoints.go +++ b/desktop/internal/workbench/debug_breakpoints.go @@ -180,7 +180,7 @@ func (a *App) sendFunctionBreakpoints(p *project) { return } session := p.debug.activeSession() - breakpoints := slices.Clone(p.debug.functionBreakpoints) + breakpoints := unlessMuted(slices.Clone(p.debug.functionBreakpoints), p.debug.muted) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() @@ -247,7 +247,7 @@ func (a *App) sendInstructionBreakpoints(p *project) { return } session := p.debug.activeSession() - breakpoints := slices.Clone(p.debug.instructionBreakpoints) + breakpoints := unlessMuted(slices.Clone(p.debug.instructionBreakpoints), p.debug.muted) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() @@ -339,6 +339,7 @@ func (a *App) sendDataBreakpoints(p *project) { for _, breakpoint := range p.debug.dataBreakpoints { breakpoints = append(breakpoints, breakpoint.DebugDataBreakpoint) } + breakpoints = unlessMuted(breakpoints, p.debug.muted) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() diff --git a/desktop/internal/workbench/debug_disassembly.go b/desktop/internal/workbench/debug_disassembly.go index 026b17f47f..b12d94c92d 100644 --- a/desktop/internal/workbench/debug_disassembly.go +++ b/desktop/internal/workbench/debug_disassembly.go @@ -2,6 +2,8 @@ package workbench import ( "context" + "slices" + "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/vivaui/viva/ui" @@ -29,7 +31,11 @@ type debugDisassembly struct { // beforeDone and afterDone record that Core found the end of the code in // that direction. beforeDone, afterDone bool - list ui.ListState + // opening is set while the first window is laid out for the first time. That layout + // takes the rows at an estimated height and the window's height for the list's, so the + // rows it reports say nothing about where the user scrolled. + opening bool + list ui.ListState // frame is the stack frame the window belongs to. frame int // pending holds the instructions of the reply being reduced; Core answers @@ -75,6 +81,30 @@ func (a *App) loadDisassemblyEdge(p *project, direction string) { a.planDisassembly(p, direction, reference, debugDisassemblyEdge, 0) } +// loadDisassemblyAtEdges extends the window when the last paint showed its first or last row, +// as IntelliJ IDEA's disassembly loads more code while it is scrolled. A window the list shows +// whole is not extended: nothing was scrolled, and every extension would show whole again. +func (a *App) loadDisassemblyAtEdges(p *project) { + w := &p.debug.disassembly + first, last := w.list.Visible() + if w.loading || last < first { + return + } + if w.opening { + // The first layout is the one this paint reports; the next reports one at the real + // heights, centred where the window opened. + w.opening = false + return + } + end := len(w.rows) - 1 + switch { + case first == 0 && last < end && !w.beforeDone: + a.loadDisassemblyEdge(p, "before") + case last >= end && first > 0 && !w.afterDone: + a.loadDisassemblyEdge(p, "after") + } +} + // planDisassembly asks Core for the first request of a window, then follows // Core's steps until it answers with a page or a failure. func (a *App) planDisassembly(p *project, direction, reference string, count, before uint32) { @@ -167,13 +197,26 @@ func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, re } switch fetch.Direction { case "before": + // The rows shown stay where they were as the earlier ones go in above. + // Visible counts the rows laid out past both edges too, so the middle of + // that range, not its first row, is what stays in place. + first, last := d.list.Visible() d.rows = append(kept, d.rows...) d.beforeDone = step.Exhausted + if len(kept) > 0 && last >= first { + d.list.ScrollTo((first+last)/2+len(kept), ui.ListCenter) + } case "after": d.rows = append(d.rows, kept...) d.afterDone = step.Exhausted default: - d.rows = kept + // The first window opens on the current instruction. + d.rows, d.opening = kept, true + if index := slices.IndexFunc(kept, func(row core.DebugInstruction) bool { + return strings.EqualFold(strings.TrimSpace(row.Address), strings.TrimSpace(d.anchor)) + }); index >= 0 { + d.list.ScrollTo(index, ui.ListCenter) + } } default: d.loading, d.failure = false, step.Message diff --git a/desktop/internal/workbench/debug_gutter.go b/desktop/internal/workbench/debug_gutter.go index 6ee0e40c46..d8f5c27953 100644 --- a/desktop/internal/workbench/debug_gutter.go +++ b/desktop/internal/workbench/debug_gutter.go @@ -47,7 +47,7 @@ func (a *App) applyDebugGutter(p *project, d *document) { for _, point := range p.debug.breakpoints[d.path] { g.next = append(g.next, editorview.Breakpoint{ Line: int(point.line - 1), - Disabled: point.disabled, + Disabled: point.disabled || p.debug.muted, Conditional: point.condition != "" || point.hitCondition != "", Log: point.logMessage != "", }) diff --git a/desktop/internal/workbench/debug_memory.go b/desktop/internal/workbench/debug_memory.go index 631b565510..59b88e3974 100644 --- a/desktop/internal/workbench/debug_memory.go +++ b/desktop/internal/workbench/debug_memory.go @@ -4,18 +4,36 @@ import ( "context" "encoding/base64" "fmt" + "strconv" "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/ui" ) const ( - // debugMemoryBytes is one readMemory window. The address is opaque text, so - // the host never asks for more than one page and never computes an address. - debugMemoryBytes = 256 - // debugMemoryColumns is how many bytes one hex row shows. - debugMemoryColumns = 16 + // debugMemoryBytes is one readMemory window. The host never asks for more than one window. + debugMemoryBytes = 1024 + // debugMemoryAlign is the multiple a window starts on when the address read at is a number, + // so the rows of every bytes-per-row choice start on a multiple of their width. + debugMemoryAlign = 64 + // debugMemoryDefaultColumns is how many bytes one row shows until the user chooses. + debugMemoryDefaultColumns = 16 + // debugMemoryAddressWidth is the width of the address field and debugMemoryPickerWidth + // that of each layout picker. + debugMemoryAddressWidth = 200 + debugMemoryPickerWidth = 130 + // debugMemoryMarkAlpha is how strongly the byte read at is tinted with the accent color. + debugMemoryMarkAlpha = 0.35 +) + +// debugMemoryColumnChoices are the bytes-per-row choices and debugMemoryRadixChoices the +// bases a byte can be written in, as the memory views of IntelliJ IDEA and CLion offer them. +var ( + debugMemoryColumnChoices = []int{8, 16, 32, 64} + debugMemoryRadixChoices = []int{16, 10, 8, 2} ) // debugMemory is the read-only memory window of the selected frame. Core owns @@ -24,22 +42,43 @@ const ( type debugMemory struct { bytes []byte address string - // at is the address the user asked to read, from the disassembly's menu; empty reads at the - // selected frame's instruction pointer. Like every reference of the adapter it is opaque - // text and holds only until the debuggee runs again. - at string + // at is the address the user asked to read, typed in the field or from the disassembly's + // menu; empty reads at the selected frame's instruction pointer. Like every reference of + // the adapter it holds only until the debuggee runs again. + at string + // input is the address field's text: the address read at once a window arrives, then + // whatever the user types until Enter reads there. + input string + // mark is the index in bytes of the byte at the address read, highlighted; -1 for none. + mark int unreadable int64 loading bool requested bool failure string - // lines is the formatted hex dump; version rises with every load. - lines []string + // columns is how many bytes one row shows and radix the base each byte is written in; + // zero is the default. Both outlive the window, which every stop resets. + columns, radix int + // lines is the laid-out window; version rises with every load and with every layout + // choice. + lines []debugMemoryLine version uint64 shown uint64 list ui.ListState } -func (m *debugMemory) reset() { *m = debugMemory{} } +func (m *debugMemory) reset() { *m = debugMemory{columns: m.columns, radix: m.radix} } + +// layout is the bytes per row and the base the window is laid out in. +func (m *debugMemory) layout() (columns, radix int) { + columns, radix = m.columns, m.radix + if columns == 0 { + columns = debugMemoryDefaultColumns + } + if radix == 0 { + radix = 16 + } + return columns, radix +} // canReadDebugMemory reports whether the paused frame has an address the adapter // can read. It mirrors Core's checks so the section never asks for a refusal. @@ -61,21 +100,27 @@ func debugMemoryReference(d *debugState) string { } // readDebugMemoryAt shows the memory window read at address, as the disassembly's Read Memory -// at Address does. +// at Address and the window's address field do. An empty address reads at the selected frame's +// instruction pointer. func (a *App) readDebugMemoryAt(p *project, address string) { d := &p.debug if d.memory.loading { return } d.memory.reset() - d.memory.at = address + d.memory.at = strings.TrimSpace(address) + if value, ok := parseDebugAddress(d.memory.at); ok { + // A number is sent as the protocol writes addresses, so a decimal one reads as typed. + d.memory.at = fmt.Sprintf("0x%x", value) + } d.section = debugSectionMemory a.loadDebugMemory(p) } -// loadDebugMemory reads one bounded window at the selected frame's instruction -// pointer. Core rejects a request the adapter cannot serve; the failure stays in -// the section. +// loadDebugMemory reads one bounded window at the address asked for. When that address is a +// number the window starts a little before it, on a multiple of debugMemoryAlign, so the +// address sits in its row as it would in a full dump; an opaque reference is read from where +// it points. Core rejects a request the adapter cannot serve; the failure stays in the section. func (a *App) loadDebugMemory(p *project) { d := &p.debug if d.memory.loading { @@ -88,8 +133,13 @@ func (a *App) loadDebugMemory(p *project) { return } reference := debugMemoryReference(d) + target, numeric := parseDebugAddress(reference) + lead := int64(0) + if numeric { + lead = int64(target % debugMemoryAlign) + } d.memory.loading, d.memory.requested, d.memory.failure = true, false, "" - offset, count := int64(0), int64(debugMemoryBytes) + offset, count := -lead, int64(debugMemoryBytes) a.debugOperation(p, "readMemory", func(ctx context.Context, session *debugSession, operationID string) (core.DebugUpdate, error) { return a.kernel.InspectDebug(ctx, core.DebugInspectRequest{ SessionID: session.id, OperationID: operationID, Kind: "readMemory", @@ -112,43 +162,119 @@ func (a *App) loadDebugMemory(p *project) { if m.address == "" { m.address = reference } + // The adapter says where the bytes start; without a number for it, the bytes start + // where they were asked from. + m.mark = int(lead) + if base, ok := parseDebugAddress(result.Address); ok && numeric { + m.mark = -1 + if target >= base && target-base < uint64(len(data)) { + m.mark = int(target - base) + } + } + if m.mark >= len(data) { + m.mark = -1 + } + if m.input == "" { + m.input = reference + } m.version++ + if m.mark >= 0 { + columns, _ := m.layout() + m.list.ScrollTo(m.mark/columns, ui.ListCenter) + } }, failed: func(a *App, message string, _ bool) { m := &p.debug.memory m.loading, m.failure = false, message }}) } -// debugMemoryLines lays out a byte window as offset, hex and printable ASCII. -// Empty data yields no rows. -func debugMemoryLines(data []byte) []string { - if len(data) == 0 { +// parseDebugAddress reads an address as the Debug Adapter Protocol writes one: hexadecimal +// after 0x, decimal otherwise. Anything else is an opaque reference and reports false. +func parseDebugAddress(text string) (uint64, bool) { + text = strings.TrimSpace(text) + base := 10 + if len(text) > 2 && (text[:2] == "0x" || text[:2] == "0X") { + text, base = text[2:], 16 + } + value, err := strconv.ParseUint(text, base, 64) + return value, err == nil +} + +// debugMemoryLine is one row of the memory window: its text, and the byte ranges of the +// marked byte's cell and character in it, both empty when the row does not hold that byte. +type debugMemoryLine struct { + text string + cell, char [2]int +} + +// debugMemoryLines lays out a byte window as rows of columns bytes: the address of the row, +// each byte written in radix, and the bytes as printable ASCII. Rows are labelled with the +// address from base on when absolute, else with their offset in the window. mark is the +// index of the byte to highlight, -1 for none. Empty data yields no rows. +func debugMemoryLines(data []byte, base uint64, absolute bool, columns, radix, mark int) []debugMemoryLine { + if len(data) == 0 || columns <= 0 { return nil } - lines := make([]string, 0, (len(data)+debugMemoryColumns-1)/debugMemoryColumns) - for start := 0; start < len(data); start += debugMemoryColumns { - end := start + debugMemoryColumns - if end > len(data) { - end = len(data) + format, width := debugMemoryCellFormat(radix) + label := "%04x" + if absolute { + digits := max(8, len(strconv.FormatUint(base+uint64(len(data)), 16))) + label = "0x%0" + strconv.Itoa(digits) + "x" + } + lines := make([]debugMemoryLine, 0, (len(data)+columns-1)/columns) + var row strings.Builder + for start := 0; start < len(data); start += columns { + end := min(start+columns, len(data)) + row.Reset() + line := debugMemoryLine{} + address := uint64(start) + if absolute { + address += base + } + fmt.Fprintf(&row, label+" ", address) + for index := start; index < start+columns; index++ { + if index >= end { + row.WriteString(strings.Repeat(" ", width+1)) + continue + } + if index == mark { + line.cell = [2]int{row.Len(), row.Len() + width} + } + fmt.Fprintf(&row, format+" ", data[index]) } - var hex, text strings.Builder + row.WriteByte(' ') for index := start; index < end; index++ { - fmt.Fprintf(&hex, "%02x ", data[index]) + if index == mark { + line.char = [2]int{row.Len(), row.Len() + 1} + } if data[index] >= 0x20 && data[index] < 0x7f { - text.WriteByte(data[index]) + row.WriteByte(data[index]) } else { - text.WriteByte('.') + row.WriteByte('.') } } - for index := end - start; index < debugMemoryColumns; index++ { - hex.WriteString(" ") - } - lines = append(lines, fmt.Sprintf("%04x %s %s", start, hex.String(), text.String())) + line.text = row.String() + lines = append(lines, line) } return lines } -// debugMemoryView declares the read-only memory window of the selected frame. +// debugMemoryCellFormat is the format of one byte in radix and the width it takes. +func debugMemoryCellFormat(radix int) (format string, width int) { + switch radix { + case 2: + return "%08b", 8 + case 8: + return "%03o", 3 + case 10: + return "%3d", 3 + } + return "%02x", 2 +} + +// debugMemoryView declares the read-only memory window of the selected frame: an address field +// to read anywhere, the way back to the current instruction, the bytes-per-row and base +// pickers, then the rows with the byte at the address read highlighted. func (a *App) debugMemoryView(c ui.C, p *project) { t, d := a.text.Debug, &p.debug m := &d.memory @@ -162,14 +288,73 @@ func (a *App) debugMemoryView(c ui.C, p *project) { m.requested = true a.loadDebugMemory(p) } - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - address := m.address - if address == "" { - address = debugMemoryReference(d) + a.debugMemoryToolbar(c, p) + columns, radix := m.layout() + if m.shown != m.version { + base, absolute := parseDebugAddress(m.address) + m.lines = debugMemoryLines(m.bytes, base, absolute, columns, radix, m.mark) + m.shown = m.version + } + lines := m.lines + if len(lines) == 0 { + // The request is in flight or failed; the header already reports both, so + // an empty window is not the "adapter cannot read memory" case. + return + } + marked := a.colors.Accent + marked.Alpha *= debugMemoryMarkAlpha + m.list.Label = func(i int) string { return lines[i].text } + ui.List(c, &m.list, len(lines), func(row ui.ListRow) { + row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center) + line := lines[row.Index] + if line.cell[1] == 0 { + ui.Text(row.C, line.text).FontSize(12.5).Color(a.colors.Text).Mono().Ellipsis() + return } - ui.Text(c, address).Shrink(0).FontSize(12).Color(a.colors.Subtle).Mono() - if ui.Button(c, t.Reload).Outline().Disabled(m.loading).Clicked() { - c.After(func() { a.loadDebugMemory(p) }) + // The row of the byte read at is written in pieces so that byte's cell and character + // can be highlighted; monospace keeps the pieces in their columns. + segment := func(text string, mark bool) { + piece := ui.Text(row.C, text).Shrink(0).FontSize(12.5).Color(a.colors.Text).Mono() + if mark { + piece.Background(marked).Radius(2) + } + } + segment(line.text[:line.cell[0]], false) + segment(line.text[line.cell[0]:line.cell[1]], true) + segment(line.text[line.cell[1]:line.char[0]], false) + segment(line.text[line.char[0]:line.char[1]], true) + ui.Text(row.C, line.text[line.char[1]:]).Shrink(1).FontSize(12.5).Color(a.colors.Text).Mono().Ellipsis() + }).Label(t.Memory).FillWidth().Grow(1) +} + +// debugMemoryToolbar declares the memory window's controls. Enter in the address field or the +// search button reads at the typed address; the locate button reads at the selected frame's +// instruction pointer again. The pickers lay the same bytes out again without reading. +func (a *App) debugMemoryToolbar(c ui.C, p *project) { + t, d := a.text.Debug, &p.debug + m := &d.memory + lang := a.language() + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(4).PadX(8).Children(func() { + placeholder := i18n.Shared(lang, "desktop.debug.memoryAddressPlaceholder") + field := ui.TextField(c.Key("memoryAddress"), &m.input, i18n.Shared(lang, "desktop.debug.memoryAddress"), placeholder). + Width(debugMemoryAddressWidth).Shrink(1).Mono() + goTo := field.Submitted() + if _, clicked := a.toolIconButton(c.Part("memoryGo"), i18n.Shared(lang, "desktop.debug.memoryGoToAddress"), icons.Search, false, m.loading || strings.TrimSpace(m.input) == ""); clicked { + goTo = true + } + if goTo && strings.TrimSpace(m.input) != "" { + address := m.input + c.After(func() { + a.performed("debug.memory.goToAddress", surfaceButton) + a.readDebugMemoryAt(p, address) + p.debug.memory.input = p.debug.memory.at + }) + } + if _, clicked := a.toolIconButton(c.Part("memoryCurrent"), t.Reload, icons.Locate, false, m.loading); clicked { + c.After(func() { + a.performed("debug.memory.currentInstruction", surfaceButton) + a.readDebugMemoryAt(p, "") + }) } if m.unreadable > 0 { ui.Text(c, t.MemoryUnreadableBytes(int(m.unreadable))).Shrink(0).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Warning) @@ -181,20 +366,48 @@ func (a *App) debugMemoryView(c ui.C, p *project) { case m.loading: ui.Text(c, t.LoadingVariables).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) } + columns, radix := m.layout() + if ui.Select(c.Key("memoryColumns"), &columns, debugMemoryColumnChoices, func(count int) string { + return i18n.SharedFormat(lang, "desktop.debug.memoryRowBytes", map[string]string{"bytes": strconv.Itoa(count)}) + }).Label(i18n.Shared(lang, "desktop.debug.memoryBytesPerRow")).Width(debugMemoryPickerWidth).Height(24).Shrink(1); columns != m.columns && (m.columns != 0 || columns != debugMemoryDefaultColumns) { + value := columns + c.After(func() { a.setDebugMemoryLayout(p, value, 0) }) + } + if ui.Select(c.Key("memoryRadix"), &radix, debugMemoryRadixChoices, func(radix int) string { + return debugMemoryRadixName(lang, radix) + }).Label(i18n.Shared(lang, "desktop.debug.memoryRadix")).Width(debugMemoryPickerWidth).Height(24).Shrink(1); radix != m.radix && (m.radix != 0 || radix != 16) { + value := radix + c.After(func() { a.setDebugMemoryLayout(p, 0, value) }) + } }) - if m.shown != m.version { - m.lines = debugMemoryLines(m.bytes) - m.shown = m.version +} + +// setDebugMemoryLayout changes the bytes per row or the base, zero leaving one as it is, and +// keeps the byte read at in view. +func (a *App) setDebugMemoryLayout(p *project, columns, radix int) { + m := &p.debug.memory + if columns != 0 { + m.columns = columns } - lines := m.lines - if len(lines) == 0 { - // The request is in flight or failed; the header already reports both, so - // an empty window is not the "adapter cannot read memory" case. - return + if radix != 0 { + m.radix = radix } - m.list.Label = func(i int) string { return lines[i] } - ui.List(c, &m.list, len(lines), func(row ui.ListRow) { - row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center) - ui.Text(row.C, lines[row.Index]).FontSize(12.5).Color(a.colors.Text).Mono().Ellipsis() - }).Label(t.Memory).FillWidth().Grow(1) + m.version++ + if m.mark >= 0 { + columns, _ := m.layout() + m.list.ScrollTo(m.mark/columns, ui.ListCenter) + } +} + +// debugMemoryRadixName names one base in the base picker. +func debugMemoryRadixName(lang i18n.Language, radix int) string { + switch radix { + case 2: + return i18n.Shared(lang, "desktop.debug.memoryRadixBinary") + case 8: + return i18n.Shared(lang, "desktop.debug.memoryRadixOctal") + case 10: + return i18n.Shared(lang, "desktop.debug.memoryRadixDecimal") + } + return i18n.Shared(lang, "desktop.debug.memoryRadixHex") } diff --git a/desktop/internal/workbench/debug_memory_test.go b/desktop/internal/workbench/debug_memory_test.go index 1fac5e12cb..300d8ee589 100644 --- a/desktop/internal/workbench/debug_memory_test.go +++ b/desktop/internal/workbench/debug_memory_test.go @@ -8,25 +8,67 @@ import ( "time" ) -func TestDebugMemoryLinesFormatOffsetsHexAndText(t *testing.T) { - lines := debugMemoryLines([]byte{0x48, 0x8b, 0x05, 0x10, 'A', 0x00}) +func TestDebugMemoryLinesFormatOffsetsRadixAndText(t *testing.T) { + data := []byte{0x48, 0x8b, 0x05, 0x10, 'A', 0x00} + lines := debugMemoryLines(data, 0, false, 16, 16, -1) if len(lines) != 1 { t.Fatalf("lines = %#v, want one row", lines) } line := lines[0] for _, want := range []string{"0000 ", "48 8b 05 10 41 00", "H...A."} { - if !strings.Contains(line, want) { - t.Fatalf("line = %q, want it to contain %q", line, want) + if !strings.Contains(line.text, want) { + t.Fatalf("line = %q, want it to contain %q", line.text, want) } } - if got := debugMemoryLines(nil); got != nil { + if line.cell != [2]int{} || line.char != [2]int{} { + t.Fatalf("an unmarked row marks %v %v", line.cell, line.char) + } + if got := debugMemoryLines(nil, 0, false, 16, 16, -1); got != nil { t.Fatalf("empty memory = %#v, want no rows", got) } - // A full row keeps its trailing text and a second row starts at 0x10. - lines = debugMemoryLines(make([]byte, debugMemoryColumns+1)) - if len(lines) != 2 || !strings.HasPrefix(lines[1], "0010 ") { + // A full row keeps its trailing text and a second row starts at the row width. + lines = debugMemoryLines(make([]byte, 17), 0, false, 16, 16, -1) + if len(lines) != 2 || !strings.HasPrefix(lines[1].text, "0010 ") { t.Fatalf("two rows = %#v", lines) } + lines = debugMemoryLines(make([]byte, 33), 0, false, 32, 16, -1) + if len(lines) != 2 || !strings.HasPrefix(lines[1].text, "0020 ") { + t.Fatalf("rows of 32 = %#v", lines) + } + + // Every base writes the same bytes in its own digits. + for radix, want := range map[int]string{2: "01001000 10001011", 8: "110 213", 10: " 72 139", 16: "48 8b"} { + if text := debugMemoryLines(data[:2], 0, false, 16, radix, -1)[0].text; !strings.Contains(text, want) { + t.Fatalf("base %d row = %q, want %q", radix, text, want) + } + } + + // An absolute window is labelled with addresses and the marked byte's cell and character + // are found in the row that holds it. + lines = debugMemoryLines(data, 0x100000470, true, 4, 16, 5) + if len(lines) != 2 || !strings.HasPrefix(lines[1].text, "0x100000474 ") { + t.Fatalf("absolute rows = %#v", lines) + } + marked := lines[1] + if lines[0].cell != [2]int{} || marked.text[marked.cell[0]:marked.cell[1]] != "00" || marked.text[marked.char[0]:marked.char[1]] != "." { + t.Fatalf("mark at byte 5 = %q cell %v char %v", marked.text, marked.cell, marked.char) + } + if got := marked.text[lines[1].char[0]-1 : marked.char[0]]; got != "A" { + t.Fatalf("the character before the mark is %q, want A", got) + } +} + +func TestParseDebugAddressReadsHexAndDecimal(t *testing.T) { + for text, want := range map[string]uint64{"0x1000": 0x1000, " 0X1f ": 0x1f, "4096": 4096} { + if got, ok := parseDebugAddress(text); !ok || got != want { + t.Fatalf("parse %q = %d %v, want %d", text, got, ok, want) + } + } + for _, text := range []string{"", "0x", "frame:1", "-4"} { + if _, ok := parseDebugAddress(text); ok { + t.Fatalf("parse %q succeeded; an opaque reference is not a number", text) + } + } } func TestDebugMemoryReadsWithoutComputedAddresses(t *testing.T) { @@ -57,8 +99,8 @@ func TestDebugMemoryReadsWithoutComputedAddresses(t *testing.T) { if p.debug.memory.unreadable != 2 { t.Fatalf("unreadable bytes = %d, want 2", p.debug.memory.unreadable) } - if got := debugMemoryLines(p.debug.memory.bytes)[0]; !strings.Contains(got, "48 8b 05 10") { - t.Fatalf("memory line = %q", got) + if p.debug.memory.mark != 0 || p.debug.memory.input != "0x1000" { + t.Fatalf("mark %d input %q, want the instruction pointer's byte and address", p.debug.memory.mark, p.debug.memory.input) } // The toolbar steps by the adapter's default unit. The adapter writes the diff --git a/desktop/internal/workbench/debug_menus.go b/desktop/internal/workbench/debug_menus.go index 0381744592..68fa4b7193 100644 --- a/desktop/internal/workbench/debug_menus.go +++ b/desktop/internal/workbench/debug_menus.go @@ -13,8 +13,8 @@ import ( ) // The context menus of the Debug tool window, with the items the earlier client's debugger -// had: the thread picker copies the thread's name; a stack frame copies its method name, its -// instruction address and its source location, and shows its disassembly; an instruction of +// had: a stack frame copies its method name, its instruction address and its source location, +// shows its disassembly, and copies, resumes or pauses its thread; an instruction of // the disassembly takes or loses a breakpoint, has the memory at its address read and copies // its address or its text; a variable is given // a new value, watched or copied; a watch is evaluated again, copied or removed; a line @@ -37,37 +37,35 @@ func (a *App) copyDebugText(action, text string) { _ = app.SetClipboardText(text) } -// debugThreadMenu is the menu of the row of the thread picker: it copies the selected thread's -// name. -func (a *App) debugThreadMenu(c ui.C, picker ui.Box, p *project) { - ui.ContextMenu(c, picker, func(menu *ui.MenuItems) { - menu.WidthRange(160, 240) - thread := threadIndexOf(p.debug.threads, p.debug.selectedThread) - if thread >= len(p.debug.threads) { - return - } - lang := a.language() - name, id := p.debug.threads[thread].Name, p.debug.threads[thread].ID - if menu.Item(i18n.Shared(lang, "native.copyThreadName")).Disabled(name == "").Clicked() { - c.After(func() { a.copyDebugText("debug.thread.copyName", name) }) +// debugThreadItems are the selected thread's items at the end of a stack frame's menu: the +// picker above the stack fills its row, so the thread is reached through its frames. They copy +// the thread's name and, when the adapter supports it, resume or pause that thread alone. +func (a *App) debugThreadItems(c ui.C, menu *ui.MenuItems, p *project) { + thread := threadIndexOf(p.debug.threads, p.debug.selectedThread) + if thread >= len(p.debug.threads) { + return + } + lang := a.language() + name, id := p.debug.threads[thread].Name, p.debug.threads[thread].ID + menu.Separator() + if menu.Item(i18n.Shared(lang, "native.copyThreadName")).Disabled(name == "").Clicked() { + c.After(func() { a.copyDebugText("debug.thread.copyName", name) }) + } + if command, enabled := canExecuteDebugThread(&p.debug, id); command != "" { + label := i18n.Shared(lang, "native.resumeThread") + if command == "pause" { + label = i18n.Shared(lang, "native.pauseThread") } - // Resuming or pausing one thread alone is offered only when the adapter supports it. - if command, enabled := canExecuteDebugThread(&p.debug, id); command != "" { - label := i18n.Shared(lang, "native.resumeThread") - if command == "pause" { - label = i18n.Shared(lang, "native.pauseThread") - } - if menu.Item(label).Disabled(!enabled).Clicked() { - c.After(func() { - a.performed("debug.thread."+command, surfaceMenu) - a.executeDebugThread(p, id) - }) - } + if menu.Item(label).Disabled(!enabled).Clicked() { + c.After(func() { + a.performed("debug.thread."+command, surfaceMenu) + a.executeDebugThread(p, id) + }) } - }) + } } -// debugFrameMenu is the menu of the stack frame at index. +// debugFrameMenu is the menu of the stack frame at index, followed by its thread's items. func (a *App) debugFrameMenu(c ui.C, row ui.Box, p *project, index int) { ui.ContextMenu(c, row, func(menu *ui.MenuItems) { d := &p.debug @@ -89,19 +87,19 @@ func (a *App) debugFrameMenu(c ui.C, row ui.Box, p *project, index int) { c.After(func() { a.showFrameDisassembly(p, index) }) } } - if frame.SourcePath == "" { - return - } - line, column := strconv.FormatInt(frame.Line, 10), strconv.FormatInt(frame.Column, 10) - menu.Separator() - if menu.Item(i18n.Shared(lang, "native.copySourceLocation")).Clicked() { - location := frame.SourcePath + ":" + line + ":" + column - c.After(func() { a.copyDebugText("debug.frame.copyLocation", location) }) - } - if menu.Item(i18n.Shared(lang, "native.copyRelativeLocation")).Clicked() { - location := filepath.Base(frame.SourcePath) + ":" + line + ":" + column - c.After(func() { a.copyDebugText("debug.frame.copyRelativeLocation", location) }) + if frame.SourcePath != "" { + line, column := strconv.FormatInt(frame.Line, 10), strconv.FormatInt(frame.Column, 10) + menu.Separator() + if menu.Item(i18n.Shared(lang, "native.copySourceLocation")).Clicked() { + location := frame.SourcePath + ":" + line + ":" + column + c.After(func() { a.copyDebugText("debug.frame.copyLocation", location) }) + } + if menu.Item(i18n.Shared(lang, "native.copyRelativeLocation")).Clicked() { + location := filepath.Base(frame.SourcePath) + ":" + line + ":" + column + c.After(func() { a.copyDebugText("debug.frame.copyRelativeLocation", location) }) + } } + a.debugThreadItems(c, menu, p) }) } @@ -236,7 +234,7 @@ func (a *App) debugWatchMenu(c ui.C, row ui.Box, p *project, index int) { lang := a.language() entry := w.entries[index] menu.WidthRange(160, 240) - if menu.Item(t.Reload).Clicked() { + if menu.Item(i18n.Shared(lang, "native.refreshWatches")).Clicked() { c.After(func() { a.performed("debug.watch.refresh", surfaceMenu) a.refreshDebugWatches(p) diff --git a/desktop/internal/workbench/debug_menus_test.go b/desktop/internal/workbench/debug_menus_test.go index f477b21122..aaac659f8f 100644 --- a/desktop/internal/workbench/debug_menus_test.go +++ b/desktop/internal/workbench/debug_menus_test.go @@ -4,8 +4,6 @@ import ( "path/filepath" "testing" "time" - - "github.com/vivaui/viva/gfx" ) // The Debug tool window's context menus copy what a stack frame, an instruction and a variable @@ -22,16 +20,10 @@ func TestDebugMenusCopyFramesAndVariablesAndToggleBreakpoints(t *testing.T) { } h.settle() - // The row of the thread picker copies the selected thread's name. + // A stack frame's menu ends with its thread's items, which copy the thread's name. awaitStateWithin(t, h, 20*time.Second, "the adapter's threads", func() bool { return len(d.threads) == 2 }) h.settle() - var threads gfx.Rect - for _, hit := range h.driver.Snapshot().Hits { - if hit.Label == h.app.text.Debug.Threads && !hit.IsLabel && hit.Bounds.Width > threads.Width { - threads = hit.Bounds - } - } - h.rightClickAt(gfx.Rect{X: threads.X + threads.Width - 40, Y: threads.Y, Width: 20, Height: threads.Height}) + h.rightClickNamed("main") h.click(center(h.popupHit(h.shared("native.copyThreadName")))) if got := h.driver.Clipboard(); got != "main" { t.Fatalf("the clipboard holds %q, want the stopped thread's name", got) @@ -62,7 +54,20 @@ func TestDebugMenusCopyFramesAndVariablesAndToggleBreakpoints(t *testing.T) { // An instruction copies its address and has the memory at that address read. awaitStateWithin(t, h, 20*time.Second, "the instruction window", func() bool { return !d.disassembly.loading && len(d.disassembly.rows) > 1 }) h.settle() - address := d.disassembly.rows[1].Address + // The window opens centred on the current instruction: the one after it is in view, the + // first row of the window is scrolled away above, and nothing more was loaded for it. + address := "0x1004" + // The list measures its rows in the frames it asks for after the first layout; virtual + // time runs them. + if err := h.driver.Advance(200 * time.Millisecond); err != nil { + t.Fatal(err) + } + if !h.shows(address) || h.shows("0xfa0") { + t.Fatalf("the window did not open centred on the current instruction") + } + if rows := len(d.disassembly.rows); rows != 96 { + t.Fatalf("the window holds %d instructions after it opened, want the 96 of the first window", rows) + } h.rightClickAt(h.labelBounds(address)) h.click(center(h.popupHit(h.shared("debugger.disassembly.copyAddress")))) if got := h.driver.Clipboard(); got != address { @@ -76,7 +81,7 @@ func TestDebugMenusCopyFramesAndVariablesAndToggleBreakpoints(t *testing.T) { awaitStateWithin(t, h, 20*time.Second, "the memory read", func() bool { return !d.memory.loading && len(d.memory.bytes) > 0 }) // A variable copies its value and its name, and Set Value shows the field for it. - h.clickNamed(h.app.text.Debug.Variables) + h.showDebugSection(h.shared("debugger.threadsAndVariables")) h.rightClickNamed("count = 1") h.click(center(h.popupHit(h.shared("native.copyValue")))) if got := h.driver.Clipboard(); got != "1" { @@ -93,11 +98,11 @@ func TestDebugMenusCopyFramesAndVariablesAndToggleBreakpoints(t *testing.T) { t.Fatalf("Set Value selected %+v, want count", selected) } - // The Breakpoints section lists the line breakpoints; one is removed with the others. + // The Breakpoints dialog lists the line breakpoints; one is removed with the others. source := d.frames[0].SourcePath d.breakpoints = map[string][]debugBreakpoint{source: {{line: 3}, {line: 5}}} h.app.sendDebugBreakpoints(p, source) - h.showDebugSection(h.app.text.Debug.Breakpoints) + h.clickNamed(h.shared("native.viewBreakpoints")) // A line breakpoint is disabled and enabled again; a disabled one keeps its line and is // sent as disabled, so Core leaves it out of what the adapter gets. h.rightClickNamed(filepath.Base(source) + ":3") diff --git a/desktop/internal/workbench/debug_mute.go b/desktop/internal/workbench/debug_mute.go new file mode 100644 index 0000000000..45186b5c53 --- /dev/null +++ b/desktop/internal/workbench/debug_mute.go @@ -0,0 +1,56 @@ +package workbench + +import "github.com/1lck/Lithe-IDEA/desktop/internal/core" + +// Muting is the Debug window's switch that keeps every breakpoint the user set but stops the +// adapters from stopping on any of them. The breakpoints stay stored and shown, faded; what +// changes is what each session is sent: every source line goes as disabled, which Core leaves +// out, and the function, instruction and data breakpoints go as empty lists. Unmuting sends +// the stored breakpoints again. + +// sessionSourceBreakpoints is what a session is sent for one file's breakpoints: the lines as +// stored, or all of them disabled while the breakpoints are muted. +func sessionSourceBreakpoints(lines []debugBreakpoint, muted bool) []core.DebugSourceBreakpoint { + points := sourceBreakpoints(lines) + if muted { + for index := range points { + points[index].Enabled = false + } + } + return points +} + +// unlessMuted is list, or nothing while the breakpoints are muted. +func unlessMuted[T any](list []T, muted bool) []T { + if muted { + return nil + } + return list +} + +// toggleMuteBreakpoints mutes or unmutes every breakpoint and sends what the sessions should +// now stop on. A kind of breakpoint the user never set is not sent, so an adapter that serves +// no such kind is never asked to. +func (a *App) toggleMuteBreakpoints(p *project) { + if p == nil { + return + } + d := &p.debug + d.muted = !d.muted + a.performed("debug.muteBreakpoints", surfaceButton) + if len(d.sessions) == 0 { + return + } + for path := range d.breakpoints { + a.sendDebugBreakpoints(p, path) + } + if len(d.functionBreakpoints) > 0 { + a.sendFunctionBreakpoints(p) + } + if len(d.instructionBreakpoints) > 0 { + a.sendInstructionBreakpoints(p) + } + if len(d.dataBreakpoints) > 0 { + a.sendDataBreakpoints(p) + } +} diff --git a/desktop/internal/workbench/debug_sections_view.go b/desktop/internal/workbench/debug_sections_view.go index f1a0f2e6bd..73d7f2025d 100644 --- a/desktop/internal/workbench/debug_sections_view.go +++ b/desktop/internal/workbench/debug_sections_view.go @@ -6,69 +6,78 @@ 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/icons" "github.com/1lck/Lithe-IDEA/desktop/internal/treelist" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) -// The sections of the Debug tool window under its toolbar. The breakpoints are one of them, so -// the call stack and the variables keep the window's height while the debuggee is paused. +// The tabs of the Debug tool window under its toolbar, as IntelliJ IDEA names them: the threads +// and variables of the shown session and its console, then the disassembly and, for an adapter +// that reads memory, the memory. The breakpoints are the toolbar's View Breakpoints dialog. const ( - debugSectionFrames = "frames" - debugSectionVariables = "variables" - debugSectionBreakpoints = "breakpoints" - debugSectionExceptions = "exceptions" + debugSectionThreads = "threads" + debugSectionConsole = "console" debugSectionDisassembly = "disassembly" debugSectionMemory = "memory" ) -// debugSections declares the section switch and the chosen section. +// Minimum widths of the two panes of Threads & Variables, and the share of the call stack +// before the user moves the divider. +const ( + debugFramesMinWidth = 160 + debugVariablesMinWidth = 220 + debugFramesRatio = 0.4 +) + +// debugSections declares the tabs and the chosen tab. func (a *App) debugSections(c ui.C, p *project) { t, d := a.text.Debug, &p.debug - if d.section == "" { - d.section = debugSectionFrames - } - sections := []string{debugSectionFrames, debugSectionVariables, debugSectionBreakpoints, debugSectionExceptions, debugSectionDisassembly} + lang := a.language() + sections := []string{debugSectionThreads, debugSectionConsole, debugSectionDisassembly} + labels := []string{i18n.Shared(lang, "debugger.threadsAndVariables"), i18n.Shared(lang, "debugger.console"), t.Disassembly} if d.capabilities != nil && d.capabilities.SupportsReadMemoryRequest { sections = append(sections, debugSectionMemory) + labels = append(labels, t.Memory) } - if !slices.Contains(sections, d.section) { - d.section = debugSectionFrames + selected := slices.Index(sections, d.section) + if selected < 0 { + selected, d.section = 0, debugSectionThreads } - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).PadX(8).Children(func() { - ui.Tabs(c, &d.section, sections, func(section string) string { - switch section { - case debugSectionVariables: - return t.Variables - case debugSectionBreakpoints: - return t.Breakpoints - case debugSectionExceptions: - return t.Exceptions - case debugSectionDisassembly: - return t.Disassembly - case debugSectionMemory: - return t.Memory - } - return t.Frames - }) + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).PadX(6).Children(func() { + a.toolTabsWith(c.Part("debug-tabs"), selected, labels, func(index int) { d.section = sections[index] }) }) + ui.Divider(c) switch d.section { - case debugSectionVariables: - a.debugVariablesView(c, p) - case debugSectionBreakpoints: - a.debugBreakpoints(c, p) - case debugSectionExceptions: - a.debugExceptionsView(c, p) + case debugSectionConsole: + a.debugConsole(c, p) case debugSectionDisassembly: a.debugDisassemblyView(c, p) case debugSectionMemory: a.debugMemoryView(c, p) default: - a.debugFrames(c, p) + a.debugThreadsAndVariables(c, p) } } +// debugThreadsAndVariables declares the Threads & Variables tab: the call stack on the left and, +// past a divider the user moves, the variables of the selected frame. +func (a *App) debugThreadsAndVariables(c ui.C, p *project) { + split := &p.panels.debugSplit + if split.Ratio <= 0 { + split.Ratio = debugFramesRatio + } + var frames, variables ui.Box + ui.Row(c).Fill().Clip().Children(func() { + frames = ui.Column(c.Part("frames")).Children(func() { a.debugFrames(c, p) }) + ui.Splitter(c, split).Mins(debugFramesMinWidth, debugVariablesMinWidth).Label(a.text.Panel.Resize) + variables = ui.Column(c.Part("variables")).Children(func() { a.debugVariablesView(c, p) }) + }) + frames.FillHeight().MinWidth(debugFramesMinWidth).Shrink(1) + variables.Fill().MinWidth(debugVariablesMinWidth) +} + // debugVariableLabel is the text assistive technology reads for one row. func debugVariableLabel(node *debugVarNode) string { switch { @@ -97,29 +106,23 @@ func (v *debugVariables) key(i int) int { func (v *debugVariables) label(i int) string { return debugVariableLabel(v.rows[i]) } -// debugVariablesView declares the Variables section: the tree or the JSON text -// of the loaded variables and the field that edits the selected one. +// debugVariablesView declares the right pane of Threads & Variables: the field that evaluates an +// expression or adds it as a watch, the watches, and the tree or the JSON text of the selected +// frame's variables with the field that edits the selected one. func (a *App) debugVariablesView(c ui.C, p *project) { t, d := a.text.Debug, &p.debug v := &d.vars + a.debugEvaluateField(c, p) + a.debugExceptionInfo(c, p) a.debugWatchView(c, p) - mode := "tree" - if v.json { - mode = "json" - } - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - a.debugRegistersTabs(c, p) - ui.Tabs(c, &mode, []string{"tree", "json"}, func(m string) string { - if m == "json" { - return t.ViewJSON + if v.registersScope() != nil || v.failure != "" { + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { + a.debugRegistersTabs(c, p) + if v.failure != "" { + ui.Text(c, v.failure).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger).Ellipsis() } - return t.ViewTree }) - if v.failure != "" { - ui.Text(c, v.failure).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger).Ellipsis() - } - }) - v.json = mode == "json" + } switch { case d.activeSession() == nil || len(v.scopes) == 0: message := t.NoVariables @@ -152,16 +155,7 @@ func (a *App) debugVariablesTree(c ui.C, p *project) { a.debugVariableStatusRow(c, node, t.LoadingVariables, t.LoadMore) return } - if node.ref > 0 { - ui.Icon(c, icons.Folder).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) - } - ui.Text(c, node.name).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) - if node.value != "" { - ui.Text(c, "= "+node.value).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis().Mono() - } - if node.typeName != "" { - ui.Text(c, node.typeName).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) - } + a.debugVariableRow(c, node) }).Grow(1).FillWidth() a.debugVariableMenu(c, p) if i, ok := v.tree.Toggled(); ok && i < len(rows) { @@ -180,6 +174,30 @@ func (a *App) debugVariablesTree(c ui.C, p *project) { } } +// debugVariableRow declares one variable as IntelliJ IDEA writes it, "name = {type} value", after +// an icon that tells a value with children from a plain one. A scope is its name alone. +func (a *App) debugVariableRow(c ui.C, node *debugVarNode) { + icon := icons.Variable + switch { + case node.scope: + icon = icons.Folder + case node.ref > 0: + icon = icons.Braces + } + ui.Icon(c, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) + ui.Text(c, node.name).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) + if node.scope || (node.value == "" && node.typeName == "") { + return + } + ui.Text(c, "=").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) + if node.typeName != "" { + ui.Text(c, "{"+node.typeName+"}").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) + } + if node.value != "" { + ui.Text(c, node.value).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis().Mono() + } +} + // debugVariableStatusRow is the last row of a container that has more children, // is loading them or failed: it loads the next page when clicked. func (a *App) debugVariableStatusRow(c ui.C, node *debugVarNode, loading, more string) { @@ -246,16 +264,16 @@ func (a *App) debugVariableEdit(c ui.C, p *project) { }) } -// debugExceptionsView declares one checkbox per exception filter the adapter -// offers. The choice is the user's and outlives the session. +// debugExceptionsView declares the breakpoints dialog's exception breakpoints: one checkbox per +// filter the adapter offers. The choice is the user's and outlives the session. func (a *App) debugExceptionsView(c ui.C, p *project) { t, d := a.text.Debug, &p.debug + ui.Text(c, t.Exceptions).Color(a.colors.Text).Weight(gfx.WeightMedium) if d.capabilities == nil || len(d.capabilities.ExceptionBreakpointFilters) == 0 { - a.panelMessage(c, t.NoExceptionFilters, a.colors.Subtle) + ui.Text(c, t.NoExceptionFilters).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) return } - a.debugExceptionInfo(c, p) - ui.Column(c).FillWidth().Grow(1).Pad(8).Gap(4).Children(func() { + ui.Column(c).FillWidth().Gap(4).PadX(8).Children(func() { for _, filter := range d.capabilities.ExceptionBreakpointFilters { enabled := d.exceptions.exceptionEnabled(filter) if ui.Checkbox(c.Key(filter.Filter), &enabled, filter.Label).Clicked() { @@ -266,7 +284,11 @@ func (a *App) debugExceptionsView(c ui.C, p *project) { }) } -// debugDisassemblyView declares the instruction window of the selected frame. +// debugDisassemblyView declares the instruction window of the selected frame as IntelliJ IDEA +// shows it: no actions of its own. The toolbar's steps take one instruction while this tab is +// shown (see debugStepGranularity), the toolbar's More menu goes back to the current +// instruction, scrolling to either end loads more code, and a click in the gutter sets or +// removes an instruction breakpoint, drawn as the editor draws a line breakpoint. func (a *App) debugDisassemblyView(c ui.C, p *project) { t, d := a.text.Debug, &p.debug w := &d.disassembly @@ -280,59 +302,34 @@ func (a *App) debugDisassemblyView(c ui.C, p *project) { // of an ordinary paint is dropped. The load marks itself loading before it returns. a.loadDisassembly(p) } - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - if ui.Button(c, t.LoadBefore).Outline().Disabled(w.loading || w.beforeDone || len(w.rows) == 0).Clicked() { - c.After(func() { a.loadDisassemblyEdge(p, "before") }) - } - if ui.Button(c, t.LoadAfter).Outline().Disabled(w.loading || w.afterDone || len(w.rows) == 0).Clicked() { - c.After(func() { a.loadDisassemblyEdge(p, "after") }) - } - if ui.Button(c, t.Reload).Outline().Disabled(w.loading).Clicked() { - c.After(func() { a.loadDisassembly(p) }) - } - // A disassembly view steps one instruction at a time; Core forwards the - // granularity only when the adapter advertised it. - if d.capabilities.SupportsSteppingGranularity { - if ui.Button(c, t.StepInto).Outline().Clicked() { - c.After(func() { a.executeDebugWithGranularity(p, "stepIn", "instruction") }) - } - if ui.Button(c, t.StepOver).Outline().Clicked() { - c.After(func() { a.executeDebugWithGranularity(p, "next", "instruction") }) - } - if ui.Button(c, t.StepOut).Outline().Clicked() { - c.After(func() { a.executeDebugWithGranularity(p, "stepOut", "instruction") }) - } - } - ui.Spacer(c) - switch { - case w.failure != "": + if w.failure != "" { + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).PadX(10).Children(func() { ui.Text(c, w.failure).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger).Ellipsis() - case w.loading: - ui.Text(c, t.LoadingVariables).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) - case w.beforeDone && w.afterDone: - ui.Text(c, t.EndOfCode).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) + }) + } + if len(w.rows) == 0 { + if w.loading { + a.panelMessage(c, t.LoadingVariables, a.colors.Subtle) } - }) + return + } + // The last paint's rows say whether the user scrolled to an end; asked on this paint for + // the same reason as the first window. + a.loadDisassemblyAtEdges(p) rows := w.rows + breakpoints := d.capabilities.SupportsInstructionBreakpoints + execution := a.colors.Accent + execution.Alpha *= debugExecutionAlpha w.list.Label = func(i int) string { return rows[i].Address + " " + rows[i].Instruction } ui.List(c, &w.list, len(rows), func(row ui.ListRow) { instruction := rows[row.Index] current := strings.EqualFold(strings.TrimSpace(instruction.Address), strings.TrimSpace(w.anchor)) - element := row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center).Gap(10) + element := row.Element.Height(debugRowHeight).PadSides(0, 10, 0, 4).Items(ui.Center).Gap(10) if current { - element.Background(a.colors.Hover) + element.Background(execution) } - if d.capabilities.SupportsInstructionBreakpoints { - marked := slices.ContainsFunc(d.instructionBreakpoints, func(b core.DebugInstructionBreakpoint) bool { - return b.InstructionReference == instruction.Address - }) - mark := ui.Button(row.C.Key("insn-bp"), t.Breakpoint.Instruction).Small() - if !marked { - mark = mark.Outline() - } - if mark.Clicked() { - row.C.After(func() { a.toggleInstructionBreakpoint(p, instruction.Address) }) - } + if breakpoints { + a.debugInstructionGutter(row.C, p, instruction.Address) } ui.Text(row.C, instruction.Address).Shrink(0).FontSize(12).Color(a.colors.Subtle).Mono() if instruction.Symbol != "" { @@ -345,3 +342,42 @@ func (a *App) debugDisassemblyView(c ui.C, p *project) { a.debugInstructionMenu(row.C, row.Element, p, instruction) }).Label(t.Disassembly).FillWidth().Grow(1) } + +// debugInstructionGutter declares the breakpoint mark at the start of one instruction's row, +// the dot the editor's gutter draws for a line breakpoint: filled while the instruction has a +// breakpoint, an outline while the breakpoints are muted, and a faint dot under the pointer +// where a click would set one. A click sets or removes the breakpoint. +func (a *App) debugInstructionGutter(c ui.C, p *project, address string) { + d := &p.debug + lang := a.language() + index := slices.IndexFunc(d.instructionBreakpoints, func(b core.DebugInstructionBreakpoint) bool { + return b.InstructionReference == address + }) + label := i18n.Shared(lang, "debugger.disassembly.setBreakpoint") + if index >= 0 { + label = i18n.Shared(lang, "debugger.disassembly.removeBreakpoint") + } + k := c.Part("insn-bp") + // The dot is the target; its pointer region reaches the whole gutter cell of the row. + reach := float32(debugRowHeight-debugGutterDot) / 2 + dot := ui.Column(k).Width(debugGutterDot).Height(debugGutterDot).Shrink(0).Radius(debugGutterDot/2). + HitWith(ui.ID(k), label, gfx.HitOptions{Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand}). + HitOutset(reach, 4, reach, 4) + color := a.theme.Danger + switch { + case index < 0: + faint := color + faint.Alpha *= debugGutterHintAlpha + dot.Hover(ui.Look{}.Background(faint)) + case d.muted || !d.instructionBreakpoints[index].Enabled: + dot.Border(debugGutterRing, color) + default: + dot.Background(color) + } + if dot.Clicked() { + c.After(func() { + a.performed("debug.instruction.toggleBreakpoint", surfaceButton) + a.toggleInstructionBreakpoint(p, address) + }) + } +} diff --git a/desktop/internal/workbench/debug_start.go b/desktop/internal/workbench/debug_start.go index 93e1173757..94161d7871 100644 --- a/desktop/internal/workbench/debug_start.go +++ b/desktop/internal/workbench/debug_start.go @@ -58,6 +58,12 @@ type debugStart struct { // startDebugging; its configuration is the adapter's, and parent answers the request. parent *debugSession startRequestID string + // targetPath is the file a launch of the open file debugs; empty means the file selected + // when the session begins. A rerun keeps the file the first start debugged. + targetPath string + // rerun starts this session again the way it was first started, for the Debug window's + // Rerun; nil for a start the window cannot repeat. + rerun func() } // debugRemotePrompt is an attach to a non-local endpoint waiting for the user. @@ -117,10 +123,18 @@ func (a *App) startDebug(p *project) { } start.request, start.target = "attach", target } - // A debuggee reads the files on disk, so settle pending writes before the - // adapter launches; a failed save keeps the session from starting. Nothing to - // settle when every document is already on disk, which also keeps the session - // from waiting on a save batch that has no work. + if doc := p.selectedDocument(p.docs.group); doc != nil { + start.targetPath = doc.path + } + start.rerun = func() { a.saveAndBeginDebug(p, start) } + a.saveAndBeginDebug(p, start) +} + +// saveAndBeginDebug begins start once the open documents are on disk. A debuggee reads the +// files on disk, so pending writes settle before the adapter launches; a failed save keeps the +// session from starting. Nothing to settle when every document is already on disk, which also +// keeps the session from waiting on a save batch that has no work. +func (a *App) saveAndBeginDebug(p *project, start debugStart) { if !a.projectHasPendingWrites(p) { a.beginDebug(p, start) return @@ -132,6 +146,26 @@ func (a *App) startDebug(p *project) { }) } +// rerunDebug is the Debug window's Rerun: it stops the sessions the project runs, the one the +// window shows and the children it started, and starts the shown one again the way it was +// first started. A provider's program is prepared again, so the rerun debugs a fresh build. +func (a *App) rerunDebug(p *project) { + if p == nil || p.debug.rerun == nil || p.debug.preparing { + return + } + a.performed("debug.rerun", surfaceButton) + rerun := p.debug.rerun + // Each stop removes one session; the bound keeps a session that will not leave from + // holding the window thread. + for range len(p.debug.sessions) { + if p.debug.activeSession() == nil { + break + } + a.stopDebugByUser(p) + } + rerun() +} + // projectHasPendingWrites reports whether some open document has content the debuggee would // not see on disk yet. func (a *App) projectHasPendingWrites(p *project) bool { @@ -342,8 +376,8 @@ func (a *App) beginDebug(p *project, start debugStart) { return } adapter := start.adapter - targetPath := "" - if doc := p.selectedDocument(p.docs.group); doc != nil { + targetPath := start.targetPath + if doc := p.selectedDocument(p.docs.group); targetPath == "" && doc != nil { targetPath = doc.path } pluginRoot := a.plugins.Root @@ -354,6 +388,8 @@ func (a *App) beginDebug(p *project, start debugStart) { // A child shares its parent's generation, so the parent's replies stay current. if start.parent == nil { p.debug.generation++ + // Rerun repeats the session the window shows; a start it cannot repeat leaves it off. + p.debug.rerun = start.rerun } generation := p.debug.generation pending := start @@ -367,7 +403,9 @@ func (a *App) beginDebug(p *project, start debugStart) { } else if declared, ok := core.DeclaredSteppingFilters(adapter.Declaration.Features, adapter.Declaration.Defaults); ok { hideFiltered = declared.HideFilteredStackFrames } - functionBreakpoints := slices.Clone(p.debug.functionBreakpoints) + // Muted breakpoints are kept but not sent, so the new session stops on none of them. + muted := p.debug.muted + functionBreakpoints := unlessMuted(slices.Clone(p.debug.functionBreakpoints), muted) // A data breakpoint whose identity does not persist ends with the session that resolved it. dataBreakpoints := make([]core.DebugDataBreakpoint, 0, len(p.debug.dataBreakpoints)) for _, breakpoint := range p.debug.dataBreakpoints { @@ -375,6 +413,7 @@ func (a *App) beginDebug(p *project, start debugStart) { dataBreakpoints = append(dataBreakpoints, breakpoint.DebugDataBreakpoint) } } + dataBreakpoints = unlessMuted(dataBreakpoints, muted) breakpoints := make(map[string][]debugBreakpoint, len(p.debug.breakpoints)) for path, lines := range p.debug.breakpoints { breakpoints[path] = append([]debugBreakpoint(nil), lines...) @@ -521,7 +560,7 @@ func (a *App) beginDebug(p *project, start debugStart) { a.postDebugUpdate(p, session, update) } for path, lines := range breakpoints { - update, err := a.kernel.SetDebugBreakpoints(ctx, session.id, path, sourceBreakpoints(lines)) + update, err := a.kernel.SetDebugBreakpoints(ctx, session.id, path, sessionSourceBreakpoints(lines, muted)) if err != nil { return func(a *App) { a.finishDebugError(p, session, err) } } diff --git a/desktop/internal/workbench/debug_state_test.go b/desktop/internal/workbench/debug_state_test.go index 00224563ca..3f931f244b 100644 --- a/desktop/internal/workbench/debug_state_test.go +++ b/desktop/internal/workbench/debug_state_test.go @@ -110,7 +110,8 @@ func TestDebugVariablesPageAndEditThroughCore(t *testing.T) { awaitStateWithin(t, h, 20*time.Second, "the stopped session", func() bool { return p.debug.activeSession() == nil }) if len(v.scopes) != 0 { // Stop leaves the stop's variables to the next reset; they are never - // shown without a session. + // shown without a session. The window paints the stop before it is looked at. + h.settle() if h.shows("count") { t.Fatal("variables are shown without a session") } diff --git a/desktop/internal/workbench/debug_tcp_test.go b/desktop/internal/workbench/debug_tcp_test.go index fb8b97563d..4c1fbe3e42 100644 --- a/desktop/internal/workbench/debug_tcp_test.go +++ b/desktop/internal/workbench/debug_tcp_test.go @@ -217,9 +217,7 @@ func TestDebugTCPLanguageServerAdapterBreakpointPauseContinueStop(t *testing.T) } h.app.openFileAtPosition(p, source, 2, 0) h.settle() - h.showDebugSection(h.app.text.Debug.Breakpoints) - h.clickNamed(h.app.text.Debug.ToggleBreakpoint) - h.showDebugSection(h.app.text.Debug.Frames) + toggleBreakpointInDialog(h) h.clickNamed(h.app.text.Debug.Start) awaitStateWithin(t, h, 30*time.Second, "the paused hosted session", func() bool { diff --git a/desktop/internal/workbench/debug_test.go b/desktop/internal/workbench/debug_test.go index 843ab58e79..79d38968e5 100644 --- a/desktop/internal/workbench/debug_test.go +++ b/desktop/internal/workbench/debug_test.go @@ -113,8 +113,8 @@ func openDebugPanel(t *testing.T, h *harness, root string) *project { return p } -// showDebugSection clicks the Debug tool window's tab named label. The section's own header and -// list carry the same name and come after it, so the tab is the first control so named. +// showDebugSection clicks the Debug tool window's tab named label. A list or a header inside +// the tab may carry the same name and comes after it, so the tab is the first control so named. func (h *harness) showDebugSection(label string) { h.t.Helper() for _, hit := range h.driver.Snapshot().Hits { @@ -127,6 +127,18 @@ func (h *harness) showDebugSection(label string) { h.t.Fatalf("no Debug section named %q", label) } +// toggleBreakpointInDialog toggles the breakpoint on the caret's line from the toolbar's +// Breakpoints dialog and closes the dialog again. +func toggleBreakpointInDialog(h *harness) { + h.t.Helper() + h.clickNamed(h.shared("native.viewBreakpoints")) + h.clickNamed(h.app.text.Debug.ToggleBreakpoint) + h.clickNamed(h.shared("ui.done")) + if p := h.app.project; p != nil && p.panels.breakpointsOpen { + h.t.Fatal("Done left the Breakpoints dialog open") + } +} + func TestDebugPanelBreakpointPauseContinueFrames(t *testing.T) { h := debugHarness(t) root := t.TempDir() @@ -144,12 +156,10 @@ func TestDebugPanelBreakpointPauseContinueFrames(t *testing.T) { h.app.openFileAtPosition(p, source, 2, 0) h.settle() - h.showDebugSection(h.app.text.Debug.Breakpoints) - h.clickNamed(h.app.text.Debug.ToggleBreakpoint) + toggleBreakpointInDialog(h) if lines := p.debug.breakpoints[source]; len(lines) != 1 || lines[0].line != 3 { t.Fatalf("breakpoints = %+v, want line 3 of %s", p.debug.breakpoints, source) } - h.showDebugSection(h.app.text.Debug.Frames) h.clickNamed(h.app.text.Debug.Start) awaitStateWithin(t, h, 30*time.Second, "the paused debuggee and its stack", func() bool { diff --git a/desktop/internal/workbench/debug_threads.go b/desktop/internal/workbench/debug_threads.go index 5d328fe0b2..f7bf36600c 100644 --- a/desktop/internal/workbench/debug_threads.go +++ b/desktop/internal/workbench/debug_threads.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/1lck/Lithe-IDEA/desktop/internal/core" - "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -168,10 +167,11 @@ func (a *App) debugThreadResumed(p *project, threadID int64) { d.watch.valuesCleared() } -// debugThreadPicker is the thread selector above the call stack. One thread needs no picker. +// debugThreadPicker is the thread selector above the call stack. It shows a single thread +// too, as IntelliJ IDEA does, so the stack always says whose it is. func (a *App) debugThreadPicker(c ui.C, p *project) { d := &p.debug - if len(d.threads) <= 1 { + if len(d.threads) == 0 { return } t := a.text.Debug @@ -183,10 +183,8 @@ func (a *App) debugThreadPicker(c ui.C, p *project) { selected = index } } - k := c.Key("debugThreads") - row := ui.Row(k).FillWidth().Height(panelHeaderHeight).Shrink(0).PadX(8).Items(ui.Center). - HitWith(ui.ID(k), t.Threads, gfx.HitOptions{SkipFocus: true}) - row.Children(func() { + // The picker fills its row; the thread's own items are at the end of each frame's menu. + ui.Row(c.Key("debugThreads")).FillWidth().Height(panelHeaderHeight).Shrink(0).PadX(8).Items(ui.Center).Children(func() { ui.Select(c.Key("debugThread"), &selected, indexes, func(index int) string { name := d.threads[index].Name if name == "" { @@ -196,13 +194,12 @@ func (a *App) debugThreadPicker(c ui.C, p *project) { name = t.ThreadRunning(name) } return name - }).Label(t.Threads).Width(240).Height(24) + }).Label(t.Threads).FillWidth().Height(24) if selected != threadIndexOf(d.threads, d.selectedThread) { id := d.threads[selected].ID c.After(func() { a.selectDebugThread(p, id) }) } }) - a.debugThreadMenu(k, row, p) } // threadIndexOf reports the position of one thread in the list, or 0 when it is absent. diff --git a/desktop/internal/workbench/debug_threads_test.go b/desktop/internal/workbench/debug_threads_test.go index 33d4b633b2..1025ceee9c 100644 --- a/desktop/internal/workbench/debug_threads_test.go +++ b/desktop/internal/workbench/debug_threads_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/shortcuts" "github.com/vivaui/viva/gfx" ) @@ -77,18 +79,43 @@ func TestDebugThreadsSelectAndRestartWatchesOnEachStop(t *testing.T) { return p.debug.state == "paused" && len(p.debug.threads) == 2 && len(p.debug.watch.entries) == 2 && p.debug.watch.entries[0].value == "42" }) - // The watch editor sits over the variables tree; a window as tall as a laptop screen leaves - // the bottom panel room for both under the breakpoints. + // The evaluate field and the watches sit over the variables tree; a window as tall as a + // laptop screen leaves the bottom panel room for them. if err := h.driver.Resize(1280, 900); err != nil { t.Fatal(err) } - p.debug.section = debugSectionVariables - h.settle() - p.debug.section = debugSectionVariables + p.debug.section = debugSectionThreads h.app.invalidator.Invalidate() h.settle() - if !h.shows("监视") || !h.shows("求值表达式") { - t.Fatal("the Debug panel does not show the watch editor") + evaluate := i18n.SharedFormat(h.app.language(), "desktop.debug.evaluatePlaceholder", map[string]string{ + "evaluate": shortcuts.Keycaps(debugEvaluateChord), + "watch": shortcuts.Keycaps(debugAddWatchChord), + }) + if _, ok := h.findPageHit("missing"); !ok || !h.shows(evaluate) { + t.Fatal("the Debug panel does not show the evaluate field and the watches") + } + // Enter evaluates the typed expression once and keeps it in the field; Primary+Shift+Enter + // adds it as a watch. + h.typeInto(evaluate, func() { p.debug.watch.input = "" }, "count") + if err := h.driver.Key(gfx.KeyEnter, 0); err != nil { + t.Fatal(err) + } + awaitStateWithin(t, h, 20*time.Second, "the evaluated expression", func() bool { + e := p.debug.watch.evaluated + return e != nil && e.expression == "count" && e.value == "42" && e.typeName == "int" + }) + if p.debug.watch.input != "count" || len(p.debug.watch.entries) != 2 { + t.Fatalf("Enter left the field %q and %d watches", p.debug.watch.input, len(p.debug.watch.entries)) + } + if err := h.driver.Key(gfx.KeyEnter, debugAddWatchChord.Modifiers); err != nil { + t.Fatal(err) + } + awaitStateWithin(t, h, 20*time.Second, "the added watch", func() bool { + entries := p.debug.watch.entries + return len(entries) == 3 && entries[2].expression == "count" && entries[2].value == "42" + }) + if p.debug.watch.input != "" { + t.Fatalf("adding the watch left %q in the field", p.debug.watch.input) } h.clickNamed(h.app.text.Debug.Stop) @@ -122,13 +149,7 @@ func TestDebugThreadResumesAloneAndWatchEditsInPlace(t *testing.T) { t.Fatalf("thread 8 offers %q enabled=%v; want continue", command, enabled) } h.settle() - var picker gfx.Rect - for _, hit := range h.driver.Snapshot().Hits { - if hit.Label == h.app.text.Debug.Threads && !hit.IsLabel && hit.Bounds.Width > picker.Width { - picker = hit.Bounds - } - } - h.rightClickAt(gfx.Rect{X: picker.X + picker.Width - 40, Y: picker.Y, Width: 20, Height: picker.Height}) + h.rightClickNamed(p.debug.frames[0].Name) h.click(center(h.popupHit(h.shared("native.resumeThread")))) awaitStateWithin(t, h, 20*time.Second, "the worker resumed alone", func() bool { return p.debug.resumedThreads[8] && len(p.debug.frames) == 0 @@ -155,7 +176,7 @@ func TestDebugThreadResumesAloneAndWatchEditsInPlace(t *testing.T) { // Double-clicking a watch turns it into a field; Enter keeps the new expression and // evaluates it. - p.debug.section = debugSectionVariables + p.debug.section = debugSectionThreads h.app.invalidator.Invalidate() h.settle() editWatch := func(expression string) { diff --git a/desktop/internal/workbench/debug_toolbar_test.go b/desktop/internal/workbench/debug_toolbar_test.go new file mode 100644 index 0000000000..6f1b2b3c69 --- /dev/null +++ b/desktop/internal/workbench/debug_toolbar_test.go @@ -0,0 +1,222 @@ +package workbench + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/gfx" +) + +// sentBreakpoints is one file's line breakpoints as a session was sent them. +type sentBreakpoints struct { + path string + points []core.DebugSourceBreakpoint +} + +// captureSetBreakpoints records each file's line breakpoints before Core sends them. +type captureSetBreakpoints struct { + Kernel + sent chan sentBreakpoints +} + +func (k *captureSetBreakpoints) SetDebugBreakpoints(ctx context.Context, sessionID, sourcePath string, breakpoints []core.DebugSourceBreakpoint) (core.DebugUpdate, error) { + select { + case k.sent <- sentBreakpoints{path: sourcePath, points: breakpoints}: + case <-ctx.Done(): + return core.DebugUpdate{}, ctx.Err() + } + return k.Kernel.SetDebugBreakpoints(ctx, sessionID, sourcePath, breakpoints) +} + +// Mute keeps the breakpoints but sends every line as disabled; Unmute sends them as stored. +func TestDebugMuteKeepsTheBreakpointsAndSendsThemDisabled(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d := &p.debug + source := d.frames[0].SourcePath + d.breakpoints = map[string][]debugBreakpoint{source: {{line: 3}}} + gate := &captureSetBreakpoints{Kernel: h.app.kernel, sent: make(chan sentBreakpoints, 1)} + h.app.kernel = gate + h.settle() + + h.clickNamed(h.shared("native.muteBreakpoints")) + sent := awaitValueWithin(t, h, 10*time.Second, gate.sent, "the muted breakpoints") + if !d.muted || sent.path != source || len(sent.points) != 1 || sent.points[0].Enabled { + t.Fatalf("muted %v sent %+v, want line 3 disabled", d.muted, sent) + } + if lines := d.breakpoints[source]; len(lines) != 1 || lines[0].disabled { + t.Fatalf("muting changed the stored breakpoints: %+v", lines) + } + + h.settle() + h.clickNamed(h.shared("desktop.debug.unmuteBreakpoints")) + sent = awaitValueWithin(t, h, 10*time.Second, gate.sent, "the unmuted breakpoints") + if d.muted || len(sent.points) != 1 || !sent.points[0].Enabled { + t.Fatalf("muted %v sent %+v, want line 3 enabled", d.muted, sent) + } +} + +// Rerun stops the shown session and starts the debug again the way it was first started. +func TestDebugRerunStartsTheSameDebugAgain(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + first := p.debug.activeSession() + h.clickNamed(h.shared("native.rerun")) + awaitStateWithin(t, h, 30*time.Second, "the debug started again", func() bool { + session := p.debug.activeSession() + return session != nil && session != first && p.debug.state == "paused" && len(p.debug.sessions) == 1 + }) + if p.debug.rerun == nil { + t.Fatal("the rerun session cannot be rerun") + } +} + +// The ⋮ menu switches the variables between the tree and JSON and collapses filtered frames. +func TestDebugMoreMenuSwitchesTheVariablesViewAndFilteredFrames(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d := &p.debug + before := d.hideFiltered + + h.clickNamed(h.shared("native.moreActions")) + h.click(center(h.popupHit(h.app.text.Debug.ViewJSON))) + h.settle() + if !d.vars.json || p.panels.debugMoreOpen { + t.Fatalf("json %v, menu open %v after choosing JSON", d.vars.json, p.panels.debugMoreOpen) + } + + h.clickNamed(h.shared("native.moreActions")) + h.click(center(h.popupHit(h.shared("native.collapseFilteredFrames")))) + h.settle() + if d.hideFiltered == before { + t.Fatal("the menu did not switch collapsing filtered frames") + } + + h.clickNamed(h.shared("native.moreActions")) + h.click(center(h.popupHit(h.app.text.Debug.ViewTree))) + h.settle() + if d.vars.json { + t.Fatal("the menu did not switch back to the tree") + } +} + +// Before a session the adapter picker sits at the right end of the toolbar, not on a row of its +// own. +func TestDebugAdapterPickerSitsInTheToolbar(t *testing.T) { + h := debugHarness(t) + root := t.TempDir() + if err := os.WriteFile(filepath.Join(root, "debug.marker"), []byte("debug\n"), 0o600); err != nil { + t.Fatal(err) + } + openDebugPanel(t, h, root) + start := h.pageHit(h.app.text.Debug.Start).Bounds + picker := h.pageHit(h.shared("desktop.debug.adapter")).Bounds + if abs32(center(picker).Y-center(start).Y) > 2 || picker.X <= start.X { + t.Fatalf("picker %+v is not on the toolbar row of Start %+v", picker, start) + } + if picker.Width > debugAdapterPickerWidth+1 { + t.Fatalf("picker is %v wide, want at most %d", picker.Width, debugAdapterPickerWidth) + } +} + +func abs32(v float32) float32 { + if v < 0 { + return -v + } + return v +} + +// The disassembly tab keeps no buttons of its own: the toolbar's steps step one instruction +// while it shows, and the red dot in front of an instruction sets and removes its breakpoint. +func TestDebugDisassemblyStepsByInstructionAndTogglesItsGutterDot(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d := &p.debug + d.section = debugSectionDisassembly + h.app.invalidator.Invalidate() + awaitStateWithin(t, h, 20*time.Second, "the instruction window", func() bool { + return !d.disassembly.loading && len(d.disassembly.rows) > 0 + }) + h.settle() + + h.clickNamed(h.shared("debugger.disassembly.setBreakpoint")) + awaitStateWithin(t, h, 10*time.Second, "the instruction breakpoint", func() bool { + return len(d.instructionBreakpoints) == 1 + }) + h.settle() + if _, ok := h.findPageHit(h.shared("debugger.disassembly.removeBreakpoint")); !ok { + t.Fatal("the instruction with a breakpoint does not offer to remove it") + } + h.clickNamed(h.shared("debugger.disassembly.removeBreakpoint")) + if len(d.instructionBreakpoints) != 0 { + t.Fatalf("breakpoints = %+v, want none after the second click", d.instructionBreakpoints) + } + + // The fixture refuses every granularity but the instruction one, so the step succeeding + // proves the toolbar sent it. + h.settle() + h.clickNamed(h.app.text.Debug.StepInto) + awaitStateWithin(t, h, 20*time.Second, "the instruction step", func() bool { + return d.state == "paused" && strings.Contains(strings.Join(d.output, ""), "stepped instruction") && d.failure == "" + }) + if d.failure != "" { + t.Fatalf("the step failed: %s", d.failure) + } +} + +// The memory window reads at a typed address, aligns its rows and highlights that address's +// byte, lays the bytes out again by row width and base, and goes back to the instruction +// pointer keeping the layout chosen. +func TestDebugMemoryGoesToAnAddressAndChangesItsLayout(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + m := &p.debug.memory + p.debug.section = debugSectionMemory + h.app.invalidator.Invalidate() + awaitStateWithin(t, h, 20*time.Second, "the memory at the instruction pointer", func() bool { + return !m.loading && len(m.bytes) == 4 && m.input == "0x1000" + }) + + h.typeInto(h.shared("desktop.debug.memoryAddress"), func() { m.input = "" }, "8208") + if err := h.driver.Key(gfx.KeyEnter, 0); err != nil { + t.Fatal(err) + } + // 8208 is 0x2010: the window starts on the 64-byte boundary before it. + awaitStateWithin(t, h, 20*time.Second, "the memory at the typed address", func() bool { + return !m.loading && m.address == "0x2000" && len(m.bytes) == debugMemoryBytes + }) + if m.at != "0x2010" || m.input != "0x2010" || m.mark != 0x10 || m.bytes[m.mark] != 0x10 { + t.Fatalf("at %q input %q mark %d, want 0x2010 highlighted", m.at, m.input, m.mark) + } + h.settle() + if line := m.lines[1]; !strings.HasPrefix(line.text, "0x00002010") || line.text[line.cell[0]:line.cell[1]] != "10" { + t.Fatalf("the second row %q marks %v, want the byte at 0x2010", line.text, line.cell) + } + + h.clickNamed(h.shared("desktop.debug.memoryBytesPerRow")) + h.click(center(h.popupHit(i18n.SharedFormat(h.app.language(), "desktop.debug.memoryRowBytes", map[string]string{"bytes": "32"})))) + h.settle() + if line := m.lines[0]; m.columns != 32 || len(m.lines) != debugMemoryBytes/32 || line.text[line.cell[0]:line.cell[1]] != "10" { + t.Fatalf("columns %d, %d rows, first row marks %v", m.columns, len(m.lines), line.cell) + } + h.clickNamed(h.shared("desktop.debug.memoryRadix")) + h.click(center(h.popupHit(h.shared("desktop.debug.memoryRadixBinary")))) + h.settle() + if line := m.lines[0]; m.radix != 2 || line.text[line.cell[0]:line.cell[1]] != "00010000" { + t.Fatalf("radix %d marks %q, want the byte in binary", m.radix, line.text[line.cell[0]:line.cell[1]]) + } + + h.clickNamed(h.app.text.Debug.Reload) + awaitStateWithin(t, h, 20*time.Second, "the memory back at the instruction pointer", func() bool { + return !m.loading && m.address == "0x1000" && m.input == "0x1000" && len(m.bytes) == 4 + }) + if m.at != "" || m.mark != 0 || m.columns != 32 || m.radix != 2 { + t.Fatalf("at %q mark %d layout %d/%d, want the instruction pointer in the kept layout", m.at, m.mark, m.columns, m.radix) + } +} diff --git a/desktop/internal/workbench/debug_view.go b/desktop/internal/workbench/debug_view.go index 689aded641..caa1223893 100644 --- a/desktop/internal/workbench/debug_view.go +++ b/desktop/internal/workbench/debug_view.go @@ -15,57 +15,40 @@ const ( // debugDisabledOpacity is the opacity of a disabled breakpoint's row, the fade the earlier // client gave it. debugDisabledOpacity = 0.55 + // debugAdapterPickerWidth fits an adapter's display name such as "Go (Delve)" without + // taking the toolbar's free space. + debugAdapterPickerWidth = 160 + // debugGutterDot is the side of an instruction breakpoint's dot, the editor gutter's + // breakpoint size; debugGutterRing is the outline of a muted one and debugGutterHintAlpha + // how strongly the dot a click would set shows under the pointer. + debugGutterDot = 12 + debugGutterRing = 1.5 + debugGutterHintAlpha = 0.35 ) -// debugView declares the Debug tool window: one adapter session, its pause/continue controls -// and its sections, the paused call stack first and the breakpoints among them. +// debugView declares the Debug tool window the way IntelliJ IDEA lays it out: one row of icon +// actions for the session that ends with the adapter picker, the session picker, then the +// tabs of the shown session (see debugSections): its threads and variables, its console, and +// the disassembly and memory where the adapter serves them. func (a *App) debugView(c ui.C, p *project) { t, d := a.text.Debug, &p.debug if !d.loaded && !d.loading { a.loadDebugAdapters(p) } ui.Column(c).Fill().Background(a.colors.Editor).Children(func() { - a.debugSessionRow(c, p) - a.debugAdapterRow(c, p) - if len(d.adapters) > 0 && d.activeSession() == nil && debugAttachOnly(d.adapters[d.selectedAdapter]) { + a.debugToolbar(c, p) + ui.Divider(c) + if len(d.sessions) > 1 { + a.debugSessionRow(c, p) + } + if d.activeSession() == nil && len(d.adapters) > 0 && debugAttachOnly(d.adapters[d.selectedAdapter]) { a.debugAttachForm(c) } a.debugRemotePrompt(c, p) + // The breakpoint editor is declared after the breakpoints dialog it opens from, so it + // stacks above that dialog. + a.debugBreakpointsDialog(c, p) a.debugBreakpointEditor(c, p) - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - if ui.Button(c, t.Start).Disabled(d.activeSession() != nil || len(d.adapters) == 0).Clicked() { - a.startDebug(p) - } - if d.activeSession() != nil { - if ui.Button(c, t.Stop).Outline().Clicked() { - a.stopDebugByUser(p) - } - } - if ui.Button(c, t.Continue).Outline().Disabled(d.activeSession() == nil || d.state != "paused").Clicked() { - a.continueDebug(p) - } - if ui.Button(c, t.Pause).Outline().Disabled(d.activeSession() == nil || d.state != "running").Clicked() { - a.pauseDebug(p) - } - // Steps need a stopped debuggee and a stopped thread to step; the adapter decides - // which commands it serves and Core rejects the rest with a visible failure. - stepDisabled := d.activeSession() == nil || d.state != "paused" || - (d.pausedThread != nil && d.resumedThreads[*d.pausedThread]) - if ui.Button(c, t.StepInto).Outline().Disabled(stepDisabled).Clicked() { - a.executeDebug(p, "stepIn") - } - if ui.Button(c, t.StepOver).Outline().Disabled(stepDisabled).Clicked() { - a.executeDebug(p, "next") - } - if ui.Button(c, t.StepOut).Outline().Disabled(stepDisabled).Clicked() { - a.executeDebug(p, "stepOut") - } - ui.Spacer(c) - if d.status != "" { - ui.Text(c, d.status).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() - } - }) - ui.Divider(c) if d.failure != "" { ui.Column(c).FillWidth().Shrink(0).PadX(shellContentPad).PadY(6).Children(func() { ui.Paragraph(c, d.failure, 3).Color(a.theme.Danger) @@ -73,16 +56,146 @@ func (a *App) debugView(c ui.C, p *project) { } if len(d.adapters) == 0 && !d.loading { a.panelMessage(c, t.NoAdapters, a.colors.Subtle) - a.debugOutput(c, p) return } a.debugSections(c, p) }) } -// debugAdapterRow declares the adapter picker. While a session runs the adapter -// is fixed, so the picker gives way to its name. -func (a *App) debugAdapterRow(c ui.C, p *project) { +// debugToolbar declares the Debug window's actions as IntelliJ IDEA groups them: rerun and +// stop the session; resume, pause and the steps of the paused thread; the breakpoints dialog +// and the switch that mutes every breakpoint; then the More menu. Start stands in for Stop +// while no session runs. The status of the shown session closes the row, and while no session +// runs the compact adapter picker follows it. +func (a *App) debugToolbar(c ui.C, p *project) { + t, d := a.text.Debug, &p.debug + lang := a.language() + session := d.activeSession() + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(2).PadX(6).Children(func() { + if _, clicked := a.toolIconButton(c.Part("rerun"), i18n.Shared(lang, "native.rerun"), icons.RotateCcw, false, d.rerun == nil || d.preparing); clicked { + c.After(func() { a.rerunDebug(p) }) + } + if session == nil { + if _, clicked := a.toolIconButton(c.Part("start"), t.Start, icons.Bug, false, len(d.adapters) == 0 || d.preparing); clicked { + c.After(func() { a.startDebug(p) }) + } + } else if _, clicked := a.toolIconButton(c.Part("stop"), t.Stop, icons.Square, false, false); clicked { + c.After(func() { a.stopDebugByUser(p) }) + } + a.debugToolbarDivider(c) + paused := session != nil && d.state == "paused" + if _, clicked := a.toolIconButton(c.Part("continue"), t.Continue, icons.Play, false, !paused); clicked { + c.After(func() { a.continueDebug(p) }) + } + if _, clicked := a.toolIconButton(c.Part("pause"), t.Pause, icons.Pause, false, session == nil || d.state != "running"); clicked { + c.After(func() { a.pauseDebug(p) }) + } + // Steps need a stopped debuggee and a stopped thread to step; the adapter decides + // which commands it serves and Core rejects the rest with a visible failure. + stepDisabled := !paused || (d.pausedThread != nil && d.resumedThreads[*d.pausedThread]) + granularity := debugStepGranularity(d) + if _, clicked := a.toolIconButton(c.Part("step-over"), t.StepOver, icons.RedoDot, false, stepDisabled); clicked { + c.After(func() { a.executeDebugWithGranularity(p, "next", granularity) }) + } + if _, clicked := a.toolIconButton(c.Part("step-into"), t.StepInto, icons.ArrowDownToDot, false, stepDisabled); clicked { + c.After(func() { a.executeDebugWithGranularity(p, "stepIn", granularity) }) + } + if _, clicked := a.toolIconButton(c.Part("step-out"), t.StepOut, icons.ArrowUpFromDot, false, stepDisabled); clicked { + c.After(func() { a.executeDebugWithGranularity(p, "stepOut", granularity) }) + } + a.debugToolbarDivider(c) + if _, clicked := a.toolIconButton(c.Part("view-breakpoints"), i18n.Shared(lang, "native.viewBreakpoints"), icons.CircleDot, p.panels.breakpointsOpen, false); clicked { + c.After(func() { + a.performed("debug.viewBreakpoints", surfaceButton) + p.panels.breakpointsOpen = true + }) + } + mute := i18n.Shared(lang, "native.muteBreakpoints") + if d.muted { + mute = i18n.Shared(lang, "desktop.debug.unmuteBreakpoints") + } + if _, clicked := a.toolIconButton(c.Part("mute"), mute, icons.CircleSlash, d.muted, false); clicked { + c.After(func() { a.toggleMuteBreakpoints(p) }) + } + more, clicked := a.toolIconButton(c.Part("more"), i18n.Shared(lang, "native.moreActions"), icons.EllipsisVertical, p.panels.debugMoreOpen, false) + if clicked { + c.After(func() { p.panels.debugMoreOpen = !p.panels.debugMoreOpen }) + } + if p.panels.debugMoreOpen { + a.debugMoreMenu(c, more, p) + } + ui.Spacer(c) + if d.status != "" { + status := d.status + if session != nil { + status = a.debugSessionLabel(session) + " · " + status + } + ui.Text(c, status).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() + } + // The adapter is chosen before a session starts; while one runs, its label says which. + if session == nil { + a.debugAdapterPicker(c.Part("adapter"), p) + } + }) +} + +// debugStepGranularity is the unit the toolbar's steps take: one instruction while the +// Disassembly tab is shown and the adapter accepts a granularity, as IntelliJ IDEA steps in its +// disassembly view, and the adapter's own unit otherwise. Core forwards the granularity only +// when the adapter advertised it. +func debugStepGranularity(d *debugState) string { + if d.section == debugSectionDisassembly && d.capabilities != nil && d.capabilities.SupportsSteppingGranularity { + return "instruction" + } + return "" +} + +// debugToolbarDivider is the thin rule between two groups of the toolbar's actions. +func (a *App) debugToolbarDivider(c ui.C) { + ui.Row(c).Height(16).Shrink(0).PadX(4).Children(func() { + ui.Column(c).Width(1).FillHeight().Background(a.colors.Line) + }) +} + +// debugMoreMenu declares the Debug toolbar's More menu: how the variables are shown, whether +// the stack folds the frames the stepping filters match, and, while the Disassembly tab is +// shown, the way back to the current instruction. +func (a *App) debugMoreMenu(c ui.C, anchor ui.Box, p *project) { + t, d := a.text.Debug, &p.debug + open := true + ui.Menu(c, anchor, &open, func(menu *ui.MenuItems) { + if menu.Item(t.ViewTree).Chosen(!d.vars.json).Clicked() { + c.After(func() { d.vars.json = false }) + } + if menu.Item(t.ViewJSON).Chosen(d.vars.json).Clicked() { + c.After(func() { d.vars.json = true }) + } + menu.Separator() + if menu.Item(i18n.Shared(a.language(), "native.collapseFilteredFrames")).Checked(d.hideFiltered).Clicked() { + c.After(func() { + a.performed("debug.collapseFilteredFrames", surfaceMenu) + d.hideFiltered, d.framesExpanded = !d.hideFiltered, false + }) + } + if d.section == debugSectionDisassembly { + menu.Separator() + if menu.Item(t.Reload).Disabled(!canDisassemble(d) || d.disassembly.loading).Clicked() { + c.After(func() { + a.performed("debug.disassembly.currentInstruction", surfaceMenu) + a.loadDisassembly(p) + }) + } + } + }) + if !open { + p.panels.debugMoreOpen = false + } +} + +// debugAdapterPicker declares the compact adapter picker at the end of the toolbar. It is +// shown only while no session runs: a running session's adapter is fixed and the status +// already names it. +func (a *App) debugAdapterPicker(c ui.C, p *project) { d := &p.debug if len(d.adapters) == 0 { return @@ -91,16 +204,9 @@ func (a *App) debugAdapterRow(c ui.C, p *project) { for index := range indexes { indexes[index] = index } - label := i18n.Shared(a.language(), "desktop.debug.adapter") - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).PadX(8).Items(ui.Center).Children(func() { - if d.activeSession() != nil { - ui.Text(c, d.adapters[d.selectedAdapter].Declaration.DisplayName).Color(a.colors.Text).Ellipsis().Grow(1).Label(label) - return - } - ui.Select(c, &d.selectedAdapter, indexes, func(index int) string { - return d.adapters[index].Declaration.DisplayName - }).Label(label).Grow(1) - }) + ui.Select(c, &d.selectedAdapter, indexes, func(index int) string { + return d.adapters[index].Declaration.DisplayName + }).Label(i18n.Shared(a.language(), "desktop.debug.adapter")).Width(debugAdapterPickerWidth).Height(24).Shrink(1) } // debugAttachOnly is true for an adapter that has no launch: the target is a @@ -166,48 +272,78 @@ func debugBreakpointList(d *debugState) []debugBreakpointRow { return rows } -// debugBreakpoints declares the toggle action and the stored breakpoint lines. -// A line row removes that breakpoint when clicked. +// debugBreakpointsHeight is the height of the breakpoints dialog's list of lines. +const debugBreakpointsHeight = 220 + +// debugBreakpointsDialog declares the dialog the toolbar's View Breakpoints opens, IntelliJ +// IDEA's Breakpoints dialog: the action that toggles a breakpoint on the caret's line, the +// method breakpoints, the line breakpoints and the exception filters the adapter offers. +func (a *App) debugBreakpointsDialog(c ui.C, p *project) { + open := &p.panels.breakpointsOpen + if !*open { + return + } + t := a.text.Debug + k := c.Part("breakpoints-dialog") + closed := ui.ModalWith(k, open, t.Breakpoints, ui.ModalSpec{Width: 560}, func() { + ui.Column(k).FillWidth().Gap(6).Children(func() { + a.debugBreakpoints(k, p) + a.debugExceptionsView(k, p) + }) + }, func() { + if ui.Button(k, i18n.Shared(a.language(), "ui.done")).Clicked() { + *open = false + } + }) + if closed { + *open = false + } +} + +// debugBreakpoints declares the toggle action and the stored breakpoints: the method names, +// then the lines. A line row removes that breakpoint when clicked. func (a *App) debugBreakpoints(c ui.C, p *project) { t, d := a.text.Debug, &p.debug - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { - ui.Text(c, t.Breakpoints).Color(a.colors.Text).Weight(gfx.WeightMedium).Shrink(0) + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).Children(func() { + ui.Text(c, i18n.Shared(a.language(), "native.lineBreakpoints")).Color(a.colors.Text).Weight(gfx.WeightMedium).Shrink(0) ui.Spacer(c) if ui.Button(c, t.ToggleBreakpoint).Outline().Clicked() { - a.toggleBreakpoint(p) + c.After(func() { a.toggleBreakpoint(p) }) } }) - a.debugFunctionBreakpoints(c, p) rows := debugBreakpointList(d) - if len(rows) == 0 { - ui.Row(c).FillWidth().Height(debugRowHeight).Shrink(0).PadX(10).Items(ui.Center).Children(func() { - ui.Text(c, t.NoBreakpoints).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() - }) - return - } - list := &p.panels.breakpoints - list.Label = func(i int) string { - return debugFileName(rows[i].path) + ":" + strconv.FormatInt(rows[i].breakpoint.line, 10) - } - ui.List(c, list, len(rows), func(row ui.ListRow) { - spec := rows[row.Index] - row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center).Gap(6).Tooltip(t.RemoveBreakpoint). - Hover(ui.Look{}.Background(a.colors.Hover)) - // A disabled breakpoint is shown faded, as the earlier client's list showed it. - if spec.breakpoint.disabled { - row.Element.Opacity(debugDisabledOpacity) - } - ui.Icon(row.C, icons.CircleX).Size(12, 12).Shrink(0).Color(a.theme.Danger) - ui.Text(row.C, debugFileName(spec.path)).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis() - ui.Text(row.C, ":"+strconv.FormatInt(spec.breakpoint.line, 10)).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) - if marker := breakpointMarker(spec.breakpoint, t.Breakpoint.Conditional, t.Breakpoint.LogPoint); marker != "" { - ui.Text(row.C, marker).Shrink(0).FontSize(11.5).Color(a.colors.Accent).Ellipsis() - } - a.debugBreakpointMenu(row.C, row.Element, p, spec.path, spec.breakpoint.line, spec.breakpoint.disabled) - if row.Element.Clicked() { - row.C.After(func() { a.removeBreakpoint(p, spec.path, spec.breakpoint.line) }) - } - }).Label(t.Breakpoints).FillWidth().Grow(1) + ui.Column(c).FillWidth().Height(debugBreakpointsHeight).Shrink(0).Border(1, a.colors.Line).Clip().Children(func() { + if len(rows) == 0 { + a.panelMessage(c, t.NoBreakpoints, a.colors.Subtle) + return + } + list := &p.panels.breakpoints + list.Label = func(i int) string { + return debugFileName(rows[i].path) + ":" + strconv.FormatInt(rows[i].breakpoint.line, 10) + } + ui.List(c, list, len(rows), func(row ui.ListRow) { + spec := rows[row.Index] + row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center).Gap(6).Tooltip(t.RemoveBreakpoint). + Hover(ui.Look{}.Background(a.colors.Hover)) + // A disabled breakpoint is shown faded, as the earlier client's list showed it, and + // so is every breakpoint while they are muted. + if spec.breakpoint.disabled || d.muted { + row.Element.Opacity(debugDisabledOpacity) + } + ui.Icon(row.C, icons.CircleX).Size(12, 12).Shrink(0).Color(a.theme.Danger) + ui.Text(row.C, debugFileName(spec.path)).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis() + ui.Text(row.C, ":"+strconv.FormatInt(spec.breakpoint.line, 10)).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) + if marker := breakpointMarker(spec.breakpoint, t.Breakpoint.Conditional, t.Breakpoint.LogPoint); marker != "" { + ui.Text(row.C, marker).Shrink(0).FontSize(11.5).Color(a.colors.Accent).Ellipsis() + } + a.debugBreakpointMenu(row.C, row.Element, p, spec.path, spec.breakpoint.line, spec.breakpoint.disabled) + if row.Element.Clicked() { + row.C.After(func() { a.removeBreakpoint(p, spec.path, spec.breakpoint.line) }) + } + }).Label(t.Breakpoints).Fill() + }) + ui.Text(c, t.Breakpoint.FunctionName).Color(a.colors.Text).Weight(gfx.WeightMedium) + a.debugFunctionBreakpoints(c, p) } // removeBreakpoint drops one stored line and tells the active adapter. @@ -228,18 +364,18 @@ func (a *App) removeBreakpoint(p *project, path string, line int64) { } } -// debugFrames declares the paused call stack. A frame with a source path opens -// that location. +// debugFrames declares the left pane of Threads & Variables: the thread picker and the paused +// thread's call stack, each frame written "name (file:line)" as IntelliJ IDEA writes it and +// faded when the stepping filters match it. A click selects the frame and opens its source. func (a *App) debugFrames(c ui.C, p *project) { t, d := a.text.Debug, &p.debug a.debugThreadPicker(c, p) - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).PadX(8).Children(func() { - ui.Text(c, t.Frames).Color(a.colors.Text).Weight(gfx.WeightMedium).Ellipsis() - }) if len(d.frames) == 0 { - ui.Row(c).FillWidth().Shrink(0).Height(debugRowHeight).PadX(10).Items(ui.Center).Children(func() { - ui.Text(c, t.NoFrames).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() - }) + message := i18n.Shared(a.language(), "debugger.stackEmpty") + if d.activeSession() != nil { + message = t.NoFrames + } + a.panelMessage(c, message, a.colors.Subtle) return } list := &p.panels.frames @@ -257,7 +393,7 @@ func (a *App) debugFrames(c ui.C, p *project) { } ui.List(c, list, len(rows), func(row ui.ListRow) { r := rows[row.Index] - element := row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center).Gap(6).Hover(ui.Look{}.Background(a.colors.Hover)) + element := row.Element.Height(debugRowHeight).PadX(10).Items(ui.Center).Gap(4).Hover(ui.Look{}.Background(a.colors.Hover)) if r.hidden > 0 { // A run of frames the stepping filters match: a click shows them all again. ui.Text(row.C, hiddenLabel(r.hidden)).Grow(1).Shrink(1).FontSize(12).Color(a.colors.Subtle).Ellipsis() @@ -267,12 +403,20 @@ func (a *App) debugFrames(c ui.C, p *project) { return } frame := d.frames[r.frame] - color := a.colors.Text + index := r.frame + if index == d.vars.frame { + element.Background(a.colors.Active) + } + color, place := a.colors.Text, a.colors.Subtle if frame.IsFiltered { color = a.colors.Subtle } - ui.Text(row.C, frame.Name).Grow(1).Shrink(1).FontSize(12.5).Color(color).Ellipsis() - index := r.frame + ui.Text(row.C, frame.Name).Shrink(1).FontSize(12.5).Color(color).Ellipsis() + if frame.SourcePath != "" { + position := "(" + debugFileName(frame.SourcePath) + ":" + strconv.FormatInt(frame.Line, 10) + ")" + ui.Text(row.C, position).Shrink(0).FontSize(12.5).Color(place) + } + ui.Spacer(row.C) a.debugFrameMenu(row.C, element, p, index) if element.Clicked() && index != d.vars.frame { // The selected frame decides which scopes and variables are shown. @@ -282,8 +426,6 @@ func (a *App) debugFrames(c ui.C, p *project) { return } element.Tooltip(t.OpenFrame) - position := debugFileName(frame.SourcePath) + ":" + strconv.FormatInt(frame.Line, 10) - ui.Text(row.C, position).Shrink(0).FontSize(11.5).Color(a.colors.Subtle) if element.Clicked() { line := int(frame.Line) if line > 0 { @@ -291,29 +433,28 @@ func (a *App) debugFrames(c ui.C, p *project) { } row.C.After(func() { a.openFileAtPosition(p, frame.SourcePath, line, 0) }) } - }).Label(t.Frames).FillWidth().Grow(1) + }).Label(t.Frames).Fill() } -// debugOutput shows the adapter's bounded diagnostics when something failed or no -// adapter was found. -func (a *App) debugOutput(c ui.C, p *project) { - if len(p.debug.output) == 0 { +// debugConsole declares the Console tab: the output the adapter reported for the session, in +// a list that follows new lines while it shows its end. +func (a *App) debugConsole(c ui.C, p *project) { + d, panels := &p.debug, &p.panels + if len(d.output) == 0 { + a.panelMessage(c, i18n.Shared(a.language(), "desktop.debug.consoleEmpty"), a.colors.Subtle) return } - lines := p.debug.output - if len(lines) > 8 { - lines = lines[len(lines)-8:] - } - ui.Divider(c) - ui.Column(c).FillWidth().Height(120).Shrink(0).Clip().Pad(8).Children(func() { - ui.Paragraph(c, joinLines(lines), 6).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) - }) -} - -func joinLines(lines []string) string { - text := "" - for _, line := range lines { - text += line + "\n" + list := &panels.console + if panels.consoleSeen != d.outputCount { + if panels.consoleSeen == 0 || list.AtEnd() { + list.ScrollToEnd() + } + panels.consoleSeen = d.outputCount } - return text + lines := d.output + list.Label = func(i int) string { return lines[i] } + ui.List(c, list, len(lines), func(row ui.ListRow) { + row.Element.Height(debugRowHeight - 4).PadX(10).Items(ui.Center) + ui.Text(row.C, lines[row.Index]).FontSize(12.5).Color(a.colors.Text).Mono() + }).Label(i18n.Shared(a.language(), "debugger.console")).Fill() } diff --git a/desktop/internal/workbench/debug_watch.go b/desktop/internal/workbench/debug_watch.go index eb467ed467..02d7b4fc9d 100644 --- a/desktop/internal/workbench/debug_watch.go +++ b/desktop/internal/workbench/debug_watch.go @@ -7,7 +7,11 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/shortcuts" + "github.com/1lck/Lithe-IDEA/desktop/internal/treelist" "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/keymap" "github.com/vivaui/viva/ui" ) @@ -23,10 +27,14 @@ type debugWatchEntry struct { failure string } -// debugWatch is the Variables section's watch list and its editor. +// debugWatch is the Variables pane's evaluate field, the result it evaluated last, and the +// watch list with its editor. type debugWatch struct { entries []debugWatchEntry input string + // evaluated is the expression Enter evaluated in the field and its result; nil before one, + // and its value is dropped with the stop it belongs to. + evaluated *debugWatchEntry // history is the expressions evaluated in this session, oldest first and without repeats, and // pick is what the recent-expressions picker chose last. history []string @@ -73,20 +81,46 @@ func (w *debugWatch) valuesCleared() { for index := range w.entries { w.entries[index].value, w.entries[index].typeName, w.entries[index].failure = "", "", "" } + w.evaluated = nil } -// addDebugWatch adds the typed expression and evaluates it at the current frame. +// addDebugWatch adds the typed expression as a watch and, while the debuggee is paused, +// evaluates it at the current frame; a watch added while it runs is evaluated at the next stop. func (a *App) addDebugWatch(p *project) { d := &p.debug expression := strings.TrimSpace(d.watch.input) - if expression == "" || d.activeSession() == nil || d.state != "paused" { + if expression == "" { return } + a.performed("debug.watch.add", surfaceButton) d.watch.entries = append(d.watch.entries, debugWatchEntry{expression: expression}) d.watch.rememberExpression(expression) d.watch.input = "" - index := len(d.watch.entries) - 1 - a.evaluateDebugWatch(p, index) + if d.activeSession() != nil && d.state == "paused" { + a.evaluateDebugWatch(p, len(d.watch.entries)-1) + } +} + +// evaluateDebugInput evaluates the typed expression once at the selected frame with the DAP +// "repl" context, the way IntelliJ IDEA's Evaluate field does, and keeps the expression in the +// field so it can be changed and evaluated again. +func (a *App) evaluateDebugInput(p *project) { + d := &p.debug + w := &d.watch + expression := strings.TrimSpace(w.input) + if expression == "" || d.activeSession() == nil || d.state != "paused" || len(d.frames) == 0 { + return + } + a.performed("debug.evaluate", surfaceButton) + w.rememberExpression(expression) + entry := &debugWatchEntry{expression: expression} + w.evaluated = entry + a.evaluateDebugExpression(p, expression, "repl", func(value, typeName, failure string) { + if w.evaluated != entry { + return + } + entry.value, entry.typeName, entry.failure = value, typeName, failure + }) } // removeDebugWatch drops one expression. @@ -139,12 +173,29 @@ func (a *App) refreshDebugWatches(p *project) { } } -// evaluateDebugWatch asks Core for one expression's value with the DAP "watch" context at -// the selected frame. A result that arrives after another stop is dropped by the generation -// check in debugOperation's completion path. +// evaluateDebugWatch evaluates one watch with the DAP "watch" context at the selected frame. func (a *App) evaluateDebugWatch(p *project, index int) { d := &p.debug - if index < 0 || index >= len(d.watch.entries) || d.activeSession() == nil || len(d.frames) == 0 { + if index < 0 || index >= len(d.watch.entries) { + return + } + expression := d.watch.entries[index].expression + a.evaluateDebugExpression(p, expression, "watch", func(value, typeName, failure string) { + if index >= len(d.watch.entries) || d.watch.entries[index].expression != expression { + return + } + entry := &d.watch.entries[index] + entry.value, entry.typeName, entry.failure = value, typeName, failure + }) +} + +// evaluateDebugExpression asks Core for one expression's value in dapContext, the DAP context, at the +// selected frame, and hands done the value and its type, or the reason there is none. A result +// that arrives after another stop is dropped by the generation check in debugOperation's +// completion path. +func (a *App) evaluateDebugExpression(p *project, expression, dapContext string, done func(value, typeName, failure string)) { + d := &p.debug + if d.activeSession() == nil || len(d.frames) == 0 { return } frameIndex := d.vars.frame @@ -152,7 +203,6 @@ func (a *App) evaluateDebugWatch(p *project, index int) { frameIndex = 0 } frameID := d.frames[frameIndex].ID - expression := d.watch.entries[index].expression a.debugOperation(p, "evaluate", func(ctx context.Context, session *debugSession, operationID string) (core.DebugUpdate, error) { return a.kernel.InspectDebug(ctx, core.DebugInspectRequest{ SessionID: session.id, @@ -160,80 +210,119 @@ func (a *App) evaluateDebugWatch(p *project, index int) { Kind: "evaluate", FrameID: &frameID, Expression: expression, - Context: "watch", + Context: dapContext, }) }, debugOperationHandlers{done: func(a *App, result core.DebugOperationResult) { - if index >= len(d.watch.entries) || d.watch.entries[index].expression != expression { - return - } - entry := &d.watch.entries[index] if result.Kind != "evaluate" || result.Variable == nil { - entry.failure = a.text.Debug.EvaluateFailed - entry.value, entry.typeName = "", "" + done("", "", a.text.Debug.EvaluateFailed) return } - entry.value, entry.typeName, entry.failure = result.Variable.Value, result.Variable.Type, "" - }, failed: func(a *App, message string, _ bool) { - if index < len(d.watch.entries) { - d.watch.entries[index].failure = message - d.watch.entries[index].value, d.watch.entries[index].typeName = "", "" - } + done(result.Variable.Value, result.Variable.Type, "") + }, failed: func(_ *App, message string, _ bool) { + done("", "", message) }}) } -// debugWatchView declares the watch editor and the values of the current stop. -func (a *App) debugWatchView(c ui.C, p *project) { - t, d := a.text.Debug, &p.debug - w := &d.watch - if d.activeSession() == nil || d.state != "paused" { - w.endEdit() - return - } - ui.Column(c).FillWidth().Shrink(0).Gap(4).PadX(8).PadY(4).Children(func() { - ui.Row(c).FillWidth().Items(ui.Center).Gap(6).Children(func() { - ui.Text(c, t.Watches).FontSize(12).Color(a.colors.Subtle) - ui.Spacer(c) - if len(w.entries) > 0 && ui.Button(c.Key("watchReload"), t.Reload).Ghost().Clicked() { - c.After(func() { a.refreshDebugWatches(p) }) +// debugEvaluateField declares the field over the variables, IntelliJ IDEA's: Enter evaluates +// the expression at the selected frame and Primary+Shift+Enter adds it as a watch. The +// expressions of this session are offered beside it, and the last result is shown under it. +func (a *App) debugEvaluateField(c ui.C, p *project) { + w := &p.debug.watch + evaluate, watch := shortcuts.Keycaps(debugEvaluateChord), shortcuts.Keycaps(debugAddWatchChord) + placeholder := i18n.SharedFormat(a.language(), "desktop.debug.evaluatePlaceholder", map[string]string{ + "evaluate": evaluate, + "watch": watch, + }) + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(8).Children(func() { + field := ui.TextField(c.Key("watchInput"), &w.input, placeholder, placeholder).Grow(1) + field.OnKey(func(event gfx.KeyEvent) gfx.EventResult { + if event.Release || !isDebugAddWatch(event) { + return gfx.EventResult{} } + a.addDebugWatch(p) + return gfx.EventResult{Handled: true, Repaint: true} }) + if field.Submitted() { + c.After(func() { a.evaluateDebugInput(p) }) + } if len(w.history) > 0 { - // The recent expressions of this session: choosing one fills the field, to be evaluated as typed. - ui.Select(c.Key("watchHistory"), &w.pick, w.history, func(expression string) string { return expression }).FillWidth() + // The recent expressions of this session: choosing one fills the field, to be + // evaluated as typed. + ui.Select(c.Key("watchHistory"), &w.pick, w.history, func(expression string) string { return expression }). + Label(a.text.Debug.Watches).Width(140).Shrink(0) if w.pick != "" { w.input, w.pick = w.pick, "" } } - submitted := ui.TextField(c.Key("watchInput"), &w.input, t.WatchPlaceholder, t.WatchPlaceholder).FillWidth().Submitted() - if submitted || ui.Button(c.Key("watchAdd"), t.AddWatch).Outline().Disabled(strings.TrimSpace(w.input) == "").Clicked() { - c.After(func() { a.addDebugWatch(p) }) + }) + if entry := w.evaluated; entry != nil { + ui.Row(c.Key("evaluated")).FillWidth().Height(debugRowHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(10).Children(func() { + ui.Icon(c, icons.Variable).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Accent) + a.debugWatchText(c, *entry) + }) + } +} + +// debugEvaluateChord evaluates the expression in the field once. +var debugEvaluateChord = keymap.Chord{Key: gfx.KeyEnter} + +// debugAddWatchChord adds the evaluate field's expression as a watch: ⇧⌘↵ on macOS, as in +// IntelliJ IDEA, and Ctrl+Shift+Enter elsewhere. +var debugAddWatchChord = keymap.Chord{Modifiers: keymap.Primary | gfx.ModifierShift, Key: gfx.KeyEnter} + +// isDebugAddWatch reports whether event presses debugAddWatchChord. +func isDebugAddWatch(event gfx.KeyEvent) bool { + chord, ok := keymap.FromEvent(event) + return ok && chord.Key == gfx.KeyEnter && + chord.Modifiers&(gfx.ModifierShift|gfx.ModifierControl|gfx.ModifierAlt|gfx.ModifierMeta) == debugAddWatchChord.Modifiers +} + +// debugWatchText declares an expression with its result as IntelliJ IDEA writes it, +// "expression = {type} value", or with the reason it has none. +func (a *App) debugWatchText(c ui.C, entry debugWatchEntry) { + ui.Text(c, entry.expression).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) + switch { + case entry.failure != "": + ui.Text(c, entry.failure).Shrink(1).FontSize(12.5).Color(a.theme.Danger).Ellipsis() + case entry.value != "" || entry.typeName != "": + ui.Text(c, "=").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) + if entry.typeName != "" { + ui.Text(c, "{"+entry.typeName+"}").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) } + ui.Text(c, entry.value).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis().Mono() + } +} + +// debugWatchView declares the watches over the variables, each with its value at the current +// stop: a double click edits one in place and its button removes it. +func (a *App) debugWatchView(c ui.C, p *project) { + t, d := a.text.Debug, &p.debug + w := &d.watch + if d.activeSession() == nil { + w.endEdit() + } + if len(w.entries) == 0 { + return + } + ui.Column(c).FillWidth().Shrink(0).Children(func() { for index := range w.entries { if w.editOpen && w.editIndex == index { - a.debugWatchEditField(c, p) + ui.Row(c.Key("watchEditRow")).FillWidth().Height(debugRowHeight + 4).Shrink(0).Items(ui.Center).PadX(8).Children(func() { + a.debugWatchEditField(c, p) + }) continue } entry := w.entries[index] - k := c.Key("watch/" + entry.expression) - row := ui.Row(k).FillWidth().Items(ui.Center).Gap(6).HitWith(ui.ID(k), entry.expression, gfx.HitOptions{SkipFocus: true}) + k := c.Part("watch").KeyInt(index) + row := ui.Row(k).FillWidth().Height(debugRowHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(10). + Hover(ui.Look{}.Background(a.colors.Hover)). + HitWith(ui.ID(k), entry.expression, gfx.HitOptions{SkipFocus: true}) row.Children(func() { - text := entry.expression - if entry.value != "" { - text += " = " + entry.value - } - if entry.typeName != "" { - text += " (" + entry.typeName + ")" - } - if entry.failure != "" { - text += " — " + entry.failure - } - color := a.colors.Text - if entry.failure != "" { - color = a.theme.Danger - } - ui.Text(c, text).Grow(1).Shrink(1).FontSize(12.5).Color(color).Ellipsis() + ui.Icon(k, icons.Eye).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) + a.debugWatchText(k, entry) + ui.Spacer(k) i := index - if ui.Button(c.KeyInt(i).Key("remove"), t.RemoveWatch).Ghost().Clicked() { + if _, clicked := a.toolIconButton(k.Key("remove"), t.RemoveWatch, icons.X, false, false); clicked { c.After(func() { a.removeDebugWatch(p, i) }) } }) @@ -247,6 +336,7 @@ func (a *App) debugWatchView(c ui.C, p *project) { a.debugWatchMenu(k, row, p, index) } }) + ui.Divider(c) } // debugWatchEditField declares the field that edits one watch in place: Enter or moving the diff --git a/desktop/internal/workbench/drag.go b/desktop/internal/workbench/drag.go index b18e9f5787..c8e9497702 100644 --- a/desktop/internal/workbench/drag.go +++ b/desktop/internal/workbench/drag.go @@ -447,7 +447,7 @@ func dockMoveTitle(messages *i18n.Messages, z zone) string { // other buttons are icons only. func (a *App) dragGhostText(item int) string { if a.chrome.catalog[item].id == itemRunConfig { - return a.text.Title.CurrentFile + return a.titleRunLabel() } return a.chromeStatusText(item) } diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index dbbc62a319..258bbe4971 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -436,6 +436,11 @@ func (a *App) splitterKey(event gfx.KeyEvent) gfx.EventResult { return r } } + if p := a.project; p != nil { + if r := p.panels.debugSplit.Key(event); r.Handled { + return r + } + } return gfx.EventResult{} } diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index 02ed984817..de03c0dd39 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -25,6 +25,14 @@ type runConfigState struct { editor runConfigEditor // browser is the list that shows the configurations by scope and build system. browser runConfigBrowser + // currentFile says the user chose Current File in the title bar, so its Run and Debug act + // on the open file instead of the selected configuration (title_run.go). + currentFile bool + // pending is the title bar's Run or Debug waiting for the configurations to be read. + pending titleAction + // wanted says the title bar asked for the configurations, so every detected instance + // loads its model and not only the one the Build window shows. + wanted bool } // configuration is the listed configuration id, or nil. @@ -115,6 +123,7 @@ func (a *App) finishRunConfigurations(p *project, generation uint64, resolved co return } s.loading = false + defer a.settleTitleAction(p) a.loadRunConfigPins(p) if err != nil { s.failure = err.Error() diff --git a/desktop/internal/workbench/runpanels.go b/desktop/internal/workbench/runpanels.go index dd768af006..825c853d92 100644 --- a/desktop/internal/workbench/runpanels.go +++ b/desktop/internal/workbench/runpanels.go @@ -15,8 +15,13 @@ type runPanels struct { // testResults is the grouped result list, testOutput the console of a run that // failed before reporting results. testResults, testOutput ui.ListState - // breakpoints and frames are the Debug tool window's lists. - breakpoints, frames ui.ListState - // remoteOpen shows the confirmation of an attach to a non-local endpoint. - remoteOpen bool + // breakpoints, frames and console are the Debug tool window's lists, debugSplit the + // divider between its call stack and its variables, and consoleSeen the output additions + // the console has shown (see debugSessionView.outputCount). + breakpoints, frames, console ui.ListState + debugSplit ui.SplitterState + consoleSeen int + // remoteOpen shows the confirmation of an attach to a non-local endpoint, breakpointsOpen + // the dialog of every breakpoint, and debugMoreOpen the Debug toolbar's More menu. + remoteOpen, breakpointsOpen, debugMoreOpen bool } diff --git a/desktop/internal/workbench/shell_view.go b/desktop/internal/workbench/shell_view.go index 40fcc9f59b..8077db91c7 100644 --- a/desktop/internal/workbench/shell_view.go +++ b/desktop/internal/workbench/shell_view.go @@ -251,10 +251,16 @@ const ( // of the selected tab, and a click selects another. The row may shrink, the labels cut, in a // narrow panel. func (a *App) toolTabs(c ui.C, selected *int, labels []string) { + a.toolTabsWith(c, *selected, labels, func(index int) { *selected = index }) +} + +// toolTabsWith is toolTabs for a selection the caller keeps its own way: selected is the +// index of the selected tab, and choose takes the index of a clicked one after the frame. +func (a *App) toolTabsWith(c ui.C, selected int, labels []string, choose func(int)) { ui.Row(c).Shrink(1).MinWidth(0).Height(panelHeaderHeight).Items(ui.Center).Gap(2).Clip().Children(func() { for i, label := range labels { k := c.KeyInt(i) - on := i == *selected + on := i == selected chip := ui.Row(k).Height(rowHeight).Shrink(1).MinWidth(0).Items(ui.Center).PadX(toolTabPad). Radius(a.theme.Metrics.RadiusItem()). HitWith(ui.ID(k), label, gfx.HitOptions{ @@ -277,7 +283,7 @@ func (a *App) toolTabs(c ui.C, selected *int, labels []string) { }) if chip.Clicked() { index := i - c.After(func() { *selected = index }) + c.After(func() { choose(index) }) } } }) diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go new file mode 100644 index 0000000000..803773c0b7 --- /dev/null +++ b/desktop/internal/workbench/title_run.go @@ -0,0 +1,218 @@ +package workbench + +import ( + "errors" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// titleAction is a press on the title bar's Run or Debug button that waits for the project's +// run configurations to be read. +type titleAction uint8 + +const ( + titleActionNone titleAction = iota + titleActionRun + titleActionDebug +) + +// titleConfiguration is the run configuration the title bar's Run and Debug start, nil when +// they act on the current file: the user chose Current File, or the project has no +// configuration. +func (p *project) titleConfiguration() *core.RunConfiguration { + if p == nil || p.runConfigs.currentFile { + return nil + } + return p.runConfigs.configuration(p.runConfigs.selected) +} + +// titleRunLabel is what the title bar's run configuration button reads: the chosen +// configuration, or Current File. +func (a *App) titleRunLabel() string { + if configuration := a.project.titleConfiguration(); configuration != nil { + return configuration.Name + } + return a.text.Title.CurrentFile +} + +// runConfigsSettled reports whether the configurations the project can offer are read: build +// detection answered, no model is on its way and Core resolved the configurations since. +func (p *project) runConfigsSettled() bool { + if !p.build.loaded || p.build.loading || p.runConfigs.loading { + return false + } + for index := range p.build.instances { + if p.build.instances[index].modelLoading { + return false + } + } + return true +} + +// loadTitleRunConfigs reads what the title bar lists. Detection runs once; after it every +// detected instance loads its model, since each offers its own runs, where the Build window +// only loads the instance it shows. +func (a *App) loadTitleRunConfigs(p *project) { + if p == nil { + return + } + p.runConfigs.wanted = true + if !p.build.loaded { + a.loadBuildSystems(p) + return + } + for index := range p.build.instances { + if p.build.instances[index].modelError == "" { + a.loadBuildModel(p, index) + } + } +} + +// openRunConfigMenu opens the run configuration menu, closes the other menus of the title bar +// and starts reading the configurations the menu lists. +func (a *App) openRunConfigMenu() { + a.title.runConfigOpen = true + a.title.projectOpen, a.title.gearOpen = false, false + a.closeBranches() + a.loadTitleRunConfigs(a.project) +} + +// chooseTitleConfiguration makes configuration id what the title bar runs; the empty id is +// Current File. +func (a *App) chooseTitleConfiguration(p *project, id string) { + if p == nil { + return + } + if id == "" { + p.runConfigs.currentFile = true + return + } + if p.runConfigs.configuration(id) == nil { + return + } + p.runConfigs.currentFile = false + p.runConfigs.selected = id +} + +// editRunConfigurations opens the Run window, which lists the configurations, and the editor +// of the one the title bar runs. +func (a *App) editRunConfigurations(p *project) { + if p == nil { + return + } + a.openToolWindow(itemRun) + if configuration := p.titleConfiguration(); configuration != nil { + a.openRunConfigEditor(p, configuration.ID) + } +} + +// openToolWindow shows tool window id, leaving it open when it already is. +func (a *App) openToolWindow(id string) { + if !a.chrome.isOpen(catalogIndex[id]) { + a.reduceChrome(core.ToggleChrome(id)) + } +} + +// titleRun is a press on the title bar's Run button: it opens the Run window and runs the +// chosen configuration. +func (a *App) titleRun(p *project) { + if p == nil { + return + } + a.performed("title.run", surfaceButton) + a.openToolWindow(itemRun) + a.titleStart(p, titleActionRun) +} + +// titleDebug is a press on the title bar's Debug button: it opens the Debug window and debugs +// the chosen configuration, or the current file under the selected adapter. +func (a *App) titleDebug(p *project) { + if p == nil { + return + } + a.performed("title.debug", surfaceButton) + a.openToolWindow(itemDebug) + a.titleStart(p, titleActionDebug) +} + +// titleStart performs action now when the configurations are read, and otherwise reads them +// and performs it once they are. A later press replaces the waiting one. +func (a *App) titleStart(p *project, action titleAction) { + if p.runConfigs.currentFile { + a.performTitleAction(p, action, true) + return + } + p.runConfigs.pending = action + a.loadTitleRunConfigs(p) + if p.runConfigs.pending == action && p.runConfigsSettled() { + p.runConfigs.pending = titleActionNone + a.performTitleAction(p, action, true) + } +} + +// settleTitleAction performs the press that waited for the configurations once they are read. +// It runs after every answer that can settle them: detection, a model and the configurations. +func (a *App) settleTitleAction(p *project) { + if p == nil || a.project != p || p.runConfigs.pending == titleActionNone || !p.runConfigsSettled() { + return + } + action := p.runConfigs.pending + p.runConfigs.pending = titleActionNone + a.performTitleAction(p, action, false) +} + +// performTitleAction starts action on the title bar's choice. A configuration whose model has +// not loaded loads it first and waits again; retry says a model that failed before is loaded +// once more, which only a press asks for, so an answer that fails again does not loop. +func (a *App) performTitleAction(p *project, action titleAction, retry bool) { + configuration := p.titleConfiguration() + if configuration == nil { + a.performCurrentFileAction(p, action) + return + } + reference, ok := configuration.BuildReference() + if !ok { + return + } + index := p.buildInstanceIndex(reference) + if index < 0 { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New("the configuration's build instance was not detected"))) + a.notifyError(a.text.Build.TargetMissing) + return + } + instance := &p.build.instances[index] + if !instance.modelLoaded { + if instance.modelError != "" && !retry { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New(instance.modelError))) + a.notifyError(instance.modelError) + return + } + p.runConfigs.pending = action + a.loadBuildModel(p, index) + return + } + switch action { + case titleActionRun: + if _, err := a.startRunConfiguration(p, configuration.ID); errors.Is(err, errBuildBusy) { + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.runBusy")) + } + case titleActionDebug: + run, ok := buildRunDeclaration(instance.System, reference.Run) + if !ok || run.DebugAdapter == "" { + a.notifyInfo(i18n.SharedFormat(a.language(), "desktop.title.notDebuggable", map[string]string{"name": configuration.Name})) + return + } + a.debugProviderTarget(p, index, reference.ProjectID, reference.TargetID, reference.Run) + } +} + +// performCurrentFileAction is Run or Debug on Current File. The Debug window starts the open +// file under its selected adapter; nothing runs the current file outside a configuration. +func (a *App) performCurrentFileAction(p *project, action titleAction) { + if action == titleActionDebug { + a.whenDebugAdaptersLoaded(p, func() { a.startDebug(p) }) + return + } + a.notifyInfo(i18n.Shared(a.language(), "desktop.title.currentFileNotRunnable")) +} diff --git a/desktop/internal/workbench/title_run_test.go b/desktop/internal/workbench/title_run_test.go new file mode 100644 index 0000000000..d7c01f8001 --- /dev/null +++ b/desktop/internal/workbench/title_run_test.go @@ -0,0 +1,191 @@ +package workbench + +import ( + "context" + "encoding/json" + "errors" + "os" + "path/filepath" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" +) + +// captureBuildDebug records the provider debug request and refuses it, so no provider starts. +type captureBuildDebug struct { + Kernel + requests chan core.BuildPlanRequest +} + +func (k *captureBuildDebug) PlanBuildDebug(_ context.Context, _ json.RawMessage, _ string, request core.BuildPlanRequest) (core.BuildPlan, error) { + k.requests <- request + return core.BuildPlan{}, errors.New("captured") +} + +// titleRunHarness opens root with the detected instance whose run is declared as run, and +// returns once the project's configurations are read. +func titleRunHarness(t *testing.T, kernel Kernel, run pluginservice.BuildRunDeclaration) (*harness, *project) { + t.Helper() + h := newHarness(t, kernel) + h.open(runConfigRoot(t)) + p := h.app.project + h.app.post(func(a *App) { + instance := runConfigInstance("app") + instance.System.Runs = []pluginservice.BuildRunDeclaration{run} + p.build.loaded = true + p.build.instances = []buildInstance{instance} + a.refreshRunConfigurations(p) + }) + awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + if len(p.runConfigs.list) != 1 || p.titleConfiguration() == nil { + t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) + } + return h, p +} + +// runConfigRoot is a workspace with the project directory runConfigInstance("app") reports. +func runConfigRoot(t *testing.T) string { + t.Helper() + root := t.TempDir() + if err := os.MkdirAll(filepath.Join(root, "app", "server"), 0o755); err != nil { + t.Fatal(err) + } + return root +} + +// lastNotice is the newest notice of the history, empty when there is none. +func lastNotice(h *harness) string { + if list := h.app.notifications.list; len(list) > 0 { + return list[0].text + } + return "" +} + +// A press on Run before the configurations are read waits for them and then runs the one +// the title bar shows, which is the first configuration when none was chosen. +func TestTitleRunWaitsForTheConfigurationsAndRunsTheChosenOne(t *testing.T) { + gate := &captureBuildPlan{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h := newHarness(t, gate) + h.open(runConfigRoot(t)) + p := h.app.project + h.app.post(func(a *App) { + p.build.loaded = true + p.build.instances = []buildInstance{runConfigInstance("app")} + a.refreshRunConfigurations(p) + a.titleRun(p) + if p.runConfigs.pending != titleActionRun { + t.Errorf("the press did not wait for the configurations: pending %v", p.runConfigs.pending) + } + }) + request := awaitValueWithin(t, h, 10*time.Second, gate.requests, "the provider run request") + if request.Run != "application" || request.Target == nil || request.Target.Name != "Main" { + t.Fatalf("run request = %+v", request) + } + if p.runConfigs.pending != titleActionNone || h.app.titleRunLabel() != "Run Main" { + t.Fatalf("pending %v label %q", p.runConfigs.pending, h.app.titleRunLabel()) + } + if !h.app.chrome.isOpen(catalogIndex[itemRun]) { + t.Fatal("Run did not open the Run window") + } +} + +// Current File has nothing to run outside a configuration: Run says so and plans nothing. +func TestTitleRunOnCurrentFileExplainsAConfigurationIsNeeded(t *testing.T) { + gate := &captureBuildPlan{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h, p := titleRunHarness(t, gate, pluginservice.BuildRunDeclaration{ID: "application", Name: "Run", Tags: []string{"app"}}) + h.app.post(func(a *App) { + a.chooseTitleConfiguration(p, "") + a.titleRun(p) + }) + h.settle() + want := i18n.Shared(h.app.language(), "desktop.title.currentFileNotRunnable") + if got := lastNotice(h); got != want { + t.Fatalf("notice = %q, want %q", got, want) + } + if h.app.titleRunLabel() != h.app.text.Title.CurrentFile || len(gate.requests) != 0 { + t.Fatalf("label %q, %d run requests", h.app.titleRunLabel(), len(gate.requests)) + } +} + +// Debug on a configuration whose run declares no adapter names the configuration and plans +// nothing. +func TestTitleDebugWithoutADeclaredAdapterSaysSo(t *testing.T) { + gate := &captureBuildDebug{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h, p := titleRunHarness(t, gate, pluginservice.BuildRunDeclaration{ID: "application", Name: "Run", Tags: []string{"app"}}) + h.app.post(func(a *App) { a.titleDebug(p) }) + h.settle() + want := i18n.SharedFormat(h.app.language(), "desktop.title.notDebuggable", map[string]string{"name": "Run Main"}) + if got := lastNotice(h); got != want { + t.Fatalf("notice = %q, want %q", got, want) + } + if len(gate.requests) != 0 || p.debug.preparing { + t.Fatalf("%d debug requests, preparing %v", len(gate.requests), p.debug.preparing) + } +} + +// Debug on a configuration whose run declares an adapter asks the provider to prepare that +// run, and a refused preparation ends the preparing state with the reason. +func TestTitleDebugPreparesTheConfigurationsRun(t *testing.T) { + gate := &captureBuildDebug{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h, p := titleRunHarness(t, gate, pluginservice.BuildRunDeclaration{ID: "application", Name: "Run", Tags: []string{"app"}, DebugAdapter: "native"}) + h.app.post(func(a *App) { a.titleDebug(p) }) + request := awaitValueWithin(t, h, 10*time.Second, gate.requests, "the provider debug request") + if request.Run != "application" || request.Target == nil || request.Target.Name != "Main" || request.WorkspaceRoot != p.root { + t.Fatalf("debug request = %+v", request) + } + awaitStateWithin(t, h, 10*time.Second, "the refused preparation", func() bool { return !p.debug.preparing && lastNotice(h) == "captured" }) + if !h.app.chrome.isOpen(catalogIndex[itemDebug]) { + t.Fatal("Debug did not open the Debug window") + } +} + +// The prepared program starts under the adapter the preparation names, not the first adapter +// of the same plugin, with its workspace-relative paths joined onto the project. +func TestProviderDebugStartsTheNamedAdapter(t *testing.T) { + h := debugHarness(t) + p := openDebugPanel(t, h, t.TempDir()) + named := p.debug.adapters[0] + decoy := named + decoy.Declaration.ID, decoy.Declaration.AdapterID = "decoy", "decoy-dap" + p.debug.adapters = []debugAdapter{decoy, named} + h.app.startProviderDebug(p, named.PluginID, core.BuildDebugPreparation{Adapter: named.Declaration.ID, Program: "bin/app", WorkingDirectory: "."}, nil) + session := p.debug.activeSession() + if session == nil || session.adapter.Declaration.ID != named.Declaration.ID { + t.Fatalf("session = %+v, want adapter %q", session, named.Declaration.ID) + } + launch := p.debug.pendingRemote.launchTarget + if launch == nil || launch.Executable != filepath.Join(p.root, "bin", "app") || launch.WorkingDirectory != p.root || launch.Arguments == nil || launch.Environment == nil { + t.Fatalf("launch target = %+v", launch) + } +} + +// A preparation naming an adapter its plugin does not install starts nothing and says so. +func TestProviderDebugRefusesAnAdapterThePluginDoesNotInstall(t *testing.T) { + h := debugHarness(t) + p := openDebugPanel(t, h, t.TempDir()) + h.app.startProviderDebug(p, p.debug.adapters[0].PluginID, core.BuildDebugPreparation{Adapter: "missing", Program: "bin/app"}, nil) + if p.debug.activeSession() != nil { + t.Fatal("an adapter the preparation does not name started") + } + want := i18n.Shared(h.app.language(), "desktop.build.noDebugAdapter") + if got := lastNotice(h); got != want { + t.Fatalf("notice = %q, want %q", got, want) + } +} + +// A model that came with detection turns into configurations without a model answer. +func TestStaticModelDetectionResolvesRunConfigurations(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.open(runConfigRoot(t)) + p := h.app.project + h.app.post(func(a *App) { + a.finishBuildDetection(p, p.build.generation, []buildInstance{runConfigInstance("app")}, nil) + }) + awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + if len(p.runConfigs.list) != 1 || p.runConfigs.list[0].Name != "Run Main" || h.app.titleRunLabel() != "Run Main" { + t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) + } +} diff --git a/desktop/internal/workbench/title_run_view.go b/desktop/internal/workbench/title_run_view.go new file mode 100644 index 0000000000..ca7fb87417 --- /dev/null +++ b/desktop/internal/workbench/title_run_view.go @@ -0,0 +1,61 @@ +package workbench + +import ( + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/ui" +) + +// Widths of the run configuration menu: wide enough for Edit Configuration…, and no wider +// than a long configuration name needs. +const ( + runConfigMenuMin = 224 + runConfigMenuMax = 360 +) + +// titleRunConfigMenu declares the menu under the title bar's run configuration button: Current +// File, the project's configurations while they are read or once they are, and the entry +// that edits them. Choosing one is what Run and Debug start next. +func (a *App) titleRunConfigMenu(c ui.C, anchor ui.Box) { + p := a.project + if p == nil { + a.title.runConfigOpen = false + return + } + lang := a.language() + open := true + ui.Menu(c, anchor, &open, func(menu *ui.MenuItems) { + menu.WidthRange(runConfigMenuMin, runConfigMenuMax) + chosen := p.titleConfiguration() + if menu.Item(a.text.Title.CurrentFile).Icon(icons.FileCode).Chosen(chosen == nil).Clicked() { + c.After(func() { a.chooseTitleConfiguration(p, "") }) + } + menu.Separator() + menu.Label(i18n.Shared(lang, "native.runConfigurations")) + s := &p.runConfigs + for index := range s.list { + configuration := &s.list[index] + id := configuration.ID + if menu.Item(configuration.Name).Icon(icons.Play).Chosen(chosen != nil && chosen.ID == id).Clicked() { + c.After(func() { a.chooseTitleConfiguration(p, id) }) + } + } + switch { + case !p.runConfigsSettled(): + menu.Item(i18n.Shared(lang, "native.loading")).Disabled(true) + case s.failure != "": + menu.Item(i18n.SharedFormat(lang, "desktop.runConfig.loadFailed", map[string]string{"reason": s.failure})).Disabled(true) + case p.build.failed != "": + menu.Item(p.build.failed).Disabled(true) + case len(s.list) == 0: + menu.Item(i18n.Shared(lang, "desktop.title.noRunConfigurations")).Disabled(true) + } + menu.Separator() + if menu.Item(i18n.Shared(lang, "native.editConfiguration")).Icon(icons.Pencil).Clicked() { + c.After(func() { a.editRunConfigurations(p) }) + } + }) + if !open { + a.title.runConfigOpen = false + } +} diff --git a/scripts/desktop/generate-desktop-icons.sh b/scripts/desktop/generate-desktop-icons.sh index 5602c4c93b..73f5b3c8ae 100755 --- a/scripts/desktop/generate-desktop-icons.sh +++ b/scripts/desktop/generate-desktop-icons.sh @@ -29,7 +29,8 @@ ICONS=( trash-2 cloud-download locate tag cloud ellipsis-vertical panel-right eye eye-off clock arrow-up-down arrow-down-to-line circle-x loader-circle wrap-text info copy square wrench eraser undo-2 pencil arrow-up arrow-down git-compare fold-vertical unfold-vertical archive - columns-2 + columns-2 pause redo-dot arrow-down-to-dot arrow-up-from-dot circle-dot circle-slash braces + variable rotate-ccw ) RAW_URL="https://raw.githubusercontent.com/lucide-icons/lucide/$LUCIDE_VERSION" diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 93f517542e..4d30d35fd9 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -880,15 +880,12 @@ "desktop.debug.continue": "Continue", "desktop.debug.disassembly": "Disassembly", "desktop.debug.editValue": "New value", - "desktop.debug.endOfCode": "No more instructions.", "desktop.debug.exceptions": "Exception Breakpoints", "desktop.debug.failed": "Debug session failed", "desktop.debug.filteredFrames": "Filtered frames ({count})", "desktop.debug.frames": "Call stack", "desktop.debug.initialized": "Debug adapter initialized", "desktop.debug.invalidEndpoint": "The debug adapter endpoint is not valid.", - "desktop.debug.loadAfter": "Load later", - "desktop.debug.loadBefore": "Load earlier", "desktop.debug.loadMore": "Load more", "desktop.debug.loadingVariables": "Loading…", "desktop.debug.noAdapters": "The installed plugins declare no debug adapter this client can start.", @@ -1550,7 +1547,6 @@ "desktop.title.noRecentProjects": "No recent projects", "desktop.title.pluginsLater": "The plugins page comes later", "desktop.title.projectMenu": "Project menu", - "desktop.title.runLater": "Running needs a build plugin, which comes later", "desktop.toolchains.automatic": "Automatic ({value})", "desktop.toolchains.chooseHelp": "Selecting a row only changes the draft. Save writes the choice to this project's .lithe/toolchains/local.json; Cancel leaves the file unchanged.", "desktop.toolchains.conflict": "{tool} is defined by {plugins}; disable all but one of those plugins.", @@ -10439,6 +10435,16 @@ "desktop.debug.memory": "Memory", "desktop.debug.noMemory": "The adapter cannot read memory for this frame.", "desktop.debug.memoryUnreadableBytes": "Unreadable bytes: {bytes}", + "desktop.debug.memoryAddress": "Memory address", + "desktop.debug.memoryAddressPlaceholder": "Address, e.g. 0x1000", + "desktop.debug.memoryGoToAddress": "Go to Address", + "desktop.debug.memoryBytesPerRow": "Bytes per row", + "desktop.debug.memoryRowBytes": "{bytes} bytes per row", + "desktop.debug.memoryRadix": "Number base", + "desktop.debug.memoryRadixBinary": "Binary", + "desktop.debug.memoryRadixOctal": "Octal", + "desktop.debug.memoryRadixDecimal": "Decimal", + "desktop.debug.memoryRadixHex": "Hexadecimal", "desktop.debug.stepInto": "Step Into", "desktop.debug.stepOver": "Step Over", "desktop.debug.stepOut": "Step Out", @@ -10700,7 +10706,6 @@ "desktop.debug.breakpoint.functionRow": "ƒ {name}", "desktop.debug.breakpoint.removeFunction": "Remove method breakpoint", "desktop.marketplace.tab.settings": "Settings", - "desktop.debug.breakpoint.instruction": "Breakpoint", "desktop.languageStatus.title": "Language server", "desktop.languageStatus.none": "Not running", "desktop.languageStatus.starting": "Starting", @@ -10983,7 +10988,14 @@ "desktop.terminal.runSelection": "Run Selection in Terminal", "desktop.build.debugTarget": "Debug", "desktop.build.noDebugAdapter": "The build provider's own plugin declares no debug adapter that can start a prepared program.", - "desktop.plugins.installedOnThisComputer": "Installed on this computer: {arg1}" + "desktop.debug.consoleEmpty": "The debug session's output appears here.", + "desktop.debug.evaluatePlaceholder": "Evaluate expression ({evaluate}) or add a watch ({watch})", + "desktop.debug.unmuteBreakpoints": "Unmute breakpoints", + "desktop.plugins.installedOnThisComputer": "Installed on this computer: {arg1}", + "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", + "desktop.title.noRunConfigurations": "No run configurations", + "desktop.title.notDebuggable": "{name} cannot be debugged: its plugin declares no debug adapter for this run.", + "desktop.title.runBusy": "The Run window is still running another operation. Wait for it to finish or stop it first." }, "overrides": { "windows": { diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 8552413c6d..5e2e48a3ad 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -880,15 +880,12 @@ "desktop.debug.continue": "继续", "desktop.debug.disassembly": "反汇编", "desktop.debug.editValue": "新值", - "desktop.debug.endOfCode": "没有更多指令。", "desktop.debug.exceptions": "异常断点", "desktop.debug.failed": "调试会话失败", "desktop.debug.filteredFrames": "已过滤的帧({count})", "desktop.debug.frames": "调用栈", "desktop.debug.initialized": "调试适配器已初始化", "desktop.debug.invalidEndpoint": "调试适配器的端点无效。", - "desktop.debug.loadAfter": "向下加载", - "desktop.debug.loadBefore": "向上加载", "desktop.debug.loadMore": "加载更多", "desktop.debug.loadingVariables": "正在加载…", "desktop.debug.noAdapters": "已安装的插件没有声明此客户端能启动的调试适配器。", @@ -1550,7 +1547,6 @@ "desktop.title.noRecentProjects": "无最近项目", "desktop.title.pluginsLater": "插件页稍后提供", "desktop.title.projectMenu": "项目菜单", - "desktop.title.runLater": "运行需要接入构建插件,稍后提供", "desktop.toolchains.automatic": "自动({value})", "desktop.toolchains.chooseHelp": "选择一行只修改草稿。保存会写入本项目的 .lithe/toolchains/local.json;取消不会改动文件。", "desktop.toolchains.conflict": "{tool} 同时由 {plugins} 定义;请只保留其中一个插件。", @@ -10439,6 +10435,16 @@ "desktop.debug.memory": "内存", "desktop.debug.noMemory": "适配器无法读取当前栈帧的内存。", "desktop.debug.memoryUnreadableBytes": "无法读取的字节:{bytes}", + "desktop.debug.memoryAddress": "内存地址", + "desktop.debug.memoryAddressPlaceholder": "地址,如 0x1000", + "desktop.debug.memoryGoToAddress": "跳转到地址", + "desktop.debug.memoryBytesPerRow": "每行字节数", + "desktop.debug.memoryRowBytes": "每行 {bytes} 字节", + "desktop.debug.memoryRadix": "显示进制", + "desktop.debug.memoryRadixBinary": "二进制", + "desktop.debug.memoryRadixOctal": "八进制", + "desktop.debug.memoryRadixDecimal": "十进制", + "desktop.debug.memoryRadixHex": "十六进制", "desktop.debug.stepInto": "单步进入", "desktop.debug.stepOver": "单步跳过", "desktop.debug.stepOut": "单步跳出", @@ -10700,7 +10706,6 @@ "desktop.debug.breakpoint.functionRow": "ƒ {name}", "desktop.debug.breakpoint.removeFunction": "移除方法断点", "desktop.marketplace.tab.settings": "设置", - "desktop.debug.breakpoint.instruction": "断点", "desktop.languageStatus.title": "语言服务", "desktop.languageStatus.none": "未运行", "desktop.languageStatus.starting": "正在启动", @@ -10983,7 +10988,14 @@ "desktop.terminal.runSelection": "在终端运行选中内容", "desktop.build.debugTarget": "调试", "desktop.build.noDebugAdapter": "该构建插件所属的插件没有声明可以启动已准备程序的调试适配器。", - "desktop.plugins.installedOnThisComputer": "本机已安装:{arg1}" + "desktop.debug.consoleEmpty": "调试会话的输出会显示在这里。", + "desktop.debug.evaluatePlaceholder": "对表达式求值({evaluate})或添加监视({watch})", + "desktop.debug.unmuteBreakpoints": "恢复断点", + "desktop.plugins.installedOnThisComputer": "本机已安装:{arg1}", + "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", + "desktop.title.noRunConfigurations": "没有运行配置", + "desktop.title.notDebuggable": "无法调试 {name}:它所属的插件没有为这个运行声明调试适配器。", + "desktop.title.runBusy": "运行窗口还在执行其他操作。请等它结束,或者先停止它。" }, "overrides": { "macos": { diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 8d59f7f82f..94340603e3 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -5198,7 +5198,8 @@ "id": "debugger.console", "description": "Windows UI: debugger.console", "platforms": [ - "windows" + "windows", + "desktop" ] }, { @@ -5946,7 +5947,8 @@ "id": "debugger.stackEmpty", "description": "Windows UI: debugger.stackEmpty", "platforms": [ - "windows" + "windows", + "desktop" ] }, { @@ -6060,7 +6062,8 @@ "description": "Windows UI: debugger.threadsAndVariables", "platforms": [ "windows", - "macos" + "macos", + "desktop" ], "macos": { "key": "Threads & Variables", @@ -7852,13 +7855,6 @@ "desktop" ] }, - { - "id": "desktop.debug.breakpoint.instruction", - "description": "Button on a disassembly row that toggles a machine-instruction breakpoint there", - "platforms": [ - "desktop" - ] - }, { "id": "desktop.debug.breakpoint.logMessage", "description": "Label of the log message field of a log point", @@ -7968,6 +7964,13 @@ "desktop" ] }, + { + "id": "desktop.debug.consoleEmpty", + "description": "Shown in the Debug window's Console tab before the debug session wrote any output", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.debug.continue", "description": "Continue", @@ -7990,18 +7993,22 @@ ] }, { - "id": "desktop.debug.endOfCode", - "description": "Disassembly note that no more instructions exist in that direction", + "id": "desktop.debug.evaluateFailed", + "description": "Shown when the debugger did not return a value for an expression.", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.evaluateFailed", - "description": "Shown when the debugger did not return a value for an expression.", + "id": "desktop.debug.evaluatePlaceholder", + "description": "Placeholder and accessible name of the Debug window's expression field. {evaluate} and {watch} are the keyboard shortcuts that evaluate the expression once and add it as a watch", "platforms": [ "desktop" - ] + ], + "parameters": { + "evaluate": "string", + "watch": "string" + } }, { "id": "desktop.debug.exceptionInfo", @@ -8056,43 +8063,67 @@ ] }, { - "id": "desktop.debug.loadAfter", - "description": "Disassembly button that lists instructions after the last one shown", + "id": "desktop.debug.loadMore", + "description": "Row that requests the next page of a large variable container", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.loadBefore", - "description": "Disassembly button that lists instructions before the first one shown", + "id": "desktop.debug.loadingVariables", + "description": "Row shown while a page of variables is being requested", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.loadMore", - "description": "Row that requests the next page of a large variable container", + "id": "desktop.debug.memory", + "description": "Tab label of the read-only debug memory view.", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.loadingVariables", - "description": "Row shown while a page of variables is being requested", + "id": "desktop.debug.memoryUnreadableBytes", + "description": "Shows how many requested memory bytes the adapter could not read. {bytes} is the count.", + "platforms": [ + "desktop" + ], + "parameters": { + "bytes": "string" + } + }, + { + "id": "desktop.debug.memoryAddress", + "description": "Accessible label of the memory window's address field", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.memory", - "description": "Tab label of the read-only debug memory view.", + "id": "desktop.debug.memoryAddressPlaceholder", + "description": "Placeholder of the memory window's address field", "platforms": [ "desktop" ] }, { - "id": "desktop.debug.memoryUnreadableBytes", - "description": "Shows how many requested memory bytes the adapter could not read. {bytes} is the count.", + "id": "desktop.debug.memoryGoToAddress", + "description": "Memory window button that reads the memory at the address typed in the field", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryBytesPerRow", + "description": "Accessible label of the memory window's bytes-per-row picker", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryRowBytes", + "description": "One choice of the memory window's bytes-per-row picker. {bytes} is the count.", "platforms": [ "desktop" ], @@ -8100,6 +8131,41 @@ "bytes": "string" } }, + { + "id": "desktop.debug.memoryRadix", + "description": "Accessible label of the memory window's picker for the base each byte is written in", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryRadixBinary", + "description": "Memory window base choice: each byte in binary", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryRadixOctal", + "description": "Memory window base choice: each byte in octal", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryRadixDecimal", + "description": "Memory window base choice: each byte in decimal", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.debug.memoryRadixHex", + "description": "Memory window base choice: each byte in hexadecimal", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.debug.noAdapters", "description": "No installed plugin declares a stdio debug adapter.", @@ -8200,7 +8266,7 @@ }, { "id": "desktop.debug.reload", - "description": "Disassembly button that rebuilds the window around the current instruction", + "description": "Goes back to the current instruction: rebuilds the disassembly around it, or reads the memory at it", "platforms": [ "desktop" ] @@ -8375,6 +8441,13 @@ "desktop" ] }, + { + "id": "desktop.debug.unmuteBreakpoints", + "description": "Debug toolbar toggle, shown while the breakpoints are muted: lets the debuggee stop on them again", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.debug.variables", "description": "Debug tool window section listing the paused frame's scopes and variables", @@ -16489,6 +16562,13 @@ "desktop" ] }, + { + "id": "desktop.title.currentFileNotRunnable", + "description": "Desktop title bar: Run pressed while Current File is chosen; nothing runs a file outside a run configuration", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.title.keymapLater", "description": "Desktop title bar: KeymapLater", @@ -16517,6 +16597,23 @@ "desktop" ] }, + { + "id": "desktop.title.noRunConfigurations", + "description": "Desktop title bar: the run configuration menu when the project has no run configuration", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.title.notDebuggable", + "description": "Desktop title bar: Debug pressed on a run configuration whose plugin declares no debug adapter for its run", + "platforms": [ + "desktop" + ], + "parameters": { + "name": "string" + } + }, { "id": "desktop.title.pluginsLater", "description": "Desktop title bar: PluginsLater", @@ -16532,8 +16629,8 @@ ] }, { - "id": "desktop.title.runLater", - "description": "Desktop title bar: RunLater", + "id": "desktop.title.runBusy", + "description": "Desktop title bar: Run pressed while the Run window is still running another operation", "platforms": [ "desktop" ] @@ -45279,7 +45376,8 @@ "id": "native.collapseFilteredFrames", "description": "Native UI: Collapse filtered frames", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Collapse filtered frames", @@ -60070,7 +60168,8 @@ "id": "native.lineBreakpoints", "description": "Native UI: Line Breakpoints", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Line Breakpoints", @@ -64379,7 +64478,8 @@ "id": "native.muteBreakpoints", "description": "Native UI: Mute breakpoints", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Mute breakpoints", @@ -72540,7 +72640,8 @@ "id": "native.refreshWatches", "description": "Native UI: Refresh watches", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Refresh watches", @@ -74101,7 +74202,8 @@ "id": "native.rerun", "description": "Native UI: Rerun", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Rerun", @@ -90550,7 +90652,8 @@ "id": "native.viewBreakpoints", "description": "Native UI: View Breakpoints", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "View Breakpoints", diff --git a/shared/platform-feature-matrix/features/debug-variable-json-view.json b/shared/platform-feature-matrix/features/debug-variable-json-view.json index 31e5b27e6e..9bb4257a15 100644 --- a/shared/platform-feature-matrix/features/debug-variable-json-view.json +++ b/shared/platform-feature-matrix/features/debug-variable-json-view.json @@ -23,7 +23,7 @@ }, "owner": "Debug", "verification": "暂停真实目标,确认默认JSON可选择和复制,Variables标题右端按钮切树并切回JSON,树展开状态保持;切换线程/帧/作用域、恢复运行或离开JSON时取消并拒绝迟到结果。验证多层对象、连续索引数组、重复引用、循环、长整数、字段失败、根分页及深度/节点/输出限制标记;深浅主题高亮、固定标题和Watches原操作。 验证JSON对象/数组箭头折叠、父子状态保持、更新后清空旧折叠、折叠后仍可复制完整快照及紧凑线程选择器。 实际拖动Watches分隔条、缩放窗口、Add/Edit Watch居中与取消保存;比较Console空/非空及主题和壁纸背景。 验证JSON展开/收起行hover显隐、跨行移动、隐藏时点击不折叠、键盘聚焦、拖动期间隐藏及布局不跳动。 深浅主题验证方法/行号颜色、同名去重、关闭源码名称恢复、内部类与不同类名保留。", - "notes": "Variables 区可在树与 JSON 文本之间切换:JSON 只镜像已加载的变量(`[n]` 子项为数组,数字、布尔、null 与带引号字符串保持原文,其余文本为字符串),未展开容器显示适配器的摘要值,不额外请求适配器。", + "notes": "Variables 区可在树与 JSON 文本之间切换:JSON 只镜像已加载的变量(`[n]` 子项为数组,数字、布尔、null 与带引号字符串保持原文,其余文本为字符串),未展开容器显示适配器的摘要值,不额外请求适配器。 Viva 2026-11-12:树与 JSON 的切换移到调试工具栏“更多”(⋮)菜单,变量区不再有切换标签。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json new file mode 100644 index 0000000000..5bca069be0 --- /dev/null +++ b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json @@ -0,0 +1,47 @@ +{ + "id": "viva-debug-tool-window-layout", + "area": "运行与调试", + "group": "调试器", + "capability": "调试工具窗口按 IntelliJ IDEA 布局:图标工具栏(重新运行、停止 | 继续、暂停、单步跳过、单步进入、单步跳出 | 查看断点、静音断点 | 更多);“线程和变量”“控制台”标签;左栏线程下拉与“函数 (文件:行)”栈帧,过滤帧淡色;右栏“对表达式求值(⏎)或添加监视(⇧⌘⏎)”输入框、监视行和带类型图标的“名称 = {类型} 值”变量树;“反汇编”标签无自带按钮,工具栏单步按指令执行,行首红点设置或移除指令断点,滚动到两端加载更多代码;“内存”标签可输入地址跳转(十六进制或十进制)、切换每行 8/16/32/64 字节与十六/十/八/二进制,并高亮目标字节;断点和异常断点在“查看断点”对话框中管理", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/debug_view.go", + "desktop/internal/workbench/debug_sections_view.go", + "desktop/internal/workbench/debug_watch.go", + "desktop/internal/workbench/debug_mute.go", + "desktop/internal/workbench/debug_threads.go", + "desktop/internal/workbench/debug_menus.go", + "desktop/internal/workbench/debug_start.go", + "desktop/internal/workbench/debug_toolbar_test.go", + "desktop/internal/workbench/debug_threads_test.go", + "desktop/internal/workbench/debug_menus_test.go", + "desktop/internal/workbench/debug_disassembly.go", + "desktop/internal/workbench/debug_memory.go", + "desktop/internal/workbench/debug_memory_test.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/debug_view.go", + "desktop/internal/workbench/debug_sections_view.go", + "desktop/internal/workbench/debug_watch.go", + "desktop/internal/workbench/debug_mute.go", + "desktop/internal/workbench/debug_threads.go", + "desktop/internal/workbench/debug_menus.go", + "desktop/internal/workbench/debug_start.go", + "desktop/internal/workbench/debug_toolbar_test.go", + "desktop/internal/workbench/debug_threads_test.go", + "desktop/internal/workbench/debug_menus_test.go", + "desktop/internal/workbench/debug_disassembly.go", + "desktop/internal/workbench/debug_memory.go", + "desktop/internal/workbench/debug_memory_test.go" + ] + }, + "owner": "Debug", + "verification": "用 fixture 调试适配器暂停目标:工具栏各按钮按会话状态启用;重新运行停止当前会话并按首次启动方式重启;静音后断点保留并以禁用状态发送,取消静音按原样重发;更多菜单在树与 JSON 间切换并开关折叠过滤帧;回车求值保留输入,⇧⌘⏎(其他平台 Ctrl+Shift+Enter)加为监视并清空输入;栈帧右键菜单末尾可复制线程名、单独恢复线程;控制台显示适配器输出并在位于末尾时跟随新行;查看断点对话框可增删、启用禁用断点并选择异常断点;反汇编打开时以当前指令居中,点击行首红点增删指令断点,单步按指令执行;内存输入 8208 跳到 0x2010 并高亮该字节,切换每行 32 字节和二进制后版式保持,回到当前指令时保留版式。原生窗口视觉与真实 Go/LLDB 适配器验收 pending。", + "notes": "线程下拉在只有一个线程时也显示。树与 JSON 的切换从变量区移到工具栏“更多”菜单。暂无布局切换按钮、异步栈、包名列(DebugStackFrame 无包字段);监视以独立行显示,尚未并入变量树。 内存暂不支持表达式输入(变量未携带 memoryReference);进制提供 16/10/8/2,未提供 4 进制。反汇编向前加载时以可见范围(含 2 行预排)中点保持位置,属近似。" +} diff --git a/shared/platform-feature-matrix/features/viva-title-run-debug.json b/shared/platform-feature-matrix/features/viva-title-run-debug.json new file mode 100644 index 0000000000..f8791aab0a --- /dev/null +++ b/shared/platform-feature-matrix/features/viva-title-run-debug.json @@ -0,0 +1,35 @@ +{ + "id": "viva-title-run-debug", + "area": "运行与调试", + "group": "运行配置", + "capability": "标题栏右上角的运行配置下拉、运行和调试按钮:下拉列出构建提供者检测到的运行配置并可选择“当前文件”,运行按所选配置交给提供者启动并打开运行窗口,调试让提供者准备该运行声明的调试适配器后在调试窗口启动会话;配置尚未读出时按下会等读出后再执行", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/title_run.go", + "desktop/internal/workbench/title_run_view.go", + "desktop/internal/workbench/title_run_test.go", + "desktop/internal/workbench/runconfig.go", + "desktop/internal/workbench/build.go", + "desktop/internal/pluginservice/builds.go", + "desktop/internal/core/build.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/title_run.go", + "desktop/internal/workbench/title_run_view.go", + "desktop/internal/workbench/title_run_test.go", + "desktop/internal/workbench/runconfig.go", + "desktop/internal/workbench/build.go", + "desktop/internal/pluginservice/builds.go", + "desktop/internal/core/build.go" + ] + }, + "owner": "Run", + "verification": "打开带构建提供者(如 Maven、Go)的项目:标题栏下拉列出检测到的运行配置并记住所选项;运行按钮启动所选配置并打开运行窗口;调试按钮对声明了调试适配器的运行准备并启动调试会话、打开调试窗口,未声明时提示该配置不能调试;准备失败时结束“准备中”并显示原因;选择“当前文件”时提示需要运行配置。单元测试覆盖等待配置读出后运行、当前文件提示、无适配器提示、提供者准备请求、按名称选择适配器和拒绝插件未安装的适配器。", + "notes": "Viva 标题栏按钮此前只有外观。运行忙碌时仅提示,不排队;当前文件运行尚未实现,只提示需要配置;提供者调试暂不携带运行配置的启动选项。macOS、Windows 原生窗口验收 pending。" +} From 22de0b40fd292e314446aef5120f2c36d0142baf Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Fri, 13 Nov 2026 12:15:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(desktop):=20#1794=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A0=8F=E6=82=AC=E5=81=9C=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E3=80=81=E5=8F=8D=E6=B1=87=E7=BC=96=E5=B7=A6=E4=BE=A7=E6=A0=88?= =?UTF-8?q?=E5=B8=A7=E3=80=81=E9=80=82=E9=85=8D=E5=99=A8=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E4=B8=AD=E5=8F=AF=E5=88=87=E6=8D=A2=E3=80=81=E6=B1=82=E5=80=BC?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=AE=8C=E6=95=B4=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调试工具栏和其他只有图标的按钮(工具窗口按钮、搜索、终端查找、欢迎页设置等)鼠标悬停显示操作名 - 调试适配器下拉在会话中仍显示并可切换,供下次启动;状态只在下拉显示的不是该会话适配器时带会话名 - 反汇编标签左栏复用线程下拉和栈帧,右栏显示所选栈帧的指令;切换栈帧重置反汇编, 过期回复按 epoch 丢弃 - 求值结果和监视的失败原因折行完整显示,不再截断;有值的监视保持单行 --- .../internal/workbench/debug_disassembly.go | 28 ++++++-- .../internal/workbench/debug_sections_view.go | 31 +++++--- .../internal/workbench/debug_threads_test.go | 64 +++++++++++++++++ .../internal/workbench/debug_toolbar_test.go | 71 +++++++++++++++++++ desktop/internal/workbench/debug_variables.go | 3 + desktop/internal/workbench/debug_view.go | 29 +++++--- desktop/internal/workbench/debug_watch.go | 48 +++++++++---- desktop/internal/workbench/editor_view.go | 3 +- desktop/internal/workbench/git_widgets.go | 2 +- .../internal/workbench/new_project_view.go | 3 +- .../workbench/search_everywhere_view.go | 5 +- .../internal/workbench/search_replace_view.go | 2 +- desktop/internal/workbench/search_view.go | 5 +- desktop/internal/workbench/shell_view.go | 3 +- desktop/internal/workbench/terminal_find.go | 8 ++- desktop/internal/workbench/welcome_view.go | 2 +- .../viva-debug-tool-window-layout.json | 4 +- 17 files changed, 260 insertions(+), 51 deletions(-) diff --git a/desktop/internal/workbench/debug_disassembly.go b/desktop/internal/workbench/debug_disassembly.go index b12d94c92d..2569297e4f 100644 --- a/desktop/internal/workbench/debug_disassembly.go +++ b/desktop/internal/workbench/debug_disassembly.go @@ -41,9 +41,13 @@ type debugDisassembly struct { // pending holds the instructions of the reply being reduced; Core answers // with indexes into them. pending []core.DebugInstruction + // epoch counts the windows: a reply that arrives after its window was dropped (another + // frame or thread was selected, or the debuggee moved) belongs to an older epoch and is + // dropped too, so it cannot fill the window of the frame shown now. + epoch int } -func (d *debugDisassembly) reset() { *d = debugDisassembly{} } +func (d *debugDisassembly) reset() { *d = debugDisassembly{epoch: d.epoch + 1} } // canDisassemble reports whether the selected frame can be shown as code: the // adapter advertised disassemble, the session is paused and the frame carries @@ -108,7 +112,7 @@ func (a *App) loadDisassemblyAtEdges(p *project) { // planDisassembly asks Core for the first request of a window, then follows // Core's steps until it answers with a page or a failure. func (a *App) planDisassembly(p *project, direction, reference string, count, before uint32) { - session := p.debug.activeSession() + session, epoch := p.debug.activeSession(), p.debug.disassembly.epoch a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { fetch, err := a.kernel.PlanDebugDisassemblyWindow(ctx, direction, reference, count, before) return func(a *App) { @@ -116,6 +120,9 @@ func (a *App) planDisassembly(p *project, direction, reference string, count, be return } defer p.debug.bindSession(session)() + if p.debug.disassembly.epoch != epoch { + return + } if err != nil { p.debug.disassembly.loading, p.debug.disassembly.failure = false, err.Error() return @@ -129,13 +136,21 @@ func (a *App) planDisassembly(p *project, direction, reference string, count, be func (a *App) fetchDisassembly(p *project, fetch core.DebugDisassemblyFetch) { request := fetch.Request offset, count := request.InstructionOffset, int64(request.InstructionCount) - reduce := func(a *App, reply core.DebugDisassemblyReply) { a.reduceDisassembly(p, fetch, reply) } + epoch := p.debug.disassembly.epoch + reduce := func(a *App, reply core.DebugDisassemblyReply) { + if p.debug.disassembly.epoch == epoch { + a.reduceDisassembly(p, fetch, reply) + } + } a.debugOperation(p, "disassemble", func(ctx context.Context, session *debugSession, operationID string) (core.DebugUpdate, error) { return a.kernel.InspectDebug(ctx, core.DebugInspectRequest{ SessionID: session.id, OperationID: operationID, Kind: "disassemble", MemoryReference: request.MemoryReference, InstructionOffset: &offset, InstructionCount: &count, }) }, debugOperationHandlers{done: func(a *App, result core.DebugOperationResult) { + if p.debug.disassembly.epoch != epoch { + return + } reply := core.DebugDisassemblyReply{Kind: "instructions"} for _, instruction := range result.Instructions { reply.Instructions = append(reply.Instructions, core.DebugDisassemblyReplyInstruction{ @@ -159,7 +174,7 @@ func (a *App) fetchDisassembly(p *project, fetch core.DebugDisassemblyFetch) { // reduceDisassembly applies Core's decision for one reply. func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, reply core.DebugDisassemblyReply) { - session := p.debug.activeSession() + session, epoch := p.debug.activeSession(), p.debug.disassembly.epoch known := make([]string, 0, len(p.debug.disassembly.rows)) for _, row := range p.debug.disassembly.rows { known = append(known, row.Address) @@ -169,11 +184,14 @@ func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, re a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { step, err := a.kernel.ReduceDebugDisassemblyPage(ctx, fetch, reply, known) return func(a *App) { - d := &p.debug.disassembly if a.project != p || !p.debug.hasSession(session) { return } defer p.debug.bindSession(session)() + d := &p.debug.disassembly + if d.epoch != epoch { + return + } if err != nil { d.loading, d.failure = false, err.Error() return diff --git a/desktop/internal/workbench/debug_sections_view.go b/desktop/internal/workbench/debug_sections_view.go index 73d7f2025d..29972242ab 100644 --- a/desktop/internal/workbench/debug_sections_view.go +++ b/desktop/internal/workbench/debug_sections_view.go @@ -23,8 +23,8 @@ const ( debugSectionMemory = "memory" ) -// Minimum widths of the two panes of Threads & Variables, and the share of the call stack -// before the user moves the divider. +// Minimum widths of the call stack and of the pane beside it in Threads & Variables and +// Disassembly, and the share of the call stack before the user moves the divider. const ( debugFramesMinWidth = 160 debugVariablesMinWidth = 220 @@ -64,18 +64,26 @@ func (a *App) debugSections(c ui.C, p *project) { // debugThreadsAndVariables declares the Threads & Variables tab: the call stack on the left and, // past a divider the user moves, the variables of the selected frame. func (a *App) debugThreadsAndVariables(c ui.C, p *project) { + a.debugBesideFrames(c, p, "variables", func() { a.debugVariablesView(c, p) }) +} + +// debugBesideFrames declares the thread picker and call stack on the left of a tab, as IntelliJ +// IDEA keeps them beside the variables and the disassembly, and the tab's own pane past a +// divider the user moves. The tabs share the divider, so the stack keeps its width as the user +// moves between them. +func (a *App) debugBesideFrames(c ui.C, p *project, part string, pane func()) { split := &p.panels.debugSplit if split.Ratio <= 0 { split.Ratio = debugFramesRatio } - var frames, variables ui.Box + var frames, beside ui.Box ui.Row(c).Fill().Clip().Children(func() { frames = ui.Column(c.Part("frames")).Children(func() { a.debugFrames(c, p) }) ui.Splitter(c, split).Mins(debugFramesMinWidth, debugVariablesMinWidth).Label(a.text.Panel.Resize) - variables = ui.Column(c.Part("variables")).Children(func() { a.debugVariablesView(c, p) }) + beside = ui.Column(c.Part(part)).Children(pane) }) frames.FillHeight().MinWidth(debugFramesMinWidth).Shrink(1) - variables.Fill().MinWidth(debugVariablesMinWidth) + beside.Fill().MinWidth(debugVariablesMinWidth) } // debugVariableLabel is the text assistive technology reads for one row. @@ -284,12 +292,19 @@ func (a *App) debugExceptionsView(c ui.C, p *project) { }) } -// debugDisassemblyView declares the instruction window of the selected frame as IntelliJ IDEA -// shows it: no actions of its own. The toolbar's steps take one instruction while this tab is +// debugDisassemblyView declares the Disassembly tab: the call stack on the left, as in Threads & +// Variables, and the instructions of the selected frame beside it. Choosing another frame +// shows that frame's code. +func (a *App) debugDisassemblyView(c ui.C, p *project) { + a.debugBesideFrames(c, p, "disassembly", func() { a.debugInstructions(c, p) }) +} + +// debugInstructions declares the instruction window of the selected frame as IntelliJ IDEA +// shows it: no actions of its own. The toolbar's steps take one instruction while the tab is // shown (see debugStepGranularity), the toolbar's More menu goes back to the current // instruction, scrolling to either end loads more code, and a click in the gutter sets or // removes an instruction breakpoint, drawn as the editor draws a line breakpoint. -func (a *App) debugDisassemblyView(c ui.C, p *project) { +func (a *App) debugInstructions(c ui.C, p *project) { t, d := a.text.Debug, &p.debug w := &d.disassembly if !canDisassemble(d) { diff --git a/desktop/internal/workbench/debug_threads_test.go b/desktop/internal/workbench/debug_threads_test.go index 1025ceee9c..82d0e3756a 100644 --- a/desktop/internal/workbench/debug_threads_test.go +++ b/desktop/internal/workbench/debug_threads_test.go @@ -3,6 +3,7 @@ package workbench import ( "os" "path/filepath" + "strings" "testing" "time" @@ -239,3 +240,66 @@ func TestDebugThreadResumesAloneAndWatchEditsInPlace(t *testing.T) { return p.debug.state == "running" && p.debug.resumedThreads == nil }) } + +// TestDebugEvaluateAndWatchShowTheirWholeReason checks that a reason the debugger gives for not +// evaluating an expression wraps to be read whole, in the evaluate field's result and in a +// watch, while a watch with a value keeps its row one line tall. +func TestDebugEvaluateAndWatchShowTheirWholeReason(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + if err := h.driver.Resize(1280, 900); err != nil { + t.Fatal(err) + } + reason := func(marker string) string { + return "Expression evaluation in pure C not supported. Ran expression as 'ISO C++'. " + + strings.Repeat("error: use of undeclared identifier in the selected frame of the stopped thread; ", 4) + marker + } + w := &p.debug.watch + w.evaluated = &debugWatchEntry{expression: "evaluated", failure: reason("EVALUATED_END")} + w.entries = []debugWatchEntry{ + {expression: "refused", failure: reason("WATCH_END")}, + {expression: "kept", value: "42", typeName: "int"}, + } + p.debug.section = debugSectionThreads + h.app.invalidator.Invalidate() + h.settle() + + for _, entry := range []debugWatchEntry{*w.evaluated, w.entries[0]} { + if !h.showsWrapped(entry.failure) { + t.Fatalf("the reason for %q is not shown whole", entry.expression) + } + } + line := func(part string) gfx.Rect { + t.Helper() + for _, label := range h.driver.Snapshot().Labels { + if strings.Contains(label.Value, part) { + if strings.Contains(label.Value, "…") { + t.Fatalf("the reason was cut: %q", label.Value) + } + return label.Bounds + } + } + t.Fatalf("no line shows %q", part) + return gfx.Rect{} + } + expression := line("evaluated") + first, last := line("pure C"), line("EVALUATED_END") + if last.Y <= first.Y { + t.Fatalf("the evaluated reason did not wrap: first line %v, last line %v", first, last) + } + // The reason's first line sits beside the expression, as a one-line row places both. + if first.Y != expression.Y { + t.Fatalf("the reason starts at %v beside the expression at %v", first, expression) + } + refused, ok := h.findPageHit("refused") + if !ok || refused.Bounds.Height <= debugRowHeight { + t.Fatalf("the refused watch row did not grow for its reason: %+v", refused.Bounds) + } + if end := line("WATCH_END"); end.Y+end.Height > refused.Bounds.Y+refused.Bounds.Height { + t.Fatalf("the watch reason ends at %v below its row %v", end, refused.Bounds) + } + kept, ok := h.findPageHit("kept") + if !ok || kept.Bounds.Height != debugRowHeight { + t.Fatalf("the watch with a value is not one row tall: %+v", kept.Bounds) + } +} diff --git a/desktop/internal/workbench/debug_toolbar_test.go b/desktop/internal/workbench/debug_toolbar_test.go index 6f1b2b3c69..ca3ff0b746 100644 --- a/desktop/internal/workbench/debug_toolbar_test.go +++ b/desktop/internal/workbench/debug_toolbar_test.go @@ -125,6 +125,41 @@ func TestDebugAdapterPickerSitsInTheToolbar(t *testing.T) { } } +// Every icon of the toolbar names its action in the tip that shows while the pointer rests on +// it, and while a session runs the adapter picker stays on the toolbar, switchable for the next +// session, with the status beside it naming the session only when the picker shows another +// adapter. +func TestDebugToolbarNamesItsIconsAndKeepsTheAdapterSwitchable(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d, words := &p.debug, h.app.text.Debug + for _, name := range []string{ + h.shared("native.rerun"), words.Stop, words.Continue, words.Pause, words.StepOver, words.StepInto, words.StepOut, + h.shared("native.viewBreakpoints"), h.shared("native.muteBreakpoints"), h.shared("native.moreActions"), + } { + if hint := h.pageHit(name).Hint; hint != name { + t.Errorf("the %q icon shows the tip %q", name, hint) + } + } + picker := h.pageHit(h.shared("desktop.debug.adapter")) + stop := h.pageHit(words.Stop).Bounds + if abs32(center(picker.Bounds).Y-center(stop).Y) > 2 || picker.Bounds.X <= stop.X { + t.Fatalf("picker %+v is not on the toolbar row of Stop %+v", picker.Bounds, stop) + } + named := h.app.debugSessionLabel(d.activeSession()) + " · " + words.Paused + if !h.shows(words.Paused) || h.shows(named) { + t.Fatal("the status repeats the adapter the picker shows") + } + // A session the picker no longer shows is named by the status again. + d.adapters = append(d.adapters, debugAdapter{PluginID: "dev.lithe.test.other", Declaration: d.adapters[0].Declaration}) + d.selectedAdapter = len(d.adapters) - 1 + h.app.invalidator.Invalidate() + h.settle() + if !h.shows(named) { + t.Fatal("the status does not name the running session after the picker switched away from it") + } +} + func abs32(v float32) float32 { if v < 0 { return -v @@ -170,6 +205,42 @@ func TestDebugDisassemblyStepsByInstructionAndTogglesItsGutterDot(t *testing.T) } } +// The Disassembly tab keeps the call stack on its left, as Threads & Variables does, and choosing +// another frame there shows that frame's code, not the code of the frame chosen before. +func TestDebugDisassemblyShowsTheStackBesideTheChosenFramesCode(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d := &p.debug + d.section = debugSectionDisassembly + h.app.invalidator.Invalidate() + awaitStateWithin(t, h, 20*time.Second, "the instruction window", func() bool { + return !d.disassembly.loading && len(d.disassembly.rows) > 0 + }) + // The list centres the current instruction in the frames it asks for; virtual time runs them. + if err := h.driver.Advance(200 * time.Millisecond); err != nil { + t.Fatal(err) + } + frame, code := h.pageHit("worker").Bounds, h.labelBounds("0x1000") + if code.Width == 0 || frame.X+frame.Width > code.X { + t.Fatalf("frame %+v is not on the left of the code %+v", frame, code) + } + + // The fixture's second frame has no instruction pointer, so its tab has no code. + h.click(center(frame)) + awaitStateWithin(t, h, 10*time.Second, "the second frame", func() bool { return d.vars.frame == 1 }) + h.settle() + if len(d.disassembly.rows) != 0 || !h.shows(h.app.text.Debug.NoDisassembly) { + t.Fatalf("the second frame shows %d rows of the first frame's code", len(d.disassembly.rows)) + } + h.clickNamed("main") + awaitStateWithin(t, h, 20*time.Second, "the first frame's code again", func() bool { + return d.vars.frame == 0 && !d.disassembly.loading && len(d.disassembly.rows) > 0 + }) + if d.disassembly.anchor != "0x1000" { + t.Fatalf("the window opened at %q, want the first frame's instruction pointer", d.disassembly.anchor) + } +} + // The memory window reads at a typed address, aligns its rows and highlights that address's // byte, lays the bytes out again by row width and base, and goes back to the instruction // pointer keeping the layout chosen. diff --git a/desktop/internal/workbench/debug_variables.go b/desktop/internal/workbench/debug_variables.go index 8fa678a6cc..2d57132705 100644 --- a/desktop/internal/workbench/debug_variables.go +++ b/desktop/internal/workbench/debug_variables.go @@ -275,6 +275,9 @@ func (a *App) selectDebugFrame(p *project, index int) { return } d.vars.reset() + // The disassembly and memory belong to the frame shown before; the tab that shows them + // loads them again for this one. + d.disassembly.reset() d.memory.reset() d.vars.frame = index d.vars.loading = true diff --git a/desktop/internal/workbench/debug_view.go b/desktop/internal/workbench/debug_view.go index caa1223893..44c3af5c48 100644 --- a/desktop/internal/workbench/debug_view.go +++ b/desktop/internal/workbench/debug_view.go @@ -65,8 +65,8 @@ func (a *App) debugView(c ui.C, p *project) { // debugToolbar declares the Debug window's actions as IntelliJ IDEA groups them: rerun and // stop the session; resume, pause and the steps of the paused thread; the breakpoints dialog // and the switch that mutes every breakpoint; then the More menu. Start stands in for Stop -// while no session runs. The status of the shown session closes the row, and while no session -// runs the compact adapter picker follows it. +// while no session runs. Each icon names its action when the pointer rests on it. The status +// of the shown session and the compact adapter picker close the row. func (a *App) debugToolbar(c ui.C, p *project) { t, d := a.text.Debug, &p.debug lang := a.language() @@ -127,18 +127,27 @@ func (a *App) debugToolbar(c ui.C, p *project) { ui.Spacer(c) if d.status != "" { status := d.status - if session != nil { + // The picker names the session's adapter while it shows that adapter; a child + // session, or a session whose adapter the user switched away from, is named here. + if session != nil && !d.pickerShows(session) { status = a.debugSessionLabel(session) + " · " + status } ui.Text(c, status).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() } - // The adapter is chosen before a session starts; while one runs, its label says which. - if session == nil { - a.debugAdapterPicker(c.Part("adapter"), p) - } + a.debugAdapterPicker(c.Part("adapter"), p) }) } +// pickerShows reports whether the toolbar's adapter picker shows the adapter session runs: a +// session the user started from it, not one another session started. +func (d *debugState) pickerShows(session *debugSession) bool { + if session.parent != nil || len(d.adapters) == 0 { + return false + } + picked := d.adapters[d.selectedAdapter] + return picked.PluginID == session.adapter.PluginID && picked.Declaration.ID == session.adapter.Declaration.ID +} + // debugStepGranularity is the unit the toolbar's steps take: one instruction while the // Disassembly tab is shown and the adapter accepts a granularity, as IntelliJ IDEA steps in its // disassembly view, and the adapter's own unit otherwise. Core forwards the granularity only @@ -192,9 +201,9 @@ func (a *App) debugMoreMenu(c ui.C, anchor ui.Box, p *project) { } } -// debugAdapterPicker declares the compact adapter picker at the end of the toolbar. It is -// shown only while no session runs: a running session's adapter is fixed and the status -// already names it. +// debugAdapterPicker declares the compact adapter picker at the end of the toolbar. It stays +// switchable while a session runs, as IntelliJ IDEA's run configuration does: a running +// session keeps its adapter, and the choice is the one Start and the next session use. func (a *App) debugAdapterPicker(c ui.C, p *project) { d := &p.debug if len(d.adapters) == 0 { diff --git a/desktop/internal/workbench/debug_watch.go b/desktop/internal/workbench/debug_watch.go index 02d7b4fc9d..c80ce0916f 100644 --- a/desktop/internal/workbench/debug_watch.go +++ b/desktop/internal/workbench/debug_watch.go @@ -256,9 +256,11 @@ func (a *App) debugEvaluateField(c ui.C, p *project) { } }) if entry := w.evaluated; entry != nil { - ui.Row(c.Key("evaluated")).FillWidth().Height(debugRowHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(10).Children(func() { - ui.Icon(c, icons.Variable).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Accent) - a.debugWatchText(c, *entry) + // The result is read once, so it is shown whole: a long value or reason, such as the + // debugger saying it ran the expression in another language, wraps over more lines. + ui.Row(c.Key("evaluated")).FillWidth().MinHeight(debugRowHeight).Shrink(0).Items(ui.Start).Gap(6).PadX(10).Children(func() { + ui.Icon(c, icons.Variable).Size(treelist.Icon, treelist.Icon).Shrink(0).MarginTop(debugIconInset).Color(a.colors.Accent) + a.debugWatchText(c, *entry, true) }) } } @@ -277,19 +279,39 @@ func isDebugAddWatch(event gfx.KeyEvent) bool { chord.Modifiers&(gfx.ModifierShift|gfx.ModifierControl|gfx.ModifierAlt|gfx.ModifierMeta) == debugAddWatchChord.Modifiers } +// A watch row starts its items at the top so a reason or value that wraps grows it down, and +// places them where a one-line row of debugRowHeight centres them: the icon debugIconInset +// down, and each line of text debugTextLeading tall, debugTextInset down. +const ( + debugTextLeading = 18 + debugTextInset = (debugRowHeight - debugTextLeading) / 2 + debugIconInset = (debugRowHeight - treelist.Icon) / 2 +) + +// debugRowText sets a text of a watch row on the lines debugTextLeading lays out. +func debugRowText(text ui.Box) ui.Box { + return text.FontSize(12.5).LineHeight(debugTextLeading).MarginY(debugTextInset) +} + // debugWatchText declares an expression with its result as IntelliJ IDEA writes it, -// "expression = {type} value", or with the reason it has none. -func (a *App) debugWatchText(c ui.C, entry debugWatchEntry) { - ui.Text(c, entry.expression).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) +// "expression = {type} value", or with the reason it has none. The reason always wraps to be +// read whole; whole wraps the value too, where watches keep theirs to one line as IntelliJ +// IDEA does. +func (a *App) debugWatchText(c ui.C, entry debugWatchEntry, whole bool) { + debugRowText(ui.Text(c, entry.expression)).Shrink(0).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) switch { case entry.failure != "": - ui.Text(c, entry.failure).Shrink(1).FontSize(12.5).Color(a.theme.Danger).Ellipsis() + debugRowText(ui.Wrap(c, entry.failure)).Grow(1).Shrink(1).Color(a.theme.Danger) case entry.value != "" || entry.typeName != "": - ui.Text(c, "=").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) + debugRowText(ui.Text(c, "=")).Shrink(0).Color(a.colors.Subtle) if entry.typeName != "" { - ui.Text(c, "{"+entry.typeName+"}").Shrink(0).FontSize(12.5).Color(a.colors.Subtle) + debugRowText(ui.Text(c, "{"+entry.typeName+"}")).Shrink(0).Color(a.colors.Subtle) + } + if whole { + debugRowText(ui.Wrap(c, entry.value)).Grow(1).Shrink(1).Color(a.colors.Text).Mono() + return } - ui.Text(c, entry.value).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis().Mono() + debugRowText(ui.Text(c, entry.value)).Shrink(1).Color(a.colors.Text).Ellipsis().Mono() } } @@ -314,12 +336,12 @@ func (a *App) debugWatchView(c ui.C, p *project) { } entry := w.entries[index] k := c.Part("watch").KeyInt(index) - row := ui.Row(k).FillWidth().Height(debugRowHeight).Shrink(0).Items(ui.Center).Gap(6).PadX(10). + row := ui.Row(k).FillWidth().MinHeight(debugRowHeight).Shrink(0).Items(ui.Start).Gap(6).PadX(10). Hover(ui.Look{}.Background(a.colors.Hover)). HitWith(ui.ID(k), entry.expression, gfx.HitOptions{SkipFocus: true}) row.Children(func() { - ui.Icon(k, icons.Eye).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) - a.debugWatchText(k, entry) + ui.Icon(k, icons.Eye).Size(treelist.Icon, treelist.Icon).Shrink(0).MarginTop(debugIconInset).Color(a.colors.Subtle) + a.debugWatchText(k, entry, false) ui.Spacer(k) i := index if _, clicked := a.toolIconButton(k.Key("remove"), t.RemoveWatch, icons.X, false, false); clicked { diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index 258bbe4971..a83fc01e46 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -313,7 +313,8 @@ func (a *App) terminalTabs(c ui.C) { u.tool, u.toolDrawn = place, true ui.Row(c).Grow(1).Shrink(1).MinWidth(0).Height(panelHeaderHeight).Items(ui.Center).Gap(chromeGap).Clip().Draw(place.stripHook).Children(func() { a.tabBar(c, place, tabsScroll, func() { - if ui.Button(c.Part("new"), a.text.Terminal.NewTab).Icon(icons.Plus).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Shrink(0).Clicked() { + if ui.Button(c.Part("new"), a.text.Terminal.NewTab).Icon(icons.Plus).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Shrink(0). + Tooltip(a.text.Terminal.NewTab).Clicked() { c.After(func() { a.openToolTerminal("") }) } a.shellMenuButton(c) diff --git a/desktop/internal/workbench/git_widgets.go b/desktop/internal/workbench/git_widgets.go index 74838a59ed..40e34881e7 100644 --- a/desktop/internal/workbench/git_widgets.go +++ b/desktop/internal/workbench/git_widgets.go @@ -18,7 +18,7 @@ func (a *App) gitIconButton(c ui.C, label string, icon gfx.Icon, on, disabled bo // gitToolButton is gitIconButton that also returns the button, for a popover or a menu that // hangs off it. func (a *App) gitToolButton(c ui.C, label string, icon gfx.Icon, on, disabled bool) (ui.Box, bool) { - button := ui.Button(c, label).Icon(icon).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Disabled(disabled) + button := ui.Button(c, label).Icon(icon).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Disabled(disabled).Tooltip(label) if on { button = button.Background(a.colors.Active) } diff --git a/desktop/internal/workbench/new_project_view.go b/desktop/internal/workbench/new_project_view.go index cfb5c4ee0c..2faaa089ab 100644 --- a/desktop/internal/workbench/new_project_view.go +++ b/desktop/internal/workbench/new_project_view.go @@ -271,7 +271,8 @@ func (a *App) newProjectFields(c ui.C, language i18n.Language, choice *projectCh if locked { field.Disabled(true) } - if ui.Button(c, i18n.Shared(language, "desktop.newProject.choose")).Icon(icons.Folder).IconOnly().Ghost().Disabled(locked).Clicked() { + if ui.Button(c, i18n.Shared(language, "desktop.newProject.choose")).Icon(icons.Folder).IconOnly().Ghost().Disabled(locked). + Tooltip(i18n.Shared(language, "desktop.newProject.choose")).Clicked() { a.chooseNewProjectParent() } }) diff --git a/desktop/internal/workbench/search_everywhere_view.go b/desktop/internal/workbench/search_everywhere_view.go index f50f8bfb51..061300ef02 100644 --- a/desktop/internal/workbench/search_everywhere_view.go +++ b/desktop/internal/workbench/search_everywhere_view.go @@ -119,7 +119,8 @@ func (a *App) everywhereScopes(c ui.C, p *project, language i18n.Language) { } } ui.Spacer(c).Grow(1) - preview := ui.Button(c.Key("everywherePreview"), i18n.Shared(language, "native.showPreview")).Icon(icons.Eye).IconOnly().Ghost() + preview := ui.Button(c.Key("everywherePreview"), i18n.Shared(language, "native.showPreview")).Icon(icons.Eye).IconOnly().Ghost(). + Tooltip(i18n.Shared(language, "native.showPreview")) if v.preview { preview.Secondary() } @@ -145,7 +146,7 @@ func (a *App) everywhereFilter(c ui.C, p *project, language i18n.Language) { if v.scope == 5 { label = i18n.Shared(language, "native.searchOptions") } - button := ui.Button(c.Key("everywhereFilter"), label).Icon(icons.Settings).IconOnly().Ghost() + button := ui.Button(c.Key("everywhereFilter"), label).Icon(icons.Settings).IconOnly().Ghost().Tooltip(label) if v.filtered() { button.Secondary() } diff --git a/desktop/internal/workbench/search_replace_view.go b/desktop/internal/workbench/search_replace_view.go index 8cb54e966b..a349084c54 100644 --- a/desktop/internal/workbench/search_replace_view.go +++ b/desktop/internal/workbench/search_replace_view.go @@ -18,7 +18,7 @@ var searchReplaceID = tree.ID(shellPage, "project-search-replace") func (a *App) searchReplaceToggle(c ui.C) { v := &a.searchView t := a.text.Search - button := ui.Button(c.Key("replace-toggle"), t.ReplaceToggle).Icon(icons.ArrowLeftRight).IconOnly() + button := ui.Button(c.Key("replace-toggle"), t.ReplaceToggle).Icon(icons.ArrowLeftRight).IconOnly().Tooltip(t.ReplaceToggle) if !v.replaceOpen { button = button.Ghost() } diff --git a/desktop/internal/workbench/search_view.go b/desktop/internal/workbench/search_view.go index b02d29f05b..b12a2c1128 100644 --- a/desktop/internal/workbench/search_view.go +++ b/desktop/internal/workbench/search_view.go @@ -41,7 +41,7 @@ func (a *App) searchPanel(c ui.C) { a.searchReplaceToggle(c) a.searchOptions(c, language) refresh := ui.Button(c, i18n.Shared(language, "ui.refresh")).Icon(icons.RefreshCw).IconOnly().Ghost(). - Disabled(strings.TrimSpace(p.search.want.text) == "") + Disabled(strings.TrimSpace(p.search.want.text) == "").Tooltip(i18n.Shared(language, "ui.refresh")) if refresh.Clicked() { a.performed("workspace.search.refresh", surfaceButton) c.After(func() { a.refreshProjectSearch(p) }) @@ -81,7 +81,8 @@ func (a *App) searchPanel(c ui.C) { // expression switches. func (a *App) searchOptions(c ui.C, language i18n.Language) { v := &a.searchView - button := ui.Button(c, i18n.Shared(language, "native.searchOptions")).Icon(icons.Settings).IconOnly().Ghost() + button := ui.Button(c, i18n.Shared(language, "native.searchOptions")).Icon(icons.Settings).IconOnly().Ghost(). + Tooltip(i18n.Shared(language, "native.searchOptions")) if button.Clicked() { v.optionsOpen = !v.optionsOpen } diff --git a/desktop/internal/workbench/shell_view.go b/desktop/internal/workbench/shell_view.go index 8077db91c7..9315f90470 100644 --- a/desktop/internal/workbench/shell_view.go +++ b/desktop/internal/workbench/shell_view.go @@ -118,7 +118,8 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { if tabbed && p != nil { a.drawGitActions(c, p) } - hide := ui.Button(c, a.text.Panel.Hide).Icon(icons.Minus).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Shrink(0) + hide := ui.Button(c, a.text.Panel.Hide).Icon(icons.Minus).IconOnly().Ghost().Size(shellHideSize, shellHideSize).Shrink(0). + Tooltip(a.text.Panel.Hide) if hide.Clicked() { *hidden = s } diff --git a/desktop/internal/workbench/terminal_find.go b/desktop/internal/workbench/terminal_find.go index 9e501af8f6..a8dd0ec565 100644 --- a/desktop/internal/workbench/terminal_find.go +++ b/desktop/internal/workbench/terminal_find.go @@ -75,13 +75,15 @@ func (a *App) terminalFindBar(c ui.C, t *terminal) { if f.query != "" { ui.Text(c, label).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Shrink(0) } - if ui.Button(c.Key("previous"), words.FindPrevious).Icon(icons.ChevronUp).IconOnly().Ghost().Disabled(f.count == 0).Clicked() { + if ui.Button(c.Key("previous"), words.FindPrevious).Icon(icons.ChevronUp).IconOnly().Ghost().Disabled(f.count == 0). + Tooltip(words.FindPrevious).Clicked() { f.count, f.current = t.view.FindStep(-1) } - if ui.Button(c.Key("next"), words.FindNext).Icon(icons.ChevronDown).IconOnly().Ghost().Disabled(f.count == 0).Clicked() { + if ui.Button(c.Key("next"), words.FindNext).Icon(icons.ChevronDown).IconOnly().Ghost().Disabled(f.count == 0). + Tooltip(words.FindNext).Clicked() { f.count, f.current = t.view.FindStep(1) } - if ui.Button(c.Key("close"), words.FindClose).Icon(icons.X).IconOnly().Ghost().Clicked() { + if ui.Button(c.Key("close"), words.FindClose).Icon(icons.X).IconOnly().Ghost().Tooltip(words.FindClose).Clicked() { c.After(func() { a.closeTerminalFind(t) }) } }) diff --git a/desktop/internal/workbench/welcome_view.go b/desktop/internal/workbench/welcome_view.go index bbeb625931..9d7da19acb 100644 --- a/desktop/internal/workbench/welcome_view.go +++ b/desktop/internal/workbench/welcome_view.go @@ -79,7 +79,7 @@ func (a *App) welcomeSidebar(c ui.C) { }) ui.Spacer(c) ui.Row(c).PadSides(0, 14, 14, 14).Items(ui.Center).Gap(4).Children(func() { - if ui.Button(c, a.text.Welcome.Settings).Icon(icons.Settings).IconOnly().Ghost().Clicked() { + if ui.Button(c, a.text.Welcome.Settings).Icon(icons.Settings).IconOnly().Ghost().Tooltip(a.text.Welcome.Settings).Clicked() { c.After(func() { a.openSettings(surfaceButton) }) } // The welcome page has no status bar: the notices of a closed project are read here. diff --git a/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json index 5bca069be0..32247721ed 100644 --- a/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json +++ b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json @@ -2,7 +2,7 @@ "id": "viva-debug-tool-window-layout", "area": "运行与调试", "group": "调试器", - "capability": "调试工具窗口按 IntelliJ IDEA 布局:图标工具栏(重新运行、停止 | 继续、暂停、单步跳过、单步进入、单步跳出 | 查看断点、静音断点 | 更多);“线程和变量”“控制台”标签;左栏线程下拉与“函数 (文件:行)”栈帧,过滤帧淡色;右栏“对表达式求值(⏎)或添加监视(⇧⌘⏎)”输入框、监视行和带类型图标的“名称 = {类型} 值”变量树;“反汇编”标签无自带按钮,工具栏单步按指令执行,行首红点设置或移除指令断点,滚动到两端加载更多代码;“内存”标签可输入地址跳转(十六进制或十进制)、切换每行 8/16/32/64 字节与十六/十/八/二进制,并高亮目标字节;断点和异常断点在“查看断点”对话框中管理", + "capability": "调试工具窗口按 IntelliJ IDEA 布局:图标工具栏(重新运行、停止 | 继续、暂停、单步跳过、单步进入、单步跳出 | 查看断点、静音断点 | 更多),鼠标停在图标上显示操作名,右端状态后的调试适配器下拉在会话中仍可切换(供下次启动使用);“线程和变量”“控制台”标签;左栏线程下拉与“函数 (文件:行)”栈帧,过滤帧淡色;右栏“对表达式求值(⏎)或添加监视(⇧⌘⏎)”输入框(求值结果和失败原因折行完整显示)、监视行(失败原因折行完整显示)和带类型图标的“名称 = {类型} 值”变量树;“反汇编”标签左栏与“线程和变量”共用线程下拉、栈帧和分隔条,右栏为所选栈帧的指令,切换栈帧即显示该帧代码,无自带按钮,工具栏单步按指令执行,行首红点设置或移除指令断点,滚动到两端加载更多代码;“内存”标签可输入地址跳转(十六进制或十进制)、切换每行 8/16/32/64 字节与十六/十/八/二进制,并高亮目标字节;断点和异常断点在“查看断点”对话框中管理", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -42,6 +42,6 @@ ] }, "owner": "Debug", - "verification": "用 fixture 调试适配器暂停目标:工具栏各按钮按会话状态启用;重新运行停止当前会话并按首次启动方式重启;静音后断点保留并以禁用状态发送,取消静音按原样重发;更多菜单在树与 JSON 间切换并开关折叠过滤帧;回车求值保留输入,⇧⌘⏎(其他平台 Ctrl+Shift+Enter)加为监视并清空输入;栈帧右键菜单末尾可复制线程名、单独恢复线程;控制台显示适配器输出并在位于末尾时跟随新行;查看断点对话框可增删、启用禁用断点并选择异常断点;反汇编打开时以当前指令居中,点击行首红点增删指令断点,单步按指令执行;内存输入 8208 跳到 0x2010 并高亮该字节,切换每行 32 字节和二进制后版式保持,回到当前指令时保留版式。原生窗口视觉与真实 Go/LLDB 适配器验收 pending。", + "verification": "用 fixture 调试适配器暂停目标:工具栏各按钮按会话状态启用,每个图标的提示为其操作名;会话中适配器下拉仍在工具栏,状态只在下拉显示的不是该会话适配器时带上会话名;重新运行停止当前会话并按首次启动方式重启;静音后断点保留并以禁用状态发送,取消静音按原样重发;更多菜单在树与 JSON 间切换并开关折叠过滤帧;回车求值保留输入,求值和监视的长失败原因折行完整显示、不加省略号,有值的监视仍为单行;⇧⌘⏎(其他平台 Ctrl+Shift+Enter)加为监视并清空输入;栈帧右键菜单末尾可复制线程名、单独恢复线程;控制台显示适配器输出并在位于末尾时跟随新行;查看断点对话框可增删、启用禁用断点并选择异常断点;反汇编左侧显示栈帧、右侧显示指令,打开时以当前指令居中,选中无指令指针的栈帧显示无反汇编,选回后按该帧指令指针重新打开,点击行首红点增删指令断点,单步按指令执行;内存输入 8208 跳到 0x2010 并高亮该字节,切换每行 32 字节和二进制后版式保持,回到当前指令时保留版式。原生窗口视觉与真实 Go/LLDB 适配器验收 pending。", "notes": "线程下拉在只有一个线程时也显示。树与 JSON 的切换从变量区移到工具栏“更多”菜单。暂无布局切换按钮、异步栈、包名列(DebugStackFrame 无包字段);监视以独立行显示,尚未并入变量树。 内存暂不支持表达式输入(变量未携带 memoryReference);进制提供 16/10/8/2,未提供 4 进制。反汇编向前加载时以可见范围(含 2 行预排)中点保持位置,属近似。" } From 60473564a9cac4db33aefe85dcea138dac40e473 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Fri, 13 Nov 2026 13:13:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(desktop):=20#1794=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=20#1837=20=E5=AE=A1=E6=A0=B8=E6=84=8F=E8=A7=81=EF=BC=9A?= =?UTF-8?q?=E9=9D=99=E9=9F=B3=E8=A6=86=E7=9B=96=E6=89=80=E6=9C=89=E6=96=AD?= =?UTF-8?q?=E7=82=B9=E7=B1=BB=E5=9E=8B=E3=80=81=E5=86=85=E5=AD=98=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E4=B8=8E=E6=A0=87=E9=A2=98=E6=A0=8F=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E7=A7=BB=E5=85=A5=20Core=E3=80=81=E5=8F=8D=E6=B1=87=E7=BC=96?= =?UTF-8?q?=E7=BF=BB=E9=A1=B5=E5=A4=B1=E8=B4=A5=E5=8F=AF=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 静音断点:Core 新增 debug.setBreakpointsMuted,静音期间源码、异常、函数、指令和数据断点都以空集合发送;静音时启动的会话一创建就静音 - 内存窗口:读取范围、对齐、地址规范化和高亮位置由 Core 的 debug.planMemoryWindow / debug.locateMemoryWindow 计算;没有指令指针的栈帧也能读输入的地址 - 标题栏运行/调试:按下后做什么由 Core 的 runConfig.decideTitleAction 判定;没有构建插件负责的配置给出提示 - 反汇编:向前、向后翻页失败时显示重试 - PINNED_CORE_REVISION 升到 Lithe-core-rust #21 分支头 3350dd7 --- desktop/internal/core/debug_state.go | 65 +++++ desktop/internal/core/debug_state_test.go | 45 ++++ desktop/internal/core/run_config.go | 35 +++ desktop/internal/core/run_config_test.go | 33 +++ desktop/internal/i18n/shared.generated.go | 6 + desktop/internal/workbench/app.go | 1 + desktop/internal/workbench/debug.go | 5 +- .../internal/workbench/debug_breakpoints.go | 5 +- .../internal/workbench/debug_disassembly.go | 43 ++- desktop/internal/workbench/debug_kernel.go | 3 + desktop/internal/workbench/debug_memory.go | 131 +++++---- .../internal/workbench/debug_memory_test.go | 18 +- desktop/internal/workbench/debug_mute.go | 88 +++--- .../internal/workbench/debug_sections_view.go | 9 +- desktop/internal/workbench/debug_start.go | 21 +- .../internal/workbench/debug_toolbar_test.go | 255 ++++++++++++++++-- desktop/internal/workbench/title_run.go | 128 +++++---- desktop/internal/workbench/title_run_test.go | 19 ++ scripts/desktop/build-desktop-core.sh | 14 +- shared/fixtures/debug/memory-window-v1.json | 78 ++++++ .../run-configuration/title-action-v1.json | 217 +++++++++++++++ shared/i18n/locales/en-US.json | 3 + shared/i18n/locales/zh-CN.json | 3 + shared/i18n/messages.json | 24 ++ .../viva-debug-tool-window-layout.json | 4 +- .../features/viva-title-run-debug.json | 10 +- 26 files changed, 1056 insertions(+), 207 deletions(-) create mode 100644 shared/fixtures/debug/memory-window-v1.json create mode 100644 shared/fixtures/run-configuration/title-action-v1.json diff --git a/desktop/internal/core/debug_state.go b/desktop/internal/core/debug_state.go index 4887f32eab..6ebd8220fc 100644 --- a/desktop/internal/core/debug_state.go +++ b/desktop/internal/core/debug_state.go @@ -353,3 +353,68 @@ func (c *Client) SetDebugDataBreakpoints(ctx context.Context, sessionID string, } return update, nil } + +// SetDebugBreakpointsMuted mutes or unmutes every breakpoint kind of a session. Core keeps the +// stored sets and sends each kind empty while muted; a child session starts muted when its +// parent is. +func (c *Client) SetDebugBreakpointsMuted(ctx context.Context, sessionID string, muted bool) (DebugUpdate, error) { + var update DebugUpdate + if err := c.Execute(ctx, "debug.setBreakpointsMuted", struct { + SessionID string `json:"sessionId"` + Muted bool `json:"muted"` + }{sessionID, muted}, &update); err != nil { + return DebugUpdate{}, err + } + return update, nil +} + +// DebugReadMemoryArguments are the exact DAP readMemory arguments of a memory window. +type DebugReadMemoryArguments struct { + MemoryReference string `json:"memoryReference"` + Offset int64 `json:"offset"` + Count uint32 `json:"count"` +} + +// DebugMemoryWindow is one planned readMemory window. The host keeps it and passes it back +// with the adapter's reply. +type DebugMemoryWindow struct { + // Address is what the address field shows: a number in lowercase 0x hexadecimal, any + // other reference as given. + Address string `json:"address"` + Request DebugReadMemoryArguments `json:"request"` +} + +// DebugMemoryLocation is where one reply's bytes sit. +type DebugMemoryLocation struct { + // Base is the first returned byte's address in lowercase 0x hexadecimal; empty when + // neither the reply nor the window gives a number. + Base string `json:"base,omitempty"` + // Mark is the index of the byte at the address read; nil when the reply does not hold it. + Mark *uint32 `json:"mark,omitempty"` +} + +// PlanDebugMemoryWindow places the memory view's readMemory window at an address the user +// typed or at a frame's instruction pointer. +func (c *Client) PlanDebugMemoryWindow(ctx context.Context, address string) (DebugMemoryWindow, error) { + var window DebugMemoryWindow + if err := c.Execute(ctx, "debug.planMemoryWindow", struct { + Address string `json:"address"` + }{address}, &window); err != nil { + return DebugMemoryWindow{}, err + } + return window, nil +} + +// LocateDebugMemoryWindow finds where a reply's bytes start and which of them is at the +// window's address. start is the reply's address, empty when the adapter gave none. +func (c *Client) LocateDebugMemoryWindow(ctx context.Context, window DebugMemoryWindow, start string, length uint32) (DebugMemoryLocation, error) { + var location DebugMemoryLocation + if err := c.Execute(ctx, "debug.locateMemoryWindow", struct { + Window DebugMemoryWindow `json:"window"` + Start string `json:"start,omitempty"` + Length uint32 `json:"length"` + }{window, start, length}, &location); err != nil { + return DebugMemoryLocation{}, err + } + return location, nil +} diff --git a/desktop/internal/core/debug_state_test.go b/desktop/internal/core/debug_state_test.go index e0e8a60932..a7239e5e81 100644 --- a/desktop/internal/core/debug_state_test.go +++ b/desktop/internal/core/debug_state_test.go @@ -192,3 +192,48 @@ func TestDebugStartOrContinueFollowsCore(t *testing.T) { } } } + +// TestDebugMemoryWindowFollowsTheContractFixture plans each scenario's window and locates +// each reply through the typed wrappers. +func TestDebugMemoryWindowFollowsTheContractFixture(t *testing.T) { + var fixture struct { + Scenarios []struct { + Name string `json:"name"` + Address string `json:"address"` + Window DebugMemoryWindow `json:"window"` + Replies []struct { + Start string `json:"start"` + Length uint32 `json:"length"` + Expected DebugMemoryLocation `json:"expected"` + } `json:"replies"` + } `json:"scenarios"` + } + if err := json.Unmarshal(readDebugFixture(t, "memory-window-v1.json"), &fixture); err != nil { + t.Fatal(err) + } + ctx := debugContext(t) + client := NewClient() + for _, scenario := range fixture.Scenarios { + t.Run(scenario.Name, func(t *testing.T) { + window, err := client.PlanDebugMemoryWindow(ctx, scenario.Address) + if err != nil { + t.Fatal(err) + } + if window != scenario.Window { + t.Fatalf("window = %+v, want %+v", window, scenario.Window) + } + for index, reply := range scenario.Replies { + got, err := client.LocateDebugMemoryWindow(ctx, window, reply.Start, reply.Length) + if err != nil { + t.Fatalf("reply %d: %v", index, err) + } + if !reflect.DeepEqual(got, reply.Expected) { + t.Fatalf("reply %d: got %+v, want %+v", index, got, reply.Expected) + } + } + }) + } + if _, err := client.PlanDebugMemoryWindow(ctx, " "); err == nil { + t.Fatal("a blank address was planned") + } +} diff --git a/desktop/internal/core/run_config.go b/desktop/internal/core/run_config.go index f6bd806509..46c32f655f 100644 --- a/desktop/internal/core/run_config.go +++ b/desktop/internal/core/run_config.go @@ -79,6 +79,41 @@ func (c *Client) ResolveRunConfigurations(ctx context.Context, root string) (Run return result, err } +// TitleConfiguration describes the configuration the title bar shows, as far as starting it +// depends on. Kind is "unsupported", "instanceMissing", "modelNotLoaded" (with Failed) or +// "modelLoaded" (with Debuggable). +type TitleConfiguration struct { + Kind string `json:"kind"` + Failed *bool `json:"failed,omitempty"` + Debuggable *bool `json:"debuggable,omitempty"` +} + +// TitleActionFacts are the facts one title bar Run or Debug decision depends on. +type TitleActionFacts struct { + // Action is "run" or "debug". + Action string `json:"action"` + // Trigger is "press", or "settled" when the host asks again for a press it kept. + Trigger string `json:"trigger"` + CurrentFileChosen bool `json:"currentFileChosen"` + // Settled says detection answered, no model is loading and the configurations were + // resolved since. + Settled bool `json:"settled"` + Configuration *TitleConfiguration `json:"configuration,omitempty"` +} + +// DecideTitleAction asks Core what a title bar press does. The answer is "currentFile", +// "wait", "loadModel", "unsupported", "targetMissing", "modelFailed", "run", "debug" or +// "notDebuggable". +func (c *Client) DecideTitleAction(ctx context.Context, facts TitleActionFacts) (string, error) { + var decision struct { + Kind string `json:"kind"` + } + if err := c.Execute(ctx, "runConfig.decideTitleAction", facts, &decision); err != nil { + return "", err + } + return decision.Kind, nil +} + // RunLaunchOptions are the typed launch options of a build provider run // (buildProviders 10): the user's resolved choices, passed to the provider's // prepareRun and to the decoder of its answer. diff --git a/desktop/internal/core/run_config_test.go b/desktop/internal/core/run_config_test.go index af1080113d..f8cd439ab9 100644 --- a/desktop/internal/core/run_config_test.go +++ b/desktop/internal/core/run_config_test.go @@ -100,3 +100,36 @@ func TestRunConfigurationOptionsRoundTrip(t *testing.T) { t.Fatalf("argument text = %q, %v", texts, err) } } + +// TestTitleActionsFollowTheContractFixture replays every title bar case through the typed +// wrapper. +func TestTitleActionsFollowTheContractFixture(t *testing.T) { + data, err := os.ReadFile(filepath.Join("..", "..", "..", "shared", "fixtures", "run-configuration", "title-action-v1.json")) + if err != nil { + t.Fatal(err) + } + var fixture struct { + Cases []struct { + Name string `json:"name"` + Request TitleActionFacts `json:"request"` + Expected struct { + Kind string `json:"kind"` + } `json:"expected"` + } `json:"cases"` + } + if err := json.Unmarshal(data, &fixture); err != nil { + t.Fatal(err) + } + client := NewClient() + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + for _, testCase := range fixture.Cases { + got, err := client.DecideTitleAction(ctx, testCase.Request) + if err != nil { + t.Fatalf("%s: %v", testCase.Name, err) + } + if got != testCase.Expected.Kind { + t.Fatalf("%s: decision = %q, want %q", testCase.Name, got, testCase.Expected.Kind) + } + } +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 850b6e14d6..e28b761de4 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -260,6 +260,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.consoleEmpty": "The debug session's output appears here.", "desktop.debug.continue": "Continue", "desktop.debug.disassembly": "Disassembly", + "desktop.debug.disassemblyRetry": "Retry", "desktop.debug.editValue": "New value", "desktop.debug.evaluateFailed": "The expression could not be evaluated", "desktop.debug.evaluatePlaceholder": "Evaluate expression ({evaluate}) or add a watch ({watch})", @@ -283,6 +284,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.memoryRadixHex": "Hexadecimal", "desktop.debug.memoryRadixOctal": "Octal", "desktop.debug.memoryRowBytes": "{bytes} bytes per row", + "desktop.debug.memoryTypeAddress": "The selected frame has no instruction address. Type an address above to read memory there.", "desktop.debug.memoryUnreadableBytes": "Unreadable bytes: {bytes}", "desktop.debug.noAdapters": "The installed plugins declare no debug adapter this client can start.", "desktop.debug.noBreakpoints": "No breakpoints", @@ -1389,6 +1391,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tests.timedOut": "Tests timed out", "desktop.title.branchMenu": "Branch menu", "desktop.title.cloneLater": "Cloning repositories comes later", + "desktop.title.configurationNotStartable": "{name} cannot be started: no build plugin runs it.", "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", "desktop.title.keymapLater": "The keymap page comes later", "desktop.title.logsUnavailable": "The log could not be opened when Lithe started", @@ -2603,6 +2606,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.consoleEmpty": "调试会话的输出会显示在这里。", "desktop.debug.continue": "继续", "desktop.debug.disassembly": "反汇编", + "desktop.debug.disassemblyRetry": "重试", "desktop.debug.editValue": "新值", "desktop.debug.evaluateFailed": "无法对该表达式求值", "desktop.debug.evaluatePlaceholder": "对表达式求值({evaluate})或添加监视({watch})", @@ -2626,6 +2630,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.debug.memoryRadixHex": "十六进制", "desktop.debug.memoryRadixOctal": "八进制", "desktop.debug.memoryRowBytes": "每行 {bytes} 字节", + "desktop.debug.memoryTypeAddress": "选中的栈帧没有指令地址,请在上方输入要读取的地址", "desktop.debug.memoryUnreadableBytes": "无法读取的字节:{bytes}", "desktop.debug.noAdapters": "已安装的插件没有声明此客户端能启动的调试适配器。", "desktop.debug.noBreakpoints": "没有断点", @@ -3732,6 +3737,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tests.timedOut": "测试超时", "desktop.title.branchMenu": "分支菜单", "desktop.title.cloneLater": "克隆仓库稍后提供", + "desktop.title.configurationNotStartable": "无法启动 {name}:没有构建插件负责运行它。", "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", "desktop.title.keymapLater": "快捷键页稍后提供", "desktop.title.logsUnavailable": "Lithe 启动时未能打开日志", diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 0c425831c5..f93098df64 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -93,6 +93,7 @@ type Kernel interface { NormalizeSteppingFilters(ctx context.Context, adapterID string, filters core.DebugSteppingFilters) (core.DebugSteppingFilters, error) GenerateRunConfigurations(ctx context.Context, root, cacheDirectory string, providerRuns json.RawMessage) (core.RunConfigGeneration, error) ResolveRunConfigurations(ctx context.Context, root string) (core.RunConfigResolution, error) + DecideTitleAction(ctx context.Context, facts core.TitleActionFacts) (string, error) ProviderLaunchInputs(ctx context.Context, root, configurationID, providerRoot string) (core.RunProviderLaunchInputs, error) UpdateRunConfigurationOptions(ctx context.Context, edit core.RunOptionsEdit) (string, error) RunArgumentText(ctx context.Context, lists [][]string) ([]string, error) diff --git a/desktop/internal/workbench/debug.go b/desktop/internal/workbench/debug.go index 3c7c2e5e84..ae7308b35e 100644 --- a/desktop/internal/workbench/debug.go +++ b/desktop/internal/workbench/debug.go @@ -263,6 +263,9 @@ type debugSession struct { cancel context.CancelFunc // stopped is set when Stop or project close already took the session apart. stopped atomic.Bool + // muted is the project's mute switch as this session should have it; written on the + // window thread, read by the operations that tell Core (see debug_mute.go). + muted atomic.Bool // exitCode is the debuggee's exit code from the terminated event, when the // adapter reported one. ended, when set, receives it once the session is released. exitCode atomic.Pointer[int] @@ -733,7 +736,7 @@ func (a *App) sendSessionBreakpoints(p *project, session *debugSession, path str if session == nil || session.stopped.Load() { return } - points := sessionSourceBreakpoints(p.debug.breakpoints[path], p.debug.muted) + points := sourceBreakpoints(p.debug.breakpoints[path]) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { // A session still starting takes the change once Core has it; one that never // got that far has no breakpoints to replace. diff --git a/desktop/internal/workbench/debug_breakpoints.go b/desktop/internal/workbench/debug_breakpoints.go index b5745aedb1..dec9295402 100644 --- a/desktop/internal/workbench/debug_breakpoints.go +++ b/desktop/internal/workbench/debug_breakpoints.go @@ -180,7 +180,7 @@ func (a *App) sendFunctionBreakpoints(p *project) { return } session := p.debug.activeSession() - breakpoints := unlessMuted(slices.Clone(p.debug.functionBreakpoints), p.debug.muted) + breakpoints := slices.Clone(p.debug.functionBreakpoints) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() @@ -247,7 +247,7 @@ func (a *App) sendInstructionBreakpoints(p *project) { return } session := p.debug.activeSession() - breakpoints := unlessMuted(slices.Clone(p.debug.instructionBreakpoints), p.debug.muted) + breakpoints := slices.Clone(p.debug.instructionBreakpoints) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() @@ -339,7 +339,6 @@ func (a *App) sendDataBreakpoints(p *project) { for _, breakpoint := range p.debug.dataBreakpoints { breakpoints = append(breakpoints, breakpoint.DebugDataBreakpoint) } - breakpoints = unlessMuted(breakpoints, p.debug.muted) a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { session.operationMu.Lock() defer session.operationMu.Unlock() diff --git a/desktop/internal/workbench/debug_disassembly.go b/desktop/internal/workbench/debug_disassembly.go index 2569297e4f..60885c8eaa 100644 --- a/desktop/internal/workbench/debug_disassembly.go +++ b/desktop/internal/workbench/debug_disassembly.go @@ -31,6 +31,10 @@ type debugDisassembly struct { // beforeDone and afterDone record that Core found the end of the code in // that direction. beforeDone, afterDone bool + // failedEdge is the direction, "before" or "after", whose last load failed. Scrolling to + // that edge no longer loads it, so a request that keeps failing is not sent again on every + // paint; the Retry button beside the failure asks once more. + failedEdge string // opening is set while the first window is laid out for the first time. That layout // takes the rows at an estimated height and the window's height for the list's, so the // rows it reports say nothing about where the user scrolled. @@ -102,13 +106,35 @@ func (a *App) loadDisassemblyAtEdges(p *project) { } end := len(w.rows) - 1 switch { - case first == 0 && last < end && !w.beforeDone: + case first == 0 && last < end && !w.beforeDone && w.failedEdge != "before": a.loadDisassemblyEdge(p, "before") - case last >= end && first > 0 && !w.afterDone: + case last >= end && first > 0 && !w.afterDone && w.failedEdge != "after": a.loadDisassemblyEdge(p, "after") } } +// retryDisassembly asks again for what failed last: the edge whose load failed, or the first +// window when no rows arrived. +func (a *App) retryDisassembly(p *project) { + w := &p.debug.disassembly + edge := w.failedEdge + w.failure, w.failedEdge = "", "" + if edge == "" || len(w.rows) == 0 { + a.loadDisassembly(p) + return + } + a.loadDisassemblyEdge(p, edge) +} + +// fail ends a load with the adapter's or Core's message. A failed edge stops loading +// by itself until the user retries it. +func (w *debugDisassembly) fail(direction, message string) { + w.loading, w.failure = false, message + if direction == "before" || direction == "after" { + w.failedEdge = direction + } +} + // planDisassembly asks Core for the first request of a window, then follows // Core's steps until it answers with a page or a failure. func (a *App) planDisassembly(p *project, direction, reference string, count, before uint32) { @@ -124,7 +150,7 @@ func (a *App) planDisassembly(p *project, direction, reference string, count, be return } if err != nil { - p.debug.disassembly.loading, p.debug.disassembly.failure = false, err.Error() + p.debug.disassembly.fail(direction, err.Error()) return } a.fetchDisassembly(p, fetch) @@ -193,7 +219,7 @@ func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, re return } if err != nil { - d.loading, d.failure = false, err.Error() + d.fail(fetch.Direction, err.Error()) return } switch step.Kind { @@ -204,7 +230,12 @@ func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, re } d.loading = false case "page": - d.loading, d.failure = false, "" + d.loading = false + // A page clears the failure it answers; a failure of the other edge stays + // shown, and that edge stays paused, until it is retried. + if d.failedEdge == "" || d.failedEdge == fetch.Direction { + d.failure, d.failedEdge = "", "" + } kept := make([]core.DebugInstruction, 0, len(step.Keep)) // keep indexes the reply as sent: padding stays in the array, and Core // only leaves its indexes out of keep. @@ -237,7 +268,7 @@ func (a *App) reduceDisassembly(p *project, fetch core.DebugDisassemblyFetch, re } } default: - d.loading, d.failure = false, step.Message + d.fail(fetch.Direction, step.Message) } } }) diff --git a/desktop/internal/workbench/debug_kernel.go b/desktop/internal/workbench/debug_kernel.go index 3bb8c6e02a..7f91904a48 100644 --- a/desktop/internal/workbench/debug_kernel.go +++ b/desktop/internal/workbench/debug_kernel.go @@ -16,6 +16,9 @@ type debugStateKernel interface { DebugDataBreakpointInfo(ctx context.Context, sessionID, operationID, name string, variablesReference int64) (core.DebugUpdate, error) SetDebugDataBreakpoints(ctx context.Context, sessionID string, breakpoints []core.DebugDataBreakpoint) (core.DebugUpdate, error) SetDebugFunctionBreakpoints(ctx context.Context, sessionID string, breakpoints []core.DebugFunctionBreakpoint) (core.DebugUpdate, error) + SetDebugBreakpointsMuted(ctx context.Context, sessionID string, muted bool) (core.DebugUpdate, error) + PlanDebugMemoryWindow(ctx context.Context, address string) (core.DebugMemoryWindow, error) + LocateDebugMemoryWindow(ctx context.Context, window core.DebugMemoryWindow, start string, length uint32) (core.DebugMemoryLocation, error) SetDebugVariable(ctx context.Context, sessionID, operationID string, variablesReference int64, name, value string) (core.DebugUpdate, error) DebugStartDebuggingResponse(ctx context.Context, sessionID, requestID string, success bool, message string) (core.DebugUpdate, error) DebugStartOrContinue(ctx context.Context, active, paused, requestPending bool) (core.DebugStartAction, error) diff --git a/desktop/internal/workbench/debug_memory.go b/desktop/internal/workbench/debug_memory.go index 59b88e3974..7ab784abf1 100644 --- a/desktop/internal/workbench/debug_memory.go +++ b/desktop/internal/workbench/debug_memory.go @@ -14,11 +14,6 @@ import ( ) const ( - // debugMemoryBytes is one readMemory window. The host never asks for more than one window. - debugMemoryBytes = 1024 - // debugMemoryAlign is the multiple a window starts on when the address read at is a number, - // so the rows of every bytes-per-row choice start on a multiple of their width. - debugMemoryAlign = 64 // debugMemoryDefaultColumns is how many bytes one row shows until the user chooses. debugMemoryDefaultColumns = 16 // debugMemoryAddressWidth is the width of the address field and debugMemoryPickerWidth @@ -36,12 +31,17 @@ var ( debugMemoryRadixChoices = []int{16, 10, 8, 2} ) -// debugMemory is the read-only memory window of the selected frame. Core owns -// the readMemory request and capability checks; the host decodes the base64 -// bytes and lays them out. +// debugMemory is the read-only memory window of the selected frame. Core places the window, +// owns the readMemory request and capability checks, and finds where the reply's bytes start +// and which of them is at the address read; the host decodes the base64 bytes and lays them out. type debugMemory struct { - bytes []byte - address string + bytes []byte + // window is the readMemory window Core placed at the address read, echoed back to it with + // the reply. + window core.DebugMemoryWindow + // base is the first byte's address as Core writes it, lowercase 0x hexadecimal; empty when + // no number gives it, and rows are labelled with their offset in the window. + base string // at is the address the user asked to read, typed in the field or from the disassembly's // menu; empty reads at the selected frame's instruction pointer. Like every reference of // the adapter it holds only until the debuggee runs again. @@ -80,19 +80,26 @@ func (m *debugMemory) layout() (columns, radix int) { return columns, radix } -// canReadDebugMemory reports whether the paused frame has an address the adapter -// can read. It mirrors Core's checks so the section never asks for a refusal. +// canReadDebugMemory reports whether the memory window can read at all: the session is paused +// on an adapter that reads memory. It mirrors Core's checks so the section never asks for a +// refusal. Where it reads is debugMemoryReference; a frame without an instruction pointer still +// reads at an address the user types. func canReadDebugMemory(d *debugState) bool { - return d.activeSession() != nil && d.state == "paused" && d.capabilities != nil && d.capabilities.SupportsReadMemoryRequest && - debugMemoryReference(d) != "" + return d.activeSession() != nil && d.state == "paused" && d.capabilities != nil && d.capabilities.SupportsReadMemoryRequest } // debugMemoryReference is the address the memory window reads: the one asked for, or else -// the selected frame's instruction pointer. +// the selected frame's instruction pointer. Empty when neither is known. func debugMemoryReference(d *debugState) string { if d.memory.at != "" { return d.memory.at } + return debugFrameInstruction(d) +} + +// debugFrameInstruction is the selected frame's instruction pointer, empty for a frame the +// adapter gave none. +func debugFrameInstruction(d *debugState) string { if d.vars.frame >= 0 && d.vars.frame < len(d.frames) { return d.frames[d.vars.frame].InstructionPointerReference } @@ -109,41 +116,46 @@ func (a *App) readDebugMemoryAt(p *project, address string) { } d.memory.reset() d.memory.at = strings.TrimSpace(address) - if value, ok := parseDebugAddress(d.memory.at); ok { - // A number is sent as the protocol writes addresses, so a decimal one reads as typed. - d.memory.at = fmt.Sprintf("0x%x", value) - } d.section = debugSectionMemory a.loadDebugMemory(p) } -// loadDebugMemory reads one bounded window at the address asked for. When that address is a -// number the window starts a little before it, on a multiple of debugMemoryAlign, so the -// address sits in its row as it would in a full dump; an opaque reference is read from where -// it points. Core rejects a request the adapter cannot serve; the failure stays in the section. +// loadDebugMemory reads one bounded window at the address asked for, placed by Core: a number +// is read from a little before it so the address sits in its row as it would in a full dump, +// an opaque reference from where it points. Core rejects an address or a request the adapter +// cannot serve; the failure stays in the section. func (a *App) loadDebugMemory(p *project) { d := &p.debug if d.memory.loading { return } - if !canReadDebugMemory(d) { + reference := debugMemoryReference(d) + if !canReadDebugMemory(d) || reference == "" { // The frame changed between the paint that asked and this call; let the // next paint ask again instead of leaving the section waiting forever. d.memory.requested = false return } - reference := debugMemoryReference(d) - target, numeric := parseDebugAddress(reference) - lead := int64(0) - if numeric { - lead = int64(target % debugMemoryAlign) + m := &d.memory + m.requested = false + ctx, cancel := context.WithTimeout(p.ctx, kernelCallTimeout) + window, err := a.kernel.PlanDebugMemoryWindow(ctx, reference) + cancel() + if err != nil { + m.failure = err.Error() + return } - d.memory.loading, d.memory.requested, d.memory.failure = true, false, "" - offset, count := -lead, int64(debugMemoryBytes) + if m.at != "" { + // A typed number is shown and read as Core writes it, so a decimal one reads as typed. + m.at = window.Address + } + m.window, m.loading, m.failure = window, true, "" + request := window.Request + offset, count := request.Offset, int64(request.Count) a.debugOperation(p, "readMemory", func(ctx context.Context, session *debugSession, operationID string) (core.DebugUpdate, error) { return a.kernel.InspectDebug(ctx, core.DebugInspectRequest{ SessionID: session.id, OperationID: operationID, Kind: "readMemory", - MemoryReference: reference, Offset: &offset, Count: &count, + MemoryReference: request.MemoryReference, Offset: &offset, Count: &count, }) }, debugOperationHandlers{done: func(a *App, result core.DebugOperationResult) { m := &p.debug.memory @@ -157,25 +169,20 @@ func (a *App) loadDebugMemory(p *project) { m.failure = err.Error() return } - m.bytes, m.unreadable, m.failure = data, result.UnreadableBytes, "" - m.address = result.Address - if m.address == "" { - m.address = reference - } - // The adapter says where the bytes start; without a number for it, the bytes start - // where they were asked from. - m.mark = int(lead) - if base, ok := parseDebugAddress(result.Address); ok && numeric { - m.mark = -1 - if target >= base && target-base < uint64(len(data)) { - m.mark = int(target - base) - } + ctx, cancel := context.WithTimeout(p.ctx, kernelCallTimeout) + location, err := a.kernel.LocateDebugMemoryWindow(ctx, window, result.Address, uint32(len(data))) + cancel() + if err != nil { + m.failure = err.Error() + return } - if m.mark >= len(data) { - m.mark = -1 + m.bytes, m.unreadable, m.failure = data, result.UnreadableBytes, "" + m.base, m.mark = location.Base, -1 + if location.Mark != nil { + m.mark = int(*location.Mark) } if m.input == "" { - m.input = reference + m.input = window.Address } m.version++ if m.mark >= 0 { @@ -188,15 +195,14 @@ func (a *App) loadDebugMemory(p *project) { }}) } -// parseDebugAddress reads an address as the Debug Adapter Protocol writes one: hexadecimal -// after 0x, decimal otherwise. Anything else is an opaque reference and reports false. -func parseDebugAddress(text string) (uint64, bool) { - text = strings.TrimSpace(text) - base := 10 - if len(text) > 2 && (text[:2] == "0x" || text[:2] == "0X") { - text, base = text[2:], 16 +// debugMemoryBase reads the first byte's address Core gave, lowercase 0x hexadecimal, for the +// row labels; false when Core gave none. +func debugMemoryBase(base string) (uint64, bool) { + digits, ok := strings.CutPrefix(base, "0x") + if !ok { + return 0, false } - value, err := strconv.ParseUint(text, base, 64) + value, err := strconv.ParseUint(digits, 16, 64) return value, err == nil } @@ -282,16 +288,22 @@ func (a *App) debugMemoryView(c ui.C, p *project) { a.panelMessage(c, t.NoMemory, a.colors.Subtle) return } - if len(m.bytes) == 0 && !m.loading && !m.requested && m.failure == "" { + reference := debugMemoryReference(d) + if len(m.bytes) == 0 && !m.loading && !m.requested && m.failure == "" && reference != "" { // Ask on this paint: the answer is a background operation, and a deferred // callback can be dropped when the next update repaints the section first. m.requested = true a.loadDebugMemory(p) } a.debugMemoryToolbar(c, p) + if reference == "" { + // The frame has no instruction pointer to start from; the address field reads anywhere. + a.panelMessage(c, i18n.Shared(a.language(), "desktop.debug.memoryTypeAddress"), a.colors.Subtle) + return + } columns, radix := m.layout() if m.shown != m.version { - base, absolute := parseDebugAddress(m.address) + base, absolute := debugMemoryBase(m.base) m.lines = debugMemoryLines(m.bytes, base, absolute, columns, radix, m.mark) m.shown = m.version } @@ -350,7 +362,8 @@ func (a *App) debugMemoryToolbar(c ui.C, p *project) { p.debug.memory.input = p.debug.memory.at }) } - if _, clicked := a.toolIconButton(c.Part("memoryCurrent"), t.Reload, icons.Locate, false, m.loading); clicked { + // Going back to the current instruction needs a frame that has one. + if _, clicked := a.toolIconButton(c.Part("memoryCurrent"), t.Reload, icons.Locate, false, m.loading || debugFrameInstruction(d) == ""); clicked { c.After(func() { a.performed("debug.memory.currentInstruction", surfaceButton) a.readDebugMemoryAt(p, "") diff --git a/desktop/internal/workbench/debug_memory_test.go b/desktop/internal/workbench/debug_memory_test.go index 300d8ee589..d5d11b1169 100644 --- a/desktop/internal/workbench/debug_memory_test.go +++ b/desktop/internal/workbench/debug_memory_test.go @@ -58,15 +58,17 @@ func TestDebugMemoryLinesFormatOffsetsRadixAndText(t *testing.T) { } } -func TestParseDebugAddressReadsHexAndDecimal(t *testing.T) { - for text, want := range map[string]uint64{"0x1000": 0x1000, " 0X1f ": 0x1f, "4096": 4096} { - if got, ok := parseDebugAddress(text); !ok || got != want { - t.Fatalf("parse %q = %d %v, want %d", text, got, ok, want) +// Core writes the first byte's address in lowercase 0x hexadecimal; anything else labels the +// rows with their offsets. +func TestDebugMemoryBaseReadsCoreAddresses(t *testing.T) { + for text, want := range map[string]uint64{"0x1000": 0x1000, "0x0": 0, "0xffffffffffffffc0": 0xffffffffffffffc0} { + if got, ok := debugMemoryBase(text); !ok || got != want { + t.Fatalf("base %q = %d %v, want %d", text, got, ok, want) } } - for _, text := range []string{"", "0x", "frame:1", "-4"} { - if _, ok := parseDebugAddress(text); ok { - t.Fatalf("parse %q succeeded; an opaque reference is not a number", text) + for _, text := range []string{"", "0x", "frame:1"} { + if _, ok := debugMemoryBase(text); ok { + t.Fatalf("base %q gave a number; rows are labelled with offsets", text) } } } @@ -94,7 +96,7 @@ func TestDebugMemoryReadsWithoutComputedAddresses(t *testing.T) { h.app.loadDebugMemory(p) awaitStateWithin(t, h, 20*time.Second, "the memory window", func() bool { - return len(p.debug.memory.bytes) == 4 && p.debug.memory.address == "0x1000" + return len(p.debug.memory.bytes) == 4 && p.debug.memory.base == "0x1000" }) if p.debug.memory.unreadable != 2 { t.Fatalf("unreadable bytes = %d, want 2", p.debug.memory.unreadable) diff --git a/desktop/internal/workbench/debug_mute.go b/desktop/internal/workbench/debug_mute.go index 45186b5c53..4e73940c44 100644 --- a/desktop/internal/workbench/debug_mute.go +++ b/desktop/internal/workbench/debug_mute.go @@ -1,36 +1,18 @@ package workbench -import "github.com/1lck/Lithe-IDEA/desktop/internal/core" +import "context" // Muting is the Debug window's switch that keeps every breakpoint the user set but stops the -// adapters from stopping on any of them. The breakpoints stay stored and shown, faded; what -// changes is what each session is sent: every source line goes as disabled, which Core leaves -// out, and the function, instruction and data breakpoints go as empty lists. Unmuting sends -// the stored breakpoints again. +// adapters from stopping on any of them. The breakpoints stay stored and shown, faded, and the +// host keeps sending every change as usual; Core keeps each session's sets and, while the +// session is muted, sends every kind empty: source, exception, function, instruction and data +// breakpoints alike. Unmuting has Core send the stored sets again. +// +// The switch belongs to the project, so every running session follows it, and a session that +// starts while it is on starts muted (see startDebugSession). A child session started through +// startDebugging inherits its parent's state in Core. -// sessionSourceBreakpoints is what a session is sent for one file's breakpoints: the lines as -// stored, or all of them disabled while the breakpoints are muted. -func sessionSourceBreakpoints(lines []debugBreakpoint, muted bool) []core.DebugSourceBreakpoint { - points := sourceBreakpoints(lines) - if muted { - for index := range points { - points[index].Enabled = false - } - } - return points -} - -// unlessMuted is list, or nothing while the breakpoints are muted. -func unlessMuted[T any](list []T, muted bool) []T { - if muted { - return nil - } - return list -} - -// toggleMuteBreakpoints mutes or unmutes every breakpoint and sends what the sessions should -// now stop on. A kind of breakpoint the user never set is not sent, so an adapter that serves -// no such kind is never asked to. +// toggleMuteBreakpoints mutes or unmutes every breakpoint of every running session. func (a *App) toggleMuteBreakpoints(p *project) { if p == nil { return @@ -38,19 +20,43 @@ func (a *App) toggleMuteBreakpoints(p *project) { d := &p.debug d.muted = !d.muted a.performed("debug.muteBreakpoints", surfaceButton) - if len(d.sessions) == 0 { - return - } - for path := range d.breakpoints { - a.sendDebugBreakpoints(p, path) - } - if len(d.functionBreakpoints) > 0 { - a.sendFunctionBreakpoints(p) + for _, session := range d.sessions { + session.muted.Store(d.muted) + a.sendSessionMuted(p, session) } - if len(d.instructionBreakpoints) > 0 { - a.sendInstructionBreakpoints(p) - } - if len(d.dataBreakpoints) > 0 { - a.sendDataBreakpoints(p) +} + +// sendSessionMuted tells Core the session's current mute state. Each send reads the state when +// it runs, under the session's operation lock, so the last send carries the last toggle however +// the sends are scheduled; Core sends nothing for a state it already has. +func (a *App) sendSessionMuted(p *project, session *debugSession) { + if session == nil || session.stopped.Load() { + return } + a.background(p, debugOperationTimeout, func(ctx context.Context) func(*App) { + // A session still starting applies the state itself once Core has it; one that never + // got that far has nothing to mute. + select { + case <-session.startupDone: + case <-ctx.Done(): + return nil + } + if !session.created { + return nil + } + session.operationMu.Lock() + defer session.operationMu.Unlock() + if session.stopped.Load() { + return nil + } + update, err := a.kernel.SetDebugBreakpointsMuted(ctx, session.id, session.muted.Load()) + if err != nil { + return func(a *App) { a.finishDebugError(p, session, err) } + } + if err := session.writeFrames(update.OutboundFrames); err != nil { + return func(a *App) { a.finishDebugError(p, session, err) } + } + a.postDebugUpdate(p, session, update) + return nil + }) } diff --git a/desktop/internal/workbench/debug_sections_view.go b/desktop/internal/workbench/debug_sections_view.go index 29972242ab..b9bc0428a8 100644 --- a/desktop/internal/workbench/debug_sections_view.go +++ b/desktop/internal/workbench/debug_sections_view.go @@ -318,8 +318,15 @@ func (a *App) debugInstructions(c ui.C, p *project) { a.loadDisassembly(p) } if w.failure != "" { - ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).PadX(10).Children(func() { + ui.Row(c).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(8).PadX(10).Children(func() { ui.Text(c, w.failure).Shrink(1).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger).Ellipsis() + // A failed load is not asked again by itself; this asks once more. + if ui.Button(c.Part("disassembly-retry"), i18n.Shared(a.language(), "desktop.debug.disassemblyRetry")).Small().Outline().Disabled(w.loading).Clicked() { + c.After(func() { + a.performed("debug.disassembly.retry", surfaceButton) + a.retryDisassembly(p) + }) + } }) } if len(w.rows) == 0 { diff --git a/desktop/internal/workbench/debug_start.go b/desktop/internal/workbench/debug_start.go index 94161d7871..7a905bc7d8 100644 --- a/desktop/internal/workbench/debug_start.go +++ b/desktop/internal/workbench/debug_start.go @@ -403,9 +403,7 @@ func (a *App) beginDebug(p *project, start debugStart) { } else if declared, ok := core.DeclaredSteppingFilters(adapter.Declaration.Features, adapter.Declaration.Defaults); ok { hideFiltered = declared.HideFilteredStackFrames } - // Muted breakpoints are kept but not sent, so the new session stops on none of them. - muted := p.debug.muted - functionBreakpoints := unlessMuted(slices.Clone(p.debug.functionBreakpoints), muted) + functionBreakpoints := slices.Clone(p.debug.functionBreakpoints) // A data breakpoint whose identity does not persist ends with the session that resolved it. dataBreakpoints := make([]core.DebugDataBreakpoint, 0, len(p.debug.dataBreakpoints)) for _, breakpoint := range p.debug.dataBreakpoints { @@ -413,7 +411,6 @@ func (a *App) beginDebug(p *project, start debugStart) { dataBreakpoints = append(dataBreakpoints, breakpoint.DebugDataBreakpoint) } } - dataBreakpoints = unlessMuted(dataBreakpoints, muted) breakpoints := make(map[string][]debugBreakpoint, len(p.debug.breakpoints)) for path, lines := range p.debug.breakpoints { breakpoints[path] = append([]debugBreakpoint(nil), lines...) @@ -433,6 +430,8 @@ func (a *App) beginDebug(p *project, start debugStart) { parent: start.parent, startRequestID: start.startRequestID, } + // A session started while the breakpoints are muted starts muted. + session.muted.Store(p.debug.muted) parentSessionID := "" if start.parent != nil { parentSessionID = start.parent.id @@ -539,6 +538,18 @@ func (a *App) beginDebug(p *project, start debugStart) { return func(a *App) { a.finishDebugError(p, session, err) } } a.postDebugUpdate(p, session, update) + // Muting comes before the first breakpoint set, so a muted session never stops on + // one; a later toggle is applied once this startup is done. + if session.muted.Load() { + update, err := a.kernel.SetDebugBreakpointsMuted(ctx, session.id, true) + if err != nil { + return func(a *App) { a.finishDebugError(p, session, err) } + } + if err := session.writeFrames(update.OutboundFrames); err != nil { + return func(a *App) { a.finishDebugError(p, session, err) } + } + a.postDebugUpdate(p, session, update) + } if len(dataBreakpoints) > 0 { update, err := a.kernel.SetDebugDataBreakpoints(ctx, session.id, dataBreakpoints) if err != nil { @@ -560,7 +571,7 @@ func (a *App) beginDebug(p *project, start debugStart) { a.postDebugUpdate(p, session, update) } for path, lines := range breakpoints { - update, err := a.kernel.SetDebugBreakpoints(ctx, session.id, path, sessionSourceBreakpoints(lines, muted)) + update, err := a.kernel.SetDebugBreakpoints(ctx, session.id, path, sourceBreakpoints(lines)) if err != nil { return func(a *App) { a.finishDebugError(p, session, err) } } diff --git a/desktop/internal/workbench/debug_toolbar_test.go b/desktop/internal/workbench/debug_toolbar_test.go index ca3ff0b746..83caf51151 100644 --- a/desktop/internal/workbench/debug_toolbar_test.go +++ b/desktop/internal/workbench/debug_toolbar_test.go @@ -2,8 +2,11 @@ package workbench import ( "context" + "encoding/base64" + "encoding/json" "os" "path/filepath" + "slices" "strings" "testing" "time" @@ -11,44 +14,121 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" ) -// sentBreakpoints is one file's line breakpoints as a session was sent them. -type sentBreakpoints struct { - path string - points []core.DebugSourceBreakpoint +// debugCall is one breakpoint call the host made for a session and the DAP requests Core wrote +// for it. +type debugCall struct { + session string + kind string // "muted", "unmuted" or "breakpoints" + requests []dapRequest } -// captureSetBreakpoints records each file's line breakpoints before Core sends them. -type captureSetBreakpoints struct { +// dapRequest is one DAP request as Core framed it for the adapter. +type dapRequest struct { + command string + arguments map[string]any +} + +// request is the first request of the call named command, or nil. +func (c debugCall) request(command string) *dapRequest { + for index := range c.requests { + if c.requests[index].command == command { + return &c.requests[index] + } + } + return nil +} + +// captureBreakpointCalls records each mute and source breakpoint call with what Core sent. +type captureBreakpointCalls struct { Kernel - sent chan sentBreakpoints + calls chan debugCall } -func (k *captureSetBreakpoints) SetDebugBreakpoints(ctx context.Context, sessionID, sourcePath string, breakpoints []core.DebugSourceBreakpoint) (core.DebugUpdate, error) { +func (k *captureBreakpointCalls) record(ctx context.Context, call debugCall, update core.DebugUpdate, err error) (core.DebugUpdate, error) { + if err != nil { + return update, err + } + for _, frame := range update.OutboundFrames { + data, decodeErr := base64.StdEncoding.DecodeString(frame) + if decodeErr != nil { + return core.DebugUpdate{}, decodeErr + } + _, body, _ := strings.Cut(string(data), "\r\n\r\n") + var message struct { + Type string `json:"type"` + Command string `json:"command"` + Arguments map[string]any `json:"arguments"` + } + if json.Unmarshal([]byte(body), &message) == nil && message.Type == "request" { + call.requests = append(call.requests, dapRequest{command: message.Command, arguments: message.Arguments}) + } + } select { - case k.sent <- sentBreakpoints{path: sourcePath, points: breakpoints}: + case k.calls <- call: case <-ctx.Done(): return core.DebugUpdate{}, ctx.Err() } - return k.Kernel.SetDebugBreakpoints(ctx, sessionID, sourcePath, breakpoints) + return update, nil +} + +func (k *captureBreakpointCalls) SetDebugBreakpointsMuted(ctx context.Context, sessionID string, muted bool) (core.DebugUpdate, error) { + update, err := k.Kernel.SetDebugBreakpointsMuted(ctx, sessionID, muted) + kind := "unmuted" + if muted { + kind = "muted" + } + return k.record(ctx, debugCall{session: sessionID, kind: kind}, update, err) +} + +func (k *captureBreakpointCalls) SetDebugBreakpoints(ctx context.Context, sessionID, sourcePath string, breakpoints []core.DebugSourceBreakpoint) (core.DebugUpdate, error) { + update, err := k.Kernel.SetDebugBreakpoints(ctx, sessionID, sourcePath, breakpoints) + return k.record(ctx, debugCall{session: sessionID, kind: "breakpoints"}, update, err) +} + +// sentLines is the lines of a setBreakpoints request. +func sentLines(request *dapRequest) []float64 { + var lines []float64 + points, _ := request.arguments["breakpoints"].([]any) + for _, point := range points { + if entry, ok := point.(map[string]any); ok { + line, _ := entry["line"].(float64) + lines = append(lines, line) + } + } + return lines +} + +// sentFilters is the filters of a setExceptionBreakpoints request. +func sentFilters(request *dapRequest) []any { + filters, _ := request.arguments["filters"].([]any) + return filters } -// Mute keeps the breakpoints but sends every line as disabled; Unmute sends them as stored. -func TestDebugMuteKeepsTheBreakpointsAndSendsThemDisabled(t *testing.T) { +// Mute keeps the breakpoints but has Core send every kind empty, the adapter's default exception +// filter included; Unmute has Core send them as stored. +func TestDebugMuteSendsEveryKindEmptyAndUnmuteRestoresThem(t *testing.T) { h, p := pausedDebugSession(t) defer releaseLaunchedDebug(h, p) d := &p.debug source := d.frames[0].SourcePath - d.breakpoints = map[string][]debugBreakpoint{source: {{line: 3}}} - gate := &captureSetBreakpoints{Kernel: h.app.kernel, sent: make(chan sentBreakpoints, 1)} + gate := &captureBreakpointCalls{Kernel: h.app.kernel, calls: make(chan debugCall, 4)} h.app.kernel = gate + d.breakpoints = map[string][]debugBreakpoint{source: {{line: 3}}} + h.app.sendDebugBreakpoints(p, source) + stored := awaitValueWithin(t, h, 10*time.Second, gate.calls, "the stored breakpoint") + if request := stored.request("setBreakpoints"); request == nil || !slices.Equal(sentLines(request), []float64{3}) { + t.Fatalf("stored %+v, want line 3 sent", stored) + } h.settle() h.clickNamed(h.shared("native.muteBreakpoints")) - sent := awaitValueWithin(t, h, 10*time.Second, gate.sent, "the muted breakpoints") - if !d.muted || sent.path != source || len(sent.points) != 1 || sent.points[0].Enabled { - t.Fatalf("muted %v sent %+v, want line 3 disabled", d.muted, sent) + muted := awaitValueWithin(t, h, 10*time.Second, gate.calls, "the muted breakpoints") + exceptions, lines := muted.request("setExceptionBreakpoints"), muted.request("setBreakpoints") + if !d.muted || muted.kind != "muted" || exceptions == nil || len(sentFilters(exceptions)) != 0 || lines == nil || len(sentLines(lines)) != 0 { + t.Fatalf("muted %v sent %+v, want every kind empty", d.muted, muted) } if lines := d.breakpoints[source]; len(lines) != 1 || lines[0].disabled { t.Fatalf("muting changed the stored breakpoints: %+v", lines) @@ -56,9 +136,57 @@ func TestDebugMuteKeepsTheBreakpointsAndSendsThemDisabled(t *testing.T) { h.settle() h.clickNamed(h.shared("desktop.debug.unmuteBreakpoints")) - sent = awaitValueWithin(t, h, 10*time.Second, gate.sent, "the unmuted breakpoints") - if d.muted || len(sent.points) != 1 || !sent.points[0].Enabled { - t.Fatalf("muted %v sent %+v, want line 3 enabled", d.muted, sent) + unmuted := awaitValueWithin(t, h, 10*time.Second, gate.calls, "the unmuted breakpoints") + exceptions, lines = unmuted.request("setExceptionBreakpoints"), unmuted.request("setBreakpoints") + if d.muted || unmuted.kind != "unmuted" || exceptions == nil || !slices.Equal(sentFilters(exceptions), []any{"uncaught"}) || + lines == nil || !slices.Equal(sentLines(lines), []float64{3}) { + t.Fatalf("muted %v sent %+v, want the default filter and line 3", d.muted, unmuted) + } +} + +// A session started while the breakpoints are muted is muted before its first breakpoint set, +// so it never stops on one; unmuting it sends the stored breakpoints. +func TestDebugSessionStartedWhileMutedStartsMuted(t *testing.T) { + h := debugHarness(t) + root := t.TempDir() + if err := os.WriteFile(filepath.Join(root, "debug.marker"), []byte("debug\n"), 0o600); err != nil { + t.Fatal(err) + } + source := filepath.Join(root, "tests", "debug_source.go") + if err := os.MkdirAll(filepath.Dir(source), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(source, []byte("package tests\n\nfunc main() {}\n"), 0o600); err != nil { + t.Fatal(err) + } + p := openDebugPanel(t, h, root) + gate := &captureBreakpointCalls{Kernel: h.app.kernel, calls: make(chan debugCall, 4)} + h.app.kernel = gate + p.debug.breakpoints = map[string][]debugBreakpoint{source: {{line: 3}}} + h.clickNamed(h.shared("native.muteBreakpoints")) + if !p.debug.muted { + t.Fatal("the breakpoints were not muted before the start") + } + h.clickNamed(h.app.text.Debug.Start) + defer releaseLaunchedDebug(h, p) + first := awaitValueWithin(t, h, 30*time.Second, gate.calls, "the new session's first breakpoint call") + if first.kind != "muted" { + t.Fatalf("first call %+v, want the session muted before its breakpoints", first) + } + if next := awaitValueWithin(t, h, 10*time.Second, gate.calls, "the new session's breakpoints"); next.kind != "breakpoints" || next.session != first.session { + t.Fatalf("second call %+v, want the stored breakpoints", next) + } + awaitStateWithin(t, h, 30*time.Second, "the paused debuggee", func() bool { + if p.debug.failure != "" { + t.Fatalf("debug start failed: %s", p.debug.failure) + } + return p.debug.state == "paused" + }) + + h.clickNamed(h.shared("desktop.debug.unmuteBreakpoints")) + unmuted := awaitValueWithin(t, h, 10*time.Second, gate.calls, "the unmuted breakpoints") + if lines := unmuted.request("setBreakpoints"); unmuted.kind != "unmuted" || lines == nil || !slices.Equal(sentLines(lines), []float64{3}) { + t.Fatalf("unmuting sent %+v, want line 3", unmuted) } } @@ -260,7 +388,7 @@ func TestDebugMemoryGoesToAnAddressAndChangesItsLayout(t *testing.T) { } // 8208 is 0x2010: the window starts on the 64-byte boundary before it. awaitStateWithin(t, h, 20*time.Second, "the memory at the typed address", func() bool { - return !m.loading && m.address == "0x2000" && len(m.bytes) == debugMemoryBytes + return !m.loading && m.base == "0x2000" && len(m.bytes) == int(m.window.Request.Count) }) if m.at != "0x2010" || m.input != "0x2010" || m.mark != 0x10 || m.bytes[m.mark] != 0x10 { t.Fatalf("at %q input %q mark %d, want 0x2010 highlighted", m.at, m.input, m.mark) @@ -273,7 +401,7 @@ func TestDebugMemoryGoesToAnAddressAndChangesItsLayout(t *testing.T) { h.clickNamed(h.shared("desktop.debug.memoryBytesPerRow")) h.click(center(h.popupHit(i18n.SharedFormat(h.app.language(), "desktop.debug.memoryRowBytes", map[string]string{"bytes": "32"})))) h.settle() - if line := m.lines[0]; m.columns != 32 || len(m.lines) != debugMemoryBytes/32 || line.text[line.cell[0]:line.cell[1]] != "10" { + if line := m.lines[0]; m.columns != 32 || len(m.lines) != len(m.bytes)/32 || line.text[line.cell[0]:line.cell[1]] != "10" { t.Fatalf("columns %d, %d rows, first row marks %v", m.columns, len(m.lines), line.cell) } h.clickNamed(h.shared("desktop.debug.memoryRadix")) @@ -285,9 +413,90 @@ func TestDebugMemoryGoesToAnAddressAndChangesItsLayout(t *testing.T) { h.clickNamed(h.app.text.Debug.Reload) awaitStateWithin(t, h, 20*time.Second, "the memory back at the instruction pointer", func() bool { - return !m.loading && m.address == "0x1000" && m.input == "0x1000" && len(m.bytes) == 4 + return !m.loading && m.base == "0x1000" && m.input == "0x1000" && len(m.bytes) == 4 }) if m.at != "" || m.mark != 0 || m.columns != 32 || m.radix != 2 { t.Fatalf("at %q mark %d layout %d/%d, want the instruction pointer in the kept layout", m.at, m.mark, m.columns, m.radix) } } + +// A frame the adapter gave no instruction pointer still reads memory at a typed address: the +// address field shows, only the way back to the current instruction is unavailable. +func TestDebugMemoryReadsAtATypedAddressOnAFrameWithoutAnInstructionPointer(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + m := &p.debug.memory + // The fixture's second frame has no instruction pointer. + h.app.selectDebugFrame(p, 1) + p.debug.section = debugSectionMemory + h.app.invalidator.Invalidate() + h.settle() + if m.loading || len(m.bytes) != 0 || !h.shows(h.shared("desktop.debug.memoryTypeAddress")) { + t.Fatalf("loading %v with %d bytes; the frame without an address asks for one", m.loading, len(m.bytes)) + } + if current, ok := h.findPageHit(h.app.text.Debug.Reload); !ok || !current.Disabled { + t.Fatalf("the current-instruction button %+v is not disabled on a frame that has none", current) + } + + h.typeInto(h.shared("desktop.debug.memoryAddress"), func() { m.input = "" }, "0x2010") + if err := h.driver.Key(gfx.KeyEnter, 0); err != nil { + t.Fatal(err) + } + awaitStateWithin(t, h, 20*time.Second, "the memory at the typed address", func() bool { + return !m.loading && m.base == "0x2000" && len(m.bytes) == int(m.window.Request.Count) + }) + if m.failure != "" || m.bytes[m.mark] != 0x10 { + t.Fatalf("failure %q, mark %d", m.failure, m.mark) + } +} + +// An edge of the disassembly whose load failed is not loaded again by every paint that shows +// it, as it would be by a request that times out each time; Retry asks once more. +func TestDebugDisassemblyEdgeFailureWaitsForRetry(t *testing.T) { + h, p := pausedDebugSession(t) + defer releaseLaunchedDebug(h, p) + d := &p.debug + w := &d.disassembly + d.section = debugSectionDisassembly + h.app.invalidator.Invalidate() + awaitStateWithin(t, h, 20*time.Second, "the instruction window", func() bool { + return !w.loading && len(w.rows) > 0 + }) + if err := h.driver.Advance(200 * time.Millisecond); err != nil { + t.Fatal(err) + } + rows := len(w.rows) + + // The earlier page fails as a request without an answer does. + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + fetch, err := h.app.kernel.PlanDebugDisassemblyWindow(ctx, "before", w.rows[0].Address, debugDisassemblyEdge, 0) + if err != nil { + t.Fatal(err) + } + w.loading = true + h.app.reduceDisassembly(p, fetch, core.DebugDisassemblyReply{Kind: "failed", Message: "timed out"}) + awaitStateWithin(t, h, 10*time.Second, "the failed page", func() bool { return !w.loading && w.failure != "" }) + if w.failedEdge != "before" { + t.Fatalf("failed edge %q, want before", w.failedEdge) + } + + // The list is at its first row, where every paint would load the earlier page. + w.list.ScrollTo(0, ui.ListStart) + for range 5 { + h.app.invalidator.Invalidate() + h.settle() + if w.loading { + t.Fatal("a paint at the failed edge asked for it again") + } + } + if len(w.rows) != rows || !h.shows("timed out") { + t.Fatalf("%d rows, want %d with the failure shown", len(w.rows), rows) + } + + h.clickNamed(h.shared("desktop.debug.disassemblyRetry")) + awaitStateWithin(t, h, 20*time.Second, "the retried page", func() bool { return !w.loading && len(w.rows) > rows }) + if w.failure != "" || w.failedEdge != "" { + t.Fatalf("failure %q edge %q after a page arrived", w.failure, w.failedEdge) + } +} diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go index 803773c0b7..b7ad9e64f8 100644 --- a/desktop/internal/workbench/title_run.go +++ b/desktop/internal/workbench/title_run.go @@ -1,6 +1,7 @@ package workbench import ( + "context" "errors" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -136,75 +137,104 @@ func (a *App) titleDebug(p *project) { a.titleStart(p, titleActionDebug) } -// titleStart performs action now when the configurations are read, and otherwise reads them -// and performs it once they are. A later press replaces the waiting one. +// titleStart is a press on Run or Debug. Unless the user chose Current File, the press waits +// while the configurations are read, and an answer that settles them while they are asked for +// performs it; otherwise Core decides what the press does now. func (a *App) titleStart(p *project, action titleAction) { - if p.runConfigs.currentFile { - a.performTitleAction(p, action, true) - return - } - p.runConfigs.pending = action - a.loadTitleRunConfigs(p) - if p.runConfigs.pending == action && p.runConfigsSettled() { - p.runConfigs.pending = titleActionNone - a.performTitleAction(p, action, true) + if !p.runConfigs.currentFile { + p.runConfigs.pending = action + a.loadTitleRunConfigs(p) + if p.runConfigs.pending != action { + return + } } + a.decideTitleAction(p, action, "press") } -// settleTitleAction performs the press that waited for the configurations once they are read. -// It runs after every answer that can settle them: detection, a model and the configurations. +// settleTitleAction asks again for the press that waited, after every answer that can settle +// the configurations: detection, a model and the configurations. func (a *App) settleTitleAction(p *project) { - if p == nil || a.project != p || p.runConfigs.pending == titleActionNone || !p.runConfigsSettled() { + if p == nil || a.project != p || p.runConfigs.pending == titleActionNone { return } - action := p.runConfigs.pending - p.runConfigs.pending = titleActionNone - a.performTitleAction(p, action, false) + a.decideTitleAction(p, p.runConfigs.pending, "settled") } -// performTitleAction starts action on the title bar's choice. A configuration whose model has -// not loaded loads it first and waits again; retry says a model that failed before is loaded -// once more, which only a press asks for, so an answer that fails again does not loop. -func (a *App) performTitleAction(p *project, action titleAction, retry bool) { - configuration := p.titleConfiguration() - if configuration == nil { - a.performCurrentFileAction(p, action) - return +// decideTitleAction reports the facts a press depends on to Core and does what Core decides: +// keep the press until the configurations are read, load the configuration's model first, start +// it, or end with a notice. A model that failed before is loaded again only on a press, so an +// answer that fails again ends instead of looping. +func (a *App) decideTitleAction(p *project, action titleAction, trigger string) { + facts := core.TitleActionFacts{ + Action: "run", Trigger: trigger, + CurrentFileChosen: p.runConfigs.currentFile, Settled: p.runConfigsSettled(), } - reference, ok := configuration.BuildReference() - if !ok { - return + if action == titleActionDebug { + facts.Action = "debug" } - index := p.buildInstanceIndex(reference) - if index < 0 { - a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New("the configuration's build instance was not detected"))) - a.notifyError(a.text.Build.TargetMissing) + configuration := p.titleConfiguration() + var reference core.RunProviderReference + index := -1 + if configuration != nil { + facts.Configuration = &core.TitleConfiguration{Kind: "unsupported"} + var ok bool + if reference, ok = configuration.BuildReference(); ok { + index = p.buildInstanceIndex(reference) + facts.Configuration = p.titleConfigurationFacts(index, reference) + } + } + ctx, cancel := context.WithTimeout(p.ctx, kernelCallTimeout) + decision, err := a.kernel.DecideTitleAction(ctx, facts) + cancel() + p.runConfigs.pending = titleActionNone + if err != nil { + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", err)) + a.notifyError(err.Error()) return } - instance := &p.build.instances[index] - if !instance.modelLoaded { - if instance.modelError != "" && !retry { - a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New(instance.modelError))) - a.notifyError(instance.modelError) - return - } + switch decision { + case "wait": + p.runConfigs.pending = action + case "loadModel": p.runConfigs.pending = action a.loadBuildModel(p, index) - return - } - switch action { - case titleActionRun: + case "currentFile": + a.performCurrentFileAction(p, action) + case "unsupported": + a.notifyInfo(i18n.SharedFormat(a.language(), "desktop.title.configurationNotStartable", map[string]string{"name": configuration.Name})) + case "targetMissing": + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New("the configuration's build instance was not detected"))) + a.notifyError(a.text.Build.TargetMissing) + case "modelFailed": + failure := p.build.instances[index].modelError + a.emit(operationFailedLevel, operationFailedEvent, operationFailedFields("title_run", errors.New(failure))) + a.notifyError(failure) + case "run": if _, err := a.startRunConfiguration(p, configuration.ID); errors.Is(err, errBuildBusy) { a.notifyInfo(i18n.Shared(a.language(), "desktop.title.runBusy")) } - case titleActionDebug: - run, ok := buildRunDeclaration(instance.System, reference.Run) - if !ok || run.DebugAdapter == "" { - a.notifyInfo(i18n.SharedFormat(a.language(), "desktop.title.notDebuggable", map[string]string{"name": configuration.Name})) - return - } + case "debug": a.debugProviderTarget(p, index, reference.ProjectID, reference.TargetID, reference.Run) + case "notDebuggable": + a.notifyInfo(i18n.SharedFormat(a.language(), "desktop.title.notDebuggable", map[string]string{"name": configuration.Name})) + } +} + +// titleConfigurationFacts describes a build provider configuration for Core's decision: whether +// its instance was detected, and whether that instance's model is loaded, failed its last load, +// or declares a debug adapter for the configuration's run. +func (p *project) titleConfigurationFacts(index int, reference core.RunProviderReference) *core.TitleConfiguration { + if index < 0 { + return &core.TitleConfiguration{Kind: "instanceMissing"} + } + instance := &p.build.instances[index] + if !instance.modelLoaded { + failed := instance.modelError != "" + return &core.TitleConfiguration{Kind: "modelNotLoaded", Failed: &failed} } + run, ok := buildRunDeclaration(instance.System, reference.Run) + debuggable := ok && run.DebugAdapter != "" + return &core.TitleConfiguration{Kind: "modelLoaded", Debuggable: &debuggable} } // performCurrentFileAction is Run or Debug on Current File. The Debug window starts the open diff --git a/desktop/internal/workbench/title_run_test.go b/desktop/internal/workbench/title_run_test.go index d7c01f8001..1bd3b3fa9d 100644 --- a/desktop/internal/workbench/title_run_test.go +++ b/desktop/internal/workbench/title_run_test.go @@ -189,3 +189,22 @@ func TestStaticModelDetectionResolvesRunConfigurations(t *testing.T) { t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) } } + +// A configuration no build provider starts cannot start from the title bar either: Run names it +// and plans nothing, where the press did nothing before. +func TestTitleRunOnAConfigurationNoProviderStartsSaysSo(t *testing.T) { + gate := &captureBuildPlan{Kernel: &testKernel{Client: core.NewClient()}, requests: make(chan core.BuildPlanRequest, 1)} + h, p := titleRunHarness(t, gate, pluginservice.BuildRunDeclaration{ID: "application", Name: "Run", Tags: []string{"app"}}) + h.app.post(func(a *App) { + p.runConfigs.list[0].Provider = "process" + a.titleRun(p) + }) + h.settle() + want := i18n.SharedFormat(h.app.language(), "desktop.title.configurationNotStartable", map[string]string{"name": "Run Main"}) + if got := lastNotice(h); got != want { + t.Fatalf("notice = %q, want %q", got, want) + } + if len(gate.requests) != 0 || p.runConfigs.pending != titleActionNone { + t.Fatalf("%d run requests, pending %v", len(gate.requests), p.runConfigs.pending) + } +} diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 59a4c908d4..d3426fb113 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -28,14 +28,16 @@ native_path() { } PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" -# Lithe-core-rust main at #20 (lsp.declarationOrUsages and the references operation's -# includeDeclaration, for Go to Declaration or Usages), on top of #19 (MCP configuration and -# library commands removed) and #17: the plugin contract is one baseline with pluginAPIVersion and every -# capability, protocol and document version at 0, and the contract, plugin guides, reference and -# SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), +# Lithe-core-rust #21 (debug.setBreakpointsMuted, debug.planMemoryWindow and +# debug.locateMemoryWindow, runConfig.decideTitleAction), its branch head on top of main at #20 +# (lsp.declarationOrUsages and the references operation's includeDeclaration, for Go to +# Declaration or Usages); a squash merge of #21 moves this pin to the merged commit. On top of +# #19 (MCP configuration and library commands removed) and #17: the plugin contract is one +# baseline with pluginAPIVersion and every capability, protocol and document version at 0, and +# 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 (execution.planLaunchCommand), #8, #7, #6 and #4. -PINNED_CORE_REVISION="74d5aacac4fad9bbaf847128c7fd545ffd8b8374" +PINNED_CORE_REVISION="3350dd71088f1a08c369129164e306373672e076" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/fixtures/debug/memory-window-v1.json b/shared/fixtures/debug/memory-window-v1.json new file mode 100644 index 0000000000..cec35d9e42 --- /dev/null +++ b/shared/fixtures/debug/memory-window-v1.json @@ -0,0 +1,78 @@ +{ + "description": "debug.planMemoryWindow places the memory view's readMemory window at an address; debug.locateMemoryWindow finds where each reply's bytes start and which of them is at the address read. A number (0x hexadecimal or decimal) is read from the multiple of 64 at or below it; any other reference is opaque and read from where it points. Addresses are strings because a 64-bit address can exceed the JavaScript safe integer range.", + "scenarios": [ + { + "name": "hexadecimal address inside an aligned row", + "address": "0x2010", + "window": { + "address": "0x2010", + "request": { "memoryReference": "0x2010", "offset": -16, "count": 1024 } + }, + "replies": [ + { "start": "0x2000", "length": 1024, "expected": { "base": "0x2000", "mark": 16 } }, + { "length": 1024, "expected": { "base": "0x2000", "mark": 16 } }, + { "start": "0x2008", "length": 1024, "expected": { "base": "0x2008", "mark": 8 } }, + { "start": "0x2000", "length": 8, "expected": { "base": "0x2000" } }, + { "start": "0x2020", "length": 1024, "expected": { "base": "0x2020" } } + ] + }, + { + "name": "decimal address and decimal reply start", + "address": "8208", + "window": { + "address": "0x2010", + "request": { "memoryReference": "0x2010", "offset": -16, "count": 1024 } + }, + "replies": [ + { "start": "8192", "length": 1024, "expected": { "base": "0x2000", "mark": 16 } } + ] + }, + { + "name": "uppercase prefix, padding and surrounding spaces", + "address": " 0X0000ABCD ", + "window": { + "address": "0xabcd", + "request": { "memoryReference": "0xabcd", "offset": -13, "count": 1024 } + }, + "replies": [ + { "start": "0x000000000000ABC0", "length": 1024, "expected": { "base": "0xabc0", "mark": 13 } } + ] + }, + { + "name": "opaque reference is read from where it points", + "address": "frame:3:ip", + "window": { + "address": "frame:3:ip", + "request": { "memoryReference": "frame:3:ip", "offset": 0, "count": 1024 } + }, + "replies": [ + { "start": "0x7ff0", "length": 1024, "expected": { "base": "0x7ff0", "mark": 0 } }, + { "length": 1024, "expected": { "mark": 0 } }, + { "length": 0, "expected": {} } + ] + }, + { + "name": "address zero", + "address": "0", + "window": { + "address": "0x0", + "request": { "memoryReference": "0x0", "offset": 0, "count": 1024 } + }, + "replies": [ + { "length": 0, "expected": { "base": "0x0" } }, + { "length": 1024, "expected": { "base": "0x0", "mark": 0 } } + ] + }, + { + "name": "highest 64-bit address", + "address": "0xffffffffffffffff", + "window": { + "address": "0xffffffffffffffff", + "request": { "memoryReference": "0xffffffffffffffff", "offset": -63, "count": 1024 } + }, + "replies": [ + { "start": "0xffffffffffffffc0", "length": 64, "expected": { "base": "0xffffffffffffffc0", "mark": 63 } } + ] + } + ] +} diff --git a/shared/fixtures/run-configuration/title-action-v1.json b/shared/fixtures/run-configuration/title-action-v1.json new file mode 100644 index 0000000000..7781b2cb45 --- /dev/null +++ b/shared/fixtures/run-configuration/title-action-v1.json @@ -0,0 +1,217 @@ +{ + "version": 1, + "expected": { "providerNeutral": true, "failedModelLoadsAgainOnlyOnPress": true }, + "description": "runConfig.decideTitleAction: what a press on the title bar's Run or Debug button does, from the facts the host reports. The host keeps a press answered wait or loadModel and asks again with trigger settled once the configurations or the model arrive.", + "cases": [ + { + "name": "current file chosen acts at once, even before the configurations are read", + "request": { + "action": "debug", + "trigger": "press", + "currentFileChosen": true, + "settled": false + }, + "expected": { + "kind": "currentFile" + } + }, + { + "name": "a press before the configurations are read waits", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": false, + "configuration": { + "kind": "modelLoaded", + "debuggable": true + } + }, + "expected": { + "kind": "wait" + } + }, + { + "name": "an answer that leaves the configurations unread keeps waiting", + "request": { + "action": "run", + "trigger": "settled", + "currentFileChosen": false, + "settled": false + }, + "expected": { + "kind": "wait" + } + }, + { + "name": "a project without configurations acts on the current file", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true + }, + "expected": { + "kind": "currentFile" + } + }, + { + "name": "a configuration that does not start through a build provider", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "unsupported" + } + }, + "expected": { + "kind": "unsupported" + } + }, + { + "name": "an undetected build instance", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "instanceMissing" + } + }, + "expected": { + "kind": "targetMissing" + } + }, + { + "name": "an unloaded model is loaded first", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelNotLoaded", + "failed": false + } + }, + "expected": { + "kind": "loadModel" + } + }, + { + "name": "a press loads a model that failed before once more", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelNotLoaded", + "failed": true + } + }, + "expected": { + "kind": "loadModel" + } + }, + { + "name": "a model that fails again ends the waiting press", + "request": { + "action": "run", + "trigger": "settled", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelNotLoaded", + "failed": true + } + }, + "expected": { + "kind": "modelFailed" + } + }, + { + "name": "a model that has not loaded yet after an answer is loaded", + "request": { + "action": "run", + "trigger": "settled", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelNotLoaded", + "failed": false + } + }, + "expected": { + "kind": "loadModel" + } + }, + { + "name": "run with a loaded model", + "request": { + "action": "run", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelLoaded", + "debuggable": false + } + }, + "expected": { + "kind": "run" + } + }, + { + "name": "run once the waited model arrives", + "request": { + "action": "run", + "trigger": "settled", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelLoaded", + "debuggable": true + } + }, + "expected": { + "kind": "run" + } + }, + { + "name": "debug a run that declares a debug adapter", + "request": { + "action": "debug", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelLoaded", + "debuggable": true + } + }, + "expected": { + "kind": "debug" + } + }, + { + "name": "debug a run that declares no debug adapter", + "request": { + "action": "debug", + "trigger": "press", + "currentFileChosen": false, + "settled": true, + "configuration": { + "kind": "modelLoaded", + "debuggable": false + } + }, + "expected": { + "kind": "notDebuggable" + } + } + ] +} diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 4d30d35fd9..79b31aa2a7 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -879,6 +879,7 @@ "desktop.debug.connectionClosed": "The debug connection closed.", "desktop.debug.continue": "Continue", "desktop.debug.disassembly": "Disassembly", + "desktop.debug.disassemblyRetry": "Retry", "desktop.debug.editValue": "New value", "desktop.debug.exceptions": "Exception Breakpoints", "desktop.debug.failed": "Debug session failed", @@ -10445,6 +10446,7 @@ "desktop.debug.memoryRadixOctal": "Octal", "desktop.debug.memoryRadixDecimal": "Decimal", "desktop.debug.memoryRadixHex": "Hexadecimal", + "desktop.debug.memoryTypeAddress": "The selected frame has no instruction address. Type an address above to read memory there.", "desktop.debug.stepInto": "Step Into", "desktop.debug.stepOver": "Step Over", "desktop.debug.stepOut": "Step Out", @@ -10992,6 +10994,7 @@ "desktop.debug.evaluatePlaceholder": "Evaluate expression ({evaluate}) or add a watch ({watch})", "desktop.debug.unmuteBreakpoints": "Unmute breakpoints", "desktop.plugins.installedOnThisComputer": "Installed on this computer: {arg1}", + "desktop.title.configurationNotStartable": "{name} cannot be started: no build plugin runs it.", "desktop.title.currentFileNotRunnable": "The current file cannot run on its own. Choose a project run configuration from the run configuration menu.", "desktop.title.noRunConfigurations": "No run configurations", "desktop.title.notDebuggable": "{name} cannot be debugged: its plugin declares no debug adapter for this run.", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 5e2e48a3ad..68c9f10221 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -879,6 +879,7 @@ "desktop.debug.connectionClosed": "调试连接已断开。", "desktop.debug.continue": "继续", "desktop.debug.disassembly": "反汇编", + "desktop.debug.disassemblyRetry": "重试", "desktop.debug.editValue": "新值", "desktop.debug.exceptions": "异常断点", "desktop.debug.failed": "调试会话失败", @@ -10445,6 +10446,7 @@ "desktop.debug.memoryRadixOctal": "八进制", "desktop.debug.memoryRadixDecimal": "十进制", "desktop.debug.memoryRadixHex": "十六进制", + "desktop.debug.memoryTypeAddress": "选中的栈帧没有指令地址,请在上方输入要读取的地址", "desktop.debug.stepInto": "单步进入", "desktop.debug.stepOver": "单步跳过", "desktop.debug.stepOut": "单步跳出", @@ -10992,6 +10994,7 @@ "desktop.debug.evaluatePlaceholder": "对表达式求值({evaluate})或添加监视({watch})", "desktop.debug.unmuteBreakpoints": "恢复断点", "desktop.plugins.installedOnThisComputer": "本机已安装:{arg1}", + "desktop.title.configurationNotStartable": "无法启动 {name}:没有构建插件负责运行它。", "desktop.title.currentFileNotRunnable": "当前文件不能单独运行。请在运行配置菜单里选择一个项目运行配置。", "desktop.title.noRunConfigurations": "没有运行配置", "desktop.title.notDebuggable": "无法调试 {name}:它所属的插件没有为这个运行声明调试适配器。", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index 94340603e3..b543bb0238 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -7985,6 +7985,13 @@ "desktop" ] }, + { + "id": "desktop.debug.disassemblyRetry", + "description": "Disassembly: button beside a failed load that asks for the same instructions again", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.debug.editValue", "description": "Placeholder and label of the field that holds a variable's new value", @@ -8166,6 +8173,13 @@ "desktop" ] }, + { + "id": "desktop.debug.memoryTypeAddress", + "description": "Memory window: shown when the selected stack frame has no instruction address to read at, so the user types one", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.debug.noAdapters", "description": "No installed plugin declares a stdio debug adapter.", @@ -16562,6 +16576,16 @@ "desktop" ] }, + { + "id": "desktop.title.configurationNotStartable", + "description": "Desktop title bar: Run or Debug pressed on a run configuration that does not start through a build provider, so nothing can start it", + "platforms": [ + "desktop" + ], + "parameters": { + "name": "string" + } + }, { "id": "desktop.title.currentFileNotRunnable", "description": "Desktop title bar: Run pressed while Current File is chosen; nothing runs a file outside a run configuration", diff --git a/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json index 32247721ed..3025d1bfd3 100644 --- a/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json +++ b/shared/platform-feature-matrix/features/viva-debug-tool-window-layout.json @@ -11,6 +11,7 @@ "desktop/internal/workbench/debug_sections_view.go", "desktop/internal/workbench/debug_watch.go", "desktop/internal/workbench/debug_mute.go", + "desktop/internal/core/debug_state.go", "desktop/internal/workbench/debug_threads.go", "desktop/internal/workbench/debug_menus.go", "desktop/internal/workbench/debug_start.go", @@ -30,6 +31,7 @@ "desktop/internal/workbench/debug_sections_view.go", "desktop/internal/workbench/debug_watch.go", "desktop/internal/workbench/debug_mute.go", + "desktop/internal/core/debug_state.go", "desktop/internal/workbench/debug_threads.go", "desktop/internal/workbench/debug_menus.go", "desktop/internal/workbench/debug_start.go", @@ -42,6 +44,6 @@ ] }, "owner": "Debug", - "verification": "用 fixture 调试适配器暂停目标:工具栏各按钮按会话状态启用,每个图标的提示为其操作名;会话中适配器下拉仍在工具栏,状态只在下拉显示的不是该会话适配器时带上会话名;重新运行停止当前会话并按首次启动方式重启;静音后断点保留并以禁用状态发送,取消静音按原样重发;更多菜单在树与 JSON 间切换并开关折叠过滤帧;回车求值保留输入,求值和监视的长失败原因折行完整显示、不加省略号,有值的监视仍为单行;⇧⌘⏎(其他平台 Ctrl+Shift+Enter)加为监视并清空输入;栈帧右键菜单末尾可复制线程名、单独恢复线程;控制台显示适配器输出并在位于末尾时跟随新行;查看断点对话框可增删、启用禁用断点并选择异常断点;反汇编左侧显示栈帧、右侧显示指令,打开时以当前指令居中,选中无指令指针的栈帧显示无反汇编,选回后按该帧指令指针重新打开,点击行首红点增删指令断点,单步按指令执行;内存输入 8208 跳到 0x2010 并高亮该字节,切换每行 32 字节和二进制后版式保持,回到当前指令时保留版式。原生窗口视觉与真实 Go/LLDB 适配器验收 pending。", + "verification": "用 fixture 调试适配器暂停目标:工具栏各按钮按会话状态启用,每个图标的提示为其操作名;会话中适配器下拉仍在工具栏,状态只在下拉显示的不是该会话适配器时带上会话名;重新运行停止当前会话并按首次启动方式重启;静音后每个会话的源码、异常、函数、指令和数据断点都由 Core 以空集发送、本地仍保留,静音期间启动的会话以静音状态启动,取消静音按原样重发;更多菜单在树与 JSON 间切换并开关折叠过滤帧;回车求值保留输入,求值和监视的长失败原因折行完整显示、不加省略号,有值的监视仍为单行;⇧⌘⏎(其他平台 Ctrl+Shift+Enter)加为监视并清空输入;栈帧右键菜单末尾可复制线程名、单独恢复线程;控制台显示适配器输出并在位于末尾时跟随新行;查看断点对话框可增删、启用禁用断点并选择异常断点;反汇编左侧显示栈帧、右侧显示指令,打开时以当前指令居中,选中无指令指针的栈帧显示无反汇编,选回后按该帧指令指针重新打开,点击行首红点增删指令断点,单步按指令执行;反汇编某一端加载失败后不再随每次绘制重复请求,点“重试”再加载一次;内存输入 8208 跳到 0x2010 并高亮该字节(读取窗口和高亮位置由 Core 计算),没有指令指针的栈帧也能输入地址读取,切换每行 32 字节和二进制后版式保持,回到当前指令时保留版式。原生窗口视觉与真实 Go/LLDB 适配器验收 pending。", "notes": "线程下拉在只有一个线程时也显示。树与 JSON 的切换从变量区移到工具栏“更多”菜单。暂无布局切换按钮、异步栈、包名列(DebugStackFrame 无包字段);监视以独立行显示,尚未并入变量树。 内存暂不支持表达式输入(变量未携带 memoryReference);进制提供 16/10/8/2,未提供 4 进制。反汇编向前加载时以可见范围(含 2 行预排)中点保持位置,属近似。" } diff --git a/shared/platform-feature-matrix/features/viva-title-run-debug.json b/shared/platform-feature-matrix/features/viva-title-run-debug.json index f8791aab0a..bc4e1ebe2c 100644 --- a/shared/platform-feature-matrix/features/viva-title-run-debug.json +++ b/shared/platform-feature-matrix/features/viva-title-run-debug.json @@ -2,7 +2,7 @@ "id": "viva-title-run-debug", "area": "运行与调试", "group": "运行配置", - "capability": "标题栏右上角的运行配置下拉、运行和调试按钮:下拉列出构建提供者检测到的运行配置并可选择“当前文件”,运行按所选配置交给提供者启动并打开运行窗口,调试让提供者准备该运行声明的调试适配器后在调试窗口启动会话;配置尚未读出时按下会等读出后再执行", + "capability": "标题栏右上角的运行配置下拉、运行和调试按钮:下拉列出构建提供者检测到的运行配置并可选择“当前文件”,运行按所选配置交给提供者启动并打开运行窗口,调试让提供者准备该运行声明的调试适配器后在调试窗口启动会话;配置尚未读出时按下会等读出后再执行;按下后做什么(等待、先加载模型、运行、调试或提示)由 Core 判定", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -13,7 +13,8 @@ "desktop/internal/workbench/runconfig.go", "desktop/internal/workbench/build.go", "desktop/internal/pluginservice/builds.go", - "desktop/internal/core/build.go" + "desktop/internal/core/build.go", + "desktop/internal/core/run_config.go" ] }, "windows": { @@ -26,10 +27,11 @@ "desktop/internal/workbench/runconfig.go", "desktop/internal/workbench/build.go", "desktop/internal/pluginservice/builds.go", - "desktop/internal/core/build.go" + "desktop/internal/core/build.go", + "desktop/internal/core/run_config.go" ] }, "owner": "Run", - "verification": "打开带构建提供者(如 Maven、Go)的项目:标题栏下拉列出检测到的运行配置并记住所选项;运行按钮启动所选配置并打开运行窗口;调试按钮对声明了调试适配器的运行准备并启动调试会话、打开调试窗口,未声明时提示该配置不能调试;准备失败时结束“准备中”并显示原因;选择“当前文件”时提示需要运行配置。单元测试覆盖等待配置读出后运行、当前文件提示、无适配器提示、提供者准备请求、按名称选择适配器和拒绝插件未安装的适配器。", + "verification": "打开带构建提供者(如 Maven、Go)的项目:标题栏下拉列出检测到的运行配置并记住所选项;运行按钮启动所选配置并打开运行窗口;调试按钮对声明了调试适配器的运行准备并启动调试会话、打开调试窗口,未声明时提示该配置不能调试;准备失败时结束“准备中”并显示原因;选择“当前文件”时提示需要运行配置。单元测试覆盖等待配置读出后运行、当前文件提示、无适配器提示、不经构建提供者启动的配置提示、提供者准备请求、按名称选择适配器和拒绝插件未安装的适配器。", "notes": "Viva 标题栏按钮此前只有外观。运行忙碌时仅提示,不排队;当前文件运行尚未实现,只提示需要配置;提供者调试暂不携带运行配置的启动选项。macOS、Windows 原生窗口验收 pending。" } From 7ca23a973093813ca6b9082730e2438d69c0949f Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Fri, 13 Nov 2026 13:13:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?build(desktop):=20#1794=20Core=20=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E5=88=B0=20Lithe-core-rust=20#21=20=E7=9A=84=E5=90=88?= =?UTF-8?q?=E5=85=A5=E6=8F=90=E4=BA=A4=20c001967?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/desktop/build-desktop-core.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index d3426fb113..0297c1e37c 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -29,15 +29,14 @@ native_path() { PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # Lithe-core-rust #21 (debug.setBreakpointsMuted, debug.planMemoryWindow and -# debug.locateMemoryWindow, runConfig.decideTitleAction), its branch head on top of main at #20 +# debug.locateMemoryWindow, runConfig.decideTitleAction), squash-merged into main, on top of #20 # (lsp.declarationOrUsages and the references operation's includeDeclaration, for Go to -# Declaration or Usages); a squash merge of #21 moves this pin to the merged commit. On top of -# #19 (MCP configuration and library commands removed) and #17: the plugin contract is one +# Declaration or Usages), #19 (MCP configuration and library commands removed) and #17: the plugin contract is one # baseline with pluginAPIVersion and every capability, protocol and document version at 0, and # 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 (execution.planLaunchCommand), #8, #7, #6 and #4. -PINNED_CORE_REVISION="3350dd71088f1a08c369129164e306373672e076" +PINNED_CORE_REVISION="c001967afac3fd8b706c16119c180807cac7d85a" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in