Method and apparatus for editing code
By displaying candidate paths in the code editing window and generating the target path all at once, the problem of low code completion efficiency in existing technologies is solved, enabling efficient and accurate code writing and improving the user experience.
Patent Information
- Application Number
- CN202111386829.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-11-22
AI Technical Summary
Existing code completion technologies are inefficient in complex code files, requiring users to perform multiple operations to complete multiple nodes and need to understand the complete data structure to edit the code correctly.
A method and apparatus for editing code are provided, in which a user can select and generate target paths for multiple nodes at once by displaying candidate paths in a code editing window, including filtering candidate paths and generating target paths, ensuring that the generated paths conform to the syntax specifications of the file to be written.
It improves the efficiency and quality of code writing, saves time and effort, enhances the user experience, and reduces tedious multiple operations, especially in scenarios involving the writing of complex configuration files.
Smart Images

Figure CN116149629B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method and apparatus for editing code. Background Technology
[0002] Code completion technology has always been a research hotspot in the field of software engineering. This technology can greatly reduce the workload of programmers and improve development efficiency, quality, and user experience. Code completion functionality is a core feature of all current mainstream integrated development environments (IDEs).
[0003] Existing code completion technology can use description files to edit code files. By precisely matching the relative position of the cursor position in the semantic tree of the description file, it can edit the code of the node at the cursor position and complete it.
[0004] However, most code files have complex semantics, and users generally experience low work efficiency when using code completion features to edit such files. Summary of the Invention
[0005] This application provides a method and apparatus for editing code, which can complete multiple nodes at once, helping to improve the user's development efficiency and experience.
[0006] In a first aspect, a method for editing code is provided, comprising: displaying a first window in a code editing window, the first window including at least one candidate path, each candidate path including one or more nodes; detecting a first operation by a user on the first window, the first operation being used to determine a target path from the at least one candidate path; and generating the target path in the code editing window in response to the first operation.
[0007] According to this technical solution, multiple nodes can be completed at once, such as all nodes on a path. This avoids users having to complete the code multiple times in different locations, improving the efficiency and quality of code writing, saving time and effort, and enhancing the user experience.
[0008] In conjunction with the first aspect, in one possible implementation, the method further includes: detecting a second user action; the step of displaying the first window in the code editing window includes: displaying the first window in the code editing window in response to the second action.
[0009] Users can use the code editing methods provided in this application as needed.
[0010] In conjunction with the first aspect, in one possible implementation, the second operation is any one of the following: inputting characters, inputting commands, inputting shortcut keys, inputting shortcut key combinations, and clicking a menu.
[0011] In conjunction with the first aspect, in one possible implementation, the code editing window includes a location node; generating the target path in the code editing window includes: starting from the location node, generating the target path in the code editing window.
[0012] It should be understood that this code editing window is used to write the file to be written, and the code in the code editing window is the code that has already been written in the file to be written. The positioning node can be understood as the node where the cursor is located in the editing window.
[0013] Generating the target path in the code editing window can be achieved by directly replacing the location node in the code editing window with the target path. Alternatively, the location node in the code editing window can be deleted before generating the target path. Or, based on the target path and the location node in the code editing window, the missing path between them can be determined, and the missing path can be generated.
[0014] It should also be understood that when the cursor is at a node in the middle of a path—that is, when the positioned node has one or more pre-written descendant nodes—generating the target path in the code editing window directly replaces the positioned node and its descendant nodes in the code editing window with the target path. Alternatively, the positioned node and its descendant nodes in the code editing window can be deleted before generating the target path. Or, based on the target path and the positioned node and its descendant nodes in the code editing window, the missing path between them can be determined, and the missing path can be generated.
[0015] In conjunction with the first aspect, in one possible implementation, the start node of each candidate path in the at least one candidate path includes the field corresponding to the location node.
[0016] In conjunction with the first aspect, in one possible implementation, the field corresponding to the location node is the prefix of the starting node of each candidate path.
[0017] This can improve the accuracy of candidate paths, providing users with paths that are more likely to be chosen by them.
[0018] In conjunction with the first aspect, in one possible implementation, before detecting the user's first operation on the first window, the method further includes: detecting a third operation by the user on the first window, the third operation being an operation of inputting characters; in response to the third operation, obtaining one or more filtered candidate paths by filtering the at least one candidate path, wherein each of the one or more filtered candidate paths includes the characters input by the user; and displaying the filtered candidate paths in the first window.
[0019] In this way, users can further filter the multiple candidate paths displayed in the first window to narrow down the range of candidate paths. This filtering operation can improve the efficiency of code writing, especially when there are many candidate paths.
[0020] In conjunction with the first aspect, in one possible implementation, before displaying the first window in the code editing window, the method further includes: determining the at least one candidate path from a first path set corresponding to the description file based on at least one node in the code editing window, wherein the code editing window is used to write code for a file to be written, and the file to be written conforms to the same syntax structure as the description file.
[0021] It should be understood that the user is writing a file in the code editor based on the description file. During the writing process, the file should always meet the specifications defined by the description file. That is, the nodes in the file, the relationships between nodes, and the relative positions of nodes should be consistent with those described in the description file, so that the file and the description file conform to the same syntax structure.
[0022] In conjunction with the first aspect, in one possible implementation, the code editing window includes a positioning node; determining the at least one candidate path from a first path set corresponding to the description file based on at least one node in the code editor includes: determining at least one candidate node from the first path set based on the at least one node, wherein each candidate node in the at least one candidate node includes a field corresponding to the positioning node; and determining the at least one candidate path from the first path set using each candidate node in the at least one candidate node as a starting node.
[0023] In conjunction with the first aspect, in one possible implementation, the at least one node includes the location node and the parent node of the location node; determining at least one candidate node from the first path set based on the at least one node includes: determining a first node from the first path set based on the parent node of the location node, wherein the first node has the same field as the parent node of the location node; and determining the at least one candidate node from the child nodes of the first node based on the field corresponding to the location node.
[0024] In conjunction with the first aspect, in one possible implementation, the at least one node includes all nodes from the location node to its root node; determining at least one candidate node from the first path set based on the at least one node includes: determining a first path from the first path set based on the path from the root node to the parent node of the location node, wherein the first path is the same as the path from the root node to the parent node of the location node; and determining the at least one candidate node from the child nodes of the terminal node of the first path based on the field corresponding to the location node.
[0025] In conjunction with the first aspect, in one possible implementation, the code editing window includes a location node, and the location node is empty; determining the at least one candidate path from a first path set corresponding to the description file based on at least one node in the code editing window includes: determining a first node from the first path set based on the parent node of the location node, wherein the first node has the same field as the parent node of the location node; and determining the at least one candidate path from the first path set with each child node of the first node as a starting node.
[0026] Secondly, a method for editing code is provided, comprising: displaying a second window in a code editing window, the second window including a plurality of nodes, the plurality of nodes being used to indicate a first set of paths corresponding to a description file; detecting a fourth operation by a user on the second window, the fourth operation being used to determine a target node from the plurality of nodes; and generating a target path in the code editing window in response to the fourth operation, wherein the terminal node of the target path is the target node, and the nodes included in the target path belong to nodes not configured in the code editing window.
[0027] It should be understood that this code editing window is used to write the file to be written, and the code in the code editing window is the code that has already been written in the file to be written.
[0028] According to this technical solution, all editable nodes, i.e., unconfigured nodes, can be displayed. When a user selects a target node, all unconfigured nodes in the target path with that target node as the terminal node can be generated at once. In this way, users can intuitively see the unconfigured nodes in the file to be written, and multiple unconfigured nodes can be generated at once, improving the efficiency and quality of users' code writing, saving time and effort, and enhancing the user experience.
[0029] In conjunction with the second aspect, in one possible implementation, generating the target path in the code editing window includes: determining the path from the root node to the target node from the first path set; and determining the target path based on the path from the root node to the target node and the nodes configured in the code editing window.
[0030] This allows all unconfigured nodes along the path from the root node to the target node to be generated at once, improving the efficiency and quality of code writing, saving time and effort, and enhancing the user experience.
[0031] In conjunction with the second aspect, in one possible implementation, the multiple nodes are arranged in a tree structure or a multi-level directory structure.
[0032] In conjunction with the second aspect, in one possible implementation, the plurality of nodes includes a first node set and a second node set, wherein the nodes in the first node set are nodes configured in the code editing window, and the nodes in the second node set are nodes not configured in the code editing window.
[0033] In conjunction with the second aspect, in one possible implementation, the second window includes a first identifier for indicating a node in the second node set.
[0034] In this way, the first identifier can intuitively indicate to the user which nodes have been configured and which nodes have not been configured, which helps to improve writing efficiency.
[0035] In conjunction with the second aspect, in one possible implementation, the second window includes a second identifier that indicates the type of each of the plurality of nodes.
[0036] In this way, the second identifier can represent the type of each node, making it easier for users to select the type of node that needs to be configured.
[0037] In conjunction with the second aspect, in one possible implementation, the second window includes a first control for displaying or hiding nodes in the second node set.
[0038] In this way, users can choose to hide or show unconfigured nodes as needed, and quickly bring up a second window for editing when code editing is required.
[0039] Thirdly, an apparatus for editing code is provided, the apparatus comprising: a display unit for displaying a first window in a code editing window, the first window including at least one candidate path, each candidate path including one or more nodes; a detection unit for detecting a first operation by a user on the first window, the first operation being used to determine a target path from the at least one candidate path; and a generation unit for generating the target path in the code editing window in response to the first operation.
[0040] In conjunction with the third aspect, in one possible implementation, the detection unit is further configured to detect a second user operation; the display unit is further configured to display a first window in the code editing window in response to the second operation.
[0041] In conjunction with the third aspect, in one possible implementation, the second operation is any one of the following: inputting characters, inputting commands, inputting shortcut keys, inputting shortcut key combinations, and clicking a menu.
[0042] In conjunction with the third aspect, in one possible implementation, the generation unit is specifically used to generate the target path in the code editing window, starting from the positioning node in the code editing window.
[0043] In conjunction with the third aspect, in one possible implementation, the starting node of each candidate path in the at least one candidate path includes the field corresponding to the positioning node.
[0044] In conjunction with the third aspect, in one possible implementation, the field corresponding to the positioning node is the prefix of the starting node of each candidate path.
[0045] In conjunction with the third aspect, in one possible implementation, the apparatus may further include a determining unit; the detecting unit is further configured to detect a third operation by the user on the first window, the third operation being an operation of inputting characters; the determining unit is configured to, in response to the third operation by the user on the first window, obtain one or more filtered candidate paths by filtering the at least one candidate path, wherein each of the one or more filtered candidate paths includes characters input by the user; the display unit is further configured to display the filtered candidate paths in the first window.
[0046] In conjunction with the third aspect, in one possible implementation, the determining unit is further configured to determine the at least one candidate path from a first path set corresponding to the description file based on at least one node in the code editing window, wherein the code editing window is used to write the code of the file to be written, and the file to be written conforms to the same syntax structure as the description file.
[0047] In conjunction with the third aspect, in one possible implementation, the determining unit may further be specifically used to: determine at least one candidate node from a first path set based on the at least one node, wherein each candidate node in the at least one candidate node includes a field corresponding to the positioning node; and determine at least one candidate path from the first path set, using each candidate node in the at least one candidate node as a starting node.
[0048] In conjunction with the third aspect, in one possible implementation, the determining unit may further be specifically used to: determine a first node from a first path set based on the parent node of the positioning node, wherein the first node has the same field as the parent node of the positioning node; and determine the at least one candidate node from the child nodes of the first node based on the field corresponding to the positioning node.
[0049] In conjunction with the third aspect, in one possible implementation, the determining unit may further be specifically configured to determine a first path from a first path set based on the path from the root node of the positioning node to the parent node of the positioning node, wherein the first path is the same as the path from the root node of the positioning node to the parent node of the positioning node; and determine the at least one candidate node from the child nodes of the terminal node of the first path based on the field corresponding to the positioning node.
[0050] In conjunction with the third aspect, in one possible implementation, the determining unit may further be specifically used to: determine a first node from the first path set based on the parent node of the positioning node, wherein the first node has the same field as the parent node of the positioning node; the determining unit may further be specifically used to determine the at least one candidate path from the first path set, with each child node of the first node as the starting node.
[0051] Fourthly, an apparatus for editing code is provided, the apparatus comprising: a display unit for displaying a second window in a code editing window, the second window including a plurality of nodes, the plurality of nodes being used to indicate a first set of paths corresponding to a description file; a detection unit for detecting a fourth operation by a user on the second window, the fourth operation being used to determine a target node from the plurality of nodes; and a generation unit for generating a target path in the code editing window in response to the fourth operation, wherein the terminal node of the target path is the target node, and the nodes included in the target path belong to nodes not configured in the code editing window.
[0052] In conjunction with the fourth aspect, in one possible implementation, the apparatus may further include a determining unit, the determining unit being configured to: determine a path from the root node to the target node from a first path set; and determine the target path based on the path from the root node to the target node and the nodes configured in the code editing window.
[0053] In conjunction with the fourth aspect, in one possible implementation, the multiple nodes are arranged in a tree structure or a multi-level directory structure.
[0054] In conjunction with the fourth aspect, in one possible implementation, the plurality of nodes includes a first node set and a second node set, wherein the nodes in the first node set are nodes configured in the code editing window, and the nodes in the second node set are nodes not configured in the code editing window.
[0055] In conjunction with the fourth aspect, in one possible implementation, the second window includes a first identifier that indicates a node in the second node set.
[0056] In conjunction with the fourth aspect, in one possible implementation, the second window includes a second identifier that indicates the type of each of the plurality of nodes.
[0057] In conjunction with the fourth aspect, in one possible implementation, the second window includes a first control for displaying or hiding nodes in the second node set.
[0058] Fifthly, an apparatus for editing code is provided, comprising a module or unit for performing the method described in the first aspect or any possible implementation thereof. The module or unit may be hardware circuitry, software, or a combination of hardware circuitry and software implementation.
[0059] Sixthly, an apparatus for editing code is provided, comprising a module or unit for performing the method described in the second aspect or any possible implementation thereof. The module or unit may be hardware circuitry, software, or a combination of hardware circuitry and software implementation.
[0060] A seventh aspect provides an apparatus for editing code, comprising: a memory for storing a computer program; and a processor for executing the computer program stored in the memory, such that the apparatus performs a method in either the first or second aspect.
[0061] In one possible implementation, taking into account the seven aspects, the device is a code editor.
[0062] Eighthly, a chip system is provided, including at least one processor, wherein when program instructions are executed in the at least one processor, the at least one processor causes the at least one processor to perform the method in any possible implementation of the first or second aspect described above.
[0063] Ninth aspect, a computer-readable storage medium is provided, characterized in that it stores computer-executable instructions, which, when executed on a computer, cause the computer to perform the method in any one of the implementations of the first aspect or the second aspect.
[0064] In a tenth aspect, a computer program product is provided, the computer program product comprising: computer program code, which, when run on a computer, causes the computer to perform the method in any possible implementation of the first or second aspect described above.
[0065] It is understood that any of the above-mentioned code editing devices, chip systems, computer-readable storage media, or computer program products are used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here. Attached Figure Description
[0066] Figure 1 This is a schematic flowchart illustrating a method for editing code provided in an embodiment of this application.
[0067] Figure 2 This is a schematic flowchart illustrating another method for editing code provided in an embodiment of this application.
[0068] Figure 3 This is a schematic diagram of a description document provided in an embodiment of this application.
[0069] Figure 4 yes Figure 3The diagram shows a tree structure corresponding to the description file.
[0070] Figure 5 This is a schematic diagram of a code editor interface provided in an embodiment of this application.
[0071] Figure 6 This is a schematic flowchart illustrating a method for editing code provided in an embodiment of this application.
[0072] Figure 7 This is a schematic flowchart illustrating another method for editing code provided in an embodiment of this application.
[0073] Figure 8 This is a schematic diagram of a code editor interface provided in an embodiment of this application.
[0074] Figure 9 This is a schematic block diagram of a code editing device provided in an embodiment of this application.
[0075] Figure 10 This is a schematic block diagram of a code editing device provided in an embodiment of this application.
[0076] Figure 11 This is a schematic structural diagram of a code editing device provided in an embodiment of this application. Detailed Implementation
[0077] The technical solutions in this application will now be described with reference to the accompanying drawings.
[0078] The methods in this application embodiment can be applied to electronic devices such as smartphones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application embodiment does not impose any restrictions on the specific type of electronic device, as long as it can be used for code editing, such as the electronic device including an integrated development environment.
[0079] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0080] JSON, YAML, and XML are commonly used data serialization languages. Documents in formats such as JSON, YAML, and XML can store structured data and are often used as application configuration files. A configuration file is essentially a text document that allows you to configure parameters and initial settings for computer programs, such as HarmonyOS's config.json, AndroidManifest.xml, and service.yml.
[0081] A schemafile is a vocabulary used to annotate and validate configuration files, providing a unified data specification syntax. Each configuration file format has its own schemafile, such as JSON schemafiles, YAML schemafiles, and XML schemafiles. Each type of schemafile shares the same syntax as the configuration file it describes; for example, JSONSchema is a JSON file that conforms to JSON syntax.
[0082] In application development, users often use documents in formats such as JSON, XML, or YAML as configuration files. To ensure that the written configuration files can be correctly configured and parsed, users need to write configuration files based on description files. For example, the configuration files of the Java persistence framework MyBatis are written in XML. To ensure that the configuration files are valid and that the MyBatis framework can parse them correctly, users need to write configuration files based on XML description files, ensuring that the configuration files not only conform to the basic syntax of XML but also to the data specification syntax defined in the XML description files.
[0083] To facilitate understanding, the technical terms used in this application will be explained and described below.
[0084] An Integrated Development Environment (IDE) is an application that provides a program development environment, typically including a code editor, compiler, debugger, and graphical user interface. An IDE integrates code writing, analysis, compilation, and debugging capabilities into a single development software suite. Any software or software suite (or group of software) possessing these characteristics can be called an IDE, such as the Visual Studio series, C++Builder, and Devon Studio. This program can run independently or in conjunction with other programs.
[0085] In computer science, a tree is an abstract data type (ADT) or a data structure that implements this abstract data type, used to simulate a data set with tree-like structure properties. It is a hierarchical set composed of a finite number of n (n>0) nodes. It is called a "tree" because it looks like an upside-down tree, that is, with the root at the top and the leaves at the bottom. It has the following characteristics:
[0086] (1) Each node has only a finite number of child nodes or no child nodes;
[0087] (2) A node without a parent node is called the root node;
[0088] (3) Every non-root node has one and only one parent node;
[0089] (4) Except for the root node, each child node can be divided into multiple disjoint subtrees;
[0090] (5) There are no loops in the tree, and the path from the root node to any node is uniquely determined.
[0091] In a tree structure, there are generally the following types of nodes:
[0092] Leaf node or terminal node: A node that has no child nodes;
[0093] Parent node or parent node's: If a node has child nodes, then this node is called the parent node of that child node;
[0094] Child node or sub-node: The root node of the subtree contained in a node is called the child node of that node;
[0095] Descendant node: Any node in the subtree rooted at a given node is called a descendant node of that node.
[0096] Sibling nodes: Nodes that share the same parent node are called sibling nodes.
[0097] Generally, we consider a description file or configuration file to contain only one root node. However, in some formats, the root node is explicitly shown within the file itself. For example, an XML file has exactly one root node, each with a start and end tag, and all other nodes are contained within it. In other formats, the root node is not directly shown in the file. For instance, a JSON file can contain multiple parallel subtrees, all with the file itself as their root node.
[0098] Code completion technology can predict the class name, method name, and code snippet to be completed in real time based on user input and existing code, and provide the user with a suggestion list. After the user selects a completion option from the suggestion list, the corresponding code can be completed. Existing technology can use description files to achieve code completion for configuration files. By accurately matching the relative position of the cursor position in the description file's syntax tree, code editing can be performed on the node at the cursor position. However, this method can only complete missing fields of the current node. If the user needs to complete multiple nodes, multiple completion operations are required, which is inefficient. Furthermore, due to the semantic complexity of configuration files in most development scenarios, which contain multi-level nested structures, such as the action configuration in AndroidManifest.xml (activity>inten>filter>action) and the Ark Compiler configuration in HarmonyOSconfig.json (deviceConfig>phone>ark>flag), when using code completion to perform code editing operations, users not only need to perform code completion multiple times in the configuration file (e.g., first complete the activity, then the inten, then the filter, and finally the action), which is cumbersome, but also need to understand the complete data structure of the configuration file in order to perform code editing operations in the correct location.
[0099] In view of this, this application provides a method and apparatus for editing code. The method can complete multiple nodes at once, such as completing all nodes on a path at once, avoiding the need for users to perform multiple code editing operations at different locations in the code editing window, thereby improving the efficiency and quality of code file writing, saving time and effort, and enhancing the user experience.
[0100] The method for editing code according to the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0101] Figure 1 This is an example of a schematic flowchart of a method for editing code provided in an embodiment of this application. Figure 1 The method shown includes steps S110 to S130, which are described below.
[0102] S110, Display a first window in the code editing window. The first window includes at least one candidate path, and each candidate path includes one or more nodes.
[0103] It should be noted that the code editing window is used to edit the code of the file to be written. Users can enter characters in the code editing window to write the code of the file to be written, or they can generate the code of the file to be written in the code editing window through code completion technology. The nodes in the code editing window are the configured nodes of the file to be written.
[0104] The file to be written can be a configuration file or a code file of other types or formats. For example, the file to be written can be a configuration file in JSON, YAML, or XML format, or a code file of other types in JSON, YAML, or XML format, or a code file of other formats. This application does not limit the type of the file to be written.
[0105] In this embodiment, a node can be understood as a single syntactic unit in a description file or a file to be written. It should be noted that keywords in the description file, such as "type" and "properties," are not nodes.
[0106] In this embodiment, a path refers to an ordered, hierarchical sequence of nodes consisting of one or more nodes. For example, "a" has child nodes "b1" and "b2", and "b1" has child nodes "c1" and "c2". "a>b1" or "a>b1>c2" are both paths. It should be understood that when the first window includes only one candidate path, that candidate path should also be considered a path.
[0107] In some embodiments, the start node of each candidate path in the at least one candidate path corresponds to a positioning node in the code editing window, and the start node includes the field corresponding to the positioning node.
[0108] It should be understood that the start node should completely and continuously include the field corresponding to the location node. That is, at least part of the field corresponding to the start node is exactly the same as the field corresponding to the location node, including the same characters and character length. For example, assuming the field corresponding to the location node is "abc", then the node "dabc" includes the field corresponding to the location node, while the node "adbc" does not include the field corresponding to the location node.
[0109] Optionally, the field corresponding to the location node is the prefix of the starting node of each candidate path.
[0110] This improves the accuracy of candidate paths, providing users with paths more likely to be selected. Understandably, the prefix of a starting node includes several characters starting from the first character. For example, assuming the field corresponding to the location node is "abc", then "abc" can be considered the prefix of the node "abcd", not the prefix of the node "dabc". In fact, the first character in the prefix of the node "dabc" is "d".
[0111] It should be noted that the positioning node is the node where the cursor is located in the code editing window, which is also the node the user is currently editing in the code editor. This application does not limit the cursor position. That is to say, the positioning node can be at a leaf node of a path, or at a node in the middle of a path. The positioning node can be a node that conforms to the description file specification, or it can be a node that does not conform to the description file specification; it can be a complete node, or it can be an incomplete node. The corresponding field of the positioning node can be a letter or a symbol, or it can be empty; this application does not limit this.
[0112] In some embodiments, the at least one candidate path can be determined from a first set of paths corresponding to the description file based on at least one node in the code editing window.
[0113] In this embodiment, the file being edited in the code editing window is the file to be written, which conforms to the same syntax structure as the description file. Here, the first path set includes all the paths described by the description file, including both complete paths (such as paths from the root node to the leaf node) and incomplete paths (such as paths including one or more nodes).
[0114] There are several ways to determine at least one candidate path.
[0115] As an example, if the code editing window includes a location node, and the location node is empty, a first node can be determined from the first path set based on the parent node of the location node, where the first node and the parent node of the location node have the same fields. Then, using each child node of the first node as a starting node, at least one candidate path is determined from the first path set.
[0116] In other words, when the positioning node in the code editing window is empty, the relative position of the positioning node in the first path set can be determined based on its parent node. That is, the first node corresponding to the parent node of the positioning node is determined in the first path set, and the child nodes of the first node are the relative positions of the positioning node in the first path set. In this way, candidate paths in the first path set that start from the first node can be enumerated.
[0117] As another example, at least one candidate node can be determined from the first path set based on at least one node mentioned above, wherein each candidate node includes a field corresponding to the location node. Using each candidate node as a starting node, at least one candidate path is determined from the first path set.
[0118] In other words, based on the location node, candidate nodes with fields corresponding to the location node can be determined directly in the first path set, and then candidate paths starting from the candidate node can be enumerated in the first path set.
[0119] In this example, there are multiple ways to determine candidate nodes.
[0120] For example, if at least one node includes a locator node and its parent node, then a first node can be determined from the first path set based on the parent node of the locator node, wherein the first node and the parent node of the locator node have the same fields. Based on the fields corresponding to the locator node, the at least one candidate node is determined from the child nodes of the first node.
[0121] In other words, the relative position of the locating node in the first path set can be determined first based on its parent node. Specifically, the first node corresponding to the parent node of the locating node is identified in the first path set, and the child nodes of this first node represent the relative position of the locating node in the first path set. Then, candidate nodes with the same fields as the locating node are identified among the child nodes of the first node. At this point, the parent nodes of the candidate nodes in the first path set have the same fields as the parent node of the locating node in the code editing window, and the candidate nodes include the fields of the locating node, thus improving the accuracy of the candidate nodes.
[0122] For example, if at least one node includes all nodes from the locating node to its root node, then a first path can be determined from the first path set based on the path from the root node to the parent node of the locating node. This first path is the same as the path from the root node to the parent node of the locating node. Based on the fields corresponding to the locating node, the at least one candidate node is determined from the child nodes of the terminal node of the first path.
[0123] In other words, the relative position of the locating node in the first path set can be determined firstly by following the path from the root node to its parent node in the code editing window. This means identifying the first path that matches the current path, and the child nodes of the terminal node of that first path represent the relative position of the locating node in the first path set. Then, candidate nodes with the same fields as the locating node are identified from among the child nodes of the terminal node of the first path. At this point, the path from the root node to the parent node of the candidate node is the same as the path from the root node to the parent node of the locating node, and the candidate nodes include the fields corresponding to the locating node, greatly improving the accuracy of the candidate nodes. The following section will discuss how to determine the candidate paths in conjunction with... Figure 2 A more detailed explanation will not be provided here.
[0124] In some embodiments, a second user action is detected, and in response to the second action, a first window is displayed in the code editing window.
[0125] Therefore, users can invoke the first window for code editing as needed. When code editing is not required, the first window is hidden, allowing users to write code directly in the code editing window.
[0126] Optionally, the second operation can be any of the following: entering characters, entering commands, entering shortcut keys, entering a combination of shortcut keys, or clicking a menu. The entered characters can be letters or symbols.
[0127] Of course, the second operation can also be other operations. For example, the second operation can also be other types of operations that are user-defined or predefined by the program. As long as the operation can bring up the first window for code editing, it is within the protection scope of this application.
[0128] S120, detect the user's first operation on the first window, the first operation being used to determine the target path from at least one candidate path.
[0129] The first operation is the selection and confirmation of a candidate path from at least one candidate path. This first operation can be a click operation; for example, a user can confirm the target path by clicking with a mouse, or by selecting and confirming the target path using the keyboard.
[0130] In some embodiments, before detecting a first user action on the first window, a third user action, which is the user inputting characters, may also be detected. The at least one candidate path is then filtered based on the user-input characters, such that each of the filtered candidate paths includes the user-input characters. Accordingly, the first window can display the filtered candidate paths.
[0131] In other words, users can further filter the multiple candidate paths displayed in the first window to narrow down the range of candidate paths. This filtering operation can improve the efficiency of code writing, especially when there are many candidate paths.
[0132] S130, in response to the first operation, generates the target path in the code editing window.
[0133] In this embodiment of the application, the generated target path includes all nodes and necessary symbols in the target path, so that the generated target path conforms to the basic syntax specifications of the format corresponding to the file to be written.
[0134] For example, when writing a JSON format file, the target path generated using the code editing method provided in this application should conform to the basic syntax specifications of JSON. Assuming the target path is "a>b1>c1", and the file to be written in the current code editing window is empty, the final generated target path will be:
[0135]
[0136] Optionally, in some embodiments, the necessary symbol can be determined based on the data type of the node. That is, the necessary symbol corresponds to the data type of the node. For example, assuming the target path is "a>b1>c1", and the data type of "c1" is an array, and the file to be written in the code editing window is empty, the final generated target path is:
[0137]
[0138]
[0139] In some embodiments, when a user's first action is detected, the target path is generated in the code editing window, starting from the location node in the code editing window.
[0140] That is, when executing the code editing method provided in this application, the nodes in the target path are generated starting from the locating node.
[0141] It should be understood that when the cursor is at the terminal node of a path, generating the target path in the code editing window directly replaces the positioning node in the code editing window with the target path. Alternatively, the positioning node in the code editing window can be deleted before generating the target path. Or, based on the target path and the positioning node in the code editing window, the missing path between them can be determined, and the missing path can be generated.
[0142] Alternatively, when the locator node has one or more configured descendant nodes, generating the target path in the code editing window directly replaces the locator node and its descendant nodes in the code editing window with the target path. Alternatively, deleting the locator node and its descendant nodes in the code editing window and then generating the target path. Alternatively, determining the missing path between the target path and the locator node and its descendant nodes in the code editing window, and generating the missing path.
[0143] In this embodiment, a list of suggested paths can be provided to the user based on the content in the code editing window, allowing the user to select a path for completion. This allows the user to complete multiple nodes with a single completion operation, such as completing all nodes on a path, which helps improve the user's development efficiency and experience.
[0144] Figure 2 This is a schematic flowchart illustrating another method for editing code provided in an embodiment of this application. Figure 2 The method shown includes steps S210 to S250, which are described below.
[0145] S210, parse the description file and obtain the first set of paths corresponding to the description file.
[0146] This application embodiment can obtain all nodes in the description file and the paths between nodes by parsing the description file. This application does not limit the method of parsing the description file; for example, it can parse the description file using a depth-first traversal.
[0147] Optionally, in some embodiments, in S210, the description file may not be parsed. Instead, the description file may be parsed by an external parsing tool before S210 is executed, and the first path set corresponding to the description file may be obtained and then the first path set may be imported into the code editor.
[0148] In this way, by directly obtaining the first set of paths corresponding to the description file, instead of importing the complete description file, the process of loading and parsing the description file is avoided, reducing resource overhead and lowering the burden on memory and computing power.
[0149] It should be understood that the first set of paths corresponding to the description file includes all nodes in the description file and the paths between nodes. That is, the first set of paths includes at least one or more paths, and each of the first or more paths includes one or more nodes.
[0150] Optionally, the first path set can be a tree structure, a multi-level directory structure, or a set stored in the form of nodes and paths.
[0151] In this embodiment of the application, a node can be understood as a single syntactic unit in a description file or a file to be written, for example... Figure 3 In the description file shown, "a", "b1", "c1", and "d1" all belong to nodes. The description file also contains predefined keywords such as "type", "properties", "string", and "array", which only indicate the data type or assignment range of the nodes. These keywords are not nodes that need to be edited in the method provided in this application. After the above nodes are defined in the description file, the file to be written based on the description file will also include these nodes. Generally, those skilled in the art can determine whether a syntactic unit is a node by reading the structure of the code file.
[0152] Optionally, the first path set may also include the data type of the nodes described in the file definition.
[0153] For example, Figure 3 A schematic diagram of a description document provided in an embodiment of the application is shown. For example... Figure 3 As shown, the description file defines JSON objects "a", "b1", and "c1", and strings "b2", "c2", "d1", and "d2", which are then parsed. Figure 3 The description file shown can be used to obtain the first set of paths corresponding to the description file.
[0154] For ease of understanding, Figure 4 It shows Figure 3 The diagram shows a tree structure corresponding to the description file. For example... Figure 4 As shown, the description file contains a subtree with "a" as the root node, "a" as the parent node of "b1" and "b2", "b1" as the parent node of "c1" and "c2", and "c1" as the parent node of "d1" and "d2". That is, "b1" and "b2" are children of "a", "c1" and "c2" are children of "b1", and "d1" and "d2" are children of "c1". "d1", "d2", "c2", and "b2" are leaf nodes.
[0155] It should be noted that, Figure 3 The description file and Figure 4 The tree structure shown is merely an example and should not impose any limitations on the description file or the first set of paths. For example, the description file may also include other parallel subtrees, such as other subtrees rooted at the sibling node of "a".
[0156] It should be noted that in this embodiment of the application, parsing the description file, obtaining the description file, or obtaining the first path set corresponding to the description file are all completed before step S220.
[0157] S220, detects the user's second action, which is used to trigger the code completion function.
[0158] The second operation can be any of the following: entering characters, entering commands, entering shortcut keys, entering shortcut key combinations, or clicking a menu. The entered characters can be letters or symbols. The second operation can also be other types of user-defined or program-predefined operations, which are not limited in this application. For example, the user can enter double quotes, single quotes, or simultaneously press the Ctrl and Shift keys.
[0159] It should be understood that when the user's second action is detected, step S230 and subsequent steps are executed.
[0160] S230, determine at least one candidate path from the first path set corresponding to the description file based on at least one node in the code editing window.
[0161] It should be noted that users can enter characters in the code editor window to write the code for the file to be written, or they can generate the code for the file to be written in the code editor window using code completion technology. In other words, the code editor window is used to write the code for the file to be written. The nodes in the code editor window are either the file to be written or pre-configured nodes within the code editor window.
[0162] In this embodiment of the application, the user is writing code for a file to be written in the code editing window based on the description file. The nodes, paths between nodes, relative positions of nodes, and data types of nodes in the file to be written should all be consistent with those defined in the description file, so that the file to be written and the description file conform to the same syntax structure.
[0163] For example, suppose the user based on Figure 3 When writing a file based on the description file shown, the nodes in the file to be written must be one of "a", "b1", "b2", "c1", "c2", "d1", and "d2", and the relative positions of the nodes in the file to be written should be consistent with their relative positions in the description file. That is, if "c1" exists in the file to be written, then "c1" must have a parent node "b1", and "b1" must have a parent node "a". However, the file to be written can contain "d1", "d2", "c2", and "b2", or it can contain none of the above nodes.
[0164] When a node in the file to be written does not exist in the description file, that node and its descendant nodes will be considered invalid nodes, and any path starting from that node will be considered invalid. Of course, it's possible that some fields in the file to be written may not conform to the specifications defined in the description file due to human error or other factors. In such cases, existing technologies will typically display an error message indicating the non-compliant nodes in the file, allowing the user to make targeted modifications.
[0165] In some embodiments, at least one candidate path can be determined from the first path set corresponding to the description file based on the location node in the code editing window.
[0166] Specifically, iterate through the nodes in the first path set, query the nodes that match the location node in the code editing window, and identify them as candidate nodes. The candidate node should include the field corresponding to the location node.
[0167] For example, if the location node is "abc", the node "dabc" matches the location node, while the node "adbc" does not match the location node. Finally, enumerate the paths in the first path set that start with the candidate node and determine them as candidate paths.
[0168] The candidate paths determined in this way only include the fields corresponding to the location nodes in their starting nodes. The relative position of the starting node in the description file and the relative position of the location node in the file to be written can be the same or different. Therefore, the range and number of candidate paths determined are relatively large.
[0169] In some embodiments, at least one candidate path may be determined from the first path set corresponding to the description file based on the location node and its parent node.
[0170] Specifically, iterate through the nodes in the first path set, query the first node that has the same field as the parent node of the positioning node, then iterate through the child nodes of the first node, query the child nodes of the first node that include the field corresponding to the positioning node, and determine them as candidate nodes. Finally, enumerate the paths in the first path set that start from the candidate node and determine them as candidate paths.
[0171] The candidate paths determined in this way not only include the fields corresponding to the location nodes in their starting nodes, but also have the same fields as the parent nodes of the location nodes, which greatly improves the accuracy of the candidate paths.
[0172] In some embodiments, at least one candidate path can be determined from the first path set corresponding to the description file based on the location node and all nodes between the location node's parent node and the root node.
[0173] Specifically, based on the path from the root node of the positioning node to its parent node, a first path identical to the one in the first path set is determined. Nodes whose child nodes of the terminal node of the first path include the field corresponding to the positioning node are obtained and identified as candidate nodes. Finally, paths in the first path set that start from the candidate node are enumerated and identified as candidate paths.
[0174] It should be understood that the path from the root node of the positioning node to the parent node of the positioning node includes all nodes from the parent node to the root node of the positioning node.
[0175] Alternatively, based on all nodes from the parent node to the root node of the current location node, determine the corresponding node in the first path set layer by layer, starting from the root node. For example, first determine the node corresponding to the root node in the first path set, then determine the nodes corresponding to the child nodes of the root node in the first path set, and finally determine the second node corresponding to the parent node of the current location node in the first path set. Traverse the child nodes of this second node, querying for nodes whose child nodes include the field corresponding to the current location node, and determine them as candidate nodes. Finally, enumerate the paths in the first path set that start from this candidate node and determine them as candidate paths.
[0176] The candidate paths determined in this way not only include the fields corresponding to the locating node in their starting node, but also have the same relative position in the description file as the relative position of the locating node in the file to be written, thus greatly improving the accuracy of the determined candidate paths.
[0177] In some embodiments, when the location node is empty, or when the location node is a symbol, at least one candidate path is determined from the first path set corresponding to the description file based on the parent node of the location node.
[0178] Specifically, iterate through the nodes in the first path set, query the first node that has the same field as the parent node of the located node, and determine at least one candidate path from the first path set, using each child node of the first node as the starting node.
[0179] In some embodiments, when the location node is empty, or when the location node is a symbol, at least one candidate path is determined from the first path set corresponding to the description file based on all nodes between the parent node and the root node of the location node.
[0180] Specifically, based on the path from the root node of the positioning node to its parent node, a first path identical to that path is determined in the first path set. Then, taking each child node of the terminal node of the first path as the starting node, at least one candidate path is determined from the first path set.
[0181] In some embodiments, when the file to be written in the code editing window is empty, i.e., when there is no node in the code editing window, at least one candidate path is determined from the first path set, starting from the root node of the subtree in the first path set. For example, assume the tree structure corresponding to the description file is referenced... Figure 4 When no node exists in the code editing window, starting from the root node "a" of the subtree, candidate paths such as "a>b2", "a>b1>c2", and "a>b1>c1>d1" can be determined.
[0182] In this embodiment, the location node may not conform to the specifications defined in the description file, and no matching node can be found in the description file. Therefore, the number of candidate nodes can be zero, or the number of candidate nodes can be one or more. One candidate node can correspond to one or more candidate paths, that is, the number of candidate paths can be zero, or the number of candidate paths can be one or more.
[0183] In some embodiments, the start node of each candidate path in the at least one candidate path corresponds to a positioning node in the code editing window, and the start node includes the field corresponding to the positioning node.
[0184] It should be understood that when a user enters characters at the cursor position in the code editing window, the field corresponding to the positioning node updates in real time as the user inputs. Therefore, candidate nodes also update as the field corresponding to the positioning node updates. In other words, the candidate paths displayed in the code completion window update in real time as the user enters characters in the code editing window.
[0185] In some embodiments, the field corresponding to the location node is the prefix of the starting node of each candidate path, that is, the prefix of the candidate node should be the same as the field corresponding to the location node.
[0186] To facilitate understanding, a specific example will be used below. For instance, suppose the tree structure of the first set of paths corresponding to the description file is as follows:
[0187]
[0188] The child nodes of "code" are "completion" and "helps". The child nodes of "completion" are "you", "yourself", and "complete". The child node of "helps" is "tips". The child node of "you" is "select". The child node of "yourself" is "service". The child node of "complete" is "classes". The child node of "select" is "path". Among them, "path", "service", "classes", and "tips" are leaf nodes.
[0189] Assume the file to be written in the code editor window is as follows:
[0190]
[0191]
[0192] Here, "|" represents the cursor, i.e., the positioning node is "yo". The path from the parent node of this positioning node to the root node of this positioning node is "code>completion". The first path corresponding to "code>completion" in the first path set is determined. The child nodes of the terminal node of this first path are "you", "yourself", and "complete". The prefixes of the nodes "you" and "yourself" are the same as the field "yo" corresponding to this positioning node. The nodes "you" and "yourself" can be determined as candidate nodes. The paths in the first path set that start with "you" and "yourself" are enumerated respectively, and then "you>select", "you>select>path", and "yourself>service" are determined as candidate paths.
[0193] In some embodiments, the candidate path starts with a candidate node in the first path set and terminates with a leaf node in the first path set. It should be understood that the termination node is the endpoint of the candidate path.
[0194] For example, as shown in the example above, nodes "you" and "yourself" can be identified as candidate nodes. By enumerating the paths in the first path set that start with "you" and "yourself" and end with leaf nodes, "you>select>path" and "yourself>service" can be identified as candidate paths.
[0195] S240 displays at least one candidate path in the first window so that the user can determine the target path from it.
[0196] This step and Figure 1 Step S110 is similar; for details not described in detail below, please refer to the relevant description of step S10. For ease of understanding, specific examples are provided here.
[0197] For example, Figure 5 A schematic diagram of a code editor interface provided in an embodiment of this application is shown. Figure 5 As shown, the code editor interface includes a code editing window 510 and a first window 520. Users can manually write the file to be written in the code editing window 510, or automatically generate the code to be completed using code completion technology. The first window 520 includes candidate paths, whose names are displayed as parent node 1 (+) > parent node 2 (+) > parent node 3 (+) > ... > leaf node (+). The "+" sign in the name indicates the node to be automatically inserted, and the closing bracket ">" in the name is used to separate the nodes in the candidate path.
[0198] In some embodiments, a third operation by the user on the first window is detected, and in response to the third operation, the candidate paths are filtered to obtain one or more filtered candidate paths, which are then displayed in the first window.
[0199] Optionally, the third operation can be the user entering characters in the first window.
[0200] For example, suppose that candidate paths "you>select", "you>select>path" and "yourself>service" have been obtained in step S230. For instance, if the user enters the letter "s", "s" is found in all candidate paths "you>select", "you>select>path" and "yourself>service". The code completion window can display all candidate paths. Suppose the user enters the letter "el" again. This time the search sequence is "sel". Since the sequence "sel" does not appear in "yourself>service", "yourself>service" is filtered out. The filtered candidate paths are "you>select" and "you>select>path". The code completion window displays two paths, "you>select" and "you>select>path", for the user to choose from.
[0201] S250, starting from the location node, generate the target path in the code editing window.
[0202] Step S250 is similar to step S130. For details, please refer to the relevant description of step S130. For the sake of brevity, it will not be repeated here.
[0203] Figure 6 A schematic flowchart illustrating a method for editing code according to an embodiment of this application is shown. Figure 6 The method shown includes steps S610 to S630, and each step is described below.
[0204] S610, a second window is displayed in the code editing window. The second window includes multiple nodes, which are used to indicate the first set of paths corresponding to the description file.
[0205] It should be understood that the first set of paths corresponding to the description file includes all nodes in the description file and the paths between nodes. That is, the first set of paths includes at least one or more paths, and each of these first or more paths includes one or more nodes.
[0206] It should be understood that these multiple nodes correspond to the first path set, so the second window can display the connection relationship between these multiple nodes or their relative positional relationship in the first path set.
[0207] Optionally, the first path set may also include the data type of the nodes described in the file definition.
[0208] In some embodiments, multiple nodes are arranged into a tree structure or a multi-level directory structure, where the multiple nodes are nodes in a first path set. That is, multiple nodes in the first path set are arranged into a tree structure or a multi-level directory structure.
[0209] This allows for a clear and intuitive display of multiple nodes in the first path set, making it easy for users to select the target node they need to configure.
[0210] In this embodiment of the application, the code editing window is a window used by the user to write the code of the file to be written. The nodes in the code editing window are the configured nodes of the file to be written, and these configured nodes are recorded as the first node set; the nodes that do not exist in the code editing window but exist in the first path set are unconfigured nodes, and these unconfigured nodes are recorded as the second node set.
[0211] In some embodiments, the plurality of nodes includes a first node set and a second node set, wherein the nodes in the first node set are nodes configured in the code editing window, and the nodes in the second node set are nodes not configured in the code editing window.
[0212] In some embodiments, the second window includes a first identifier, which is used to indicate nodes that are not configured in the code editing window, i.e., the first identifier is used to indicate nodes in the second node set.
[0213] In this way, the first identifier can intuitively indicate to the user which nodes have been configured and which nodes have not been configured, which helps to improve writing efficiency.
[0214] In some embodiments, the second window includes a second identifier that indicates the type of each of the plurality of nodes.
[0215] In this way, the second identifier can represent the type of each node, making it easier for users to select the type of node that needs to be configured.
[0216] In some embodiments, the second window includes a first control for showing or hiding nodes in the second node set.
[0217] In this way, users can choose to hide or show unconfigured nodes as needed, and quickly bring up a second window for editing when code editing is required.
[0218] In some embodiments, a fifth user action is detected, and in response to the fifth action, a second window is displayed or hidden.
[0219] Optionally, the fifth operation can be any one of the following: entering a command, entering a shortcut key, entering a combination of shortcut keys, or clicking a menu.
[0220] S620, detect the user's fourth operation on the second window, the fourth operation being used to determine the target node from the plurality of nodes.
[0221] The fourth operation can be the selection and confirmation of a node among the multiple nodes. The fourth operation can be the user confirming the target node by clicking with the mouse, or the user selecting and confirming the target node by the keyboard. This application does not limit the specific operation.
[0222] Users can determine the target node by first selecting one or more nodes, and then designating those nodes as the target node.
[0223] Optionally, the target node can be one or more.
[0224] S630, in response to the fourth operation, generates a target path in the code editing window, wherein the terminal node of the target path is the target node, and the nodes included in the target path are nodes not configured in the code editing window.
[0225] Generating the target path in the code editing window is similar to step S130. For details, please refer to the relevant description of step S130. For the sake of brevity, it will not be repeated here.
[0226] It should be understood that the target path should include one or more nodes that are not configured in the code editing window.
[0227] It is worth noting that, optionally, when the user determines multiple target nodes, multiple target paths are generated in the code editing window. These multiple target paths are paths with each of the multiple target nodes as the terminal node, and the nodes included in the target paths belong to nodes not configured in the code editing window.
[0228] In some embodiments, the target path includes all unconfigured nodes in the path from the root node to the target node.
[0229] In this embodiment, the second window can display all editable nodes, i.e., unconfigured nodes. When the user selects a target node, a path with the target node as the terminal node can be generated. In this way, the user can intuitively see the unconfigured nodes in the file to be written, and can generate the target path from the locating node to the target node in one go, improving the efficiency and quality of the user's code writing, saving time and effort, and enhancing the user experience.
[0230] Figure 7 A schematic flowchart of another method for editing code provided in an embodiment of this application is shown. Figure 7 The method shown includes steps S710 to S130, and each step is described below.
[0231] S710, parse the description file and obtain the first path set corresponding to the description file.
[0232] Steps S710 and S210 are the same, and for the sake of brevity, they will not be described again here.
[0233] S720 parses the file to be written in the code editor window and obtains the nodes configured in the code editor window.
[0234] Similar to the process of parsing a description file, embodiments of this application can obtain all nodes in the code editing window and the paths between nodes by parsing the file to be written in the code editing window. This application does not limit the method of parsing the file to be written in the code editing window; for example, it can be parsed using a depth-first traversal.
[0235] It should be noted that users can enter characters in the code editing window to write the code for the file to be written, or they can generate the code for the file to be written in the code editing window through code completion technology. That is, the code editing window is used to write the code for the file to be written, and the nodes in the code editing window are the file to be written or the nodes already configured in the code editing window.
[0236] In this embodiment of the application, the user is writing a file to be written based on the description file. During the writing process, the file to be written should always meet the specifications defined by the description file. That is, the nodes in the file to be written, the paths between nodes, the relative positions of nodes, and the data types of nodes should all be consistent with those described in the description file, so that the file to be written and the description file conform to the same syntax structure.
[0237] S730 determines the configurable structured view based on the nodes in the first path set and the nodes configured in the code editing window.
[0238] It should be understood that, in this embodiment of the application, the configurable structured view is equivalent to the second window in step S610.
[0239] Specifically, the configurable structured view presents multiple nodes in the first path set in the form of a tree structure or a multi-level directory structure, and uses a first identifier to indicate nodes that are not configured in the code editing window.
[0240] It should be understood that the configurable structured view includes not only the nodes configured in the code editing window, but also the nodes that are not configured relative to the first path set, i.e., the nodes not configured in the file to be written. The configured nodes in the file to be written are denoted as the first node set, and the unconfigured nodes are denoted as the second node set. In other words, the configurable node-based view includes both the first and second node sets.
[0241] It should be understood that the unconfigured node is a descendant node, sibling node, or descendant node of a sibling node of the node corresponding to the configured node in the first path set.
[0242] For example, Figure 8 A schematic diagram of a code editor interface provided in an embodiment of this application is shown. Figure 8 As shown, the code editor interface in this embodiment includes a code editing window 510, a configurable structured view 810, and a configurable structured view switch 820.
[0243] The configurable structured view switch 820 can be an example of a first control that can be used to show or hide nodes in a second set of nodes.
[0244] In some embodiments, the configurable structured view can be integrated into an existing structured view, and the display or hiding of nodes in the second node set can be controlled by adding a first control to the existing structured view. Alternatively, after opening an existing structured view, the nodes in the second node set can be displayed or hidden by entering a command, entering a shortcut key, entering a combination of shortcut keys, or clicking a menu.
[0245] Optionally, in some embodiments, the configurable structured view can also be a separate function alongside the existing structured view, which can be independently activated by entering commands, entering shortcut keys, entering shortcut key combinations, or clicking a menu.
[0246] In some embodiments, a first identifier is used to indicate nodes in the second path set that do not exist relative to the first path set. For example, refer to... Figure 8 In a configurable structured view, use the "+" symbol to indicate nodes that are not configured in the file to be written.
[0247] In some embodiments, in a configurable structured view, a second identifier is used to indicate the type of nodes in the configurable structured view. For example, refer to... Figure 8 The identifier "{}" indicates that the node is a JSON object. This indicates that the node is a JSON attribute.
[0248] In some embodiments, the configurable structured view includes a third identifier that indicates a node has child nodes. Clicking the third identifier can show or hide the child nodes of a node in the configurable structured view. For example, refer to... Figure 8 The symbol “ˇ” indicates that a node has child nodes, and the child nodes can be collapsed or expanded by clicking “ˇ”.
[0249] S740 detects the user's fourth operation on the configurable structured view and determines the target node from the configurable structured view.
[0250] Step S740 is similar to step S620. For details, please refer to the relevant description of step S620. For the sake of brevity, it will not be repeated here.
[0251] S750 determines the target path based on the path from the root node to the target node and the nodes configured in the code editing window.
[0252] In this embodiment, the path from the root node to the target node is uniquely determined within the first path set. That is, once the target node is determined, a path from the root node to the target node can be determined from the first path set. Within this path, some nodes are configured in the code editing window, and some are not. Removing the configured nodes from the code editing window yields the target path. At this point, the target path includes all unconfigured nodes from the root node to the target node.
[0253] The nodes configured in the code editing window may be nodes outside the path between the root node and the target node. For example, see the reference. Figure 4 Suppose the user determines the target node as "d2". The path from the root node to the target node is "a>b1>c1>d2". However, in this case, the code editor window may contain the path "a>b1>c1>d1", meaning "d1" is a node outside the path from the root node to the target node. In this situation, it is not necessary to remove the configured nodes outside the path from the root node to the target node.
[0254] The root node can be the description file or the file to be written itself, or it can be the root node of the subtree containing the target node. The difference between these two does not affect the determination of the target path. For example, Figure 3 The description file shown contains only one subtree. Assuming the description file itself or the file to be written is considered the root node, denoted as `root`, the path "a>b1" in the code editor window should actually be represented as "root>a>b1". When the user determines the target node as "d2", the path from the root node to the target node in the first path set is "root>a>b1>c1>d2". Removing the configured nodes in the code editor window yields the target path "c1>d2". In other words, when the description file itself or the file to be written is considered the root node, this root node can be considered a configured node.
[0255] S760, generate the target path in the code editing window.
[0256] In this embodiment, the generated target path includes all nodes and necessary symbols in the target path, ensuring that the generated target path conforms to the basic syntax specifications of the file to be written. For example, when writing a JSON format file, the generated target path should conform to the basic syntax specifications of JSON.
[0257] For example, after the user selects the target nodes "d2+" and "b2+" and executes step S770, the final code in the code editing window is as follows:
[0258]
[0259] Optionally, in some embodiments, the necessary symbol corresponds to the data type of the node. For example, if the node is an array, the symbol corresponding to the node is [].
[0260] The above text combined Figures 1 to 8 The method embodiments of this application are described in detail below, in conjunction with... Figures 9 to 11 This application provides a detailed description of the apparatus embodiments. It should be understood that the descriptions of the method embodiments correspond to the descriptions of the apparatus embodiments; therefore, any parts not described in detail can be found in the preceding method embodiments.
[0261] Figure 9 A schematic block diagram of an apparatus for editing code, according to an embodiment of this application, is shown. This apparatus can be used to perform actions such as... Figure 1 or Figure 2 The method shown, and the execution as follows Figure 5 The example shown. Figure 9 As shown, the device 900 includes a display unit 901, a detection unit 902, and a generation unit 903.
[0262] Display unit 901 is used to display a first window in a code editing window, the first window including at least one candidate path, each candidate path including one or more nodes.
[0263] The detection unit 902 is used to detect a user’s first operation on the first window, the first operation being used to determine a target path from the at least one candidate path.
[0264] Generation unit 903 is used to generate the target path in the code editing window in response to the first operation.
[0265] The code editing apparatus of this application embodiment can complete multiple nodes at once, such as completing all nodes on a path at once, avoiding the need for users to edit code multiple times in different locations, improving the efficiency and quality of code editing, saving time and effort, and enhancing the user experience.
[0266] Optionally, the detection unit 902 is further configured to detect a second operation by the user; the display unit 901 is further configured to display a first window in the code editing window in response to the second operation.
[0267] Optionally, the second operation can be any of the following: entering characters, entering commands, entering shortcut keys, entering shortcut key combinations, or clicking a menu.
[0268] Optionally, the generation unit 903 is specifically used to generate the target path in the code editing window, starting from the positioning node in the code editing window.
[0269] Optionally, the starting node of each candidate path in the at least one candidate path includes the field corresponding to the positioning node.
[0270] Optionally, the field corresponding to the location node is the prefix of the starting node of each candidate path.
[0271] Optionally, the device 900 may further include a determining unit.
[0272] The detection unit is also used to detect a third operation by the user on the first window, which is an operation of inputting characters;
[0273] The determining unit is used to filter the at least one candidate path in response to a third operation by the user on the first window, to obtain one or more filtered candidate paths, wherein each of the one or more filtered candidate paths includes characters entered by the user.
[0274] The display unit 901 is also used to display the filtered candidate paths in the first window.
[0275] Optionally, the determining unit is further configured to determine the at least one candidate path from the first path set corresponding to the description file based on at least one node in the code editing window, wherein the code editing window is used to write the code of the file to be written, and the file to be written conforms to the same syntax structure as the description file.
[0276] Optionally, the determining unit can also be specifically used for:
[0277] Based on at least one node, at least one candidate node is determined from a first path set, wherein each candidate node in the at least one candidate node includes a field corresponding to the location node;
[0278] Using each candidate node from at least one candidate node as the starting node, determine at least one candidate path from the first path set.
[0279] Optionally, the determining unit is specifically used for:
[0280] Based on the parent node of the location node, determine the first node from the first path set, where the first node has the same field as the parent node of the location node;
[0281] Based on the fields corresponding to the location node, at least one candidate node is determined from the child nodes of the first node.
[0282] Optionally, the determining unit may also be specifically used to determine a first path from a first path set based on the path from the root node of the positioning node to the parent node of the positioning node, wherein the first path is the same as the path from the root node of the positioning node to the parent node of the positioning node.
[0283] Based on the fields corresponding to the location node, at least one candidate node is determined from the child nodes of the terminal node of the first path.
[0284] Optionally, the determining unit can also be specifically used for:
[0285] Based on the parent node of the location node, determine the first node from the first path set, where the first node has the same field as the parent node of the location node;
[0286] The determining unit can also be specifically used to determine at least one candidate path from the first path set, starting from each child node of the first node.
[0287] This application also provides another code editing device, the schematic block diagram of which is still referred to for simplicity. Figure 9 This device can be used to perform actions such as Figure 6 or Figure 7 The method shown, and the execution as follows Figure 8 The example shown. Figure 9 As shown, the device 900 includes a display unit 901, a detection unit 902, and a generation unit 903.
[0288] Display unit 901 is used to display a second window in the code editing window. The second window includes multiple nodes, which are used to indicate the first path set corresponding to the description file.
[0289] The detection unit 902 is used to detect the user's fourth operation on the second window, which is used to determine the target node from multiple nodes.
[0290] The generation unit 903 is configured to generate a target path in the code editing window in response to the fourth operation, wherein the terminal node of the target path is the target node, and the nodes included in the target path are nodes not configured in the code editing window.
[0291] The code editing apparatus of this application embodiment, by displaying a configurable structured view in a second window, allows the user to generate all unconfigured nodes in the target path with the target node as the terminal node at once after the user determines the target node, thereby improving the efficiency and quality of code writing and enhancing the user experience.
[0292] Optionally, the device 900 may further include a determining unit, the determining unit being used for
[0293] Determine the path from the root node to the target node from the first path set;
[0294] Determine the target path based on the path from the root node to the target node and the nodes configured in the code editing window.
[0295] Optionally, the multiple nodes can be arranged in a tree structure or a multi-level directory structure.
[0296] Optionally, the plurality of nodes includes a first node set and a second node set, wherein the nodes in the first node set are nodes that have been configured in the code editing window, and the nodes in the second node set are nodes that have not been configured in the code editing window.
[0297] Optionally, the second window includes a first identifier, which is used to indicate a node in the second node set.
[0298] Optionally, the second window includes a second identifier that indicates the type of each of the multiple nodes.
[0299] Optionally, the second window includes a first control for showing or hiding nodes in the second node set.
[0300] Figure 10 A schematic block diagram of a code editing apparatus provided in an embodiment of this application is shown. Figure 10 As shown, the code editing device includes a code editing window 1001, a code completion window 1002, a path calculation module 1004, a code generation module 1005, and a file loading module 1007.
[0301] The code editing window 1001 can be used for users to manually write the code for the file to be written, or the code can be automatically generated in the code editing window 1002 using code completion.
[0302] Code completion window 1002 is equivalent to Figure 1 or Figure 2 The first window in the method shown, code completion window 1002, is used to display... Figure 1 or Figure 2 The content displayed in the first window in the illustrated embodiment.
[0303] Path calculation module 1004 is used to execute Figure 2 Step S230 in the method shown or used for execution Figure 7 Step S760 in the method shown.
[0304] The file loading module 1007 can be used to retrieve the configured nodes of the file to be written in the code editing window. For example, in Figure 2Before step S230 in the illustrated embodiment, the file loading module 1007 parses the file to be written and obtains at least one node in the code editing window.
[0305] Optionally, the device 1000 may further include a description file parsing module 1006, which can be used to perform... Figure 2 Step S210 in the illustrated embodiment, or execution Figure 7 Step S710 in the illustrated embodiment.
[0306] Optionally, the device 1000 may further include a configurable structured view 1003, which is equivalent to a configurable structured view window. Figure 6 The second window in the method shown Figure 7 The configurable structured view in the method shown.
[0307] It should be understood that the device 1000 may include a code completion window 1002, a configurable structured view 1003, or both a code completion window 1002 and a configurable structured view 1003.
[0308] It is worth noting that, Figure 10 This is merely a schematic block diagram of a code editing device provided in an embodiment of this application. The positional relationships between the devices, components, modules, etc., shown in the diagram do not constitute any limitation. For example, in Figure 10 In this context, the parsing module can be an external parsing tool.
[0309] Figure 11 This is a schematic diagram of the hardware structure of the code editing device provided in the embodiments of this application. Figure 11 The illustrated code editing device 1100 (which may specifically be a computer device) includes a memory 1110, a processor 1120, a communication interface 1130, and a bus 1140. The memory 1110, processor 1120, and communication interface 1130 are interconnected via the bus 1140.
[0310] The memory 1110 may be a ROM, a static storage device, a dynamic storage device, or RAM. The memory 1110 may store a program, and when the program stored in the memory 1110 is executed by the processor 1120, the processor 1120 is used to execute the various steps of the method for editing code according to the embodiments of this application.
[0311] The processor 1120 may be a general-purpose CPU, microprocessor, ASIC, GPU, or one or more integrated circuits, used to execute relevant programs to achieve the functions required by the units in the code editing apparatus of this application embodiment, or to execute the code editing method of this application embodiment.
[0312] The processor 1120 can also be an integrated circuit chip with signal processing capabilities. During implementation, each step of the code editing method of this application can be completed by the integrated logic circuitry in the hardware of the processor 1120 or by instructions in software form. The processor 1120 can also be a general-purpose processor, DSP, ASIC, FPGA, or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory 1110. The processor 1120 reads the information in memory 1110 and, in conjunction with its hardware, completes the functions required by the units included in the code editing apparatus of the embodiments of this application, or executes the code editing method of the method embodiments of this application.
[0313] The communication interface 1130 uses a transceiver device, such as, but not limited to, a transceiver, to enable communication between the device 1100 and other devices or communication networks. For example, a description file or a first set of paths corresponding to the description file can be obtained through the communication interface 1130.
[0314] Bus 1140 may include a pathway for transmitting information between various components of device 1100 (e.g., memory 1110, processor 1120, communication interface 1130).
[0315] It should be noted that, although Figure 11 The illustrated device 1100 only shows the memory, processor, and communication interface. However, those skilled in the art should understand that in specific implementations, device 1100 may also include other devices necessary for normal operation. Furthermore, depending on specific needs, those skilled in the art should understand that device 1100 may also include hardware devices for implementing other additional functions. Moreover, those skilled in the art should understand that device 1100 may only include the devices necessary for implementing the embodiments of this application, and may not necessarily include... Figure 11 All the devices shown.
[0316] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0317] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0318] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0319] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0320] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0321] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0322] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for editing code, characterized in that, include: Before the first window is displayed in the code editing window, at least one candidate path is determined from the first path set corresponding to the description file based on at least one node in the code editing window. Each candidate path in the at least one candidate path includes one or more nodes, and each candidate path in the at least one candidate path takes a leaf node in the first path set as its terminal node. The code editing window is used to write the code of the file to be written, and the file to be written conforms to the same syntax structure as the description file. The first window is displayed in the code editing window, and the first window includes the at least one candidate path; Detect a user's first operation on the first window, the first operation being used to determine a target path from the at least one candidate path; In response to the first operation, the target path is generated in the code editing window; The node is a single syntactic unit in the description file or the file to be written; the path is an ordered, hierarchical sequence of nodes consisting of one or more of the nodes. The leaf node is a node that does not have any child nodes; The first path set includes all paths described in the description file, including both complete and incomplete paths.
2. The method according to claim 1, characterized in that, The method further includes: Detect the user's second action; The provision of displaying the first window in the code editing window includes: In response to the second operation, the first window is displayed in the code editing window.
3. The method according to claim 2, characterized in that, The second operation is any one of the following: entering characters, entering commands, entering shortcut keys, entering shortcut key combinations, and clicking the menu.
4. The method according to any one of claims 1 to 3, characterized in that, The code editing window includes a positioning node; Generating the target path in the code editing window includes: Starting from the location node, the target path is generated in the code editing window.
5. The method according to claim 4, characterized in that, The starting node of each of the at least one candidate paths includes the field corresponding to the positioning node.
6. The method according to claim 5, characterized in that, The field corresponding to the location node is the prefix of the starting node of each candidate path.
7. The method according to any one of claims 1 to 6, characterized in that, Before detecting the user's first operation on the first window, the method further includes: Detect the user's third operation on the first window, wherein the third operation is the operation of inputting characters; In response to the third operation, one or more filtered candidate paths are obtained by filtering the at least one candidate path, wherein each of the one or more filtered candidate paths includes characters input by the user. The filtered candidate paths are displayed in the first window.
8. The method according to claim 7, characterized in that, The code editing window includes a positioning node; The step of determining the at least one candidate path from the first path set corresponding to the description file based on at least one node in the code editing window includes: Based on the at least one node, at least one candidate node is determined from the first path set, wherein each candidate node includes a field corresponding to the location node; Using each of the at least one candidate node as a starting node, determine the at least one candidate path from the first path set.
9. The method according to claim 8, characterized in that, The at least one node includes the positioning node and the parent node of the positioning node; The step of determining at least one candidate node from the first path set based on the at least one node includes: Based on the parent node of the location node, a first node is determined from the first path set, wherein the first node has the same field as the parent node of the location node; Based on the fields corresponding to the positioning node, at least one candidate node is determined from the child nodes of the first node.
10. The method according to claim 8, characterized in that, The at least one node includes all nodes from the positioning node to the root node of the positioning node; The step of determining at least one candidate node from the first path set based on the at least one node includes: Based on the path from the root node of the positioning node to the parent node of the positioning node, a first path is determined from the first path set, and the first path is the same as the path from the root node of the positioning node to the parent node of the positioning node. Based on the fields corresponding to the positioning node, at least one candidate node is determined from the child nodes of the terminal node of the first path.
11. The method according to claim 7, characterized in that, The code editing window includes a positioning node, and the positioning node is empty; The step of determining the at least one candidate path from the first path set corresponding to the description file based on at least one node in the code editing window includes: Based on the parent node of the location node, a first node is determined from the first path set, wherein the first node has the same field as the parent node of the location node; Using each child node of the first node as a starting node, determine the at least one candidate path from the first path set.
12. A method for editing code, characterized in that, include: A second window is displayed in the code editing window, which is used to show multiple nodes in the first path set corresponding to the description file; The plurality of nodes includes a first node set and a second node set. The nodes in the first node set are the nodes configured in the code editing window, and the nodes in the second node set are the nodes outside the code editing window that belong to the first path set. The second window includes a first identifier, which indicates a node in the second node set, wherein the node is a single syntactic unit in the description file or the file to be written; the path is an ordered, hierarchical sequence of nodes consisting of one or more of the nodes. Detect a fourth operation by the user on the second window, the fourth operation being used to determine a target node from the plurality of nodes; In response to the fourth operation, a path from the root node to the target node is determined from the first path set; a target path is determined based on the path from the root node to the target node and the nodes configured in the code editing window, wherein the terminal node of the target path is the target node, and the nodes included in the target path belong to nodes not configured in the code editing window.
13. The method according to claim 12, characterized in that, The multiple nodes are arranged in a tree structure or a multi-level directory structure.
14. The method according to claim 13, characterized in that, The second window includes a second identifier, which indicates the type of each of the plurality of nodes.
15. The method according to claim 14, characterized in that, The second window includes a first control, which is used to show or hide nodes in the second node set.
16. An apparatus for editing code, characterized in that, include: Memory, used to store computer programs; A processor for executing a computer program stored in the memory, causing the apparatus to perform the method as described in any one of claims 1 to 15.
17. The apparatus according to claim 16, characterized in that, The device is a code editor.
18. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1 to 15.
Citation Information
Patent Citations
Code completion method, device and equipment and storage medium
CN109683907A
Mechanisms For Efficient Autocompletion In XML Search Applications
US20100191721A1
