pyright/docs/build-debug.md
Lucian Wischik c0fbb93ee4
Debugging (#7332)
* launch.json CLI debug that bypasses webpack

I got a bit irritated in my edit-build-debug inner loop with the time to run webpack.

This commit adds a new launch target called "Pyright CLI (pyright-internal)" which bypasses webpack and just runs the package straight from the packages/pyright-internal/out directory where tsc has built it.

* fix outFiles directive

The VSCode docs say about outFiles:
> By default, VS Code will search your entire workspace, excluding node_modules, for sourcemaps. In large workspaces, this search might be slow. You can configure the locations where VS Code will search for source maps by setting the outFiles attribute in your launch.json.

I guess this is the right change to make? it didn't make any difference in VSCode debugger's ability to hit breakpoints, though.

---------

Co-authored-by: Eric Traut <eric@traut.com>
2024-02-25 15:26:06 -07:00

2.4 KiB

Building Pyright

To install the dependencies for all packages in the repo:

  1. Install nodejs version 16.x
  2. Open terminal window in main directory of cloned source
  3. Execute npm run install:all to install dependencies for projects and sub-projects

Building the CLI

  1. cd to the packages/pyright directory
  2. Execute npm run build

Once built, you can run the command-line tool by executing the following:

node index.js

Building the VS Code extension

  1. cd to the packages/vscode-pyright directory
  2. Execute npm run package

The resulting package (pyright-X.Y.Z.vsix) can be found in the client directory. To install in VS Code, go to the extensions panel and choose “Install from VSIX...” from the menu, then select the package.

Running Pyright tests

  1. cd to the packages/pyright-internal directory
  2. Execute npm run test

Debugging Pyright

To debug pyright, open the root source directory within VS Code. Open the debug sub-panel and choose “Pyright CLI” from the debug target menu. Click on the green “run” icon or press F5 to build and launch the command-line version in the VS Code debugger. There's also a similar option that provides a slightly faster build/debug loop: make sure you've built the pyright-internal project e.g. with Terminal > Run Build Task > tsc: watch, then choose “Pyright CLI (pyright-internal)”.

To debug the VS Code extension, select “Pyright extension” from the debug target menu. Click on the green “run” icon or press F5 to build and launch a second copy of VS Code with the extension. Within the second VS Code instance, open a python source file so the pyright extension is loaded. Return to the first instance of VS Code and select “Pyright extension attach server” from the debug target menu and click the green “run” icon. This will attach the debugger to the process that hosts the type checker. You can now set breakpoints, etc.

To debug the VS Code extension in watch mode, you can do the above, but select “Pyright extension (watch mode)”. When pyright's source is saved, an incremental build will occur, and you can either reload the second VS Code window or relaunch it to start using the updated code. Note that the watcher stays open when debugging stops, so you may need to stop it (or close VS Code) if you want to perform packaging steps without the output potentially being overwritten.