Cursor prediction method and system for code editing and related device

By constructing training samples and training a cursor prediction model, the cursor position of the target code is predicted based on the content and location of the code being edited, thus solving the problem of low cursor prediction accuracy in existing tools and improving the efficiency of code editing.

CN121541864APending Publication Date: 2026-02-17IFLYTEK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511499161.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-20
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing code editing tools lack the ability to dynamically perceive and predict the current editing context of the development object, resulting in low cursor prediction accuracy and affecting development efficiency.

Method used

By acquiring multiple target editing information of the target code, and using the trained cursor prediction model, reference editing information is filtered based on the code editing content, actual editing position, and associated editing position to construct training samples and train the cursor prediction model to predict the cursor position of the target code.

Benefits of technology

It improves code editing efficiency by reducing the frequency of movement of development objects during code editing through dynamic sensing and accurate cursor prediction, thereby increasing development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121541864A_ABST
    Figure CN121541864A_ABST
Patent Text Reader

Abstract

The invention discloses a cursor prediction method and system for code editing and a related device. The method comprises the steps of obtaining multiple pieces of target editing information matched with a target code; inputting the target editing information into the trained cursor prediction model, and obtaining a target cursor position to which a target code output by the cursor prediction model needs to jump; wherein the cursor prediction model is obtained by training a plurality of training samples, each training sample comprises reference editing information and a training label which are matched with each other, and the reference editing information is obtained by screening a plurality of initial editing information on the basis of code editing content, an actual editing position and an associated editing position; the initial editing information is determined based on the edited reference training code, the associated editing position is determined based on the code editing content matched with at least part of adjacent initial editing information, and the training label is determined based on the actual editing position. In this way, the code editing efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a cursor prediction method, system and related apparatus for code editing. Background Technology

[0002] Software development often involves code modification. During this process, developers frequently need to move the cursor to locate the target code, disrupting the continuity of coding and reducing development efficiency. Existing tools can provide some navigation support by analyzing the static structure of the code, but this approach lacks the ability to dynamically perceive and predict the current editing context, resulting in low prediction accuracy.

[0003] Therefore, how to propose a more accurate cursor prediction method to improve the efficiency of code editing in development objects has become an urgent problem to be solved. Summary of the Invention

[0004] The main technical problem addressed by this application is to provide a cursor prediction method, system, and related apparatus for code editing, which can improve the efficiency of code editing.

[0005] To address the aforementioned technical problems, this application provides a technical solution: a cursor prediction method for code editing, comprising: acquiring multiple target editing information matching the target code; inputting the target editing information into a trained cursor prediction model to obtain the target cursor position to which the target code needs to jump, as output by the cursor prediction model; wherein the cursor prediction model is trained using multiple training samples, the training samples including mutually matching reference editing information and training labels, the reference editing information being obtained by filtering multiple initial editing information based on code editing content, actual editing position, and associated editing position, the initial editing information being determined based on the edited reference training code, the associated editing position being determined based on the code editing content that matches at least a portion of the adjacent initial editing information, and the training labels being determined based on the actual editing position.

[0006] To address the aforementioned technical problems, another technical solution adopted in this application is: providing a cursor prediction system for code editing, comprising: an acquisition module for acquiring multiple target editing information matching the target code; and a prediction module for inputting the target editing information into a trained cursor prediction model to acquire the target cursor position to which the target code needs to jump, as output by the cursor prediction model; wherein the cursor prediction model is trained using multiple training samples, the training samples including mutually matching reference editing information and training labels, the reference editing information being obtained by filtering multiple initial editing information based on code editing content, actual editing position, and associated editing position, the initial editing information being determined based on the edited reference training code, the associated editing position being determined based on the code editing content that matches at least a portion of the adjacent initial editing information, and the training labels being determined based on the actual editing position.

[0007] The beneficial effects of this application are as follows: Unlike existing technologies, this application proposes a cursor prediction method for code editing. It determines multiple initial editing information based on edited reference training code, and then filters out multiple interrelated reference editing information from all initial editing information based on the code editing content, actual editing position, and associated editing positions. Training samples are determined based on the reference editing information, and a cursor prediction model is trained using these samples. The cursor prediction model then predicts the target cursor position based on target editing information within a historical time period, thereby locating the next editing position in the target code and improving the efficiency of editing target code. Attached Figure Description

[0008] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of 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. Wherein: Figure 1 This is a flowchart illustrating one implementation of the cursor prediction method for code editing in this application; Figure 2 This is a flowchart illustrating one implementation method of the training sample construction process in this application; Figure 3 yes Figure 2 The flowchart of step S201 corresponds to another embodiment; Figure 4 yes Figure 2 The flowchart of step S202 corresponds to another embodiment; Figure 5 yes Figure 2The flowchart of step S203 corresponds to another embodiment; Figure 6 This is a flowchart illustrating another implementation of the training sample construction method of this application; Figure 7 This is a schematic diagram of one embodiment of the cursor prediction system for code editing in this application; Figure 8 This is a schematic diagram of the structure of one embodiment of the electronic device of this application; Figure 9 This is a schematic diagram of one embodiment of the computer-readable storage medium of this application. Detailed Implementation

[0009] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments, and different embodiments can be adaptively combined. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0010] Please see Figure 1 , Figure 1 This is a flowchart illustrating one embodiment of the cursor prediction method for code editing according to this application. The method includes: S101: Obtain multiple target editing information matching the target code.

[0011] In one embodiment, for the target code, target editing information is obtained after the development object edits the target code.

[0012] In some implementation scenarios, to ensure the quality of the target code, developers may re-edit portions of the completed target code. Based on the content edited by developers within a historical timeframe, multiple target editing information entries are determined. The specific duration of the aforementioned historical timeframe can be set according to actual needs.

[0013] In one implementation, all historical editing information of the target code edited by the development object is obtained, and at least a portion of the historical editing information is used as the target editing information.

[0014] Specifically, all historical editing information that has been used to edit the target code is considered as target editing information. Alternatively, all historical editing information can be arranged according to the editing order to obtain a historical editing information sequence. Multiple consecutive historical editing information entries are extracted from this sequence as target editing information. The editing time of any target editing information entry must be later than the editing time of any other historical editing information entry in the aforementioned historical editing information sequence.

[0015] S102: Input the target editing information into the trained cursor prediction model to obtain the target cursor position that the target code needs to jump to, as output by the cursor prediction model; wherein, the cursor prediction model is trained using multiple training samples, the training samples include mutually matched reference editing information and training labels, the reference editing information is obtained by filtering multiple initial editing information based on code editing content, actual editing position and associated editing position, the initial editing information is determined based on the edited reference training code, the associated editing position is determined based on the code editing content that matches at least some of the adjacent initial editing information, and the training label is determined based on the actual editing position.

[0016] In one embodiment, a trained cursor prediction model is obtained, and the target editing information obtained through the above embodiments is input into the cursor prediction model. The cursor prediction model is used to predict the next editing position in the target code, and the target cursor position output by the cursor prediction model is obtained, so that the target code can be jumped to the target cursor position in the future, so that the developer can edit the code at the target cursor position.

[0017] In some implementation scenarios, the cursor prediction model described above is trained using multiple training samples. These training samples include mutually matched reference editing information and training labels, where the training labels represent the next editing position corresponding to the reference editing information. Furthermore, the reference editing information is obtained by filtering multiple initial editing pieces of information, which are determined based on the edited reference training code. In other words, through the training samples, the cursor prediction model learns during training how to predict the next editing position corresponding to the training label based on known reference editing information. The filtered reference editing information is interconnected.

[0018] In some implementation scenarios, the response to the reference edit information is part of the reference training code, and the training samples also include the reference training code between adjacent reference edit information. For example, for any training sample, if the starting editing position of its corresponding first reference edit information is line a in the reference training code, and the ending editing position of its corresponding final reference edit information is line b in the reference training code, then the code statements between lines a and b in the reference training code are used as training samples.

[0019] This application proposes a cursor prediction method for code editing. It determines multiple initial editing information based on edited reference training code, and then filters out multiple interrelated reference editing information from all initial editing information based on the code editing content, actual editing position, and associated editing positions. Training samples are determined based on the reference editing information, and a cursor prediction model is trained using these samples. The cursor prediction model then predicts the target cursor position based on target editing information within a historical time period, thereby locating the next editing position in the target code and improving the efficiency of editing target code.

[0020] Please see Figure 2 , Figure 2 This is a flowchart illustrating one implementation of the training sample construction process of this application. Specifically, the training sample construction process includes: S201: Based on the initial training code before editing and the reference training code after editing, obtain multiple initial editing information.

[0021] In one embodiment, initial training code before editing and reference training code after editing are obtained. The initial training code and the reference training code are compared to determine multiple differences in the reference training code. These differences are used as initial editing information.

[0022] In some implementation scenarios, the aforementioned discrepancy information includes multiple code editing statements, with each statement serving as the corresponding initial editing information. Multiple discrepancy information is determined by using the git diff algorithm to display all edits corresponding to the edited reference training code.

[0023] In one embodiment, in response to the aforementioned difference information including multiple code editing statements, a series of consecutive code editing statements are treated as a set of initial editing information. That is, the multiple code editing statements corresponding to any initial editing information are consecutive, and any two code editing statements in different initial editing information are not consecutive.

[0024] S202: Obtain the correlation information between the initial editing information, and based on the correlation information, filter out multiple first editing information from all the initial editing information.

[0025] In one embodiment, code semantic analysis is performed on the code editing content corresponding to each initial editing information to obtain the code semantics corresponding to each initial editing information. Based on the above code semantics, all initial editing information is clustered to obtain multiple sets of first editing information. Each set of first editing information includes multiple sets of first editing information, and all first editing information within the same set is interconnected.

[0026] It should be noted that in practical applications, since the reference training code contains a large number of code statements, multiple sets of first edit information can be obtained by filtering all the initial edit information. Subsequent filtering steps are performed for each set of first edit information to finally obtain at least one training sample corresponding to each set of first edit information.

[0027] S203: For at least a portion of adjacent first edit information, obtain the associated edit position determined based on the matched code edit content, and based on the associated edit position, filter out multiple reference edit information from all first edit information.

[0028] In one embodiment, all first edit information is sorted according to the editing order to obtain a first edit information sequence. For at least a portion of adjacent first edit information in the first edit information sequence, the corresponding code edit content is obtained, and the associated edit position determined based on the code edit content is obtained.

[0029] Furthermore, by using the determined associated editing positions to filter all first editing information, multiple reference editing information are obtained from all first editing information, so that the subsequent training samples constructed based on all reference editing information have a high degree of matching with the corresponding training labels.

[0030] S204: Obtain a reference editing information sequence composed of multiple reference editing information, and construct multiple training samples based on the reference editing information sequence.

[0031] In one embodiment, multiple obtained reference editing information are arranged in editing order to obtain a reference editing information sequence. Any reference editing information that is not the first element in the reference editing information sequence is used as a tag editing information, and the actual editing position of the code editing content corresponding to the tag editing information is used as a training tag. Based on at least some of the reference editing information preceding the tag editing information in the aforementioned reference editing information sequence and the training tag, corresponding training samples are constructed.

[0032] In some implementation scenarios, all reference editing information preceding the tag editing information, and the code statements between all reference editing information preceding the tag editing information, are used as training samples. Furthermore, the starting position of the code editing content corresponding to the tag editing information is used as the actual editing position, and the actual editing position is used as the training label for the aforementioned training samples.

[0033] In a specific application scenario, the obtained The reference editing information is sorted to obtain a reference editing information sequence. The reference editing information is included. As label editing information, the starting position of the code edit content corresponding to the label editing information in the reference training code is determined, that is, the actual editing position corresponding to the label editing information. The actual editing position is used as the training label, based on the reference editing information. Reference editing information The training samples are constructed using the aforementioned training labels.

[0034] In one embodiment, to improve training effectiveness, a pre-constructed sample template is obtained. After obtaining at least a portion of the reference editing information and training labels located before the label editing information, the reference editing information and training labels are filled into the corresponding positions in the sample template to obtain training samples.

[0035] In a specific application scenario, the above sample template is as follows: You are a {language} programming expert with rich practical experience in code development. You are able to analyze code structure, semantic logic, and code editing content from multiple dimensions to achieve accurate cursor prediction.

Objective

Requirements

Code Context

Code Editing Content

Return Format

HOP

NOHOP

[0036] In the sample template above, {language} represents the language, such as Java or Python. {file_content} is the context of the current cursor line, {file_path} is the relative path of the current reference training code, and {edit_history} represents the reference edit content. <|start|> and <|end|> are used to limit the range of cursor prediction.

[0037] The above scheme, after obtaining multiple initial editing information, performs multiple rounds of filtering on these initial editing information to finally obtain multiple interrelated training samples. Each training sample has a high degree of matching with its corresponding training label, which enables the cursor prediction model to learn how to predict the starting position of the next editing based on the existing reference editing information during subsequent training, thereby improving the training accuracy.

[0038] Alternatively, in other embodiments, in order to improve the efficiency of training sample construction, after obtaining multiple initial editing information, only step S202 can be performed to use the multiple first editing information obtained by filtering as reference editing information.

[0039] Please see Figure 3 , Figure 3 yes Figure 2 The flowchart of step S201 corresponds to another embodiment. Specifically, the implementation process of step S201 includes: S301: Obtain the initial difference information between the initial training code before editing and the reference training code after editing, and determine the matching degree between different initial difference information.

[0040] In one embodiment, initial training code before editing and reference training code after editing are obtained. The initial training code and the reference training code are compared to obtain multiple initial difference information. The process for determining the initial difference information can refer to the corresponding embodiment described above, and will not be elaborated further here.

[0041] Furthermore, static structural analysis is performed on the obtained initial difference information to obtain the matching degree between different initial difference information.

[0042] In some implementation scenarios, Tree-sitter's semantic analysis tools are used to perform static structural analysis on the acquired initial difference information, generating corresponding abstract syntax trees (ASTs). The tree edit distance between the ASTs corresponding to different initial difference information is calculated, and the matching degree between the corresponding initial difference information is determined based on the tree edit distance. The tree edit distance characterizes the structural similarity between different initial difference information; the smaller the tree edit distance, the higher the structural similarity between different initial difference information, and the higher the corresponding matching degree.

[0043] S302: Based on the matching degree, obtain multiple interrelated reference difference information from all initial difference information.

[0044] In one embodiment, multiple reference difference information are obtained from all initial difference information based on a determined matching degree. These multiple reference difference information are interconnected.

[0045] S303: Obtain the code edit content matched for each reference difference information, and determine the initial edit information from all reference difference information based on the code edit content.

[0046] In one embodiment, code editing content matching each reference difference information is obtained. In response to the code editing content including at least one code editing statement, the number of references for the code editing statement matching each reference difference information is obtained. In response to the number of references being less than a preset threshold, the corresponding reference difference information is used as initial editing information.

[0047] Specifically, a preset quantity threshold is obtained. If the number of code editing statements corresponding to the reference difference information is less than the preset quantity threshold, the reference difference information is used as the initial editing information. Alternatively, if the number of code editing statements corresponding to the reference difference information is greater than or equal to the preset quantity threshold, the reference difference information is removed. By filtering all reference difference information based on the number of corresponding code editing statements, excessively long reference editing information obtained later is avoided, which could affect the quality of training.

[0048] In one implementation, the code edit content matching each reference difference information is obtained, and the number of characters corresponding to the code edit content is obtained. If the number of characters is less than a set threshold, the corresponding reference difference information is used as the initial edit information.

[0049] In one embodiment, to improve sample construction efficiency, the implementation process of step S201 may also include: after obtaining multiple reference difference information through steps S301 and S302, using the reference difference information as initial editing information.

[0050] The above scheme, by filtering out multiple interrelated initial editing information and avoiding the code editing process corresponding to each initial editing information, helps to improve the quality of the initial editing information, thereby improving the quality of subsequent training.

[0051] Optionally, in one embodiment, the process of obtaining multiple initial editing information based on matching degree in steps S301 and S302 may further include: obtaining multiple initial difference information, sorting all initial difference information according to the editing order to obtain an initial difference information sequence; performing static structural analysis on the current initial difference information and the historical initial difference information adjacent to the current initial difference information in the initial difference information sequence to obtain the corresponding matching degree; and determining the correlation between the current initial difference information and the historical initial difference information when the matching degree is greater than a preset threshold, and using the current initial difference information as reference difference information.

[0052] In some implementation scenarios, each initial difference information is matched with a corresponding edit timestamp, which represents the edit time of the corresponding initial difference information. All initial difference information is sorted in ascending order of timestamps to obtain an initial difference information sequence. The first initial difference information in the sequence is used as the historical initial difference information, and the next initial difference information adjacent to it is used as the current initial difference information. Static structural analysis is performed on the historical and current initial difference information to determine their matching degree. If the matching degree is greater than a preset threshold, the historical and current initial difference information are used as reference difference information. Alternatively, if the matching degree is less than or equal to the preset threshold, the current initial difference information is removed from the initial difference information sequence. Further, the current initial difference information is updated to the historical initial difference information, the next initial difference information is used as the current initial difference information, and the process returns to the step of performing static structural analysis on the historical and current initial difference information, until all initial difference information is traversed and all reference difference information is obtained.

[0053] It should be noted that, in order to improve data utilization and avoid data waste, all initial difference information removed from the initial difference information sequence is used to construct a new initial difference information sequence, and the above steps are repeated to filter out the corresponding reference difference information from the new initial difference information sequence. Furthermore, subsequent steps are performed separately for the reference difference information filtered from the new initial difference information sequence to construct the corresponding training samples.

[0054] Please see Figure 4 , Figure 4 yes Figure 2 The flowchart of step S202 corresponds to another implementation method. Specifically, the code editing content is matched with an identifier, which corresponds to adding or deleting an editing category. Based on this, the implementation process of step S202 includes: S401: Based on the editing order of all initial editing information, determine the current initial editing information and other initial editing information that precedes the current initial editing information from all initial editing information.

[0055] In one embodiment, all the selected initial edit information is sorted according to the editing order to obtain an initial edit information sequence. The current initial edit information, as well as other initial edit information preceding the current initial edit information, are then determined from this sequence.

[0056] In some implementation scenarios, after obtaining the initial editing information sequence, the first initial editing information is used as other initial editing information, and the next initial editing information adjacent to other initial editing information is used as the current initial editing information.

[0057] S402: For other initial editing information, obtain the set of historical newly added identifiers corresponding to the newly added editing category, and the set of historical deleted identifiers corresponding to the deleted editing category.

[0058] In one embodiment, for each code edit content corresponding to other initial editing information, an identifier corresponding to the code edit content is obtained. In response to each identifier corresponding to a newly added or deleted editing category, in the code edit content corresponding to other initial editing information, all identifiers corresponding to newly added editing categories are grouped into a historical set of newly added identifiers, and all identifiers corresponding to deleted editing categories are grouped into a historical set of deleted identifiers.

[0059] In some implementation scenarios, the code editing content corresponding to each initial editing information includes at least one code editing statement. Each code editing statement is matched with an identifier, which includes editing category information, either a new editing category or a deleted editing category. In response to determining that there are multiple other initial editing information entries, for each of the code editing statements corresponding to all other initial editing information entries, the identifiers of the code editing statements corresponding to the new editing category are used to form a historical set of newly added identifiers; and for each of the code editing statements corresponding to the code editing statements corresponding to the deleted editing category, the identifiers of the code editing statements are used to form a historical set of deleted identifiers.

[0060] S403: For the current initial editing information, obtain the current set of newly added identifiers corresponding to the newly added editing category, and the current set of deleted identifiers corresponding to the deleted editing category.

[0061] In one embodiment, the code editing content corresponding to the current initial editing information includes at least one code editing statement. For all code editing statements corresponding to the current initial editing information, identifiers of code editing statements corresponding to the new editing category are added to form a current set of newly added identifiers; and for all code editing statements corresponding to the current initial editing information, identifiers of code editing statements corresponding to the delete editing category are deleted to form a current set of deleted identifiers.

[0062] In a specific application scenario, the first character of a code editing statement is either "+" or "-". The "+" character indicates that the corresponding code editing statement is a new editing category, and the "-" character indicates that the corresponding code editing statement is a delete editing category. The code editing statement with the "+" character is added to the historical new identifier set or the current new identifier set, and the code editing statement with the "-" character is added to the historical delete identifier set or the current delete identifier set.

[0063] In one implementation, for the code editing content corresponding to other initial editing information, the code editing statements corresponding to custom variables or custom functions are divided into a historical set of newly added identifiers and a historical set of deleted identifiers based on identifiers. Similarly, for the code editing content corresponding to the current initial editing information, the code editing statements corresponding to custom variables or custom functions are divided into a currently added identifier set and a currently deleted identifier set based on identifiers. This approach allows for greater focus on the user-defined functions and variables during the partitioning process, improving the accuracy and flexibility of the partitioning.

[0064] It should be noted that in practical applications, the execution order of steps S402 and S403 can also be different. For example, step S403 can be executed first, followed by step S402; or, steps S402 and S403 can be executed simultaneously.

[0065] S404: In response to the intersection of the historical set of newly added identifiers and the current set of newly added identifiers, or the intersection of the historical set of deleted identifiers and the current set of deleted identifiers, the current initial editing information is used as the first editing information.

[0066] In one embodiment, the intersection of the historical set of newly added identifiers and the current set of newly added identifiers is calculated; and the intersection of the historical set of deleted identifiers and the current set of deleted identifiers is calculated. In response to the existence of an intersection between the historical set of newly added identifiers and the current set of newly added identifiers, or an intersection between the historical set of deleted identifiers and the current set of deleted identifiers, it is determined that the current initial edit information is related to other initial edit information, and the current initial edit information is used as the first edit information.

[0067] The above scheme filters all initial editing information by using identifiers that match the code editing content, resulting in a high degree of matching between the first editing information. This improves the ability of the cursor prediction model to determine whether different editing contents match during the training process.

[0068] Please see Figure 5 , Figure 5 yes Figure 2The flowchart of step S203 corresponds to another embodiment. Specifically, the implementation process of step S203 includes: S501: Based on the editing order of each first editing information, determine the current first editing information and at least one other first editing information that precedes the current first editing information from all the first editing information.

[0069] In one embodiment, all first edited information is sorted according to the editing order to obtain a first edited information sequence. The current first edited information is determined from the first edited information sequence, and all first edited information preceding the current first edited information are designated as other first edited information.

[0070] In one embodiment, after obtaining the first editing information sequence, the current first editing information is determined in the first editing information sequence; and, a portion of the first editing information located before the current first editing information is taken as other first editing information, that is, a plurality of first editing information located before the current first editing information and adjacent to the current first editing information are taken as other first editing information.

[0071] S502: Obtain the associated editing position determined by the code editing content matched based on other first editing information, and the actual editing position of all code editing statements matched by the current first editing information.

[0072] In one embodiment, the associated editing position is obtained based on the code editing content matched with other first editing information. Also, the starting position of all code editing statements matched with the current first editing information is obtained, and this starting position is used as the actual editing position.

[0073] In some implementation scenarios, the aforementioned associated editing locations can be obtained by relevant annotators through annotation of code editing content matched with other first editing information.

[0074] In a specific application scenario, the code editing content that responds to the current first editing information includes multiple code editing statements. If the multiple code editing statements are located on lines 10, 11, and 12 of the reference training code, then line 10 of the reference training code will be taken as the actual editing position corresponding to the current first editing information.

[0075] S503: In response to the fact that the associated editing position is consistent with the actual editing position, the current first editing information is used as the reference editing information.

[0076] In one implementation, it is determined whether the associated edit position is consistent with the actual edit position. If they are consistent, the current first edit information is used as the reference edit information. If they are inconsistent, it indicates that the actual edit position of the current first edit information is unrelated to the code edit content matched with other first edit information, and the current first edit information is removed from the first edit information sequence to avoid affecting the quality of subsequent training sample construction.

[0077] S504: Traverse all first-edit information until all reference editing information is obtained from all first-edit information.

[0078] In one embodiment, in the first editing information sequence, the next first editing information is taken as the current first editing information, and the process returns to step S501 above, and subsequent steps are executed sequentially until all reference editing information is obtained from all first editing information.

[0079] The above scheme filters the first edit information based on the associated edit position and the actual edit position to determine whether the actual edit position of the current first edit information is related to the code edit content matched by other first edit information. It removes the current first edit information with poor relevance to avoid the cursor prediction model learning relationships between irrelevant code edit content, thus improving the training quality.

[0080] Please see Figure 6 , Figure 6 This is a flowchart illustrating another implementation of the training sample construction method of this application. The constructed training samples also include multiple negative samples, and the specific construction process of the negative samples includes: S601: Obtain negative sample labels that match the last round of reference editing information in the reference editing information sequence.

[0081] In one embodiment, after obtaining the reference editing information sequence through the corresponding implementation methods described above, a corresponding negative sample label is generated based on the last round of reference editing information in the reference editing information sequence.

[0082] In some implementation scenarios, the negative sample labels mentioned above can be any code location in the corresponding reference training code.

[0083] S602: Construct negative samples based on all reference editing information and negative sample labels.

[0084] In one implementation, negative samples are constructed by combining all reference editing information and the aforementioned negative sample labels.

[0085] Specifically, all reference editing information indicates that the editing of the reference training code has been completed. In order to prevent the trained cursor prediction model from predicting new cursor positions after completing the last round of cursor prediction, corresponding negative sample labels are generated based on the last round of reference editing information. This allows the subsequent cursor prediction model to avoid predicting the next cursor position after predicting all target cursor positions.

[0086] S603: Construct negative samples based on the partial code editing content matched by any reference editing information and the actual editing position corresponding to the next reference editing information.

[0087] In one embodiment, for any reference edit information, the matching partial code edit content is obtained. And, for the next reference edit information, its corresponding actual edit position is used as a negative sample label, and negative samples are constructed based on the partial code edit content and the corresponding negative sample label.

[0088] In some implementation scenarios, the current reference editing information is determined from the sequence of reference editing information, and the partial code editing content matching the current reference editing information is obtained. The actual editing position corresponding to the next reference editing information adjacent to the current reference editing information is used as the negative sample label. A negative sample is constructed by combining all reference editing information preceding the current reference editing information, the partial code editing content matching the current reference editing information, and the negative sample label. By constructing negative samples based on partial code editing content, the cursor prediction model can avoid predicting the next target cursor position and jumping to the next target cursor position when the development object has not completed the current round of editing in actual applications.

[0089] In a specific application scenario, in response to obtaining the reference editing information sequence is: Please refer to the editing information. As the current reference editing information, the adjacent next reference editing information will be used. The corresponding actual edit position is used as the negative sample label. The code edit content that responds to the current reference edit information includes the first line in the reference training code. line, number row and number The code statements in the line will refer to the editing information. Reference editing information The first reference to the editing information matched Negative samples are constructed using line-of-speech code statements and negative sample labels.

[0090] In one embodiment, in response to obtaining training samples constructed through any of the above embodiments, the cursor prediction model is trained using the training samples until the model reaches a preset convergence condition, or the number of training rounds reaches a preset threshold, at which point training stops, and the trained cursor prediction model is obtained. The specific training process can refer to existing neural network model training methods, and will not be described in detail here.

[0091] Please see Figure 7 , Figure 7 This is a schematic diagram of one embodiment of the cursor prediction system for code editing according to this application. Specifically, the cursor prediction system includes an acquisition module 10 and a prediction module 20 coupled to each other. The acquisition module 10 is used to acquire multiple target editing information matching the target code.

[0092] The prediction module 20 is used to input the target editing information into the trained cursor prediction model to obtain the target cursor position that the target code output by the cursor prediction model needs to jump to. The cursor prediction model is trained using multiple training samples. The training samples include mutually matched reference editing information and training labels. The reference editing information is obtained by filtering multiple initial editing information based on the code editing content, the actual editing position, and the associated editing position. The initial editing information is determined based on the edited reference training code. The associated editing position is determined based on the code editing content that matches at least some of the adjacent initial editing information. The training labels are determined based on the actual editing position.

[0093] In one embodiment, the cursor prediction system further includes a sample construction module 30 coupled to the prediction module 20. The sample construction module 30 is used to obtain multiple initial editing information based on the initial training code before editing and the reference training code after editing; obtain the correlation information between the initial editing information; and based on the correlation information, filter out multiple first editing information from all the initial editing information; for at least some of the adjacent first editing information, obtain the associated editing position determined based on the matched code editing content; and based on the associated editing position, filter out multiple reference editing information from all the first editing information; obtain a reference editing information sequence composed of multiple reference editing information; and construct multiple training samples based on the reference editing information sequence.

[0094] In one embodiment, the sample construction module 30 obtains multiple initial editing information based on the initial training code before editing and the reference training code after editing, including: obtaining initial difference information between the initial training code before editing and the reference training code after editing, and determining the matching degree between different initial difference information; based on the matching degree, obtaining multiple interrelated reference difference information from all initial difference information; obtaining the code editing content matched by each reference difference information, and determining the initial editing information from all reference difference information based on the code editing content.

[0095] In one embodiment, in response to the code editing content including at least one code editing statement, the sample construction module 30 determines the initial editing information from all reference difference information based on the code editing content, including: obtaining the reference number of code editing statements matched by each reference difference information; and in response to the reference number being less than a preset number threshold, using the corresponding reference difference information as the initial editing information.

[0096] In one embodiment, the code editing content is matched with an identifier, which corresponds to a new editing category or a deleted editing category. The sample construction module 30 obtains the association information between the initial editing information. Based on the association information, it filters out multiple first editing information from all the initial editing information, including: determining the current initial editing information and other initial editing information preceding the current initial editing information based on the editing order of all the initial editing information; for the other initial editing information, obtaining the historical set of newly added identifiers corresponding to the new editing category and the historical set of deleted identifiers corresponding to the deleted editing category; and for the current initial editing information, obtaining the current set of newly added identifiers corresponding to the new editing category and the current set of deleted identifiers corresponding to the deleted editing category; in response to the intersection of the historical set of newly added identifiers and the current set of newly added identifiers, or the intersection of the historical set of deleted identifiers and the current set of deleted identifiers, the current initial editing information is taken as the first editing information.

[0097] In one embodiment, the sample construction module 30 obtains associated editing positions determined based on matched code editing content for at least a portion of adjacent first editing information, and filters multiple reference editing information from all first editing information based on the associated editing positions, including: determining the current first editing information and at least one other first editing information preceding the current first editing information from all first editing information based on the editing order of each first editing information; obtaining associated editing positions determined based on the code editing content matched by the other first editing information respectively, and the actual editing positions of all code editing statements matched by the current first editing information; in response to the association editing position being consistent with the actual editing position, using the current first editing information as reference editing information; and traversing all first editing information until all reference editing information is obtained from all first editing information.

[0098] In one embodiment, the training samples also include multiple negative samples. The sample construction module 30 is further configured to obtain negative sample labels that match the last round of reference editing information in the reference editing information sequence; construct negative samples based on all reference editing information and negative sample labels; and construct negative samples based on the partial code editing content matched by any reference editing information and the actual editing position corresponding to the next reference editing information.

[0099] Please see Figure 8 , Figure 8 This is a schematic diagram of one embodiment of the electronic device of this application. The electronic device includes a memory 40 and a processor 50 coupled to each other. The memory 40 stores program instructions, and the processor 50 executes the program instructions to implement the methods mentioned in any of the above embodiments. Specifically, the electronic device includes, but is not limited to, desktop computers, laptops, tablets, servers, etc., and is not limited thereto. In addition, the processor 50 may also be called a CPU (Center Processing Unit). The processor 50 may be an integrated circuit chip with signal processing capabilities. The processor 50 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor or any conventional processor. In addition, the processor 50 may be implemented by integrated circuit chips.

[0100] Please see Figure 9 , Figure 9 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 60 stores program instructions 70 that can be executed by a processor. When the program instructions 70 are executed by the processor, they implement the methods mentioned in any of the above embodiments.

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

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

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

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

[0105] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A cursor prediction method for code editing, characterized by, The method comprises: obtaining a plurality of target editing information matched with target code; inputting the target editing information into a trained cursor prediction model to obtain a target cursor position to which the target code needs to jump, wherein the cursor prediction model is obtained by training a plurality of training samples, the training samples comprise reference editing information and training labels matched with each other, the reference editing information is obtained by screening a plurality of initial editing information based on code editing content, actual editing position and associated editing position, the initial editing information is determined based on the reference training code after editing, the associated editing position is determined based on the code editing content matched with at least part of the adjacent initial editing information, and the training label is determined based on the actual editing position.

2. The cursor prediction method for code editing according to claim 1, wherein, The construction of the training sample comprises: obtaining a plurality of initial editing information based on the initial training code before editing and the reference training code after editing; obtaining associated information between the initial editing information, and screening a plurality of first editing information from all the initial editing information based on the associated information; for at least part of the adjacent first editing information, obtaining an associated editing position determined based on the matched code editing content, and screening a plurality of reference editing information from all the first editing information based on the associated editing position; obtaining a reference editing information sequence composed of a plurality of reference editing information, and constructing a plurality of training samples based on the reference editing information sequence.

3. The cursor prediction method for code editing according to claim 2, wherein, The obtaining of the plurality of initial editing information based on the initial training code before editing and the reference training code after editing comprises: obtaining initial difference information between the initial training code before editing and the reference training code after editing, and determining the matching degree between different initial difference information; obtaining a plurality of reference difference information associated with each other from all the initial difference information based on the matching degree; obtaining code editing content matched with each reference difference information, and determining the initial editing information from all the reference difference information based on the code editing content.

4. The cursor prediction method for code editing according to claim 3, wherein, In response to the code editing content comprising at least one code editing statement, the determination of the initial editing information from all the reference difference information based on the code editing content comprises: obtaining a reference number of code editing statements matched with each reference difference information; in response to the reference number being less than a preset number threshold, taking the reference difference information corresponding to the reference difference information as the initial editing information.

5. The cursor prediction method for code editing according to claim 2, wherein, The code editing content is matched with an identifier, the identifier corresponds to an added editing category or a deleted editing category, and the obtaining of the associated information between the initial editing information and the screening of a plurality of first editing information from all the initial editing information based on the associated information comprises: determining a current initial editing information and other initial editing information located before the current initial editing information from all the initial editing information based on the editing order of all the initial editing information. For the other initial editing information, a set of historical added identifiers corresponding to the added editing category and a set of historical deleted identifiers corresponding to the deleted editing category are obtained; and For the current initial editing information, a set of current added identifiers corresponding to the added editing category and a set of current deleted identifiers corresponding to the deleted editing category are obtained; In response to the set of historical added identifiers and the set of current added identifiers having an intersection, or the set of historical deleted identifiers and the set of current deleted identifiers having an intersection, the current initial editing information is taken as the first editing information.

6. The cursor prediction method for code editing according to claim 2, wherein, For at least part of the adjacent first editing information, an associated editing position is determined based on the matched code editing content, and based on the associated editing position, a plurality of reference editing information is filtered from all the first editing information, including: Based on the editing order of each first editing information, a current first editing information and at least one other first editing information located before the current first editing information are determined from all the first editing information; The associated editing position determined based on the code editing content matched by the other first editing information and the actual editing position of all code editing statements matched by the current first editing information are obtained; In response to the associated editing position being consistent with the actual editing position, the current first editing information is taken as the reference editing information; All the reference editing information is filtered from all the first editing information by traversing all the first editing information.

7. The cursor prediction method for code editing according to claim 2, wherein, The training sample further includes a plurality of negative samples, and the construction step of the training sample further includes: Obtaining a negative sample label matched by the last round of reference editing information in the sequence of reference editing information; Based on all the reference editing information and the negative sample label, the negative sample is constructed; and Based on part of the code editing content matched by any reference editing information and the actual editing position corresponding to the next reference editing information, the negative sample is constructed.

8. A cursor prediction system for code editing, the system comprising: Including: An acquisition module is configured to acquire a plurality of target editing information matched by target code; A prediction module is configured to input the target editing information into a trained cursor prediction model to obtain a target cursor position to which the target code needs to jump; wherein the cursor prediction model is obtained by training a plurality of training samples, the training samples include reference editing information and training labels matched with each other, the reference editing information is obtained by screening a plurality of initial editing information based on code editing content, actual editing position and associated editing position, the initial editing information is determined based on edited reference training code, the associated editing position is determined based on at least part of the adjacent initial editing information matched by code editing content, and the training label is determined based on the actual editing position.

9. An electronic device, comprising: Including: a memory and a processor coupled to each other, the memory having program instructions stored therein, the processor being configured to execute the program instructions to implement the method of any one of claims 1-7.

10. A computer-readable storage medium having stored thereon program instructions, wherein, the program instructions, when executed by a processor, implement the method of any one of claims 1-7.