actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
435 stars 94 forks source link

How to handle multiple script roots? #185

Open sewbacca opened 2 years ago

sewbacca commented 2 years ago

I have a subfolder, in which scripts are without prefix (e.g. main.lua) and all other folders are reachable via package.path (though the debug console says it has mixed / and \ (i'm on win)). If I set sourcemap, either the subfolder or the other "script roots" are found, but I couldn't get both working at the same time.

{
    "name": "Launch Debugger 2",
    "type": "lua",
    "request": "attach",
    "address": "127.0.0.1:4278",
    "sourceMaps": [
        [
            "*\\src\\*", // This is in package.path
            "${workspaceFolder}/src/*",
        ],
        [
            "./*",
            "${workspaceFolder}/examples/component_explorer/*",
        ]
    ]
},
actboy168 commented 2 years ago

You can change the chunkname so that they can be distinguished correctly.

sewbacca commented 2 years ago

How so? The modules are loaded via require(). Do you suggest to create my own require() function? And if so, how should I go about writing it? How is the path inferred from the chunkname? It's not that I haven't written my own require function, I am more interested in how the debugger interprets the chunkname. Thanks for your feedback :)

actboy168 commented 2 years ago

If you don't modify require, you shouldn't need to set sourceMaps. The debugger understands chunknames using the rules on the lua documentation.