一句话:提出 RepoScope,用调用链感知的多视图上下文与结构保持序列化提升仓库级代码生成。
仓库级代码生成要求 LLM 在指定仓库上下文中生成代码。现有方法多采用检索增强生成(RAG),但难以识别真正相关、能反映仓库丰富语义的上下文,上下文视角也较为狭窄;此外,多数方法在构建提示时忽略了检索代码之间的结构关系,阻碍 LLM 准确理解上下文。为此,作者提出 RepoScope:构建仓库结构语义图(RSSG),检索融合结构与相似度的四视图综合上下文;提出一种新的调用链预测方法,利用仓库结构语义改进目标函数中被调函数的识别;并提出结构保持的序列化算法来构建提示,保证上下文对 LLM 的连贯性。RepoScope 仅依赖静态分析,无需额外训练或多次 LLM 查询,兼顾效率与泛化性。在 CoderEval 和 DevEval 上,其 pass@1 相对提升最高达 36.35%,并展现出跨任务迁移及与现有方法结合的能力。
Repository-level code generation aims to generate code within the context of a specified repository. Existing approaches typically employ retrieval-augmented generation (RAG) techniques to provide LLMs with relevant contextual information extracted from the repository. However, these approaches often struggle with effectively identifying truly relevant contexts that capture the rich semantics of the repository, and their contextual perspectives remains narrow. Moreover, most approaches fail to account for the structural relationships in the retrieved code during prompt construction, hindering the LLM’s ability to accurately interpret the context. To address these issues, we propose RepoScope, which leverages call chain-aware multi-view context for repository-level code generation. RepoScope constructs a Repository Structural Semantic Graph (RSSG) and retrieves a comprehensive four-view context, integrating both structural and similarity-based contexts. We propose a novel call chain prediction method that utilizes the repository’s structural semantics to improve the identification of callees in the target function. Additionally, we present a structure-preserving serialization algorithm for prompt construction, ensuring the coherence of the context for the LLM. Notably, RepoScope relies solely on static analysis, eliminating the need for additional training or multiple LLM queries, thus ensuring both efficiency and generalizability. Evaluation on widely-used repository-level code generation benchmarks (CoderEval and DevEval) demonstrates that RepoScope outperforms state-of-the-art methods, achieving up to a 36.35% relative improvement in pass@1 scores. Further experiments emphasize RepoScope’s potential to improve code generation across different tasks and its ability to integrate effectively with existing approaches. We provide the replication package at https://github.com/Lorien1128/RepoScope.
@inproceedings{paperbot11901,
title = {RepoScope: Leveraging Call Chain-Aware Multi-View Context for Repository-Level Code Generation},
author = {Yang Liu and Li Zhang and Fang Liu and Zhuohang Wang and Donglin Wei and Zhishuo Yang and Kechi Zhang and Jia Li and Lin Shi},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773211}
}