local-lua-debugger-vscode icon indicating copy to clipboard operation
local-lua-debugger-vscode copied to clipboard

Source mapping doesn't work with multiple sources in one map

Open Zorbn opened this issue 2 years ago • 1 comments

The source mapping feature works well when each lua file has its own .lua.map file. However, when using the luaBundle feature of TypeScriptToLua or other tools that generate a single lua file with one .lua.map which points to many source files, the debugger seems to get breakpoints across different files mixed up, and often skips them. For example, if you have a breakpoint in a file like foo.ts in the love-ts test, but no breakpoint in main.ts, then the debugger will ignore the breakpoint in foo.ts and never break.

Zorbn avatar Dec 29 '23 21:12 Zorbn

This is fixed in my fork by changing the conditional in Breakpoint.add from

if (mapping.sourceLine === line) {
    sourceFile = file;
    file = scriptFile;
    sourceLine = line;
    line = scriptLine;
    break;
}

to

if (mapping.sourceLine === line && file === sourceMap.sources[mapping.sourceIndex]) {
    sourceFile = file;
    file = scriptFile;
    sourceLine = line;
    line = scriptLine;
    break;
}

Zorbn avatar Jan 02 '24 02:01 Zorbn