From ecd24bd2e08e165a4bdc9fbebb18d4b44f6ed780 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 31 Mar 2026 09:22:38 +0200 Subject: [PATCH] =?UTF-8?q?-=20[NEW]=20Expressions=20evaluables=20desde=20?= =?UTF-8?q?la=20consola=20de=20vscode=20-=20[FIX]=20Ara=20els=20breakpoint?= =?UTF-8?q?s=20que=20hi=20havia=20abans=20de=20llan=C3=A7ar=20la=20aplicac?= =?UTF-8?q?i=C3=B3=20ja=20es=20tenen=20en=20compte=20-=20[FIX]=20Ja=20no?= =?UTF-8?q?=20fa=20falta=20apretar=20dos=20vegades=20el=20bot=C3=B3=20de?= =?UTF-8?q?=20parar=20en=20vscode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/debugAdapter.js | 123 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 7 deletions(-) diff --git a/adapter/debugAdapter.js b/adapter/debugAdapter.js index 36d214b..5728e40 100644 --- a/adapter/debugAdapter.js +++ b/adapter/debugAdapter.js @@ -28,6 +28,8 @@ constructor() { this._pendingGlobals = null; this._refTable = new Map(); // ref → { luaRef } this._nextRef = 1000; // IDs únicos para tablas + this._pendingEval = null; + this.programStarted = false; } //initializeRequest(response, args) { @@ -193,6 +195,29 @@ constructor() { return; } + if (json.type === "eval") { + const r = this._pendingEval; + this._pendingEval = null; + + const v = json.payload.result; + + let variablesReference = 0; + + if (v.type === "table" && v.ref > 0) { + const id = this._nextRef++; + this._refTable.set(id, v.ref); + variablesReference = id; + } + + r.body = { + result: v.value, + variablesReference + }; + + this.sendResponse(r); + return; + } + // salida normal this.sendEvent(new OutputEvent(line + "\n", "stdout")); } @@ -207,8 +232,7 @@ constructor() { cwd: cwd, stdio: ['pipe', 'pipe', 'pipe'] }); - - this.sendEvent(new ThreadEvent("started", 1)); + this.programStarted = true; this.stdoutBuffer = ""; @@ -232,6 +256,21 @@ constructor() { this.sendEvent(new TerminatedEvent()); }); + // 3. Ahora que stdout ya está conectado, enviar breakpoints + if (this.breakpoints) { + for (const path in this.breakpoints) { + const lines = this.breakpoints[path]; + + this.sendDebugCommand({ + cmd: "setBreakpoints", + file: path, + lines: lines + }); + } + } + + this.sendEvent(new ThreadEvent("started", 1)); + this.sendResponse(response); } @@ -258,6 +297,36 @@ constructor() { } setBreakPointsRequest(response, args) { + const path = args.source.path; + const clientBreakpoints = args.breakpoints || []; + + const lines = clientBreakpoints.map(bp => bp.line); + + if (!this.breakpoints) + this.breakpoints = {}; + + this.breakpoints[path] = lines; + + // Si el programa YA está corriendo → enviar breakpoints al motor + if (this.programStarted) { + this.sendDebugCommand({ + cmd: "setBreakpoints", + file: path, + lines: lines + }); + } + + response.body = { + breakpoints: lines.map(line => ({ + verified: true, + line: line + })) + }; + + this.sendResponse(response); + } + + /*setBreakPointsRequest(response, args) { const path = args.source.path; // archivo donde se han puesto breakpoints const clientBreakpoints = args.breakpoints || []; @@ -291,7 +360,7 @@ constructor() { }; this.sendResponse(response); - } + }*/ continueRequest(response, args) { const msg = { @@ -344,11 +413,40 @@ constructor() { } disconnectRequest(response, args) { - const msg = { cmd: "continue" }; // por si estaba pausado - this.sendDebugCommand(msg); - //this.process.stdin.write("@@DEBUGCMD@@" + JSON.stringify(msg) + "\n"); + console.log("[ADAPTER] disconnectRequest"); - this.process.kill(); + if (this.process) { + try { + // 1. Cerrar stdin para desbloquear lecturas + this.process.stdin.end(); + } catch (e) {} + + try { + // 2. Intento de kill suave + this.process.kill(); + } catch (e) {} + + try { + // 3. Kill duro por si acaso + this.process.kill('SIGKILL'); + } catch (e) {} + } + + // 4. Notificar a VSCode + this.sendEvent(new TerminatedEvent()); + this.sendResponse(response); + } + + terminateRequest(response, args) { + console.log("[ADAPTER] terminateRequest"); + + if (this.process) { + try { this.process.stdin.end(); } catch (e) {} + try { this.process.kill(); } catch (e) {} + try { this.process.kill('SIGKILL'); } catch (e) {} + } + + this.sendEvent(new TerminatedEvent()); this.sendResponse(response); } @@ -451,6 +549,17 @@ constructor() { this.sendResponse(response); } + evaluateRequest(response, args) { + console.log("[ADAPTER] evaluateRequest:", args.expression); + + this._pendingEval = response; + + this.sendDebugCommand({ + cmd: "eval", + expr: args.expression + }); + } + configurationDoneRequest(response, args) { console.log("[ADAPTER] configurationDoneRequest"); this.sendResponse(response);