Code insertion completion
AssigneeMicrosoft Technology Licensing, LLC
InventorsNEELAKANTAN SUNDARESAN, ALEXEY SVYATKOVSKIY
Life of this patent
Estimating the term…
Abstract
A code insertion engine predicts one or more statements of a programming language to be inserted at an insertion point in between existing source code statements of a source code program being edited. The code insertion engine extracts the surrounding context of the insertion point which includes the source code immediately preceding and the source code immediately following the insertion point. The code insertion engine uses a neural expansion model and a neural selector model to predict the one or more statements most likely to be inserted into the insertion point that are syntactically and semantically consistent with the surrounding context of the existing program.
Claims20
A system comprising:
- one or more processors;
- and
- a memory that stores one or more programs configured to be executed by the one or more processors, the one or more programs including instructions to perform acts that:
- detect an insertion point in a source code program during an edit session, wherein the insertion point represents a location where additional source code is to be inserted in between existing source code segments of the source code program;
- extract a context surrounding the insertion point, the context including a prefix and a suffix of the insertion point;
- form an input sequence including the prefix, a single non-terminal symbol representing a statement, and the suffix;
- obtain from a code insertion engine, one or more source code statements to insert at the insertion point that are syntactically correct with the surrounding context, wherein the code insertion engine uses a non-terminal expansion model and a non-terminal selector model to expand the single non-terminal symbol into a sequence of terminal symbols representing the one or more source code statements given the input sequence;
- and
- display the one or more source code statements in the source code program.
A computer-implemented method, comprising:
- representing a source code program during an edit session as a tree of non-terminal symbols and terminal symbols;
- accessing a code insertion state of the source code program, wherein the code insertion state includes a prefix, an insertion point and a suffix, wherein the insertion point represents a location in the source code program where one or more source code statements are to be inserted in between the prefix and the suffix, wherein the prefix and the suffix represent existing source code segments of the source code program;
- representing the code insertion state as a sequence of terminal symbols representing the prefix, a single statement non-terminal symbol representing a statement, and a sequence of terminal symbols representing the suffix;
- expanding the code insertion state into an insertion candidate representing the one or more source code statements to be inserted at the insertion point, wherein the expansion expands the single statement non-terminal symbol representing a statement iteratively into a series of new code states using production rules of a grammar of a programming language of the source code program until a stop expansion condition exists;
- utilizing a non-terminal selector model to select a non-terminal symbol of each new code state to expand and a non-terminal expansion model to select a production rule to expand the selected non-terminal symbol;
- and
- upon detection of the stop expansion condition, presenting the insertion candidate in the source code program.
A non-transitory computer-readable storage medium having instructions that when executed performs operations, comprising:
- accessing a non-terminal expansion model to predict a production rule of a grammar of a programming language to expand a non-terminal symbol;
- accessing a non-terminal selector model to predict a non-terminal symbol to expand;
- obtaining a code insertion state of a source code program, the code insertion state including an input sequence of terminal symbols representing a prefix, a single non-terminal statement symbol, and terminal symbols representing a suffix, wherein the single non-terminal statement symbol represents a location in the source code program to insert predicted source code statements in between the prefix and the suffix;
- decoding the single non-terminal statement symbol into the predicted source code statements by iteratively expanding the single non-terminal statement symbol into new code states, a new code state having terminal symbols and zero or more non-terminal symbols, wherein the expansion uses the non-terminal selector model to select a non-terminal symbol to expand at each iteration and the non-terminal expansion model to choose the production rule to expand each selected non-terminal symbol;
- and
- generating the predicted source code statements upon expansion of a select one of the new code states into a sequence of all terminal symbols.
Dependencies are inferred from the claim text.