From c0fbb93ee4e74500f03e596457ae2e4841444ae4 Mon Sep 17 00:00:00 2001 From: Lucian Wischik Date: Sun, 25 Feb 2024 14:26:06 -0800 Subject: [PATCH] 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 --- .vscode/launch.json | 15 +++++++++++++++ docs/build-debug.md | 2 +- packages/pyright-internal/debug.js | 2 ++ packages/pyright-internal/tsconfig.json | 6 ++++-- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 packages/pyright-internal/debug.js diff --git a/.vscode/launch.json b/.vscode/launch.json index c4190bb21..1cc3bf95d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,21 @@ "${workspaceRoot}/packages/pyright/dist/**/*.js" ] }, + { + "name": "Pyright CLI (pyright-internal)", + "type": "node", + "request": "launch", + "program": "${workspaceRoot}/packages/pyright-internal/debug.js", + "args": [ + "--typeshedpath", + "${workspaceRoot}/packages/pyright-internal/typeshed-fallback", + "--version", + ], + "internalConsoleOptions": "openOnSessionStart", + "outFiles": [ + "${workspaceRoot}/packages/pyright-internal/out/**/*.js" + ] + }, { "name": "Pyright tests", "type": "node", diff --git a/docs/build-debug.md b/docs/build-debug.md index 101d4364b..29a75efc7 100644 --- a/docs/build-debug.md +++ b/docs/build-debug.md @@ -32,7 +32,7 @@ To install in VS Code, go to the extensions panel and choose “Install from VSI ## 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. +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. diff --git a/packages/pyright-internal/debug.js b/packages/pyright-internal/debug.js new file mode 100644 index 000000000..39f3c7ce8 --- /dev/null +++ b/packages/pyright-internal/debug.js @@ -0,0 +1,2 @@ +// This is an entry-point for debugging the pyright CLI +require('./out/packages/pyright-internal/src/pyright').main(); \ No newline at end of file diff --git a/packages/pyright-internal/tsconfig.json b/packages/pyright-internal/tsconfig.json index d32e800c2..6ffa901b5 100644 --- a/packages/pyright-internal/tsconfig.json +++ b/packages/pyright-internal/tsconfig.json @@ -8,11 +8,13 @@ "include": [ "src/**/*", "src/localization/*.json", - "**/*.js" + "**/*.js", + "package.json", ], "exclude": [ "node_modules", "dist", - "out" + "out", + "debug.js", ] }