Hierarchical Code Completion via Markov Chain Models

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software development environments face challenges with automatic code completion when dealing with large, irrelevant lists of candidates, which can slow down development time and increase errors, particularly in hierarchically-structured languages like XAML.

Innovation Solution

A code completion system using first-order and second-order Markov chain models to predict tag and attribute names based on usage patterns, generating ranked candidate lists to assist developers in completing code fragments efficiently.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If statistical language modeling is used for automatic code completion, then code development time is reduced and common errors are reduced, but the list of candidates becomes large and not relevant, making it too lengthy for developers to browse

Engineering Contradiction:
Improvecode development timeVSAvoidbrowsing efficiency
Core Design Contradiction:
ProductivityVSEase of operation

Solution Approach 1:

The patent segments the code completion problem into two distinct tasks: tag name completion and attribute name completion. This is achieved by implementing separate completion logic that detects the current context (whether the cursor is positioned for a tag or attribute) and applies appropriate completion strategies. The segmentation allows each completion type to be optimized independently, preventing the mixing of irrelevant candidates that occurs in unified completion systems.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent applies local quality by providing different completion behaviors based on the local context in the code. When completing tag names, the system uses parent tag context and frequency-based ranking. When completing attribute names, it uses the specific tag context and attribute usage patterns. This context-aware approach ensures that only relevant candidates are presented at each location, improving browsing efficiency while maintaining high completion accuracy.

Inventive Principle:
Principle #3Local quality

2Adaptability or versatility

If a large list of code completion candidates is provided, then more possible options are available, but the list becomes too lengthy and irrelevant for developers to browse through efficiently

Engineering Contradiction:
Improvecandidate optionsVSAvoidbrowsing efficiency
Core Design Contradiction:
Adaptability or versatilityVSEase of operation

Solution Approach 1:

The patent extracts and removes irrelevant candidates from the completion list by implementing context-filtering mechanisms. For tag completion, it extracts only child tags relevant to the parent tag context. For attribute completion, it extracts only attributes relevant to the current tag. This extraction process eliminates unrelated options that would otherwise clutter the completion list, maintaining versatility while improving browsability.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent implements dynamic candidate selection that adapts the completion list based on the current code context. The system dynamically determines whether to show tag candidates or attribute candidates based on the cursor position and code structure. This dynamic behavior ensures that the candidate list remains concise and relevant, changing according to the immediate context rather than presenting a static, overly comprehensive list.

Inventive Principle:
Principle #15Dynamics

3Productivity

If automatic code completion is implemented, then development speed increases, but errors increase when developers cannot find the right element in a lengthy list

Engineering Contradiction:
Improvedevelopment speedVSAvoiderror rate
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent applies preliminary action by pre-ranking completion candidates based on their frequency and relevance to the current context. Instead of presenting candidates in an arbitrary or alphabetical order, the system pre-sorts them according to usage patterns and contextual relevance. This preliminary ordering ensures that the most likely correct element appears at the top of the list, reducing the time to find the right element and minimizing errors caused by overlooking the correct option in a lengthy unsorted list.

Inventive Principle:
Principle #10Preliminary action

4Measurement precision

If context-aware completion is implemented for hierarchically-structured languages, then prediction accuracy improves, but system complexity increases due to the need for hierarchical structure analysis

Engineering Contradiction:
Improveprediction accuracyVSAvoidsystem complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent introduces an intermediary parser component that handles the complex task of analyzing hierarchical language structures. The parser acts as a mediator between the raw code input and the completion logic, extracting relevant contextual information (parent tags, attribute sequences, nesting levels) without requiring the completion algorithms themselves to be complex. This intermediary layer simplifies the overall system architecture while enabling accurate context-aware predictions by preprocessing the structural information.

Inventive Principle:
Principle #24Intermediary (Mediator)

Data Source

PatentEP3959599B1Code completion for languages with hierarchical structures
Publication Date: 2024.11.06 MICROSOFT TECHNOLOGY LICENSING LLC
  • EP3959599B1 patent drawingFigure 1
  • EP3959599B1 patent drawingFigure 2A
  • EP3959599B1 patent drawingFigure 2B

AI summary

A code completion system predicts candidates to complete a code fragment with a tag name and/or an attribute name in source code written in a hierarchically-structured language. Candidates for predicting a tag name are based on a first-order tag Markov chain model generated from usage patterns of relationships of tag names found in a training dataset. Candidates for predicting an attribute name are based on a second-order attribute Markov chain model generated from usage patterns of sequences of attribute names associated with each tag name found in the training dataset.