Skip to content

Auto-unbind bound destination when file is renamed #613

@couimet

Description

@couimet

Summary

When a bound text editor destination's file is renamed, the binding still points to the old URI. While less critical than file deletion (the file still exists at the new path), the stale binding is incorrect and should be cleaned up automatically.

Following the same established pattern as terminal-close, editor-close, and file-deletion auto-unbind, RangeLink should listen to vscode.workspace.onDidRenameFiles and auto-unbind when a renamed file matches the bound text editor destination.

Details

Listener registration

Add an onDidRenameFiles listener in BoundDestinationLifecycle, co-located with the existing onDidCloseTerminal, onDidCloseTextDocument, and onDidDeleteFiles listeners.

Detection logic

When onDidRenameFiles fires with a FilesRenameEvent containing one or more { oldUri, newUri } pairs, compare each oldUri against the current bound destination's URI (for text-editor type destinations). If matched, trigger the unbind.

Unbind behavior

  • Call unbind({ silent: true }) to remove the binding without a full toast.
  • Show a single merged setStatusBarMessage: "Unbound from Text Editor (name) - file renamed"
    • Plain text, no checkmark prefix
    • Use the same merged-message pattern as the file-deletion unbind (gather pending edits, show one combined message)

Messages

Add a new message code and entry to messages.en.ts for the status bar message text.

Tests

  • Unit tests for the new onDidRenameFiles listener, following the same pattern as existing lifecycle listener tests
  • Integration tests covering the rename-triggers-unbind flow (via vscode.workspace.fs.rename() or simulated rename event)

Priority

This is lower priority than file deletion. A renamed file still exists at the new path; the user can re-bind without data loss. Implement after the file-deletion auto-unbind is fully shipped and verified.

Dependencies

  • Depends on: BoundDestinationLifecycle extraction (adds listener in the lifecycle module)
  • Blocks: nothing

Acceptance criteria

  1. Renaming an open file that is bound as a text-editor destination auto-unbinds the destination
  2. Status bar message shows "Unbound from Text Editor (name) - file renamed" without a checkmark
  3. Renaming an unrelated file does not trigger unbind
  4. Existing lifecycle listeners (terminal-close, editor-close, file-deletion) continue to work unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:lowLow priority / nice to have

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions