Code completion methods, devices, equipment, and storage media

By obtaining the code text change operations and the preset syntax tree, and updating the matching cache, the problem of low efficiency in recursive traversal matching when adding and deleting code text is solved, achieving more efficient code suggestions and improving the user editing experience.

CN119536704BActive Publication Date: 2025-12-02FOSHAN INST OF INTELLIGENT EQUIP TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411429442.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-12-02
Estimated Expiration
2044-10-14

AI Technical Summary

Technical Problem

In the current code editing process, when adding or deleting code text, recursive traversal matching needs to be repeatedly executed, resulting in low matching efficiency and affecting user experience.

Method used

By comparing code text change operations at preset intervals, the system obtains the language change operations and code change data of the code text, obtains the preset syntax tree of the code text's language, updates the matching cache, and determines code suggestion information based on code change data and preset syntax tree when adding or deleting code text.

Benefits of technology

It improves the matching efficiency of code suggestions and enhances the user experience when editing code, especially when the code text changes frequently.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536704B_ABST
    Figure CN119536704B_ABST
Patent Text Reader

Abstract

This invention discloses a code suggestion method, apparatus, device, and storage medium, belonging to the field of data processing technology. The method includes: acquiring code text; comparing the code text before and after a preset period according to a preset period to determine the code text's change operation and code change data; acquiring a preset syntax tree for the language corresponding to the code text; when the change operation is adding the code text, updating the matching cache according to the code change data and the preset syntax tree, and determining code suggestion information; when the change operation is deleting the code text, determining the code suggestion information according to the code change data, the preset syntax tree, and the matching cache; and outputting the code suggestion information. This invention aims to improve the matching efficiency of code suggestions and enhance the user experience when editing code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, specifically to a code hinting method, apparatus, device, and storage medium. Background Technology

[0002] Currently, to improve editing efficiency during code editing, there is generally a design that performs syntax matching based on the input code text and displays code suggestions based on the syntax matching results. The current method is generally to compare the code text with the syntax tree and perform recursive traversal matching. However, when there are both additions and deletions in the code text, the recursive traversal matching steps need to be repeated every time the code text is changed, resulting in low matching efficiency and easily affecting the user's experience when editing code. Summary of the Invention

[0003] The present invention provides a code hinting method, apparatus, device and storage medium to solve one or more technical problems existing in the prior art, and at least provide a beneficial option or create conditions.

[0004] This invention provides a code suggestion method, the code suggestion method comprising:

[0005] Obtain code text, compare the code text before and after the preset period according to the preset period, and determine the code text change operation and code change data;

[0006] Obtain the preset syntax tree of the language corresponding to the code text;

[0007] When the change operation is to add the code text, the matching cache is updated according to the code change data and the preset syntax tree, and the code hint information is determined;

[0008] When the change operation is to delete the code text, the code hint information is determined based on the code change data, the preset syntax tree, and the matching cache.

[0009] Output the code hint message.

[0010] Optionally, when the change operation is to add the code text, the step of updating the matching cache according to the code change data and the preset syntax tree, and determining the code suggestion information, includes:

[0011] When the change operation is to add the code text, the matching start position is determined according to the whitespace in the code change data, and there are several strings after the matching start position in the code change data;

[0012] Based on the order of the strings, find several target syntax nodes in the preset syntax tree that match each of the strings;

[0013] The target syntax nodes are mounted to the matching cache in the order corresponding to the strings;

[0014] The code hint information is formed by concatenating the character data of the target syntax node mounted in the matching cache.

[0015] Optionally, the matching cache includes multiple cache nodes, each cache node corresponding to each character in the code change data, and the step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings includes:

[0016] The start point of the target syntax node is attached to the cache node corresponding to the first character of the string;

[0017] The end point of the target syntax node is attached to the cache node corresponding to the last character of the string;

[0018] Establish a causal relationship between the target syntax nodes of adjacent strings, and attach the causal relationship to the cache node of the first character of the next string in the adjacent strings. The causal relationship represents the order between the target syntax nodes.

[0019] Optionally, when the change operation is to delete the code text, the step of determining the code hint information based on the code change data, the preset syntax tree, and the matching cache further includes:

[0020] When the change operation is to delete the code text, the code change data and the matching cache are compared to determine the target cache node of the deleted code text;

[0021] Delete the start point, the end point, and / or the causal relationship attached to the target cache node;

[0022] Based on the code change data, the target syntax node to be matched is re-determined, and the matching cache is updated;

[0023] The code hint information is formed by concatenating the character data of the target syntax node mounted in the matching cache.

[0024] Optionally, after the step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings, the method further includes:

[0025] The code change data is updated based on the character data of the target syntax node mounted in the matching cache;

[0026] Update the matching target syntax node according to the updated code change data, update the matching cache, and return to the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache, until the target syntax node has no change before and after the update;

[0027] The step of concatenating the character data of the target syntax node mounted in the matching cache to form the code hint information is performed.

[0028] Optionally, the step of searching for several target syntax nodes that match each of the strings in the preset syntax tree includes:

[0029] If no target syntax node matches the string, output a syntax error message.

[0030] Optionally, the preset syntax tree is formed by multiple leaf syntaxes and multiple branch syntaxes, wherein the leaf syntaxes include the target syntax node, and the branch syntaxes include sequential syntaxes, selection matching syntaxes, optional matching syntaxes, and / or arbitrary matching syntaxes.

[0031] Furthermore, to achieve the above objectives, this application also proposes a code suggestion device, the code suggestion device comprising:

[0032] An input module is used to acquire code text, compare the code text before and after the preset period according to a preset period, and determine the code text change operation and code change data.

[0033] A syntax tree module, which is used to obtain a preset syntax tree for the language corresponding to the code text;

[0034] A matcher module is configured to: when the change operation is to add the code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code suggestion information; when the change operation is to delete the code text, determine the code suggestion information according to the code change data, the preset syntax tree, and the matching cache;

[0035] The prompt output module is used to output the code prompt information.

[0036] In addition, to achieve the above objectives, this application also proposes a code suggestion device, the code suggestion device comprising: a memory, a processor, and a code suggestion program stored in the memory and executable on the processor, the code suggestion program being configured to implement the steps of the code suggestion method as described in any of the preceding claims.

[0037] In addition, to achieve the above objectives, this application also proposes a storage medium storing a code suggestion program, which, when executed by a processor, implements the steps of the code suggestion method as described in any of the preceding claims.

[0038] This invention has at least the following beneficial effects: By acquiring code text and comparing its changes before and after a preset period, the change operations and code change data of the code text are determined. Furthermore, a preset syntax tree corresponding to the language of the code text is acquired. When the change operation is adding code text, the matching data is used to match within the preset syntax tree, the matching cache is updated, and code suggestion information is determined. When the change operation is deleting code text, the matching cache updated when adding code text is combined with the code change data to match within the preset syntax tree, and code suggestion information is determined and finally output. Compared to recursively traversing and matching for each code text update, this application performs different matching operations for adding and deleting code text, and utilizes a matching cache to reduce the matching operations required when deleting code text, thereby improving the matching efficiency of code suggestions and enhancing the user experience when editing code. Attached Figure Description

[0039] The accompanying drawings are provided to further understand the technical solutions of the present invention and constitute a part of the specification. They are used together with the embodiments of the present invention to explain the technical solutions of the present invention, and do not constitute a limitation on the technical solutions of the present invention.

[0040] Figure 1 This is a flowchart illustrating the first embodiment of the code suggestion method of the present invention;

[0041] Figure 2 This is an example diagram of the syntax tree involved in the first embodiment of the code suggestion method of the present invention;

[0042] Figure 3 This is a matching diagram of the first embodiment of the code suggestion method of the present invention;

[0043] Figure 4 This is another matching diagram of the first embodiment of the code suggestion method of the present invention;

[0044] Figure 5 This is a schematic diagram illustrating the connection involved in the operation of an embodiment of the code prompting device of the present invention;

[0045] Figure 6 This is a schematic diagram of the device structure involved in the operation of an embodiment of the code prompting device of the present invention. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0047] It should be noted that although functional modules are divided in the system diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0048] This invention provides a code suggestion method. (Refer to...) Figure 1 This application presents a first embodiment of the code suggestion method. In this embodiment, the code suggestion method includes:

[0049] Step S10: Obtain the code text, compare the code text before and after the preset period according to the preset period, and determine the code text change operation and code change data.

[0050] When a user edits code, the code text edited by the user is obtained through a code input device. In this embodiment, the language of the code text is not limited; for example, it can be robot language code with structured text syntax. The obtained code text is compared at preset intervals to check whether the code text has changed before and after the preset interval. The preset interval can be set to, for example, 1 second or 3 seconds. By comparing the code text, the code text change operation can be determined when the code text changes. The change operation includes adding or deleting code text. Then, the code text involved in the change is determined to be code change data, and the code change data is stored in the text cache. Based on this, retrieving the code change data in the text cache is equivalent to retrieving the code content recently edited by the user.

[0051] Step S20: Obtain the preset syntax tree of the language corresponding to the code text.

[0052] On the other hand, the preset syntax tree corresponding to the language of the code text can be obtained. The syntax tree is used to represent the syntax structure of the programming language in a tree-like form. Each node in the tree represents a structure of the source code. The structure at the end of the syntax tree is the syntax node. By comparing the code text with the preset syntax tree, it is possible to analyze and determine whether the code text uses syntax that conforms to the language specification.

[0053] The preset syntax tree is configured in the environment in the form of a configuration file. After determining the language of the code text, the preset syntax tree can be obtained by loading the configuration file. For different languages, the corresponding preset syntax tree can be configured separately.

[0054] Step S31: When the change operation is to add code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code hint information.

[0055] Optionally, in addition to the text cache used to store code change data, this embodiment also sets up a matching cache to store the matching results between code change data and a preset syntax tree. Specifically, when the change operation is to add code text, the syntax node that matches the code change data is found in the preset syntax tree, and it is associated with the matching cache to realize the storage of the matching results. The syntax node includes the character data corresponding to the node, such as the syntax node of "=". By extracting the character data of the syntax node associated with the matching cache and performing concatenation processing, code prompt information can be obtained.

[0056] Step S32: When the change operation is to delete code text, determine the code hint information based on the code change data, the preset syntax tree, and the matching cache.

[0057] Optionally, when the change operation is to delete code text, the matching cache that was matched with the deleted code text during input can be used. This cache allows direct identification of the syntax nodes matching the deleted code text. Then, based on the code change data, the specific content to be deleted is determined. Based on this, the syntax nodes associated with the matching cache can be directly modified, and other adaptive modifications can be made according to the code change data and the preset syntax tree to update the matching cache. This determines the code suggestion information after deleting the code text, eliminating the need to start matching syntax nodes from scratch during deletion. From the user's perspective, this is equivalent to achieving a code suggestion backtracking effect when deleting code.

[0058] Step S40: Output code hint information.

[0059] Furthermore, the code hint information is output on the user's code editing interface to provide the user with information on the code syntax. In this embodiment, the output style and position of the code hint information are not limited. For example, it can be displayed below the input cursor or in a new window.

[0060] The embodiments of the present invention have at least the following beneficial effects: By acquiring code text and comparing the changes in the code text before and after a preset period, the change operation and code change data of the code text are determined. On the other hand, a preset syntax tree corresponding to the language of the code text is acquired. When the change operation is adding code text, the code change data is used to match from the preset syntax tree, the matching cache is updated, and then the code suggestion information is determined. When the change operation is deleting code text, the matching cache updated when adding code text is combined with the code change data to match from the preset syntax tree, and then the code suggestion information is determined and finally output. Compared with the recursive traversal matching required for each code text update, this application performs different matching operations for adding and deleting code text, and uses a matching cache to reduce the matching operations required when deleting code text, thereby improving the matching efficiency of code suggestions and improving the user experience when editing code.

[0061] Furthermore, in this embodiment, the preset syntax tree is formed by multiple leaf syntaxes and multiple branch syntaxes, and the branch syntaxes include sequential syntaxes, selection matching syntaxes, optional matching syntaxes, and / or arbitrary matching syntaxes.

[0062] Specifically, refer to Figure 2 , Figure 2 This is an example diagram of a syntax tree. It's important to note that both leaf syntax and branch syntax can be matched. Leaf syntax is equivalent to a syntax node in the syntax tree. Leaf syntax is located at the end of the syntax tree and stores lexical data. Lexical data includes the character data of the syntax nodes. A match is determined by comparing the lexical data with the text. Figure 2 The syntax tree shown includes leaf syntax L1, leaf syntax L2, leaf syntax L3, and leaf syntax L4, with their lexical representations indicated by dashed boxes. Sequential syntax is determined by whether its child nodes can be successfully matched in the correct order. Figure 2 In the sequence syntax S1, leaf syntax L2, and selection matching syntax O1, all leaf nodes are child nodes of the sequence syntax S1, and their matching order is leaf syntax L1 > leaf syntax L2 > selection matching syntax O1. The selection matching syntax determines whether a match exists by checking if any of its child nodes match. Figure 2 The child nodes of the selected matching syntax O1 include leaf syntax L3 and leaf syntax L4; the optional matching syntax ( Figure 2 (Not shown) has one and only one child node, which may not match. In this case, the optional matching syntax determines that the match is successful, and the child node can also be matched. In this case, the matching result of the optional matching syntax follows the matching result of the child node; any matching syntax ( Figure 2(Not shown) There is one and only one child node. This child node may not match. In this case, any matching syntax judges it as a successful match. This child node can also be matched. If the child node matches successfully, the arbitrary matching syntax matches successfully, and the child node can be matched again. If the child node fails to match, the arbitrary matching syntax fails. In addition to the two states of successful and failed matching, the leaf syntax also has a state of matching in progress. When the lexical expression and the text match completely, it is judged as a successful match. For example, the lexical expression is "VEL" and the text is also "VEL". However, for the case where the lexical expression is "number" and the text is "1", it is judged as a matching in progress. Only when the lexical expression and the text do not match completely is it judged as a failed match.

[0063] By constructing a preset syntax tree consisting of multiple leaf syntaxes and multiple branch syntaxes, the preset syntax tree can include as much of the syntax that may appear in the code text as possible, thereby achieving more complete matching, more comprehensive code suggestion effects, and improving the user's experience when editing code.

[0064] Furthermore, in this embodiment, the step of updating the matching cache based on the code change data and the preset syntax tree, and determining the code suggestion information when the change operation is to add new code text, includes:

[0065] When the change operation is to add code text, the starting position of the match is determined based on the whitespace characters in the code change data. After the starting position of the match, there are several strings in the code change data.

[0066] Based on the order of the strings, search for several target syntax nodes in the preset syntax tree that match each string.

[0067] Mount the target syntax nodes to the matching cache in the order of their corresponding strings.

[0068] The code hint message is generated by concatenating the character data of the target syntax node mounted in the matching cache.

[0069] Reference Figure 3 , Figure 3 This is a diagram illustrating the matching process when adding new code text. For clarity, it is combined with... Figure 2 Let's take the example of changing the code data to "VEL=1" to illustrate.

[0070] It should be noted that for spaces in the code-modified data, they are first converted to whitespace characters before matching. The first character in "VEL=1" above is a whitespace character. Figure 3The symbol SP represents a whitespace character. Using the whitespace character in the code change data as the starting position for matching ensures correct matching even after deleting non-whitespace content from the code text. Whitespace characters not present at the starting position in the code change data are ignored. Taking "VEL=1" as an example, there are three strings after the whitespace character: "VEL", "=", and "1". In this embodiment, each string must contain at least one character. Based on the order of the strings after the whitespace character, the target syntax node matching each character is searched sequentially in the preset syntax tree. The leaf syntax of the preset syntax tree includes the target syntax node. Furthermore, in the actual matching process, the matching is still determined character by character to see if the string formed by the combination of several characters matches the leaf syntax. There is no step of splitting the code change data into several strings; the "VEL=1" example above is only for illustrative purposes.

[0071] by Figure 2 Taking the syntax tree as an example, first, the child nodes of the sequential syntax S1 are judged. Leaf syntax L1 matches "VEL" successfully, and leaf syntax L2 matches "=" successfully. Then, the child nodes of the selection matching syntax O1 are judged. Among leaf syntaxes L3 and L4, leaf syntax L3 matches "1". Leaf syntax L3 is judged to be in a match, while leaf syntax L4 is judged to be in a failed match. For the target syntax node, only leaf syntaxes that are judged to be in a match or have been judged to be in a match are determined as target syntax nodes. Therefore, the target syntax nodes are determined to be leaf syntaxes L1, L2, and L3. Further, the target syntax nodes are mounted to the matching buffer according to the order of their corresponding strings, forming an association between the matching buffer and the target syntax nodes. When outputting code hints, the associated target syntax nodes are determined through the matching buffer, and the code hints are formed by concatenating the character data of the target syntax nodes, thus outputting the code hints.

[0072] By comparing the strings in the code change data with the syntax nodes in the preset syntax tree, the target syntax node is determined, thus achieving the matching and determination of code suggestion information. Furthermore, by mounting the target syntax node in the matching cache, it is easier to quickly determine the target syntax node when further editing the code text, thereby performing further syntax node matching, improving the matching efficiency of code suggestion, and enhancing the user's experience when editing code.

[0073] Furthermore, in this embodiment, the matching cache includes multiple cache nodes, each cache node corresponding to each character in the code change data. The step of mounting the target syntax nodes to the matching cache according to the order of the corresponding strings includes:

[0074] Mount the starting point of the target syntax node to the cache node of the first character of the corresponding string.

[0075] Attach the end point of the target syntax node to the cache node of the last character of the corresponding string.

[0076] Establish causal relationships between target syntax nodes of adjacent strings, and attach the causal relationships to the cache node of the first character of the next string in the adjacent strings. The causal relationships represent the order between target syntax nodes.

[0077] Specifically, refer to Figure 3 For each character in the code change data, a corresponding cache node exists for matching, including whitespace characters in the code change data. The start and end points of the target syntax node are attached to the cache node of the first character and the cache node of the last character of the corresponding string, respectively. If the string has only one character, the start and end points are both attached to the cache node of that character. Causal relationship represents the order relationship between different target syntax nodes. The causal relationship between two target syntax nodes corresponding to adjacent strings, where the target syntax node is attached to the cache node of the first character of the latter string, indicates that the former target syntax node leads to the latter target syntax node, and there is a causal relationship between the two target syntax nodes. In addition to the start point, end point, and causal relationship of the target syntax node being attached to the cache node, the branch syntax also has its own start point, end point, and causal relationship. When a child node of the branch syntax begins matching, the start point of the branch syntax is attached to the cache node of the first character of the string corresponding to the first matched child node, and the end point is attached to the cache node of the last character of the string corresponding to the last matched child node. Furthermore, causal relationships can be established not only between target syntax nodes (leaf syntax) but also between target syntax nodes and branch syntax, thus encompassing both leaf and branch syntax and establishing associations between various structures of the syntax tree in the matching cache. Moreover, for the first string after a whitespace character in the code change data, the start point associated with this first string is attached to the cache node corresponding to the whitespace character, not the cache node of the first character in the first string. This ensures that when deleting non-whitespace characters from the code text, the associations between syntax nodes can still be correctly traced back.

[0078] For example, with Figure 2 and Figure 3 For example, for "VEL=1", there are cache nodes numbered from 0 to 5, each corresponding to a character within it. Figure 3The dashed arrows indicate the matching process of the syntax tree, the solid arrows indicate the mounting status of each leaf and branch syntax with the cache nodes, the rounded rectangles indicate the nodes where matching begins, and the circles indicate the nodes where matching ends. When matching begins, SP is used as the starting position. The starting points of sequential syntax S1 and leaf syntax L1 are attached to cache node 0. Leaf syntax L1 is judged to match the string "VEL", so the ending point of leaf syntax L1 is attached to cache node 3, which is the last character "L" of "VEL". Then, leaf syntax L2 is judged to match the string "=", and both the starting and ending points of leaf syntax L2 are attached to cache node 4. At the same time, a causal relationship between leaf syntax L2 and leaf syntax L1 is established in cache node 4. Further, selection matching syntax O1 is judged, specifically whether leaf syntax L3 and leaf syntax L4 match "1". The starting points of selection matching syntax O1, leaf syntax L3, and leaf syntax L4 are attached to cache node 5. At the same time, a causal relationship between selection matching syntax O1 and leaf syntax L2 is established in cache node 5. Leaf syntax L3 is judged to be matching "1", while leaf syntax L4 is judged to be failing to match "1", and the matching ends.

[0079] By associating each character with a cache node, the start point, end point, and causal relationship of the target syntax node are determined and attached to the specific cache node, achieving a precise correspondence between code text and syntax nodes. This results in a more accurate code suggestion matching effect and facilitates faster identification of relevant target syntax nodes and the relationships between target syntax nodes when further editing code text, thereby improving the matching efficiency of code suggestions and enhancing the user's experience when editing code.

[0080] Furthermore, in this embodiment, when the change operation is to delete code text, the step of determining the code suggestion information based on the code change data, the preset syntax tree, and the matching cache further includes:

[0081] When the change operation is to delete code text, the code change data is compared with the matching cache to determine the target cache node of the deleted code text.

[0082] Remove the start point, end point, and / or causal relationship attached to the target cache node.

[0083] The target syntax node for matching is redefined based on the code change data, and the matching cache is updated.

[0084] The code hint message is generated by concatenating the character data of the target syntax node mounted in the matching cache.

[0085] Reference Figure 4 , Figure 4This is a diagram illustrating the matching process when deleting code text. The example shown is deleting the code text "VEL=1" to "VE".

[0086] Specifically, by comparing code change data and matching caches, the cache nodes of deleted code text and the cache nodes of remaining code text are determined. The cache node of the deleted code text is defined as the target cache node. Figure 4 For example, the target cache nodes include cache node 3, cache node 4, and cache node 5. Deleting the start point, end point, and / or causal relationship attached to the target cache nodes is equivalent to canceling the association between the matching cache and the related target syntax node. In the actual execution of this step, execution starts from the cache node with the last character of the original string, which is equivalent to the reverse of the process when adding new code text. If a causal relationship is attached to a cache node, the target syntax node related to the previous cache node can be determined based on the causal relationship, and thus the matching of the target syntax node can be traced back according to the causal relationship. Figure 4 Backtracking from cache node 5 to cache node 3, since "VE" cannot completely match leaf syntax L1, leaf syntax L1 is judged to be in a match. Cache node 3 cannot attach the end point of leaf syntax L1, the match ends, and the redefined target syntax node only includes leaf syntax L1.

[0087] It should be noted that the operation of deleting code text does not necessarily start from the last character. It may also start from the middle position to delete part of the characters. For example, deleting "VEL=1" to "VE=1". In this case, the target cache node is still determined first. Any cache node whose corresponding characters have changed is determined as the target cache node. In this example, the characters of cache node 3 to cache node 5 have changed. Similarly, the start point, end point and / or causal relationship attached to the target cache node are deleted.

[0088] Optionally, after deleting the start point, end point, and / or causal relationship attached to the target cache node, the target syntax node is redefined and the matching cache is updated. For code text deleted starting from the last character of the string, the target syntax node and matching cache are generally updated after deleting the start point, end point, and / or causal relationship attached to the target cache node. However, for code text deleted starting from the middle character of the string, the matching process described above for adding code text needs to be executed starting from the first cache node in the target cache node to determine whether there are other updates to the target syntax node and matching cache. For example, it may be that the user corrected the typo "VEEEL=1" to the correct "VEL=1". Finally, the character data of the target syntax node attached to the updated matching cache is concatenated to form the code hint information.

[0089] By utilizing the start point, end point, and causal relationship of the syntax nodes attached to the cache node, the matching process of the target syntax node can be traced back based on the attached content when deleting code text. Compared with the existing technology, which requires a complete recursive traversal matching before and after deletion, the matching operation is simplified. This improves the matching efficiency of code suggestion in scenarios where there are multiple input and deletion operations in the code text, and enhances the user's experience when editing code.

[0090] It should be noted that for leaf syntax that is determined to be matched, since the starting point of the leaf syntax has been mounted to the cache node, the leaf syntax also belongs to the target syntax node. When determining the code suggestion information, its corresponding character data will also be used to concatenate to form the code suggestion information. Based on this, the code suggestion effect including prediction function is achieved. For example, when the input code text is "VE", the code suggestion information output is "VEL".

[0091] Furthermore, in this embodiment, the step of searching for several target syntax nodes that match each string in the preset syntax tree includes:

[0092] If no target syntax node matching the string exists, output a syntax error message.

[0093] It should be noted that the matching results between the leaf syntax and the string include successful match, match in progress, and failed match. Only when it is determined that the leaf syntax does not match the string is it determined that the leaf syntax does not match the string. When there is no target syntax node that matches the string, that is, it does not exist in the leaf syntax that matches the string, it is determined to be a syntax error and a syntax error message is output.

[0094] In other embodiments, the matching results of branch syntax can also be monitored. When a branch syntax fails to match, it means that the structure of the currently input code text is different from that of the regular syntax, and a syntax error message can be output.

[0095] By outputting syntax error messages, in addition to providing users with positive code suggestions, it can also determine whether there are syntax errors in the code text currently being edited by the user, thereby correcting syntax problems in the code text and improving the user's experience when editing code.

[0096] Furthermore, based on the above embodiments, a second embodiment of the code hinting method of this application is proposed. (Refer to...) Figure 5 In this embodiment, after the step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings, the method further includes:

[0097] The code change data is updated based on the character data of the target syntax node mounted in the matching cache.

[0098] Update the matching target syntax node according to the updated code change data, update the matching cache, and return to the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache, until the target syntax node has no change before and after the update.

[0099] The step of concatenating the character data of the target syntax node mounted in the matching cache to form the code hint information is performed.

[0100] For certain parts of the code syntax, since their syntax rules are relatively fixed, the final text can be inferred from a small number of characters. Based on this, for the target syntax node mounted in the matching cache, new code change data can be formed by first concatenating the character data of the target syntax node. The updated code change data is regarded as the newly added code text, and the matching process of the target syntax node when adding code text in the above embodiment is executed again, thereby updating the target syntax node and the matching cache, until the target syntax node is not updated or changed before and after matching. Then, the step of concatenating the character data of the target syntax node to form code hint information can be executed.

[0101] By updating the code change data based on the character data of the target syntax node, and re-executing the matching process using the updated code change data, the output results can be used as input for further prediction, providing a more complete code suggestion effect and improving the user's experience when editing code.

[0102] On the other hand, reference Figure 5 , Figure 5 This is a connection diagram of the code completion device.

[0103] A code completion device is provided, the code completion device comprising:

[0104] The input module is used to acquire code text, compare the code text before and after the preset period according to the preset period, and determine the code text change operation and code change data.

[0105] The syntax tree module is used to obtain the preset syntax tree for the language corresponding to the code text.

[0106] The matcher module is used to: update the matching cache and determine the code suggestion information based on the code change data and the preset syntax tree when the change operation is adding code text; and determine the code suggestion information based on the code change data, the preset syntax tree, and the matching cache when the change operation is deleting code text.

[0107] The prompt output module is used to output code prompt messages.

[0108] Specifically, the input module is connected to the matcher module via a text cache. The input module is used to acquire code text, compare the code text before and after the preset period according to a preset period, determine the code text change operation and code change data, and store the code change data in the text cache. The syntax tree module is used to acquire the preset syntax tree of the language corresponding to the code text. The matcher module is also connected to the syntax tree module. The matcher module is used to acquire the preset syntax tree from the syntax tree module and acquire the code change data from the text cache. Based on the change operation, it determines the code prompt information according to the code change data and the preset syntax tree, and stores the code prompt information in the matching cache. The prompt output module is connected to the matcher module via the matching cache. The prompt output module is used to acquire the code prompt information from the matching cache and output it.

[0109] On the other hand, reference Figure 6 , Figure 6 This is a schematic diagram of the device structure of the code completion device.

[0110] A code completion device is provided, comprising: a processor and a memory; wherein the memory is used to store a computer-readable program. When the computer-readable program is executed by the processor, the processor causes the processor to implement the code completion method as described in any of the above technical solutions.

[0111] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. As is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0112] Furthermore, this embodiment of the invention also proposes a storage medium storing a code suggestion program, which, when executed by a processor, implements the relevant steps of any of the above-described code suggestion methods.

[0113] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatuses.

[0114] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0115] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, apparatuses, or units, and may be electrical, mechanical, or other forms.

[0116] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0117] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0118] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0119] Although the description of this application has been quite detailed and has particularly described several embodiments, it is not intended to limit itself to any of these details or embodiments or any particular embodiments, but should be regarded as effectively covering the intended scope of this application by referring to the appended claims and taking into account the prior art, which provides for a broad possible interpretation of these claims. Furthermore, the foregoing description of this application with respect to embodiments foreseeable by the inventors is intended to provide a useful description, and non-substantial modifications to this application that have not yet been foreseen may still represent equivalent modifications.

Claims

1. A code completion method, characterized in that, The code suggestion method includes: Obtain code text, compare the code text before and after the preset period according to the preset period, and determine the code text change operation and code change data; Obtain the preset syntax tree of the language corresponding to the code text; When the change operation is to add the code text, the matching cache is updated according to the code change data and the preset syntax tree, and the code hint information is determined; When the change operation is to delete the code text, the code hint information is determined based on the code change data, the preset syntax tree, and the matching cache. Output the code prompt message; When the change operation is to add the code text, the step of updating the matching cache based on the code change data and the preset syntax tree, and determining the code suggestion information, includes: When the change operation is to add the code text, the matching start position is determined according to the whitespace in the code change data, and there are several strings after the matching start position in the code change data; Based on the order of the strings, find several target syntax nodes in the preset syntax tree that match each of the strings; The target syntax nodes are mounted to the matching cache in the order corresponding to the strings; The code suggestion information is formed by concatenating the character data of the target syntax node mounted in the matching cache; The matching cache includes multiple cache nodes, each cache node corresponding to each character in the code change data. The step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings includes: The start point of the target syntax node is attached to the cache node corresponding to the first character of the string; The end point of the target syntax node is attached to the cache node corresponding to the last character of the string; Establish a causal relationship between the target syntax nodes of adjacent strings, and attach the causal relationship to the cache node of the first character of the next string in the adjacent strings. The causal relationship represents the order between the target syntax nodes.

2. The code suggestion method according to claim 1, characterized in that, When the change operation is to delete the code text, the step of determining the code suggestion information based on the code change data, the preset syntax tree, and the matching cache includes: When the change operation is to delete the code text, the code change data and the matching cache are compared to determine the target cache node of the deleted code text; Delete the start point, the end point, and / or the causal relationship attached to the target cache node; Based on the code change data, the target syntax node to be matched is re-determined, and the matching cache is updated; The code hint information is formed by concatenating the character data of the target syntax node mounted in the matching cache.

3. The code suggestion method according to claim 1, characterized in that, After the step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings, the method further includes: The code change data is updated based on the character data of the target syntax node mounted in the matching cache; Update the matching target syntax node according to the updated code change data, update the matching cache, and return to the step of updating the code change data according to the character data of the target syntax node mounted in the matching cache, until the target syntax node has no change before and after the update; The step of concatenating the character data of the target syntax node mounted in the matching cache to form the code hint information is performed.

4. The code suggestion method according to claim 1, characterized in that, The step of searching for several target syntax nodes that match each of the strings in the preset syntax tree includes: If no target syntax node matches the string, output a syntax error message.

5. The code suggestion method according to any one of claims 1 to 4, characterized in that, The preset syntax tree is formed by multiple leaf syntaxes and multiple branch syntaxes. The leaf syntaxes include the target syntax node, and the branch syntaxes include sequential syntaxes, selection matching syntaxes, optional matching syntaxes, and / or arbitrary matching syntaxes.

6. A code suggestion device, characterized in that, The code suggestion device includes: An input module is used to acquire code text, compare the code text before and after the preset period according to a preset period, and determine the code text change operation and code change data. A syntax tree module, which is used to obtain a preset syntax tree for the language corresponding to the code text; A matcher module is configured to: when the change operation is to add the code text, update the matching cache according to the code change data and the preset syntax tree, and determine the code suggestion information; when the change operation is to delete the code text, determine the code suggestion information according to the code change data, the preset syntax tree, and the matching cache; The prompt output module is used to output the code prompt information; When the change operation is to add the code text, the step of updating the matching cache based on the code change data and the preset syntax tree, and determining the code suggestion information, includes: When the change operation is to add the code text, the matching start position is determined according to the whitespace in the code change data, and there are several strings after the matching start position in the code change data; Based on the order of the strings, find several target syntax nodes in the preset syntax tree that match each of the strings; The target syntax nodes are mounted to the matching cache in the order corresponding to the strings; The code suggestion information is formed by concatenating the character data of the target syntax node mounted in the matching cache; The matching cache includes multiple cache nodes, each cache node corresponding to each character in the code change data. The step of mounting the target syntax nodes to the matching cache in the order corresponding to the strings includes: The start point of the target syntax node is attached to the cache node corresponding to the first character of the string; The end point of the target syntax node is attached to the cache node corresponding to the last character of the string; Establish a causal relationship between the target syntax nodes of adjacent strings, and attach the causal relationship to the cache node of the first character of the next string in the adjacent strings. The causal relationship represents the order between the target syntax nodes.

7. A code completion device, characterized in that, The code suggestion device includes: a memory, a processor, and a code suggestion program stored in the memory and executable on the processor, the code suggestion program being configured to implement the steps of the code suggestion method as described in any one of claims 1 to 5.

8. A storage medium, characterized in that, The storage medium stores a code suggestion program, which, when executed by a processor, implements the steps of the code suggestion method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Complex data matching method and medium

    CN111176656A

  • Intelligent contract code completion method based on deep neural network and global cache

    CN118092889A