commit eb123a60cb70c15bc0987b13d066d80b93835b87 Author: Raimon Zamora Date: Sun Mar 29 18:36:02 2026 +0200 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5cb2a37 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +adapter/node_modules/* \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..77d976e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + } + ] +} diff --git a/adapter/debugAdapter.js b/adapter/debugAdapter.js new file mode 100644 index 0000000..21e44a0 --- /dev/null +++ b/adapter/debugAdapter.js @@ -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); diff --git a/adapter/package-lock.json b/adapter/package-lock.json new file mode 100644 index 0000000..61506c4 --- /dev/null +++ b/adapter/package-lock.json @@ -0,0 +1,46 @@ +{ + "name": "mini-adapter", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "mini-adapter", + "version": "0.0.1", + "dependencies": { + "vscode-debugadapter": "^1.51.0", + "vscode-debugprotocol": "^1.51.0" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "license": "MIT", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/vscode-debugadapter": { + "version": "1.51.0", + "resolved": "https://registry.npmjs.org/vscode-debugadapter/-/vscode-debugadapter-1.51.0.tgz", + "integrity": "sha512-mObaXD5/FH/z6aL2GDuyCLbnwLsYRCAJWgFid01vKW9Y5Si8OvINK+Tn+Yl/lRUbetjNuZW3j1euMEz6z8Yzqg==", + "deprecated": "This package has been renamed to @vscode/debugadapter, please update to the new name", + "license": "MIT", + "dependencies": { + "mkdirp": "^1.0.4", + "vscode-debugprotocol": "1.51.0" + } + }, + "node_modules/vscode-debugprotocol": { + "version": "1.51.0", + "resolved": "https://registry.npmjs.org/vscode-debugprotocol/-/vscode-debugprotocol-1.51.0.tgz", + "integrity": "sha512-dzKWTMMyebIMPF1VYMuuQj7gGFq7guR8AFya0mKacu+ayptJfaRuM0mdHCqiOth4FnRP8mPhEroFPx6Ift8wHA==", + "deprecated": "This package has been renamed to @vscode/debugprotocol, please update to the new name", + "license": "MIT" + } + } +} diff --git a/adapter/package.json b/adapter/package.json new file mode 100644 index 0000000..554354d --- /dev/null +++ b/adapter/package.json @@ -0,0 +1,9 @@ +{ + "name": "mini-adapter", + "version": "0.0.1", + "main": "debugAdapter.js", + "dependencies": { + "vscode-debugadapter": "^1.51.0", + "vscode-debugprotocol": "^1.51.0" + } +} diff --git a/extension.js b/extension.js new file mode 100644 index 0000000..60ebf0b --- /dev/null +++ b/extension.js @@ -0,0 +1,24 @@ +const vscode = require('vscode'); +const path = require('path'); + +function activate(context) { + const factory = { + createDebugAdapterDescriptor(session, executable) { + const command = "node"; + const args = [path.join(__dirname, "adapter", "debugAdapter.js")]; + + return new vscode.DebugAdapterExecutable(command, args); + } + }; + + const registration = vscode.debug.registerDebugAdapterDescriptorFactory( + "myLuaApp", + factory + ); + + context.subscriptions.push(registration); +} + +function deactivate() {} + +module.exports = { activate, deactivate }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..643323d --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "mini-debugger", + "displayName": "Mini Debugger", + "description": "Debug Lua inside my C/C++ application", + "version": "0.0.1", + "publisher": "raimon", + "engines": { + "vscode": "^1.85.0" + }, + "categories": ["Debuggers"], + "activationEvents": ["onDebug"], + "main": "./extension.js", + "contributes": { + "debuggers": [ + { + "type": "myLuaApp", + "label": "Debug My Lua App", + "program": "./adapter/debugAdapter.js", + "runtime": "node", + "languages": ["lua"], + "configurationAttributes": { + "launch": { + "properties": { + "program": { + "type": "string", + "description": "Ruta a tu aplicación C/C++" + } + }, + "required": ["program"] + } + } + } + ] + } +}