Skip to content

impl show file ref in safe delete #2415#2663

Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2415
Open

impl show file ref in safe delete #2415#2663
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2415

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Mar 5, 2026

Summary

Fixes #2415

Added two unsafe-delete actions for files: Find usages of file ...(opens a reference list via a client command) and Delete file ... anyway.

Implemented import-usage collection to provide exact reference locations for the new command.

Updated the VS Code extension to handle pyrefly.findFileUsages and show the references list.

Test Plan

Adjusted LSP interaction tests to expect the new actions.

@meta-cla meta-cla bot added the cla signed label Mar 5, 2026
@asukaminato0721 asukaminato0721 changed the title impl show file ref impl show file ref in safe delete Mar 5, 2026
@asukaminato0721 asukaminato0721 changed the title impl show file ref in safe delete impl show file ref in safe delete #2415 Mar 5, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review March 5, 2026 06:38
Copilot AI review requested due to automatic review settings March 5, 2026 06: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 extends the safe-delete file feature (from #2415) by adding two new code actions when a file has import usages: "Find usages of file ..." (which opens a reference list via a client command) and "Delete file ... anyway" (which performs the delete regardless of usages). It also includes the corresponding VS Code extension handler for the pyrefly.findFileUsages command and updates tests.

Changes:

  • Refactored safe_delete_file_code_action into safe_delete_file_code_actions to return multiple actions, adding "Find usages" and "Delete anyway" options when imports are found
  • Implemented collect_import_usage_locations to gather exact reference locations (file URI + range) instead of just detecting presence of usages
  • Added VS Code extension command handler (pyrefly.findFileUsages) to display references using editor.action.showReferences

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyrefly/lib/lsp/non_wasm/safe_delete_file.rs Refactored to return multiple code actions and collect usage locations with ranges
pyrefly/lib/lsp/non_wasm/server.rs Updated import and call site for renamed function returning Vec
pyrefly/lib/test/lsp/lsp_interaction/safe_delete_file.rs Updated tests to verify new "Find usages" and "Delete anyway" actions
lsp/src/extension.ts Added pyrefly.findFileUsages command handler to show references
lsp/package.json Registered pyrefly.findFileUsages command in extension manifest

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +136 to +147
CodeActionOrCommand::CodeAction(CodeAction {
title: title.clone(),
command: Some(Command {
title,
command: "pyrefly.findFileUsages".to_owned(),
arguments: Some(vec![json!({
"uri": uri,
"locations": locations,
})]),
}),
..Default::default()
})
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The find_usages_code_action is missing a kind field (defaults to None). Every other code action in this codebase sets a kind (e.g., refactor.delete, refactor.move, quickfix, source.fixAll). While kind is optional per the LSP spec, some clients use CodeActionContext.only to filter actions by kind. Actions without a kind may be unexpectedly hidden or shown depending on the client's filtering logic. Consider setting a kind here, such as CodeActionKind::new("refactor.delete") to be consistent with the sibling "delete anyway" action, or another appropriate kind.

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

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.

2 participants