typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Debugging emitters -- how to attach VSCode debugger?

Open marron-at-work opened this issue 3 years ago • 2 comments

Remarkably when working on some TypeSpec emitter code I made a mistake somewhere :-)

I wanted to hookup the debugger in VSCode but I am not having any luck with the launch.json file and finding the right configuration. I am not sure if I am just missing something obvious or if there is a special trick that is needed.

Running on Windows 11, Typescript 5.0, Node 16.13, VSCode with March 23 update, and the 0.42 version of the compiler and emitter-framework.

Thanks

marron-at-work avatar Mar 24 '23 17:03 marron-at-work

This is one of the configuration in launch.json we have to debug compiling a spec(./samples/sratch)

{
      "type": "node",
      "request": "launch",
      "name": "Compile Scratch",
      "program": "${workspaceFolder}/packages/compiler/dist/core/cli/cli.js",
      "args": [
        "compile",
        "../samples/scratch",
        "--output-dir=temp/scratch-output",
        "--emit=@typespec/openapi3"
      ],
      "smartStep": true,
      "sourceMaps": true,
      "skipFiles": ["<node_internals>/**/*.js"],
      "outFiles": [
        "${workspaceFolder}/packages/*/dist/**/*.js",
        "${workspaceFolder}/packages/*/dist-dev/**/*.js"
      ],
      "cwd": "${workspaceFolder}/packages/compiler",
      "presentation": {
        "order": 2
      }
    },

timotheeguerin avatar Mar 24 '23 17:03 timotheeguerin

Hi @timotheeguerin, that was a little funny but with some hacking I got your config to work! In case someone else hits this here is what I altered:

First change is that I am using the npm installed compiler so I was needed to change the program path to point to it. node_modules/@typespec/compiler/dist/core/cli/cli.js instead of ${workspaceFolder}/packages/compiler/dist/core/cli/cli.js

Second I need to fix the cwd to match my project and (delete) the outfiles.

marron-at-work avatar Mar 24 '23 17:03 marron-at-work