First commit
This commit is contained in:
80
adapter/debugAdapter.js
Normal file
80
adapter/debugAdapter.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const {
|
||||
LoggingDebugSession,
|
||||
InitializedEvent,
|
||||
TerminatedEvent,
|
||||
OutputEvent
|
||||
} = require('vscode-debugadapter');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
class MyLuaDebugSession extends LoggingDebugSession {
|
||||
|
||||
constructor() {
|
||||
super("myLuaDebug.txt");
|
||||
this.setDebuggerLinesStartAt1(true);
|
||||
this.setDebuggerColumnsStartAt1(true);
|
||||
}
|
||||
|
||||
initializeRequest(response, args) {
|
||||
this.sendEvent(new InitializedEvent());
|
||||
this.sendResponse(response);
|
||||
}
|
||||
|
||||
launchRequest(response, args) {
|
||||
const program = args.program;
|
||||
const cwd = args.cwd || process.cwd();
|
||||
|
||||
this.process = spawn(program, [], {
|
||||
cwd: cwd,
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
this.process.stdout.on('data', data => {
|
||||
const text = data.toString();
|
||||
|
||||
if (text.startsWith("@@DEBUG@@")) {
|
||||
const json = JSON.parse(text.substring(9));
|
||||
|
||||
if (json.type === "luaError") {
|
||||
const e = new OutputEvent(json.message + "\n", "stderr");
|
||||
e.body.source = { path: json.file };
|
||||
e.body.line = json.line;
|
||||
|
||||
this.sendEvent(e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// salida normal
|
||||
this.sendEvent(new OutputEvent(text, "stdout"));
|
||||
});
|
||||
|
||||
this.process.stderr.on('data', data => {
|
||||
this.sendEvent(new OutputEvent(data.toString(), "stderr"));
|
||||
});
|
||||
|
||||
this.process.on('exit', () => {
|
||||
this.sendEvent(new TerminatedEvent());
|
||||
});
|
||||
|
||||
this.sendResponse(response);
|
||||
}
|
||||
|
||||
setBreakPointsRequest(response, args) {
|
||||
const path = args.source.path;
|
||||
const bps = args.breakpoints.map(bp => bp.line);
|
||||
|
||||
// Guardamos los breakpoints internamente
|
||||
this.breakpoints[path] = bps;
|
||||
|
||||
// Enviar confirmación a VSCode
|
||||
response.body = {
|
||||
breakpoints: bps.map(line => ({ verified: true, line }))
|
||||
};
|
||||
|
||||
this.sendResponse(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new MyLuaDebugSession().start(process.stdin, process.stdout);
|
||||
Reference in New Issue
Block a user