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

面向仓库级代码补全的数据流引导检索增强

Dataflow-Guided Retrieval Augmentation for Repository-Level Code Completion

Nanjing University(南京大学);State Key Laboratory for Novel Software Technology, Nanjing University(南京大学计算机软件新技术国家重点实验室);National Institute of Healthcare Data Science, Nanjing University(南京大学国家卫生数据科学研究院)

Wei Cheng, Yuhan Wu, Wei Hu

AI总结:

提出数据流引导的检索增强方法DraCo,通过构建仓库特定上下文图精确检索跨文件背景知识,提升私有仓库代码补全的准确性与效率。

摘要:

近年来,代码语言模型(LMs)已被部署在各种代码智能任务中,如代码补全。然而,预训练的LMs在私有仓库中生成正确的补全仍然具有挑战性。先前的研究基于导入关系或文本相似性检索跨文件上下文,这与补全目标的相关性不足。在本文中,我们提出了一种数据流引导的检索增强方法,称为DraCo,用于仓库级代码补全。DraCo将私有仓库解析为代码实体,并通过扩展的数据流分析建立它们之间的关系,形成特定于仓库的上下文图。每当触发代码补全时,DraCo从特定于仓库的上下文图中精确检索相关的背景知识,并生成格式良好的提示以查询代码LMs。此外,我们构建了一个大型Python数据集ReccEval,其补全目标更加多样化。我们的实验证明了DraCo卓越的准确性和适用效率,与最先进的方法相比,代码精确匹配平均提高了3.43%,标识符F1分数平均提高了3.27%。

英文摘要:

Recent years have witnessed the deployment of code language models (LMs) in various code intelligence tasks such as code completion. Yet, it is challenging for pre-trained LMs to generate correct completions in private repositories. Previous studies retrieve cross-file context based on import relations or text similarity, which is insufficiently relevant to completion targets. In this paper, we propose a dataflow-guided retrieval augmentation approach, called DraCo, for repository-level code completion. DraCo parses a private repository into code entities and establishes their relations through an extended dataflow analysis, forming a repo-specific context graph. Whenever triggering code completion, DraCo precisely retrieves relevant background knowledge from the repo-specific context graph and generates well-formed prompts to query code LMs. Furthermore, we construct a large Python dataset, ReccEval, with more diverse completion targets. Our experiments demonstrate the superior accuracy and applicable efficiency of DraCo, improving code exact match by 3.43% and identifier F1-score by 3.27% on average compared to the state-of-the-art approach.

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

↑