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:
- a processor;
- and
- a memory that stores a program configured to be executed by the processor, wherein the program comprises instructions to perform acts that:
- receive an insertion point in a source code program to insert additional source code in between existing source code segments of the source code program, wherein the source code program is associated with a grammar comprising production rules, wherein a production rule comprises a rule for expanding a non-terminal symbol into one or more non-terminal symbols or one or more terminal symbols;
- extract a context surrounding the insertion point, the context including a prefix and a suffix of the insertion point;
- form an input sequence comprising the prefix, a single non-terminal symbol, and the suffix;
- input the input sequence into a grammar-guided code insertion engine to expand the single non-terminal symbol representing the statement into an output sequence comprising terminal symbols representing one or more source code statements to insert at the insertion point, wherein the grammar-guided code insertion engine comprises a selector neural network model and an expansion neural network model, wherein the selector neural network model determines a position of a select non-terminal symbol to expand for a given sequence of terminal and non-terminal symbols, wherein the expansion neural network model determines a production rule to expand the select non-terminal symbol;
- and
- upon user input, incorporate the one or more source code statements into the source code program at the insertion point.
A computer-implemented method, comprising:
- receiving a code insertion state comprising a prefix, a non-terminal symbol, and a suffix, wherein the prefix comprises source code prior to an insertion point, wherein the suffix comprises source code after the insertion point, wherein the insertion point is a location in a source code program to insert additional source code in between the prefix and the suffix, wherein the source code program is associated with a grammar comprising production rules, wherein a production rule comprises a rule for expanding a non-terminal symbol into one or more non-terminal symbols and/or one or more terminal symbols;
- inputting the code insertion state into a selector neural model to obtain at least one non-terminal symbol of the code insertion state to expand;
- inputting the at least one non-terminal symbol of the code insertion state to expand into an expansion neural model to determine the production rule to expand the at least one non-terminal symbol into a new code insertion state;
- continuously generating additional code insertion states by invoking the selector neural model to select a new non-terminal symbol to expand and the expansion neural model to determine a new production rule to perform the expansion, until a termination condition is met;
- and
- upon user input, input the code insertion state into the source code program.
A hardware storage device having stored thereon computer executable instructions that are structured to be executable by a processor of a computing device to thereby cause the computing device to perform actions that:
- obtain a location in a source code program to insert additional source code that is syntactically and semantically consistent with a surrounding context;
- construct a code insertion state comprising a prefix, a non-terminal symbol of a statement, and a suffix, wherein the prefix comprises source code of a source code program positioned immediately before the location, wherein the suffix comprises source code of the source code program positioned immediately after the location, wherein the source code program is associated with a grammar comprising a plurality of production rules;
- generate, by an expansion neural model, an encoding of a code insertion state;
- select, by a selector neural model, a position of a non-terminal symbol in the code insertion state to expand given the encoding of the code insertion state;
- determine, by the expansion neural model, a select one of the production rules of the plurality of production rules to expand the non-terminal symbol selected by the selector neural model, wherein the expansion generates a new code state;
- generate additional new code states until a termination condition exists, wherein the selector neural model generates the position of the non-terminal symbol in each additional new code state to expand and the expansion neural model determines the production rule to perform the expansion;
- and
- upon the termination condition being met, output a select one of the additional new code states into the source code program.
Dependencies are inferred from the claim text.