Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the Safe Delete feature for Pyrefly, addressing part of issue #2207. The implementation provides two levels of safe deletion:
-
Symbol-level safe delete: Allows deletion of unused functions, methods, classes, variables, constants, and type aliases within a file. Uses global reference finding across all reverse dependencies to ensure the symbol is truly unused.
-
File-level safe delete: Enables deletion of entire Python files when no import usages are detected. Uses AST-based import scanning across reverse dependencies to verify safety.
Changes:
- Added symbol-level safe delete using global reference checking
- Added file-level safe delete using import usage analysis
- Introduced
refactor.deleteCodeActionKind for LSP clients - Added comprehensive test coverage for both deletion types
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pyrefly/lib/state/lsp/quick_fixes/safe_delete.rs |
Implements symbol-level safe delete with reference checking |
pyrefly/lib/lsp/non_wasm/safe_delete_file.rs |
Implements file-level safe delete with import usage scanning |
pyrefly/lib/state/lsp.rs |
Adds find_global_references_from_definition and supporting methods |
pyrefly/lib/lsp/non_wasm/server.rs |
Integrates safe delete actions into LSP server and registers refactor.delete kind |
pyrefly/lib/test/lsp/code_actions.rs |
Unit tests for symbol-level safe delete |
pyrefly/lib/test/lsp/lsp_interaction/safe_delete_file.rs |
LSP interaction tests for file-level safe delete |
| Test fixtures | Example Python files for testing safe delete scenarios |
| Module files | Updates to module structure to include new safe delete modules |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
25861e8 to
23adbca
Compare
This comment has been minimized.
This comment has been minimized.
23adbca to
b787696
Compare
This comment has been minimized.
This comment has been minimized.
|
@asukaminato0721 I am working on getting this in now. Could you just resolve the merge conflict here first? |
b787696 to
3b00c71
Compare
3b00c71 to
51b2d1a
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
No diffs to classify. |
Summary
Fixes part of #2207
Added a file-level Safe Delete code action that deletes a Python file only when no import usages are found, using a workspace edit DeleteFile operation and a new refactor.delete kind.
Implemented an AST-based import usage scan across reverse dependencies to decide safety.
note: for simplicity, I didn't impl find ref and delete anyway yet. will add in the future.
Test Plan
Added LSP interaction tests and fixtures for safe delete.