Code editing method and device, equipment and storage medium

By responding to user editing instructions in code editing, presenting editing location and operation information, and updating the code based on attention mechanism, the problem of difficulty in capturing syntax and semantic correlation in the prior art is solved, and more efficient and accurate code editing is achieved .

CN119088381APending Publication Date: 2024-12-06DOUYIN VISION CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410620287.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-17
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

Existing code editing techniques have difficulty capturing syntax dependencies and semantic correlations in code editing, and traditional methods assume that all previous edits are relevant, resulting in damage to noise input and editing accuracy.

Method used

By responding to user's editing instructions, editing location information and operation information are presented, helping users select target editing locations, and updating codes based on editing operations. Using attention mechanism-based methods to promote code generation schemes to code editing, determining editing propagation probability and dependency degree, precise positioning editing position and operation type.

Benefits of technology

It improves code development efficiency, enhances code quality, reduces errors caused by code inconsistency, and provides a more accurate and efficient code editing experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088381A_ABST
    Figure CN119088381A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code editing method and device, equipment and a storage medium. The method comprises: in response to receiving an editing indication for a code set, presenting editing position information indicating one or more candidate editing positions at which codes in the code set are to be edited; in response to selection of a target editing position in the one or more candidate editing positions, presenting operation information, the operation information indicating an editing operation for a code at the target editing position; and updating the code at the target editing position based on the editing operation. Therefore, the user does not need to position editing positions one by one. In this way, the code development efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Example embodiments of the present disclosure generally relate to the field of computers, and more particularly, to methods, devices, apparatuses, and computer-readable storage media for code editing. Background Art

[0002] In recent years, the application of language models (LM) in code generation tasks has been successful. LM-based methods dominate code generation solutions by transforming user descriptions and code contexts into a new piece of code. However, compared with generating new code, people have more demands for editing existing code. Therefore, it is expected to provide a more editable code editing method. Summary of the invention

[0003] In a first aspect of the present disclosure, a method for code editing is provided. The method comprises: in response to receiving an editing instruction for a code set, presenting editing position information indicating one or more candidate editing positions where the code in the code set is to be edited; in response to selecting a target editing position from the one or more candidate editing positions, presenting operation information indicating an editing operation for the code at the target editing position; and updating the code at the target editing position based on the editing operation.

[0004] In a second aspect of the present disclosure, a device for code editing is provided. The device includes: a position information presentation module, configured to present editing position information in response to receiving an editing instruction for a code set, wherein the editing position information indicates one or more candidate editing positions where the code in the code set is to be edited; an operation information presentation module, configured to present operation information in response to selecting a target editing position from one or more candidate editing positions, wherein the operation information indicates an editing operation for the code at the target editing position; and a code update module, configured to update the code at the target editing position based on the editing operation.

[0005] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory, the at least one memory is coupled to the at least one processing unit and stores instructions for execution by the at least one processing unit. When the instructions are executed by the at least one processing unit, the device executes the method of the first aspect.

[0006] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and the computer program can be executed by a processor to implement the method of the first aspect.

[0007] It should be understood that the contents described in this content section are not intended to limit the key features or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0009] Figure 1 A schematic diagram showing an example environment in which embodiments of the present disclosure can be implemented;

[0010] Figure 2 A schematic diagram showing the architecture of a code editing system according to some embodiments of the present disclosure;

[0011] Figure 3 A schematic diagram showing positioning of edits according to some embodiments of the present disclosure is shown;

[0012] Figure 4 A schematic diagram of generating editing content according to some embodiments of the present disclosure is shown;

[0013] Figure 5 shows a user interface of a code editing system according to some embodiments of the present disclosure;

[0014] Figure 6 A flowchart showing a process of code editing according to some embodiments of the present disclosure is shown;

[0015] Figure 7 A block diagram showing an apparatus for code editing according to some embodiments of the present disclosure; and

[0016] Figure 8 A block diagram of a device capable of implementing various embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0017] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0018] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0019] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0020] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0021] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0022] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0023] It should be noted that the titles of any sections / subsections provided herein are not restrictive. Various embodiments are described throughout this article, and any type of embodiment may be included under any section / subsection. In addition, the embodiments described in any section / subsection may be combined in any manner with any other embodiments described in the same section / subsection and / or different sections / subsections.

[0024] Herein, unless explicitly stated, executing a step “in response to A” does not mean executing the step immediately after “A” but may include one or more intermediate steps.

[0025] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may be included below. The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may be included below.

[0026] As used herein, the term "model" can learn the association between the corresponding input and output from the training data, so that after the training is completed, the corresponding output can be generated for a given input. The generation of the model can be based on machine learning technology. Deep learning is a machine learning algorithm that processes inputs and provides corresponding outputs by using multiple layers of processing units. In this article, "model" may also be referred to as "machine learning model", "machine learning network" or "network", which are used interchangeably in this article. A model may also include different types of processing units or networks.

[0027] As briefly mentioned above, users have a lot of demands for code editing. Attention-based methods have been proposed to generalize code generation scenarios to code editing scenarios. Although these methods differ in representing edits in deep learning models, they formulate the edit generation problem as a conversion problem, taking known relevant previous edits (and their context) and code regions (and their context) as input and generating an edited code as output.

[0028] In code editing, traditional schemes usually assume that all previous edits of the target edit are relevant. However, this may not be the case in practice. Inputting irrelevant previous edits to the model may introduce noisy inputs, which harms the accuracy of the generated edits. It is also important to know where an edit may have occurred, as the ripple effects of previous edits may propagate throughout the code set. In addition, code edits can interact with each other in terms of syntactic dependencies and semantic relevance. However, capturing such interactions remains a black box for traditional schemes. Although these solutions have laid an important foundation for code editing tasks, there is still a gap between these solutions and real-world scenarios.

[0029] Embodiments of the present disclosure propose a scheme for code editing. According to various embodiments of the present disclosure, in response to receiving an editing instruction for a code set, editing position information is presented, and the editing position information indicates one or more candidate editing positions where the code in the code set is to be edited. In response to selecting a target editing position from one or more candidate editing positions, operation information is presented, and the operation information indicates an editing operation for the code at the target editing position. Based on the editing operation, the code at the target editing position is updated.

[0030] According to an embodiment of the present disclosure, after the user instructs to edit the code, possible code editing positions are first recommended to the user, and after the user selects a certain editing position, possible editing operations at the selected position are recommended to the user. Thus, the user does not need to locate the editing positions one by one. In this way, the efficiency of code development can be improved. In addition, this is conducive to enhancing code quality and reducing errors caused by code inconsistency.

[0031] The disclosed example embodiments will now be described with continued reference to the accompanying drawings.

[0032] Example Environment

[0033] Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. In the environment 100, a code editing system 120 is deployed in an electronic device 110. The code editing system 120 is configured to generate an edited code set 102 based on a code set 101 in a code editing task. Before being applied to the code editing task, the code editing system 120 has been trained using training data. The code set 101 may be, for example, all or part of the code of a certain code development project.

[0034] The code editing system 120 can determine the position to be edited and the type of editing operation in the code set 101 according to the code set 101. The position to be edited can indicate, for example, a line of code in a code file, and the type of editing operation can include, for example, replacement, insertion, and retention.

[0035] In environment 100, electronic device 110 can be any type of device with computing capabilities, including terminal devices or server devices. The terminal device can be any type of mobile terminal, fixed terminal or portable terminal, including mobile phones, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, media computers, multimedia tablets, personal communication systems (PCS) devices, personal navigation devices, personal digital assistants (PDAs), audio / video players, digital cameras / camcorders, positioning devices, television receivers, radio broadcast receivers, e-book devices, gaming devices, or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. The server device can include, for example, a computing system / server, such as a mainframe, an edge computing node, an electronic device in a cloud environment, and the like.

[0036] It should be understood that the structure and functionality of environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure.

[0037] Overview of the Code Editing System

[0038] Figure 2 FIG. 1 is a schematic diagram showing the architecture of the code editing system 120 according to an embodiment of the present disclosure. Figure 2 As shown, code editing system 120 includes subsequent edit analysis subsystem 220 , previous edit analysis subsystem 250 , and edit generation subsystem 260 .

[0039] In some embodiments, the code set 101 may include multiple code subsets. The code subsets here may include, for example, code files or code segments in code files. The edit propagation analyzer 222 in the subsequent edit analysis subsystem 220 may determine the corresponding edit propagation probabilities of the multiple code subsets based on at least one of the prompt information 230 describing the code editing target or the target edit record 232 of the code set, and the edit propagation probability of each code subset indicates the possibility that the code subset includes the code to be edited. The prompt information 230 may indicate the operation that the user wants to perform on the code editing target. An example of the prompt information 230 may be "Add scale option to initializer". The target edit record 232 may include previous edits for the code set 101, for example, it may be the last edit for the code set 101.

[0040] In some embodiments, for a given code subset among the plurality of code subsets, the edit propagation analyzer 222 may determine at least one propagation factor based on at least one of the hint information 230 or the target edit record 232, the at least one propagation factor including at least one of the following: the degree of dependence of the given code subset on the target edit 232 record, the semantic similarity between the given code subset and the pre-edit code in the target edit record 232, or the relevance of the given code subset to the hint information 230. The edit propagation analyzer 222 may determine the edit propagation probability of the given code subset based on the at least one propagation factor. In one example, determining the edit propagation probability of the given code subset may be expressed as follows:

[0041] sub edt (f, prp, e) = α1·dep (e, f) + α2·sem (e, f) + α3·sim (prp, f) (1)

[0042] Where f represents a given code subset, prp represents the prompt information 230, e represents the target edit record, dep(e, f) represents the degree of dependence of the given code subset on the target edit record 232, sem(e, f) represents the semantic similarity between the given code subset and the pre-edit code in the target edit record 232, and sim(prp, f) represents the correlation between the given code subset and the prompt information 230. The sum of all coefficients ∑α i =1 and each coefficient α i > 0. The values ​​of dep(e, f), sem(e, f) and sim(prp, f) can be between 0 and 1.

[0043] In this way, the edit propagation probability can be obtained through the weighted sum of multiple propagation factors, so as to more accurately determine the code subset that may contain the code to be edited.

[0044] Formula (1) uses all the propagation factors to determine the edit propagation probability of a given code subset. It should be noted that formula (1) is only an example. It is also possible to use part of the above propagation factors to calculate the edit propagation probability.

[0045] Regarding the degree of dependency, given a target edit record e=(c b , c a) and a code subset f, the dependency inference function dep(e, f) can be used to quantify the probability that f depends on e. Any suitable model (e.g., a model based on an attention mechanism) can be used as a base model to determine the degree of dependency between code subsets. A dense layer with two output neurons can be added, which are activated using a sigmoid function, i.e., the previous code depends on the subsequent code and the subsequent code depends on the previous code. Given a pair of source code c1 and c2, the loss function of the degree of dependency between them can be used to train the base model, so that a more accurate estimate of the degree of dependency can be generated. The loss function can be expressed as follows:

[0046]

[0047] where y1 and y2 are the labeled degrees of dependence of c1 and c2 (y1 = 1 or 0 for whether c1 depends on c2 and y2 = 1 or 0 for whether c2 depends on c1), and their estimated degrees of dependence are

[0048] In some embodiments, the given code subset is a code file, and the code file includes multiple code segments. For each code segment in the multiple code segments, the edit propagation analyzer 222 can determine the factor value of the given propagation factor based on the prompt information 230 or at least one item in the target edit record 232 to obtain multiple factor values ​​of the given propagation factor, each factor value corresponding to a code segment in the multiple code segments. Then, the edit propagation analyzer 222 can derive the value of the given propagation factor of the code file based on the multiple factor values. Due to the limitation of the input length, the code file f can be divided into k smaller code segments seg1, .., seg k . Taking the propagation factor as an example, the dependence of a given code subset on the target edit record 232, the code before the last edit (an example of the target edit record 232) (given by c b indicates) is determined as the target code c tar , then we can estimate c tar The probability of the dependency between a given code subset and the target edit record 232 can be expressed as in represents the probability that the subsequent code depends on the previous code, and max(·) represents the maximum value in the selection parameter. That is, the maximum value of the degree of dependence of the code segments in the given code subset on the target edit record 232 is determined as the degree of dependence of the given code subset on the target edit record 232.

[0049] In this way, by dividing the code file into smaller code segments, the factor value of each propagation factor can be evaluated more accurately, thereby more accurately determining the code subset that may contain the code to be edited.

[0050] Regarding semantic similarity and hint relevance, the semantic similarity between code and hint can be captured by neural embedding. The pre-trained neural network model can capture syntactic and semantic similarity. Still considering the input length limit, the code file f can be divided into k smaller code segments seg1, .., seg k As an example, the semantic similarity between the given code subset and the pre-editing code in the target edit record 232 and the correlation between the given code subset and the prompt information 230 can be expressed by the following formulas (3) and (4), respectively:

[0051] sem(e,f)=max(cos(emd(c tar ), emd(seg i ))) (3)

[0052] sem(prp, f)=max(cos(emd(prp), emd(seg i ))) (4)

[0053] where e tar =c b , where c b represents the code before editing, and emd(.) represents the code extracted from the converter or the representation of the prompt information.

[0054] As shown in formula (3), the maximum value of the semantic similarity between the code segments in the given code subset and the pre-editing code in the target edit record 232 is determined as the semantic similarity between the given code subset and the pre-editing code in the target edit record 232. As shown in formula (4), the maximum value of the correlation between the code segments in the given code subset and the prompt information 230 is determined as the correlation between the given code subset and the prompt information 230.

[0055] Alternatively or additionally, a statistical value such as an average or median of the degree of dependence of the code segments in a given code subset on the target edit record 232 may be determined as the degree of dependence of the given code subset on the target edit record 232. Similarly, a statistical value such as an average or median of the semantic similarity between the code segments in a given code subset and the pre-edit code in the target edit record 232 may be determined as the semantic similarity between the given code subset and the pre-edit code in the target edit record 232. Similarly, a statistical value such as an average or median of the correlation between the code segments in a given code subset and the prompt information 230 may be determined as the correlation between the given code subset and the prompt information 230.

[0056] After determining the corresponding edit propagation probabilities of the plurality of code subsets, the edit propagation analyzer 222 may determine at least one code subset 224 from the plurality of code subsets based on the edit propagation probabilities. As an example, determining at least one code subset 224 may be expressed as where F′={f|sub edt (f, prp, e)>th sub , f∈F}, F′ represents multiple code subsets, F represents code set 101, sub edt (.,.,.) represents the edit propagation probability of each code subset f in multiple code subsets, th sub represents a threshold value for determining at least one code subset 224. In the case where the edit propagation probability of a code subset is greater than the threshold value, the code subset may be determined as at least one code subset 224.

[0057] After determining at least one code subset 224, for a given code subset in the at least one code subset 224, the edit type detector 226 in the subsequent edit analysis subsystem 220 may determine one or more lines of code in the given code subset as candidate edit positions 240 based on the prompt information 230 and / or at least one edit record related to the given code subset. The edit record here may include an edit position and a specific edit operation.

[0058] In some embodiments, the edit type detector 226 can estimate the edit operation type of each line of code in a given code subset based on at least one edit record or at least one item of the prompt information, and determine one or more lines of code whose estimated edit operation type is a preset type as candidate edit positions.

[0059] As an example, a sliding window may be applied over a given subset of code to identify the type of edit operations for each line of code. Figure 3 Schematic diagram 300 of positioning an edit according to some embodiments of the present disclosure is shown. Figure 3As shown, the edit type detector 226 can be fine-tuned as Mask Language Modeling (MLM) through instruction fine-tuning. The input of the edit type detector 226 may include the target code 310, the prompt information 230 and the target edit record 232. For each input element, an instruction (or label) is introduced as a separator so that the edit type detector 226 can learn the input structure. The content of the target code 310 can be included in the instruction code-window 320, the content of the prompt information 230 can be included in the instruction prompt 330, and the content of the target edit record 232 can be included in the instruction prior-edits 340 or edit. In addition, for each line of code in the code, the operator <k>To indicate a hold operation, a hold operation means that the line of code has not changed. To indicate an insert operation, an insert operation means that some code is inserted before the line of code. <r>To represent a replacement operation, the replacement operation means that the line of code is replaced by an empty line (ie, deleted) or replaced by some different lines (ie, updated). One or more lines of code whose estimated editing operation type is insertion or replacement can be determined as candidate editing positions respectively.

[0060] Continue to refer Figure 2 In some embodiments, the previous edit analysis subsystem 250 may determine at least one edit record 254 related to the target edit location from a set of edit records for the code set 101. The previous edit analysis subsystem 250 may then predict the edit operation to be performed on the code at the target edit location based on the at least one edit record 254. The previous edit analysis subsystem 250 may predict the edit operation to be performed on the code at the target edit location by finding the most relevant previous edit.

[0061] In some embodiments, for each edit record in a set of edit records, the dependency analyzer 252 in the previous edit analysis subsystem 250 may determine the degree of influence of the edit record on the target edit position. Based on the respective influence degrees of the set of edit records, the dependency analyzer 252 may select the at least one edit record from the set of edit records.

[0062] As an example, given a set of edit records in Represents the code before editing, Indicates the edited code. Each edit record Editing location for target The influence degree of can be quantified between 0 and 1. Specifically, the estimation function is expressed as rel(.,.): p ×C→(0,1), where C represents the set of codes, that is, The corresponding influence levels of a group of edit records may be sorted in descending order, and at least one edit record with a higher influence level may be selected.

[0063] In some embodiments, the degree of influence of the edit record on the target edit position is determined based on at least one of the following: the degree of dependence of the target edit position on the edit record, the semantic similarity between the code at the target edit position and the pre-edit code in the edit record, or the proximity between the target edit position and the edit record position in the edit record. As an example, determining the degree of influence of the edit record on the target edit position can be expressed as follows:

[0064]

[0065] in Indicates the degree of dependence of the target edit position on the edit record. Indicates the semantic similarity between the code at the target editing position and the code before editing in the editing record, represents the proximity between the target edit position and the edit record position in the edit record. Similar to formula (1), the sum of the coefficients β1+β2+β3=1 and β i >0.

[0066] Continue to refer Figure 2 After determining the relevant edit record 254 and the edit position 240, the edit content generator 262 in the edit generation subsystem 260 can generate the edit operation 264. Figure 4 Detailed instructions for generating editorial content.

[0067] Figure 4 4 shows a schematic diagram 400 of generating editing content according to some embodiments of the present disclosure. Figure 4 As shown, the input of the edit content generator 262 may include a target code 420, a prompt information 230, and at least one edit record 430. For each input element, an instruction (or label) is introduced as a separator so that the edit content generator 262 can learn the input structure. The content of the target code 420 can be included in the instruction code-window 320, the content of the prompt information 230 can be included in the instruction prompt 330, and the content of at least one edit record 430 can be included in the instruction prior-edits340 or edit. The edit content generator 262 can be trained using a cross-entropy loss function. In the inference phase, the edit content generator 262 can generate k edit options and sort them according to confidence. The user can receive or modify the edit options generated by the edit content generator 262, and the new edit will be saved as an edit record, thereby facilitating the entire editing session.

[0068] The following will refer to Figure 5 Describe the interaction between the code editing system 120 and the user. Figure 5 FIG. 5 shows an example user interface 500 provided by the code editing system 120 according to some embodiments of the present disclosure. Figure 5 As shown, in response to receiving an edit indication 510 for the code set 101 , the code editing system 120 presents edit location information 520 , which indicates one or more candidate edit locations in the code set 101 where the code is to be edited.

[0069] In some embodiments, the editing instructions 510 may include a hint 230 describing the code editing target, and one or more candidate editing locations are generated based on the hint. As an example, the hint 230 may be "Add scale option to initializer". Based on the hint, the location of the initializer can be determined so that the initializer can be edited.

[0070] In some embodiments, the editing location information 520 may include identification information of one or more code files in the code set, and identification information of one or more lines of code in each of the one or more code files. For example, the editing location information 520 may be displayed in a hierarchical structure of file names and line numbers.

[0071] After presenting the editing position information, in response to selecting a target editing position from one or more candidate editing positions, the code editing system 120 presents operation information 530. Operation information 530 indicates an editing operation for the code at the target editing position. The editing operation here may include operations such as replacement, insertion, and retention. For example, a user may select a line of code in the display area of ​​the editing position information 520. After the line of code is selected, an editing operation for the line of code may be presented. Figure 5 In the example of , the original code and the code on which the editing operation is performed are presented together, for example, in parallel.

[0072] The code editing system 120 may update the code at the target editing position based on the editing operation. For example, the code editing system 120 may perform the recommended editing operation on the code at the selected editing position.

[0073] In some embodiments, updating the code at the target edit position is in response to receiving a confirmation indication for the edit operation. As an example, in response to the user triggering the confirmation button 540, the code editing system 120 can update the code at the target edit position. In this way, updating the code based on the received confirmation indication can reduce the possibility of misoperation and improve the safety of operation execution.

[0074] In some embodiments, in response to the update of the code at the target location, the code editing system 120 can also present updated editing location information. After the code at the target location is updated, the original location information may change, for example, the number of lines may change, so the code editing system 120 can also present updated editing location information. In this way, after the code at the target location is updated, the location information of the code to be edited later can be accurately presented.

[0075] In some embodiments, when a user is editing code, editing recommendations can be triggered by a shortcut or by clicking on the code editor.

[0076] In some embodiments, different colors may be used to identify different edit types. For example, green may be used to identify the code line to be inserted, and red may be used to identify the code line to be replaced.

[0077] In some embodiments, the user can accept or ignore the editing recommendation. For the accepted editing recommendation, the editing recommendation can be recorded as an editing record.

[0078] Example Process

[0079] Figure 6 FIG. 6 is a flowchart of a process 600 for code editing according to some embodiments of the present disclosure. The process 600 may be implemented in Figure 1 The code editing system 120 is located at.

[0080] At block 610 , in response to receiving an edit indication for a code set, the code editing system 120 presents edit location information indicating one or more candidate edit locations in the code set where code is to be edited.

[0081] In block 620 , in response to selection of a target editing location from among the one or more candidate editing locations, the code editing system 120 presents operation information indicating an editing operation for the code at the target editing location.

[0082] In block 630 , the code editing system 120 updates the code at the target editing location based on the editing operation.

[0083] In some embodiments, the editing indication includes hint information describing a code editing target, and one or more candidate editing locations are generated based on the hint information.

[0084] In some embodiments, the editing location information includes: identification information of one or more code files in the code set, and identification information of one or more lines of code in each of the one or more code files.

[0085] In some embodiments, process 600 further includes presenting updated edit location information in response to an update of the code at the target location.

[0086] In some embodiments, updating the code at the target edit location is in response to receiving a confirmation indication of the edit operation.

[0087] In some embodiments, a code set includes multiple code subsets, and one or more candidate editing positions are determined in the following manner: based on prompt information describing a code editing target or at least one of the target editing records of the code set, corresponding editing propagation probabilities of the multiple code subsets are determined, and the editing propagation probability of each code subset indicates the possibility that the code subset includes the code to be edited; based on the corresponding editing propagation probabilities of the multiple code subsets, at least one code subset is determined from the multiple code subsets; and for a given code subset in the at least one code subset, one or more lines of code in the given code subset are determined as candidate editing positions respectively based on at least one of the following: prompt information, or at least one editing record related to the given code subset.

[0088] In some embodiments, determining corresponding edit propagation probabilities of multiple code subsets includes, for a given code subset among the multiple code subsets: determining at least one propagation factor based on at least one of the prompt information or the target edit record, the at least one propagation factor including at least one of the following: the degree of dependence of the given code subset on the target edit record, the semantic similarity between the given code subset and the pre-edit code in the target edit record, or the relevance of the given code subset to the prompt information; and determining the edit propagation probability of the given code subset based on the at least one propagation factor.

[0089] In some embodiments, the given code subset is a code file, the code file includes multiple code segments, and a given propagation factor in at least one propagation factor is determined as follows: for each code segment in the multiple code segments, based on prompt information or at least one of the target editing records, a factor value of the given propagation factor is determined to obtain multiple factor values ​​of the given propagation factor, each factor value corresponding to a code segment in the multiple code segments; and based on the multiple factor values, the value of the given propagation factor of the code file is obtained.

[0090] In some embodiments, determining one or more lines of code in a given code subset as candidate editing locations includes: estimating the editing operation type of each line of code in the given code subset based on at least one editing record or at least one item of prompt information; and determining one or more lines of code whose estimated editing operation type is a preset type as candidate editing locations.

[0091] In some embodiments, an editing operation for a code at a target editing location is determined by: determining at least one editing record related to the target editing location from a set of editing records for a code set; and predicting an editing operation to be performed on the code at the target editing location based on the at least one editing record.

[0092] In some embodiments, determining at least one editing record related to a target editing position includes: determining, for each editing record in a set of editing records, a degree of influence of the editing record on the target editing position; and selecting at least one editing record from a set of editing records based on the corresponding degrees of influence of the set of editing records.

[0093] In some embodiments, the degree of influence of the editing record on the target editing position is determined based on at least one of the following: the degree of dependence of the target editing position on the editing record, the semantic similarity between the code at the target editing position and the pre-editing code in the editing record, or the proximity between the target editing position and the editing record position in the editing record.

[0094] Example devices and equipment

[0095] Figure 7 A schematic structural block diagram of a device 700 for code editing according to some embodiments of the present disclosure is shown. The device 700 may be implemented as or included in the code editing system 120. Each module / component in the device 700 may be implemented by hardware, software, firmware, or any combination thereof.

[0096] like Figure 7 As shown, the device 700 includes a position information presentation module 710, which is configured to present editing position information in response to receiving an editing indication for a code set, wherein the editing position information indicates one or more candidate editing positions where the code in the code set is to be edited. The device 700 also includes an operation information presentation module 720, which is configured to present operation information in response to selecting a target editing position from one or more candidate editing positions, wherein the operation information indicates an editing operation for the code at the target editing position. The device 700 also includes a code update module 730, which is configured to update the code at the target editing position based on the editing operation.

[0097] In some embodiments, the editing indication includes hint information describing a code editing target, and one or more candidate editing locations are generated based on the hint information.

[0098] In some embodiments, the editing location information includes: identification information of one or more code files in the code set, and identification information of one or more lines of code in each of the one or more code files.

[0099] In some embodiments, the apparatus 700 further includes an updating module configured to present updated editing location information in response to an update of the code at the target location.

[0100] In some embodiments, updating the code at the target edit location is in response to receiving a confirmation indication of the edit operation.

[0101] In some embodiments, a code set includes multiple code subsets, and one or more candidate editing positions are determined in the following manner: based on prompt information describing a code editing target or at least one of the target editing records of the code set, corresponding editing propagation probabilities of the multiple code subsets are determined, and the editing propagation probability of each code subset indicates the possibility that the code subset includes the code to be edited; based on the corresponding editing propagation probabilities of the multiple code subsets, at least one code subset is determined from the multiple code subsets; and for a given code subset in the at least one code subset, one or more lines of code in the given code subset are determined as candidate editing positions respectively based on at least one of the following: prompt information, or at least one editing record related to the given code subset.

[0102] In some embodiments, the location information presentation module 710 includes an edit propagation probability determination module, which is configured to determine at least one propagation factor based on at least one of the prompt information or the target edit record, the at least one propagation factor including at least one of the following: the degree of dependence of a given code subset on the target edit record, the semantic similarity between the given code subset and the pre-edit code in the target edit record, or the relevance of the given code subset to the prompt information; and determine the edit propagation probability of the given code subset based on the at least one propagation factor.

[0103] In some embodiments, the given code subset is a code file, the code file includes multiple code segments, and a given propagation factor in at least one propagation factor is determined as follows: for each code segment in the multiple code segments, based on prompt information or at least one of the target editing records, a factor value of the given propagation factor is determined to obtain multiple factor values ​​of the given propagation factor, each factor value corresponding to a code segment in the multiple code segments; and based on the multiple factor values, the value of the given propagation factor of the code file is obtained.

[0104] In some embodiments, the location information presentation module 710 includes a candidate editing location determination module, which is configured to estimate the editing operation type of each line of code in a given code subset based on at least one editing record or at least one item of prompt information; and to determine one or more lines of code whose estimated editing operation type is a preset type as candidate editing locations.

[0105] In some embodiments, an editing operation for a code at a target editing location is determined by: determining at least one editing record related to the target editing location from a set of editing records for a code set; and predicting an editing operation to be performed on the code at the target editing location based on the at least one editing record.

[0106] In some embodiments, the operation information presentation module 720 includes an editing record selection module, which is configured to determine, for each editing record in a group of editing records, a degree of influence of the editing record on a target editing position; and select at least one editing record from a group of editing records based on the corresponding degrees of influence of the group of editing records.

[0107] In some embodiments, the degree of influence of the editing record on the target editing position is determined based on at least one of the following: the degree of dependence of the target editing position on the editing record, the semantic similarity between the code at the target editing position and the pre-editing code in the editing record, or the proximity between the target editing position and the editing record position in the editing record.

[0108] like Figure 8 As shown, the electronic device 800 is in the form of a general electronic device. The components of the electronic device 800 may include, but are not limited to, one or more processors or processing units 810, a memory 820, a storage device 830, one or more communication units 840, one or more input devices 850, and one or more output devices 860. The processing unit 810 may be an actual or virtual processor and is capable of performing various processes according to a program stored in the memory 820. In a multi-processor system, multiple processing units execute computer executable instructions in parallel to improve the parallel processing capability of the electronic device 800.

[0109] The electronic device 800 typically includes a plurality of computer storage media. Such media can be any accessible media that can be obtained by the electronic device 800, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 820 can be a volatile memory (e.g., a register, a cache, a random access memory (RAM)), a non-volatile memory (e.g., a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 830 can be a removable or non-removable medium, and can include a machine-readable medium, such as a flash drive, a disk, or any other medium, which can be used to store information and / or data and can be accessed within the electronic device 800.

[0110] The electronic device 800 may further include additional removable / non-removable, volatile / non-volatile storage media. Figure 8 As shown in , a disk drive for reading or writing from a removable, non-volatile disk (e.g., a "floppy disk") and an optical drive for reading or writing from a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to the bus (not shown) by one or more data media interfaces. The memory 820 may include a computer program product 825 having one or more program modules that are configured to perform various methods or actions of various embodiments of the present disclosure.

[0111] The communication unit 840 implements communication with other electronic devices through a communication medium. Additionally, the functions of the components of the electronic device 800 can be implemented with a single computing cluster or multiple computing machines that can communicate through a communication connection. Therefore, the electronic device 800 can operate in a networked environment using a logical connection with one or more other servers, a network personal computer (PC), or another network node.

[0112] The input device 850 may be one or more input devices, such as a mouse, a keyboard, a tracking ball, etc. The output device 860 may be one or more output devices, such as a display, a speaker, a printer, etc. The electronic device 800 may also communicate with one or more external devices (not shown) through the communication unit 840 as needed, such as a storage device, a display device, etc., communicate with one or more devices that allow a user to interact with the electronic device 800, or communicate with any device that allows the electronic device 800 to communicate with one or more other electronic devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface (not shown).

[0113] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, wherein the computer-executable instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the method described above.

[0114] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices, equipment, and computer program products implemented according to the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0115] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0116] Computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, so that the instructions executed on the computer, other programmable data processing apparatus, or other device implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0117] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple implementations of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some implementations as replacements, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.

[0118] The above descriptions of various implementations of the present disclosure are exemplary, non-exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. The selection of terms used herein is intended to best explain the principles of the implementations, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the various implementations disclosed herein.< / r> < / k>

Claims

1. A code editing method, include: In response to receiving an edit indication for a code set, presenting edit location information indicating one or more candidate edit locations where code in the code set is to be edited; In response to selection of a target editing position from among the one or more candidate editing positions, presenting operation information indicating an editing operation for a code at the target editing position; as well as Based on the editing operation, the code at the target editing position is updated. 2 . The method according to claim 1 , wherein the editing instruction includes hint information describing a code editing target, and the one or more candidate editing positions are generated based on the hint information.

3. The method according to claim 1, wherein the editing position information include: identification information of one or more code files in the code set, and Identification information of one or more lines of code in each of the one or more code files.

4. The method according to claim 1, further comprising: include: In response to the updating of the code at the target location, the updated editing location information is presented. 5 . The method of claim 1 , wherein updating the code at the target edit location is in response to receiving a confirmation indication of the edit operation.

6. The method of claim 1 , wherein the code set comprises a plurality of code subsets, and the one or more candidate edit locations are determined by: Determining corresponding edit propagation probabilities of the plurality of code subsets based on at least one of the prompt information describing the code edit target or the target edit record of the code set, the edit propagation probability of each code subset indicating the likelihood that the code subset includes the code to be edited; determining at least one code subset from the plurality of code subsets based on respective edit propagation probabilities of the plurality of code subsets; as well as For a given code subset in the at least one code subset, one or more lines of code in the given code subset are determined as candidate editing positions based on at least one of the following: The prompt information, or At least one edit record associated with the given subset of codes.

7. The method of claim 6, wherein determining respective edit propagation probabilities for the plurality of code subsets comprises, for a given code subset of the plurality of code subsets: Based on at least one of the prompt information or the target edit record, at least one propagation factor is determined, and the at least one propagation factor includes at least one of the following: the degree to which the given code subset depends on the target edit record, The semantic similarity between the given code subset and the pre-edit code in the target edit record, or The correlation between the given code subset and the prompt information; and Based on the at least one propagation factor, the edit propagation probability for the given code subset is determined.

8. The method of claim 7, wherein the given code subset is a code file, the code file comprising a plurality of code segments, and a given propagation factor in the at least one propagation factor is determined as follows: For each code segment in the plurality of code segments, based on at least one of the prompt information or the target edit record, determine a factor value of the given propagation factor to obtain a plurality of factor values ​​of the given propagation factor, each factor value corresponding to a code segment in the plurality of code segments; and Based on the multiple factor values, a value of the given propagation factor of the code file is derived.

9. The method according to claim 6, wherein one or more lines of code in the given code subset are determined as candidate editing positions respectively. include: Based on at least one of the at least one editing record or the prompt information, estimating the editing operation type of each line of code in the given code subset; as well as One or more lines of code whose estimated editing operation type is a preset type are respectively determined as candidate editing positions.

10. The method according to claim 1, wherein the editing operation for the code at the target editing position is determined by: determining at least one edit record associated with the target edit position from a set of edit records for the code set; and The editing operation to be performed on the code at the target editing position is predicted based on the at least one editing record.

11. The method of claim 10, wherein determining at least one edit record associated with the target edit location include: For each edit record in the set of edit records, determining the degree of influence of the edit record on the target edit position; as well as The at least one editing record is selected from the set of editing records based on the respective influence levels of the set of editing records.

12. The method according to claim 11, wherein the degree of influence of the editing record on the target editing position is determined based on at least one of the following: The degree of dependence of the target editing position on the editing record, The semantic similarity between the code at the target editing position and the code before editing in the editing record, or The proximity between the target edit position and the edit record position in the edit record.

13. A device for code editing, include: a position information presenting module, configured to present, in response to receiving an edit indication for a code set, edit position information indicating one or more candidate edit positions where codes in the code set are to be edited; an operation information presenting module, configured to present operation information in response to selection of a target editing position from one or more candidate editing positions, the operation information indicating an editing operation for the code at the target editing position; as well as The code updating module is configured to update the code at the target editing position based on the editing operation.

14. An electronic device, include: at least one processing unit; as well as At least one memory, the at least one memory being coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 12 when executed by the at least one processing unit.

15. A computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the method according to any one of claims 1 to 12.

Citation Information

Cited By

  • Method and apparatus for code editing, and device and storage medium

    WO2025236833A1