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 在所有设置下均将零样本代码补全基线提升超过 10%,且持续优于传统检索增强的代码补全方法。此外,我们通过全面分析验证了 RepoCoder 的有效性,为未来研究提供了宝贵见解。