Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes part of #364

Implemented LSP refactor actions to mirror PyCharm’s “convert module ↔ package” behavior: module→package renames foo.py to foo/__init__.py, and package→module is only offered when the package directory contains only __init__.py (empty package), keeping content in __init__.py as the module body.

Added workspace-edit refactor actions (rename + delete operations; gated on client support for documentChanges/resourceOperations).

Test Plan

Added LSP interaction tests and fixtures.

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

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 13, 2026 16:59
Copilot AI review requested due to automatic review settings January 13, 2026 16:59
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 LSP refactor actions for converting between Python modules and packages, mirroring PyCharm's behavior. A module (e.g., foo.py) can be converted to a package (foo/__init__.py), and an empty package (containing only __init__.py and optionally __pycache__) can be converted back to a module.

Changes:

  • Added workspace edit support for file rename and delete operations
  • Implemented bidirectional module-package conversion code actions
  • Added comprehensive LSP interaction tests

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

File Description
pyrefly/lib/lsp/non_wasm/server.rs Added helper functions to check workspace edit capabilities, validate empty packages, and generate convert module/package code actions with appropriate rename and delete operations
pyrefly/lib/test/lsp/lsp_interaction/convert_module_package.rs Added tests verifying both module-to-package and package-to-module conversion code actions with proper workspace edit operations
pyrefly/lib/test/lsp/lsp_interaction/mod.rs Registered the new test module
pyrefly/lib/test/lsp/lsp_interaction/test_files/convert_module_package/*.py Added test fixtures for module and empty package conversion scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the new helpers be in a dedicated module rather than server.rs? I think in general we're trying to avoid too much growth in the central LSP modules as we add refactoring capabilities which often require a lot of code

@stroxler stroxler self-assigned this Jan 14, 2026
@asukaminato0721 asukaminato0721 force-pushed the 364-6 branch 2 times, most recently from 4a272c5 to cb39cb1 Compare January 15, 2026 01:56
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

.

.

fmt
@github-actions
Copy link

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

@meta-codesync
Copy link

meta-codesync bot commented Jan 15, 2026

@stroxler has imported this pull request. If you are a Meta employee, you can view this in D90779991.

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.

2 participants