-
Notifications
You must be signed in to change notification settings - Fork 259
impl Convert import to relative path / absolute path (and Convert all... variants) #1589 #2195
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
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.
Pull request overview
This PR implements convert import code actions that allow users to convert between relative and absolute import paths in Python code. The implementation adds both single-import conversion and "convert all" variants, properly integrated with the LSP server.
Changes:
- Added
convert_import.rsmodule implementing conversion logic for bothimportandfrom...importstatements - Wired convert import actions into LSP server with proper code action kind registration
- Added comprehensive tests covering relative-to-absolute and absolute-to-relative conversions
- Made
handle_require_absolute_importfunction public for reuse in the new module
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pyrefly/lib/state/lsp/quick_fixes/convert_import.rs | New module implementing core conversion logic for import statements with support for both relative and absolute paths |
| pyrefly/lib/state/lsp/quick_fixes/mod.rs | Added module declaration for convert_import |
| pyrefly/lib/state/lsp.rs | Added Transaction method to expose convert import code actions |
| pyrefly/lib/state/ide.rs | Changed visibility of handle_require_absolute_import from private to pub(crate) for reuse |
| pyrefly/lib/lsp/non_wasm/server.rs | Registered REFACTOR_REWRITE action kind and integrated convert import actions into code action handler |
| pyrefly/lib/test/lsp/code_actions.rs | Added test helper function and three comprehensive tests covering from-import and import statement conversions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| _ => {} | ||
| } | ||
| ruff_python_ast::visitor::walk_stmt(self, stmt); |
Copilot
AI
Jan 22, 2026
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.
The ImportCollector visitor recursively visits nested statements through walk_stmt, which means it will collect imports from within functions, classes, and other nested scopes. This might not be the expected behavior for "Convert all imports" action, as users typically expect it to only affect top-level module imports. Consider whether this is intentional, and if not, avoid calling walk_stmt to only collect imports at the module's top level.
| ruff_python_ast::visitor::walk_stmt(self, stmt); |
43be138 to
192ae1f
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Fixes part of #1589
Added convert‑import code actions (single + all) for relative/absolute paths, wired them into LSP.
Test Plan
Added tests for both from and import forms.