Code completion method, device, electronic device and storage medium
By introducing auxiliary programming plug-ins and code completion large language model in the code editor, combined with the function description matching of the target database, the problem that intelligent auxiliary programming tools cannot understand the overall structure of user code is solved, and the accuracy of code completion is improved. Business correlation.
Patent Information
- Application Number
- CN202411631390.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-11-15
AI Technical Summary
Existing intelligent assisted programming tools cannot fully understand the overall engineering structure of user code, resulting in low accuracy of generated complete code.
By introducing auxiliary programming plug-ins in the code editor, using preset code to complete the large language model and target database, identify the type of input content, determine the content to be analyzed, match the function description to obtain the candidate code module, and execute it according to user instructions Complete operation.
It improves the accuracy and business relevance of code completion, reduces code redundancy and maintenance difficulty, and enhances the connection between code and other project files.
Smart Images

Figure CN119149000B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a code completion method, device, electronic equipment and storage medium. Background Art
[0002] With the rapid development of artificial intelligence technology, intelligent assisted programming has become a common method in the field of programming. These tools use machine learning and natural language processing technologies to understand the user's code context and thus complete the code. However, due to the limited length of context that intelligent assisted programming tools can handle, this makes it impossible for intelligent assisted programming tools to fully understand the overall engineering structure of the user's code, resulting in low accuracy of the generated completion code. Summary of the invention
[0003] The purpose of the embodiments of the present invention is to provide a code completion method, device, electronic device and storage medium to improve the accuracy of code completion. The specific technical solution is as follows:
[0004] In a first aspect, the present application provides a code completion method, which is applied to an auxiliary programming plug-in of a code editor, and the method comprises:
[0005] In response to a user performing an input operation in the code editing interface, obtaining input content corresponding to the input operation;
[0006] Based on the type of the input content, determine the content to be analyzed for code completion in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed;
[0007] Identify the function description corresponding to the content to be analyzed as the target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content;
[0008] Determine each target candidate code module that matches the target function description from a target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module;
[0009] Output each target candidate code module to the target window for the user to select;
[0010] In response to a user issuing a specified completion instruction in the target window, executing a completion operation corresponding to the specified completion instruction to complete code completion for the input content;
[0011] Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction;
[0012] The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user;
[0013] The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user;
[0014] The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
[0015] In a second aspect, the present application provides a code completion device, which is applied to an auxiliary programming plug-in of a code editor, and the device includes:
[0016] An acquisition module, configured to acquire input content corresponding to an input operation performed by a user in a code editing interface;
[0017] A first determination module is used to determine the content to be analyzed for code completion based on the type of the input content in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed;
[0018] An identification module, used to identify the function description corresponding to the content to be analyzed as a target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content;
[0019] A second determination module is used to determine each target candidate code module matching the target function description from a target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module;
[0020] The output module is used to output each target candidate code module to the target window for the user to select;
[0021] A completion module, configured to respond to a user issuing a specified completion instruction in the target window and execute a completion operation corresponding to the specified completion instruction to complete code completion for the input content;
[0022] Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction;
[0023] The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user;
[0024] The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user;
[0025] The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
[0026] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0027] Memory, used to store computer programs;
[0028] The processor is used to implement any of the above-mentioned code completion methods when executing a program stored in the memory.
[0029] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the code completion method described above is implemented.
[0030] Beneficial effects of the embodiments of the present invention: The scheme provided by the embodiments of the present invention is that after the user performs an input operation in the code editing interface, the auxiliary programming plug-in can first determine the content to be analyzed for code completion based on the type of the input content in a predetermined manner, and then determine the target candidate code module that matches the functional description of the content to be analyzed in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in the present application are the candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the code completion is completed by using the candidate code modules in the target database, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this solution.
[0031] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0033] Figure 1 A flowchart of a code completion method provided in an embodiment of the present application;
[0034] Figure 2 An exemplary schematic diagram of constructing a code context provided in an embodiment of the present application;
[0035] Figure 3 An exemplary interactive schematic diagram of building a target database provided in an embodiment of the present application;
[0036] Figure 4 An exemplary interactive schematic diagram of a target database construction method provided in this application;
[0037] Figure 5 An exemplary schematic diagram of a target window provided in an embodiment of the present application;
[0038] Figure 6 An exemplary interactive schematic diagram of a code completion method provided in an embodiment of the present application;
[0039] Figure 7 A schematic diagram of the structure of a code completion device provided in an embodiment of the present application;
[0040] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field based on this application belong to the scope of protection of the present invention.
[0042] In the field of front-end development, the accuracy and relevance of code completion are crucial to improving development efficiency and code quality. Although existing front-end auxiliary programming tools have made progress in some aspects, they still have obvious shortcomings in the following aspects:
[0043] 1. Insufficient relevance to front-end business: When dealing with front-end projects, existing auxiliary programming tools often find it difficult to deeply understand the front-end-specific business logic and development model, resulting in the completed code not being well matched with the front-end business scenarios, poorly matching requirements, and lacking specificity.
[0044] 2. Limitations of context understanding: Front-end development involves multiple technology stacks such as HTML (Hyper Text Markup Language), CSS (Cascading Style Sheets), and JavaScript (an advanced, multi-paradigm, interpreted programming language). Existing auxiliary programming tools have limitations in understanding the complex interactions and contextual relationships between these technology stacks, which affects the accuracy of completion results. In addition, when generating code, the relationship between the three is often not taken into account, and multiple generations are required to get the desired answer, which makes the interaction cumbersome.
[0045] 3. Code redundancy problem: When auxiliary programming tools are used to assist programming in a project, due to the lack of in-depth understanding of code structure and design patterns, it is easy to generate a lot of duplicate code, resulting in redundancy, which not only increases the size of the project, but also increases the difficulty of maintenance.
[0046] The above defects result in poor accuracy of code completion in the prior art, which is difficult to meet the needs.
[0047] In order to improve the accuracy of code completion, embodiments of the present application provide a code completion method, device, electronic device, and storage medium.
[0048] The following first introduces a code completion method provided by an embodiment of the present application. The code completion method of the present application is applied to an auxiliary programming plug-in of a code editor. It is understandable that any code editor can apply an auxiliary programming plug-in to implement the code completion method of the present application.
[0049] Among them, a code completion method provided in an embodiment of the present application may include:
[0050] In response to a user performing an input operation in the code editing interface, obtaining input content corresponding to the input operation;
[0051] Based on the type of the input content, determine the content to be analyzed for code completion in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed;
[0052] Identify the function description corresponding to the content to be analyzed as the target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content;
[0053] Determine each target candidate code module that matches the target function description from a target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module;
[0054] Output each target candidate code module to the target window for the user to select;
[0055] In response to a user issuing a specified completion instruction in the target window, executing a completion operation corresponding to the specified completion instruction to complete code completion for the input content;
[0056] Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction;
[0057] The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user;
[0058] The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user;
[0059] The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
[0060] According to the scheme provided by the embodiment of the present invention, after the user performs an input operation in the code editing interface, the auxiliary programming plug-in can first determine the content to be analyzed for code completion based on the type of the input content in a predetermined manner, and then determine the target candidate code module that matches the functional description of the content to be analyzed in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in the present application are the various candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the code completion is completed by using the candidate code modules in the target database, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this scheme. In addition, using the solution of the present application for code completion can reduce the occurrence of duplicate code, reduce code redundancy, and reduce the difficulty of code maintenance.
[0061] A code completion method provided in an embodiment of the present application is introduced below in conjunction with the accompanying drawings.
[0062] like Figure 1 As shown, a code completion method provided in an embodiment of the present application, applied to an auxiliary programming plug-in of a code editor, may include the following steps:
[0063] S101, in response to a user performing an input operation on a code editing interface, obtaining input content corresponding to the input operation;
[0064] The code editor of this application can be any code editor, and this application does not limit the code editor.
[0065] In one implementation, before obtaining the input content corresponding to the input operation, a trigger condition can be set, and after the trigger condition is met, the step of obtaining the input content corresponding to the input operation is performed. The trigger condition can represent the completion of a complete input operation. Exemplarily, the trigger condition can be the detection of an end character in the input content, and the end character can be pre-defined, which is not limited in this application. The trigger condition can also be the detection of a trigger instruction issued by the user. For example, a button for triggering code completion can be provided in the code editing interface. After performing the input operation, the user can click the button to indicate that the input operation is over, thereby triggering code completion. The trigger condition can also be that the user stops the input operation after a predetermined time, triggering code completion. For example, after the user stops performing the input operation for 5 seconds, the acquisition of the input content corresponding to the input operation begins.
[0066] S102, based on the type of the input content, determine the content to be analyzed for code completion in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content, and obtains the content to be analyzed;
[0067] Based on the type of the input content, the step of determining the content to be analyzed for code completion in a predetermined manner may be performed directly after the input content corresponding to the input operation is obtained, or may be performed after the user issues a corresponding instruction.
[0068] It is understandable that when developers write code, they usually show two different operating habits. One is the comment-first development method, in which developers first describe the comments of the functional logic to be implemented in detail, and then develop the code according to the logic described in these comments; the other is the code-first development method: in this method, developers first start to write code, and after the code is written, they supplement the comments and documents corresponding to the code. The developer can be the user of this application. Based on the above two different operating habits, in this application, the type of the input content can be identified based on the content entered by the user, and then different processing can be performed on the input content based on different types. Specifically, when it is recognized that the user input is text, the type of the input content is a text comment type; when it is recognized that the user input is code, the type of the input content is a code type.
[0069] When the input content is of a text comment type, the input content can usually express the function that the user wants to implement, so the input content can be directly used as the content to be analyzed; and when the input content is of a code type, the user usually writes a part of the code of the function to be implemented. At this time, the code written by the user alone usually cannot directly express a complete function. Therefore, a specified preprocessing can be performed on the input content. The specified preprocessing can be to complete the code. The completed code can express a complete function, so the completed code can be used as the content to be analyzed. It can be understood that the code completion performed by the specified preprocessing is only based on the code of the current code editing page. Therefore, there is no business association between the completed code and the various files of the target code project.
[0070] In the present application, the specified preprocessing is to input the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs the first code completion content. It is understandable that the code in the code editing interface includes the code entered by the user in S101 when performing the input operation in the code editing interface, and the code existing before the input operation is performed. The code completion large language model can generate code completion content based on the context content of the code. Specifically, in the code editing interface, the position of the mouse cursor is the position to be code completed, the code before the cursor is the previous content, and the code after the cursor is the following content. It is understandable that in the specific implementation, the position to be code completed can have context content at the same time, can have only the previous content, or can have only the following content. No matter what the situation is, code completion can be performed.
[0071] The code completion large language model described in this application can be any large language model that can implement code completion, such as Wenxin Yiyan and Tongyi Qianwen, etc., and this application does not limit this.
[0072] S103, identifying the function description corresponding to the content to be analyzed as the target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content;
[0073] Exemplarily, the functions that can be realized may be: a function for optimizing the function calling frequency, a delay function, a function for obtaining a certain parameter, and the like.
[0074] This step can perform semantic recognition on the content to be analyzed and identify the functional description corresponding to the content to be analyzed. It is understandable that there are many ways to implement semantic recognition of the content to be analyzed, such as through vector matching, pre-trained semantic recognition models, and conversational large language models, etc. This application does not limit the method of identifying the functional description corresponding to the content to be analyzed.
[0075] Exemplarily, the identification method of the functional description corresponding to any content may include:
[0076] The content is input into a preset conversational large language model so that the conversational large language model generates a functional description corresponding to the content.
[0077] It is understandable that, generally, any large language model can realize the function of semantic recognition, and therefore, the conversational large language model of the present application can be any large language model. Thus, no matter the content is a text comment or the first code completion content, the conversational large language model can be used to obtain the corresponding functional description.
[0078] Optionally, the input of the conversational large language model further includes target parameters representing format and length constraint values;
[0079] The inputting the content into a preset conversation large language model so that the conversation large language model generates a functional description corresponding to the content includes:
[0080] The content and the target parameters are input into a conversation large language model, so that the conversation large language model generates a functional description corresponding to the content according to the format and length constraint value represented by the target parameters.
[0081] The target parameter representing the format and length constraint value may be in the form of natural language. For example, if the content is: write a function that limits the frequency of function calls, the target parameter may be "describe the function described in the above content in the format of "function description is...", with a length of no more than 100 words", so that the conversational large language model may output: the function description is to limit the frequency of function calls. It is understandable that the format described in this application refers to the text description format of the function description.
[0082] The above-mentioned identification of the functional description corresponding to the content to be analyzed is only an example, and the present invention does not limit the specific implementation of the identification of the functional description corresponding to the content to be analyzed.
[0083] S104, determining each target candidate code module that matches the target function description from a target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs, and the function description corresponding to each candidate code module.
[0084] It is understandable that in a code project, there may be multiple files, and these files may contain pre-written code modules. Among these code modules, there may be code modules that match the target function description. The code modules may also be called code blocks, function blocks or function code blocks.
[0085] Therefore, the present application can store each candidate code module existing in each file of the target code project and the functional description corresponding to each candidate code module in the target database in advance. Thus, each target candidate code module that matches the target functional description can be determined from the target database. It is understandable that the determination of each target candidate code module that matches the target functional description is determined by matching the target functional description with the functional description corresponding to each candidate code module, and specifically, it can be achieved by character matching, semantic analysis, and calculating vector similarity.
[0086] Exemplarily, in one implementation, the storage form of the function description corresponding to each candidate code module in the target database is in the form of a vector value;
[0087] Determining each target candidate code module matching the target function description from the target database includes:
[0088] Vectorizing the target function description to obtain a target vector value;
[0089] For each candidate functional module in the target database, calculating the similarity between the target vector value and the vector value of the functional description corresponding to the candidate code module, and obtaining the similarity corresponding to each candidate code module;
[0090] Based on the similarity corresponding to each candidate code module, the candidate code module whose similarity meets the matching condition is used as the target candidate code module.
[0091] In this embodiment, the similarity between the target vector value of the target function description and the vector value of the function description corresponding to each candidate code module can be calculated; thus, the N candidate code modules with the greatest similarity can be selected, that is, the N candidate code modules arranged in the front after being sorted in descending order according to the size of the similarity, to obtain each target candidate code module. Of course, candidate code modules with a similarity greater than a predetermined threshold can also be selected to obtain each target candidate code module.
[0092] In the present application, each function description that appears can be generated by the conversational large language model according to the format and length constraint value represented by the target parameter. For example, the function description can be the function description of each candidate code block in the target database and the function description corresponding to the content to be analyzed, etc. The generation method of the function description has been introduced in the above embodiment and will not be repeated here. Therefore, the format and length of each function description are relatively uniform, and the accuracy is higher when calculating the similarity between the target vector value and the vector value of the function description corresponding to the candidate code module.
[0093] For the sake of clarity of the solution and layout, the following will exemplarily introduce the method of determining each candidate code module stored in the target database in combination with other embodiments.
[0094] S105, outputting each target candidate code module to a target window for selection by the user;
[0095] The target window may be a window independent of the code editing interface, or may be a part of the code editing interface, which is not limited in the present application.
[0096] The target window may display various target candidate code modules for user selection.
[0097] S106, in response to the user issuing a specified completion instruction in the target window, executing a completion operation corresponding to the specified completion instruction to complete code completion for the input content;
[0098] Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction;
[0099] The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user;
[0100] The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user;
[0101] The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
[0102] Next, a specific implementation method of executing a completion operation corresponding to the specified completion instruction in response to the user issuing the specified completion instruction in the target window to complete the code completion for the input content is introduced.
[0103] In one implementation, in response to a user issuing a first completion instruction in the target window, the target candidate code module selected by the user and the code in the code editing interface are input into the code completion large language model, so that the code completion large language model outputs a second code completion content;
[0104] Determining a reference path of the target candidate code module contained in the second code completion content in the target code project;
[0105] The target candidate code module contained in the second code completion content is replaced with a reference code corresponding to a reference path of the target candidate code module to obtain a target completion code; wherein the reference code is a code generated based on the reference path and used to reference the target candidate code module;
[0106] The target completion code is used to perform a specified completion operation; wherein, if the type of the input content is a text annotation type, the specified completion operation is: writing the target completion code to the end position of the input operation; if the type of the input content is a code type, the specified completion operation is: replacing the input content corresponding to the input operation with the target completion code.
[0107] When the user believes that a target candidate code module in the target window can be used as part of the content to be completed, the first completion instruction can be issued. The user's operation can be to select the target candidate code module and then click the corresponding button provided to issue the first completion instruction.
[0108] like Figure 2 As shown, it is an exemplary schematic diagram of constructing a code context provided by the present application.
[0109] The inputting of the target candidate code module selected by the user and the code in the code editing interface into the code completion large language model may be to construct the context corresponding to the code completion content and input it into the code completion large language model. Figure 2As shown, first, a vector similarity search can be performed from the project engineering file to obtain a matching result corresponding to the functional description, that is, the process of determining each of the above-mentioned target candidate code modules, and the matching result is the target candidate code module. The user can manually select the required target candidate code module from each target candidate code module, and then the target candidate code module selected by the user and the code in the current editing file, that is, the current code editing interface, can be used together as the engineering relevance context corresponding to the code completion content, input into the code completion large language model, and obtain the corresponding completion content. Among them, the code in the current code editing interface is called the code generation context. Figure 2 The functional problem description is the above comment content.
[0110] The present invention combines the characteristics of code understanding and completion through code context in the process of generating code completion by the code completion large language model, and designs to divide the code completion context input content into two parts, one part is the code generation context, that is, the actual context of the code (that is, the code content before and after the position of the code completion cursor that triggers the code completion), and the other part is designed as the code engineering relevance context, which is the plug-in that recognizes the user's intention and inserts the most relevant part of the existing code modules in the project into the context for reference by the code completion large language model. If the completion content of the code completion large language model uses functions, methods, and modules in the associated context, these modules are referenced through an engineering method to complete the engineering association of the code completion content.
[0111] The position where the cursor is located is the end position of the input operation. If the type of the input content is a text annotation type, the target completion code can be directly written into the position.
[0112] If the input content type is a code type, and the user has already entered a code in the input operation, the code entered in the input operation can be replaced with the target completion code. It can be understood that the target completion code includes the code entered in the input operation. After the code completion is completed, the target function description can be written as a comment after the completed code.
[0113] In this embodiment, the target candidate code module selected by the user and the code in the code editing interface can be input into the code completion large language model to generate corresponding second code completion content. When inputting, it is necessary to input a constraint condition representing that the target candidate code module is used as a part of the second code completion content, so that the second code completion content includes the target candidate code module selected by the user.
[0114] The second generated code completion content has a target candidate code module selected by the user, and the target candidate code module already exists in the target code project. Therefore, the reference path of the code module in the target code project can be used to reference the target candidate code module, so that the code in other files in the target code project can be referenced in the current code editing interface when performing code completion. In this application, the reference path can usually be a relative path of the target candidate code module, and the relative path refers to the position of the target candidate code module relative to the file or directory of the currently edited code. The relative path can be determined based on the absolute path of the target candidate code module and the position of the file or directory of the currently edited code.
[0115] Optionally, before the step of determining a reference path of the target candidate code module included in the second code completion content in the target code project, the following may also be included:
[0116] For the target candidate code module, determine whether the target candidate code module has been globally mounted or exported;
[0117] If the target candidate code module has been globally mounted or exported, then performing a step of determining a reference path of the target candidate code module contained in the second code completion content in the target code project;
[0118] Otherwise, the second code completion content is used as the target completion code, and the specified completion operation is performed using the target completion code.
[0119] In some cases, the code module needs to be globally mounted or exported before it can be referenced. Therefore, in this case, if the target candidate code module is not globally mounted or exported, it can be completed directly using the second code completion content without being referenced. And after determining that the target candidate code module is not globally mounted or exported, a prompt message representing that the target candidate code module can be optimized can be displayed in the target window to remind the user to globally mount or export the target candidate code module. Wherein, the global mounting refers to mounting some variables, functions, components or instructions, etc. on a global scope or instance so that they can be easily used in the entire code project. The code module has been exported, which means that a part of the code in the code project, i.e., the code module, has been encapsulated and is ready to be used or referenced by the code of other parts in the code project.
[0120] In one implementation, in response to a user issuing a second completion instruction in the target window, determining a reference path of the target candidate code module selected by the user in the target code project;
[0121] The reference code corresponding to the reference path is written into the position of the cursor in the code editing interface.
[0122] When the user believes that a target candidate code module in the target window can be directly used as the completion content, the second completion instruction can be issued to complete the code using the selected target candidate code module as the completion content. It can be understood that the target candidate code module already exists in the target code project, so the code module can be referenced by using the reference path of the code module in the target code project, so that the code in other files in the target code project can be referenced in the current code editing interface when completing the code.
[0123] Optionally, before the step of determining the reference path of the target candidate code module selected by the user in the target code project, the following steps may also be included:
[0124] For the target candidate code module, determine whether the target candidate code module has been globally mounted or exported;
[0125] If the target candidate code module has been globally mounted or exported, then executing the step of determining a reference path of the target candidate code module selected by the user in the target code project;
[0126] Otherwise, the target candidate code module is used as the target completion code, and the specified completion operation is performed using the target completion code.
[0127] The reason why this embodiment determines that the target candidate code module is globally mounted or exported is the same as that in the above embodiment, and will not be elaborated here.
[0128] In one implementation, in response to a user issuing a third completion instruction in the target window, if the type of the input content is a text comment type, the code in the code editing interface is input into the code completion large language model, so that the code completion large language model outputs a third code completion content; and the third code completion content is used as the target completion code, and the specified completion operation is performed using the target completion code; and, if the type of the input content is a code type, the first code completion content is used as the target completion code, and the specified completion operation is performed using the target completion code.
[0129] When the user believes that none of the target candidate code modules in the target window can be used as completion content, a third completion instruction can be issued, and when the type of the input content is a text annotation type, in response to the third completion instruction issued by the user, the code in the code editing interface can be input into the code completion large language model, so that the code completion large language model outputs a third code completion content; the third code completion content is used as the target completion code, and the target completion code is used to perform a specified completion operation.
[0130] If the type of the input content is a code type, because the step of inputting the code in the code editing interface into the code completion large language model and outputting the first code completion content has been executed in step S102, the first code completion content can be directly used as the target completion code, and the specified completion operation can be performed using the target completion code.
[0131] In the above embodiments, the physical meanings of the designated completion operation representations are the same and will not be elaborated herein.
[0132] For example, Figure 3 As shown, an exemplary schematic diagram of a target window is provided for the present application.
[0133] like Figure 3 As shown, the target window may include various target completion contents, as well as three buttons: insert context, use directly, and skip. If the user selects the target completion content and clicks the insert context button, the first completion instruction is triggered; if the user selects the target completion content and clicks use directly, the second completion instruction is triggered; if the user clicks skip, the third completion instruction is triggered.
[0134] According to the scheme provided by the embodiment of the present invention, after the user performs an input operation in the code editing interface, the auxiliary programming plug-in can first determine the content to be analyzed for code completion based on the type of the input content in a predetermined manner, and then determine the target candidate code module that matches the functional description of the content to be analyzed in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in the present application are the various candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the code completion is completed by using the candidate code modules in the target database, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this scheme.
[0135] In addition, the solution of this application deeply integrates large-scale machine learning models and is specially designed for the structure of front-end engineering and the grammatical characteristics of specific technology stacks. The core advantage of the solution of this application is that it can significantly improve the relevance of auxiliary generated code with existing engineering code, thereby optimizing the development process and enhancing the consistency and maintainability of the code. The code completed by the solution of this application has a high degree of match with the front-end business scenario.
[0136] Compared with traditional solutions, the solution of this application not only focuses on the generation of a single code snippet during the code generation process through an engineering methodology, but also further improves the modularization level of the entire project and the relevance between the various code parts. This method avoids the generation of code snippets that are separated from other parts of the project and lack connection, reduces the generation of redundant code, and helps maintain the neatness and efficiency of the code.
[0137] The following is an exemplary introduction to the method of determining each candidate code module stored in the target database and the functional description corresponding to each candidate code module.
[0138] The method for determining each candidate code module stored in the target database and the functional description corresponding to each candidate code module includes steps A1-A4:
[0139] Step A1, identifying the file type of each file of the target code project;
[0140] Step A2, based on the file types of the various files, determining from the various files the first type of files related to the component code, the second type of files related to the function body code, and the third type of files related to the static constants;
[0141] Step A3, determining the code in the first category of files to obtain a candidate code module belonging to a component code type, extracting the function body code from the second category of files to obtain a candidate code module belonging to a function body code type, and extracting the static constant code from the third category of files to obtain a candidate code module belonging to a static constant type;
[0142] Step A4: for each obtained candidate code module, identify the function description corresponding to the candidate code module.
[0143] In this application, the component code refers to the code corresponding to the component in the front-end project. In the front-end project, a component is a code module that can contain UI (User Interface), style and logic, and the component is highly reusable. Files related to the component can be determined by the file's suffix identifier and the framework feature identifier. Exemplarily, in the React framework (a front-end framework), component files usually end with a .jsx or .js suffix, and the file name usually corresponds to the component name. .jsx and .js are the above-mentioned suffix identifiers, and the React framework is the above-mentioned framework feature identifier. Thus, after determining the component-related files based on the file's suffix identifier and the framework feature identifier, the code module can be extracted from the component-related files as a candidate code module.
[0144] The function body code is a complete functional logic code module, and its expression in the code mainly includes ordinary function declarations, function variables, arrow functions, object methods, callback functions, constructors, classes, and asynchronous functions, etc. The second type of files related to the function body code can be determined by the file type, for example, file types such as js, ts, jsx, tsx, and vue are file types related to the function body code.
[0145] A static constant is a variable whose value does not change while the program is running.
[0146] For component code, the corresponding functional description can be: a component that implements the function of...; for function body code, the corresponding functional description can be: a function body that implements the function of...; for static constants, the corresponding functional description can be: a static constant used for...
[0147] It can be understood that there may be a situation where there is only component code in the first category file, only function body code in the second category file, and only static constant code in the third category file. It is also possible that component code, function body code and static constants may appear in the same file at the same time. In this case, the first category file, the second category file and the third category file can be the same file.
[0148] Extracting component code from the first type of file, extracting function body code content from the second type of file, and extracting static constant code from the third type of file can be performed by regular matching and abstract syntax parsing of the code in the first type of file, the second type of file, or the third type of file, so as to extract component code, function body code module, or static constant code in the file. The regular matching is to match patterns in strings using regular expressions. Regular expressions can be used to find, replace, and parse strings that conform to specific patterns. Abstract syntax parsing refers to the abstract representation and analysis of source code or data structures. Both regular matching and abstract syntax parsing can be completed using existing solutions.
[0149] Optionally, when storing the function body code module in the database, the function name can be used as the key value (a key value used to uniquely identify information), and the anonymous function can generate a uuid (Universally Unique Identifier) as the key value for storage in the database. The fields stored in each function body code module may include the function body, absolute path, whether it is globally mounted, the object / class to which it belongs, whether it has been exported, and the function description (empty by default), etc.
[0150] It can be seen that the solution provided in the embodiment can effectively extract candidate code modules from various files of the target code project.
[0151] like Figure 4 As shown in FIG. 1 , it is an interactive schematic diagram of a target database construction method provided by the present application. Figure 4 As shown, the interaction parties include: developers, editing services, plug-in services, conversational large language models and vector databases. The plug-in services correspond to the auxiliary programming plug-ins of the above-mentioned code editors. The interaction methods include:
[0152] S401, import code project.
[0153] The developer imports the code project into the editing service. The developer is the user mentioned above.
[0154] S402, traverse and read the core code files.
[0155] S401-S402 correspond to the above step A1. The purpose of traversing and reading the core code files is to identify the file type of the core code file of the target code project.
[0156] This step is performed by a plug-in, which is the auxiliary programming plug-in mentioned above.
[0157] It is understandable that when determining each candidate code module, the present application may identify all code files in the code project. Of course, in order to improve efficiency, only the core code files in the code project may be identified. This embodiment only identifies the core code files in the code project. The core code files may be code files in the src (SourceCode, source code) directory.
[0158] S403, matching the component code and function code in the code to the conversational large language model to generate a code function description.
[0159] S403 corresponds to the above steps A2-A4, which matches the component code and function code from the first type of files related to the component code and the second type of files related to the function body code, and inputs them into the conversational large language model to generate the code function description, which will not be described in detail here. The component code and function code correspond to the above candidate code module.
[0160] S404, return to the function description.
[0161] The code function description generated by the conversational large language model is returned to the plug-in.
[0162] S405, the component code and function code are stored locally with the component name / function name / uuid as the key value, and the storage fields include the absolute path of the code, the code content, the export status, the mounting status and the function description, etc. The function description is stored as a vector.
[0163] This step is performed by the plugin.
[0164] S406, storage is successful.
[0165] After executing S405-S406, the code engineering preprocessing is completed, and the preparation work is ready to provide support for subsequent code completion.
[0166] like Figure 5 As shown, it is an interactive schematic diagram of a code completion method provided by the present application when the input content type is a text comment type. Figure 5As shown, the interacting parties include: developers, editing services, plug-in services, session large models, code large models and vector databases; wherein the session large model corresponds to the above-mentioned session large language model, the code large model corresponds to the above-mentioned code completion large language model; the plug-in service corresponds to the auxiliary programming plug-in of the above-mentioned code editor; the code completion method includes:
[0167] S501, write notes.
[0168] The developer writes the comments in the code editing interface. The developer in this embodiment corresponds to the user.
[0169] S502, triggering plug-in code completion.
[0170] When the plugin recognizes the comments written by the developer, it triggers code completion.
[0171] S501-S502 correspond to the above-mentioned S101.
[0172] S503, optimizing the annotation function description according to the fixed format.
[0173] S503 corresponds to the above-mentioned S103 and will not be described in detail here.
[0174] S504, returning the optimized function description.
[0175] The session model returns the functional description to the plug-in.
[0176] S505, vectorize the annotations and perform a functional description similarity search in the database.
[0177] S506, returning the N code contents with the highest similarity.
[0178] S505-S506 correspond to the above-mentioned S104 and will not be elaborated here.
[0179] S507, prompting the developer that there is currently a public function / class / component / variable that is similar to the comment content.
[0180] S508: A list is popped up for the developer to choose. The developer can choose to add context, use directly, or skip.
[0181] S507-S508 correspond to S105 above, and will not be elaborated here. It can be understood that when the developer selects a code module and clicks Add to Context, the first completion instruction is triggered; when the developer selects a code module and clicks Use Directly, the second completion instruction is triggered; when the developer clicks Skip, the third completion instruction is triggered.
[0182] S509: The developer selects the functions / classes / components / variables that may be used and adds them to the context.
[0183] S510, triggering the construction context logic: inserting the code block selected by the developer into the code completion context as a fragment of the project association context.
[0184] S511, calling the code model to generate code.
[0185] S512, returning the code generation result; if the code model generates content based on the understanding, similar functions in the associated context will be directly referenced in the code.
[0186] S513, checking whether the generated code contains a reference to the content in the associated context.
[0187] S514, returning the code completion result and calculating the relative path to introduce the content referenced by the generated code.
[0188] S515, code generation is completed.
[0189] S509-S515 correspond to the operations of completing the code by the first completion instruction described above, and will not be elaborated here.
[0190] S516: The developer believes that the function / class / component / variable in the list meets the requirements and chooses to import it directly after selecting it.
[0191] S517, directly import the selected content.
[0192] S518, calculating the relative path to introduce the content referenced by the generated code.
[0193] S519, inserting annotation information related to the selected content.
[0194] S516-S519 correspond to the operations of completing the code with the second completion instruction described above, and will not be elaborated here.
[0195] After the code is completed based on the second completion instruction, the function description may be written as a code comment to a position corresponding to the comment of the completed code.
[0196] S520, the developer considers the list content useless and chooses to skip it.
[0197] S521, build a code generation context.
[0198] S522, calling the code big model to generate code.
[0199] S523, return to the generated code.
[0200] S524, insert the generated code.
[0201] S525, code generation is completed.
[0202] S520-S525 correspond to the operations of completing the code of the third completion instruction mentioned above, and will not be elaborated here.
[0203] According to the scheme provided by the embodiment of the present invention, after the user performs input operation in the code editing interface and enters the comment, the auxiliary programming plug-in can first determine the functional description of the input comment, and then determine the target candidate code module matching the functional description in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in this application are the various candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the candidate code modules in the target database are used to complete the code completion, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this scheme.
[0204] like Figure 6 As shown, it is an interactive schematic diagram of a code completion method provided by the present application when the type of input content is a code type. Figure 6 As shown, the interacting parties include: developers, editing services, plug-in services, session large models, code large models and vector databases; wherein the session large model corresponds to the above-mentioned session large language model, the code large model corresponds to the above-mentioned code completion large language model; the plug-in service corresponds to the auxiliary programming plug-in of the above-mentioned code editor; the code completion method includes:
[0205] S601, enter code.
[0206] The developer inputs the code in the code editing interface. The developer in this embodiment corresponds to the user.
[0207] S602, triggering code completion.
[0208] When the plug-in recognizes the code entered by the developer, it triggers code completion.
[0209] S601-S602 correspond to the above-mentioned S101.
[0210] S603, construct a code completion context, and input a large code model for code completion.
[0211] S604, returning the code completion result.
[0212] S605, returning the code completion result.
[0213] S604 is when the code big model returns the code completion result to the plug-in service, and S605 is when the plug-in service returns the code completion result to the editing service.
[0214] S606, prompting the developer with the code completion result.
[0215] S607, receiving code completion.
[0216] S608, the plug-in monitors the developer to accept code completion.
[0217] S603-S608 and the above S102, if the type of the input content is a code type, input the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the corresponding content to be analyzed.
[0218] It is understandable that, after the code completion content is generated, the generated code completion content may be provided to the developer, and after the developer accepts the code completion content, subsequent steps are performed.
[0219] S609, generating a functional description of the partial code accepted by the developer.
[0220] S610, return to the function description.
[0221] S611, vectorize the function description and search for similar codes through the vector database.
[0222] S612, returning the first N pieces of data with the highest similarity matching.
[0223] S609-S612 correspond to the above-mentioned S104 and will not be elaborated here.
[0224] S613, initiating a developer prompt box.
[0225] S614, prompting the developer whether to select existing code to replace the generated part.
[0226] S615, the developer clicks to accept a recommended code content.
[0227] S616: The developer accepts the code content in the list.
[0228] S617, import the code into the file and insert the function / class / component / variable reference.
[0229] S618, the developer uses similar codes as associated contexts.
[0230] S619, triggering secondary code completion: inserting the code block selected by the developer into the code completion context as a fragment of the project-related context.
[0231] S620, calling the code big model to generate code.
[0232] S621, returning the code generation result: if the code model generates content based on understanding, similar functions in the associated context will be directly referenced in the code.
[0233] S622, checking whether the generated code contains a reference to the content in the associated context.
[0234] S623, returning the code completion result and calculating the relative path to introduce the content referenced by the generated code.
[0235] S624, code generation is completed.
[0236] S614-S624 correspond to the operations of completing the code with the first completion instruction described above, and will not be elaborated here.
[0237] S625, the developer retains the first generated code.
[0238] S626, code completion is completed.
[0239] S625-S626 correspond to the operation of completing the code of the second completion instruction mentioned above, and will not be elaborated here.
[0240] According to the scheme provided by the embodiment of the present invention, after the user performs input operation in the code editing interface and enters the code, the auxiliary programming plug-in can firstly complete the code input by the user's input operation based on the content of the current code editing interface, and determine the functional description of the completed code, and then determine the target candidate code module matching the functional description in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in the present application are the candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the code completion is completed by using the candidate code modules in the target database, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this solution.
[0241] The present application also provides a code completion device, which is applied to an auxiliary programming plug-in of a code editor, such as Figure 7 As shown, the device comprises:
[0242] The acquisition module 701 is used to acquire input content corresponding to the input operation in response to the user performing the input operation in the code editing interface;
[0243] A first determination module 702 is used to determine the content to be analyzed for code completion based on the type of the input content in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed;
[0244] The identification module 703 is used to identify the function description corresponding to the content to be analyzed as the target function description; wherein the function description corresponding to any content is the description content of the function that can be realized by the content;
[0245] The second determination module 704 is used to determine each target candidate code module matching the target function description from the target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module;
[0246] The output module 705 is used to output each target candidate code module to the target window for the user to select;
[0247] A completion module 706, configured to execute a completion operation corresponding to the specified completion instruction in response to the user issuing the specified completion instruction in the target window, so as to complete code completion for the input content;
[0248] Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction;
[0249] The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user;
[0250] The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user;
[0251] The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
[0252] According to the scheme provided by the embodiment of the present invention, after the user performs an input operation in the code editing interface, the auxiliary programming plug-in can first determine the content to be analyzed for code completion based on the type of the input content in a predetermined manner, and then determine the target candidate code module that matches the functional description of the content to be analyzed in the target database for the user to select, so that after the user issues a specified completion instruction based on the target candidate code module, the auxiliary programming plug-in executes the completion operation corresponding to the specified completion instruction to complete the code completion for the input content. Since the candidate code modules in the target database in the present application are the various candidate code modules and the functional descriptions corresponding to each candidate code module determined after analyzing the various files of the target code project to which the code of the current code editing interface belongs, the code completion is completed by using the candidate code modules in the target database, which can improve the business correlation between the code of the current code editing interface and other files of the target code project; and, in the present invention, different methods are used to determine the content to be analyzed for code completion for different types of input content, so that the content used for code completion has a relatively complete semantic expression, thereby providing a better analysis basis for the code completion process. It can be seen that the accuracy of code completion can be improved through this scheme.
[0253] Optionally, the method for determining each candidate code module stored in the target database and the functional description corresponding to each candidate code module includes:
[0254] Identify the file type of each file of the target code project;
[0255] Based on the file types of the respective files, determining from the respective files a first type of file related to the component code and a second type of file related to the function body code;
[0256] Determine the code in the first category of files to obtain a candidate code module belonging to a component code type, and extract the function body code from the second category of files to obtain a candidate code module belonging to a function body code type;
[0257] For each obtained candidate code module, a functional description corresponding to the candidate code module is identified.
[0258] Optionally, the storage form of the function description corresponding to each candidate code module in the target database is a vector value form;
[0259] Determining each target candidate code module matching the target function description from the target database includes:
[0260] Vectorizing the target function description to obtain a target vector value;
[0261] For each candidate functional module in the target database, calculating the similarity between the target vector value and the vector value of the functional description corresponding to the candidate code module, and obtaining the similarity corresponding to each candidate code module;
[0262] Based on the similarity corresponding to each candidate code module, the candidate code module whose similarity meets the matching condition is used as the target candidate code module.
[0263] Optionally, the method for identifying the functional description corresponding to any content includes: inputting the content into a preset conversational large language model, so that the conversational large language model generates the functional description corresponding to the content.
[0264] Optionally, the input of the conversational large language model further includes target parameters representing format and length constraint values;
[0265] The inputting the content into a preset conversation large language model so that the conversation large language model generates a functional description corresponding to the content includes: inputting the content and the target parameter into the conversation large language model so that the conversation large language model generates a functional description corresponding to the content according to the format and length constraint value represented by the target parameter.
[0266] Optionally, the completion module includes:
[0267] A first completion unit is configured to, in response to a user issuing a first completion instruction in the target window, input a target candidate code module selected by the user and the code in the code editing interface into the code completion large language model, so that the code completion large language model outputs a second code completion content;
[0268] Determine a reference path of the target candidate code module contained in the second code completion content in the target code project;
[0269] The target candidate code module contained in the second code completion content is replaced with the reference code of the target candidate code module to obtain the target completion code; wherein the reference code is generated based on the reference path of the target candidate code module and is used to reference the target candidate code module;
[0270] Utilizing the target completion code to perform a designated completion operation; wherein, if the type of the input content is a text comment type, the designated completion operation is: writing the target completion code to the end position of the input operation; if the type of the input content is a code type, the designated completion operation is: replacing the input content corresponding to the input operation with the target completion code;
[0271] Alternatively, the second completion unit is used to determine the reference code of the target candidate code module selected by the user in the target code project in response to the user issuing a second completion instruction in the target window;
[0272] The reference code is used as a target completion code, and a specified completion operation is performed using the target completion code;
[0273] Alternatively, a third completion unit is used to respond to a user issuing a third completion instruction in the target window. If the type of the input content is a text comment type, the code in the code editing interface is input into the code completion large language model, so that the code completion large language model outputs a third code completion content, and uses the third code completion content as a target completion code, and uses the target completion code to perform a specified completion operation; and if the type of the input content is a code type, uses the first code completion content as a target completion code, and uses the target completion code to perform a specified completion operation.
[0274] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, it includes a processor 801 , a communication interface 802 , a memory 803 and a communication bus 804 , wherein the processor 801 , the communication interface 802 , and the memory 803 communicate with each other via the communication bus 804 .
[0275] The memory 803 is used to store computer programs; the processor 801 is used to implement any of the above-mentioned code completion methods when executing the program stored in the memory 803.
[0276] The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above electronic device and other devices. The memory may include a random access memory (RAM) and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor. The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0277] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned code completion methods are implemented.
[0278] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes the code completion method described in any one of the above embodiments.
[0279] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one 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 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 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 drive Solid State Disk (SSD)), etc.
[0280] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0281] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0282] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A code completion method, characterized in that: An auxiliary programming plug-in applied to a code editor, the method comprising: In response to a user performing an input operation in the code editing interface, obtaining input content corresponding to the input operation; Based on the type of the input content, determine the content to be analyzed for code completion in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed; Identify the function description corresponding to the content to be analyzed as the target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content; Determine each target candidate code module that matches the target function description from the target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module; Output each target candidate code module to the target window for the user to select; In response to a user issuing a specified completion instruction in the target window, executing a completion operation corresponding to the specified completion instruction to complete code completion for the input content; Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction; The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user; The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user; The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
2. The method according to claim 1, characterized in that: The method for determining each candidate code module stored in the target database and the functional description corresponding to each candidate code module includes: Identify the file type of each file of the target code project; Based on the file types of the respective files, determining from the respective files a first category of files related to component codes, a second category of files related to function body codes, and a third category of files related to static constants; Determine the code in the first category of files to obtain a candidate code module belonging to a component code type, extract the function body code from the second category of files to obtain a candidate code module belonging to a function body code type, and extract the static constant code from the third category of files to obtain a candidate code module belonging to a static constant type; For each obtained candidate code module, a functional description corresponding to the candidate code module is identified.
3. The method according to claim 2, characterized in that The storage form of the function description corresponding to each candidate code module in the target database is a vector value form; Determining each target candidate code module matching the target function description from the target database includes: Vectorizing the target function description to obtain a target vector value; For each candidate functional module in the target database, calculating the similarity between the target vector value and the vector value of the functional description corresponding to the candidate code module, and obtaining the similarity corresponding to each candidate code module; Based on the similarity corresponding to each candidate code module, the candidate code module whose similarity meets the matching condition is used as the target candidate code module.
4. The method according to any one of claims 1 to 3, characterized in that: Methods for identifying the functional description corresponding to any content include: The content is input into a preset conversational large language model so that the conversational large language model generates a functional description corresponding to the content.
5. The method according to claim 4, characterized in that The input of the conversational large language model also includes target parameters representing format and length constraint values; The inputting the content into a preset conversation large language model so that the conversation large language model generates a functional description corresponding to the content includes: The content and the target parameters are input into a conversation large language model, so that the conversation large language model generates a functional description corresponding to the content according to the format and length constraint value represented by the target parameters.
6. The method according to claim 1, characterized in that In response to the user issuing a specified completion instruction in the target window, executing a completion operation corresponding to the specified completion instruction to complete code completion for the input content includes: In response to a user issuing a first completion instruction in the target window, inputting a target candidate code module selected by the user and the code in the code editing interface into the code completion large language model, so that the code completion large language model outputs a second code completion content; Determine a reference path of the target candidate code module contained in the second code completion content in the target code project; The target candidate code module contained in the second code completion content is replaced with the reference code of the target candidate code module to obtain the target completion code; wherein the reference code is generated based on the reference path of the target candidate code module and is used to reference the target candidate code module; Utilizing the target completion code to perform a designated completion operation; wherein, if the type of the input content is a text comment type, the designated completion operation is: writing the target completion code to the end position of the input operation; if the type of the input content is a code type, the designated completion operation is: replacing the input content corresponding to the input operation with the target completion code; or, In response to a user issuing a second completion instruction in the target window, determining a reference code in the target code project of the target candidate code module selected by the user; The reference code is used as a target completion code, and a specified completion operation is performed using the target completion code; or, In response to the user issuing a third completion instruction in the target window, if the type of the input content is a text comment type, the code in the code editing interface is input into the code completion large language model, so that the code completion large language model outputs a third code completion content, and the third code completion content is used as a target completion code, and the target completion code is used to perform a specified completion operation; and if the type of the input content is a code type, the first code completion content is used as a target completion code, and the target completion code is used to perform a specified completion operation.
7. A code completion device, characterized in that: An auxiliary programming plug-in applied to a code editor, the device comprising: An acquisition module, configured to acquire input content corresponding to an input operation performed by a user in a code editing interface; A first determination module is used to determine the content to be analyzed for code completion based on the type of the input content in a predetermined determination method; wherein the predetermined determination method includes, if the type of the input content is a text comment type, using the input content as the content to be analyzed, and if the type of the input content is a code type, inputting the code in the code editing interface into a preset code completion large language model, so that the code completion large language model outputs a first code completion content to obtain the content to be analyzed; An identification module, used to identify the function description corresponding to the content to be analyzed as a target function description; wherein the function description corresponding to any content is a description of the function that can be realized by the content; A second determination module is used to determine each target candidate code module matching the target function description from a target database; wherein the target database stores: each candidate code module determined after analyzing each file of the target code project to which the code of the current code editing interface belongs and the function description corresponding to each candidate code module; The output module is used to output each target candidate code module to the target window for the user to select; A completion module, configured to respond to a user issuing a specified completion instruction in the target window and execute a completion operation corresponding to the specified completion instruction to complete code completion for the input content; Wherein, the specified completion instruction includes a first completion instruction, a second completion instruction or a third completion instruction; The first completion instruction is an instruction for instructing to complete the code with the second code completion content; wherein the second code completion content is generated based on the target candidate code module selected by the user and the code in the code editing interface, and includes the target candidate code module selected by the user; The second completion instruction is an instruction for instructing to complete the code with the target candidate code module selected by the user; The third completion instruction is an instruction for instructing to complete the code based on the code completion content generated based on the code in the code editing interface.
8. The device according to claim 7, characterized in that The method for determining each candidate code module stored in the target database and the functional description corresponding to each candidate code module includes: Identify the file type of each file of the target code project; Based on the file types of the respective files, determining from the respective files a first category of files related to component codes, a second category of files related to function body codes, and a third category of files related to static constants; Determine the code in the first category of files to obtain a candidate code module belonging to a component code type, extract the function body code from the second category of files to obtain a candidate code module belonging to a function body code type, and extract the static constant code from the third category of files to obtain a candidate code module belonging to a static constant type; For each obtained candidate code module, a functional description corresponding to the candidate code module is identified.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-6 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Code editing method and device, server, user equipment and storage medium
CN112817583A
Question and answer model-based code completion method, code completion terminal, medium and system
CN118170354A