Grammar-Aware Code Completion With Expandable Holes

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code completion systems generate incorrect candidates due to early stopping when probabilities are below a confidence threshold, leading to incomplete and confusing suggestions.

Innovation Solution

A neural transformer model with attention and a bidirectional encoder-decoder architecture is used to predict syntactically-correct candidates with holes, allowing for non-terminal symbol expansion without left-to-right constraints, utilizing a supervised training dataset and nested beam search to present complete and accurate code snippets.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If the code completion system stops expansion when probabilities are below a confidence threshold, then the system avoids generating low-confidence predictions, but the generated candidates become incomplete and truncated

Engineering Contradiction:
Improveconfidence threshold complianceVSAvoidcode completion accuracy
Core Design Contradiction:
ReliabilityVSManufacturing precision

Solution Approach 1:

The code completion system segments the code generation process into multiple independent expansion steps, where each non-terminal symbol is expanded separately. This allows the system to generate complete syntactically-correct candidates by continuing expansion beyond traditional stopping thresholds, as each segment can be independently validated for syntactic correctness.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system performs preliminary syntactic validation by using a parser to verify the syntactic correctness of generated candidates before presenting them to the user. This preliminary action ensures that even though expansion continues beyond confidence thresholds, only syntactically-valid complete candidates are output, maintaining both reliability and precision.

Inventive Principle:
Principle #10Preliminary action

2Device complexity

If the system expands non-terminal symbols in left-to-right order only, then the generation process is simple and constrained, but the system fails to generate complete candidates when uncertain about later tokens

Engineering Contradiction:
Improveexpansion process simplicityVSAvoidcandidate completeness
Core Design Contradiction:
Device complexityVSManufacturing precision

Solution Approach 1:

The system dynamically determines the expansion order of non-terminal symbols based on confidence probabilities and syntactic context, rather than following a fixed left-to-right sequence. This dynamic approach allows the system to expand more certain non-terminals first and defer uncertain ones, enabling complete candidate generation while maintaining manageable complexity through guided exploration.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The system adds a dimension of syntactic structure awareness by using parse trees to represent and validate code structure. This allows expansion to proceed in multiple directions simultaneously while maintaining syntactic correctness, transforming the problem from a linear sequence constraint to a structured tree-based exploration where completeness can be achieved through proper structural guidance.

Inventive Principle:
Principle #17Another dimension (Dimensionality change)

3Productivity

If the system generates truncated sequences to maintain confidence thresholds, then the generation process remains fast and constrained, but the user experience deteriorates due to incomplete and confusing suggestions

Engineering Contradiction:
Improvegeneration speedVSAvoiduser experience
Core Design Contradiction:
ProductivityVSEase of operation

Solution Approach 1:

The system performs preliminary syntactic validation using a parser to ensure that generated candidates are complete and syntactically-correct before presenting them to the user. This preliminary check prevents the delivery of incomplete or confusing suggestions, significantly improving user experience while maintaining generation speed through efficient validation.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system uses syntactic parse results as feedback to guide the expansion process, adjusting expansion decisions based on whether intermediate structures are syntactically valid. This feedback mechanism ensures that generation remains focused on producing complete, valid candidates, improving both user experience and generation efficiency by avoiding pursuit of invalid paths.

Inventive Principle:
Principle #23Feedback

Data Source

PatentEP4338046B1Code completion including suggestions with holes
Publication Date: 2025.08.06 MICROSOFT TECHNOLOGY LICENSING LLC
  • EP4338046B1 patent drawingFigure 1
  • EP4338046B1 patent drawingFigure 2
  • EP4338046B1 patent drawingFigure 3

AI summary

A code completion tool uses a neural transformer model with attention to generate syntactically-correct candidates with holes to complete a partially-formed code snippet. The model is trained to predict the expansion of non-terminal symbols of the production rules of the underlying grammar of the code snippet without being constrained to a left-to-right expansion order. A hole is a non-terminal symbol of the grammar of a programming language that marks a position in a candidate where the code completion engine is not certain of the production rule that should be used to expand the non-terminal symbol. The hole allows the code completion engine to expand other non-terminal symbols in a candidate and allow the user to guide the expansion of the holes in a candidate.