Code repairing method and device, electronic equipment and computer storage medium
By constructing an abstract syntax tree and using a large language model to analyze the code, automatic repair suggestions are provided, solving the problems of low efficiency and insufficient accuracy in code repair caused by manual comparison, and achieving efficient and accurate code repair.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2026-03-27
AI Technical Summary
In existing technologies, code review mainly relies on manual comparison, which leads to low efficiency and insufficient accuracy in code repair, affecting the reliability of the repaired code.
By acquiring the initial code segment, constructing an abstract syntax tree and analyzing it using a large language model, code summary information is generated and matched with reference summary information in a preset database to provide repair suggestions and automatically repair the code.
It improves the efficiency of code repair and the accuracy of the repaired code, reduces human intervention, and ensures the quality of the repaired code.
Smart Images

Figure CN121742880A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of development, and in particular, relates to a code repair method and device, electronic equipment and computer storage medium. BACKGROUND
[0002] Code review refers to systematic review of computer source code, aiming to find and repair errors that are not found in the early stage of software development, and to improve software quality and developer technology. In related technologies, code review is usually performed by manual comparison, which may result in high labor costs, and the accuracy of manual comparison is low, resulting in low efficiency of code repair and affecting the accuracy and reliability of the repaired code. SUMMARY
[0003] The embodiments of the present application provide a code repair method, device, electronic equipment and computer storage medium, which can improve the efficiency of code repair and the accuracy and reliability of the repaired code. The above technical solution is as follows:
[0004] In a first aspect, the embodiments of the present application provide a code repair method, which comprises:
[0005] Obtaining an initial code segment;
[0006] Analyzing the initial code segment to obtain an analysis result of the initial code segment and repair suggestion information;
[0007] Displaying the analysis result and the repair suggestion information;
[0008] When a confirmation instruction for the repair suggestion information is detected, modifying the initial code segment based on the repair suggestion information to obtain a target code segment corresponding to the initial code segment.
[0009] In a possible implementation, the analysis of the initial code segment to obtain the analysis result of the initial code segment and the repair suggestion information comprises:
[0010] Determining an abstract syntax tree corresponding to the initial code segment according to the initial code segment;
[0011] Analyzing the abstract syntax tree to obtain the analysis result of the initial code segment and the repair suggestion information.
[0012] In a possible implementation, the analysis of the abstract syntax tree to obtain the analysis result of the initial code segment and the repair suggestion information comprises:
[0013] Inputting the abstract syntax tree into a preset large language model to determine code summary information of the abstract syntax tree by using the large language model.
[0014] matching the code summary information and a plurality of reference summary information in a preset database by using the large language model to obtain a matching result;
[0015] determining an analysis result and repair suggestion information of the initial code segment according to the matching result.
[0016] In a possible implementation, the determination of the code summary information of the abstract syntax tree by using the large language model comprises:
[0017] generating a corresponding code vector of the abstract syntax tree by using the large language model;
[0018] determining the code summary information of the abstract syntax tree based on the code vector.
[0019] In a possible implementation, the matching of the code summary information and a plurality of reference summary information in a preset database by using the large language model to obtain a matching result comprises:
[0020] determining a matching degree of the code summary information and each reference summary information in the plurality of reference summary information in the preset database to obtain a plurality of matching degrees of the code summary information and the plurality of reference summary information;
[0021] determining, as target summary information, a reference summary information in the plurality of reference summary information and having a matching degree greater than a preset threshold value with the code summary information;
[0022] determining the target summary information as the matching result.
[0023] In a possible implementation, the determination of the analysis result and repair suggestion information of the initial code segment according to the matching result comprises:
[0024] querying, according to the target summary information included in the matching result, a code exception type and code repair information corresponding to the target summary information in the preset database;
[0025] determining the code exception type corresponding to the target summary information as the analysis result of the initial code segment, and determining the code repair information as the repair suggestion information of the initial code segment.
[0026] In a possible implementation, after the analysis result and the repair suggestion information are displayed, the method further comprises:
[0027] When an upload instruction for the initial code segment is detected, the preset database is updated based on the initial code segment, the analysis result, and the repair suggestion information.
[0028] In a second aspect, the embodiments of the present application provide a code repair device, and the device comprises:
[0029] An acquisition module is configured to acquire an initial code segment.
[0030] An analysis module is configured to analyze the initial code segment to obtain an analysis result and repair suggestion information of the initial code segment.
[0031] A display module is configured to display the analysis result and the repair suggestion information.
[0032] A modification module is configured to modify the initial code segment based on the repair suggestion information to obtain a target code segment corresponding to the initial code segment when a confirmation instruction for the repair suggestion information is detected.
[0033] In a possible implementation, the analysis module comprises:
[0034] A first determination unit is configured to determine an abstract syntax tree corresponding to the initial code segment according to the initial code segment.
[0035] An analysis unit is configured to analyze the abstract syntax tree to obtain the analysis result and the repair suggestion information of the initial code segment.
[0036] In a possible implementation, the analysis unit comprises:
[0037] A first determination subunit is configured to input the abstract syntax tree into a preset large language model to determine code summary information of the abstract syntax tree by using the large language model.
[0038] A matching subunit is configured to match the code summary information and a plurality of reference summary information in a preset database by using the large language model to obtain a matching result.
[0039] A second determination subunit is configured to determine the analysis result and the repair suggestion information of the initial code segment according to the matching result.
[0040] In a possible implementation, the first determination subunit is specifically configured to:
[0041] Generate a corresponding code vector according to the abstract syntax tree by using the large language model.
[0042] Determine the code summary information of the abstract syntax tree based on the code vector.
[0043] In one possible implementation, the above matching subunit is specifically used for:
[0044] For each reference digest in a preset database, determine the matching degree between the code digest and the reference digest, and obtain multiple matching degrees between the code digest and the multiple reference digests.
[0045] Among the above multiple reference summary information, the reference summary information whose matching degree with the above code summary information is greater than a preset threshold is determined as the target summary information;
[0046] The above target summary information is identified as the matching result.
[0047] In one possible implementation, the aforementioned second determining subunit is specifically used for:
[0048] Based on the target summary information included in the above matching results, query the code exception type and code repair information corresponding to the above target summary information in the above preset database;
[0049] The code exception type corresponding to the target summary information is used as the analysis result of the initial code segment, and the code repair information is used as the repair suggestion information of the initial code segment.
[0050] In one possible implementation, after the display module displays the analysis results and repair suggestions, the apparatus further includes:
[0051] The update module is used to update the preset database based on the initial code segment, the analysis results, and the repair suggestion information when an upload command for the initial code segment is detected.
[0052] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory;
[0053] The aforementioned memory stores a computer program adapted to be loaded by the aforementioned processor and execute the steps of the method provided by the first aspect of the embodiments of this application or any possible implementation thereof.
[0054] Fourthly, embodiments of this application provide a computer storage medium storing a plurality of instructions adapted for loading by a processor and executing the steps of the method provided by the first aspect of the embodiments of this application or any possible implementation thereof.
[0055] This application embodiment obtains an initial code segment, analyzes it to obtain analysis results and repair suggestions, and then displays these results and suggestions. Upon detecting a confirmation instruction triggered by the repair suggestions, the initial code segment is modified based on these suggestions to obtain the target code segment. By automatically analyzing the initial code segment to generate corresponding analysis results and repair suggestions, no manual intervention is required. The obtained analysis results and repair suggestions are displayed to relevant developers. After detecting a confirmation instruction, the initial code is repaired according to the repair suggestions, resulting in a highly accurate target code segment. This effectively improves the efficiency of code repair and the accuracy and reliability of the repaired code segment. Attached Figure Description
[0056] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0057] Figure 1 A schematic diagram of the structure of a code repair system provided as an exemplary embodiment of this application;
[0058] Figure 2 A flowchart illustrating a code repair method provided for an exemplary embodiment of this application;
[0059] Figure 3 A schematic diagram of a code repair page provided for an exemplary embodiment of this application;
[0060] Figure 4 Another flowchart illustrating a code repair method provided for an exemplary embodiment of this application;
[0061] Figure 5 A detailed flowchart illustrating a code repair method provided for an exemplary embodiment of this application;
[0062] Figure 6 A schematic diagram of a code repair device provided for an exemplary embodiment of this application;
[0063] Figure 7 This is a schematic diagram of the structure of an electronic device provided as an exemplary embodiment of this application. Detailed Implementation
[0064] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0065] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0066] Please refer to the following. Figure 1 The example illustrates a schematic diagram of the structure of a code repair system provided in an embodiment of this application. Figure 1 As shown, the system includes a terminal 10 and a server 20, wherein the terminal 10 and the server 20 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0067] In some embodiments, terminal 10 may be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these. Terminal 10 may have related software installed for developers to write and modify code. Specifically, the related software may be a Chrome extension. A Chrome extension is a small software program used to extend and enhance browser functionality. It provides users with a programming interface for developing using technologies such as JavaScript (a computer programming language), Hyper Text Markup Language (HTML), and Cascading Style Sheets (CSS), thereby creating feature-rich extensions.
[0068] In some embodiments, server 20 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), big data and artificial intelligence platforms.
[0069] In some embodiments, the terminal 10 may be used to perform the following steps: obtaining an initial code segment; analyzing the initial code segment to obtain analysis results and repair suggestion information for the initial code segment; displaying the analysis results and repair suggestion information; when a confirmation instruction for the repair suggestion information is detected, modifying the initial code segment based on the repair suggestion information to obtain the target code segment corresponding to the initial code segment.
[0070] In other embodiments, the server 20 may further perform the following steps: obtaining an initial code segment; analyzing the initial code segment to obtain analysis results and repair suggestion information; displaying the analysis results and repair suggestion information; and when a confirmation instruction for the repair suggestion information is detected, modifying the initial code segment based on the repair suggestion information to obtain the target code segment corresponding to the initial code segment. The initial code segment is sent to the server 20 by the terminal 10, and the server 20 can feed back the analysis results and repair suggestion information to the terminal 10 so that the terminal 10 can display the analysis results and repair suggestion information.
[0071] Optionally, the initial code snippet mentioned above can be written or viewed by the relevant developers.
[0072] Optionally, the analysis results of the initial code segment may include vulnerabilities or errors that appear in the initial code segment, and may also include the error types corresponding to the vulnerabilities or errors.
[0073] Optionally, the repair suggestions for the initial code segment can be repair recommendations for vulnerabilities or errors identified in the analysis results. Specifically, this may include code modification information, refactoring suggestions, and the addition of comments.
[0074] Optionally, relevant pages can be rendered and generated based on the analysis results and the above-mentioned repair suggestions, so as to display the analysis results and the above-mentioned repair suggestions for developers to view.
[0075] Optionally, the aforementioned related page may also include a "Confirm Repair" button. When the "Confirm Repair" button is detected, a confirmation instruction for the aforementioned repair suggestion information is triggered.
[0076] An exemplary embodiment of this application provides a code repair method. This code repair method can be applied to the terminal 10 or the server 20 described above. Please refer to [reference needed] for details. Figure 2 The example illustrates a flowchart of a code repair method provided in an embodiment of this application. Figure 2 As shown, the code fix method includes the following S21-S24:
[0077] S21. Obtain the initial code segment.
[0078] The aforementioned initial code segment can be written or viewed by users (such as relevant developers).
[0079] In some embodiments, relevant tools can be used to obtain the initial code snippet. For example, a Chrome extension can be used to capture the code snippet written or viewed by the developer; another example is to use a Chrome extension to automatically capture the code snippet entered by the developer in the developer tools.
[0080] S22. Analyze the above initial code segment to obtain the analysis results and repair suggestions for the above initial code segment.
[0081] In some embodiments, the analysis results of the initial code segment may include vulnerabilities or errors found in the initial code segment, and may also include the error types corresponding to the vulnerabilities or errors. The remediation suggestions for the initial code segment may be remediation suggestions for the vulnerabilities or errors identified in the analysis results. Specifically, this may include code modification information, refactoring suggestions, and the addition of comments.
[0082] S23. Present the above analysis results and the above repair suggestions.
[0083] In some embodiments, a relevant code repair page can be generated based on the analysis results and the above-mentioned repair suggestions, so as to display the analysis results and the above-mentioned repair suggestions on the relevant page for developers to view.
[0084] S24. When a confirmation instruction for the above-mentioned repair suggestion information is detected, the initial code segment is modified based on the above-mentioned repair suggestion information to obtain the target code segment corresponding to the initial code segment.
[0085] In some embodiments, the code repair page may include a confirmation button. When the confirmation button is clicked, a confirmation instruction for the repair suggestion information is triggered, and the initial code segment is modified based on the repair suggestion information to obtain the target code segment corresponding to the initial code segment. The target code segment is the modified initial code segment.
[0086] Figure 3 A schematic diagram of a code repair page provided for an exemplary embodiment of this application, such as... Figure 3As shown, the code repair page can include display area 31 and display area 32. Display area 31 can be used to display the initial code segment, its analysis results, and repair suggestions. Display area 32 can be used to display the target code segment corresponding to the initial code segment. Displaying the initial code segment and its corresponding target code segment on the same page provides developers with a more intuitive viewing experience, facilitating their browsing and comparison of the two code segments.
[0087] In addition, the code repair page may also include a confirm button 33 and a cancel button 34. When the confirm button 33 is clicked, a confirmation instruction for the repair suggestion information is triggered. When the cancel button 34 is clicked, no processing is performed on the initial code segment.
[0088] In some embodiments, for an initial code segment, there may be multiple errors. For each of the multiple errors, a corresponding confirmation and repair button can be displayed. That is, there is a one-to-one correspondence between the error and the confirmation and repair button. When any confirmation and repair button is clicked, the error corresponding to that confirmation and repair button is repaired.
[0089] In this embodiment, the error and the confirmation / repair button correspond one-to-one, which allows developers to address at least some of the errors in a targeted manner, and makes it easier to locate and test each error, reducing the impact of error repair on other parts of the code and effectively improving code repair efficiency.
[0090] This application embodiment obtains an initial code segment, analyzes it to obtain analysis results and repair suggestions, and then displays these results and suggestions. Upon detecting a confirmation instruction for the repair suggestions, the initial code segment is modified based on these suggestions to obtain a target code segment. By automatically analyzing the initial code segment to generate corresponding analysis results and repair suggestions, and displaying them to relevant developers, and then repairing the initial code based on the repair suggestions after a confirmation instruction is detected, a highly accurate target code segment can be obtained. This effectively improves the efficiency of code repair and the accuracy and reliability of the repaired code segment.
[0091] In some embodiments, in S22 above, the initial code segment is analyzed to obtain the analysis results and repair suggestion information of the initial code segment, including S221-S222:
[0092] S221. Determine the abstract syntax tree corresponding to the initial code segment based on the initial code segment.
[0093] An Abstract Syntax Tree (AST) is a structured representation of the initial code segment. It displays the syntactic structure of the initial code segment in a tree format, rather than directly representing the textual form of the code. An AST can include multiple nodes, each representing a construct (such as an expression, statement, or operator) within the initial code segment. The hierarchical structure of the AST reflects the nesting and dependencies between the initial code segments. The root node of the AST corresponding to the initial code segment represents the entire initial code segment.
[0094] In some embodiments, the initial code segment described above can be input into a parser, such as Esprima (a JavaScript parser) or Babel (a JavaScript parser), so that the parser can generate an abstract syntax tree (AST) corresponding to the initial code segment. The AST provides a structured representation of the initial code segment, facilitating further analysis and processing.
[0095] S222. Analyze the above abstract syntax tree to obtain the analysis results and repair suggestions for the above initial code segment.
[0096] In some embodiments, the various parts of the initial code segment can be examined by traversing the nodes of the abstract syntax tree and applying specific rules to detect potential vulnerabilities or errors.
[0097] In some embodiments, in S222, the abstract syntax tree is analyzed to obtain the analysis results and repair suggestion information of the initial code segment, including S2221-S2223:
[0098] S2221. Input the above abstract syntax tree into a preset large language model to determine the code summary information of the above abstract syntax tree using the large language model.
[0099] Large language models refer to deep learning models trained on large amounts of text data that can generate natural language text or understand the meaning of language text. Large language models can handle various natural language tasks, such as text classification, question answering, and dialogue. Large language models include, but are not limited to, chatbot models (Chat Generative Pre-trained Transformer, ChatGPT) and ChatGPT-like models. In this implementation, the ChatGPT model will be used as an example to illustrate large language models.
[0100] In some embodiments, the aforementioned large language model can be a model privately deployed by an enterprise or individual. The enterprise or individual installs the large language model or its corresponding front-end application on their own server or in a dedicated cloud environment, rather than using public cloud services. This approach provides enterprises or individuals with higher data security and control capabilities, reduces the risk of data interception during internet transmission, and effectively improves the security and reliability of using the large language model.
[0101] In some embodiments, the code summary information described above may be a brief description or summary of the initial code segment, specifically including the main functions, key logic, and important implementation details of the initial code segment.
[0102] In some embodiments, in S2221, determining the code digest information of the abstract syntax tree using the large language model includes: generating a corresponding code vector based on the abstract syntax tree using the large language model; and determining the code digest information of the abstract syntax tree based on the code vector.
[0103] In some embodiments, generating corresponding code vectors based on the abstract syntax tree using the large language model includes: traversing multiple nodes in the abstract syntax tree using the large language model to extract structural and semantic information and other feature information of the initial code segment; the feature information may include node type, relationships between nodes (parent-child relationship), variable names, operators, etc.; and then converting the extracted feature information into numerical vectors as the code vectors corresponding to the abstract syntax tree. The code vectors can be generated based on the abstract syntax tree using any of the following related techniques: one-hot encoding, word embedding, etc.
[0104] S2222. Using the above-mentioned large language model, the above code summary information and multiple reference summary information in the preset database are matched to obtain the matching results.
[0105] In some embodiments, the aforementioned preset database may include multiple reference summary information, as well as code exception types and code repair information corresponding to each reference summary information. The data in the preset database may be collected from multiple sources, such as code exception and repair records extracted from open-source code repositories, obtained from official documentation of programming languages and developer communities, or annotated by relevant developers (e.g., developers annotate the reference summary information with corresponding code exception types and code repair information).
[0106] In some embodiments, the matching result is used to indicate that the preset library includes at least one reference digest information that matches the code digest information, or the matching result is used to indicate that the preset library does not include reference digest information that matches the code digest information.
[0107] In some embodiments, in S2222, the code digest information and multiple reference digest information in a preset database are matched using the large language model described above to obtain matching results, including S201-S203:
[0108] S201. For each reference digest in the multiple reference digest information in the preset database, determine the matching degree between the code digest information and the reference digest information, and obtain multiple matching degrees between the code digest information and the multiple reference digest information.
[0109] In some embodiments, determining the matching degree between the code digest information and the reference digest information can be achieved by any of the following methods: calculating the Jaccard similarity coefficient (used to compare the similarity and difference between a finite set of samples) between the code digest information and the reference digest information, calculating the cosine similarity between the code digest information and the reference digest information, or using a deep learning model to capture the relationship between words in the code digest information and the reference digest information.
[0110] S202. Among the above multiple reference summary information, the reference summary information whose matching degree with the above code summary information is greater than a preset threshold is determined as the target summary information.
[0111] S203. The above target summary information is determined as the matching result.
[0112] In some embodiments, if among the plurality of reference digests there is a target digest with a matching degree greater than a preset threshold that matches the code digest, then the target digest is determined as a matching result; if among the plurality of reference digests there is no target digest with a matching degree greater than a preset threshold that matches the code digest, then the matching result is determined to be that the preset library does not contain reference digests that match the code digest.
[0113] In this embodiment of the application, by calculating the similarity between the reference summary information and the code summary information, the reference summary information related to the initial code segment can be quickly filtered out, avoiding the inefficient work of manual comparison one by one, effectively improving the efficiency of summary information retrieval, and thus improving the efficiency of code review and repair.
[0114] S2223. Based on the above matching results, determine the analysis results and repair suggestions for the above initial code segment.
[0115] In some embodiments, in S2223, the analysis results and repair suggestion information of the initial code segment are determined based on the matching results, including:
[0116] Based on the target summary information included in the above matching results, the code exception type and code repair information corresponding to the target summary information are queried in the above preset database; the code exception type corresponding to the target summary information is used as the analysis result of the above initial code segment, and the above code repair information is used as the repair suggestion information of the above initial code segment.
[0117] In other embodiments, when the matching result indicates that the preset library does not contain reference digest information that matches the code digest information, a prompt message can be generated and displayed. The prompt message is used to indicate that there are no vulnerabilities or errors in the initial code segment and no code repair is required.
[0118] In this embodiment, by automatically matching code summary information and reference summary information, the code exception type can be quickly determined, saving time and effort in manual analysis; and then the repair suggestion information is provided to the developer, which can help the developer quickly locate the problem and provide a solution, greatly improving the efficiency of software development and maintenance.
[0119] In some embodiments, after displaying the analysis results and repair suggestions, the method further includes: when an upload instruction for the initial code segment is detected, updating the preset database based on the initial code segment, the analysis results, and the repair suggestions.
[0120] Specifically, updating the preset database based on the initial code segment, the analysis results, and the repair suggestions includes: uploading the code digest information corresponding to the initial code segment as reference digest information to the preset database; uploading the abnormal code type in the analysis results as the code abnormal type in the reference digest information to the preset database; and uploading the code repair suggestions as the code repair information in the reference digest information to the preset database, thereby updating the preset database.
[0121] The preset database in this embodiment can gradually build a more comprehensive code knowledge base by continuously absorbing new code segments and their corresponding analysis results and repair suggestions. As the data in the preset database increases, the system's analysis results and repair suggestions will become more accurate and reliable.
[0122] In some embodiments, the method further includes: obtaining the user's historical behavior information, which is used to indicate whether the user has triggered a confirmation instruction for the repair suggestion information; and then, in the step of analyzing the abstract syntax tree to obtain the analysis result and repair suggestion information of the initial code segment, the abstract syntax tree is analyzed in conjunction with the user's historical behavior information to obtain the analysis result and repair suggestion information of the initial code segment.
[0123] In this embodiment of the application, when generating analysis results and repair suggestions, the user's historical behavior information can be considered. The generation process of repair suggestions can be adjusted or optimized according to the user's past behavior patterns (such as acceptance or rejection of repair suggestions) to improve the relevance and effectiveness of repair suggestions, ensure that they are more in line with the user's needs and preferences, and provide more personalized repair suggestions and analysis results based on the coding habits and common problems of different developers.
[0124] Furthermore, the present application will be described below with reference to specific embodiments.
[0125] Figure 4 The following is a schematic diagram of another code repair method provided for an exemplary embodiment of this application. As shown in the figure, the code repair method may include the following processes: a user accesses a browser page, captures the initial code segment in the browser page, generates an abstract syntax tree, inputs the abstract syntax tree into a large language model, performs anomaly detection, generates analysis results and repair suggestion information, displays the analysis results and repair suggestion information, the user operates to apply the repair suggestions, and enhances the capabilities of the large language model based on the user's historical behavior, etc.
[0126] Specifically, Figure 5 A detailed flowchart illustrating a code repair method provided for an exemplary embodiment of this application is shown below. Figure 5 As shown, the code fix methods include the following S501-S514:
[0127] S501. Display the browser page. This browser page can be a page related to a Chrome extension, where users can write or view code.
[0128] S502, Obtain the initial code segment.
[0129] S503. Determine the abstract syntax tree corresponding to the initial code segment based on the initial code segment.
[0130] S504. Input the abstract syntax tree into the preset large language model, and use the large language model to generate the corresponding code vector based on the abstract syntax tree.
[0131] S505. Determine the code summary information of the abstract syntax tree based on code vectors.
[0132] S506. For each reference digest in the multiple reference digest information in the preset database, determine the matching degree between the code digest information and the reference digest information, and obtain multiple matching degrees between the code digest information and the multiple reference digest information.
[0133] S507. Determine whether the multiple matching scores include matching scores greater than a preset threshold. If yes, execute S508-S512; if no, execute S513-S514.
[0134] S508. Among multiple reference summary information, the reference summary information whose matching degree with the code summary information is greater than a preset threshold is determined as the target summary information.
[0135] S509. The target summary information is determined as the matching result.
[0136] S510. Based on the target summary information included in the matching results, query the code exception type and code repair information corresponding to the target summary information in the preset database.
[0137] S511. Use the code exception type corresponding to the target summary information as the analysis result of the initial code segment, and use the code repair information as the repair suggestion information of the initial code segment.
[0138] S512. Display the analysis results and repair suggestions.
[0139] S513. Determine that the matching result is a reference summary information that does not match the code summary information in the preset library.
[0140] S514. Generate and display the prompt message.
[0141] The specific implementation of the above steps in this embodiment has been described above and will not be repeated here.
[0142] In this embodiment, a large language model is used to analyze the abstract syntax tree, which can automatically detect and fix anomalies or errors in the code, reducing manual intervention. The combination of structured abstract syntax tree representation and the powerful analysis capabilities of the large language model can accurately identify and fix various types of code anomalies. In addition, code capture and repair are implemented through a Chrome extension, which is convenient to use and easy to integrate into the existing development process, improving development efficiency and code maintenance efficiency.
[0143] Please refer to the following. Figure 6 This is a schematic diagram of the structure of a code repair device provided in an exemplary embodiment of this application. Figure 6 As shown, the code repair device 600 includes:
[0144] Module 601 is used to obtain the initial code segment;
[0145] Analysis module 602 is used to analyze the above initial code segment and obtain the analysis results and repair suggestions of the above initial code segment;
[0146] Display module 603 is used to display the above analysis results and the above repair suggestions;
[0147] Modification module 604 is used to modify the initial code segment based on the repair suggestion information when a confirmation instruction for the above repair suggestion information is detected, so as to obtain the target code segment corresponding to the initial code segment.
[0148] In one possible implementation, the analysis module 602 includes:
[0149] The first determining unit is used to determine the abstract syntax tree corresponding to the initial code segment based on the initial code segment.
[0150] The analysis unit is used to analyze the abstract syntax tree mentioned above to obtain the analysis results and repair suggestions for the initial code segment.
[0151] In one possible implementation, the above-mentioned analysis unit includes:
[0152] The first determining subunit is used to input the above abstract syntax tree into a preset large language model, so as to use the above large language model to determine the code summary information of the above abstract syntax tree;
[0153] The matching subunit is used to match the code summary information and multiple reference summary information in the preset database using the large language model mentioned above, and obtain the matching result;
[0154] The second determining subunit is used to determine the analysis results and repair suggestions for the initial code segment based on the matching results.
[0155] In one possible implementation, the aforementioned first determining subunit is specifically used for:
[0156] Using the aforementioned large language model, corresponding code vectors are generated based on the aforementioned abstract syntax tree;
[0157] The code summary information of the abstract syntax tree is determined based on the code vectors described above.
[0158] In one possible implementation, the above matching subunit is specifically used for:
[0159] For each reference digest in a preset database, determine the matching degree between the code digest and the reference digest, and obtain multiple matching degrees between the code digest and the multiple reference digests.
[0160] Among the above multiple reference summary information, the reference summary information whose matching degree with the above code summary information is greater than a preset threshold is determined as the target summary information;
[0161] The above target summary information is identified as the matching result.
[0162] In one possible implementation, the aforementioned second determining subunit is specifically used for:
[0163] Based on the target summary information included in the above matching results, query the code exception type and code repair information corresponding to the above target summary information in the above preset database;
[0164] The code exception type corresponding to the target summary information is used as the analysis result of the initial code segment, and the code repair information is used as the repair suggestion information of the initial code segment.
[0165] In one possible implementation, after the display module 603 displays the analysis results and repair suggestions, the apparatus further includes:
[0166] The update module is used to update the preset database based on the initial code segment, the analysis results, and the repair suggestion information when an upload command for the initial code segment is detected.
[0167] The division of modules in the code repair device 600 described above is for illustrative purposes only. In other embodiments, the code repair device can be divided into different modules as needed to complete all or part of the functions of the code repair device. The implementation of each module in the code repair device provided in the embodiments of this specification can be in the form of a computer program. This computer program can run on a terminal or server. The program modules constituted by this computer program can be stored in the memory of the terminal or server. When the computer program is executed by a processor, it implements all or part of the steps of the code repair method described in the embodiments of this specification.
[0168] Please refer to the following. Figure 7 This is a schematic diagram of the structure of an electronic device provided in an exemplary embodiment of this application. Figure 7 As shown, the electronic device 700 may include a processor 710 and a memory 720, and may also include a user interface 730, a network interface 740 and a communication bus 750.
[0169] The processor 710 may include one or more processing cores. The processor 710 connects to various parts within the electronic device 700 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 720, and by calling data stored in the memory 720. Optionally, the processor 710 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 710 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system and applications; the GPU is responsible for rendering and drawing the content required for display on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 710 and may be implemented as a separate chip.
[0170] The memory 720 may include random access memory (RAM) or read-only memory. Optionally, the memory 720 may include a non-transitory computer-readable storage medium. The memory 720 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 720 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as receiving functions, control functions, etc.), instructions for implementing the various method embodiments described above, etc.; the data storage area may store data involved in the various method embodiments described above, etc. Optionally, the memory 720 may also be at least one storage device located remotely from the aforementioned processor 710. Figure 7 As shown, the memory 720, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and program instructions.
[0171] Optionally, the communication bus 750 is used to realize the connection and communication between these components. The user interface 730 may include a display screen, a camera, and may also include standard wired interfaces and wireless interfaces. The network interface 740 may optionally include standard wired interfaces and wireless interfaces (such as WIFI interfaces).
[0172] exist Figure 7 In the illustrated electronic device 700, the processor 710 can be used to call program instructions stored in the memory 720 and specifically perform the following operations:
[0173] Obtain the initial code segment;
[0174] The initial code segment described above was analyzed, and the analysis results and repair suggestions were obtained.
[0175] The above analysis results and repair recommendations are presented.
[0176] When a confirmation instruction for the above-mentioned repair suggestion information is detected, the initial code segment is modified based on the above-mentioned repair suggestion information to obtain the target code segment corresponding to the initial code segment.
[0177] In one possible implementation, the initial code segment is analyzed to obtain analysis results and repair suggestions, including:
[0178] Determine the abstract syntax tree corresponding to the initial code segment based on the initial code segment described above;
[0179] The abstract syntax tree described above is analyzed to obtain the analysis results and repair suggestions for the initial code segment.
[0180] In one possible implementation, the above-mentioned abstract syntax tree is analyzed to obtain the analysis results and repair suggestions for the initial code segment, including:
[0181] The above abstract syntax tree is input into a preset large language model to determine the code summary information of the above abstract syntax tree using the large language model;
[0182] The above-mentioned large language model is used to match the code summary information with multiple reference summary information in the preset database to obtain the matching results;
[0183] Based on the above matching results, the analysis results and repair suggestions for the above initial code segment are determined.
[0184] In one possible implementation, the code summary information for determining the abstract syntax tree using the large language model includes:
[0185] Using the aforementioned large language model, corresponding code vectors are generated based on the aforementioned abstract syntax tree;
[0186] The code summary information of the abstract syntax tree is determined based on the code vectors described above.
[0187] In one possible implementation, the above-mentioned large language model is used to match the code digest information with multiple reference digest information in a preset database to obtain matching results, including:
[0188] For each reference digest in a preset database, determine the matching degree between the code digest and the reference digest, and obtain multiple matching degrees between the code digest and the multiple reference digests.
[0189] Among the above multiple reference summary information, the reference summary information whose matching degree with the above code summary information is greater than a preset threshold is determined as the target summary information;
[0190] The above target summary information is identified as the matching result.
[0191] In one possible implementation, the analysis results and repair suggestion information for determining the initial code segment based on the matching results include:
[0192] Based on the target summary information included in the above matching results, query the code exception type and code repair information corresponding to the above target summary information in the above preset database;
[0193] The code exception type corresponding to the target summary information is used as the analysis result of the initial code segment, and the code repair information is used as the repair suggestion information of the initial code segment.
[0194] In one possible implementation, after presenting the above analysis results and repair suggestions, the method further includes:
[0195] When an upload command targeting the initial code segment is detected, the preset database is updated based on the initial code segment, the analysis results, and the repair suggestions.
[0196] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform one or more steps in the above embodiments. If the constituent modules of the above-described code repair device are implemented as software functional units and sold or used as independent products, they can be stored in the aforementioned computer-readable storage medium.
[0197] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The aforementioned available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state drives (SSDs)).
[0198] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks. Unless otherwise specified, the technical features of this embodiment and its implementation can be combined arbitrarily.
[0199] The above-described embodiments are merely preferred embodiments of this application and are not intended to limit the scope of this application. Any modifications and improvements made by those skilled in the art to the technical solutions of this application without departing from the spirit of this application should fall within the protection scope defined by the claims of this application.
Claims
1. A code repair method, characterized in that, include: Obtain the initial code segment; The initial code segment is analyzed to obtain the analysis results and repair suggestions. The analysis results and repair recommendations are presented. When a confirmation instruction for the repair suggestion information is triggered, the initial code segment is modified based on the repair suggestion information to obtain the target code segment corresponding to the initial code segment.
2. The method as described in claim 1, characterized in that, The analysis of the initial code segment to obtain the analysis results and repair suggestions includes: Determine the abstract syntax tree corresponding to the initial code segment based on the initial code segment; The abstract syntax tree is analyzed to obtain the analysis results and repair suggestions for the initial code segment.
3. The method as described in claim 2, characterized in that, The analysis of the abstract syntax tree to obtain the analysis results and repair suggestions for the initial code segment includes: The abstract syntax tree is input into a preset large language model to determine the code summary information of the abstract syntax tree using the large language model; The large language model is used to match the code summary information with multiple reference summary information in a preset database to obtain the matching result; The analysis results and repair suggestions for the initial code segment are determined based on the matching results.
4. The method as described in claim 3, characterized in that, The step of using the large language model to determine the code digest information of the abstract syntax tree includes: The large language model is used to generate corresponding code vectors based on the abstract syntax tree; The code digest information of the abstract syntax tree is determined based on the code vector.
5. The method as described in claim 3, characterized in that, The process of matching the code digest information with multiple reference digests in a preset database using the large language model to obtain matching results includes: For each reference digest in a preset database, determine the matching degree between the code digest and the reference digest, and obtain multiple matching degrees between the code digest and the multiple reference digests. Among the plurality of reference digest information, the reference digest information whose matching degree with the code digest information is greater than a preset threshold is determined as the target digest information; The target summary information is determined as the matching result.
6. The method as described in claim 5, characterized in that, The step of determining the analysis results and repair suggestion information of the initial code segment based on the matching results includes: Based on the target summary information included in the matching result, query the preset database for the code exception type and code repair information corresponding to the target summary information; The code exception type corresponding to the target summary information is used as the analysis result of the initial code segment, and the code repair information is used as the repair suggestion information of the initial code segment.
7. The method as described in claim 3, characterized in that, After displaying the analysis results and the repair recommendations, the method further includes: When an upload command for the initial code segment is detected, the preset database is updated based on the initial code segment, the analysis results, and the repair suggestion information.
8. A code repair device, characterized in that, include: The module is used to retrieve the initial code segment; The analysis module is used to analyze the initial code segment and obtain the analysis results and repair suggestions for the initial code segment. The display module is used to display the analysis results and the repair suggestions. The modification module is used to modify the initial code segment based on the repair suggestion information when a confirmation instruction for the repair suggestion information is detected, so as to obtain the target code segment corresponding to the initial code segment.
9. An electronic device, characterized in that, include: Processor and memory; The memory stores a computer program adapted to be loaded by the processor and to execute the steps of the method as described in any one of claims 1 to 7.
10. A computer storage medium, characterized in that, The computer storage medium stores a plurality of instructions adapted for loading by a processor and executing the steps of the method as described in any one of claims 1 to 7.