ruff/crates/ty_server/tests/e2e
Andrew Gallant 52f59c5c39 [ty] Fix auto-import code action to handle pre-existing import
Previously, the code action to do auto-import on a pre-existing symbol
assumed that the auto-importer would always generate an import
statement. But sometimes an import statement already exists.

A good example of this is the following snippet:

```
import warnings

@deprecated
def myfunc(): pass
```

Specifically, `deprecated` exists in `warnings` but isn't currently
imported. A code action to fix this could feasibly do two
transformations here. One is:

```
import warnings

@warnings.deprecated
def myfunc(): pass
```

Another is:

```
from warnings import deprecated
import warnings

@deprecated
def myfunc(): pass
```

The existing auto-import infrastructure chooses the former, since it
reuses a pre-existing import statement. But this PR chooses the latter
for the case of a code action. I'm not 100% sure this is the correct
choice, but it seems to defer more strongly to what the user has typed.
That is, that they want to use it unqualified because it's what has been
typed. So we should add the necessary import statement to make that
work.

Fixes astral-sh/ty#1668
2025-12-01 14:20:47 -05:00
..
snapshots [ty] Fix auto-import code action to handle pre-existing import 2025-12-01 14:20:47 -05:00
code_actions.rs [ty] Fix auto-import code action to handle pre-existing import 2025-12-01 14:20:47 -05:00
commands.rs [ty] Add panic-by-default await methods to `TestServer` (#21451) 2025-11-14 19:47:39 +01:00
initialize.rs [ty] Add panic-by-default await methods to `TestServer` (#21451) 2025-11-14 19:47:39 +01:00
inlay_hints.rs [ty] Double click to insert inlay hint (#21600) 2025-11-24 19:48:30 +00:00
main.rs [ty] Add 'remove unused ignore comment' code action (#21582) 2025-11-25 08:08:21 -05:00
notebook.rs [ty] Add panic-by-default await methods to `TestServer` (#21451) 2025-11-14 19:47:39 +01:00
publish_diagnostics.rs [ty] Add panic-by-default await methods to `TestServer` (#21451) 2025-11-14 19:47:39 +01:00
pull_diagnostics.rs [ty] Add panic-by-default await methods to `TestServer` (#21451) 2025-11-14 19:47:39 +01:00