Table of Contents
Fetching ...

In Line with Context: Repository-Level Code Generation via Context Inlining

Chao Hu, Wenhao Zeng, Yuling Shi, Beijun Shen, Xiaodong Gu

TL;DR

InlineCoder targets repository-level code generation by re framing the task as function-level reasoning through inlining the unfinished function into its call graph. The method generates a draft anchor, then performs bidirectional context inlining—upstream inlining into callers and downstream retrieval of callees—before integrating all signals into a context-rich prompt for final generation. Empirical results on DevEval and RepoExec across multiple backbones show consistent improvements over strong baselines, with substantial gains on RepoExec (EM 29.73%, ES 20.82%, BLEU 49.34%). Ablation and case studies confirm the importance of the anchor draft, upstream/downstream inlining, and confidence guidance, indicating strong generalization across domains and robustness to varied repository contexts.

Abstract

Repository-level code generation has attracted growing attention in recent years. Unlike function-level code generation, it requires the model to understand the entire repository, reasoning over complex dependencies across functions, classes, and modules. However, existing approaches such as retrieval-augmented generation (RAG) or context-based function selection often fall short: they primarily rely on surface-level similarity and struggle to capture the rich dependencies that govern repository-level semantics. In this paper, we introduce InlineCoder, a novel framework for repository-level code generation. InlineCoder enhances the understanding of repository context by inlining the unfinished function into its call graph, thereby reframing the challenging repository understanding as an easier function-level coding task. Given a function signature, InlineCoder first generates a draft completion, termed an anchor, which approximates downstream dependencies and enables perplexity-based confidence estimation. This anchor drives a bidirectional inlining process: (i) Upstream Inlining, which embeds the anchor into its callers to capture diverse usage scenarios; and (ii) Downstream Retrieval, which integrates the anchor's callees into the prompt to provide precise dependency context. The enriched context, combining draft completion with upstream and downstream perspectives, equips the LLM with a comprehensive repository view.

In Line with Context: Repository-Level Code Generation via Context Inlining

TL;DR

InlineCoder targets repository-level code generation by re framing the task as function-level reasoning through inlining the unfinished function into its call graph. The method generates a draft anchor, then performs bidirectional context inlining—upstream inlining into callers and downstream retrieval of callees—before integrating all signals into a context-rich prompt for final generation. Empirical results on DevEval and RepoExec across multiple backbones show consistent improvements over strong baselines, with substantial gains on RepoExec (EM 29.73%, ES 20.82%, BLEU 49.34%). Ablation and case studies confirm the importance of the anchor draft, upstream/downstream inlining, and confidence guidance, indicating strong generalization across domains and robustness to varied repository contexts.

Abstract

Repository-level code generation has attracted growing attention in recent years. Unlike function-level code generation, it requires the model to understand the entire repository, reasoning over complex dependencies across functions, classes, and modules. However, existing approaches such as retrieval-augmented generation (RAG) or context-based function selection often fall short: they primarily rely on surface-level similarity and struggle to capture the rich dependencies that govern repository-level semantics. In this paper, we introduce InlineCoder, a novel framework for repository-level code generation. InlineCoder enhances the understanding of repository context by inlining the unfinished function into its call graph, thereby reframing the challenging repository understanding as an easier function-level coding task. Given a function signature, InlineCoder first generates a draft completion, termed an anchor, which approximates downstream dependencies and enables perplexity-based confidence estimation. This anchor drives a bidirectional inlining process: (i) Upstream Inlining, which embeds the anchor into its callers to capture diverse usage scenarios; and (ii) Downstream Retrieval, which integrates the anchor's callees into the prompt to provide precise dependency context. The enriched context, combining draft completion with upstream and downstream perspectives, equips the LLM with a comprehensive repository view.
Paper Structure (33 sections, 3 equations, 9 figures, 5 tables)

This paper contains 33 sections, 3 equations, 9 figures, 5 tables.

Figures (9)

  • Figure 1: A Motivating Example. Inlining The target function into its call chain creates a more context-aware task formulation, leading to repository-consistent completions.
  • Figure 2: Framework of InlineCoder.
  • Figure 3: Function Inlining.
  • Figure 4: Downstream Retrieval.
  • Figure 5: Prompt Template for The Final Context-Enhanced Code Generation.
  • ...and 4 more figures