Machine-Learning Code Completion With Ranked Method Suggestions

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software development environments face challenges with lengthy and irrelevant code completion suggestions, making it difficult for developers to find the right code elements quickly.

Innovation Solution

A code completion tool utilizing sequential machine learning models, specifically n-order Markov chain models, to predict likely method completions based on context and usage patterns in source code, generating ranked candidate recommendations.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Quantity of substance

If traditional code completion presents all possible candidates, then completeness of suggestions is improved, but relevance and brevity deteriorate due to large list size

Engineering Contradiction:
Improvenumber of code completion candidatesVSAvoidrelevance of code completion candidates
Core Design Contradiction:
Quantity of substanceVSMeasurement precision

Solution Approach 1:

The patent transforms the code completion problem from presenting all possible candidates to predicting a limited set of highly relevant candidates by changing the approach from exhaustive listing to probabilistic prediction using n-order Markov chains. The system calculates transition probabilities based on historical usage patterns and context, then presents only the top candidates with highest probabilities, thereby maintaining completeness of relevant suggestions while eliminating irrelevant ones.

Inventive Principle:
Principle #35Parameter changes

2Measurement precision

If code completion presents detailed context information, then accuracy of predictions is improved, but complexity of the system increases

Engineering Contradiction:
Improveaccuracy of code completion predictionsVSAvoidcomplexity of machine learning model
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent segments the code completion task into manageable components: extracting contextual features (preceding methods, parameters, data types), computing transition probabilities for each feature combination, and ranking candidates based on cumulative probabilities. This segmentation allows the system to handle complex context analysis through multiple independent feature extractions rather than requiring a single monolithic complex model.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system computes transition probabilities for all possible context feature combinations (which would be excessive) but only uses the top-ranked candidates with highest probabilities for completion suggestions. This partial action approach computes more than needed but selectively applies only the most relevant results, achieving high accuracy without presenting all computed possibilities to the user.

Inventive Principle:
Principle #16Partial or excessive action

3Measurement precision

If code completion analyzes more context features, then prediction accuracy is improved, but time to generate suggestions increases

Engineering Contradiction:
Improveprediction accuracyVSAvoidtime to generate completion suggestions
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent performs preliminary actions by pre-computing and storing transition probabilities for all context feature combinations during an offline training phase using historical code data. During actual code completion, the system only needs to extract current context features and retrieve pre-computed probabilities, rather than performing complex analysis in real-time. This separates the computationally intensive probability computation from the fast retrieval operation.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentEP4147122B1Code completion with machine learning
Publication Date: 2025.09.17 MICROSOFT TECHNOLOGY LICENSING LLC
  • EP4147122B1 patent drawingFigure 1
  • EP4147122B1 patent drawingFigure 2A~2B
  • EP4147122B1 patent drawingFigure 3

AI summary

A code completion tool uses machine learning models to more precisely predict the likelihood of a method invocation completing a code fragment that follows one or more method invocations of different classes in a same document during program development. In one aspect, the machine learning model is a n-order Markov chain model that is trained on features that represent characteristics of the context of method invocations found in commonly-used programs from a sampled population. The machine learning model is implemented as a hash table contained a ranked order of hash values in descending order of probability of completing a partially-formed method invocation.