Abstract
Repository-level code completion is challenging as it involves complicated contexts from multiple files in the repository. To date, researchers have proposed two technical categories to enhance LLM-based repository-level code completion: retrieval-augmented generation (RAG) and static analysis integration. This work performs the first study on static analysis integration in LLM-based repository-level code completion by investigating both the effectiveness and efficiency of integration strategies across different phases of code completion. We implement STALL+, a framework supporting extendable integration of multiple static analysis strategies. Based on STALL+, we perform extensive experiments using various code LLMs on the CrossCodeEval benchmark. Our findings show that integrating file-level dependencies in the prompting phase performs best, while post-processing integration performs worst. We also observe performance differences between dynamic (Python) and static (Java) languages due to the limitations of statically analyzing dynamic languages. Finally, we demonstrate the complementarity between RAG and static analysis integration and their cost-effectiveness when combined.
Introduction
Modern software development is inherently repository-centric. Developers frequently invoke methods, classes, and variables defined across numerous files and directories. Traditional Large Language Model (LLM) code completion tools often struggle in these scenarios because they primarily focus on the local file context. This leads to two major issues: context window limitations that prevent the inclusion of the entire repository, and hallucinations where the model generates plausible-looking but non-existent API calls.
To address these challenges, researchers have explored Retrieval-Augmented Generation (RAG) to fetch relevant snippets and basic static analysis to identify imports. However, a systematic understanding of how static analysis can be optimized throughout the generation pipeline has been lacking. This paper introduces STALL+, a framework designed to evaluate and enhance repository-level completion through multi-phase static analysis integration.
The STALL+ Framework
STALL+ introduces a "pluggable" architecture that integrates static analysis at three critical stages of the LLM generation pipeline: prompting, decoding, and post-processing.
- Prompting Phase: Before generation, STALL+ uses a static analyzer to extract File-level Dependencies (signatures of imported entities) and Token-level Dependencies (a list of valid identifiers at the cursor). These are prepended to the prompt to ground the LLM in the repository's actual structure.
- Decoding Phase: During the token-by-token generation process, the framework intercepts the model's logits. It uses a static analyzer to identify valid tokens in real-time and boosts their probability, effectively constraining the model to syntactically and semantically valid code.
- Post-processing Phase: After generating multiple candidate completions (e.g., via beam search), STALL+ employs compilers or linters (like
javacorpylint) to filter out candidates that fail to compile, ensuring the final prediction is functional.
Experimental Setup
The researchers evaluated STALL+ using CrossCodeEval, a state-of-the-art benchmark for repository-level completion. The dataset includes over 4,500 examples across Java and Python, sourced from repositories created between March and June 2023. This timeframe ensures that the data was not included in the training sets of the evaluated models (such as DeepSeek-Coder), preventing data leakage and ensuring a fair test of the models' reasoning capabilities.
Key Insights and Results
The Power of Prompting
The study found that integrating file-level dependencies in the prompt is the most effective single strategy. It provides the LLM with a high-level map of the repository, which aligns with the model's pre-trained ability to understand hierarchical structures. This method is also highly efficient, adding less than one second of overhead to the generation process.
Static vs. Dynamic Languages
A significant finding is the performance gap between Java and Python. Static analysis is inherently more precise for Java. In Python, dynamic features like runtime parameter determination and global variable scoping can lead to "bad cases" where the static analyzer fails to identify valid tokens, potentially misleading the LLM.
RAG and Static Analysis Synergy
While RAG provides semantic context (how similar logic was implemented elsewhere), static analysis provides structural constraints (what actually exists in the current environment). The combination of these two approaches yielded the best results, achieving a Line Exact Match (Line EM) of 34.67% for Python and 52.05% for Java using DeepSeek-Coder-6.7B, setting a new benchmark for models of this scale.
Conclusion
STALL+ demonstrates that while all phases of static analysis integration provide benefits, the prompting phase offers the best balance of accuracy and efficiency. For production environments, the combination of RAG and prompting-phase static analysis is the most viable path forward. Future work will focus on improving analyzer precision for dynamic languages and reducing the latency of decoding-phase interventions to make them suitable for real-time IDE integration.
Summary updated