-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Respect notebook cell boundaries when adding an auto import #21322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
7e31390 to
d5de564
Compare
a9dae9e to
fbbed61
Compare
|
| [[profile.default.overrides]] | ||
| filter = 'binary(e2e)' | ||
| test-group = 'serial' | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this intended to be checked in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of. My hope was that it makes the lsp e2e tests less flaky
Gankra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, when we were talking about it before I had convinced myself this would fall out more naturally from treating the cells as separate files, but I guess we're (reasonably) treating the notebooks as one file still.
BurntSushi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
249643e to
7a1fad3
Compare
fbbed61 to
b3e4db8
Compare
crates/ty_ide/src/importer.rs
Outdated
| // What we want here: Given an offset, return the range of that cell. I guess that's what containing range is | ||
| let range = source_text(self.db, self.file) | ||
| .as_notebook() | ||
| .and_then(|notebook| notebook.cell_offsets().containing_range(members.at)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this comment is correct. The containing_range will return the cell range that contains this offset.
0f3fc0f to
86c98f8
Compare
Enable auto-import functionality for notebook cells with proper scoping to ensure import edits are restricted to the current cell rather than spanning across cells. Changes: - Update Insertion::start_of_file to accept optional within_range parameter - When provided, restricts import placement to statements within that range - Allows per-cell import handling in notebooks - Update importer logic to handle notebook cell boundaries - Find cell range for the position where import is needed - Pass cell range to restrict import insertion to current cell - Skip imports from other cells when searching for existing imports - Ensure import insertions respect cell document URIs - Add tests verifying auto-import works correctly in notebooks - Verify imports aren't added to different cells This ensures that when auto-completing in a notebook cell, suggested imports are added to the current cell only, not to import statements in other cells.
ac99544 to
d550ea9
Compare
|
I marked this as internal because notebook support hasn't shipped yet. So this isn't a user visible change |
* origin/main: (59 commits) [ty] Improve diagnostic range for `non-subscriptable` diagnostics (#21461) [ty] Improve literal promotion heuristics (#21439) [ty] Further improve details around which expressions should be deferred in stub files (#21456) [ty] Improve generic class constructor inference (#21442) [ty] Propagate type context through conditional expressions (#21443) [ty] Suppress completions when introducing names with `as` [ty] Add panic-by-default await methods to `TestServer` (#21451) [ty] name is parameter and global is a syntax error (#21312) [ty] Fixup a few details around version-specific dataclass features (#21453) [ty] Support attribute-expression `TYPE_CHECKING` conditionals (#21449) [ty] Support stringified annotations in value-position `Annotated` instances (#21447) [ty] Type inference for genererator expressions (#21437) [ty] Make `__getattr__` available for `ModuleType` instances (#21450) [ty] Increase default receive timeout in tests to 10s (#21448) [ty] Add synthetic members to completions on dataclasses (#21446) [ty] Support legacy `typing` special forms in implicit type aliases (#21433) Bump 0.14.5 (#21435) [ty] Support `type[…]` and `Type[…]` in implicit type aliases (#21421) [ty] Respect notebook cell boundaries when adding an auto import (#21322) Update PyCharm setup instructions (#21409) ...
Summary
The text edits for auto-completion are constrained to within the same document (because there's only a range but no URI field). Given that the LSP represents each cell as a separate document, this means that auto import edits must be limited to the same cell (we can't change an import from another cell or add an import to the first cell).
This PR does just that.
Test plan
Added e2e tests