add code lens run command for test and main #2361#2397
add code lens run command for test and main #2361#2397asukaminato0721 wants to merge 16 commits intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds LSP CodeLens support to Pyrefly for running __main__ blocks and executing pytest/unittest-style tests, with corresponding VS Code extension commands to run files/tests from the editor.
Changes:
- Implemented CodeLens entry collection in the Rust LSP (detecting
if __name__ == "__main__"and test functions/classes). - Added LSP request handling + capability advertisement for
textDocument/codeLens. - Added VS Code extension commands (
pyrefly.runMain,pyrefly.runTest) and test fixtures/interaction coverage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pyrefly/lib/lsp/non_wasm/code_lens.rs | Adds AST-based collection of CodeLens entries for tests and main-guards. |
| pyrefly/lib/lsp/non_wasm/server.rs | Advertises CodeLens capability and handles CodeLensRequest by converting entries to LSP CodeLens commands. |
| pyrefly/lib/lsp/non_wasm/workspace.rs | Adds disabled_language_services.code_lens support for request gating. |
| pyrefly/lib/lsp/non_wasm/mod.rs | Exposes the new code_lens module. |
| pyrefly/lib/test/lsp/lsp_interaction/code_lens.rs | Adds integration-style LSP interaction test validating returned CodeLens commands/args. |
| pyrefly/lib/test/lsp/lsp_interaction/mod.rs | Registers the new code_lens test module. |
| pyrefly/lib/test/lsp/lsp_interaction/test_files/code_lens/main_and_tests.py | Test fixture containing pytest/unittest patterns + __main__ guard. |
| lsp/src/extension.ts | Adds command handlers to run main files/tests via an integrated terminal (and intended Testing API fallback). |
| lsp/package.json | Contributes the new VS Code commands in the extension manifest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pyrefly/lib/test/lsp/lsp_interaction/test_files/code_lens/main_and_tests.py
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pyrefly/lib/test/lsp/lsp_interaction/test_files/code_lens/main_and_tests.py
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
sorry about the delay: two more small requests and then i'm happy with it
|
|
Missing interpreter now shows a more specific error: “Ensure the correct interpreter is selected in your IDE…” Pytest runs now do a preflight import pytest check before launching the task. I did not add a generic “disable this feature” prompt for every task failure after launch, because with ProcessExecution we do not get a reliable structured reason for arbitrary runner failures. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |

Summary
Fixes #2361
Implemented LSP CodeLens generation for pytest/unittest-style tests and
if __name__ == "__main__"with Run/Test commandsAdded VS Code extension commands (pyrefly.runMain, pyrefly.runTest) and wiring to execute main files or trigger the VS Code Testing API at the cursor.
Test Plan
Added LSP interaction coverage and fixtures for CodeLens behavior.