Table of Contents
Fetching ...

CATCODER: Repository-Level Code Generation with Relevant Code and Type Context

Zhiyuan Pan, Xing Hu, Xin Xia, Xiaohu Yang

TL;DR

CatCoder tackles the challenge of repository-level code generation by introducing a hybrid prompt strategy that combines two contextual signals: retrieved relevant code chunks and explicit type context derived from static analysis. The method operates in three stages—code retrieval, type-context extraction, and LLM-based code generation using a frozen model—without additional training. Empirical results on Java and Rust benchmarks show CatCoder substantially outperforms vanilla prompts and RepoCoder, with notable gains in compile@k and pass@k, and its benefits generalize across multiple LLMs and languages. The approach demonstrates scalability in large repositories, achieving significant prompt-construction speedups after a cold start, and highlights potential for practical integration in real-world software development. Limitations include dependence on the underlying LLM and static analyzers, with future work pointing to broader language support and enhanced retrieval strategies.

Abstract

Large language models (LLMs) have demonstrated remarkable capabilities in code generation tasks. However, repository-level code generation presents unique challenges, particularly due to the need to utilize information spread across multiple files within a repository. Specifically, successful generation depends on a solid grasp of both general, context-agnostic knowledge and specific, context-dependent knowledge. While LLMs are widely used for the context-agnostic aspect, existing retrieval-based approaches sometimes fall short as they are limited in obtaining a broader and deeper repository context. In this paper, we present CatCoder, a novel code generation framework designed for statically typed programming languages. CatCoder enhances repository-level code generation by integrating relevant code and type context. Specifically, it leverages static analyzers to extract type dependencies and merges this information with retrieved code to create comprehensive prompts for LLMs. To evaluate the effectiveness of CatCoder, we adapt and construct benchmarks that include 199 Java tasks and 90 Rust tasks. The results show that CatCoder outperforms the RepoCoder baseline by up to 14.44% and 17.35%, in terms of compile@k and pass@k scores. In addition, the generalizability of CatCoder is assessed using various LLMs, including both code-specialized models and general-purpose models. Our findings indicate consistent performance improvements across all models, which underlines the practicality of CatCoder. Furthermore, we evaluate the time consumption of CatCoder in a large open source repository, and the results demonstrate the scalability of CatCoder.

CATCODER: Repository-Level Code Generation with Relevant Code and Type Context

TL;DR

CatCoder tackles the challenge of repository-level code generation by introducing a hybrid prompt strategy that combines two contextual signals: retrieved relevant code chunks and explicit type context derived from static analysis. The method operates in three stages—code retrieval, type-context extraction, and LLM-based code generation using a frozen model—without additional training. Empirical results on Java and Rust benchmarks show CatCoder substantially outperforms vanilla prompts and RepoCoder, with notable gains in compile@k and pass@k, and its benefits generalize across multiple LLMs and languages. The approach demonstrates scalability in large repositories, achieving significant prompt-construction speedups after a cold start, and highlights potential for practical integration in real-world software development. Limitations include dependence on the underlying LLM and static analyzers, with future work pointing to broader language support and enhanced retrieval strategies.

Abstract

Large language models (LLMs) have demonstrated remarkable capabilities in code generation tasks. However, repository-level code generation presents unique challenges, particularly due to the need to utilize information spread across multiple files within a repository. Specifically, successful generation depends on a solid grasp of both general, context-agnostic knowledge and specific, context-dependent knowledge. While LLMs are widely used for the context-agnostic aspect, existing retrieval-based approaches sometimes fall short as they are limited in obtaining a broader and deeper repository context. In this paper, we present CatCoder, a novel code generation framework designed for statically typed programming languages. CatCoder enhances repository-level code generation by integrating relevant code and type context. Specifically, it leverages static analyzers to extract type dependencies and merges this information with retrieved code to create comprehensive prompts for LLMs. To evaluate the effectiveness of CatCoder, we adapt and construct benchmarks that include 199 Java tasks and 90 Rust tasks. The results show that CatCoder outperforms the RepoCoder baseline by up to 14.44% and 17.35%, in terms of compile@k and pass@k scores. In addition, the generalizability of CatCoder is assessed using various LLMs, including both code-specialized models and general-purpose models. Our findings indicate consistent performance improvements across all models, which underlines the practicality of CatCoder. Furthermore, we evaluate the time consumption of CatCoder in a large open source repository, and the results demonstrate the scalability of CatCoder.
Paper Structure (51 sections, 6 equations, 8 figures, 8 tables, 1 algorithm)

This paper contains 51 sections, 6 equations, 8 figures, 8 tables, 1 algorithm.

Figures (8)

  • Figure 1: The two essential sources of local context for generating the triu method. (1) Relevant Code (the ones method) provides a crucial, repository-specific pattern for instantiating a RealMatrix object. (2) Type Context provides the equally crucial API definition for the RealMatrix interface, including methods like getEntry needed for element access.
  • Figure 2: Overview of our approach
  • Figure 3: Dependency Graph and Type context of the triu method in class CMAESOptimizer.
  • Figure 4: Our prompt design. The actual prompt ends right after the signature.
  • Figure 5: Two tasks in the Java benchmark, where RepoCoder fails but CatCoder succeeds.
  • ...and 3 more figures