- [NEW] (del debugger) Ja funciona: start, pause, stop, breakpoints, step into, step over, step out. Intentant que funcione el enviament del stackTrace
This commit is contained in:
@@ -13,6 +13,8 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("myLuaDebug.txt");
|
super("myLuaDebug.txt");
|
||||||
|
console.log("ADAPTER INICIADO");
|
||||||
|
this._stackFrames = [];
|
||||||
this.setDebuggerLinesStartAt1(true);
|
this.setDebuggerLinesStartAt1(true);
|
||||||
this.setDebuggerColumnsStartAt1(true);
|
this.setDebuggerColumnsStartAt1(true);
|
||||||
}
|
}
|
||||||
@@ -27,6 +29,10 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
this.sendResponse(response);
|
this.sendResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pendingStackTrace(frames) {
|
||||||
|
this._stackFrames = frames;
|
||||||
|
}
|
||||||
|
|
||||||
handleLine(line) {
|
handleLine(line) {
|
||||||
if (line.startsWith("@@DEBUG@@")) {
|
if (line.startsWith("@@DEBUG@@")) {
|
||||||
const json = JSON.parse(line.substring(9));
|
const json = JSON.parse(line.substring(9));
|
||||||
@@ -47,6 +53,11 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (json.type === "stackTrace") {
|
||||||
|
this.pendingStackTrace(json.payload.frames);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +99,28 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
this.sendResponse(response);
|
this.sendResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendDebugCommand(obj) {
|
||||||
|
if (!this.process || !this.process.stdin) return;
|
||||||
|
console.log("ENVIANDO CMD:", obj);
|
||||||
|
const msg = "@@DEBUGCMD@@" + JSON.stringify(obj) + "\n";
|
||||||
|
this.process.stdin.write(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
nextRequest(response, args) {
|
||||||
|
this.sendDebugCommand({ cmd: "stepOver" });
|
||||||
|
this.sendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
stepInRequest(response, args) {
|
||||||
|
this.sendDebugCommand({ cmd: "stepInto" });
|
||||||
|
this.sendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
stepOutRequest(response, args) {
|
||||||
|
this.sendDebugCommand({ cmd: "stepOut" });
|
||||||
|
this.sendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
setBreakPointsRequest(response, args) {
|
setBreakPointsRequest(response, args) {
|
||||||
const path = args.source.path; // archivo donde se han puesto breakpoints
|
const path = args.source.path; // archivo donde se han puesto breakpoints
|
||||||
const clientBreakpoints = args.breakpoints || [];
|
const clientBreakpoints = args.breakpoints || [];
|
||||||
@@ -108,9 +141,10 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
lines: lines
|
lines: lines
|
||||||
};
|
};
|
||||||
|
|
||||||
this.process.stdin.write(
|
this.sendDebugCommand(msg);
|
||||||
"@@DEBUGCMD@@" + JSON.stringify(msg) + "\n"
|
//this.process.stdin.write(
|
||||||
);
|
// "@@DEBUGCMD@@" + JSON.stringify(msg) + "\n"
|
||||||
|
//);
|
||||||
|
|
||||||
// VSCode necesita una respuesta con los breakpoints "verificados"
|
// VSCode necesita una respuesta con los breakpoints "verificados"
|
||||||
response.body = {
|
response.body = {
|
||||||
@@ -128,16 +162,55 @@ class MyLuaDebugSession extends LoggingDebugSession {
|
|||||||
cmd: "continue"
|
cmd: "continue"
|
||||||
};
|
};
|
||||||
|
|
||||||
this.process.stdin.write(
|
this.sendDebugCommand(msg);
|
||||||
"@@DEBUGCMD@@" + JSON.stringify(msg) + "\n"
|
//this.process.stdin.write(
|
||||||
);
|
// "@@DEBUGCMD@@" + JSON.stringify(msg) + "\n"
|
||||||
|
//);
|
||||||
|
|
||||||
this.sendResponse(response);
|
this.sendResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pauseRequest(response, args) {
|
||||||
|
this.sendDebugCommand({ cmd: "pause" });
|
||||||
|
this.sendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
stackTraceRequest(response, args) {
|
||||||
|
// Pedimos al motor el stack trace
|
||||||
|
this.sendDebugCommand({ cmd: "stackTrace" });
|
||||||
|
|
||||||
|
// IMPORTANTE: el motor responde async, así que esperamos
|
||||||
|
// a que llegue el mensaje @@DEBUG@@ con type=stackTrace
|
||||||
|
|
||||||
|
const check = () => {
|
||||||
|
if (this._stackFrames.length > 0) {
|
||||||
|
const frames = this._stackFrames;
|
||||||
|
this._stackFrames = [];
|
||||||
|
|
||||||
|
response.body = {
|
||||||
|
stackFrames: frames.map((f, i) => ({
|
||||||
|
id: i + 1,
|
||||||
|
name: f.name,
|
||||||
|
source: { path: f.file },
|
||||||
|
line: f.line,
|
||||||
|
column: 1
|
||||||
|
})),
|
||||||
|
totalFrames: frames.length
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sendResponse(response);
|
||||||
|
} else {
|
||||||
|
setTimeout(check, 5);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
disconnectRequest(response, args) {
|
disconnectRequest(response, args) {
|
||||||
const msg = { cmd: "continue" }; // por si estaba pausado
|
const msg = { cmd: "continue" }; // por si estaba pausado
|
||||||
this.process.stdin.write("@@DEBUGCMD@@" + JSON.stringify(msg) + "\n");
|
this.sendDebugCommand(msg);
|
||||||
|
//this.process.stdin.write("@@DEBUGCMD@@" + JSON.stringify(msg) + "\n");
|
||||||
|
|
||||||
this.process.kill();
|
this.process.kill();
|
||||||
this.sendResponse(response);
|
this.sendResponse(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user