Skip to content

Smart Rename Preview #5

Description

@sidkr222003

VS Code's default rename applies changes immediately or shows a minimal preview. Developers often miss cross-file impacts, dynamic references, or naming collisions, leading to broken builds or subtle runtime bugs. A dedicated, risk-aware preview workflow would surface potential issues before commitment.

Objective

Build a rename interception & preview system that collects all proposed rename edits, visualizes them in a structured UI, highlights potential conflicts/risky patterns, and requires explicit user confirmation before applying.

📋 Scope & Implementation Details

1. Rename Interception & Collection

  • Register custom command: safeRename.start (optionally override editor.action.rename)
  • Fetch rename locations without applying:
    const edit = await vscode.commands.executeCommand<vscode.WorkspaceEdit>(
      'vscode.executeDocumentRenameProvider',
      document.uri,
      position,
      newName
    );
  • Parse edit.entries() to build a preview model grouped by file

2. Preview UI

  • Use vscode.window.createTreeView with a custom TreeDataProvider
  • Tree structure:
    📁 src/auth/login.ts
      ├─ 🟢 L14: const userId = ...
      ├─ 🟡 L42: obj["userId"] (dynamic access)
      └─ 🔴 L89: function userId() (scope collision)
    
  • On tree item click: open transient diff preview (vscode.commands.executeCommand('vscode.diff', ...))
  • Support checkboxes for selective apply (Phase 2)

3. Risk & Conflict Detection

  • Analyze each edit location and assign risk level:
    • $(green) Safe: Direct symbol reference, same scope, static access
    • $(yellow) Review: String literal match, comment match, template literal, dynamic key (obj["old"])
    • $(red) Conflict: Name already exists in target scope, cross-language boundary (e.g., TS → CSS class), framework-specific binding
  • Use lightweight scope lookup + regex heuristics for initial pass

4. Confirm/Cancel Workflow

  • Action bar in TreeView or QuickPick:
    • "Apply All"vscode.workspace.applyEdit(collectedEdit)
    • "Review Selected" → open diff
    • "Cancel" → discard edit, restore cursor
  • Apply atomically; VS Code handles undo stack automatically

Acceptance Criteria

  • Intercepts rename and collects all proposed edits before applying
  • Displays structured preview grouped by file with line/context snippets
  • Highlights ≥3 risk types (collisions, dynamic refs, string/comment matches)
  • Provides explicit Apply/Cancel actions
  • Applies edits atomically with full undo support
  • Generates preview in <100ms for ≤50 occurrences

Technical Notes

  • Do not reimplement language server rename logic. Delegate to vscode.executeDocumentRenameProvider and enhance the output.
  • Risk detection should be heuristic-based initially:
    • Scope collision: vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider') + name overlap check
    • Dynamic/string matches: regex fallback on surrounding text
  • Use vscode.WorkspaceEdit for atomic application; preserves undo/redo history
  • Cache provider response during preview session to avoid redundant LS calls
  • Gracefully fallback to default rename if provider returns null or times out
  • use codicons

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumImportant but not urgent. Can be scheduled after high-priority tasks are completed.documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueBeginner-friendly tasks with clear scope and minimal complexity, ideal for new contributors.intermediateModerately complex tasks requiring familiarity with the codebase and relevant APIs.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions