Skip to content
junfff edited this page Sep 4, 2021 · 1 revision

Debug by EmmyLua

~/.vim/vimspector-config/gadgets/linux/.gadgets.json .gadgets.json

        "emmylua_debug": {
      "command": [
        "node",
        "${gadgetDir}/tangzx.emmylua-0.3.49/out/debugger/EmmyDebugAdapter.js"
      ],
      "configuration": {
        "extensionPath": "${gadgetDir}/tangzx.emmylua-0.3.49",
        "interpreter": "lua"
      },
      "name": "emmylua_debug"
    },

Vimspector config

{
  "configurations": {
    "EmmyLua":    {
      "adapter": "emmylua_debug",
      "configuration":{
            "type": "emmylua_debug",
            "request": "launch",
            "name": "EmmyLua New Debug",
            "host": "localhost",
            "cwd": "${workspaceFolder}",
            "codePaths":[
                        "${workspaceFolder}/A path/Lua"
			"${workspaceFolder}/B path/Lua",
			"${workspaceFolder}/C path/Lua"
            ],
            "port": 9966,
            "ext": [
                ".lua",
                ".lua.txt",
                ".lua.bytes"
            ],
            "ideConnectDebugger": true
        }
  }
}

EmmyDebugSession.js

{

launchRequest(response, args) {
        this.ext = args.ext;
        this.rootpath = args.cwd;
        this.codePaths = args.codePaths; 
...
}

...
    // implementation findFile
    findFile(startPath,filter) {
            if (path_1.isAbsolute(filter)) {
                return filter;
            }
            const r = this._fileCache.get(filter);
            if (r) {
                return r;
            }
    if (!fs_1.existsSync(startPath)){
        this.sendEvent(new vscode_debugadapter_1.OutputEvent(`fromDir:ERROR:startPath:${startPath},filter:${filter}.\n`));
        return "";
    }
    var files=fs_1.readdirSync(startPath);
    for(var i=0;i<files.length;i++){
        var filename=path_1.join(startPath,files[i]);
        var stat = fs_1.lstatSync(filename);
        if (stat.isDirectory()){
            this.findFile(filename,filter); //recurse
        }
        else if (filename.indexOf(filter)>=0) {
            this._fileCache.set(filter, filename);
            return filename
        };
    };
}

stackTraceRequest(response, args) {
...
          //yield this.findFile(stack.file);   disable this ,impl function findFile
          file = "";
          for (let j = 0; j < this.codePaths.length; j++) {
              file = this.findFile(this.codePaths[i],stack.file);
               if (file != null) {
                   break;
               }
           }
          

...
}

in your project

Main.lua

{

package.cpath = package.cpath .. ";/home/XXX/.vscode-insiders/extensions/tangzx.emmylua-0.3.49/debugger/emmy/linux/emmy_core.so"
local dbg = require("emmy_core")
dbg.tcpListen("localhost", 9966)

}

https://github.com/EmmyLua/VSCode-EmmyLua