arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.00376cs.SEcs.AI
收藏

与上下文一致:通过上下文内联实现仓库级代码生成

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

Shanghai Jiao Tong University(上海交通大学)

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

AI总结:

本文提出InlineCoder框架,通过内联未完成函数到调用图中,将仓库理解转化为更易处理的函数级编码任务,提升仓库级代码生成能力。

摘要:

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

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑