Developers often dedicate significant time to maintaining and refactoring existing code. However, most prior work on generative models for code focuses solely on creating new code, neglecting the unique requirements of editing existing code. In this work, we explore a multi-round code auto-editing setting, aiming to predict edits to a code region based on recent changes within the same codebase. Our model, Coeditor, is a fine-tuned CodeT5 model with enhancements specifically designed for code editing tasks. We encode code changes using a line diff format and employ static analysis to form large customized model contexts, ensuring appropriate information for prediction. We collect a code editing dataset from the commit histories of 1650 open-source Python projects for training and evaluation. In a simplified single-round, single-edit task, Coeditor significantly outperforms the best code completion approach -- nearly doubling its exact-match accuracy, despite using a much smaller model -- demonstrating the benefits of incorporating editing history for code completion. In a multi-round, multi-edit setting, we observe substantial gains by iteratively prompting the model with additional user edits. We open-source our code, data, and model weights to encourage future research and release a VSCode extension powered by our model for interactive usage.
翻译:摘要:开发人员通常需要花费大量时间来维护和重构现有代码。然而,现有关于代码生成模型的研究大多聚焦于创建新代码,忽略了编辑现有代码的独特需求。本文探索了一种多轮代码自动编辑场景,旨在根据同一代码库中的最近变更来预测对代码区域的编辑。我们的模型Coeditor基于微调的CodeT5模型,并针对代码编辑任务进行了专门增强。我们采用行差异格式对代码变更进行编码,并利用静态分析构建大规模定制化模型上下文,确保为预测提供适当信息。我们从1650个开源Python项目的提交历史中收集了一个代码编辑数据集用于训练和评估。在简化的单轮单编辑任务中,Coeditor显著优于最佳代码补全方法——准确率近乎翻倍(尽管使用了更小的模型)——这证明了将编辑历史纳入代码补全的益处。在多轮多编辑场景中,我们观察到通过迭代地向模型提供额外用户编辑可实现显著的性能提升。我们开源代码、数据和模型权重以鼓励未来研究,并发布了基于我们模型的VSCode扩展以实现交互式使用。