diff --git a/adapter/debugAdapter.js b/adapter/debugAdapter.js index 5da2726..aed7da4 100644 --- a/adapter/debugAdapter.js +++ b/adapter/debugAdapter.js @@ -32,6 +32,7 @@ constructor() { this.programStarted = false; this._nextVarRef = 100; this._varRefMap = new Map(); + this._exceptionFilters = new Set(["uncaught"]); } initializeRequest(response, args) { @@ -62,9 +63,13 @@ constructor() { supportsClipboardContext: false, supportsValueFormattingOptions: false, supportsExceptionOptions: false, - supportsExceptionFilterOptions: false, + supportsExceptionFilterOptions: true, supportsSingleThreadExecutionRequests: true }; + response.body.exceptionBreakpointFilters = [ + { filter: "all", label: "Break on all exceptions", default: false }, + { filter: "uncaught", label: "Break on uncaught exceptions", default: true } + ]; this.sendResponse(response); } @@ -121,10 +126,20 @@ constructor() { } if (json.type === "stackTrace") { - console.log("[ADAPTER] STACKTRACE PAYLOAD:", JSON.stringify(json.payload)); - console.log("[ADAPTER] BEFORE HANDLING STACKTRACE"); - this.pendingStackTrace(json.payload.frames); - console.log("[ADAPTER] AFTER HANDLING STACKTRACE"); + this._lastStackFrames = json.payload.stackFrames; + this._lastTotalFrames = json.payload.totalFrames; + + if (this._pendingStackTraceResponse) { + const resp = this._pendingStackTraceResponse; + this._pendingStackTraceResponse = null; + + resp.body = { + stackFrames: this._lastStackFrames, + totalFrames: this._lastTotalFrames + }; + + this.sendResponse(resp); + } return; } @@ -226,6 +241,11 @@ constructor() { return; } + if (json.type === "stopped" && json.payload.reason === "exception") { + this.sendEvent(new StoppedEvent("exception", 1, json.payload.text)); + return; + } + // salida normal this.sendEvent(new OutputEvent(line + "\n", "stdout")); } @@ -278,6 +298,11 @@ constructor() { } } + this.sendDebugCommand({ + cmd: "setExceptionFilters", + filters: [...this._exceptionFilters] + }); + this.sendEvent(new ThreadEvent("started", 1)); this.sendResponse(response); @@ -410,11 +435,23 @@ constructor() { stackTraceRequest(response, args) { console.log("[ADAPTER] stackTraceRequest"); - // Pedimos el stack trace al motor - this.sendDebugCommand({ cmd: "stackTrace" }); + if (!this._lastStackFrames) { + // Pedimos el stack trace al motor + this.sendDebugCommand({ cmd: "stackTrace" }); + // Guardar el response para enviarlo más tarde + this._pendingStackTraceResponse = response; + return; + } + // Si ya tenemos frames, responder inmediatamente + response.body = { + stackFrames: this._lastStackFrames, + totalFrames: this._lastTotalFrames + }; + + this.sendResponse(response); // Esperamos la respuesta del motor - const check = () => { +/* const check = () => { if (this._stackFrames && this._stackFrames.length > 0) { const frames = this._stackFrames; this._stackFrames = []; @@ -437,7 +474,7 @@ constructor() { } }; - check(); + check();*/ } makeVarRef(type, frameId) { @@ -567,6 +604,18 @@ constructor() { this.sendResponse(response); } + setExceptionBreakPointsRequest(response, args) { + // Si VSCode envía filtros explícitos, los usamos + if (args.filters && args.filters.length > 0) { + this._exceptionFilters = new Set(args.filters); + } + + // Si VSCode envía [], NO tocamos los filtros por defecto + + response.body = {}; + this.sendResponse(response); + } + configurationDoneRequest(response, args) { console.log("[ADAPTER] configurationDoneRequest"); this.sendResponse(response);