mirror of https://github.com/astral-sh/ruff
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 |
||
|---|---|---|
| .. | ||
| all_symbols.rs | ||
| code_action.rs | ||
| completion.rs | ||
| doc_highlights.rs | ||
| docstring.rs | ||
| document_symbols.rs | ||
| find_node.rs | ||
| find_references.rs | ||
| goto.rs | ||
| goto_declaration.rs | ||
| goto_definition.rs | ||
| goto_type_definition.rs | ||
| hover.rs | ||
| importer.rs | ||
| inlay_hints.rs | ||
| lib.rs | ||
| markup.rs | ||
| references.rs | ||
| rename.rs | ||
| selection_range.rs | ||
| semantic_tokens.rs | ||
| signature_help.rs | ||
| stub_mapping.rs | ||
| symbols.rs | ||
| workspace_symbols.rs | ||