NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Scope-aware Code Completion with Discriminative Modeling

Sheng Hu, Chuan Xiao, Yoshiharu Ishikawa

Abstract

Modern IDEs often struggle with large API libraries, where simple prefix matching leads to overwhelming lists of suggestions. This paper presents a scope-aware code completion system that supports flexible, acronym-like inputs and leverages local code context. By integrating human typing patterns and API co-occurrence data into a discriminative SVM-based ranker, the proposed model achieves superior accuracy and significant performance gains over traditional methods.

Introduction

Standard code completion tools typically rely on strict prefix matching. For instance, typing get might return hundreds of methods, forcing developers to type extensively to narrow down the list. This "prefix rigidity" and a general "context blindness" — ignoring the APIs called in the immediate vicinity — hinder developer productivity.

Example of scope-aware completion using acronym-like input "swu" following a graphics-related call.

The authors address these gaps by introducing a system that understands how humans naturally abbreviate (e.g., "swu" for SwingUtilities) and uses the "scope context" to prioritize relevant suggestions.

Methodology

The system employs a two-stage ranking approach designed for high accuracy and low latency. The pipeline begins with a partial input that is processed through a Trie index to efficiently narrow down the search space.

The two-stage system architecture combining a Trie index, Noisy Channel Model, and SVM ranker.

Key Components

  • Acronym-like Matching: A logistic regression model, trained on human abbreviation data from Amazon Mechanical Turk, predicts the likelihood of an abbreviation representing a specific API based on features like letter skips and consonant/vowel matches.
  • Scope-Awareness: The model tracks API co-occurrences. If a developer recently called g.DrawRect(), the system increases the weight for other graphics-related APIs within that scope. Interestingly, the authors found that using just the single most recent line of code as context performed better than using the last five lines, as too much context introduces noise.
  • Discriminative Modeling (SVM): The final ranker weighs three primary features: API popularity ($F_{lang}$), transformation probability ($F_{trans}$), and scope co-occurrence ($F_{scope}$).
  • Efficiency: A Trie index with inverted lists of scope IDs allows for near-instant co-occurrence calculations, ensuring the system remains responsive even with large dictionaries like the JDK.

Evaluation and Results

The model was trained on a Java corpus of 1,000 GitHub projects and evaluated against 12 popular Java projects.

  • Accuracy: The Scope-aware Discriminative Model (SDM) outperformed popularity-based and noisy channel baselines by up to 7.3% in top-1 accuracy.
  • Ranking Quality: A Mean Reciprocal Ranking (MRR) of 0.928 indicates that the correct suggestion is typically the first or second option.
  • Performance: The system processes requests in approximately 1ms, making it 31 times faster than naive re-ranking approaches due to efficient Trie-based pruning.

Conclusion

By combining human-centric abbreviation modeling with local code context, this research demonstrates a significant leap in code completion utility. Future work may explore deeper semantic understanding through Transformers or adapt the model to dynamic, project-specific APIs.

Summary updated

BibTeX
@article{hu2019scope,
  author = {Sheng Hu and Chuan Xiao and Yoshiharu Ishikawa},
  title = {{Scope-aware Code Completion with Discriminative Modeling}},
  journal = {J. Inf. Process.},
  year = {2019},
  doi = {10.2197/ipsjjip.27.469},
}
Figure