Code editing method and device, equipment and storage medium
Patent Information
- Application Number
- CN202480004624.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-25
- Publication Date
- 2025-12-26
Smart Images

Figure CN121219673A_ABST
Abstract
Description
Method, device, equipment and storage medium for editing code Technical Field
[0001] Example embodiments of the present disclosure generally relate to the field of computers, and more particularly, to a method, apparatus, device, and computer-readable storage medium for editing code. Background Art
[0002] With the development of the Internet, users can, for example, edit codes through a code editing interface of an electronic device. How to improve the efficiency of the user's code editing process has become a focus of attention.
[0003] Summary of the Invention
[0004] In a first aspect of the present disclosure, a method for editing code is provided. The method includes: obtaining edit suggestions for target code in a code editing interface provided by an editing application; determining a set of decorators for displaying the edit suggestions based at least on a type of the edit suggestions; and displaying the set of decorators associated with the target code in the code editing interface to present at least a portion of the edit suggestions.
[0005] In a second aspect of the present disclosure, a device for editing code is provided. The device includes: an acquisition module configured to acquire edit suggestions for target code in a code editing interface provided by an editing application; a first determination module configured to determine, based at least on a type of the edit suggestion, a set of decorators for displaying the edit suggestions; and a display module configured to display the set of decorators associated with the target code in the code editing interface to present at least a portion of the edit suggestions.
[0006] 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 coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit. When executed by the at least one processing unit, the instructions cause the device to perform the method of the first aspect.
[0007] 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.
[0008] In a fifth aspect of the present disclosure, a computer program product is provided, which includes computer-executable instructions, and when the computer-executable instructions are executed by a processor, the method of the first aspect is implemented.
[0009] It should be understood that the content described in this summary section is not intended to limit the key features or important features of the embodiments of the present disclosure, nor is it 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
[0010] 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:
[0011] FIG1 shows a schematic diagram of an example environment in which embodiments according to the present disclosure may be implemented;
[0012] FIG2 illustrates an example interface according to some embodiments of the present disclosure;
[0013] FIG3 illustrates a flowchart of an example process for editing code according to some embodiments of the present disclosure;
[0014] FIG4 shows a schematic structural block diagram of an apparatus for editing code according to some embodiments of the present disclosure; and
[0015] FIG5 shows a block diagram of an electronic device capable of implementing various embodiments of the present disclosure. DETAILED DESCRIPTION
[0016] The following describes embodiments of the present disclosure in more detail 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 limited to the embodiments described herein. Rather, 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 for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.
[0017] It should be noted that the titles of any section / subsection provided herein are not limiting. Various embodiments are described throughout this document, and any type of embodiment may be included under any section / subsection. Furthermore, 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 in different sections / subsections.
[0018] 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.
[0019] The embodiments of the present disclosure may involve user data, data acquisition and / or use, etc. These aspects shall comply with the corresponding laws, regulations and relevant provisions. In the embodiments of the present disclosure, all data collection, acquisition, processing, processing, forwarding, use, etc. are carried out on the premise that the user is aware of and confirms them. Accordingly, when implementing the various embodiments of the present disclosure, the types, scope of use, and usage scenarios of the data or information that may be involved should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with the relevant laws and regulations. The specific notification and / or authorization method may vary according to the actual situation and application scenario, and the scope of the present disclosure is not limited in this respect.
[0020] If this specification and the solutions in the examples involve the processing of personal information, such processing will be done only with a legitimate basis (such as with the consent of the subject of personal information or as necessary for the performance of a contract) and only within the prescribed or agreed scope. A user's refusal to process personal information other than that required for basic functions will not affect the user's use of basic functions.
[0021] Embodiments of the present disclosure provide a solution for editing code. According to this solution, edit suggestions for target code in a code editing interface provided by an editing application can be obtained. Furthermore, based at least on the type of the edit suggestion, a set of decorators for displaying the edit suggestion is determined. Furthermore, the set of decorators associated with the target code is displayed in the code editing interface to present at least a portion of the edit suggestion.
[0022] In this way, the embodiments of the present disclosure can display editing suggestions for the target code based on the editing interface provided by the editing application, and highlight at least part of different types of editing suggestions with different decorators, which can effectively improve the efficiency of code editing.
[0023] Various example implementations of this solution are described in detail below in conjunction with the accompanying drawings.
[0024] Sample Environment
[0025] FIG1 illustrates a schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented. In this example environment 100, an electronic device 110 has an application 120 installed. A user 140 can interact with the application 120 via the electronic device 110 and / or its attached devices. The application 120 can be a code editing application, or any other plug-in capable of editing code projects.
[0026] In the environment 100 of FIG1 , if the application 120 is in an active state, the electronic device 110 may present an interface 150 of the application 120. The interface 150 may include various interfaces that the application 120 may provide, such as a code editing interface.
[0027] In some embodiments, the electronic device 110 communicates with the server 130 to enable the provision of services for the application 120. The electronic device 110 can be any type of mobile terminal, fixed terminal or portable terminal, including a mobile phone, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a media computer, a multimedia tablet, a personal communication system (PCS) device, a personal navigation device, a personal digital assistant (PDA), an audio / video player, a digital camera / camcorder, a positioning device, a television receiver, a radio broadcast receiver, an e-book device, a gaming device or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. In some embodiments, the electronic device 110 can also support any type of interface for the user (such as a "wearable" circuit, etc.). The server 130 can be various types of computing systems / servers that can provide computing power, including but not limited to mainframes, edge computing nodes, computing devices in cloud environments, and the like.
[0028] It should be understood that the structure and function of the various elements in the environment 100 are described for illustrative purposes only and do not imply any limitation on the scope of the present disclosure.
[0029] Some example embodiments of the present disclosure will be described below with continued reference to the accompanying drawings.
[0030] Example Interaction
[0031] The following describes an example code editing process according to some embodiments of the present disclosure with reference to Figure 2. Figure 2 shows an example code editing interface 200 according to some embodiments of the present disclosure. The interface 200 may be provided by the electronic device 110 shown in Figure 1, for example.
[0032] In some embodiments, the electronic device 110 may support the user to edit the code in a code editing interface. Taking FIG2 as an example, the code editing interface 200 may include the code 210 currently being edited by the user.
[0033] When a user edits a target code based on the code editing interface 200, the electronic device can obtain editing suggestions for the target code in the code editing interface 200 and present at least part of the editing suggestions in the code editing interface 200. The editing suggestions indicate how to edit the target code. The editing suggestions may include, but are not limited to, information such as the code modification scope and the code editing content. The code editing interface is provided by the editing application.
[0034] Taking Figure 2 as an example, the code editing interface 200 may include target code 202, target code 204, target code 206, etc., code editing content 203 for target code 202, code editing content 205 for target code 204, and code editing content 209 for target code 206. In some embodiments, editing suggestions correspond to different types, which may include but are not limited to at least one of the following: insert type, delete type, and modify type. Modification type may also include inline completion type and non-inline completion type. Insert type is used to represent the insertion of code editing content into the target position in the target code, where the target position can be any appropriate position in the target code. For example, if the target code includes two lines of code, the target position can be the middle position of the two lines of code. Delete type is used to represent the deletion of target code. Modification type is used to represent the modification of target code to other code. Specifically, the inline completion type in the modification type is used to represent the completion of incomplete words and sentences in the line where the target code is located. At this time, the number of lines corresponding to the target code and the code editing content is the same. The target code corresponding to the non-inline completion type in the modification type and the number of lines corresponding to the code editing content are generally not exactly the same.
[0035] In some embodiments, the electronic device can obtain the code currently being edited by the user in the code editing interface and send the currently edited code to the target device so that the target device can obtain editing suggestions based on the currently edited code and the target model deployed in the target device.
[0036] In some embodiments, the editing suggestion can be a suggestion information in the form of "change the code in the line range [x, y) to code s". The line range [x, y) represents the code range from line x to the previous line of line y in the currently edited code. The line range [x, y) can also be called the code modification range, and the code range from line x to the previous line of line y can also be called the target code. s is the code editing content. If x is equal to y and s is not empty, then the electronic device can determine that the type of editing suggestion is "insert type". If s is empty and x is not equal to y, then the electronic device can determine that the type of editing suggestion is "deletion type". If x is equal to y and s is empty, then the electronic device can ignore this edit. If x is not equal to y and s is not empty, then the electronic device can determine that the type of editing suggestion is "modification type". Furthermore, the electronic device can determine whether the type of the editing suggestion is "inline completion type" or "non-inline completion type" based on whether the target code in the line range [x, y) corresponds to the code editing content s with the same number of lines and whether the target code and the code editing content only add characters but do not delete characters at the character level. If the target code in the line range [x, y) corresponds to the code editing content s with the same number of lines and the target code and the code editing content only add characters but do not delete characters at the character level, the electronic device can determine that the type of the editing suggestion is "inline completion type". If the target code in the line range [x, y) corresponds to the code editing content s with different numbers of lines or the target code and the code editing content have characters deleted at the character level, the electronic device can determine that the type of the editing suggestion is "non-inline completion type". In some embodiments, when displaying the code editing content of the non-inline completion type, the electronic device displays it based on the display method corresponding to the word level difference.
[0037] In some embodiments, the electronic device may use the diffChars function of the jsdiff package to compare the target code and the code edited content to determine the differences at the character level for each line. The electronic device may also use the diffWordsWithSpace function of the jsdiff package to compare the target code and the code edited content to determine the differences at the word level for each line.
[0038] In some embodiments, different types of edit suggestions may have different decorators corresponding to them in the editing interface to facilitate differentiation. Each edit suggestion may correspond to a set of decorators. The decorators are used to render the edit suggestions so that they appear in the code editing interface in the corresponding display format.
[0039] In some embodiments, the electronic device may determine a first decorator corresponding to the type of editing suggestion, and the first decorator is used to display a symbol element corresponding to the type. The symbol element is used to display the type corresponding to the editing suggestion in the code editing interface. Different types of symbol elements may be the same or different and may be set as needed. In some embodiments, the electronic device may also determine the code editing content corresponding to the editing suggestion in response to the type of editing suggestion satisfying a second preset condition. The electronic device may determine a group of third decorators corresponding to the code editing content, and a group of third decorators is used to display the code editing content. In some embodiments, the number of this group of third decorators is determined based on the number of lines of code editing content, where one line of code corresponds to one third decorator. The second preset condition may be any appropriate condition. As an example, the second preset condition may be that the type of code suggestion is not an inline completion type.
[0040] In some embodiments, the display position of the first decorator may be determined based on the code modification range targeted by the editing suggestion. The display positions of the set of third decorators may also be determined by the electronic device based on the code modification range targeted by the editing suggestion.
[0041] As an example, the display positions of the first decorator and the group of third decorators may also be determined based on the number of lines corresponding to the code range and the code editing content.
[0042] Taking Figure 2 as an example, the first line of code 203 can be displayed aligned with the line where code 202 is located, and in the editing interface 200 of the electronic device, character 230 can also be displayed between the last character of code 202 and the first character of the first line of code 203 to indicate that the type corresponding to the editing suggestion is an insert type, and code 230 is inserted between code 201 and code 202.
[0043] As shown in FIG2 , as an example, the first line of code 205 can be displayed aligned with the first line of code 204 . Furthermore, character 231 can be displayed between the first character of the first line of code 205 and the last character of the first line of code 204 in the editing interface 200 of the electronic device to indicate that the editing suggestion corresponds to a deletion type, specifically indicating that code 204 is to be deleted. As another example, the electronic device can determine the first target code with the smallest number of code lines between code 204 and code 205 and align the middle line of code in the first target code with character 231 . It should be noted that if the first target code has an even number of code lines, there are no middle lines in the first target code. In this case, the electronic device can align the previous line of code in the middle position of the first target code with character 231 . Using FIG2 as an example, if both code 204 and code 205 contain one line of code, the first target code can be either code 204 or code 205 , and character 231 is located on the same line as code 204 and code 205 in the editing interface 200 .
[0044] As shown in FIG2 , as an example, the first line of code 209 can be displayed aligned with the first line of code 208 . Furthermore, character 232 can be displayed between the first character of the first line of code 209 and the last character of the first line of code 208 in the editing interface 200 of the electronic device to indicate that the editing suggestion type is a non-inline completion type, i.e., code 208 is modified to code 209 . As another example, the electronic device can determine the second target code with the smallest number of lines between code 208 and code 209 and align the middle line of code in the second target code with character 232 . It should be noted that if the second target code has an even number of lines, there are no middle lines in the second target code. In this case, the electronic device can align the previous code in the middle position of the second target code with character 232 . For example, in FIG2 , if code 209 is the second target code, but the number of lines corresponding to the second target code is 2, the first line of code in code 209 can be aligned with character 232 .
[0045] In some embodiments, the electronic device may further determine, in response to the type satisfying a first preset condition, the portion of the target code to be modified by the edit suggestion; and determine a second decorator corresponding to the portion of the code, the second decorator being used to distinguishably display the modified portion of the target code. As an example, the second decorator may set the target code to a predetermined background color. As another example, the second decorator may also set the modified portion of the target code to italic or bold, etc.
[0046] 2 as an example, the electronic device may also set a predetermined background color for code 208. The electronic device may also set a predetermined background color for code 204. The electronic device may also display the corresponding modified portion of code 206 in italics.
[0047] In some embodiments, the electronic device determines a display position of a set of third decorators based on the code modification range. If the set of third decorators exceeds a first boundary of a code editing area of a code editing interface, the display position of the set of third decorators is adjusted. The first boundary may be the last line of code allowed to be displayed in the code editing interface.
[0048] As shown in FIG2 , if the last line of code 208 is the last line of code allowed to be displayed in the editing interface, and code 209 includes more than three lines of code, then the subsequent codes including the fourth line of code 209 cannot be displayed in the editing interface.
[0049] In order to solve the problem of incomplete code display, as an example, the electronic device can move code 209 upward so that the last line of code 209 is aligned with the last line of code allowed to be displayed by the editing interface to adjust the display position of this group of third decorators.
[0050] In response to the adjusted set of third decorators exceeding the second boundary of the code editing area, the electronic device can control at least one of the set of third decorators not to be displayed, so that only part of the code editing content is presented. The second boundary can be the first line of code allowed to be displayed in the code editing interface.
[0051] For example, if the first line of code 209 is moved up to the position aligned with the first line of code allowed to be displayed in the editing interface, but code 209 is still not fully displayed, the electronic device can display part of code 209 in the editing interface. For easy reminder, the electronic device can also display a prompt message indicating that code 209 is not fully displayed on the line corresponding to the last line of code allowed to be displayed in the editing interface, indicating that part of code 209 is not displayed on the editing page 200.
[0052] In some embodiments, a set of decorators includes at least a first set of decorators corresponding to a first line of code and a second set of decorators corresponding to a second line of code, wherein the first set of decorators and the second set of decorators have the same indentation in the code editing interface. The first set of decorators and the second set of decorators can decorate different lines of code, respectively. The first code and the second code can be represented as different lines of code.
[0053] Taking FIG. 2 as an example, the first line in code 203 and the second line in code 203 have the same indentation.
[0054] In some embodiments, a certain distance relationship may exist between the character element and the target code or the code editing content in terms of display position in the code editing interface.
[0055] Taking FIG. 2 as an example, a predetermined number of characters may be spaced between the character 231 and the last character of the code 204 , and a predetermined number of characters may also be spaced between the character 231 and the first character of the code 205 .
[0056] Taking Figure 2 as an example, a predetermined number of characters can be spaced between character 232 and the middle line code of the second target code, and a predetermined number of characters can also be spaced between character 232 and the last character of the code line in the third target code line corresponding to the middle line code of the second target code line. The third target code line is another code line in code 208 and code 209 other than the second target code line.
[0057] It should be noted that the code editing content can be displayed in different display modes for the editing suggestions for inline completion and the editing suggestions for non-inline completion.
[0058] For editing suggestions of the non-inline completion type, not all contents in the target code and the code editing content may be modified. For ease of display, in some embodiments, the electronic device can distinguish between the consistent contents in the target code and the code editing content (content that does not need to be modified) and the inconsistent contents in the target code and the code editing content (content that needs to be modified) in different display modes, that is, display the consistent content and the inconsistent content in different styles. As an example, the electronic device can set the content that does not need to be modified to italics, set the content that needs to be modified to bold, and so on. Taking Figure 2 as an example, for the first line of code in code 208, the content of "console.log(″") that has not been modified can be displayed in italics in the editing interface. If "return a+b" is modified, it will be displayed in bold in the editing interface.
[0059] For edit suggestions that are inline completion, the electronic device can display the code edit content at the target location in the target code in a non-differentiated style. Taking Figure 2 as an example, in response to the edit suggestion being an inline completion type, the electronic device can directly insert code 207 into code 206 and set code 207 to italics to indicate that the edit suggestion is an inline completion type, specifically indicating that code 207 will complete the line containing code 206.
[0060] The following describes the process of decorator-based rendering of each line of code in the editing interface, the character elements representing the type of each editing suggestion, and the display style of each code setting. In some embodiments, adjacent characters containing the same style (code is composed of multiple characters) are rendered with an after pseudo-element decoration type, that is, a decoration type can be applied to a text range, and a decoration type is implemented by a text decorator.
[0061] Taking Figure 2 as an example, character 230, the two characters between character 230 and the last character of code 202, and a predetermined number of characters between character 230 and the first character of code 203 are implemented by a text decorator, the first line of code 203 is implemented by a text decorator, the second line of code 203 is implemented by a text decorator, and the third line of code 203 is implemented by a text decorator.
[0062] The background color set for character 204 corresponds to a text decorator, character 231, a predetermined number of characters between character 231 and the last character of code 204, and a predetermined number of characters between character 231 and the first character of code 205 are implemented by a text decorator, and code 205 corresponding to the deletion style is implemented by a text decorator.
[0063] The first subcode in code 207 is implemented by a text decorator, and the second subcode corresponds to one text decorator, that is, code 207 corresponds to two text decorators.
[0064] In code 209, “console.log(″”) is implemented by a text decorator, “return a+b” is implemented by a text decorator, “″,″” is implemented by a text decorator, “developer” is implemented by a text decorator, and “″);” is implemented by a text decorator.
[0065] It should be noted that the display styles of various codes and the display styles of symbols identifying editing types in FIG. 2 are merely examples and do not constitute a limitation to the present disclosure.
[0066] The present disclosure can display suggested editing codes including multiple lines of code or characters representing the editing type corresponding to the suggested editing codes in the editing interface based on multiple text decorators, and can display different display styles for each code or character.
[0067] In this way, the embodiments of the present disclosure can display editing suggestions for the target code based on the editing interface provided by the editing application, and highlight at least part of different types of editing suggestions with different decorators, which can effectively improve the efficiency of code editing.
[0068] Example Process
[0069] 3 shows a flow chart of an example process 300 for editing code according to some embodiments of the present disclosure. Process 300 may be implemented at electronic device 110. Process 300 is described below with reference to FIG1.
[0070] As shown in FIG. 3 , in block 310 , the electronic device 110 obtains editing suggestions for a target code in a code editing interface provided by an editing application.
[0071] At block 320 , the electronic device 110 determines a set of decorators for presenting the edit suggestion based at least on the type of the edit suggestion.
[0072] In block 330 , the electronic device 110 displays a set of decorators associated with the target code in the code editing interface to present at least a portion of the editing suggestions.
[0073] In some embodiments, process 300 further includes determining a type of the editing suggestion based on the code modification scope and code editing content targeted by the editing suggestion, where the type includes an insertion type, a deletion type, or a modification type.
[0074] In some embodiments, determining a set of decorators for displaying edit suggestions based at least on the type of the edit suggestions includes determining a first decorator corresponding to the type of the edit suggestions, the first decorator being configured to display a symbol element corresponding to the type.
[0075] In some embodiments, the display position of the first decorator is determined based on the code modification scope targeted by the editing suggestion.
[0076] In some embodiments, determining a set of decorators for displaying editing suggestions based at least on the type of the editing suggestions includes: determining the code portion of the target code modified by the editing suggestions in response to the type satisfying a first preset condition; and determining a second decorator corresponding to the code portion, the second decorator being used to distinctively display the modified code portion in the target code.
[0077] In some embodiments, determining a set of decorators for displaying editing suggestions based at least on the type of editing suggestions includes: determining the code editing content corresponding to the editing suggestions in response to the type satisfying a second preset condition; and determining a set of third decorators corresponding to the code editing content, the set of third decorators being used to display the code editing content, and the number of the set of third decorators being determined based on the number of lines of the code editing content.
[0078] In some embodiments, process 300 further includes determining display positions of a set of third decorators based on the code modification scope targeted by the editing suggestion.
[0079] In some embodiments, determining the display position of a group of third decorators based on the code modification scope targeted by the editing suggestion includes: determining the display position of a group of third decorators based on the code modification scope; and adjusting the display position of a group of third decorators in response to a group of third decorators exceeding a first boundary of a code editing area of a code editing interface.
[0080] In some embodiments, process 300 further includes: in response to the adjusted set of third decorators exceeding a second boundary of the code editing area, controlling at least one of the set of third decorators to not be displayed so that only a portion of the code editing content is presented.
[0081] In some embodiments, the display style of the code editing content in the set of third devices is determined based on the editing type of the code editing content.
[0082] In some embodiments, a group of decorators includes at least a first group of decorators corresponding to a first line of code and a second group of decorators corresponding to a second line of code, wherein the first group of decorators and the second group of decorators have the same indentation in the code editing interface.
[0083] In some embodiments, the indentation is determined based on the length of a predetermined code line in the target code displayed in the code editing interface.
[0084] Example devices and equipment
[0085] The embodiments of the present disclosure also provide corresponding devices for implementing the above methods or processes.
[0086] 4 shows a schematic structural block diagram of an apparatus 400 for editing code according to certain embodiments of the present disclosure. The apparatus 400 may be implemented as or included in the electronic device 110. Each module / component in the apparatus 400 may be implemented by hardware, software, firmware, or any combination thereof.
[0087] The device 400 includes an acquisition module 410, configured to obtain editing suggestions for a target code in a code editing interface provided by an editing application; a first determination module 420, configured to determine a set of decorators for displaying the editing suggestions based at least on a type of the editing suggestions; and a display module 430, configured to display a set of decorators associated with the target code in the code editing interface to present at least part of the editing suggestions.
[0088] In some embodiments, the apparatus 400 further includes a second determination module configured to determine the type of the editing suggestion based on the code modification scope and code editing content targeted by the editing suggestion, where the type includes: insertion type, deletion type, or modification type.
[0089] In some embodiments, the first determining module 420 is specifically configured to determine a first decorator corresponding to the type of the editing suggestion, where the first decorator is used to display a symbol element corresponding to the type.
[0090] In some embodiments, the display position of the first decorator is determined based on the code modification scope targeted by the editing suggestion.
[0091] In some embodiments, the first determination module 420 is specifically configured to determine the code portion of the target code modified by the editing suggestion in response to the type satisfying the first preset condition; and determine a second decorator corresponding to the code portion, the second decorator being used to distinctively display the modified code portion in the target code.
[0092] In some embodiments, the first determination module 420 is specifically configured to determine the code editing content corresponding to the editing suggestion in response to the type satisfying the second preset condition; and determine a group of third decorators corresponding to the code editing content, a group of third decorators being used to display the code editing content, and the number of the group of third decorators being determined based on the number of lines of the code editing content.
[0093] In some embodiments, the apparatus 400 further includes a third determining module configured to determine display positions of a group of third decorators based on the code modification scope targeted by the editing suggestion.
[0094] In some embodiments, the third determination module is specifically configured to determine the display position of a group of third decorators based on the code modification range; and adjust the display position of a group of third decorators in response to a group of third decorators exceeding the first boundary of the code editing area of the code editing interface.
[0095] In some embodiments, the device 400 also includes a control module configured to: in response to the adjusted set of third decorators exceeding the second boundary of the code editing area, control at least one of the set of third decorators not to be displayed, so that only part of the code editing content is presented.
[0096] In some embodiments, the display style of the code editing content in the set of third devices is determined based on the editing type of the code editing content.
[0097] In some embodiments, a group of decorators includes at least a first group of decorators corresponding to a first line of code and a second group of decorators corresponding to a second line of code, wherein the first group of decorators and the second group of decorators have the same indentation in the code editing interface.
[0098] In some embodiments, the indentation is determined based on the length of a predetermined code line in the target code displayed in the code editing interface.
[0099] FIG5 shows a block diagram of an electronic device 500 in which one or more embodiments of the present disclosure may be implemented. It should be understood that the electronic device 500 shown in FIG5 is merely exemplary and should not be construed as limiting the functionality and scope of the embodiments described herein. The electronic device 500 shown in FIG5 can be used to implement the electronic device 110 of FIG1 .
[0100] As shown in FIG5 , electronic device 500 is a general-purpose electronic device. Components of electronic device 500 may include, but are not limited to, one or more processors or processing units 510, memory 520, storage device 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. Processing unit 510 may be a real or virtual processor and is capable of performing various processes according to programs stored in memory 520. In a multi-processor system, multiple processing units execute computer-executable instructions in parallel to enhance the parallel processing capabilities of electronic device 500.
[0101] The electronic device 500 typically includes a plurality of computer storage media. Such media can be any accessible media that can be obtained by the electronic device 500, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 520 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 530 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 that can be used to store information and / or data (e.g., training data for training) and can be accessed within the electronic device 500.
[0102] The electronic device 500 may further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown in FIG. 5 , a disk drive for reading from or writing to a removable, non-volatile disk (e.g., a “floppy disk”) and an optical drive for reading from or writing to a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to a bus (not shown) by one or more data media interfaces. The memory 520 may include a computer program product 525 having one or more program modules configured to perform various methods or actions of various embodiments of the present disclosure.
[0103] The communication unit 540 enables communication with other electronic devices via a communication medium. Additionally, the functions of the components of the electronic device 500 can be implemented in a single computing cluster or multiple computing machines that can communicate via a communication connection. Thus, the electronic device 500 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.
[0104] Input device 550 may be one or more input devices, such as a mouse, keyboard, or trackball. Output device 560 may be one or more output devices, such as a display, a speaker, or a printer. Electronic device 500 may also communicate with one or more external devices (not shown) via communication unit 540 as needed, such as a storage device, a display device, or the like, with one or more devices that allow a user to interact with electronic device 500, or with any device that allows electronic device 500 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).
[0105] 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.
[0106] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, apparatuses, devices, and computer program products implemented according to the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.
[0107] 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, such that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.
[0108] 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, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0109] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple implementations of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a part for a module, program segment or instruction, and a part for a module, program segment or instruction comprises one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the 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.
[0110] While various implementations of the present disclosure have been described above, the foregoing description is intended to be illustrative, not exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described implementations. The terminology used herein is selected to best explain the principles of the implementations, their practical applications, or improvements to existing technologies, or to enable others skilled in the art to understand the various implementations disclosed herein.
Claims
1. A method for editing code, comprising: Obtaining editing suggestions for a target code in a code editing interface, where the code editing interface is provided by an editing application; Based at least on the type of the edit suggestion, determining a set of decorators for displaying the edit suggestion; as well as The set of decorators associated with the target code is displayed in the code editing interface to present at least a portion of the editing suggestion.
2. The method according to claim 1, further comprising: The type of the editing suggestion is determined based on the code modification scope and code editing content targeted by the editing suggestion, wherein the type includes: insertion type, deletion type or modification type.
3. The method of claim 1 , wherein determining a set of decorators for displaying the edit suggestions based at least on the type of the edit suggestions comprises: A first decorator corresponding to the type of the editing suggestion is determined, and the first decorator is used to display a symbol element corresponding to the type. 4 . The method according to claim 3 , wherein the display position of the first decorator is determined based on the code modification scope targeted by the editing suggestion.
5. The method of claim 1 , wherein determining a set of decorators for displaying the edit suggestions based at least on the type of the edit suggestions comprises: In response to the type satisfying a first preset condition, determining a code portion of the target code modified by the editing suggestion; as well as A second decorator corresponding to the code portion is determined, wherein the second decorator is used to distinctively display the modified code portion in the target code.
6. The method of claim 1 , wherein determining a set of decorators for displaying the edit suggestion based at least on the type of the edit suggestion comprises: In response to the type satisfying a second preset condition, determining a code editing content corresponding to the editing suggestion; as well as A group of third decorators corresponding to the code editing content is determined, the group of third decorators is used to display the code editing content, and the number of the group of third decorators is determined based on the number of lines of the code editing content.
7. The method according to claim 6, further comprising: Based on the code modification scope targeted by the editing suggestion, display positions of the set of third decorators are determined.
8. The method according to claim 7, wherein determining the display position of the set of third decorators based on the code modification scope targeted by the editing suggestion comprises: Based on the code modification range, determining a display position of the set of third decorators; as well as In response to the group of third decorators exceeding a first boundary of the code editing area of the code editing interface, adjusting the display positions of the group of third decorators.
9. The method according to claim 8, further comprising: In response to the adjusted set of third decorators exceeding a second boundary of the code editing area, at least one of the set of third decorators is controlled not to be displayed, so that only a portion of the code editing content is presented.
10. The method of claim 6, wherein a display style of the code editing content in the group of third devices is determined based on an editing type of the code editing content.
11. The method according to claim 1, wherein the group of decorators includes at least a first group of decorators corresponding to a first code line and a second group of decorators corresponding to a second code line, wherein the first group of decorators and the second group of decorators have the same indentation in the code editing interface.
12. The method according to claim 11, wherein the indentation is determined based on the length of a preset code line in the target code displayed in the code editing interface.
13. A device for editing code, comprising: an acquisition module, configured to acquire editing suggestions for a target code in a code editing interface provided by an editing application; The first determining module is configured to determine the type of the editing suggestion based on at least a set of decorators for displaying said editing suggestions; as well as The display module is configured to display the set of decorators associated with the target code in the code editing interface to present at least part of the editing suggestion.
14. An electronic device, comprising: 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.
16. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 12.