arXiv:2601.00376cs.SEcs.AI2026-01中稿 · FSE 2026被引 19

通过内联代码重构,让大模型更好理解整个项目依赖。

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

  • 将待补全函数嵌入调用图,转化为易处理的函数级任务。
  • 生成初步补全作为锚点,支持上下文信心评估。
  • 双向内联增强上下文,提升代码生成准确性。

近年来,仓库级代码生成受到广泛关注。与函数级生成不同,它要求模型理解整个仓库,推理跨函数、类和模块的复杂依赖关系。然而,现有方法如基于检索的生成(RAG)或基于上下文的函数选择往往表现不佳:主要依赖表面相似性,难以捕捉支配仓库语义的丰富依赖。本文提出InlineCoder,一种新的仓库级代码生成框架。InlineCoder通过将未完成函数内联至其调用图,增强对仓库上下文的理解,从而将复杂的仓库理解问题转化为更易处理的函数级编码任务。给定函数签名后,InlineCoder首先生成一个近似下游依赖的草稿完成(称为锚点),并用于困惑度驱动的信心估计。该锚点驱动双向内联过程:(i) 上游内联,将锚点嵌入其调用者以捕获多样使用场景;(ii) 下游检索,将锚点被调用的函数集成到提示中,提供精确依赖上下文。融合草稿完成与上下游视角的丰富上下文,为LLM提供了全面的仓库视图。

原文摘要 · Abstract (English)

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.

代码生成上下文内联大模型仓库理解

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。