The task of repository-level code completion is to continue writing the unfinished code based on a broader context of the repository. While for automated code completion tools, it is difficult to utilize the useful information scattered in different files. We propose RepoCoder, a simple, generic, and effective framework to address the challenge. It streamlines the repository-level code completion process by incorporating a similarity-based retriever and a pre-trained code language model, which allows for the effective utilization of repository-level information for code completion and grants the ability to generate code at various levels of granularity. Furthermore, RepoCoder utilizes a novel iterative retrieval-generation paradigm that bridges the gap between retrieval context and the intended completion target. We also propose a new benchmark RepoEval, which consists of the latest and high-quality real-world repositories covering line, API invocation, and function body completion scenarios. We test the performance of RepoCoder by using various combinations of code retrievers and generators. Experimental results indicate that RepoCoder significantly improves the zero-shot code completion baseline by over 10% in all settings and consistently outperforms the vanilla retrieval-augmented code completion approach. Furthermore, we validate the effectiveness of RepoCoder through comprehensive analysis, providing valuable insights for future research.
翻译:代码仓库级自动补全的任务是基于代码库的广泛上下文来继续编写未完成的代码。尽管对于自动代码补全工具而言,很难利用分散在不同文件中的有用信息。我们提出了RepoCoder,这是一个简单、通用而有效的框架来应对这一挑战。它通过结合基于相似性的检索器和预训练的代码编程语言模型来优化代码库级别的代码自动补全,赋予了生成各种粒度代码的能力。此外,RepoCoder使用了一种新颖的迭代检索-生成范式,弥合了检索上下文和预期完成目标之间的差距。我们还提出了一个新的基准RepoEval,其中包含最新和高质量的真实世界仓库,覆盖了线路、API调用和函数体自动补全场景。我们通过使用不同的代码检索器和生成器来测试RepoCoder的性能。实验结果表明,在所有设置中,RepoCoder将零-shot代码自动补全基准测试的性能提高了超过10%,并始终优于基准检索增强代码自动补全方法。此外,我们通过全面的分析验证了RepoCoder的有效性,为未来的研究提供了有价值的见解。