# US 2023/0409300 A1 · Source code structural inference based on indentation

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2023/0409300 A1
- Document ID: US20230409300A1
- Status: Published application
- Kind: A1
- Application number: 17/845,739
- Filed: 2022-06-21
- Published: 2023-12-21
- Earliest claimed: 2022-06-21
- Assignees: Microsoft Technology Licensing, LLC
- Applicants: Microsoft Technology Licensing, LLC
- Inventors: Johan Sebastian Heesemann ROSENKILDE; Albert ZIEGLER
- Web page: https://patentgrep.com/patent/US20230409300A1

## CPC

- G06F 8/427: {Parsing}
- G06F 8/75: Structural analysis for program understanding
- G06F 8/33: Intelligent editors
- G06F 8/433: {Dependency analysis; Data or control flow analysis}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Inferring source code structure based on indentation. A portion of source code comprising a plurality of lines is identified, and a corresponding indentation level for each line is determined. A plurality of nodes, each representing a different line in the plurality of lines are generated. The nodes are arranged into an ordered tree based on the corresponding indentation level for each line. Based on an identified line in the plurality of lines, a subset of the plurality of lines are identified from the ordered tree, based on identifying a subtree that comprises a node representing the identified line. A source code action is initiated based on the subset of the plurality of lines.

## Claims

### Claim 1

A method, implemented at a computer system that includes a processor, for inferring source code structure based on indentation, the method comprising:
identifying a portion of source code comprising a plurality of lines;
determining a corresponding indentation level for each line in the plurality of lines;
generating a plurality of nodes that each represents a different line in the plurality of lines;
arranging the plurality of nodes into an ordered tree based at least on the corresponding indentation level for each line in the plurality of lines;
based on an identified line in the plurality of lines:
identifying, from the ordered tree, a subtree that comprises a node representing the identified line;
identifying a subset of the plurality of nodes that correspond to the subtree; and
identifying a subset of the plurality of lines that are represented by the subset of the plurality of nodes as being syntactically-related to the identified line; and
initiating a source code action based on the subset of the plurality of lines.

### Claim 2 (depends on 1)

The method of claim 1, wherein a root node of the ordered tree corresponds to the portion of the source code, and wherein a set of children nodes of the root node corresponds to lines in the plurality of lines having a lowest indentation level.

### Claim 3 (depends on 1)

The method of claim 1, wherein determining the corresponding indentation level for each blank line in the plurality of lines comprises determining that each blank line has a same indentation level as an indentation level of a most recent non-blank line in the portion of the source code.

### Claim 4 (depends on 1)

The method of claim 1, wherein arranging the plurality of nodes into the ordered tree includes arranging a first node representing a first line in the plurality of lines as a parent of a second node representing a second line in the plurality of lines based on the second line being after the first line within the plurality of lines, and based on the second line having a greater indentation level than the first line.

### Claim 5 (depends on 1)

The method of claim 1, further comprising labeling a particular node in the plurality of nodes based on a current arrangement of the plurality of nodes, and based on a code structure defined by a line represented by the particular node.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
identifying a first node and a second node within the ordered tree, wherein the first node and the second node are siblings within the ordered tree;
determining that a second line represented by the second node has a syntactic dependency on a first line represented by the first node; and
based on the syntactic dependency, arranging the second node as a child of the first node within the ordered tree.

### Claim 7 (depends on 1)

The method of claim 1, further comprising:
creating a new virtual node, which does not correspond to any line of source code, within the ordered tree; and
re-arranging one or more existing nodes as children of the new virtual node.

### Claim 8 (depends on 1)

The method of claim 1, wherein initiating the source code action comprises inserting the subset of the plurality of lines into a language generation model prompt.

### Claim 9 (depends on 1)

The method of claim 1, wherein initiating the source code action comprises initiating a code folding action, on the subset of the plurality of lines, within a code editor interface.

### Claim 10 (depends on 1)

The method of claim 1, wherein initiating the source code action comprises visually displaying the subset of the plurality of lines as being contextually-relevant to the identified line.

### Claim 11

A computer system for inferring source code structure based on indentation, comprising:
a processor; and
a computer storage media that stores computer-executable instructions that are executable by the processor to cause the computer system to at least:
identify a portion of source code comprising a plurality of lines;
determine a corresponding indentation level for each line in the plurality of lines;
generate a plurality of nodes that each represents a different line in the plurality of lines;
arrange the plurality of nodes into an ordered tree based at least on the corresponding indentation level for each line in the plurality of lines;
based on an identified line in the plurality of lines:
identify, from the ordered tree, a subtree that comprises a node representing the identified line;
identify a subset of the plurality of nodes that correspond to the subtree; and
identify a subset of the plurality of lines that are represented by the subset of the plurality of nodes as being syntactically-related to the identified line; and
initiate a source code action based on the subset of the plurality of lines.

### Claim 12 (depends on 11)

The computer system of claim 11, wherein a root node of the ordered tree corresponds to the portion of the source code, and wherein a set of children nodes of the root node corresponds to lines in the plurality of lines having a lowest indentation level.

### Claim 13 (depends on 11)

The computer system of claim 11, wherein determining the corresponding indentation level for each blank line in the plurality of lines comprises determining that each blank line has a same indentation level as an indentation level of a most recent non-blank line in the portion of the source code.

### Claim 14 (depends on 11)

The computer system of claim 11, wherein arranging the plurality of nodes into the ordered tree includes arranging a first node representing a first line in the plurality of lines as a parent of a second node representing a second line in the plurality of lines based on the second line being after the first line within the plurality of lines, and based on the second line having a greater indentation level than the first line.

### Claim 15 (depends on 11)

The computer system of claim 11, wherein the computer-executable instructions also include instructions that are executable by the processor to cause the computer system to:
label a particular node in the plurality of nodes based on a current arrangement of the plurality of nodes, and based on a code structure defined by a line represented by the particular node.

### Claim 16 (depends on 11)

The computer system of claim 11, wherein the computer-executable instructions also include instructions that are executable by the processor to cause the computer system to at least:
identify a first node and a second node within the ordered tree, wherein the first node and the second node are siblings within the ordered tree;
determine that a second line represented by the second node has a syntactic dependency on a first line represented by the first node; and
based on the syntactic dependency, arrange the second node as a child of the first node within the ordered tree.

### Claim 17 (depends on 11)

The computer system of claim 11, wherein the computer-executable instructions also include instructions that are executable by the processor to cause the computer system to at least:
create a new virtual node, which does not correspond to any line of source code, within the ordered tree; and
re-arrange one or more existing nodes as children of the new virtual node.

### Claim 18 (depends on 11)

The computer system of claim 11, wherein initiating the source code action comprises at least one of:
inserting the subset of the plurality of lines into a language generation model prompt;
initiating a code folding action, on the subset of the plurality of lines, within a code editor interface; or
visually displaying the subset of the plurality of lines as being contextually-relevant to the identified line.

### Claim 19

A computer program product comprising a computer storage media that stores computer-executable instructions that are executable by a processor to cause a computer system to infer source code structure based on indentation, the computer-executable instructions including instructions that are executable by the processor to cause the computer system to at least:
identify a portion of source code comprising a plurality of lines;
determine a corresponding indentation level for each line in the plurality of lines;
generate a plurality of nodes that each represents a different line in the plurality of lines;
arrange the plurality of nodes into an ordered tree based at least on the corresponding indentation level for each line in the plurality of lines;
based on an identified line in the plurality of lines:
identify, from the ordered tree, a subtree that comprises a node representing the identified line;
identify a subset of the plurality of nodes that correspond to the subtree; and
identify a subset of the plurality of lines that are represented by the subset of the plurality of nodes as being syntactically-related to the identified line; and
initiate a source code action based on the subset of the plurality of lines.

### Claim 20 (depends on 19)

The computer program product of claim 19, wherein the computer-executable instructions also include instructions that are executable by the processor to cause the computer system to at least:
identify a first node and a second node within the ordered tree, wherein the first node and the second node are siblings within the ordered tree;
determine that a second line represented by the second node has a syntactic dependency on a first line represented by the first node; and
based on the syntactic dependency, arrange the second node as a child of the first node within the ordered tree.
