From 0155d740845e551a09020796b7cc0dec64f977bd Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Fri, 27 Nov 2026 01:32:02 +0900 Subject: [PATCH] feat(debugger): reconnect Attach to Node.js automatically when the process restarts (#6103) Attach to Node.js ended the debug session as soon as the inspected process exited, so with nodemon, node --watch or tsx watch the attach had to be restarted after every save. The configuration gets Reconnect automatically, which passes js-debug's `restart: true`. js-debug waits for the inspector to come back and attaches the new process as a new child session with the same breakpoints. While it waits, the Frames pane says so. The restarted process's tab replaces the finished one and keeps its console output. VS Code attach configurations with `restart` (true or a policy object) import with the option on. Closes #6084 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-run/src/import/vscode.rs | 10 +- crates/ide-run/tests/import_vscode.rs | 11 +- docs/en/languages/javascript.mdx | 2 +- docs/zh/languages/javascript.mdx | 2 +- smoke/debug.test.ts | 134 +++++++++++++++++- .../debugger/__tests__/remote.test.ts | 18 +++ .../__tests__/sessionAdoption.test.ts | 35 ++++- src/features/debugger/remote.ts | 29 +++- src/features/debugger/state.ts | 17 ++- src/features/debugger/ui/DebugToolWindow.tsx | 8 +- src/platform/locales/text/en.json | 3 + src/platform/locales/text/zh.json | 3 + 12 files changed, 254 insertions(+), 18 deletions(-) diff --git a/crates/ide-run/src/import/vscode.rs b/crates/ide-run/src/import/vscode.rs index 2cb62cb7fa..57db68fc9e 100644 --- a/crates/ide-run/src/import/vscode.rs +++ b/crates/ide-run/src/import/vscode.rs @@ -45,7 +45,7 @@ const COMMON: &[&str] = &["cwd", "env", "envFile"]; const PYTHON_LAUNCH: &[&str] = &["program", "module", "args", "python", "pythonArgs"]; const PYTHON_ATTACH: &[&str] = &["connect", "host", "port", "pathMappings"]; const NODE_LAUNCH: &[&str] = &["program", "args", "runtimeExecutable", "runtimeArgs"]; -const NODE_ATTACH: &[&str] = &["address", "port", "localRoot", "remoteRoot"]; +const NODE_ATTACH: &[&str] = &["address", "port", "localRoot", "remoteRoot", "restart"]; const NODE_TERMINAL: &[&str] = &["command"]; const BROWSER_LAUNCH: &[&str] = &["url", "webRoot"]; const DART_LAUNCH: &[&str] = &["program", "args", "toolArgs", "deviceId", "flutterMode"]; @@ -254,6 +254,10 @@ impl Cx<'_> { if obj.get("pathMappings").and_then(Value::as_array).is_some_and(|m| m.len() > 1) { ignored.push("pathMappings".into()); } + // A restart policy's delays and attempts: the option reconnects with js-debug's defaults. + if handled.contains(&"restart") && obj.get("restart").is_some_and(Value::is_object) { + ignored.push("restart".into()); + } ignored.sort(); Ok(Found { config, members: Vec::new(), ignored }) } @@ -349,6 +353,10 @@ impl Cx<'_> { let port = self.string(obj, "port")?.unwrap_or_else(|| "9229".into()); let mut c = config(name, "node-remote", String::new(), Vec::new(), Some("js-debug")); c.extras.params = BTreeMap::from([("host".into(), host), ("port".into(), port)]); + // Reconnect automatically: `true`, or a restart policy object (its delays are noted as ignored). + if matches!(obj.get("restart"), Some(Value::Bool(true) | Value::Object(_))) { + c.extras.params.insert("restart".into(), "true".into()); + } self.roots(obj, &mut c)?; Ok(c) } diff --git a/crates/ide-run/tests/import_vscode.rs b/crates/ide-run/tests/import_vscode.rs index 840d215464..091e4afb01 100644 --- a/crates/ide-run/tests/import_vscode.rs +++ b/crates/ide-run/tests/import_vscode.rs @@ -380,6 +380,9 @@ fn attach_requests_become_remote_debug_configurations() { "pathMappings": [{ "localRoot": "${workspaceFolder}", "remoteRoot": "/app" }] }, { "name": "Attach to Node", "type": "node", "request": "attach", "port": 9230, "localRoot": "${workspaceFolder}/web", "remoteRoot": "/usr/src/app", "restart": true }, + { "name": "Attach (no restart)", "type": "pwa-node", "request": "attach", "restart": false }, + { "name": "Attach (restart policy)", "type": "node", "request": "attach", + "restart": { "delay": 500, "maxAttempts": 5 } }, { "name": "Attach to PID", "type": "debugpy", "request": "attach", "processId": "${command:pickProcess}" }, { "name": "Odd", "type": "node", "request": "test" } ] @@ -402,7 +405,13 @@ fn attach_requests_become_remote_debug_configurations() { assert_eq!(node.extras.params["port"], "9230"); assert_eq!(node.extras.params["localRoot"], "web"); assert_eq!(node.extras.params["remoteRoot"], "/usr/src/app"); - assert_eq!(ignored(&r, "Attach to Node"), ["restart"]); + assert_eq!(node.extras.params["restart"], "true"); + assert!(ignored(&r, "Attach to Node").is_empty()); + let off = get(&r, "Attach (no restart)"); + assert!(!off.extras.params.contains_key("restart")); + assert!(ignored(&r, "Attach (no restart)").is_empty()); + assert_eq!(get(&r, "Attach (restart policy)").extras.params["restart"], "true"); + assert_eq!(ignored(&r, "Attach (restart policy)"), ["restart"]); assert_eq!(reason(&r, "Attach to PID"), &SkipReason::UnsupportedAttach); assert_eq!(reason(&r, "Odd"), &SkipReason::UnsupportedRequest { request: "test".into() }); diff --git a/docs/en/languages/javascript.mdx b/docs/en/languages/javascript.mdx index 52a0310ed3..6a7107fd58 100644 --- a/docs/en/languages/javascript.mdx +++ b/docs/en/languages/javascript.mdx @@ -103,7 +103,7 @@ Jest, Vitest, Playwright Test, `node --test` and Mocha output is turned into the Debugging uses the JavaScript Debugger (vscode-js-debug); if it is missing, the first debug session offers to install it. - **Debug** works for npm script configurations, Node.js files and `deno run` / `deno test`. Child processes are attached automatically. -- **Attach to Node.js** is a run configuration type for a process started with `--inspect` on this or another machine (default port 9229), with local and remote root mapping. +- **Attach to Node.js** is a run configuration type for a process started with `--inspect` on this or another machine (default port 9229), with local and remote root mapping. With **Reconnect automatically** on, the session waits while the process restarts (nodemon, `node --watch`, `tsx watch`) and attaches to it again with the same breakpoints. - **Attach to Process…** in the Run menu lists running Node.js processes. - **JavaScript Debug** is a run configuration type that opens a URL in Chrome or Edge and debugs the page's JavaScript and TypeScript through source maps. Start the page's server first (for example with the `dev` npm script); **Web root** is the folder the URL serves, the project root by default. diff --git a/docs/zh/languages/javascript.mdx b/docs/zh/languages/javascript.mdx index 60302cac63..7cf9f06098 100644 --- a/docs/zh/languages/javascript.mdx +++ b/docs/zh/languages/javascript.mdx @@ -104,7 +104,7 @@ Jest、Vitest、Playwright Test、`node --test` 和 Mocha 的输出会解析成 调试使用 JavaScript 调试器(vscode-js-debug);未安装时,第一次调试会提示安装。 - **调试** 适用于 npm 脚本配置、Node.js 文件以及 `deno run` / `deno test`,子进程会自动附加。 -- **附加到 Node.js** 是一种运行配置类型,用于附加到本机或其他机器上以 `--inspect` 启动的进程(默认端口 9229),可设置本地与远程根目录映射。 +- **附加到 Node.js** 是一种运行配置类型,用于附加到本机或其他机器上以 `--inspect` 启动的进程(默认端口 9229),可设置本地与远程根目录映射。勾选 **自动重新连接** 后,进程重启时(nodemon、`node --watch`、`tsx watch`)会话会等待,并以相同的断点重新附加。 - 运行菜单中的 **附加到进程…** 会列出正在运行的 Node.js 进程。 - **JavaScript 调试** 是一种运行配置类型:在 Chrome 或 Edge 中打开一个 URL,通过 source map 调试页面中的 JavaScript 和 TypeScript。先启动页面的服务(例如 `dev` npm 脚本);**Web 根目录** 是该 URL 对应的文件夹,默认为项目根目录。 diff --git a/smoke/debug.test.ts b/smoke/debug.test.ts index 0fd4d979d5..4f6a1ebb16 100644 --- a/smoke/debug.test.ts +++ b/smoke/debug.test.ts @@ -5,8 +5,20 @@ * variables, evaluation, Step Over and Resume, with the debugger the IDE installs (GDB: * the toolchain's own, 14+ for its DAP interpreter). */ -import { execFileSync } from "node:child_process"; -import { cpSync, existsSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync } from "node:fs"; +import { type ChildProcess, execFileSync, spawn } from "node:child_process"; +import { + appendFileSync, + cpSync, + existsSync, + mkdtempSync, + readdirSync, + readFileSync, + realpathSync, + rmSync, + statSync, + writeFileSync, +} from "node:fs"; +import { createServer } from "node:net"; import { get } from "node:http"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -21,9 +33,19 @@ import { activate as activateBuildTools } from "@/features/build-tools"; import { useBuild } from "@/features/build-tools/store"; import { activate as activateDebugger } from "@/features/debugger"; import { addBreakpoint, flushBreakpoints } from "@/features/debugger/breakpoints/store"; -import { activeSession, evaluate, rootOf, sessionSupports, useDebug } from "@/features/debugger/state"; +import { nodeRemoteType, remoteWaitingNote } from "@/features/debugger/remote"; +import { + activeSession, + evaluate, + isLive, + rootOf, + selectSession, + sessionSupports, + useDebug, +} from "@/features/debugger/state"; import { activate as activateRun } from "@/features/run"; import { resetRuns, useRun } from "@/features/run/store"; +import { newConfigOfType, withParams } from "@/features/run/types"; import { activateWorkbench } from "@/workbench/activate"; import { useNotifications } from "@/workbench/notificationStore"; import { connectDesktop } from "./desktop"; @@ -220,14 +242,18 @@ beforeAll(() => { }); afterAll(() => deactivate?.()); -afterEach(async () => { +async function teardown() { resetRuns(); disconnect?.(); + disconnect = null; // `close` kills the server and what it started (debug adapters, language servers) // and waits until they're gone, so the removal below can't race their writes. await server?.close(); + server = null; if (base) rmSync(base, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }); -}); + base = ""; +} +afterEach(teardown); async function open(c: Case): Promise { base = realpathSync(mkdtempSync(join(tmpdir(), "openidea-smoke-"))); @@ -615,6 +641,102 @@ async function traceStream(language: string, t: NonNullable ]); } +/** More of a language's debugging, each with a project of its own (CI runs one test per language). */ +const MORE: Record Promise>> = { + typescript: [() => nodeReconnect(true), () => nodeReconnect(false)], +}; + for (const language of Object.keys(CASES)) { - test(language, () => smoke(language)); + test(language, async () => { + await smoke(language); + for (const more of MORE[language] ?? []) { + // oxlint-disable-next-line no-await-in-loop -- each case starts its own server after the last one is gone. + await teardown(); + // oxlint-disable-next-line no-await-in-loop -- see above. + await more(); + } + }); +} + +/** A free TCP port on the loopback interface. */ +const freePort = () => + new Promise((resolve, reject) => { + const srv = createServer(); + srv.once("error", reject); + srv.listen(0, "127.0.0.1", () => { + const { port } = srv.address() as { port: number }; + srv.close(() => resolve(port)); + }); + }); + +/** + * Attach to Node.js on a `node --watch` process that restarts when its file changes: with + * Reconnect automatically the session waits and attaches again, stopping at the same + * breakpoint; without it the session ends with the process. + */ +async function nodeReconnect(restart: boolean) { + const root = await open({ fixture: "node-test-app" } as Case); + await install("js-debug"); + const path = join(root, "watched.js"); + writeFileSync(path, "function work(n) {\n return n * 2;\n}\nsetInterval(() => work(21), 300);\n"); + addBreakpoint(path, 1); + const port = await freePort(); + const node: ChildProcess = spawn("node", ["--watch", `--inspect=127.0.0.1:${port}`, "watched.js"], { + cwd: root, + stdio: "ignore", + }); + try { + const blank = newConfigOfType(nodeRemoteType, []); + const params = { ...blank.params, host: "127.0.0.1", port: String(port), ...(restart ? { restart: "true" } : {}) }; + const config = withParams({ ...blank, name: "Attach" }, params, nodeRemoteType); + // The inspector comes up once node has started the program. + await new Promise((r) => setTimeout(r, 1000)); + const stops = useDebug.getState().stopSeq; + await executeAction("debug.startConfig", config); + const first = await until("the breakpoint", stoppedAfter(stops)); + expect([first.frames[0]!.path, first.frames[0]!.line], shown()).toEqual([path, 1]); + const rootId = rootOf(first).id; + const processes = () => Object.values(useDebug.getState().sessions).filter((c) => c.parent === rootId); + // What the Frames pane shows for the session: the note once its process has ended and none is attached. + const note = () => + remoteWaitingNote( + useDebug.getState().sessions[rootId]?.runConfig, + processes().length > 0 && !processes().some(isLive), + ); + expect(note(), "no note while attached the first time").toBeNull(); + await executeAction("debug.resume"); + + // `node --watch` restarts the program when its file changes. + appendFileSync(path, "// changed\n"); + if (!restart) { + await until("the end", () => Object.values(useDebug.getState().sessions).every((d) => !isLive(d))); + return; + } + let waited = ""; + const again = await until("the breakpoint after the restart", () => { + if (!isLive(useDebug.getState().sessions[rootId])) + throw new Error(`the session ended with the process\n${shown()}`); + waited ||= note() ?? ""; + const s = paused(); + return s && s.id !== first.id && s; + }); + expect([again.frames[0]!.path, again.frames[0]!.line], shown()).toEqual([path, 1]); + expect(rootOf(again).id, "the same debug session").toBe(rootId); + expect(again.id, "a new process").not.toBe(first.id); + expect( + processes().map((c) => c.id), + "one process tab", + ).toEqual([again.id]); + expect(waited).toBe(`Waiting to reconnect to Node.js on 127.0.0.1:${port}`); + + // With the process gone, the session waits for it; Stop ends it. + await executeAction("debug.resume"); + node.kill(); + await until("the wait for the process", () => note()); + selectSession(rootId); + await executeAction("debug.stop"); + await until("the end", () => Object.values(useDebug.getState().sessions).every((d) => !isLive(d))); + } finally { + node.kill(); + } } diff --git a/src/features/debugger/__tests__/remote.test.ts b/src/features/debugger/__tests__/remote.test.ts index 83b89dc510..564a2eee6a 100644 --- a/src/features/debugger/__tests__/remote.test.ts +++ b/src/features/debugger/__tests__/remote.test.ts @@ -177,6 +177,16 @@ describe("remote attach requests", () => { }); }); + it("Attach to Node.js reconnects automatically only when the option is on", () => { + const attach = (params: Record = {}) => + JSON.parse(remoteAttachConfig(configOf(nodeRemoteType, params), "/p")!.extraJson!); + expect(attach()).not.toHaveProperty("restart"); + expect(attach({ restart: "true" })).toMatchObject({ restart: true, port: 9229 }); + expect(nodeRemoteType.fields.find((f) => f.key === "restart")!.control).toBe("checkbox"); + const hint = nodeRemoteType.fields.find((f) => f.key === "hint")!; + expect(hint.value!({ restart: "true", port: "9230" })).toBe("nodemon --inspect=0.0.0.0:9230 app.js"); + }); + it("PHP Remote Debug defaults to port 9003 and shows the xdebug command line", () => { expect(configOf(phpRemoteType).params).toEqual({ port: "9003" }); const field = phpRemoteType.fields.find((f) => f.key === "hint")!; @@ -215,6 +225,14 @@ describe("remote attach requests", () => { for (const t of REMOTE_TYPES.filter((x) => x !== phpRemoteType)) expect(remoteWaitingNote(configOf(t))).toBeNull(); }); + it("Attach to Node.js with Reconnect automatically says it waits once its process has ended", () => { + const rc = configOf(nodeRemoteType, { restart: "true", port: "9230" }); + expect(remoteWaitingNote(rc, true)).toBe("Waiting to reconnect to Node.js on localhost:9230"); + // The first attach (or one that never connects) isn't a reconnect. + expect(remoteWaitingNote(rc)).toBeNull(); + expect(remoteWaitingNote(configOf(nodeRemoteType), true)).toBeNull(); + }); + it("start-the-remote-side hints follow the port", () => { expect(remote.delveServerCommand({ port: "4000" })).toBe( "dlv debug --headless --listen=:4000 --api-version=2 --accept-multiclient", diff --git a/src/features/debugger/__tests__/sessionAdoption.test.ts b/src/features/debugger/__tests__/sessionAdoption.test.ts index aad838eafc..ce30697493 100644 --- a/src/features/debugger/__tests__/sessionAdoption.test.ts +++ b/src/features/debugger/__tests__/sessionAdoption.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; -import type { LaunchConfig } from "@/platform/ipc"; +import type { LaunchConfig, RunConfig } from "@/platform/ipc"; import { useProject } from "@/platform/project"; import { handleDebugEvent, resetSessions, startSession, useDebug } from "../state"; @@ -83,3 +83,36 @@ describe("sessions of a window whose backend changes", () => { expect(useDebug.getState().console).toEqual({}); }); }); + +describe("Attach to Node.js with Reconnect automatically", () => { + const attach = (restart: boolean) => + startSession( + { ...launch, name: "Attach", request: "attach" }, + { runConfig: { name: "Attach", kind: "node-remote", params: restart ? { restart: "true" } : {} } as RunConfig }, + ); + const ended = (id: number) => handleDebugEvent(id, { kind: "terminated" }); + + it("shows the restarted process in place of the finished one, with its output", async () => { + expect(await attach(true)).toBe(1); + child(2, 1, "Remote Process [100]"); + handleDebugEvent(2, { kind: "output", category: "stderr", output: "Error: boom\n" }); + ended(2); + // nodemon's next process has another pid. + child(3, 1, "Remote Process [200]"); + handleDebugEvent(3, { kind: "output", category: "stdout", output: "listening\n" }); + const { sessions } = useDebug.getState(); + expect(Object.keys(sessions).map(Number)).toEqual([1, 3]); + expect(sessions[1]?.status).toBe("running"); + await vi.waitFor(() => + expect(useDebug.getState().console[3]?.map((l) => l.text)).toEqual(["Error: boom\n", "listening\n"]), + ); + }); + + it("keeps finished processes of other sessions", async () => { + await attach(false); + child(2, 1, "Remote Process [0]"); + ended(2); + child(3, 1, "Remote Process [0]"); + expect(Object.keys(useDebug.getState().sessions).map(Number)).toEqual([1, 2, 3]); + }); +}); diff --git a/src/features/debugger/remote.ts b/src/features/debugger/remote.ts index 405c134529..addae965f6 100644 --- a/src/features/debugger/remote.ts +++ b/src/features/debugger/remote.ts @@ -196,8 +196,9 @@ export const pythonRemoteType: RunConfigTypeContribution = { // --------------------------------------------------------------------------- // Attach to Node.js (inspector) +/** How to start the remote side; with Reconnect automatically, under nodemon, which restarts it on save. */ export function nodeInspectCommand(p: Params): string { - return `node --inspect=0.0.0.0:${portOf(p, 9229)} app.js`; + return `${p.restart === "true" ? "nodemon" : "node"} --inspect=0.0.0.0:${portOf(p, 9229)} app.js`; } export const nodeRemoteType: RunConfigTypeContribution = { @@ -218,6 +219,12 @@ export const nodeRemoteType: RunConfigTypeContribution = { mono: true, value: nodeInspectCommand, }, + { + key: "restart", + label: "Reconnect automatically", + control: "checkbox", + hint: "When the process restarts (nodemon, node --watch, tsx watch), attach to it again with the same breakpoints", + }, localRootField, remoteRootField("e.g. /usr/src/app"), ], @@ -407,6 +414,7 @@ export function remoteAttachConfig(rc: RunConfig, root: string): LaunchConfig | port: portOf(p, 9229), ...(map ? { localRoot: map.local, remoteRoot: map.remote } : {}), skipFiles: skip ? ["/**", "**/node_modules/**"] : [], + ...(p.restart === "true" ? { restart: true } : {}), }); case PHP_REMOTE: return requestBase(rc, "php-debug", root, "launch", { @@ -418,10 +426,23 @@ export function remoteAttachConfig(rc: RunConfig, root: string): LaunchConfig | } } -/** What a session of `rc` shows while nothing is suspended, when it waits for the debuggee to connect. */ -export function remoteWaitingNote(rc: Pick | undefined): string | null { +/** Attach to Node.js with Reconnect automatically: js-debug attaches each restarted process in a new child session. */ +export const reconnects = (rc: Pick | undefined) => + rc?.kind === NODE_REMOTE && rc.params?.restart === "true"; + +/** + * What a session of `rc` shows while nothing is suspended, when it waits for the debuggee to connect. + * `reconnecting`: the process it attached to has ended and none is attached yet. + */ +export function remoteWaitingNote( + rc: Pick | undefined, + reconnecting = false, +): string | null { + const p = rc?.params ?? {}; + if (reconnects(rc)) + return reconnecting ? tx`Waiting to reconnect to Node.js on ${serverAddress(hostOf(p), portOf(p, 9229))}` : null; if (rc?.kind !== PHP_REMOTE) return null; - return tx`Listening for Xdebug on port ${portOf(rc.params ?? {}, 9003)}`; + return tx`Listening for Xdebug on port ${portOf(p, 9003)}`; } /** What a Remote JVM Debug configuration attaches to (before the listen mode relay). */ diff --git a/src/features/debugger/state.ts b/src/features/debugger/state.ts index 34d6efd3c8..7ef33d4bad 100644 --- a/src/features/debugger/state.ts +++ b/src/features/debugger/state.ts @@ -58,6 +58,7 @@ import { missingAdapter } from "./missingAdapter"; import { startFailureMessage } from "./startFailure"; import { evaluateWithImports, forgetImports } from "./classImports"; import { JAVA_ADAPTER } from "./java"; +import { reconnects } from "./remote"; import { isTracing, markTraceStop } from "./streams/streamStore"; export type SessionStatus = "starting" | "running" | "paused" | "stopping" | "terminated"; @@ -360,8 +361,20 @@ function ownSession(id: DebugSessionId, event: DebugEvent): DebugSession | null // of a forgotten session, though its id may be one (another backend numbers from 1 again). if (owned.has(id) && event.kind !== "started") return null; if (event.kind === "started" && event.parent != null) { - if (!st.sessions[event.parent]) return null; - return adoptSession(id, { name: event.name, adapter: event.adapter, parent: event.parent }); + const parent = st.sessions[event.parent]; + if (!parent) return null; + const child = adoptSession(id, { name: event.name, adapter: event.adapter, parent: event.parent }); + // A process attached again after its restart takes the finished one's place (one tab, its output kept). + if (reconnects(rootOf(parent).runConfig)) + for (const s of Object.values(st.sessions)) { + if (s.parent !== event.parent || isLive(s)) continue; + flushConsoleOutput(); + useDebug.setState((cur) => ({ + console: { ...cur.console, [id]: [...(cur.console[s.id] ?? []), ...(cur.console[id] ?? [])] }, + })); + removeSession(s.id); + } + return child; } if (pendingStarts === 0) return null; provisional.add(id); diff --git a/src/features/debugger/ui/DebugToolWindow.tsx b/src/features/debugger/ui/DebugToolWindow.tsx index 1b1563f5e7..7731ec7cf3 100644 --- a/src/features/debugger/ui/DebugToolWindow.tsx +++ b/src/features/debugger/ui/DebugToolWindow.tsx @@ -440,6 +440,12 @@ function FramesPane({ session }: { session: DebugSession }) { if (list.current && selectedRow.current) revealVertically(list.current, selectedRow.current); }, [items]); const paused = session.status === "paused"; + const rootId = rootOf(session).id; + // js-debug attaches each process in a child session: an ended one and none live while it waits for a restart. + const reconnecting = useDebug((s) => { + const processes = Object.values(s.sessions).filter((c) => c.parent === rootId); + return processes.length > 0 && !processes.some(isLive); + }); const onKeyDown = (e: KeyboardEvent) => { if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return; const frames = items.flatMap((i) => (i.kind === "frame" ? [i.frame] : [])); @@ -475,7 +481,7 @@ function FramesPane({ session }: { session: DebugSession }) {
{session.status === "terminated" ? tx("Finished") - : (remoteWaitingNote(rootOf(session).runConfig) ?? tx("Running…"))} + : (remoteWaitingNote(rootOf(session).runConfig, reconnecting) ?? tx("Running…"))}
)} {stopNote(session) &&
{stopNote(session)}
} diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index ec9765c314..21ab16e2c1 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1180,6 +1180,9 @@ "For web requests: the XDEBUG_SESSION cookie or query parameter; point xdebug.client_host at this machine when PHP runs in a container": "For web requests: the XDEBUG_SESSION cookie or query parameter; point xdebug.client_host at this machine when PHP runs in a container", "e.g. /var/www/html": "e.g. /var/www/html", "Listening for Xdebug on port {port}": "Listening for Xdebug on port {port}", + "Reconnect automatically": "Reconnect automatically", + "When the process restarts (nodemon, node --watch, tsx watch), attach to it again with the same breakpoints": "When the process restarts (nodemon, node --watch, tsx watch), attach to it again with the same breakpoints", + "Waiting to reconnect to Node.js on {address}": "Waiting to reconnect to Node.js on {address}", "Port {port} is already in use: another IDE or debug session may be listening on it. Stop it or choose another port.": "Port {port} is already in use: another IDE or debug session may be listening on it. Stop it or choose another port.", "Unable to load image: {path}": "Unable to load image: {path}", "Load image from {host}": "Load image from {host}", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index d0cd5f65b6..5896afd5ab 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -5060,6 +5060,9 @@ "For web requests: the XDEBUG_SESSION cookie or query parameter; point xdebug.client_host at this machine when PHP runs in a container": "对于 Web 请求:设置 XDEBUG_SESSION cookie 或查询参数;当 PHP 运行在容器中时,将 xdebug.client_host 指向本机", "e.g. /var/www/html": "例如 /var/www/html", "Listening for Xdebug on port {port}": "正在端口 {port} 上监听 Xdebug", + "Reconnect automatically": "自动重新连接", + "When the process restarts (nodemon, node --watch, tsx watch), attach to it again with the same breakpoints": "进程重启时(nodemon、node --watch、tsx watch)以相同的断点重新附加", + "Waiting to reconnect to Node.js on {address}": "正在等待重新连接到 {address} 上的 Node.js", "Port {port} is already in use: another IDE or debug session may be listening on it. Stop it or choose another port.": "端口 {port} 已被占用:可能有其他 IDE 或调试会话正在监听。请停止它或选择其他端口。", "Copied": "已复制", "'{name}' can only be debugged": "'{name}' 只能调试",