Code generation method, device, equipment and medium

By using cursor information in the code generation tool to retrieve the index database to extract relevant code and associated information and input it into the target model, the problem of inaccurate code generation by existing tools is solved, and more efficient and accurate code generation is achieved.

CN119248239BActive Publication Date: 2025-05-16BEIJING QIHOOD TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411775470.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-05-16
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

Existing code generation tools are difficult to effectively utilize cursor information during the code writing process, resulting in inaccurate code generation and unable to meet the actual needs of developers.

Method used

By obtaining the cursor information in the editor, searching in the index database, extracting the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project, and inputting this information into the target big model to generate the target recommendation code information corresponding to the cursor position.

Benefits of technology

The efficiency of extracting the corresponding target-related code information and target-related information of cursor information is improved, ensuring the executability and effectiveness of the generated code in the target project, and improving the accuracy of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248239B_ABST
    Figure CN119248239B_ABST
Patent Text Reader

Abstract

The present application discloses a code generation method, device, equipment and medium. The method includes: obtaining cursor information in an editor, the cursor information includes the cursor position; searching in an index database according to the cursor information to obtain target-related code information in the current file where the cursor position is located and target-related information in other files of the target project where the cursor position is located, the index database includes target index data corresponding to each target file in the target project, the target index data is constructed based on target node information corresponding to the target file and target relationship information between each target node; inputting the cursor information, target-related code information and target-related information into a target macro model, generating target recommended code information, ensuring the integrity and accuracy of extracting information related to the cursor information in the target project, improving the extraction efficiency of target-related code information and target-related information corresponding to the cursor information, and the accuracy and effectiveness of code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code generation method, device, equipment and medium. Background Art

[0002] In the code development scenario, developers generally need to rely on the mouse and keyboard to write code during the code development process. The speed of code writing depends entirely on the software engineer's proficiency in the mouse and keyboard, and each operation is delayed, resulting in low interaction efficiency and code writing efficiency in the entire code development process.

[0003] In order to simplify the code development process, intelligent code completion and code generation tools are gradually being used to assist developers in code development. These tools usually use machine learning technology, especially natural language processing (NLP) models, to predict and recommend code snippets. However, in the process of model processing, there is often a lack of effective use of relevant codes, resulting in inaccurate generated codes and failure to provide effective code support for developers. Summary of the invention

[0004] The embodiments of the present application provide a code generation method, device, equipment and medium, which not only ensures the integrity and accuracy of the extraction of information related to cursor information in the target project, but also improves the extraction efficiency of target-related code information and target-related information corresponding to the cursor information. It can also improve the correlation between the code generation process using the target large model and the cursor information and the entire target project by inputting the target-related code information in the current file of the target project and the target-related information in other files, ensure the executability and effectiveness of the target recommended code information generated by the target large model in the target project, and improve the accuracy of code generation. The above technical solutions are as follows:

[0005] In a first aspect, an embodiment of the present application provides a code generation method, the method comprising:

[0006] Get the cursor information in the editor; the above cursor information includes the cursor position;

[0007] According to the cursor information, a search is performed in the index database to obtain target-related code information in the current file where the cursor is located and target-related information in other files of the target project where the cursor is located; the index database includes target index data corresponding to each target file in the target project; the target index data is constructed based on target node information of the target node corresponding to the target file and target relationship information between each target node;

[0008] The cursor information, the target-related code information and the target-related information are input into the target macro model to generate target recommended code information corresponding to the cursor position information.

[0009] In a possible implementation, the above-mentioned searching in the index database according to the above-mentioned cursor information to obtain the target-related code information in the current file where the above-mentioned cursor position is located and the target-related information in other files of the target project where the above-mentioned cursor position is located includes:

[0010] Searching in the index database according to the cursor position, obtaining the current file node information and the current function node information corresponding to the cursor position;

[0011] Searching the index database according to the current file node information to obtain other import information corresponding to the current file node information in other files of the target project;

[0012] Searching the index database according to the current function node information to obtain the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to the current function node information in the other files;

[0013] Determine the target-related code information in the current file where the cursor is located according to the current function node information and the current variable reference information;

[0014] The target association information in the other file where the cursor position is located is determined according to the other introduction information and the other variable reference information.

[0015] In a possible implementation, after searching in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor is located and the target-related information in other files of the target project where the cursor is located, the method further includes:

[0016] When the target-related code information and the target-associated information correspond to a total amount of target code that is less than or equal to a target threshold, searching the index database according to the current function node information to obtain function call relationship information corresponding to the current function node information;

[0017] Input the cursor information, the target-related code information, the target-related information and the function call relationship information into the target macro model to generate target recommended code information corresponding to the cursor position information;

[0018] In the case where the total amount of target codes corresponding to the above-mentioned target-related code information and the above-mentioned target association information is greater than the above-mentioned target threshold, the above-mentioned step of inputting the above-mentioned cursor information, the above-mentioned target-related code information and the target association information into the target macro model to generate the target recommended code information corresponding to the above-mentioned cursor position information is executed; the above-mentioned target threshold is less than the input length threshold of the above-mentioned target macro model.

[0019] In a possible implementation, the cursor information, the target-related code information, and the target-related information are input into the target macro model to generate target recommended code information corresponding to the cursor position information, including:

[0020] The above-mentioned cursor information, the above-mentioned target-related code information and the above-mentioned target-associated information are input into the target macro model, the type of code length to be recommended is determined according to the above-mentioned cursor position, and the target recommended code information corresponding to the above-mentioned cursor position information is generated according to the above-mentioned code length type to be recommended, the above-mentioned cursor information, the above-mentioned target-related code information and the above-mentioned target-associated information.

[0021] In a possible implementation, determining the type of code length to be recommended according to the cursor position includes:

[0022] When the cursor position is at the first line or the last line of the current function body or the code information corresponding to the cursor position is empty, determining that the recommended code length type corresponding to the cursor position is a code segment consisting of multiple lines of code;

[0023] When the cursor position is not located at the first line or the last line of the current function body and the code information corresponding to the cursor position is not empty, it is determined that the recommended code length type corresponding to the cursor position is a single line.

[0024] In a possible implementation, the above-mentioned searching in the index database according to the above-mentioned cursor information to obtain the target-related code information in the current file where the above-mentioned cursor position is located and the target-related information in other files of the target project where the above-mentioned cursor position is located includes:

[0025] In the case where the cursor position is not located within any function scope of the current file or is only located within the class function scope of the current file or is not located within any sub-element in the current file, the target-related code information corresponding to the cursor information is determined according to the function information set corresponding to the current file and the cursor position; and / or, in the case where the current file is a file of a specified language class, the code information corresponding to a preset number of context lines of the cursor position in the current file is determined as the target-related code information corresponding to the cursor information;

[0026] According to the target-related code information, a search is performed in the index database to obtain target-related information in other files of the target project where the cursor position is located.

[0027] In a possible implementation, the method further includes:

[0028] Parsing multiple target files in the target project to obtain target code structure information corresponding to each of the multiple target files;

[0029] Extracting target node information corresponding to each of the plurality of target nodes and target relationship information between the target nodes from the target code structure information corresponding to each of the plurality of target files;

[0030] Construct target index data corresponding to each of the plurality of target nodes according to target node information corresponding to each of the plurality of target nodes and target relationship information between the plurality of target nodes;

[0031] The target index data corresponding to each of the plurality of target nodes is stored in the index database.

[0032] In a possible implementation, storing the target index data corresponding to each of the plurality of target nodes in the index database includes:

[0033] Convert the target index data corresponding to each of the multiple target nodes into lsif format to obtain lsif index data corresponding to each of the multiple target nodes;

[0034] The lsif index data corresponding to each of the above multiple target nodes is stored in the above index database.

[0035] In a possible implementation, the target node information includes the target node type, target code snippet, target node position and target node identifier corresponding to the target node; the target nodes have different functions, and the target node types corresponding to the target nodes are different; the target relationship information includes the target relationship type and target relationship description information corresponding to the target relationship between the target nodes.

[0036] In a second aspect, an embodiment of the present application provides a code generation device, the code generation device comprising:

[0037] An acquisition module is used to acquire cursor information in the editor; the above cursor information includes the cursor position;

[0038] A first information retrieval module is used to search in an index database according to the cursor information to obtain target-related code information in the current file where the cursor is located and target-related information in other files of the target project where the cursor is located; the index database includes target index data corresponding to each target file in the target project; the target index data is constructed based on target node information of the target node corresponding to the target file and target relationship information between each target node;

[0039] The first code generation module is used to input the above cursor information, the above target related code information and the above target associated information into the target macro model to generate target recommended code information corresponding to the cursor position information.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory;

[0041] The processor is connected to the memory;

[0042] The above-mentioned memory is used to store executable program code;

[0043] The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method provided by the first aspect of the embodiment of this specification or any possible implementation of the first aspect.

[0044] In a fourth aspect, an embodiment of the present specification provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the method provided by the first aspect of the embodiment of the present specification or any possible implementation of the first aspect.

[0045] In one or more embodiments of the present application, on the one hand, according to the cursor information, a search is performed in the index database to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located, thereby extracting the target-related code information in the current file and the target-related information in other files instead of inputting the entire target project file or the current file, so that the code to be analyzed is less than the code of the entire target project project, and the interference of a large amount of information irrelevant to the cursor information in the current file and other files in the target project on the code generation process can be reduced, and the correlation between the target-related code information and the target-related information and the cursor information is ensured to a certain extent, while also ensuring the integrity and accuracy of the extraction of information related to the cursor information; at the same time, by constructing corresponding target index data according to the target node information corresponding to each target file in the target project and the target relationship information between each target node and storing it in the index database, so as to retrieve the relevant information related to the cursor information for the entire target project during the code generation process, the extraction efficiency of the target-related code information and the target-related information corresponding to the cursor information is improved, and the extraction of the complete code information corresponding to the cursor position can be realized according to the target index data constructed according to the target node information corresponding to each target file and the target relationship information between each target node;

[0046] On the other hand, the cursor information, target-related code information and target-associated information are input into the target big model, and the target-related code information and target-associated information related to the cursor information in the entire target project are used to assist the target big model in generating the target recommended code information corresponding to the cursor information. This reduces the code length input into the target big model, avoids the current file where the cursor is located or the target project file being too long and directly inputting into the target big model, which may cause the processor video memory error crash, or the code is directly truncated at will, resulting in incomplete code semantics, which may cause model hallucination problems, or code duplication and generation errors, thereby improving the efficiency of the target big model in generating the target recommended code information. By inputting the target-related code information and target-associated information, the correlation between the code generation process using the target big model and the cursor information and the entire target project is improved, thereby ensuring the executability and effectiveness of the target recommended code information generated by the target big model in the target project, and improving the accuracy of code generation.

[0047] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0049] Figure 1 A schematic diagram of the architecture of a code generation system provided for an exemplary embodiment of the present application;

[0050] Figure 2 A flowchart of a code generation method provided for an exemplary embodiment of the present application;

[0051] Figure 3 A schematic diagram of an implementation flow of information retrieval provided for an exemplary embodiment of the present application;

[0052] Figure 4 A schematic diagram of another implementation flow of information retrieval provided for an exemplary embodiment of the present application;

[0053] Figure 5 A schematic diagram of an interactive effect of code generation provided by an exemplary embodiment of the present application;

[0054] Figure 6 A flowchart of another code generation method provided for an exemplary embodiment of the present application;

[0055] Figure 7 A schematic diagram of a construction process of index data provided by an exemplary embodiment of the present application;

[0056] Figure 8 A schematic diagram of an implementation process of a code generation method provided by an exemplary embodiment of the present application;

[0057] Fig. 9 A schematic diagram of the structure of a code generating device provided by an exemplary embodiment of the present application;

[0058] Fig.10 A schematic structural diagram of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0059] In order to make the features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0060] The terms "first", "second", "third", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0061] Please refer to the following Figure 1 , which is a schematic diagram of the architecture of a code generation system provided by an exemplary embodiment of this specification. Figure 1 As shown, the code generation system may include: a terminal 110 and a server 120. Among them:

[0062] The terminal 110 can interact with the server 120 through the network to receive messages from the server 120 or send messages to the server 120. The terminal 110 can be hardware or software. When the terminal 110 is hardware, it can be various electronic devices, including but not limited to smart watches, smart phones, tablet computers, laptop portable computers and desktop computers. When the terminal 110 is software, it can be installed in the electronic devices listed above, which can be implemented as multiple software or software modules (for example: used to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.

[0063] In the embodiments of the present specification, the terminal 110 may be a user terminal corresponding to a user who needs to generate code, such as a software developer. An editor may be installed on the terminal 110, so that the developer can implement code editing and project development through the editor. In the process of the user using the editor to write a code file, the cursor information in the editor on the terminal 110 may be obtained, but is not limited to obtaining the cursor information, and the cursor information includes the cursor position. After obtaining the cursor information, the terminal 110 may first search in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located. The index database includes target index data corresponding to each target file in the target project, and the target index data is constructed based on the target node information of the target node corresponding to the target file and the target relationship information between each target node; then, the cursor information, the target-related code information and the target-related information are input into the target large model to generate the target recommended code information corresponding to the cursor position information.

[0064] Optionally, after the terminal 110 obtains the cursor information in the editor, the target-related code information corresponding to the cursor information, and the target-associated information, the cursor information in the above-mentioned editor, the target-related code information corresponding to the cursor information, and the target-associated information can also be directly sent to the server 120 through the network, so that the server 120 generates and returns the target recommended code information corresponding to the cursor information according to the code generation method provided in the embodiment of the present application.

[0065] The server 120 may be a server that provides various code generation services. It should be noted that the server 120 may be hardware or software. When the server 120 is hardware, it may be implemented as a distributed server cluster consisting of multiple servers, or it may be implemented as a single server. When the server 120 is software, it may be implemented as multiple software or software modules (for example, for providing distributed services), or it may be implemented as a single software or software module, which is not specifically limited here. The server 120 may be, but is not limited to, a hardware server, a virtual server, a cloud server, etc.

[0066] Optionally, after receiving the cursor information in the editor sent by the terminal 110 and the target-related code information and target-associated information corresponding to the cursor information, the server 120 can also perform corresponding code generation through the code generation method provided in the embodiment of the present application and return the generated target recommended code information to the terminal 110.

[0067] It can be understood that the code generation method provided in the embodiment of the present application can be executed by the terminal 110 alone, can be executed by the server 120 alone, or can be executed by the terminal 110 and the server 120 together, and the embodiment of the present application is not limited to this.

[0068] The network may be a medium providing a communication link between the terminal 110 and the server 120, or may be the Internet including network devices and transmission media, but is not limited thereto. The transmission media may be a wired link, such as but not limited to coaxial cable, optical fiber, and digital subscriber line (DSL), or a wireless link, such as but not limited to wireless fidelity (WIFI), Hypertext Transfer Protocol (HTTP), Bluetooth, and mobile device network.

[0069] Understandably, Figure 1 The number of terminals 110 and servers 120 in the code generation system shown is only an example. In a specific implementation, the code generation system may include any number of terminals 110 and servers 120.

[0070] Next, combine Figure 1 , taking the terminal 110 executing code generation as an example, the code generation method provided by an exemplary embodiment of the present application is introduced. For details, please refer to Figure 2 , which exemplarily shows a flow chart of a code generation method provided by an embodiment of the present application. Figure 2 As shown, the code generation method includes the following steps:

[0071] S201, obtaining cursor information in the editor, where the cursor information includes a cursor position.

[0072] Specifically, a code recommendation (code generation) function is provided in the editor. In the process of a user writing code using an editor, when the code generation function of the editor is turned on, the cursor information in the editor can be obtained first, so that code generation can be implemented based on the cursor information later. In addition to the cursor position, the above-mentioned cursor information may also include, but is not limited to, the line code information where the above-mentioned cursor position is located. The above-mentioned cursor position may be the line information where the cursor is located in the editor, and may also include the line information and column information where the cursor is located in the editor, which is not limited in the embodiments of the present application.

[0073] S202, searching in the index database according to the cursor information to obtain target related code information in the current file where the cursor is located and target related information in other files of the target project where the cursor is located, the index database including target index data corresponding to each target file in the target project.

[0074] Specifically, the target index data is constructed based on the target node information of the target node corresponding to the target file and the target relationship information between the target nodes. The target node can be any meaningful element such as class code, function code, variable code, comment, etc. in the target file. The target node information can include but is not limited to the target node type, target code fragment, target node position and target node identification corresponding to the target node. The target node position can include but is not limited to the file path where the target node is located and the range of code lines, etc. The target node identification is used to distinguish different target nodes, which can be but is not limited to numbers, strings, etc., which can be but is not limited to automatically generated during the construction process of the target index data corresponding to the target project. The functions of the target nodes are different, and the target node types corresponding to the target nodes are different. The target relationship information can include but is not limited to the target relationship type (such as but not limited to inheritance relationship, call relationship, reference relationship, etc.) and target relationship description information corresponding to the target relationship between the target nodes.

[0075] Exemplarily, the above-mentioned target node types may include but are not limited to metaData, $event, Source, Capabilities, Project, Range, Location, Document, Moniker, packageInfomation, resultSet, documentSymbolResult, foldingRangeResult, documentLinkResult, diagnosticResult, declarationResult, definitionResult, typeDefinitionResult, hoverResult, referenceResult, implementationResult, etc.The target node of the above-mentioned metaData type is used to mark the storage meta array, storing some relevant information such as the version of lsif to be generated; the target node of the above-mentioned $event type is used to identify events or behaviors. There are two types of events: begin and end, and there are three activity ranges of events: project, document, and monikerAttach; the target node of the above-mentioned Source type is used to identify the source of data; the target node of the above-mentioned Capabilities type is used to identify some functions or capabilities; the target node of the above-mentioned Project type is used to identify projects or projects; the target node of the above-mentioned Range type is used to identify ranges or intervals; the target node of the above-mentioned Location type is used to identify location information; the target node of the above-mentioned Document type is used to identify bi files or documents; the target node of the above-mentioned Moniker type is used to identify unique elements or aliases. There are three types of aliases: import, export, and local, and there are 5 types of unique elements: project, workspace, scheme, and global; the target node of the above-mentioned packageInfomation type is used to identify related information of the software package Information; the target node of the resultSet type is used to identify the result set; the target node of the documentSymbolResult type is used to identify the result of the document symbol; the target node of the foldingRangeResult type is used to identify the result of the folding range, and the types of folding ranges include comment, imports, and region; the target node of the documentLinkResult type is used to identify the result of the document link; the target node of the diagnosticResult type is used to identify the diagnostic result; the target node of the declarationResult type is used to identify the declaration result; the target node of the definitionResult type is used to identify the definition result; the target node of the typeDefinitionResult type is used to identify the type definition result; the target node of the hoverResult type is used to identify the mouse hover information result; the target node of the referenceResult type is used to identify the reference result. The target node of the implementationResult type is used to identify the specific implementation result.

[0076] Exemplarily, the above-mentioned target relationship types may include but are not limited to Contains (containment relationship), Next (next step, used in sequence elements), Item (an object), Moniker (unique name or alias), Attach (inheritance relationship), packageInformation (software package information, including version and dependent libraries), documentSymbol (obtaining symbol information in the document, such as variables and function names), foldingRange (foldable area range), documentLink (link in the document), Diagnostic (document diagnostic information, error detection during coding, warning prompt information), Definition (location of symbol definition, such as the definition of a function or variable), Declaration (declaration location, first declaration of variables and functions), typeDefinition (location of type definition, such as class, interface, type alias), Hover (displayed information when the mouse hovers over the code, such as type information, document comments), References (location of all references to a certain element of the code, such as all places where a variable is used), Implementation (implementation of an interface or abstract method), etc.

[0077] Optionally, after obtaining the cursor information, you can directly search the index database based on the cursor position and / or the line code information where the cursor position is located to obtain target index data related to the cursor information in the index database, such as but not limited to the target index data corresponding to the target node (such as but not limited to the current function node, the current file node) whose target node position range includes the cursor position, and then extract the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located from the target index data.

[0078] Alternatively, if Figure 3 As shown, the implementation process of the above S202, searching in the index database according to the cursor information to obtain the target related code information in the current file where the cursor is located and the target related information in other files of the target project where the cursor is located, may include but is not limited to:

[0079] S301, searching in the index database according to the cursor position to obtain the current file node information and the current function node information corresponding to the cursor position.

[0080] Specifically, after obtaining the cursor position, the cursor position can be used to search in the index database to find the corresponding current file node and current function node. The above current file node information may include, but is not limited to, the file name, file path, file type, file identifier, etc. corresponding to the current file where the cursor position is located. The above current function node information may include, but is not limited to, the function name, parameter list, return type, function code snippet, file information, etc. corresponding to the current function where the cursor position is located in the current file.

[0081] S302, searching in the index database according to the current file node information to obtain other import information corresponding to the current file node information in other files of the target project.

[0082] Specifically, after obtaining the current file node information, the current file node information can also be used, but not limited to, to search in the index database to obtain other import information corresponding to the current file node information in other files of the target project. The above other import information can include, but is not limited to, the import information corresponding to all other files in the target project that reference or contain the current file, and the import information corresponding to other files referenced or contained by the current file, etc. These import information can include, but is not limited to, the import method (for example, but not limited to, import, require, etc.), the import location, the imported file path, the imported code snippet, etc.

[0083] S303, searching in the index database according to the current function node information to obtain the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to other files.

[0084] Specifically, after obtaining the current function node information corresponding to the cursor position, the current function node information can be directly searched in the index database to obtain the target index data corresponding to the current function node, and the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to other files can be extracted from the target index data according to the variable reference relationship. The above variable reference information (current variable reference information or other variable reference information) can include but is not limited to the variable reference position, variable name, reference type (such as read, modify, etc.), and variable code snippet corresponding to the current function node.

[0085] S304, determining target-related code information in the current file where the cursor is located according to the current function node information and the current variable reference information.

[0086] Specifically, after obtaining the current function node information and the current variable reference information corresponding to the current function node information in the current file node information, the current function node information and the current variable reference information can be directly combined to obtain the target-related code information corresponding to the cursor information in the current file, so as to assist the target large model to understand the context of the cursor position in the current file and achieve more accurate code generation.

[0087] S305, determining target association information in other files where the cursor position is located according to other import information and other variable reference information.

[0088] Specifically, after obtaining the other import information corresponding to the current file node information in other files of the target project and the other variable reference information corresponding to the current function node information in other files, the above-mentioned other import information and other variable reference information can be directly spliced ​​and combined to obtain the target association information in other files where the cursor position is located, so as to assist the target large model to understand the position and influence of the code corresponding to the cursor position in the entire project, thereby achieving more accurate code generation.

[0089] Alternatively, if Figure 4 As shown, the implementation process of the above S202, searching in the index database according to the cursor information to obtain the target related code information in the current file where the cursor is located and the target related information in other files of the target project where the cursor is located, may include but is not limited to:

[0090] S401, when the cursor position is not located within any function scope of the current file or is only located within the class function scope of the current file or is not located within any sub-element of the current file, determine the target-related code information corresponding to the cursor information based on the function information set corresponding to the current file and the cursor position.

[0091] Specifically, when the cursor position is not located within any function scope of the current file, or is only located within the class function scope of the current file, or is not located within any sub-element in the current file, the target-related code information corresponding to the cursor information can be determined based on the function information set corresponding to the current file and the cursor position. That is, when the cursor position is not located within any code fragment with complete semantics in the current file, that is, it is not located within the code scope of any target node corresponding to the current file, the function information set of the current file can be directly extracted, and filtered according to the cursor position to obtain the target-related code information corresponding to the cursor information. The above-mentioned function information set can include, but is not limited to, each function code segment in the current file and the corresponding function code position information. For example, but not limited to, the function information corresponding to the function code segment in the function information set of the current file that is closest to the cursor position can be directly determined as the target-related code information. And / or

[0092] S402: When the current file is a file of a specified language, code information corresponding to a preset context line number at a cursor position in the current file is determined as target-related code information corresponding to the cursor information.

[0093] Specifically, since the statements of some specified languages ​​such as SQL are complete in themselves, each statement cannot be associated with other statements. Therefore, when the current file is a file of the specified language, the code information of the preset number of context lines (for example, but not limited to two lines above and below or five lines, etc.) corresponding to the cursor position in the current file can be directly determined as the target-related code information corresponding to the cursor information, so as to realize the extraction of target-related code information with complete semantics.

[0094] S403, searching in the index database according to the target-related code information to obtain target-related information in other files of the target project where the cursor is located.

[0095] Specifically, after obtaining the target-related code information in the current file corresponding to the cursor information, it is possible but not limited to searching in the index database according to the target node information corresponding to the target node involved in the target-related code information to obtain the corresponding target index data, and then extracting the target-related information in other files corresponding to the cursor position from the target index data. The above-mentioned target-related information may be but not limited to code snippet information in other files that has an association relationship (such as but not limited to variable reference relationship, function call relationship, etc.) with the target-related code information, such as but not limited to the code position range corresponding to the code snippet in other files, the type of association relationship corresponding to the target-related code information, etc.

[0096] Please continue to refer to Figure 2 ,like Figure 2 As shown, in the above S202, after searching in the index database according to the cursor information to obtain the target related code information in the current file where the cursor is located and the target related information in other files of the target project where the cursor is located, the code generation method further includes:

[0097] S203, inputting the cursor information, target-related code information and target-related information into the target macro model, and generating target recommended code information corresponding to the cursor position information.

[0098] Specifically, after obtaining the cursor information, target-related code information, and target-related information, the above information is input into the target big model for processing by calling the API interface of the target big model (for example, but not limited to a big model based on a deep neural network, a big language model, etc.). The target big model is used to analyze the structure, syntax, and semantics of the input target-related code information and target-related information, and understand the function and intention of the code, so that the corresponding target recommended code information can be generated for the cursor information such as the cursor position and the line of code corresponding to the cursor position, so as to recommend the code content that may need to be written at the cursor position, and assist developers to complete code writing more efficiently. The above-mentioned target recommended code information may include the target recommended code, and may also include the target code annotation and / or target recommendation reason corresponding to the target recommended code, so that developers can more intuitively understand the meaning of the target recommended code and the reason for recommending the target recommended code.

[0099] Optionally, the above S203, inputting the cursor information, target-related code information and target-associated information into the target big model, and the implementation process of generating target recommended code information corresponding to the cursor position information may include but is not limited to: inputting the cursor information, target-related code information and target-associated information into the target big model, the target big model may first determine the type of code length to be recommended according to the cursor position, for example but not limited to determining the type of code length to be recommended corresponding to the current position of the cursor according to the mapping relationship between the cursor position and the type of code length to be recommended; and then generating the target recommended code information corresponding to the cursor position information according to the type of code length to be recommended, the cursor information, the target-related code information and the target-associated information, thereby first determining the length of the code to be recommended that needs to be generated before generating the target recommended code information, and then performing corresponding code generation according to the length of the code to be recommended, so as to avoid generating a lot of useless and repetitive codes as much as possible.

[0100] Furthermore, the implementation process of determining the type of code length to be recommended based on the cursor position may include but is not limited to: when the cursor position is at the first line or the last line of the current function body or the code information corresponding to the cursor position is empty, it means that the previous or following context corresponding to the cursor position is complete, or there is no following code at the cursor position, then the type of code length to be recommended corresponding to the cursor position can be determined to be a code segment consisting of multiple lines of code, that is, the target large model can generate a target recommended code segment consisting of multiple lines of code corresponding to the cursor position information according to the type of code length to be recommended, cursor information, target-related code information, and target-related information. For example Figure 5As shown, when the code information corresponding to the cursor position 510 is empty, the target macro model can generate a target recommended code segment 520 consisting of multiple lines of code, and can be, but not limited to, displayed in a ghost font after the cursor position 510 of the editor. At the same time, the acceptance control 530 corresponding to the target recommended code segment 520 can also be displayed in the form of a pop-up window, but not limited to. When the developer wants to use the target recommended code segment 520 directly, it can be, but not limited to, directly clicking the acceptance control 530 to insert the target recommended code segment 520 at the cursor position 510, without the user having to complete the insertion and use of the target recommended code segment 520 by copying and pasting, further assisting developers to improve the efficiency of code writing.

[0101] When the cursor position is not at the first line or the last line of the current function body and the code information corresponding to the cursor position is not empty, it means that the code to be written corresponding to the cursor position may belong to a small part of a complete code snippet, then it can be determined that the recommended code length type corresponding to the cursor position is a single line, that is, the target large model can generate a target recommended code segment of a single line corresponding to the cursor position information according to the recommended code length type, cursor information, target-related code information, and target-related information, thereby avoiding the generation of many useless and repetitive code problems as much as possible.

[0102] In the embodiment of the present application, on the one hand, according to the cursor information, the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located are retrieved in the index database, thereby extracting the target-related code information in the current file and the target-related information in other files instead of inputting the entire target project file or the current file, which not only makes the code to be analyzed less than the code of the entire target project project, but also reduces the interference of a large amount of information irrelevant to the cursor information in the current file and other files in the target project on the code generation process, and ensures the correlation between the target-related code information and the target-related information and the cursor information to a certain extent, and also ensures the integrity and accuracy of the extraction of information related to the cursor information; at the same time, by constructing corresponding target index data according to the target node information corresponding to each target file in the target project and the target relationship information between each target node and storing it in the index database, so as to retrieve the relevant information related to the cursor information for the entire target project during the code generation process, it not only improves the extraction efficiency of the target-related code information and the target-related information corresponding to the cursor information, but also can realize the extraction of the complete code information corresponding to the cursor position according to the target index data constructed according to the target node information corresponding to each target file and the target relationship information between each target node;

[0103] On the other hand, the cursor information, target-related code information and target-associated information are input into the target big model, and the target-related code information and target-associated information related to the cursor information in the entire target project are used to assist the target big model in generating the target recommended code information corresponding to the cursor information. This reduces the code length input into the target big model, avoids the current file where the cursor is located or the target project file being too long and directly inputting into the target big model, which may cause the processor video memory error crash, or the code is directly truncated at will, resulting in incomplete code semantics, which may cause model hallucination problems, or code duplication and generation errors, thereby improving the efficiency of the target big model in generating the target recommended code information. By inputting the target-related code information and target-associated information, the correlation between the code generation process using the target big model and the cursor information and the entire target project is improved, thereby ensuring the executability and effectiveness of the target recommended code information generated by the target big model in the target project, and improving the accuracy of code generation.

[0104] Please refer to the following Figure 6 , which exemplarily shows a flowchart of another code generation method provided by an embodiment of the present application. Figure 6 As shown, the code generation method includes the following steps:

[0105] S601, obtaining cursor information in the editor, where the cursor information includes a cursor position.

[0106] Specifically, the above S601 is consistent with S201 and will not be repeated here.

[0107] S602, searching in the index database according to the cursor information to obtain target related code information in the current file where the cursor is located and target related information in other files of the target project where the cursor is located, the index database including target index data corresponding to each target file in the target project.

[0108] Specifically, the above S602 is consistent with S202 and will not be repeated here.

[0109] S603, when the total amount of target code corresponding to the target-related code information and the target-associated information is less than or equal to the target threshold, a search is performed in the index database according to the current function node information to obtain the function call relationship information corresponding to the current function node information, and the target threshold is less than the input length threshold of the target large model.

[0110] Specifically, when the total amount of target code corresponding to the target-related code information and the target-associated information (for example, the total code length) is less than or equal to the target threshold, it means that the total code length corresponding to the target-related code information and the target-associated information will not exceed the input length threshold of the target large model, and some other relevant information can also be input. Then, according to the current function node information, a search can be performed in the index database to obtain the function call relationship information corresponding to the current function node information, so as to provide the target large model with more comprehensive information knowledge support related to the cursor information, thereby ensuring that the target-related code information and the target-associated information with complete semantics are input into the target large model, and the input data will not be truncated due to excessive length, resulting in incomplete semantics of the input data, affecting the accuracy of code generation. The accuracy and effectiveness of code generation by the target large model are also improved by inputting the function call relationship information corresponding to the current function node information. In order to reserve a certain model input position for the function call relationship information and prevent the problem that the target-related code information and the target-related information are too large, resulting in the inability to input the processing function call relationship information or the input data being truncated, the above-mentioned target threshold should be smaller than the input length threshold of the target large model. For example, but not limited to, it can be the input length threshold of the target large model -100 or the input length threshold of the target large model -200, etc. It can be set according to actual needs, and the embodiments of the present application do not make specific limitations on this.

[0111] S604, inputting cursor information, target-related code information, target-related information and function call relationship information into the target macro model, and generating target recommended code information corresponding to the cursor position information.

[0112] Specifically, when the total amount of target code corresponding to the target-related code information and the target-associated information (for example, the total code length) is less than or equal to the target threshold, the cursor information, target-related code information, target-associated information and function call relationship information can be input into the target large model to generate target recommended code information corresponding to the cursor position information, thereby providing the target large model with more comprehensive information knowledge support related to the cursor information, ensuring that the target-related code information, target-associated information and function call relationship information with complete semantics will not be truncated due to the input data being too long, resulting in incomplete input data semantics and affecting the accuracy of code generation, and improving the accuracy and effectiveness of code generation by the target large model by inputting the function call relationship information corresponding to the current function node information.

[0113] S605, when the total amount of target codes corresponding to the target-related code information and the target-associated information is greater than the target threshold, the cursor information, the target-related code information and the target-associated information are input into the target macro model to generate target recommended code information corresponding to the cursor position information.

[0114] Specifically, when the total amount of target codes (e.g., total code length) corresponding to the target-related code information and the target-associated information is greater than the target threshold, it means that the total code length corresponding to the target-related code information and the target-associated information is likely to exceed the input length threshold of the target macro model, which means that it is no longer possible to provide input space for other related information. Then, only the cursor information, the target-related code information, and the target-associated information can be input into the target macro model to generate target recommended code information corresponding to the cursor position information. The above-mentioned implementation process of inputting the cursor information, the target-related code information, and the target-associated information into the target macro model to generate target recommended code information corresponding to the cursor position information is consistent with S203 and will not be repeated here.

[0115] Optionally, when the total amount of target code corresponding to the target-related code information and the target-associated information is greater than the target threshold and greater than the input length threshold of the target large model, it means that the total code length corresponding to the target-related code information and the target-associated information has exceeded the input length threshold of the target large model. In order to avoid the problem that the input data is too long and causes the input data to be truncated, resulting in incomplete semantics of the input data and affecting the accuracy of code generation, the above-mentioned target-related code information and target-associated information can be filtered first to retain only information with a high correlation with the cursor information. Then, the target-related code information and target-associated information whose total code length after filtering is less than or equal to the input length threshold of the target large model are input into the target large model to generate target recommended code information corresponding to the cursor position information.

[0116] Please refer to the following Figure 7 , which exemplarily shows a flowchart of a method for constructing index data provided in an embodiment of the present application. Figure 7 As shown, the index data method includes the following steps:

[0117] S701, parsing multiple target files in the target project to obtain target code structure information corresponding to each of the multiple target files.

[0118] Specifically, the above code structure information may include the target syntax tree information corresponding to the target file. The target syntax tree shows the hierarchical relationship of elements such as expressions, statements, and declarations in the code in a tree structure, making the structure of the code more intuitive and easy to understand. Each target node in the target syntax tree represents a specific syntax structure, such as an identifier, declaration, keyword, constant, etc. The code parsing tool Tree-sitter can be used to parse each target file in the editor, establish a specific target syntax tree for each target file, and effectively update the syntax tree when editing the target file.

[0119] S702: extract target node information corresponding to each of the multiple target nodes and target relationship information between the target nodes from target code structure information corresponding to each of the multiple target files.

[0120] Specifically, after obtaining the target code structure information corresponding to each of the multiple target files, the target nodes that need to be paid attention to can be identified in the target code structure information. These target nodes may be, but are not limited to, function nodes, variable nodes, class nodes, interface nodes, etc. Then, the detailed information (target node information) of each target node is extracted, such as, but not limited to, the name, target node type, target code snippet, target node position, target node identifier, scope, etc., and the target relationship information between the target nodes is analyzed and recorded, such as, but not limited to, target relationship types such as function call relationship, variable dependency relationship, inheritance relationship, and target relationship description information such as target relationship direction (such as directed or undirected) and target relationship strength (such as direct call or indirect call). The above-mentioned target node identifier is used to distinguish different target nodes, and may be, but is not limited to, a number, a string, etc., which may be, but is not limited to, automatically generated during the construction process of the target index data corresponding to the target project.

[0121] It is understandable that a target file may correspond to one or more target nodes, which is not limited in the present embodiment. The above target nodes have different functions, and the target nodes correspond to different target node types.

[0122] S703: construct target index data corresponding to each of the multiple target nodes according to target node information corresponding to each of the multiple target nodes and target relationship information between the target nodes.

[0123] Specifically, target index data corresponding to each of the target nodes can be constructed according to the extracted target node information and the target relationship information between the target nodes according to the preset index data structure. The preset index structure can be, but is not limited to, a graph structure for representing the target relationship between the target nodes.

[0124] S704: Store the target index data corresponding to each of the multiple target nodes in an index database.

[0125] Specifically, after the target index data corresponding to each of the multiple target nodes is constructed, the target index data corresponding to each of the multiple target nodes can be saved in a local index database. Since the local code is modified in real time during the encoding process and may not be submitted to the remote code repository, if an index is created in the remote code repository, the currently created index data may only be the latest submitted index data, which is different from the local code. In the process of joint development, each person's local code may be different, so directly building and storing index data locally can not only improve the efficiency and accuracy of cursor information in the target project for related information retrieval, but also save resources.

[0126] Optionally, the above S704, the implementation process of storing the target index data corresponding to each of the multiple target nodes in the index database may include but is not limited to: converting the target index data corresponding to each of the multiple target nodes into lsif format to obtain the lsif index data corresponding to each of the multiple target nodes. The lsif format is a standardized format used to represent the symbol information and its relationship in the code, so as to support efficient code navigation and intelligent perception functions. The above conversion process may be but is not limited to converting the target nodes into symbols in the lsif format, and converting the relationship between the target nodes into edges in the lsif format to represent specific relationships (target relationships) between symbols, such as but not limited to call relationships, inheritance relationships, definition / reference relationships, etc. Each symbol has a unique identifier, a name, a type, and possible other attributes (such as scope, access modifiers, etc.). At the same time, positioning information can also be added to each symbol, which specifies the exact location of the symbol in the code (such as but not limited to file name, line number, column number, etc.). After obtaining the lsif index data corresponding to each of the multiple target nodes, the lsif index data corresponding to each of the multiple target nodes can be but is not limited to being stored in the index database.

[0127] In an embodiment of the present application, the target index data corresponding to each target file in the target project is converted into lsif format index data for storage, so as to support efficient global code information retrieval in the subsequent user code writing process, and to achieve efficient and comprehensive consideration of the overall structure and code logic of the target project in the process of code generation recommendation, thereby improving the efficiency and accuracy of code generation.

[0128] Please refer to the following Figure 8 , which exemplarily shows a schematic diagram of the implementation process of a code generation method provided in an embodiment of the present application. Figure 8As shown, when developers use the editor to write code files, they can first configure the editor with a language service plug-in or framework, such as a Language Server Protocol (LSP) client, to ensure that it can correctly parse the code files (target files) in the target project and provide accurate recommendations and prompts. The editor needs to monitor the changes of each target file in the target project in real time and update the recommendations and prompts provided by the language service. By communicating with the language service plug-in or framework, it is ensured that the editor can immediately reflect the changes in the code in the target project. In the process of analyzing each target file of the target project, the editor can automatically switch to the appropriate language service plug-in according to the type of each target file or user settings. Then, the editor can be synchronized with the host environment (such as a development server, database, etc.) to ensure the real-time and accuracy of code generation recommendations and debugging. Then, the code parsing tool is used to parse each target file in the target project to obtain the target code structure information corresponding to each target file. In this process, by integrating the language service plug-in or framework, the editor can parse code files (target files) of multiple programming languages. Then, target node information corresponding to multiple target nodes and target relationship information between target nodes can be extracted from target code structure information corresponding to multiple target files, and target index data corresponding to multiple target nodes can be constructed based on the target node information corresponding to multiple target nodes and target relationship information between target nodes, and the target index data corresponding to multiple target nodes can be stored in an index database, thereby realizing the construction of an index database corresponding to the target project during the code editing process, and providing an efficient relevant information retrieval basis and knowledge support for subsequent code generation.

[0129] When developers use an editor to write code files, they can also obtain cursor information in the editor (such as but not limited to the cursor position, the line of code corresponding to the cursor position, etc.). Then, according to the cursor information, a search is performed in the above-mentioned index database to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located. Finally, the cursor information, the target-related code information, and the target-related information are input into the target macro model to generate the target recommended code information corresponding to the cursor position information, thereby completing the generation of the target recommended code information corresponding to the cursor information during the code editing process, so as to assist developers in achieving more efficient code writing.

[0130] Please refer to the following Fig. 9 , which is a schematic diagram of the structure of a code generation device provided by an exemplary embodiment of the present application. Fig. 9 As shown, the code generating device 900 includes:

[0131] The acquisition module 910 is used to acquire cursor information in the editor; the cursor information includes the cursor position;

[0132] The first information retrieval module 920 is used to search in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor is located and the target-related information in other files of the target project where the cursor is located; the index database includes the target index data corresponding to each target file in the target project; the target index data is constructed based on the target node information of the target node corresponding to the target file and the target relationship information between each target node;

[0133] The first code generation module 930 is used to input the above cursor information, the above target related code information and the above target associated information into the target macro model, and generate target recommended code information corresponding to the above cursor position information.

[0134] In a possible implementation, the first information retrieval module 920 includes:

[0135] A first information retrieval unit, configured to search in an index database according to the cursor position to obtain current file node information and current function node information corresponding to the cursor position;

[0136] A second information retrieval unit is used to search the index database according to the current file node information to obtain other imported information corresponding to the current file node information in other files of the target project;

[0137] A third information retrieval unit is used to search the index database according to the current function node information to obtain the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to the current function node information in the other files;

[0138] A first determining unit, configured to determine target-related code information in the current file where the cursor is located according to the current function node information and the current variable reference information;

[0139] The second determining unit is used to determine the target association information in the other file where the cursor position is located according to the other introduction information and the other variable reference information.

[0140] In a possible implementation, the code generating device 900 further includes:

[0141] A second information retrieval module is used to retrieve the function call relationship information corresponding to the current function node information in the index database when the total amount of the target code corresponding to the target-related code information and the target-associated information is less than or equal to the target threshold value;

[0142] A second code generation module is used to input the cursor information, the target related code information, the target association information and the function call relationship information into the target macro model to generate target recommended code information corresponding to the cursor position information;

[0143] The above-mentioned first code generation module 930 is specifically used for: when the total amount of target codes corresponding to the above-mentioned target-related code information and the above-mentioned target-associated information is greater than the above-mentioned target threshold, executing the above-mentioned step of inputting the above-mentioned cursor information, the above-mentioned target-related code information and the target-associated information into the target macro model to generate the target recommended code information corresponding to the above-mentioned cursor position information; the above-mentioned target threshold is less than the input length threshold of the above-mentioned target macro model.

[0144] In a possible implementation, the first code generation module 930 is specifically used to:

[0145] The above-mentioned cursor information, the above-mentioned target-related code information and the above-mentioned target-associated information are input into the target macro model, the type of code length to be recommended is determined according to the above-mentioned cursor position, and the target recommended code information corresponding to the above-mentioned cursor position information is generated according to the above-mentioned code length type to be recommended, the above-mentioned cursor information, the above-mentioned target-related code information and the above-mentioned target-associated information.

[0146] In a possible implementation, when the first code generating module 930 performs the above-mentioned determination of the code length type to be recommended according to the above-mentioned cursor position, it is specifically used to:

[0147] When the cursor position is at the first or last line of the current function body or the code information corresponding to the cursor position is empty, the recommended code length type corresponding to the cursor position is determined to be a code segment consisting of multiple lines of code; when the cursor position is not at the first or last line of the current function body and the code information corresponding to the cursor position is not empty, the recommended code length type corresponding to the cursor position is determined to be a single line.

[0148] In a possible implementation, the first information retrieval module 920 includes:

[0149] A third determination unit is used to determine the target-related code information corresponding to the cursor information according to the function information set corresponding to the current file and the cursor position when the cursor position is not located within any function scope of the current file or is only located within the class function scope of the current file or is not located within any sub-element in the current file; and / or, when the current file is a file of a specified language class, determine the code information corresponding to a preset number of context lines of the cursor position in the current file as the target-related code information corresponding to the cursor information;

[0150] The fourth information retrieval unit is used to search in the index database according to the target-related code information to obtain the target-related information in other files of the target project where the cursor position is located.

[0151] In a possible implementation, the code generating device 900 further includes:

[0152] A code parsing module, used to parse multiple target files in the target project to obtain target code structure information corresponding to each of the multiple target files;

[0153] An information extraction module is used to extract target node information corresponding to each of the multiple target nodes and target relationship information between the target nodes from the target code structure information corresponding to each of the multiple target files;

[0154] An index building module, used to build target index data corresponding to each of the multiple target nodes according to the target node information corresponding to each of the multiple target nodes and the target relationship information between the multiple target nodes;

[0155] The data storage module is used to store the target index data corresponding to each of the above-mentioned multiple target nodes in the above-mentioned index database.

[0156] In a possible implementation, the code generating device 900 includes:

[0157] A data conversion unit, used to convert the target index data corresponding to each of the plurality of target nodes into an lsif format, to obtain the lsif index data corresponding to each of the plurality of target nodes;

[0158] The data storage unit is used to store the lsif index data corresponding to each of the above-mentioned multiple target nodes in the above-mentioned index database.

[0159] In a possible implementation, the target node information includes the target node type, target code snippet, target node position and target node identifier corresponding to the target node; the target nodes have different functions, and the target node types corresponding to the target nodes are different; the target relationship information includes the target relationship type and target relationship description information corresponding to the target relationship between the target nodes.

[0160] The division of each module in the above-mentioned code generation device is only for illustration. In other embodiments, the code generation device can be divided into different modules as needed to complete all or part of the functions of the above-mentioned code generation device. The implementation of each module in the code generation device provided in the embodiment of this specification can be in the form of a computer program. The computer program can be run on a terminal or a server. The program modules constituted by the computer program can be stored in the memory of the terminal or the server. When the computer program is executed by the processor, all or part of the steps of the code generation method described in the embodiment of this specification are implemented.

[0161] See next Fig.10 , which is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of this specification. Fig.10 As shown, the electronic device 1000 may include: at least one processor 1010 , at least one communication bus 1020 , a user interface 1030 , at least one network interface 1040 , and a memory 1050 .

[0162] The communication bus 1020 may be used to realize the connection and communication among the above-mentioned components.

[0163] The user interface 1030 may include a display screen (Display) and a camera (Camera), and the optional user interface 1030 may also include a standard wired interface and a wireless interface.

[0164] The network interface 1040 may optionally include a Bluetooth module, a Near Field Communication (NFC) module, a Wireless Fidelity (Wi-Fi) module, and the like.

[0165] Among them, the processor 1010 may include one or more processing cores. The processor 1010 uses various interfaces and lines to connect various parts of the entire electronic device 1000, and executes various functions and processes data of the routing electronic device 1000 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1050, and calling data stored in the memory 1050. Optionally, the processor 1010 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1010 can be an integrated processor (Central Processing Unit, CPU), a graphics processor (Graphics Processing Unit, GPU) and a modem. One or more combinations thereof. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1010, but may be implemented separately through a chip.

[0166] Among them, the memory 1050 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory, ROM). Optionally, the memory 1050 includes a non-transitory computer-readable medium. The memory 1050 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1050 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as an acquisition function, an information retrieval function, a code generation function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1050 may also be optionally at least one storage device located away from the aforementioned processor 1010. As Fig.10 As shown, the memory 1050 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.

[0167] In some possible embodiments, the electronic device 1000 may be the aforementioned Fig. 9In the code generating device 900 shown, the processor 1010 can be used to call the program instructions stored in the memory 1050, and specifically perform the following operations: obtain the cursor information in the editor; the above cursor information includes the cursor position; search in the index database according to the above cursor information to obtain the target-related code information in the current file where the above cursor position is located and the target-related information in other files of the target project where the above cursor position is located; the above index database includes the target index data corresponding to each target file in the above target project; the above target index data is constructed based on the target node information of the target node corresponding to the above target file and the target relationship information between each of the above target nodes; the above cursor information, the above target-related code information and the above target-related information are input into the target macro model to generate the target recommended code information corresponding to the above cursor position information.

[0168] In some possible embodiments, when the processor 1010 performs the above-mentioned search in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located, it is specifically used to perform: searching in the index database according to the cursor position to obtain the current file node information and the current function node information corresponding to the cursor position; searching in the index database according to the current file node information to obtain other import information corresponding to the current file node information in other files of the target project; searching in the index database according to the current function node information to obtain the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to the other files; determining the target-related code information in the current file where the cursor position is located according to the current function node information and the current variable reference information; determining the target-related information in the other files where the cursor position is located according to the other import information and the other variable reference information.

[0169] In some possible embodiments, after the processor 1010 performs the above-mentioned search in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located, it is also used to perform: when the total amount of target code corresponding to the target-related code information and the target-related information is less than or equal to the target threshold, perform the search in the index database according to the current function node information to obtain the function call relationship information corresponding to the current function node information; input the cursor information, the target-related code information, the target-related information and the function call relationship information into the target macro model to generate the target recommended code information corresponding to the cursor position information; when the total amount of target code corresponding to the target-related code information and the target-related information is greater than the target threshold, perform the above-mentioned step of inputting the cursor information, the target-related code information and the target-related information into the target macro model to generate the target recommended code information corresponding to the cursor position information; the target threshold is less than the input length threshold of the target macro model.

[0170] In some possible embodiments, when the processor 1010 executes the input of the cursor information, the target-related code information and the target-associated information into the target big model to generate the target recommended code information corresponding to the cursor position information, it is specifically used to execute: input the cursor information, the target-related code information and the target-associated information into the target big model, determine the type of code length to be recommended according to the cursor position, and generate the target recommended code information corresponding to the cursor position information according to the type of code length to be recommended, the cursor information, the target-related code information and the target-associated information.

[0171] In some possible embodiments, when the processor 1010 executes the above-mentioned determination of the type of code length to be recommended according to the cursor position, it is specifically used to execute: when the cursor position is at the first line or the last line of the current function body or the corresponding code information after the cursor position is empty, determine that the type of code length to be recommended corresponding to the cursor position is a code segment consisting of multiple lines of code; when the cursor position is not at the first line and the last line of the current function body and the corresponding code information after the cursor position is not empty, determine that the type of code length to be recommended corresponding to the cursor position is a single line.

[0172] In some possible embodiments, when the processor 1010 performs the above-mentioned search in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor position is located and the target-related information in other files of the target project where the cursor position is located, it is specifically used to perform: when the cursor position is not located within any function scope of the current file or is only located within the class function scope of the current file or is not located within any sub-element in the current file, determine the target-related code information corresponding to the cursor information according to the function information set corresponding to the current file and the cursor position; and / or, when the current file is a file of a specified language class, determine the code information corresponding to the preset context line number of the cursor position in the current file as the target-related code information corresponding to the cursor information; and search in the index database according to the target-related code information to obtain the target-related information in other files of the target project where the cursor position is located.

[0173] In some possible embodiments, the processor 1010 is further used to execute: parsing multiple target files in the target project to obtain target code structure information corresponding to each of the multiple target files; extracting target node information corresponding to each of the multiple target nodes and target relationship information between the target nodes from the target code structure information corresponding to each of the multiple target files; constructing target index data corresponding to each of the multiple target nodes based on the target node information corresponding to each of the multiple target nodes and the target relationship information between the target nodes; and storing the target index data corresponding to each of the multiple target nodes in the index database.

[0174] In some possible embodiments, when the processor 1010 executes the above-mentioned storage of the target index data corresponding to each of the multiple target nodes in the index database, it is specifically used to execute: converting the target index data corresponding to each of the multiple target nodes into lsif format to obtain lsif index data corresponding to each of the multiple target nodes; storing the lsif index data corresponding to each of the multiple target nodes in the index database.

[0175] In some possible embodiments, the above-mentioned target node information includes the target node type, target code snippet, target node position and target node identifier corresponding to the above-mentioned target node; the functions of the above-mentioned target nodes are different, and the target node types corresponding to the above-mentioned target nodes are different; the above-mentioned target relationship information includes the target relationship type and target relationship description information corresponding to the target relationship between the above-mentioned target nodes.

[0176] The embodiment of the present application also provides a computer storage medium, which stores instructions, and when the instructions are executed on a computer or a processor, the computer or the processor executes one or more steps in any of the above methods. If the components of the above code generation device are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above storage medium.

[0177] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The above computer program product includes one or more computer instructions. When the above computer program instructions are loaded and executed on a computer, the above process or function according to the embodiment of the present application is generated in whole or in part. The above computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The above computer instructions may be stored in a computer-readable storage medium or transmitted through the above computer-readable storage medium. The above computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The above computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The above available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.

[0178] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes. In the absence of conflict, the technical features in this embodiment and the implementation scheme can be combined arbitrarily.

[0179] The above-mentioned embodiments are merely preferred embodiments of the present application and are not intended to limit the scope of the present application. Without departing from the design spirit of the present application, various modifications and improvements made to the technical solutions of the present application by ordinary technicians in this field should fall within the protection scope determined by the claims of the present application.

Claims

1. A code generation method, characterized in that: include: Obtaining cursor information in the editor; the cursor information includes the cursor position; Searching in an index database according to the cursor information to obtain target-related code information in the current file where the cursor is located and target-related information in other files of the target project where the cursor is located; the index database includes target index data corresponding to each target file in the target project; The target index data is constructed based on the target node information of the target node corresponding to the target file and the target relationship information between the target nodes; Inputting the cursor information, the target-related code information and the target-related information into a target macro model to generate target recommended code information corresponding to the cursor position; The searching in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor is located and the target-related information in other files of the target project where the cursor is located includes: Searching in the index database according to the cursor position to obtain current file node information and current function node information corresponding to the cursor position; Searching the index database according to the current file node information to obtain other imported information corresponding to the current file node information in other files of the target project; Searching the index database according to the current function node information to obtain current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to the current function node information in other files; Determine the target-related code information in the current file where the cursor is located according to the current function node information and the current variable reference information; The target association information in the other file where the cursor is located is determined according to the other import information and the other variable reference information.

2. The method according to claim 1, characterized in that: After searching in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor is located and the target-related information in other files of the target project where the cursor is located, the method further includes: When the total amount of target code corresponding to the target-related code information and the target-associated information is less than or equal to the target threshold, searching the index database according to the current function node information to obtain function call relationship information corresponding to the current function node information; Inputting the cursor information, the target-related code information, the target-related information and the function call relationship information into a target macro model to generate target recommended code information corresponding to the cursor position; In the case where the total amount of target codes corresponding to the target-related code information and the target-associated information is greater than the target threshold, the step of inputting the cursor information, the target-related code information and the target-associated information into the target macro model to generate the target recommended code information corresponding to the cursor position is performed; the target threshold is less than the input length threshold of the target macro model.

3. The method according to any one of claims 1 to 2, characterized in that: The step of inputting the cursor information, the target-related code information and the target-related information into a target macro model to generate target recommended code information corresponding to the cursor position includes: The cursor information, the target-related code information and the target-associated information are input into the target macro model, the type of code length to be recommended is determined according to the cursor position, and the target recommended code information corresponding to the cursor position is generated according to the type of code length to be recommended, the cursor information, the target-related code information and the target-associated information.

4. The method according to claim 3, characterized in that The step of determining the type of code length to be recommended according to the cursor position includes: When the cursor position is at the first line or the last line of the current function body or the code information corresponding to the cursor position is empty, determining that the recommended code length type corresponding to the cursor position is a code segment consisting of multiple lines of code; When the cursor position is not located at the first line or the last line of the current function body and the code information corresponding to the cursor position is not empty, it is determined that the recommended code length type corresponding to the cursor position is a single line.

5. The method according to claim 1, characterized in that The searching in the index database according to the cursor information to obtain the target-related code information in the current file where the cursor is located and the target-related information in other files of the target project where the cursor is located includes: In the case where the cursor position is not located within any function scope of the current file or is only located within the class function scope of the current file or is not located within any sub-element in the current file, the target-related code information corresponding to the cursor information is determined according to the function information set corresponding to the current file and the cursor position; and / or, in the case where the current file is a file of a specified language class, the code information corresponding to a preset number of context lines of the cursor position in the current file is determined as the target-related code information corresponding to the cursor information; According to the target-related code information, a search is performed in an index database to obtain target-related information in other files of the target project where the cursor position is located.

6. The method according to claim 1, characterized in that: The method further comprises: Parsing multiple target files in the target project to obtain target code structure information corresponding to each of the multiple target files; Extracting target node information corresponding to each of the plurality of target nodes and target relationship information between the target nodes from the target code structure information corresponding to each of the plurality of target files; Constructing target index data corresponding to each of the multiple target nodes according to target node information corresponding to each of the multiple target nodes and target relationship information between the target nodes; The target index data corresponding to each of the plurality of target nodes are stored in the index database.

7. A code generating device, characterized in that: The code generating device comprises: An acquisition module, used for acquiring cursor information in the editor; the cursor information includes a cursor position; A first information retrieval module is used to search in an index database according to the cursor information to obtain target-related code information in the current file where the cursor is located and target-related information in other files of the target project where the cursor is located; the index database includes target index data corresponding to each target file in the target project; the target index data is constructed based on target node information of the target node corresponding to the target file and target relationship information between each target node; A first code generation module, used for inputting the cursor information, the target-related code information and the target-related information into a target macro model, and generating target recommended code information corresponding to the cursor position; The first information retrieval module is specifically used for: searching in the index database according to the cursor position to obtain the current file node information and the current function node information corresponding to the cursor position; searching in the index database according to the current file node information to obtain other import information corresponding to the current file node information in other files of the target project; searching in the index database according to the current function node information to obtain the current variable reference information corresponding to the current function node information in the current file node information and other variable reference information corresponding to the other files; determining the target related code information in the current file where the cursor position is located according to the current function node information and the current variable reference information; determining the target association information in the other files where the cursor position is located according to the other import information and the other variable reference information.

8. An electronic device, characterized in that: include: processor and memory; wherein, The processor is connected to the memory; the memory is used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method steps as described in any one of claims 1-6.

9. A computer storage medium, characterized in that The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1-6.

Citation Information

Patent Citations

  • Code generation method and device based on cloud service

    CN118092923A

  • Code prompting method

    CN118444895A