vscode-js-debug icon indicating copy to clipboard operation
vscode-js-debug copied to clipboard

[DAP] Example/Test case debugging TypeScript

Open mickaelistria opened this issue 1 year ago • 3 comments

With #902 being resolved, I happily manage to use vscode-js-debug for JS files in Eclipse IDE using pwa-node. However, despite having attempted a bunch of things according to various docs or examples I've seen, I didn't manage yet to debug even the simplest typescript example:

let user:string = "Eclipse User";
console.log("Hello world,, " + user  + '!');

with a tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "lib": ["es6", "dom"],
    "allowJs": true,
    "sourceMap": true,
    "outDir": ".build/",
    "strict": true,
    "noImplicitAny": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

and .js and .js.map files in the .build/ folder.

The issue I see is that the DAP seems to always interpret my file as a .js file and complains it cannot be parsed.

{  "jsonrpc": "2.0",
  "method": "output",
  "params": {
    "category": "stderr",
    "output": "Uncaught SyntaxError /home/mistria/git/wildwebdeveloper/org.eclipse.wildwebdeveloper.tests/testProjects/HelloWorldTS/index.ts:1\nlet user:string \u003d \"Eclipse User\";\n        ^\n\nSyntaxError: Unexpected token \u0027:\u0027\n    at internalCompileFunction (node:internal/vm:73:18)\n    at wrapSafe (node:internal/modules/cjs/loader:1178:20)\n    at Module._compile (node:internal/modules/cjs/loader:1220:27)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)\n    at Module.load (node:internal/modules/cjs/loader:1119:32)\n    at Module._load (node:internal/modules/cjs/loader:960:12)\n    at executeUserEntryPoint (node:internal/modules/run_main:86:12)\n    at \u003canonymous\u003e (node:internal/main/run_main_module:23:47)\n",
    "variablesReference": 2
  }
}

and here is the launch request sent by the client to the Debug Adapter:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "launch",
  "params": {
    "outFiles": [
      "/home/mistria/git/wildwebdeveloper/org.eclipse.wildwebdeveloper.tests/testProjects/HelloWorldTS/.build/**/*.js"
    ],
    "request": "launch",
    "cwd": "/home/mistria/git/wildwebdeveloper/org.eclipse.wildwebdeveloper.tests/testProjects/HelloWorldTS",
    "noDebug": false,
    "runtimeExecutable": "/home/mistria/apps/eclipse-SDK/.node/node-v18.18.0-linux-x64/bin/node",
    "program": "/home/mistria/git/wildwebdeveloper/org.eclipse.wildwebdeveloper.tests/testProjects/HelloWorldTS/index.ts",
    "type": "pwa-node",
    "sourceMaps": true,
    "outDir": "/home/mistria/git/wildwebdeveloper/org.eclipse.wildwebdeveloper.tests/testProjects/HelloWorldTS/.build"
  }
}

I suspect there are some params I'm missing in the request, but I can't find a way to determine which one(s) are necessary for proper execution. Does anyone have a clue? The best format would be an automated test case to show what's need for TS debugging.

mickaelistria avatar Oct 07 '23 19:10 mickaelistria

The program should be the compiled JavaScript code, not Typescript. Things look alright otherwise.

connor4312 avatar Oct 07 '23 22:10 connor4312

OK, thanks. I could verify it works. Do you think the debug adapter could take care of that resolution from .ts to .js? If not, I'll just close the issue, if yes, I will rephrase the title to make it read more like a feature request.

mickaelistria avatar Oct 08 '23 20:10 mickaelistria

Actually, that should work. I thought it was in a different layer that the DAP server didn't have.

https://github.com/microsoft/vscode-js-debug/blob/2bf84580011121e751e98bf648e28f50edafb3b5/src/targets/node/nodeLauncher.ts#L292

Not sure entirely what's going wrong without debugging it some more; I can see if I can reproduce it with a pure DAP server in next debt week. PR's also welcome if you're feeling intrepid.

connor4312 avatar Oct 09 '23 16:10 connor4312