tomblind / local-lua-debugger-vscode

Local Lua Debugger for VSCode
MIT License
106 stars 26 forks source link

Configuring Löve2d project with TypescriptToLua #16

Closed dainkaplan closed 4 years ago

dainkaplan commented 4 years ago

Great VS extension! I am trying to configure a TypescriptToLua project to use breakpoints with your debugger. I've successfully gotten breakpoints to work with the transpiled lua files (i.e. adding break points directly to the generated .lua files), but breakpoints set in the original source-mapped .ts files are entirely ignored.

Could you provide what the project structure should look like or extra information/config on running with love?

My current launch.json looks like this:

{
  "configurations": [
    {
      "type": "lua-local",
      "request": "launch",
      "name": "Debug LÖVE",
      "program": {
        "command": "love"
      },
      "args": ["${workspaceFolder}/game"],
      "sourceRoot": "${workspaceFolder}/src",
      "stopOnEntry": true
    }
  ]
}

Where tstl builds the game to the game folder, and the original TypeScript source resides in src.

I added the require("lldebugger").start() line to the main.ts file. It works with breakpoints directly in the lua files, so I am assuming the debugger is functioning fine and it is just a configuration issue.

Thanks in advance!

dainkaplan commented 4 years ago

In case it's helpful, my tsconfig.json is as follows:

{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "game",
    "lib": ["esnext"],
    "sourceMap": true,
    "types": [
      "love-typescript-definitions", 
      "lua-types/jit"
    ],
    "downlevelIteration" : true
  },
  "tstl": {
    "noImplicitSelf": true,
    "luaTarget": "JIT",
    "luaLibImport": "require",
    "sourceMapTraceback": true
  },
  "exclude": [
    "resources",
    "game"
  ],
  "include": [ "src" ]
}
tomblind commented 4 years ago

I duplicated your setup and found an issue where source map paths weren't correctly handled due to a slight difference in how love passes them to the debugger. I've published a new version with a fix for that issue.

But, you're going to run into the same problem if you store your lua files in subfolders of game, due to a bug in how TypescriptToLua generates source maps: TypeScriptToLua/TypeScriptToLua#855

dainkaplan commented 4 years ago

Thanks @tomblind ! I have confirmed that your fix works for all files located at the source root. And, as you've guessed I have subfolders and for files in those, breakpoints do not trigger.

As a workaround until TypeScriptToLua fixes source map sourceRoots, if I understand your diagnosis correctly, if I opt to transpile in place, at least for debugging, since the lua and ts paths would be the same, breakpoints would work? (I.e. i ditch game/ and generate lua files in place within src/.) Or, do you have any other suggestions for changing config to get things working? I think having a debugger would be a tremendous boon, so happy to change configuration in anyway that enables that!

tomblind commented 4 years ago

Yes, I think generating the lua in place with the ts files should work. Although I believe you need to have them all in game for love to find them, right?

I can't think of another way to structure things right now, since the source maps basically lose any sub-path information.

dainkaplan commented 4 years ago

Although I believe you need to have them all in game for love to find them, right?

Löve can take any folder at start up (including ./) so changing it to /src for debug should be fine.

I’ll give it a go. Thanks again!

tomblind commented 4 years ago

The subfolders issue has been fixed in TSTL (TypeScriptToLua/TypeScriptToLua#859) and was included in the most recent relase (0.33.0) so I'll go ahead and close this issue. Please open new issues if more problems with source maps arrise.