tomblind / local-lua-debugger-vscode

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

Correctly parse absolute paths on macOS & Linux in some cases #33

Closed astrochili closed 3 years ago

astrochili commented 3 years ago

https://github.com/tomblind/local-lua-debugger-vscode/blob/9849009ef3b9685d7a279fb0ab7b32b7a930ea2d/debugger/path.ts#L61

Do we really need to get the drive in this case?

I don't know about Windows but, for example, on macOS the path '/path/to/there.lua' will be separated to '/' and 'path/to/there.lua' that is not correct. In this case file breakpoints and sources in the stack doesn't work. So I change

[drive, pathPart] = path.match('^[@=]?([\\/]*)(.*)');

to

drive = ''
[drive, pathPart] = path.match(`^[@=]?[\\/]*(.*)`);

and then everything works fine because isAbsolute function also begins to work correctly. I think there is no way to detect is path the absolute or not on macOS and Linux by parsing the string.

The bugfix can make to be possible to use local-lua-debugger with Defold engine. I'm ready to prepare pull request with the instruction how to do it.

astrochili commented 3 years ago

Created a guide How to get VSCode to be Defold IDE with using this debugger. It includes modified lldebugger.lua module with local fixes of https://github.com/tomblind/local-lua-debugger-vscode/issues/33 and https://github.com/defold/defold/issues/5703

tomblind commented 3 years ago

I'll look into what's going on here as I've tested this on linux and so it may be new bug.

tomblind commented 3 years ago

Sorry, just getting back around to this.

Can you give me an example of where this is breaking? drive is used to determine if it's absolute which is why it's split off even in unix and in format it is prepended back onto the path, so this should be working correctly as far as I can tell.

thejustinwalsh commented 3 years ago

I think I have a line on this error, as I am seeing (formatted for clarity)...

[message]
{
   "tag":"$luaDebug",
   "type":"stack",
   "frames":[
      {
         "line":20,
         "source":"scripts/main.script",
         "mappedLocation":{
            "line":25,
            "source":"Users/thejustinwalsh/Projects/ts-defold/tsd-template/app/scripts/Users/thejustinwalsh/Projects/ts-defold/tsd-template/src/scripts/main.script.ts",
            "column":9
         },
         "active":true
      }
   ]
}

In the debugger verbose output.

The source map paths are defined as...

{
   "version":3,
   "sources":[
      "/Users/thejustinwalsh/Projects/ts-defold/tsd-template/src/scripts/main.script.ts"
   ],
   "names":[
      "this"
   ],
   "file":"/Users/thejustinwalsh/Projects/ts-defold/tsd-template/src/scripts/main.script",
   "sourceRoot":""
}

It appears that an absolute path is being appended on-top of a relative path to the source roots.


tsconfig.json

{
    "$schema": "https://raw.githubusercontent.com/TypeScriptToLua/vscode-typescript-to-lua/master/tsconfig-schema.json",
    "compilerOptions": {
        "target": "es2019",
        "lib": ["es2019"],
        "module": "commonjs",
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "types": ["@ts-defold/types", "typescript-to-lua/language-extensions"],
        "typeRoots": ["@types", "node_modules/@types"],

        "rootDir": "src",
        "outDir": "app",
        "strict": true,
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "sourceMap": true,

        "plugins": [{ "name": "typescript-tstl-plugin" }],
    },
    "exclude": [
        "./node_modules/*",
        "./plugins/*"
    ],
    "tstl": {
        "luaTarget": "5.1",
        "luaLibImport": "require",
        "sourceMapTraceback": true,
        "trimExtensions": true,
        "luaPlugins": [
            {
                "name": "@ts-defold/tstl-export-as-global",
                "match": ".*\\.(?!editor_)script.ts$",
                "globals": { 
                    "functions": [ "init", "on_input", "on_message", "on_reload", "update", "final"]
                }
            },
            {
                "name": "@ts-defold/tstl-userdata-sugar"
            }
        ]
    }
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "Debug",
          "type": "lua-local",
          "request": "launch",
          "stopOnEntry": false,
          "verbose": true,
          "internalConsoleOptions": "openOnSessionStart",
          "program": { "command": "bash" },
          "osx": { "args": [".ts-defold/defold.sh", "launch", "macOS"] },
          "linux": { "args": [".ts-defold/defold.sh", "launch", "Linux"] },
          "windows": {
              "args": [".ts-defold/defold.sh", "launch", "Windows"],
              "program": { "command": "C:/Program Files/Git/bin/bash" }
          },
          "scriptRoots": [
              "app",
          ]
      }
  ]
}
thejustinwalsh commented 3 years ago

From the comment above if I run the two methods in the console...

image
tomblind commented 3 years ago

The absolute path in sourcemaps is fixed, but I'm not sure this is the same issue, so I'm leaving this open for now.

astrochili commented 3 years ago

Sorry guys, I can’t check the case again at the moment. I’m migrated to Apple Silicon M1 but Defold building system ‘bob.jar' doesn’t work with M1 at the moment, so I just waiting for Defold updates.

thejustinwalsh commented 3 years ago

@astrochili I'm on an M1 as well, I just haven't tried to build with bob.jar yet. Everything else is working great though. :) HMU if there is anything I can do to test / help in the meantime.

thejustinwalsh commented 3 years ago

@astrochili is #40 the same bug?

astrochili commented 3 years ago

Times change quickly, the M1 bug in Defold was fixed few months ago, so I'll check it out soon.

astrochili commented 3 years ago

@astrochili is #40 the same bug?

I'm not sure, but with this #33 breakpoints also didn't work, because the debugger didn't understand what file they are in.

astrochili commented 3 years ago

Checked it. After https://github.com/tomblind/local-lua-debugger-vscode/commit/46806ca91a58a43ba100094af8c70623b7365832 the paths and breakpoints work now in my case. Closed :)