Search documentation of Ragex

# Ragex.Editor.Preview (Ragex v0.4.0)

View Source

Preview mode for refactoring operations.

Provides dry-run capabilities to see what changes would be made without actually modifying files.

## Summary

### Types

file_preview()
preview_result()

### Functions

generate_preview(operation, changes, opts \\ [])

Generates a preview of changes for a refactoring operation.

## Types

# file_preview()

    @type file_preview() :: %{
      path: String.t(),
      diff: Ragex.Editor.Diff.diff_result(),
      formatted_diff: String.t()
    }

# preview_result()

    @type preview_result() :: %{
      operation: atom(),
      files: [file_preview()],
      stats: %{
        files_affected: non_neg_integer(),
        total_additions: non_neg_integer(),
        total_deletions: non_neg_integer()
      },
      warnings: [String.t()]
    }

## Functions

# generate_preview(operation, changes, opts \\ [])

    @spec generate_preview(
      atom(),
      %{required(String.t()) => {String.t(), String.t()}},
      keyword()
    ) ::
      {:ok, preview_result()}

Generates a preview of changes for a refactoring operation.

## Parameters

- `operation`: Operation name (e.g., :rename_function)
- `changes`: Map of file_path => {old_content, new_content}
- `opts`: Options
  - `:format` - Diff format (:unified, :side_by_side, :json, :html)
  - `:context_lines` - Context lines in diff (default: 3)

## Returns

- `{:ok, preview_result}` with diffs for all affected files