Code snippet localization method and apparatus
By obtaining code review results and comparing them using a large model and a dynamic sliding window algorithm, the problem of low efficiency and poor accuracy of manual code segment location in existing technologies is solved, achieving efficient and accurate code segment location.
Patent Information
- Application Number
- PCT/CN2026/078556
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-05-22
- Filing Date
- 2026-02-11
- Publication Date
- 2026-11-26
AI Technical Summary
In existing technologies, manually locating the problematic code segments in code review results requires a large amount of human resources and is subject to human error. Large models have poor computational capabilities and cannot accurately locate code segments.
By obtaining code review results, the target code snippet and its file path are output using a large model. The location of the code snippet is determined by comparing it with a text in a unified output format using a dynamic sliding window algorithm. Alternatively, the code snippet can be reconstructed for comparison when the large model cannot accurately locate it.
It enables accurate location of code segments without disrupting the code structure, reducing human resource consumption and human error, and improving the location accuracy of large models.
Smart Images

Figure CN2026078556_26112026_PF_FP_ABST
Abstract
Description
A method and apparatus for locating code fragments
[0001] This application claims priority to Chinese Patent Application No. 202510667784.1, filed on May 22, 2025, entitled "A Method and Apparatus for Locating Code Fragments", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This invention relates to the field of computer technology, and more specifically, to a method and apparatus for locating code fragments. Background Technology
[0003] In the field of Artificial Intelligence (AI) code review, the Unified Diff text is first input into a large model, and then code review results are generated. These results include problems found in the Unified Diff text, and the problems need to be precisely located to the corresponding code segments.
[0004] In existing technologies, manually locating the code segment containing the problem in the code review results not only requires a large amount of human resources but is also prone to human error. To reduce the consumption of human resources, a method has been proposed to locate the code segment corresponding to the problem by using a large model to calculate or return the line number. However, the computational power of the large model is relatively poor, and it cannot accurately locate the code segment.
[0005] In summary, accurately locating the code snippet corresponding to the problem is the current issue that needs to be addressed. Summary of the Invention
[0006] In view of this, embodiments of the present invention provide a method and apparatus for locating code fragments, which can accurately locate problematic code fragments in uniformly output format text.
[0007] In a first aspect, embodiments of the present invention provide a method for locating code snippets, the method comprising: obtaining code review results, wherein the code review results include the thought process during the code review process; inputting the code review results and pre-designed first prompt information into a large model, and outputting at least one target code snippet and the file path where the target code snippet is located, wherein the first prompt information is the format of the output content of the large model; obtaining the unified output format text to which the target code snippet belongs based on the file path; comparing the target code snippet with the unified output format text to generate a comparison result; and determining the position of the target code snippet based on the comparison result.
[0008] Optionally, comparing the target code fragment with the unified output format text to generate a comparison result specifically includes: using a dynamic sliding window algorithm to compare the target code fragment with the unified output format text to generate the comparison result.
[0009] Optionally, determining the location of the target code fragment based on the comparison result specifically includes: in response to the comparison result indicating that the target code fragment is included in the unified output format text, directly determining the location of the target code fragment in the unified output format text.
[0010] Optionally, determining the location of the target code fragment based on the comparison result specifically includes:
[0011] In response to the comparison result indicating that the target code fragment is not included in the unified output format text, the target code fragment is reconstructed;
[0012] The reconstructed target code fragment is compared with the unified output format text, and the position of the reconstructed target code fragment is directly determined in the unified output format text.
[0013] Optionally, the refactoring of the target code fragment specifically includes:
[0014] The unified output format text and the pre-designed second prompt information are input into the large model, and the target code fragment to be reconstructed and the file path where the target code fragment to be reconstructed are output. The second prompt information is the requirement for reconstructing the target code fragment.
[0015] Optionally, obtaining the code review results specifically includes:
[0016] The unified output format text is input into the large model, and the code review results are output.
[0017] Optionally, the method further includes:
[0018] The code suggestion for the target code snippet is inserted into the corresponding position of the target code snippet.
[0019] Optionally, the step of comparing the target code fragment with the uniformly formatted text using a dynamic sliding window algorithm to generate the comparison result specifically includes:
[0020] Identify multiple differing segments in the uniform output format text;
[0021] The target code snippet is compared with the multiple differing snippets using a dynamic sliding window algorithm to generate the comparison result.
[0022] Secondly, embodiments of the present invention provide a device for locating code snippets, the device comprising: an acquisition unit for acquiring code review results, wherein the code review results include the thought process during the code review process; a processing unit for inputting the code review results and pre-designed first prompt information into a large model, and outputting at least one target code snippet and the file path where the target code snippet is located, wherein the first prompt information is the format of the output content of the large model; the acquisition unit is further configured to acquire the unified output format text to which the target code snippet belongs based on the file path; a comparison unit for comparing the target code snippet with the unified output format text to generate a comparison result; and a determination unit for determining the position of the target code snippet based on the comparison result.
[0023] Optionally, the comparison unit is specifically used to: compare the target code fragment with the unified output format text using a dynamic sliding window algorithm, and generate the comparison result.
[0024] Optionally, the determining unit is specifically used to: in response to the comparison result indicating that the target code fragment is included in the unified output format text, directly determine the position of the target code fragment in the unified output format text.
[0025] Optionally, the determining unit is further configured to: in response to the comparison result that the target code segment is not included in the unified output format text, reconstruct the target code segment; compare the reconstructed target code segment with the unified output format text, and directly determine the position of the reconstructed target code segment in the unified output format text.
[0026] Optionally, the determining unit is specifically used to: input the unified output format text and the pre-designed second prompt information into the large model, and output the reconstructed target code fragment and the file path where the reconstructed target code fragment is located, wherein the second prompt information is the requirement for reconstructing the target code fragment.
[0027] Optionally, the acquisition unit is specifically used to: input the unified output format text into the large model and output the code review result.
[0028] Optionally, the processing unit is further configured to: insert code suggestions of the target code fragment into the position corresponding to the target code fragment.
[0029] Optionally, the comparison unit is specifically used to: determine multiple difference segments in the unified output format text; compare the target code segment with the multiple difference segments using a dynamic sliding window algorithm to generate the comparison result.
[0030] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect or any one of the possible methods of the first aspect.
[0031] Fourthly, embodiments of the present invention provide a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the method as described in the first aspect or any one of the possibilities of the first aspect.
[0032] In this embodiment of the invention, the following steps are taken: First, obtain code review results, including the thought process during the code review. Then, input the code review results and a pre-designed first prompt into a large model, outputting at least one target code fragment and the file path of the target code fragment. The first prompt is the format of the output content of the large model. Next, obtain the unified output format text to which the target code fragment belongs based on the file path. Then, compare the target code fragment with the unified output format text to generate a comparison result. Finally, determine the location of the target code fragment based on the comparison result. This method can accurately locate problematic code fragments within the unified output format text. Attached Figure Description
[0033] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings, in which:
[0034] Figure 1 is a flowchart of a code fragment location method according to an embodiment of the present invention;
[0035] Figure 2 is a flowchart of another code fragment location method in an embodiment of the present invention;
[0036] Figure 3 is a flowchart of another code fragment location method in an embodiment of the present invention;
[0037] Figure 4 is a flowchart of another code fragment location method in an embodiment of the present invention;
[0038] Figure 5 is a schematic diagram of a code segment positioning device in an embodiment of the present invention;
[0039] Figure 6 is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0040] The present application is described below based on embodiments, but it is not limited to these embodiments. In the detailed description of the present application below, certain specific details are described in detail. Those skilled in the art can fully understand the present application without these details. To avoid obscuring the substance of the present application, well-known methods, processes, flows, elements, and circuits are not described in detail.
[0041] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.
[0042] Unless the context explicitly requires it, words such as "including" or "contains" throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to".
[0043] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0044] In existing technologies, code review processes typically involve manually searching, using large-scale model-calculated line numbers, or having large-scale models return line numbers to locate code snippets corresponding to issues in the Unified Diff (UDF) text. This code review, also known as code inspection, refers to the systematic examination of computer source code, often conducted through peer review. Its purpose is to identify and correct errors missed in the early stages of software development, thereby improving software quality and the developer's technical skills. Large-scale model-based code review, or AI code review, is a method that uses artificial intelligence to assist or automate the software code review process. It combines machine learning, natural language processing, and static code analysis to analyze, evaluate, and improve code quality. During the review process, the code issues identified by the AI are simulated by humans writing comments on the code snippets using localization techniques. Specifically, manually locating the problematic code segment in the code review results is not only labor-intensive but also prone to human error. The large model calculates line numbers by providing examples (e.g., few-shots) to guide the calculation rules of the Diff head. The Diff head is the line in the Unified Diff that starts and ends with @@. For example, @@-1,7+1,6@@ indicates that the old code counts 7 lines from line 1, and the new code counts 6 lines from line 1. The old code is the code before modification, and the new code is the code after modification. The Unified Diff text is determined based on the old and new code. The large model calculates the line number of the problematic code segment according to the Diff head calculation rules, but its computational power is limited, resulting in inaccurate line number calculations and an inability to accurately locate the code segment. The large model returns the line number by calculating the line number using the Diff head, appending a line number identifier to the beginning of the line, and then returning the line number to the Diff file. The `head` function is input into a large model and returns the line number of the problematic code snippet. Some tools convert the Unified Diff code into old and new code before adding line numbers, and then add line numbers to each. However, the large model is not sensitive to numbers, leading to positional shifts in practice, making it impossible to accurately locate the code snippet. Adding line numbers before the old and new code also increases token consumption, alters the original code structure, and can cause a degree of model illusion. Therefore, accurately locating the problematic code snippet is the current problem that needs to be solved.
[0045] In this embodiment of the invention, the large model can also be called an Artificial Intelligence (AI) model or a Large Language Model (LLM). The large language model is a deep learning model based on a transformer architecture that can process and generate natural language text. It is usually trained on a large amount of text data and has the ability to understand and generate language. It is widely used in dialogue systems, text generation and other natural language processing tasks.
[0046] In this embodiment of the invention, to solve the above problems, a method for locating code snippets is proposed, as shown in Figure 1. The method includes:
[0047] Step S101: Obtain the code review results.
[0048] Specifically, the code review results include the thought process during the code review process.
[0049] In one possible implementation, the Unified Diff text is input into the large model, and the code review results are output.
[0050] The Unified Diff is a variant of the context format, omitting redundant context lines and making the format more compact. When generating the Unified Diff, the `lines` parameter is set to indicate the number of context lines to be displayed for the modified code. It is generally set to three lines by default. Specifically, the Unified Diff format can be generated using GNUdiff, where GNU diff is a command-line tool widely used in UNIX and UNIX-like systems for comparing the differences between two files or directories.
[0051] Step S102: Input the code review results and the pre-designed first prompt information into the large model, and output at least one target code fragment and the file path where the target code fragment is located.
[0052] Specifically, the first prompt message is the format of the output content of the large model, and the target code snippet is the code snippet with the problem.
[0053] Suppose that the first prompt message is as follows:
[0054] Please return the code questions summarized in the
thought
[0055] In this embodiment of the invention, the first prompt information is merely an illustrative example and may be determined based on actual circumstances. This embodiment of the invention does not limit its scope.
[0056] In one possible implementation, the answer output by the large model above includes not only the target code snippet and the file path where the target code snippet is located, but also a problem description and code suggestions.
[0057] In one possible implementation, a unified output format (Unified Diff) text and a pre-designed first prompt message can be input into the large model to output at least one target code snippet and the file path where the target code snippet is located. In this case, the at least one target code snippet and the file path where the target code snippet is located can be referred to as the code review result.
[0058] Step S103: Obtain the unified output format text to which the target code fragment belongs based on the file path.
[0059] Specifically, the file path is determined from the answer returned by the large model (also known as relevant_file), and the corresponding Unified Diff text is found based on the file path.
[0060] Step S104: Compare the target code fragment with the unified output format text to generate a comparison result.
[0061] Specifically, a dynamic sliding window algorithm is used to compare the target code snippet with the unified output format text to generate the comparison result.
[0062] In one possible implementation, the uniform output format text is split into multiple difference segments (Hunks); a dynamic sliding window algorithm is used to compare the target code segment with each of the multiple difference segments one by one to generate the comparison result; during the comparison, the first line of the target code segment is compared with the first new line in the Diff Hunk. Before the comparison, the "+" and "-" signs in the Diff Hunk are removed, and then the leading and trailing spaces in the Diff Hunk are removed by the trim operation to prevent indentation issues from causing matching failure; when the first line is successfully compared, the next line of the target code segment is compared with the next consecutive new line in the Diff Hunk that was successfully compared. If the comparison is successful, the above process is repeated until the last line of the target code segment is compared, that is, the comparison result is determined to be a successful comparison; if the comparison fails, the new lines in the Diff Hunk are slid down until the last new line is reached.
[0063] In one possible implementation, if the target code snippet is a single line, then a comparison of the first line is sufficient.
[0064] For example, suppose the target code snippet is as follows:
[0065] if(isFinished.get()){
[0066] return 0;
[0067] }
[0068] The unified output format text is as follows:
[0069] In this embodiment of the invention, the Unified Diff has a specific format, specifically: "---" represents the filename before the change, and "+++" represents the filename after the change; the lines starting and ending with "@@" indicate the range of lines that have changed, for example, "@@-1,7+1,7@@" indicates that there is a difference between the first 7 consecutive lines starting from line 1 of the first file and the second 7 consecutive lines starting from line 1; each line is preceded by an identifier to indicate that the line was deleted in the original file (represented by "-"), added in the modified file (represented by "+") (i.e., added), or not modified (represented by a space). The above Unified Diff is only an illustrative example; the Unified Diff can also include the number of context lines, which is determined according to the actual situation, and this embodiment of the invention does not limit it.
[0070] In the above target code snippet, three Diff Hunks are identified, namely Hunk1, Hunk2, and Hunk3; wherein, Hunk1 is:
[0071] The new line in Hunk1 is line 94.
[0072] The Hunk2 is:
[0073] The new line in Hunk2 is line 105.
[0074] The Hunk3 is:
[0075] The new lines in Hunk3 are line 113, line 114, line 115, and line 120. The target code segment is compared with the difference segments Hunk1, Hunk2, and Hunk3 one by one to determine that the target code segment is successfully compared with Hunk3. The above embodiments are only illustrative examples and the specific implementation should be determined according to the actual situation. The embodiments of the present invention do not limit the scope of the embodiments.
[0076] Step S105: Determine the location of the target code segment based on the comparison results.
[0077] In one possible implementation, determining the location of the target code segment based on the comparison result has two specific embodiments, as follows:
[0078] Specific Embodiment 1, as shown in Figure 2, includes the following steps after step S104:
[0079] Step S1051: In response to the comparison result indicating that the target code fragment is included in the unified output format text, the position of the target code fragment is directly determined in the unified output format text.
[0080] Specifically, assuming that the target code segment is successfully compared with lines 113, 114, and 115 of Hunk3, the position of the target code segment is determined to be lines 113 to 115.
[0081] Specific Embodiment Two, as shown in Figure 3, includes the following steps after step S104:
[0082] Step S1052: In response to the comparison result that the target code fragment is not included in the unified output format text, reconstruct the target code fragment.
[0083] In one possible implementation, while the large model excels at restating user input, the unique characteristics of the Unified Diff format and the syntactic and semantic features of the code mean that in some cases, the large model cannot follow instructions and may arbitrarily modify the code in the unified output format text before returning it to the user. Specifically, this includes the following three scenarios:
[0084] Scenario 1: The code style of the target code snippet is inconsistent with the mainstream style.
[0085] Specifically, when training large models, the coding style used may differ from mainstream styles, such as different formatting for line breaks and spaces. Large models cannot follow these instructions, so the line break formatting in the Unified Diff code will be modified. Example 1 illustrates this:
[0086] if(true)
[0087] {...}
[0088] Modified by the large model
[0089] if(true){
[0090] ...
[0091] }
[0092] Example 2:
[0093] new Object()
[0094] Modified by the large model
[0095] new Object()
[0096] Scenario 2: The target code snippet contains non-new lines. The scenario is more complex and diverse, meaning that the new and non-new code have a very strong dependency relationship.
[0097] Scenario 3: The target code snippet omits some lines that exist in the Unified Diff, resulting in the target code snippet being discontinuous and unable to match. The reason for this situation is that the problem code has a large number of lines or there are multiple discontinuous identical problems in a small code segment. The large model cannot follow the instructions and will omit the target code snippet.
[0098] All three of these situations will disrupt the continuity of the target code segment, making it impossible to match the target code segment in Unified Diff.
[0099] Step S1053: Compare the reconstructed target code segment with the unified output format text, and directly determine the position of the reconstructed target code segment in the unified output format text.
[0100] In one possible implementation, the reconstructing of the target code fragment specifically includes: inputting the unified output format text and the pre-designed second prompt information into the large model, and outputting the reconstructed target code fragment and the file path where the reconstructed target code fragment is located, wherein the second prompt information is the requirement for reconstructing the target code fragment.
[0101] In this embodiment of the invention, a sliding window algorithm is used to compare the reconstructed target code segment with the unified output format text. The specific comparison method is the same as the comparison method in step S104 above, and will not be repeated here. If the comparison is successful, the position of the reconstructed target code segment is determined. If the comparison fails, the processing ends and a comparison failure notification is returned.
[0102] Specifically, the second prompt information may include task settings, algorithm definitions, example (Few-Shot) learning, user prompt design, etc., wherein the user prompt design includes contextual information, task emphasis, etc., and the specific details are determined based on the actual situation.
[0103] For example, the task is set as follows:
[0104] You are a code comment location assistant. Your main responsibility is to help users accurately locate the target segment in code changes.
[0105] Users employ a diff-based dynamic sliding window algorithm for location, but sometimes the location may fail because the exact corresponding code snippet cannot be found in the code changes.
[0106] You will refer to the guidelines on "How to Provide Correct Target Code for Relocation" to help users provide the correct target code snippets, offering them more accurate target code snippets. Users can use your optimized code snippets for relocation to ensure comments are accurately placed in the correct location.
[0107] For example, the algorithm is defined as follows:
[0108] Used to help large models understand the algorithm's operating logic.
[0109] ### Dynamic Sliding Window Algorithm Based on Diff
[0110] Input: The original Diff, a snippet of target code (or a single line).
[0111] Execution: Using the line number of the target code snippet as the window size, line-by-line matching is performed in each Diff Hunk. After a successful match, the window is slid, and only newly added lines of code are matched during the sliding. Each time a match is performed, a trim operation is performed on the target content and the original content in the Diff.
[0112] Output: [Optional] The start and end indices of the window after a successful match.
[0113] For example, the algorithm is defined as follows:
[0114] Typical examples help large models learn why location failures occur and how to calibrate the target code to locate the correct location.
[0115] The target code snippet for the error example:
[0116] +the line code3
[0117] the line code4
[0118] or
[0119] the line code3
[0120] the line code4
[0121] At this point, you should return to the target code snippet:
[0122] +the line code3
[0123] #### The line break formatting in the target code is inconsistent with that in the code change; for example, merge multiple line breaks in the code change into a single line.
[0124] The code is under change.
[0125] At this point, you should return to the target code snippet:
[0126] +the line
[0127] +code2
[0128] +the line code3
[0129] #### Inconsistent whitespace formatting between the target code and the modified code, for example, writing `new Object()` as `new Object()` in the original code, causes a mismatch.
[0130] The code is under change.
[0131] The target code snippet for the error example:
[0132] +new Object()
[0133] At this point, you should return to the target code snippet:
[0134] +new Object()
[0135] #### During code changes, consecutive lines of code are omitted in the target code, such as blank lines or parts of lines, making it impossible to locate them.
[0136] The code is under change.
[0137] The target code snippet for the error example:
[0138] The target code snippet for the error example:
[0139] +the line code2
[0140] +the line code4
[0141] At this point, you should return to the target code snippet:
[0142] +the line code2
[0143] +
[0144] +the line code4
[0145] For example, the context information is as follows:
[0146] Provide the original code changes and a description of the current problem so that the larger model can be repositioned.
[0147] ###Code Changes
[0148] {diff}
[0149] ###Problem Description
[0150] {suggestion_content}
[0151] ###Code Changes
[0152] {diff}
[0153] ###Problem Description
[0154] {suggestion_content}
[0155] In this embodiment of the invention, the diff in the context information refers to the Unified Diff file input by the user.
[0156] For example, the emphasized task is as follows:
[0157] ###Task
[0158] - Based on the problem description, search through the code changes to find the approximate location.
[0159] Please re-output the target code snippet so that it can use the comment location algorithm to pinpoint the correct location in the code change.
[0160] Please return directly to the modified target code snippet; do not use ``` code snippet inclusions, and do not return any other content.
[0161] In one possible implementation, after step S105, the method further includes other steps, as shown in Figure 4, including the following steps:
[0162] Step S106: Insert the code suggestion of the target code fragment into the corresponding position of the target code fragment.
[0163] Specifically, the code suggestions are similar to GitHub's Suggestions feature, which allows code reviewers to directly propose applicable code modification suggestions in pull requests, simplifying the collaboration and code optimization process. That is, suggestions on how to modify the target code snippet, or code snippets to replace the target code snippet.
[0164] In one possible implementation, the target code snippet, along with its file path, a description of the problem, and code review results such as code suggestions, are inserted into the location of the target code snippet. This is called AI comment positioning. A derivative function can be used to modify the target code snippet with a one-click application of code suggestions, that is, to render the code suggestions onto the defined range of lines of code.
[0165] Through the above embodiments, there is no need to convert the format of the Unified Diff file or add line numbers to the Unified Diff. Without destroying the code structure of the Unified Diff, the target code fragments in the Unified Diff are accurately located through the dynamic sliding window algorithm of the Diff. Inaccurate location may only occur when there are multiple identical target code fragments in the extreme case of the Unified Diff file. In other cases, accurate location can be achieved, and token consumption is reduced, thus improving the performance of large models.
[0166] In this embodiment of the invention, a device for locating code fragments is provided, as shown in FIG5, specifically including: an acquisition unit 501, a processing unit 502, a comparison unit 503, and a determination unit 504;
[0167] The acquisition unit 501 is used to acquire code review results, including the thought process during the code review; the processing unit 502 is used to input the code review results and pre-designed first prompt information into the large model, and output at least one target code fragment and the file path where the target code fragment is located, wherein the first prompt information is the format of the output content of the large model; the acquisition unit 501 is also used to acquire the unified output format text to which the target code fragment belongs based on the file path; the comparison unit 503 is used to compare the target code fragment with the unified output format text to generate a comparison result; and the determination unit 504 is used to determine the position of the target code fragment based on the comparison result.
[0168] Furthermore, the comparison unit is specifically used to: compare the target code fragment with the unified output format text using a dynamic sliding window algorithm, and generate the comparison result.
[0169] Furthermore, the determining unit is specifically configured to: in response to the comparison result indicating that the target code fragment is included in the unified output format text, directly determine the position of the target code fragment in the unified output format text.
[0170] Furthermore, the determining unit is specifically configured to: in response to the comparison result that the target code segment is not included in the unified output format text, reconstruct the target code segment; compare the reconstructed target code segment with the unified output format text, and directly determine the position of the reconstructed target code segment in the unified output format text.
[0171] Furthermore, the determining unit is specifically used to: input the unified output format text and the pre-designed second prompt information into the large model, and output the reconstructed target code fragment and the file path where the reconstructed target code fragment is located, wherein the second prompt information is the requirement for reconstructing the target code fragment.
[0172] Furthermore, the acquisition unit is specifically used to: input the unified output format text into the large model and output the code review result.
[0173] Furthermore, the processing unit is also configured to: insert the code suggestion of the target code segment into the position corresponding to the target code segment.
[0174] Furthermore, the comparison unit is specifically used to: determine multiple difference segments in the unified output format text; and compare the target code segment with the multiple difference segments using a dynamic sliding window algorithm to generate the comparison result.
[0175] Figure 6 is a schematic diagram of the structure of the electronic device described in an embodiment of the present invention. As shown in Figure 6, it includes a general computer hardware structure, which includes at least a processor 601 and a memory 602. The processor 601 and the memory 602 are connected via a bus 603. The memory 602 is adapted to store instructions or programs executable by the processor 601. The processor 601 can be a standalone microprocessor or a collection of one or more microprocessors. Thus, the processor 601 executes the instructions stored in the memory 602 to perform the method flow of the embodiment of the present invention as described above, thereby realizing data processing and control of other devices. The bus 603 connects the above-mentioned components together, and also connects the above-mentioned components to a display controller 604, a display device, and an input / output (I / O) device 605. The input / output (I / O) device 605 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output device 605 is connected to the system via an input / output (I / O) controller 606.
[0176] The instructions stored in memory 602 are executed by at least one processor 601 to: obtain code review results, wherein the code review results include the thought process during the code review; input the code review results and pre-designed first prompt information into a large model, and output at least one target code fragment and the file path where the target code fragment is located, wherein the first prompt information is the format of the output content of the large model; obtain the unified output format text to which the target code fragment belongs based on the file path; compare the target code fragment with the unified output format text to generate a comparison result; and determine the position of the target code fragment based on the comparison result.
[0177] Specifically, the electronic device includes one or more processors 601 and a memory 602, with Figure 6 showing an example of one processor 601. The processor 601 and memory 602 can be connected via a bus or other means; Figure 6 shows an example of connection via a bus. The memory 602, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The processor 601 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions, and modules stored in the memory 602, thus implementing the aforementioned method for determining the location of code segments.
[0178] Memory 602 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; the data storage area may store an option list, etc. Furthermore, memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 602 may optionally include memory remotely located relative to processor 601, and these remote memories may be connected to external devices via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0179] One or more modules are stored in memory 602, and when executed by one or more processors 601, they execute the method for locating code fragments in any of the above method embodiments.
[0180] As those skilled in the art will recognize, various aspects of the embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, various aspects of the embodiments of the present invention can take the form of a completely hardware implementation, a completely software implementation (including firmware, resident software, microcode, etc.), or an implementation combining software and hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." Furthermore, various aspects of the embodiments of the present invention can take the form of a computer program product implemented in one or more computer-readable media having computer-readable program code implemented thereon.
[0181] Any combination of one or more computer-readable media can be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, (but not limited to) an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination thereof. More specific examples (not an exhaustive list) of computer-readable storage media will include: an electrical connection having one or more wires, a portable computer floppy disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable optical disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the context of embodiments of the present invention, a computer-readable storage medium can be any tangible medium capable of containing or storing a program used by or in conjunction with an instruction execution system, device, or apparatus.
[0182] Computer-readable signal media may include propagated digital signals having computer-readable program code implemented therein, such as in baseband or as part of a carrier wave. Such propagated signals may take any of a variety of forms, including, but not limited to, electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium that is not a computer-readable storage medium and can communicate, propagate, or transmit a program used by or in conjunction with an instruction execution system, device, or apparatus.
[0183] Program code implemented on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, fiber optic cable, RF, or any suitable combination thereof.
[0184] Computer program code for performing operations relating to various aspects of embodiments of the present invention can be written in any combination of one or more programming languages, including: object-oriented programming languages such as Java, Smalltalk, C++, etc.; and conventional procedural programming languages such as the "C" programming language or similar programming languages. The program code can be executed as a standalone software package entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet provided by an Internet service provider).
[0185] The flowchart illustrations and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present invention describe various aspects of the embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions (executed via the processor of the computer or other programmable data processing apparatus) create means for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0186] These computer program instructions may also be stored in a computer-readable medium that can direct a computer, other programmable data processing apparatus or other means to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing that includes instructions that implement the functions / actions specified in flowchart and / or block diagram blocks or blocks.
[0187] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus or other device to cause a series of operable steps to be performed on the computer, other programmable apparatus or other device to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide for implementing the functions / actions specified in flowchart and / or block diagram blocks or blocks.
[0188] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0189] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of such data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding access points are provided for users to choose to authorize or refuse processing. A user's refusal to process personal information beyond what is necessary for basic functions will not affect the user's use of basic functions.
Claims
1. A method for locating code snippets, characterized in that, The method includes: Obtain code review results, wherein the code review results include the thought process during the code review process; The code review results and the pre-designed first prompt information are input into the large model, and at least one target code snippet and the file path where the target code snippet is located are output, wherein the first prompt information is the format of the output content of the large model; Obtain the unified output format text of the target code fragment based on the file path; The target code snippet is compared with the unified output format text to generate a comparison result; The location of the target code fragment is determined based on the comparison results.
2. The method according to claim 1, characterized in that, The step of comparing the target code fragment with the unified output format text to generate a comparison result specifically includes: The target code snippet is compared with the uniform output format text using a dynamic sliding window algorithm to generate the comparison result.
3. The method according to claim 1, characterized in that, Determining the location of the target code segment based on the comparison result specifically includes: In response to the comparison result indicating that the target code fragment is included in the unified output format text, the position of the target code fragment is directly determined in the unified output format text.
4. The method according to claim 1, characterized in that, Determining the location of the target code segment based on the comparison result specifically includes: In response to the comparison result indicating that the target code fragment is not included in the unified output format text, the target code fragment is reconstructed; The reconstructed target code fragment is compared with the unified output format text, and the position of the reconstructed target code fragment is directly determined in the unified output format text.
5. The method according to claim 4, characterized in that, The refactoring of the target code fragment specifically includes: The unified output format text and the pre-designed second prompt information are input into the large model, and the target code fragment to be reconstructed and the file path where the target code fragment to be reconstructed are output. The second prompt information is the requirement for reconstructing the target code fragment.
6. The method according to claim 1, characterized in that, The process of obtaining code review results specifically includes: The unified output format text is input into the large model, and the code review results are output.
7. The method according to claim 1, characterized in that, The method further includes: The code suggestion for the target code snippet is inserted into the corresponding position of the target code snippet.
8. The method according to claim 2, characterized in that, The step of comparing the target code fragment with the uniformly output format text using a dynamic sliding window algorithm to generate the comparison result specifically includes: Identify multiple differing segments in the uniform output format text; The target code snippet is compared with the multiple differing snippets using a dynamic sliding window algorithm to generate the comparison result.
9. A device for locating code fragments, characterized in that, The device includes: An acquisition unit is used to acquire code review results, wherein the code review results include the thought process during the code review process; The processing unit is used to input the code review results and the pre-designed first prompt information into the large model, and output at least one target code fragment and the file path where the target code fragment is located, wherein the first prompt information is the format of the output content of the large model; The acquisition unit is further configured to acquire the unified output format text to which the target code fragment belongs based on the file path; The comparison unit is used to compare the target code fragment with the unified output format text and generate a comparison result; A determining unit is used to determine the location of the target code segment based on the comparison result.
10. An electronic device comprising a memory and a processor, characterized in that, The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-8.
