Enter flow state with auto-edit
Developers do not write code in a linear fashion. They jump from line 15 where they change a function signature to line 130 to update the parameters when calling that function, from file api.go
to commandsController.ts
, and everything in between. As the codebase grows and increases in complexity, as enterprise codebases do, developers often spend a great deal of effort maintaining and editing rather than writing new code. Wouldn’t it be great if their AI coding assistant could keep up?
Over two-thirds of the world's developers use VS Code, and for the vast majority of these developers, autocomplete is still the dominant way of interacting with AI. But autocomplete has limits. Autocomplete only suggests code after your cursor's current position. So when you start writing code, say const unique = (arr)
, the autocomplete model may suggest a completion like => [...new Set(arr)];
, which when you hit the tab key to accept the suggestion would give you the completed code of
const unique = (arr) => [...new Set(arr)];
This is a great productivity boost, and sometimes, you can just hit the Tab key repeatedly to have the LLM write the next line, series of lines, or more—tab-oriented programming, as some might call it. When you want to do something more complex, you have to rely on a different workflow, typically LLM chat or inline editing, which can take you out of the flow.
Today, we are launching the first VS Code integration that goes beyond autocomplete to suggest context-aware edits natively in VS Code. We call this feature "auto-edit" and it brings a new level of automatic code suggestion to VS Code.
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 recent changes. In addition to inserting code, auto-edit can also suggest deletions, modify code before and after the cursor's position, and propose similar changes across multiple locations across your codebase.
In building this feature, we experimented with different models based on their code quality, latency, and ability to integrate the context we provided, such as recent user edits, IDE diagnostics errors, recent code snippet views, and the current working file. This experimentation motivated the creation of a novel fine-tuning pipeline to improve the in-context learning ability of smaller and faster models that not only better understood the context we were giving it, but also the response format required.
Auto-edit in action
Let’s take a look at a couple of examples of auto-edit in action.
Autocomplete
With auto-edit enabled, you’ll still get the autocomplete experience you’re familiar with. As you start typing, if auto-edit has a relevant suggestion, you’ll see the ghost text displaying the suggestion as you normally would.
Auto-edit before and after the cursor
The auto-edit model can suggest completions before and after the cursor and in some cases both at the same time.
In the above example, we see auto-edit suggest a completion before the cursor to add parentheses around the return types, which is required if you are returning more than one item in a Go function. Additionally, we get a suggestion to check for an error from the database call by creating an err
variable to capture an error if one does occur when we execute the query, as well as chaining the .Error
to the end of the database call so that we get the value of the error if one does occur.
If we hit tab to accept this suggestion, we’ll also get a suggestion for the next action we’d naturally want to take, in this case, handling the error if one does arise. Here, we are using the text decorator VS Code API to show a slightly different UI, allowing you to easily see what the change would look like.
Here is the entire sequence of accepting multiple changes with auto-edit:
Auto-edit across multiple files
We changed the function signatures in the utils.go file. Now, when we go to main.go and navigate to where those functions are being called, we’ll see an error. But with auto-edit, all we have to do is click on the function, and we’ll get a suggestion on how to fix it.
Auto-edit looks at our recent edits and suggests a fix that we can accept by just hitting the tab button.
Auto-edit to suggest deletions
Deletions are a part of the coding lifecycle, and auto-edit can also help here. When you update a function signature to remove a parameter or change an enum, like in the example below, auto-edit can automatically suggest removing those variables elsewhere in your code.
Get started with auto-edit today
We are starting to roll out auto-edit for Cody for VS Code today. For Cody Pro users once the feature is enabled for your account, you will receive an in-editor notification. For Enterprise customers with Sourcegraph Cody Gateway access, an administrator will need to enable the cody-autoedit-experiment-enabled-flag
feature flag. Once that is done, developers will receive a notification in their editor to enable auto-edit.
This feature is experimental and there are some limitations you should be aware of. At the moment, you must initiate at least one character change for auto-edit to become active in a file. Auto-edit may not propose all necessary changes in complex refactoring scenarios and may not cover all instances of code that need to be changed. Finally, enabling auto-edit will disable the current autocomplete functionality, but we’re confident that the auto-edit completions will provide an equivalent or better autocompletion experience. We are actively working on improving and iterating on this feature to make it handle more complex cases and we welcome your feedback.
Check out the auto-edit docs for more information and connect with us on Discord to share feedback.