Skip to content

add code lens run command for test and main #2361#2397

Open
asukaminato0721 wants to merge 16 commits intofacebook:mainfrom
asukaminato0721:2361
Open

add code lens run command for test and main #2361#2397
asukaminato0721 wants to merge 16 commits intofacebook:mainfrom
asukaminato0721:2361

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

Summary

Fixes #2361

Implemented LSP CodeLens generation for pytest/unittest-style tests and if __name__ == "__main__" with Run/Test commands

Added 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.

> '/usr/bin/python' -m unittest 'main.TestT.test_'
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

> '/usr/bin/python' -m unittest 'main.TestT'
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

> '/usr/bin/python' '/tmp/tmp/main.py'
Hello from tmp!

@meta-cla meta-cla bot added the cla signed label Feb 12, 2026
@asukaminato0721 asukaminato0721 changed the title fix add code lens for test and may be main? fix add code lens for test and may be main? #2361 Feb 12, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 12, 2026 17:49
Copilot AI review requested due to automatic review settings February 12, 2026 17:49
@asukaminato0721 asukaminato0721 marked this pull request as draft February 12, 2026 17:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

asukaminato0721 and others added 4 commits February 13, 2026 02:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions bot added the stale label Mar 1, 2026
@yangdanny97 yangdanny97 removed their assignment Mar 11, 2026
@yangdanny97 yangdanny97 requested review from jvansch1 and kinto0 March 11, 2026 19:33
@kinto0 kinto0 self-assigned this Mar 16, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 16, 2026

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D96792757.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@asukaminato0721
Copy link
Copy Markdown
Contributor Author

asukaminato0721 commented Mar 19, 2026

image

now it would just run and error.

@github-actions

This comment has been minimized.

@kinto0
Copy link
Copy Markdown
Contributor

kinto0 commented Mar 25, 2026

sorry about the delay: two more small requests and then i'm happy with it

  • can we add more details to the error message? something like "ensure the correct interpreter is selected in your IDE" for the interpreter not found and something actionable for the pytest not found error?
  • should we prompt them to disable this editor setting if it does fail

@asukaminato0721
Copy link
Copy Markdown
Contributor Author

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.
If that fails, the user gets an actionable error telling them to select the correct interpreter or install pytest in that environment.

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.

@asukaminato0721 asukaminato0721 requested a review from kinto0 March 26, 2026 00:40
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approach seems good to me now, thanks for the back/forth. will get some more eyes on it

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some suggestions

@github-actions github-actions bot added size/xl and removed size/xl labels Mar 28, 2026
@asukaminato0721 asukaminato0721 requested a review from kinto0 March 28, 2026 00:17
@github-actions

This comment has been minimized.

@github-actions github-actions bot added size/xl and removed size/xl labels Mar 28, 2026
@github-actions
Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add code lens for test and may be main?

4 participants