impl LSP: Navigation support for pytest fixtures #1901#2075
impl LSP: Navigation support for pytest fixtures #1901#2075asukaminato0721 wants to merge 25 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements LSP navigation support for pytest fixtures, enabling go-to-definition and find-references functionality for fixture parameters in test functions. When a developer invokes go-to-definition on a fixture parameter (e.g., my_fixture in def test_thing(my_fixture):), the LSP will navigate to the fixture definition. Similarly, finding references on a fixture definition will include all test/fixture functions that use it as a parameter.
Changes:
- Added pytest import and fixture detection logic to identify pytest modules and fixture decorators
- Implemented fixture discovery and parameter scanning to collect fixture definitions and their usage in test functions
- Integrated pytest fixture resolution into LSP go-to-definition and find-references operations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pyrefly/lib/state/lsp.rs | Core implementation: added PytestAliases tracking, fixture detection functions, and integrated pytest-aware parameter resolution into LSP operations |
| pyrefly/lib/test/lsp/definition.rs | Added test verifying go-to-definition navigation from fixture parameters to fixture definitions |
| pyrefly/lib/test/lsp/local_find_refs.rs | Added test verifying find-references includes injected fixture parameters in test functions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
for sure. maybe a pyrefly/lib/third_party or something similar? |
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.
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.
|
https://stackoverflow.com/questions/77318902/why-using-yield-instead-of-return-in-pytest-fixtures aa, not only return but yield |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
a few small nits. I can clean them up on import |
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
| ); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
from @yangdanny97 :
do we want tests to check what happens if the parameter name doesn't exist as a function somewhere, or if the function exists but isn't a fixture, or if the function we're trying GTD isn't a top-level test function?
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #1901
Implemented pytest import/alias detection plus fixture discovery and parameter scanning in pyrefly/lib/state/lsp.rs, and hooked it into go‑to‑definition and local references.
todo: should these pytest functions in their own mod?
Test Plan
cargo test pytest_fixture_parameter_goes_to_fixture_definition
cargo test pytest_fixture_references_include_injected_parameters