Skip to content

impl LSP: Navigation support for pytest fixtures #1901#2075

Closed
asukaminato0721 wants to merge 25 commits into
facebook:mainfrom
asukaminato0721:1901
Closed

impl LSP: Navigation support for pytest fixtures #1901#2075
asukaminato0721 wants to merge 25 commits into
facebook:mainfrom
asukaminato0721:1901

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Jan 12, 2026

Copy link
Copy Markdown
Collaborator

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

@meta-cla meta-cla Bot added the cla signed label Jan 12, 2026
@asukaminato0721
asukaminato0721 marked this pull request as ready for review January 12, 2026 13:14
Copilot AI review requested due to automatic review settings January 12, 2026 13:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread pyrefly/lib/state/lsp.rs Outdated
Comment thread pyrefly/lib/state/lsp.rs Outdated
Comment thread pyrefly/lib/state/lsp.rs Outdated
@github-actions

This comment has been minimized.

@kinto0

kinto0 commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

todo: should these pytest functions in their own mod?

for sure. maybe a pyrefly/lib/third_party or something similar?

@github-actions

This comment has been minimized.

Comment thread pyrefly/lib/state/lsp.rs
@meta-codesync

meta-codesync Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

@migeed-z has imported this pull request. If you are a Meta employee, you can view this in D91537491.

Comment thread pyrefly/lib/state/pytest.rs Outdated
Comment thread pyrefly/lib/state/pytest.rs Outdated
Comment thread pyrefly/lib/test/lsp/definition.rs
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Comment thread pyrefly/lib/state/pytest.rs Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@asukaminato0721
asukaminato0721 marked this pull request as draft January 29, 2026 06:59
@asukaminato0721
asukaminato0721 marked this pull request as ready for review January 29, 2026 11:28
@asukaminato0721

Copy link
Copy Markdown
Collaborator Author

@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. ✅

@github-actions github-actions Bot added size/xl and removed size/xl labels May 22, 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. ✅

@asukaminato0721
asukaminato0721 requested a review from kinto0 May 22, 2026 20:37
Comment thread website/docs/configuration.mdx Outdated
Comment thread pyrefly/lib/state/pytest.rs Outdated
Comment thread pyrefly/lib/state/lsp.rs Outdated
@kinto0

kinto0 commented May 22, 2026

Copy link
Copy Markdown
Contributor

a few small nits. I can clean them up on import

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

);
}

#[test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread website/docs/configuration.mdx Outdated
Comment thread pyrefly/lib/binding/bindings.rs Outdated
Comment thread pyrefly/lib/binding/pytest.rs Outdated
Comment thread pyrefly/lib/binding/pytest.rs
Comment thread pyrefly/lib/binding/pytest.rs Outdated
@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. ✅

@github-actions github-actions Bot added size/xl and removed size/xl labels May 27, 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. ✅

@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. ✅

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync

meta-codesync Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@kinto0 merged this pull request in 711d99f.

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.

LSP: Navigation support for pytest fixtures

6 participants