Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

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.

@meta-cla meta-cla bot added the cla signed label Jan 22, 2026
@github-actions

This comment has been minimized.

@asukaminato0721

This comment was marked as resolved.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 22, 2026 17:37
Copilot AI review requested due to automatic review settings January 22, 2026 17:37
@asukaminato0721 asukaminato0721 marked this pull request as draft January 22, 2026 17:38
Copy link

Copilot AI left a 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.rs module implementing conversion logic for both import and from...import statements
  • 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_import function 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);
Copy link

Copilot AI Jan 22, 2026

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.

Suggested change
ruff_python_ast::visitor::walk_stmt(self, stmt);

Copilot uses AI. Check for mistakes.
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 22, 2026 18:28
@github-actions
Copy link

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant