Machine-Learning Code Completion With Ranked Method Suggestions
Find Innovative SolutionsGenerate 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
Engineering 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
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.
2Measurement precision
If code completion presents detailed context information, then accuracy of predictions is improved, but complexity of the system increases
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.
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.
3Measurement precision
If code completion analyzes more context features, then prediction accuracy is improved, but time to generate suggestions increases
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.
Data Source
Figure 1
Figure 2A~2B
Figure 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.