Skip to content

Fix types/provide-type resolving the wrong token in notebook cells#3947

Open
qnox wants to merge 1 commit into
facebook:mainfrom
qnox:fix/notebook-provide-type-wrong-cell
Open

Fix types/provide-type resolving the wrong token in notebook cells#3947
qnox wants to merge 1 commit into
facebook:mainfrom
qnox:fix/notebook-provide-type-wrong-cell

Conversation

@qnox

@qnox qnox commented Jun 25, 2026

Copy link
Copy Markdown

Summary

provide_type passed the request position straight to from_lsp_position(position, None), ignoring the notebook cell. For a cell other than the first, an LSP position is cell-relative, so dropping the cell offset resolves the position in the concatenated module at the wrong line - landing in an earlier cell. The IDE drives hover/type resolution (and the completion-trigger type lookup) through this method, so types in every cell after the first came back wrong or empty.

Thread the code-cell index (as the completion handler already does) through provide_type and translate the position with it so cell-relative positions map to the correct concatenated-module offset.

Test Plan

Added a regression test test_notebook_provide_type_second_cell in pyrefly/lib/test/lsp/lsp_interaction/notebook_provide_type.rs: requests the type of bar in the second cell and asserts typing.Literal[1]. Fails on main (wrong cell resolved), passes with the fix.

  • cargo test -p pyrefly test_notebook_provide_type
  • python3 test.py --no-test --no-conformance --no-jsonschema

Summary:
`provide_type` passed the request position straight to
`from_lsp_position(position, None)`, ignoring the notebook cell. For a
cell other than the first, an LSP position is cell-relative, so dropping
the cell offset resolves the position in the concatenated module at the
wrong line — landing in an earlier cell. The IDE drives hover/type
resolution (and the completion-trigger type lookup) through this method,
so types in every cell after the first came back wrong or empty.

Thread the code-cell index (as the completion handler already does)
through `provide_type` and translate the position with it, so cell-relative
positions map to the correct concatenated-module offset.
@meta-cla

meta-cla Bot commented Jun 25, 2026

Copy link
Copy Markdown

Hi @qnox!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@yangdanny97

Copy link
Copy Markdown
Contributor

Thanks! Once the CLA is signed we can merge it

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

@NathanTempest

NathanTempest commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Hi @qnox thank you for the fix, it is a hard requirement to sign the CLA before contributing to Pyrefly. We are glad to have you aboard and for us to merge your PR after you sign this https://code.facebook.com/cla/individual

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants