Skip to content
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

Track file renamed/moved events #7325

Open
wants to merge 6 commits into
base: mkondratek/chore/withServer
Choose a base branch
from

Conversation

mkondratek
Copy link
Contributor

@mkondratek mkondratek commented Mar 4, 2025

Fixes sourcegraph/jetbrains#2360.

This PR adds missing handling for onDidRenameFiles events.

Test plan

Note: It refers to JB Client.

Test Case 1: File Rename Operation

Setup:

project/
├── src/
│   └── foo.txt

Steps:

  1. Open foo.txt in editor
  2. Trigger Cody's "Edit Code" action
  3. Verify code lenses appear with Accept/Reject buttons
  4. Use Shift+F6 (or right click / Rename...) to rename foo.txt to bar.txt
  5. Verify:
    • Code lenses remain visible after rename
    • Accept button successfully dismisses the lenses
    • New file path is correctly reflected

Test Case 2: File Move Operation

Setup:

project/
├── src/
│   └── foo.txt
└── dest/

Steps:

  1. Open src/foo.txt in editor
  2. Trigger Cody's "Edit Code" action
  3. Verify code lenses appear with Accept/Reject buttons
  4. Drag and drop foo.txt from src/ to dest/ folder
  5. Verify:
    • Code lenses remain visible after move
    • Accept button successfully dismisses the lenses
    • File path updated to reflect new location

Expected Behavior

  • Code lenses should remain functional after file operations
  • Accept/Reject buttons should work properly
  • File path references should be updated in Cody's internal state

@mkondratek mkondratek self-assigned this Mar 4, 2025

override fun elementRenamed(p0: PsiElement) = notifyAgent(p0)

private fun notifyAgent(p0: PsiElement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you name that p0 meaningfully?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


private fun notifyAgent(p0: PsiElement) {
val uriAfter = uriFor(p0.containingFile.virtualFile)
assert(uriBefore != uriAfter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to crash if they are the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I put

    val uriBefore = uriFor(element.containingFile.virtualFile)

inside notifyAgent.

It turns out that at the moment we run that expression it evaluates to the same thing as uriAfter.

I do not see any other scenario for this assert to fail than a careless refactor. This assert is a safeguard.

@mkondratek mkondratek force-pushed the mkondratek/fix/didRename branch from 6290fcf to 699dba8 Compare March 6, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants