Skip to content

Refactoring

Sevhena Walker edited this page Apr 4, 2025 · 3 revisions

Initiating Refactors

EcoOptimizers provides multiple pathways to initiate code improvements:

  1. From the Editor:
    When you hover over a highlighted code smell in your source file, a detailed tooltip appears showing:
    • The exact nature of the smell
    • The proposed refactoring solution
    • Two action buttons:
      • "Refactor Smell" (targets only the current instance)
      • "Refactor All of this [Type]" (applies to all occurrences in the file)

User can see the screen be split into the current version of code versus the refactored version.The Refactoring Details view on the left shows information like refactoring smell type, energy saved, carbon saved, files affected by the refactor, etc. On the bottom  right corner, user can either accept or reject these changes.

  1. From the Sidebar:
    In the Code Smells panel:
    • Click a smell's wrench icon to refactor that specific instance
    • Click a file's wrench icon to see a menu of all smell types present in that file, then select which type to refactor comprehensively

Clicking on the Tools icon, triggers extension to refactor all smells of a particular type.

  1. From the Command Palette:
    Use "Eco: Refactor All of this [Type]" to initiate bulk refactoring after selecting a target file through the subsequent prompt.

Reviewing and Approving Changes

When you initiate any refactoring operation, EcoOptimizers enters a special review mode:

  1. The main editor area splits to show a diff view comparing original and refactored code

  2. The Refactoring Details panel activates to show:

    • The specific smell type being addressed
    • Detailed explanation of the changes
    • Estimated energy savings (in kg CO₂ equivalent)
    • Tree view of all affected files (primary file plus any dependencies)
  3. The VS Code status bar displays action buttons:

    • "Accept" (checkmark icon): Apply the changes
    • "Reject" (X icon): Abandon the refactoring

During this review phase, you can:

  • Click any file in the affected files tree to view its changes
  • Scroll through the diff to examine modifications in detail
  • Use standard VS Code diff navigation shortcuts

Upon accepting changes, the extension:

  1. Updates all affected files
  2. Records the carbon savings in the Metrics panel
  3. Refreshes the Code Smells panel to reflect the improved state

Clone this wiki locally