Auto-edit
Auto-edit suggests code changes by analyzing cursor movements and typing. After you've made at least one character edit in your codebase, it begins proposing contextual modifications based on your cursor position and recent changes.
Capabilities of auto-edit
- Can automatically insert and delete text
- Can modify code before and after the cursor position
- Works with repetitive tasks, especially in test files
- Can propose similar changes across multiple locations based on recent edits
- Can handle complex refactoring operations like adding parameters and unpacking functions
Enabling auto-edit
Eligible Cody Pro users will gradually be given access to the auto-edit feature. Once you have it, you will receive an in-editor notification.
Auto-edit access for Enterprise customers
Auto-edit is available for Enterprise customers with Sourcegraph Cody Gateway access. Enabling the feature requires two steps:
- Site administrators must:
- Enable the feature flag
cody-autoedit-experiment-enabled-flag
- Add
fireworks::*
as an allowed provider (see below)
- Enable the feature flag
- Once enabled, developers will receive a notification in their editor to turn it on
The following example demonstrates how to add Fireworks as an allowed LLM provider:
JSON"cody.enabled": true, "modelConfiguration": { "sourcegraph": { "modelFilters": { // Only allow "beta" and "stable" models. // Not "experimental" or "deprecated". "statusFilter": ["beta", "stable"], // Allow any models provided by Anthropic, OpenAI, Google and Fireworks. "allow": [ "anthropic::*", // Anthropic models "openai::*", // OpenAI models "google::*", // Google Gemini models "fireworks::*", // Open source models hosted by Sourcegraph ], } } }
How does auto-edit work?
The system detects potential changes based on the following:
- Cursor placement in the code
- Recent changes made in similar contexts
- Function usage patterns
- Common refactoring patterns
Auto-edit vs. Autocomplete
In terms of feature-set and functionality, auto-edit and autocomplete have some key differences:
Feature | Autocomplete | Auto-edit |
---|---|---|
Text modification | Can only insert text, not delete | Can both insert and delete text |
Cursor position | Only proposes content after the cursor | Can modify code before and after the cursor |
Suggestion trigger | Suggests on every character typed | Proposes changes based on context and recent edits |
Use cases
The auto-edit feature can help you with various repetitive tasks in your code:
- Function signature refactoring: Automatically suggests adding error returns, new parameters, or changing return types across function definitions. For example, when you modify a function to return both a value and an error, auto-edit helps update the function signature.
- Call site updates: When you change a function's signature, auto-edit detects all locations where the function is called and suggests necessary modifications to match the new signature. This includes updating parameter orders, adding error handling, and adjusting return value usage.
- Test file maintenance: Helps with repetitive updates in test files, such as modifying test assertions, updating mock objects, or changing test data structures. Auto-edit recognizes patterns from your recent changes and suggests similar modifications across related tests.
- Parameter refactoring: Assists in adding, removing, or reorganizing function parameters. When you unpack a function to handle more cases, auto-edit helps restructure the parameter list and suggests corresponding changes at call sites.
- Type system modifications: When updating type definitions or interfaces, auto-edit identifies and suggests consistent changes across your codebase. This includes updating variable declarations, function parameters, and return types to maintain type consistency.