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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- 停止、EOF、读写失败和超时先由 Core 递增代次,再由 `close` 效果取消解析任务、全部剩余计时器和 socket,清空回调与缓冲。旧连接回调以及旧写入完成不能影响新连接。显式停止由会话层投影结果,传输不重复发送终止通知。失败时 Core 先给出 `close`、`reportFailure`、`notifyTermination`;宿主执行每个效果前核对代次,观察者在错误输出回调里重新 `start` 会使剩余的旧终止通知作废。已处于停止状态的传输再收到 `stop` 则被 Core 忽略,所以观察者在错误输出回调里调用 `stop()` 时终止通知仍然送达,且只送达一次;旧实现把这种情况也当作“生命周期已被替换”而吞掉通知,这个差异是有意接受的。
- 宿主若发现 Core 调用本身失败(桥接故障而不是生命周期结果,包含 `send`),在本地静默拆除 socket 与计时器、释放登记,并向所有者报告一次,不让资源在故障后残留。释放会重置 Core 内部的代次与计时器编号,重启前必须换用新的登记 ID,并在宿主回调入口同时核对登记 ID;不能只依赖重置后的代次。故障观察者重启后也不得再收到旧终止通知。
- `DebugAdapterConnectionProviding` 是未来代理的替换点:返回尚未启动、可取消的连接,握手纳入已有启动期限;停止必须释放它自己拥有的资源。本次唯一实现为直连,不提前增加代理配置、密码或进程字段。
- 插件声明 `tcpAnnounced` 的适配器复用同一条生命周期,只把端点发现换成“读进程公告”:宿主拉起插件声明的适配器进程(stdin 不接管),把 `launch.endpoint` 声明的输出流按行切开,每一整行(去掉行尾的 `\r\n`)交给 Core 的 `debug.adapters.readAnnouncement`。Core 判定这一行是 `none`(不是公告)、`announced`(回环主机和端口)还是 `invalid`(公告了非本机地址或非法端口),哪一行算公告、哪些地址允许连接都只由 Core 决定。公告行本身不进调试控制台,其余输出(含公告之前的和另一个流的)照常显示;单行超过 64 KiB 不再缓存,原样交给控制台。传输先于进程启动,所以 Core 默认的 10 秒端点发现期限同时覆盖进程启动和公告;进程在公告前退出时以“还没输出监听端口就退出”结束,公告无效时以端点无效结束,两者和超时都会停止进程。进程用不随启动请求取消的上下文启动,归会话所有:用户停止时先把 DAP disconnect 排空到网络栈,再停止进程树(`buildprocess.Stop`:Unix 先向进程组发 SIGTERM,宽限期后强制结束;Windows 直接结束 Job Object 里的整棵树);其他结束方式直接关闭连接并停止进程。宿主实现在 `desktop/internal/workbench/debug_announced.go`。
- `tcpLanguageServer` 仍只解析同插件语言服务器返回的回环端口。外部入口在 Debug 的更多操作中,由当前文件选择已安装的调试提供方(当前文件没有提供方时菜单项不可用),单独填写 DAP 地址、请求种类和适配器 JSON 参数;不猜测语言协议,不启动本地替代进程。连接对话框在连接启动前保持打开:被拒绝的地址、未获批准的确认、已有活动会话、连接失败或初始化超时都留在对话框里显示原因,已填的主机、端口和参数不丢失,表单通过 Application 层的 `ExternalDebugAdapterConnection` 等待会话越过初始化阶段,而不是把同步 `start` 返回视为网络连接成功。用户取消或关闭表单会停止本次尝试的会话 ID,即使此时已选中另一会话也不会误停它;已有初始化期限负责等待上界,表单不再添加第二套网络超时。Core 先校验地址,非回环端点每次连接前确认,明确警告裸 TCP 没有加密或认证;确认时间不计入网络建连期限。
- 外部服务只归用户所有。关闭 socket 本身不停止共享语言服务器、外部适配器或用户隧道;目标程序的结束策略由 DAP 协议层负责,`attach` 断开使用 `terminateDebuggee=false`,`launch` 断开则可能结束该会话启动的程序。不要把字节流所有权等同于目标程序的 DAP 生命周期。配置不持久化,源码映射继续由适配器参数表达。

Expand All @@ -45,7 +46,7 @@

## 后果

普通 TCP 连接可独立测试,stdio 原有路径不变,用户提供的外部地址与语言服务器端口遵守各自的信任边界。代价是外部连接需要用户了解其适配器参数,没有保存配置、通路自动建立或断线恢复;插件 `tcpPort`、`tcpAnnounced` 的托管进程模式也仍未实现。
普通 TCP 连接可独立测试,stdio 原有路径不变,用户提供的外部地址与语言服务器端口遵守各自的信任边界。代价是外部连接需要用户了解其适配器参数,没有保存配置、通路自动建立或断线恢复。插件 `tcpAnnounced` 的托管进程已接入;`tcpPort`(宿主先分配端口再交给进程)仍未实现,声明它的适配器在启动进程前被拒绝。

此处代码实现不等于所有语言适配器都已验收。真实 JVM、debugpy、GDB 的兼容性仍需对应插件和端到端场景证明;Windows 共享地址校验与这套生命周期状态机,但尚无宿主 TCP 实现,接入时只需实现 socket、解析和计时器这些 I/O 并执行 Core 返回的效果,状态机本身不需要再写一遍。

Expand All @@ -54,7 +55,8 @@
## 验证

- `./scripts/desktop/desktop-go.sh test ./internal/workbench -run 'DebugTransport'`:可控时钟、队列预算、取消与晚到回调、外部表单初始化成功/失败/超时与按会话取消,以及回环监听器上的真实字节往返。
- `./scripts/desktop/desktop-go.sh test ./internal/core -run 'Debug'`:调试会话的启动、停止与传输登记。
- `./scripts/desktop/desktop-go.sh test ./internal/core -run 'Debug'`:调试会话的启动、停止与传输登记,以及逐条重放 Core 的 `rust/fixtures/debug/adapter-announcements-v1.json`。
- `./scripts/desktop/desktop-go.sh test ./internal/workbench -run 'DebugAnnounce'`:真实子进程公告回环端口后命中断点、暂停、继续,停止时对端先收到 disconnect 再看到进程结束;公告前退出、公告远程地址、一直不公告三种失败都停止进程;按行切分、分流、超长行与等待取消的单元测试。
- 在 Core 仓库运行 `cargo test -p lithe-core debug_adapter_endpoint` 和 `cargo test -p lithe-core dap_endpoint_contract`:共享 fixture 校验及 JSON dispatcher 边界。
- 在 Core 仓库运行 `cargo test -p lithe-core transport_lifecycle`:状态机单元测试,并逐步回放 `Lithe-core-rust/rust/fixtures/debug/transport-lifecycle-v1.json` 中的场景。新平台实现同一份 fixture 即可证明规则一致。
- `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`、`./scripts/agent-notes/verify-agent-notes.sh`。
Expand All @@ -63,6 +65,8 @@

- `desktop/internal/core/debug_transport.go`
- `desktop/internal/workbench/debug_transport_test.go`
- `desktop/internal/workbench/debug_announced.go`
- `desktop/internal/workbench/debug_announced_test.go`

- Lithe-core-rust 锁定修订:[rust/lithe-core/src/debug/endpoint.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/0ffd327b4329261e393b08ed76fbd134b4dd17e9/rust/lithe-core/src/debug/endpoint.rs)
- Lithe-core-rust 锁定修订:[rust/lithe-core/src/debug/transport_lifecycle.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/0ffd327b4329261e393b08ed76fbd134b4dd17e9/rust/lithe-core/src/debug/transport_lifecycle.rs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Java Support 的插件清单要求宿主提供 `settings` 2、`outputLinkMatcher

## 已知缺口

- `debug.target: launch`、launch.json 导入、`tcpPort` / `tcpAnnounced`(插件进程托管)、远程 attach 的路径映射输入。
- `debug.target: launch`、launch.json 导入、`tcpPort`(宿主分配端口的插件进程托管)、远程 attach 的路径映射输入。`tcpAnnounced` 已接入,见 `2026-10-27-debug-tcp-transport-lifecycle.md`。
- Build 输出区只在检测到构建系统后显示;运行视图不受影响。
- 运行视图和 Debug 表单已在 Page 迁移中改为 Viva Page(`workbench/runpanels.go`;工作台根窗口改为一个 Page 后它们是根 Page 调用的组件,见 `2026-11-10-workbench-root-page-and-viva-upgrade.md`)。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ P3 的声明层已在 Rust Core 落地:`plugin.json.debugAdapters[]` 作为插
- Core 提供 `languageServerLaunchPlan` 的 `debugAdapterID` 选择器和 `debug.adapters.startArguments` 命令;后者按 manifest、adapterID、request 与事实(注册代次、目标、运行时选择)返回启动参数,拒绝码为 `debug.provider.stale`、`debug.request.unsupported`、`debug.runtime.stale`、`debug.target.invalid`、`plugin.launch.unavailable`。
- 宿主启用模块 `<pluginID>.debug-adapters`(只承载启用、隔离与安全模式状态)。宿主按语言 ID 建立插件适配器会话;Java 等内置语言优先,宿主不按插件名字分支。
- 启动计划在会话启动时才解析,因为启动依赖工作区;被拒绝的计划就是启动错误。`adapterID` 声明时默认等于 `id`,会话创建时即需要(DAP `initialize.adapterId`),所以随描述符提前提供。
- 适配器可执行文件只允许来自插件包或 `systemCommand`。桌面端目前只接入 `stdio` 和 `tcpLanguageServer` 两种传输(见 `desktop/internal/workbench/debug_start.go` 的 `debugTransportServed`);`tcpPort`、`tcpAnnounced` 和 `runSelectedRuntime` 还没有接入宿主,之后再做。
- 适配器可执行文件只允许来自插件包或 `systemCommand`。桌面端目前接入 `stdio`、`tcpAnnounced` 和 `tcpLanguageServer` 三种传输(见 `desktop/internal/workbench/debug_start.go` 的 `debugTransportServed`,`tcpAnnounced` 在 `debug_announced.go`);`tcpPort` 和 `runSelectedRuntime` 还没有接入宿主。
- 生命周期与所有权:适配器进程归会话,随会话停止。适配器状态目录由平台存储 adapter 提供,位于插件状态目录下的 `debug-adapters/<adapterID>`,不写入插件包或安装目录,不影响代码签名和 Sparkle 增量更新;`${workspaceStateDir}` 按工作区摘要隔离。被调试程序的启动配置由 `startArguments` 生成,宿主只在没有内置适配器处理时回落到它。

P4 的纵向验收用 `lldb-dap` 推进:官方 LLDB 插件(`io.github.lithe-idea.lldb-debug`,仓库 [lithe-plugin-lldb](https://github.com/Lithe-IDEA/lithe-plugin-lldb))已作为预发布收录在 Lithe Store,需要支持 API 4 的 Lithe 才能安装;必选层全流程的验收结果还没有记录,不算 P4 完成。这一轮在契约里补了三件事,全部在尚未发布的 API 4 / `debugAdapters` v1 内,没有已发布的契约被改动:
Expand Down
56 changes: 56 additions & 0 deletions desktop/internal/core/debug_announcement_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package core

import (
"encoding/json"
"errors"
"testing"
)

// TestDebugAnnouncementFollowsTheContractFixture reads every line of the shared
// announcement fixture through the typed wrapper: a case with a result must read
// exactly that, a case without one must fail as an invalid request. A case whose
// request does not have exactly the endpoint, stream and line fields cannot be
// sent through the wrapper, so Core's own tests cover it instead.
func TestDebugAnnouncementFollowsTheContractFixture(t *testing.T) {
var fixture struct {
Cases []struct {
Name string `json:"name"`
Input map[string]json.RawMessage `json:"input"`
Result *DebugAnnouncement `json:"result"`
} `json:"cases"`
}
if err := json.Unmarshal(readDebugFixture(t, "adapter-announcements-v1.json"), &fixture); err != nil {
t.Fatal(err)
}
if len(fixture.Cases) == 0 {
t.Fatal("the announcement fixture has no cases")
}
ctx := debugContext(t)
client := NewClient()
for _, item := range fixture.Cases {
t.Run(item.Name, func(t *testing.T) {
var stream, line string
endpoint, hasEndpoint := item.Input["endpoint"]
rawStream, hasStream := item.Input["stream"]
rawLine, hasLine := item.Input["line"]
if len(item.Input) != 3 || !hasEndpoint || !hasStream || !hasLine ||
json.Unmarshal(rawStream, &stream) != nil || json.Unmarshal(rawLine, &line) != nil {
t.Skip("the wrapper always sends exactly the endpoint and the stream and line strings")
}
got, err := client.ReadDebugAnnouncement(ctx, endpoint, stream, line)
if item.Result == nil {
var coreErr *Error
if !errors.As(err, &coreErr) || coreErr.Code != CodeInvalidRequest {
t.Fatalf("reading = %+v, %v; want an invalid_request error", got, err)
}
return
}
if err != nil {
t.Fatal(err)
}
if got != *item.Result {
t.Fatalf("reading = %+v, want %+v", got, *item.Result)
}
})
}
}
38 changes: 37 additions & 1 deletion desktop/internal/core/debug_transport.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package core

import "context"
import (
"context"
"encoding/json"
)

// DebugTransportEvent is one platform event applied to an IDE-to-adapter byte
// stream lifecycle. Type selects which of the other fields Core requires; a
Expand Down Expand Up @@ -77,3 +80,36 @@ func (c *Client) DebugTransportRelease(ctx context.Context, transportID string)
TransportID string `json:"transportId"`
}{transportID}, nil)
}

// DebugAnnouncement is Core's reading of one output line of a tcpAnnounced
// adapter. Status is "none" for a line that does not announce the endpoint,
// "announced" with the loopback Host and Port to connect to, or "invalid" with
// the Reason ("malformed" or "notLoopback") the announced endpoint is refused.
type DebugAnnouncement struct {
Status string `json:"status"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Reason string `json:"reason,omitempty"`
}

// ReadDebugAnnouncement asks Core whether line, read from stream ("stdout" or
// "stderr") of a tcpAnnounced adapter's process without its line break,
// announces the adapter's endpoint. endpoint is the launch plan's
// `debugAdapter.endpoint`, passed unchanged: Core owns which line is the
// announcement and which endpoints may be connected to.
func (c *Client) ReadDebugAnnouncement(ctx context.Context, endpoint json.RawMessage, stream, line string) (DebugAnnouncement, error) {
const command = "debug.adapters.readAnnouncement"
var announcement DebugAnnouncement
if err := c.Execute(ctx, command, struct {
Endpoint json.RawMessage `json:"endpoint"`
Stream string `json:"stream"`
Line string `json:"line"`
}{endpoint, stream, line}, &announcement); err != nil {
return DebugAnnouncement{}, err
}
switch announcement.Status {
case "none", "announced", "invalid":
return announcement, nil
}
return DebugAnnouncement{}, newParseError(command, "invalid announcement reading", "")
}
2 changes: 2 additions & 0 deletions desktop/internal/i18n/debug_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type DebugMessages struct {
Reload string
BufferLimit string
InvalidEndpoint string
NotAnnounced string
// RemotePrompt asks whether to attach to a debuggee that is not local.
RemotePrompt func(endpoint string) string
// ConnectFailed reports a failed connection to the debug adapter.
Expand Down Expand Up @@ -131,6 +132,7 @@ func debugMessages(language Language) DebugMessages {
Reload: Shared(language, "desktop.debug.reload"),
BufferLimit: Shared(language, "desktop.debug.bufferLimit"),
InvalidEndpoint: Shared(language, "desktop.debug.invalidEndpoint"),
NotAnnounced: Shared(language, "desktop.debug.notAnnounced"),
RemotePrompt: func(endpoint string) string {
return SharedFormat(language, "desktop.debug.remotePrompt", map[string]string{"endpoint": endpoint})
},
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/i18n/shared.generated.go

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

5 changes: 3 additions & 2 deletions desktop/internal/pluginhost/pluginhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ type Capabilities map[string][]int
// runs the plan in a staging directory.
// - settings: pages per language and build system, sections, every control
// type, the project layer, setting effects and page buttons.
// - debugAdapters: stdio adapters and adapters inside the plugin's language
// server over loopback TCP, launch and attach (a remote host after the user
// - debugAdapters: stdio adapters, adapter processes that print the loopback
// TCP endpoint they listen on (tcpAnnounced) and adapters inside the
// plugin's language server over loopback TCP, launch and attach (a remote host after the user
// confirms it), argument and environment bindings, features and defaults.
// - outputLinkMatchers: Build, Run and Test console lines become links at the
// ranges Core finds; a matcher with resolve asks the backend on click.
Expand Down
5 changes: 3 additions & 2 deletions desktop/internal/pluginservice/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DebugPlugin struct {
}

// DebugAdapterDeclaration is the subset of one `debugAdapters` entry the host
// uses to start a stdio adapter and present it. Adapter behaviour stays in
// uses to start an adapter and present it. Adapter behaviour stays in
// Core; the host never interprets DAP payloads.
type DebugAdapterDeclaration struct {
ID string
Expand All @@ -38,7 +38,8 @@ type DebugAdapterDeclaration struct {
// ConfigurationTypes are the imported launch.json types the adapter answers to.
ConfigurationTypes []string
// Endpoint names the language server and command a tcpLanguageServer adapter
// asks for its loopback port.
// asks for its loopback port. A tcpAnnounced adapter's endpoint describes the
// output line its process prints; only Core reads it, from the launch plan.
Endpoint DebugAdapterEndpoint
// AcceptsConnection is true when the attach configuration binds a remote
// host and port, so the host may offer the host-and-port form.
Expand Down
1 change: 1 addition & 0 deletions desktop/internal/workbench/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Kernel interface {
PlanDebugExecutable(context.Context, json.RawMessage, string, string, string, map[string]json.RawMessage, map[string]json.RawMessage) (*core.DebugExecutablePlan, error)
PlanDebugStart(context.Context, json.RawMessage, string, string, core.DebugStartFacts, map[string]any) (core.DebugStart, error)
DebugTransportPolicy(context.Context) (core.DebugTransportPolicy, error)
ReadDebugAnnouncement(ctx context.Context, endpoint json.RawMessage, stream, line string) (core.DebugAnnouncement, error)
debugTransportKernel
debugStateKernel
processExitKernel
Expand Down
Loading
Loading