Conference Paper

RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generation.

Fengji Zhang, Bei Chen, Yue Zhang, Jacky W. Keung, Jin Liu, Daoguang Zan, Yi Mao, Jian-Guang Lou, Weizhu Chen

Abstract

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 repositorylevel code completion process by incorporating a similarity-based retriever and a pre-trained code language model in an iterative retrievalgeneration pipeline. RepoCoder makes effective utilization of repository-level information for code completion and has the ability to generate code at various levels of granularity. Moreover, we propose a new benchmark RepoEval, which consists of the latest and highquality real-world repositories covering line, API invocation, and function body completion scenarios. Experimental results indicate that RepoCoder significantly improves the In-File 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. Our source code and benchmark are publicly available: https://github.com/microsoft/ CodeT/tree/main/RepoCoder 1 Figure 1: Illustration of the In-File code completion method, the repository-level Retrieval-Augmented Generation (RAG) method, and the iterative retrievalgeneration RepoCoder method. Introduction In real-world software production, it is crucial for developers to be aware of other files within the repository during programming. This challenge gives rise to the task of repository-level code completion, where automated tools are expected to utilize the broader context of a repository rather than relying solely on in-file information to complete unfinished code. Code files within a repository often exhibit interrelated dependencies, including shared utilities, configurations, and cross-API invocations resulting from modularization (Tu et al., 2014). Additionally, each repository typically follows customized naming conventions and coding

Keywords