Code recommendation method, device, equipment and medium

By extracting the cursor information and code structure information in the editor and inputting it into the target model, the problem of difficult processing of long code files is solved, and the accuracy and development efficiency of code recommendations are improved.

CN119248243BActive Publication Date: 2025-06-24BEIJING QIHOOD TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411774818.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-06-24
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

During the code development process, due to the limitations of model and hardware resources, long code files are difficult to effectively process, which may lead to problems such as processor video memory errors, code truncation, model illusion, code duplication generation and generation errors.

Method used

By obtaining the cursor information and code structure information in the editor, extract the target-related code information corresponding to the cursor information from the current file and input it into the target model to generate recommended code information. This method ensures the integrity of code information and the reasonable length of the code input in the model, avoiding the processor video memory error and code truncation problems.

Benefits of technology

It improves the efficiency of extracting the corresponding target-related code information of cursor information, enhances the accuracy of code recommendations and the completeness of semantic understanding, reduces the possibility of model generation errors, and improves the efficiency of code development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248243B_ABST
    Figure CN119248243B_ABST
Patent Text Reader

Abstract

The present application discloses a code recommendation method, apparatus, device and medium. Among them, the method includes: extracting target relevant code information such as a target upper-context relevant code segment and a target lower-context relevant code segment corresponding to the cursor information with complete semantics from the current file according to the cursor information in the editor and the code structure information of the current file in the editor; inputting the cursor information and the target relevant code information into a target large model to obtain target recommended code information corresponding to the cursor information, which not only ensures the relevance between the target relevant code information and the cursor information to a certain extent while improving the extraction efficiency of the target relevant code information corresponding to the cursor information, but also improves the relevance between the code recommendation process using the target large model and the cursor context by inputting the target relevant code information with complete semantics, maintains the integrity of semantic understanding in the code recommendation process of the target large model, improves the accuracy of code recommendation, and assists developers to achieve intelligent office work.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a code recommendation method, apparatus, device, and medium. Background Art

[0002] In the scenario of code development, during the process of code development by developers, generally, developers need to rely on the mouse and keyboard to write code. The speed of code writing completely depends on the proficiency of software engineers in using the mouse and keyboard, and each operation has a delay, resulting in low interaction efficiency and code writing efficiency in the entire code development process.

[0003] In related technologies, in order to simplify the code development process, intelligent code completion and code generation tools have gradually been adopted to assist developers in code development. These tools usually use machine learning technologies, especially natural language processing (NLP) models, to predict and recommend code snippets. However, due to the limitations of the model and hardware resources, it is often unable to handle well when the code file is too long. For example, it may cause the processor video memory to report an error and crash, or the code may be randomly truncated directly, resulting in incomplete code semantics. It may cause problems such as model hallucinations, or repeated code generation and generation errors. Summary of the Invention

[0004] The embodiments of this application provide a code recommendation method, apparatus, device, and medium, which can, to a certain extent, ensure the relevance between the target-related code information and the cursor information while improving the extraction efficiency of the target-related code information corresponding to the cursor information, and also improve the relevance between the code recommendation process using the target large model and the cursor context by inputting the target-related code information with complete semantics, maintain the integrity of semantic understanding in the process of code recommendation using the target large model, and improve the accuracy of code recommendation. The above technical solutions are as follows:

[0005] In a first aspect, the embodiments of this application provide a code recommendation method, and the method includes:

[0006] Obtain the cursor information in the editor; the cursor information includes the cursor position;

[0007] According to the cursor information and the code structure information of the current file in the editor, extract the target-related code information corresponding to the cursor information from the current file; the target-related code information includes the target-related code segment with complete semantics corresponding to the cursor information; the target-related code segment includes at least one of the following: the target upper-context related code segment corresponding to the cursor position, the target lower-context related code segment;

[0008] Input the cursor information and the target-related code information into the target large model to obtain the target recommended code information corresponding to the cursor information.

[0009] In a possible implementation manner, extracting the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor includes:

[0010] Determining the target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor;

[0011] Extracting the target relevant code information corresponding to the cursor information from the target class code range of the current file.

[0012] In a possible implementation manner, extracting the target relevant code information corresponding to the cursor information from the target class code range of the current file includes:

[0013] When the code length of the target class code range is less than or equal to the threshold, determining the target upper-context relevant code segment according to the first start position of the target class code range and the cursor position, and / or determining the target lower-context relevant code segment according to the first end position of the target class code range and the cursor position;

[0014] When the code length of the target class code range is greater than the threshold, determining the target function information corresponding to the cursor position in the target class code range;

[0015] When the target function information is less than or equal to the threshold, determining the target upper-context relevant code segment according to the second start position of the target function information and the cursor position, and / or determining the target lower-context relevant code segment according to the second end position of the target function information and the cursor position.

[0016] In a possible implementation manner, extracting the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor includes:

[0017] Determining the target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor;

[0018] Extracting the initial relevant code information corresponding to the cursor information from the target class code range of the current file according to the code length of the target class code range;

[0019] Filter the second function variable information outside the target class code range in the current file according to the first function variable information within the target class code range, and obtain the target function variable information related to the first function variable information;

[0020] Determine the target related code information corresponding to the cursor information according to the above initial related code information and the above target function variable information.

[0021] In a possible implementation manner, before inputting the cursor information and the target related code information into the target large model to obtain the target recommended code information corresponding to the cursor information, the method further includes:

[0022] When the text length corresponding to the current file is less than or equal to the threshold, determine the full text information corresponding to the current file as the target related code information corresponding to the cursor information;

[0023] When the text length corresponding to the current file is greater than the threshold, execute the step of extracting the target related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor.

[0024] In a possible implementation manner, before inputting the cursor information and the target related code information into the target large model to obtain the target recommended code information corresponding to the cursor information, the method further includes:

[0025] When the cursor position is not within any function range of the current file or only within the class function range of the current file or not within any sub - element of the current file, determine the target related code information corresponding to the cursor information according to the function information set corresponding to the current file and the cursor position;

[0026] and / or

[0027] When the current file is a specified language class file, determine the code information of the preset context lines corresponding to the cursor position in the current file as the target related code information corresponding to the cursor information.

[0028] In a possible implementation manner, after inputting the cursor information and the target related code information into the target large model to obtain the target recommended code information corresponding to the cursor information, the method further includes:

[0029] Determine the target recommended code length corresponding to the target recommended code information;

[0030] According to the above cursor position and the above target recommended code length, display the above target recommended code information in the editing interface corresponding to the above editor according to a preset display method.

[0031] In a second aspect, an embodiment of the present application provides a code recommendation device, and the above code recommendation device includes:

[0032] An acquisition module, configured to acquire cursor information in an editor; the above cursor information includes a cursor position;

[0033] An extraction module, configured to extract target-related code information corresponding to the above cursor information from the above current file according to the above cursor information and the code structure information of the current file in the above editor; the above target-related code information includes a target-related code segment with complete semantics corresponding to the above cursor information; the above target-related code segment includes at least one of the following: a target upper-context related code segment corresponding to the above cursor position, a target lower-context related code segment.

[0034] A code recommendation module, configured to input the above cursor information and the above target-related code information into a target large model to obtain target recommended code information corresponding to the above cursor information.

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

[0036] The above processor is connected to the above memory;

[0037] The above memory is used to store executable program code;

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

[0039] In a fourth aspect, an embodiment of this specification provides a computer storage medium, and the above computer storage medium stores multiple instructions, and the above instructions are suitable for being loaded and executed by a processor to execute the method provided in the first aspect or any possible implementation manner of the first aspect of the embodiments of this specification.

[0040] In one or more embodiments of the present application, on the one hand, according to the cursor information in the editor and the code structure information of the current file in the editor, target relevant code information such as target upper-context relevant code segments and target lower-context relevant code segments corresponding to the cursor information is extracted from the current file (target relevant code segments). Thus, by only extracting from the current file instead of the entire target project file, the code to be analyzed is less compared to the code of the entire target project, ensuring the relevance between the target relevant code information and the cursor information to a certain extent while improving the extraction efficiency of the target relevant code information corresponding to the cursor information. Moreover, the extraction of code information with complete semantics corresponding to the cursor position can be achieved according to the code structure information of the current file where the cursor is located in the editor. On the other hand, the cursor information and the target relevant code information with complete semantics are input into the target large model, and the target relevant code information with complete semantics is used to assist the target large model in generating target recommended code information corresponding to the cursor information. This not only reduces the code length input to the target large model, avoiding problems such as the processor's video memory reporting an error and crashing due to the overly long current file where the cursor is located being directly input into the target large model, or the code being randomly truncated directly resulting in incomplete code semantics, which may cause problems such as model hallucinations, or code being repeatedly generated and generated incorrectly, improving the efficiency of the target large model in generating target recommended code information, but also improves the relevance between the code recommendation process using the target large model and the cursor context by inputting the target relevant code information with complete semantics, maintaining the integrity of semantic understanding in the code recommendation process of the target large model, and improving the accuracy of code recommendation. Furthermore, the target large model is used to assist developers in realizing artificial intelligence (AI) office.

[0041] The above description is only an overview of the technical solution of the present application. In order to be able to understand the technical means of the present application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable, the following specifically describes the embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0043] Figure 1 It is a schematic diagram of the architecture of a code recommendation system provided for an exemplary embodiment of the present application;

[0044] Figure 2A schematic flowchart of a code recommendation method provided by an exemplary embodiment of the present application;

[0045] Figure 3 A schematic flowchart of an extraction process of target-related code information provided by an exemplary embodiment of the present application;

[0046] Figure 4 Another schematic flowchart of an extraction process of target-related code information provided by an exemplary embodiment of the present application;

[0047] Figure 5 Another schematic flowchart of a code recommendation method provided by an exemplary embodiment of the present application;

[0048] Figure 6 Another schematic flowchart of a code recommendation method provided by an exemplary embodiment of the present application;

[0049] Figure 7 A schematic display diagram of target recommended code information provided by an exemplary embodiment of the present application;

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

[0051] Figure 9 A schematic structural diagram of a code recommendation device provided by an exemplary embodiment of the present application;

[0052] Figure 10 A schematic structural diagram of an electronic device provided by an exemplary embodiment of the present application. Detailed implementation manners

[0053] To make the features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of the present application.

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

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

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

[0057] In the embodiments of this specification, the terminal 110 can be the client corresponding to users such as software developers who need code recommendation. During the process of a user using an editor to write a code file, it is possible but not limited to obtaining the cursor information in the editor on the terminal 110, and the cursor information includes the cursor position. After the terminal 110 obtains the cursor information, it can first extract the target-related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor. The target-related code information includes the target-related code segment with complete semantics corresponding to the cursor information, and the target-related code segment includes at least one of the following: the target upper-context related code segment corresponding to the cursor position, the target lower-context related code segment. Then, the cursor information and the target-related code information are input into the target large model to obtain the target recommended code information corresponding to the cursor information.

[0058] Optionally, when the terminal 110 obtains the cursor information in the editor and the target-related code information corresponding to the cursor information, it can also directly send the cursor information in the above editor and the target-related code information corresponding to the cursor information to the server 120 through the network, so that the server 120 generates and returns the target recommended code information corresponding to the cursor information according to the code recommendation method provided by the embodiments of this application.

[0059] Server 120 may be a server that provides various code recommendation services or software supply chain graph construction services. It should be noted that server 120 may be hardware or software. When server 120 is hardware, it can be implemented as a distributed server cluster composed of multiple servers or as a single server. When server 120 is software, it can be implemented as multiple software or software modules (such as those used to provide distributed services), or as a single software or software module, and no specific limitation is made here. Server 120 may but is not limited to being a hardware server, a virtual server, a cloud server, etc.

[0060] Specifically, after receiving the cursor information in the editor sent by terminal 110 and the target-related code information corresponding to the cursor information, server 120 can also perform corresponding code recommendations through the code recommendation method provided in the embodiments of the present application and return the generated corresponding target recommended code information to terminal 110.

[0061] It can be understood that the code recommendation method provided in the embodiments of the present application can be executed independently by terminal 110, can also be executed independently by server 120, or can be jointly executed by terminal 110 and server 120. The embodiments of the present application do not make any limitation in this regard.

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

[0063] It can be understood that Figure 1 The number of terminals 110 and servers 120 in the shown code recommendation system is only an example. In specific implementation, the code recommendation system may include any number of terminals 110 and servers 120.

[0064] Next, in combination with Figure 1 , taking terminal 110 executing code recommendation as an example, the code recommendation method provided in an exemplary embodiment of the present application will be introduced. Specifically, please refer to Figure 2 , which exemplarily shows the flowchart of a code recommendation method provided in the embodiments of the present application. As Figure 2 shown, the code recommendation method includes the following steps:

[0065] S201. Obtain the cursor information in the editor, where the cursor information includes the cursor position.

[0066] Specifically, a code recommendation function is set in the editor. During the process of a user writing code using the editor, when the code recommendation function of the editor is in the enabled state, the cursor information in the editor can be obtained first, so as to implement code recommendation according to the cursor information subsequently. In addition to the cursor position, the above cursor information may also include, but is not limited to, the line code information where the above cursor position is located. The above cursor position may be the line information where the cursor is located in the editor, or may include the line information and column information where the cursor is located in the editor. The embodiments of the present application do not make any limitations in this regard.

[0067] S202. Extract the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor, where the target relevant code information includes the target relevant code segment with complete semantics corresponding to the cursor information.

[0068] Specifically, the above current file is the code file that the developer is currently editing in the editor. The above code structure information may include the abstract syntax tree information corresponding to the current file, or may include, but is not limited to, the class code information in the current file (such as, but not limited to, the line number range where each class code is located and the corresponding attribute information, etc.) and the function code information (such as, but not limited to, the line number range where each function code is located and the corresponding attribute information, variable information, etc.). The above target relevant code segment may include, but is not limited to, at least one of the following: the target upper context relevant code segment corresponding to the cursor position, the target lower context relevant code segment. The above target relevant code information may also include the target position information corresponding to the target relevant code segment, so as to not only provide the target relevant code segment corresponding to the cursor position for the target large model to perform code recommendation, but also provide the relationship between the position corresponding to the target relevant code segment and the cursor position, thereby improving the accuracy of the target large model in performing code recommendation.

[0069] Optionally, as Figure 3 shown, the implementation process of the above S202 to extract the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor may include, but is not limited to:

[0070] S301. Determine the target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor.

[0071] Specifically, during the process of a user writing code using an editor, the content of the current file in the editor can be parsed in real-time or at a preset interval (such as but not limited to every 1 minute, every 30 seconds, etc.), the abstract syntax tree of the code in the current file can be recognized and constructed, and then the abstract syntax tree can be traversed to locate the target class node at the cursor position (cursor location), and determine the target class code range of the target class node. The above target class code range can be composed of, for example but not limited to, the first start position information (such as but not limited to the line number of the code where the first start position is located) and the first end position information (such as but not limited to the line number of the code where the first end position is located) of the above target class node.

[0072] S302, extract the target related code information corresponding to the cursor information from the target class code range of the current file.

[0073] Optionally, one or more target code segments with complete semantics can be directly extracted from the target class code range of the current file according to the code structure in the target class code range of the current file. For example but not limited to, all target code segments with complete semantics in the target class code range or the target upper context related code segment and / or target lower context related code segment closest to the cursor position in the target class code range can be extracted, so as to obtain the target related code information corresponding to the cursor information.

[0074] Optionally, after determining the target class code range where the cursor position is located in the current file, it can first be judged whether the code length of the target class code range is less than or equal to a threshold. When the code length of the target class code range is less than or equal to the threshold, it means that the code length corresponding to the target class code range where the cursor is located will not exceed the input length threshold of the target large model, that is, inputting the code segment corresponding to the target class code range with complete semantics into the target large model will not cause the problem that the input data is truncated due to the excessive length of the input data, resulting in incomplete semantics of the input data and affecting the accuracy of code recommendation. Then, the target upper context related code segment can be directly determined according to the first start position of the target class code range and the cursor position, that is, the above target upper context related code segment can be the code segment in the corresponding range from the first start position to the cursor position in the current file, and / or, the target lower context related code segment can be determined according to the first end position of the target class code range and the cursor position, that is, the above target lower context related code segment can be the code segment in the corresponding range from the cursor position to the first end position in the current file. The above threshold is less than or equal to the input length threshold of the target large model, so that while avoiding the data length input into the target large model exceeding the input length threshold of the target large model, target related code information with complete semantics can be obtained.

[0075] When the code length of the target class code range is greater than the threshold, it indicates that the code length corresponding to the target class code range where the cursor is located is likely to exceed the input length threshold of the target large model. That is, during the code recommendation process, it is very likely that due to the excessive length of the code segment corresponding to the target class code range with complete semantics, the input to the target large model will be truncated, resulting in incomplete semantics and affecting the accuracy of code recommendation. In this case, the target function information corresponding to the cursor position within the target class code range can be determined first. Then, when the target function information is less than or equal to the threshold, the target upper-context related code segment is determined based on the second start position of the target function information and the cursor position. That is, the above-mentioned target upper-context related code segment can be the code segment within the range from the second start position to the cursor position in the current file, and / or the target lower-context related code segment is determined based on the second end position of the target function information and the cursor position. That is, the above-mentioned target lower-context related code segment can be the code segment within the range from the cursor position to the second end position in the current file. When the target function information is greater than the threshold, the sub-elements with complete semantics in the target function information, namely the target upper-context related code segment and / or the target lower-context related code segment, can be directly extracted according to the cursor position. For example, but not limited to, directly extracting the sub-element with complete semantics where the cursor is located or the previous sub-element with complete semantics at the cursor position (target upper-context related code segment) and / or the next sub-element with complete semantics (target lower-context related code segment), or directly extracting the sub-element with the highest code correlation corresponding to the cursor position in the target function information, etc.

[0076] The embodiments of the present application not only ensure the semantic integrity of the target-related code information extracted from the current file to improve the accuracy of code recommendation by the target large model, but also can reduce the code length input to the target large model, avoiding the problem that the current file where the cursor is located is too long and directly inputting it to the target large model may cause the processor video memory to report an error and crash, or the code is directly truncated randomly, resulting in incomplete code semantics, which may cause problems such as model hallucinations, or code duplication and generation errors. It improves the efficiency of the target large model to generate target recommended code information.

[0077] Optionally, as Figure 4 shown, the implementation process of the above S202, extracting the target-related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor, can but not limited to include:

[0078] S401, according to the code structure information of the current file in the editor, determine the target class code range where the cursor position is located in the current file.

[0079] Specifically, the above S401 is the same as S301, and will not be elaborated here.

[0080] S402. Extract the initial relevant code information corresponding to the cursor information from within the target class code range of the current file according to the code length of the target class code range.

[0081] Specifically, the above initial relevant code information may, but is not limited to, include the initial relevant code segments with complete semantics corresponding to the cursor position, such as, but not limited to, the initial upstream relevant code segments and / or the initial downstream relevant code segments. The extraction method of the above initial relevant code information is the same as the second optional implementation manner of extracting the target relevant code information in the above S302, and will not be elaborated here.

[0082] Optionally, when the cursor position is not within any class code range in the current file, if the cursor position is within a function code segment, the function code segment where the cursor position is located can be directly extracted as the initial relevant code segment; if the cursor position is also within a function code segment, the previous function code segment and / or the next function code segment corresponding to the cursor position can be directly extracted as the initial relevant code segment, so as to ensure the integrity of the extracted initial relevant code segment.

[0083] Next, please continue to refer to Figure 4 , as Figure 4 shown, after the above S401 determines the target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor, it may further include:

[0084] S403. Filter the second function variable information outside the target class code range in the current file according to the first function variable information within the target class code range to obtain the target function variable information related to the first function variable information.

[0085] Specifically, in order to enhance the relevance between the initial relevant code information corresponding to the cursor position and other code segments in the current file and improve the integrity and semantic richness of the target relevant code information, the second function variable information outside the target class code range in the current file can also be filtered according to the first function variable information within the target class code range. For example, but not limited to, screening out the second function variable information related to the first function variable information from all the second function variable information outside the target class code range in the current file, such as, but not limited to, screening out the second function variable information with the same variable name or not only the same variable name but also the same corresponding variable value as the local variables or parameters in the first function variable information, that is, obtaining the target function variable information related to the first function variable information, so as to avoid the problem that the semantic content of the relevant code segment (initial relevant code information) corresponding to the cursor position is less and affects the accuracy of the target large model code recommendation.

[0086] Understandably, the above S403 and S402 can be executed simultaneously or successively, and the embodiments of the present application do not limit this.

[0087] S404. Determine the target relevant code information corresponding to the cursor information according to the initial relevant code information and the target function variable information.

[0088] Specifically, after obtaining the initial relevant code information corresponding to the cursor information and the target function variable information related to the initial relevant code information, the initial relevant code information and the target function variable information can be directly combined, such as but not limited to splicing, etc., to obtain the target relevant code information corresponding to the cursor information with complete semantics.

[0089] Next, please continue to refer to Figure 2 , as Figure 2 shown, after the above S202, according to the cursor information and the code structure information of the current file in the editor, extract the target relevant code information corresponding to the cursor information from the current file, and after the target relevant code information includes the target relevant code segment corresponding to the cursor information with complete semantics, the code recommendation method further includes:

[0090] S203. Input the cursor information and the target relevant code information into the target large model to obtain the target recommended code information corresponding to the cursor information.

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

[0092] In the embodiments of the present application, on the one hand, according to the cursor information in the editor and the code structure information of the current file in the editor, target related code information (target related code segments) such as target upper context related code segments and target lower context related code segments corresponding to the cursor information are extracted from the current file. Thus, by only extracting from the current file instead of the entire target project file, the code to be analyzed is less compared to the code of the entire target project, ensuring the relevance between the target related code information and the cursor information to a certain extent while improving the extraction efficiency of the target related code information corresponding to the cursor information. Also, the extraction of code information with complete semantics corresponding to the cursor position can be achieved according to the code structure information of the current file where the cursor is located in the editor. On the other hand, the cursor information and the target related code information with complete semantics are input into the target large model, and the target large model is assisted to generate target recommended code information corresponding to the cursor information by the target related code information with complete semantics. This not only reduces the code length input to the target large model, avoiding problems such as the processor video memory reporting an error and crashing due to the overly long current file where the cursor is located being directly input into the target large model, or the code being randomly truncated directly resulting in incomplete code semantics, which may cause problems such as model hallucinations, or code duplication and generation errors, but also improves the efficiency of the target large model in generating target recommended code information. Moreover, by inputting the target related code information with complete semantics, the relevance between the code recommendation process using the target large model and the cursor context is improved, maintaining the integrity of semantic understanding during the code recommendation process using the target large model and enhancing the accuracy of code recommendation. Furthermore, the target large model is utilized to assist developers in realizing AI intelligent office and improving code development efficiency.

[0093] Next, please refer to Figure 5 , which exemplarily shows a flowchart of another code recommendation method provided by the embodiments of the present application. As Figure 5 shown, the code recommendation method includes the following steps:

[0094] S501, Obtain the cursor information in the editor, where the cursor information includes the cursor position.

[0095] Specifically, S501 is the same as S201, and details are not described here again.

[0096] S502, Determine whether the text length corresponding to the current file is less than or equal to a threshold.

[0097] Specifically, the above threshold is less than or equal to the input length threshold of the target large model, so that while avoiding the data length input to the target large model exceeding the input length threshold of the target large model, target related code information with complete semantics can be obtained.

[0098] S503. When the text length of the current file is less than or equal to the threshold, determine the full text information corresponding to the current file as the target relevant code information corresponding to the cursor information.

[0099] Specifically, when the text length of the current file is less than or equal to the threshold, it means that even if the entire current file is input into the target large model, it may not exceed the input length threshold of the target large model. Then, the full text information corresponding to the current file can be directly determined as the target relevant code information corresponding to the cursor information to ensure the integrity and analyzability of the input data of the target large model.

[0100] S504. When the text length of the current file is greater than the threshold, extract the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor.

[0101] Specifically, when the text length of the current file is greater than the threshold, the extraction process of the target relevant code information in S504 above is the same as that in S202 above, and will not be elaborated here.

[0102] Optionally, next, please continue to refer to Figure 5 , such as Figure 5 shown, after S501, obtaining the cursor information in the editor, the code recommendation method may further include, but is not limited to:

[0103] S505. When the cursor position is not within any function range of the current file or only within the class function range of the current file or not within any child element in the current file, determine the target relevant code information corresponding to the cursor information according to the function information set corresponding to the current file and the cursor position.

[0104] Specifically, in addition to determining the extraction method of the target relevant code information according to the text length of the current file, when the cursor position is not within any function range of the current file or only within the class function range of the current file or not within any child element in the current file, the target relevant code information corresponding to the cursor information can also be determined according to the function information set corresponding to the current file and the cursor position. That is, when the cursor position is not within any code segment with complete semantics in the current file, the function information set of the current file can be directly extracted, and it is filtered according to the cursor position to obtain the target relevant code information corresponding to the cursor information. The above function information set may include, but is not limited to, the function code segments in the current file and the corresponding function code position information. For example, but not limited to, the function information corresponding to the function code segment closest to the cursor position in the function information set of the current file can be directly determined as the target relevant code information.

[0105] and / or

[0106] S506. When the current file is a file of a specified language type, determine the code information corresponding to the preset context lines at the cursor position in the current file as the target relevant code information corresponding to the cursor information.

[0107] Specifically, since some specified languages such as SQL, etc., have the integrity of their statements themselves, and each statement cannot be associated with other statements. Therefore, when the current file is a file of a specified language type, the code information corresponding to the preset context lines (such as but not limited to the upper and lower two lines or five lines, etc.) at the cursor position in the current file can be directly determined as the target relevant code information corresponding to the cursor information, and the extraction of the target relevant code information with complete semantics can be achieved.

[0108] S507. Input the cursor information and the target relevant code information into the target large model to obtain the target recommended code information corresponding to the cursor information.

[0109] Specifically, S507 is the same as S203, and will not be elaborated here.

[0110] Next, please refer to Figure 6 , which exemplarily shows the flowchart of another code recommendation method provided by the embodiments of the present application. As Figure 6 shown, the code recommendation method includes the following steps:

[0111] S601. Obtain the cursor information in the editor, and the cursor information includes the cursor position.

[0112] Specifically, S601 is the same as S201, and will not be elaborated here.

[0113] S602. According to the cursor information and the code structure information of the current file in the editor, extract the target relevant code information corresponding to the cursor information from the current file, and the target relevant code information includes the target relevant code segment with complete semantics corresponding to the cursor information.

[0114] Specifically, S602 is the same as S202, and will not be elaborated here.

[0115] S603. Input the cursor information and the target relevant code information into the target large model to obtain the target recommended code information corresponding to the cursor information.

[0116] Specifically, S603 is the same as S203, and will not be elaborated here.

[0117] S604. Determine the target recommended code length corresponding to the target recommended code information.

[0118] Specifically, after obtaining the target recommended code information corresponding to the cursor information, the target recommended code length corresponding to the target recommended code information can be determined first, so that when the target recommended code is displayed subsequently, the position where the following code at the cursor position needs to be shifted down can be known.

[0119] S605, according to the cursor position and the target recommended code length, display the target recommended code information in the editing interface corresponding to the editor according to a preset display manner.

[0120] Specifically, after determining the target recommended code length corresponding to the target recommended code information, the following code at the cursor position can be shifted down by the corresponding number of lines according to the target recommended code length first, and then the target recommended code information is displayed at the cursor position in the editing interface corresponding to the editor, so that the user can intuitively understand the target recommended code information and its corresponding layout in the editing interface corresponding to the editor, improving the observability and practicality of code recommendation. The above target recommended code information can be, but is not limited to, displayed in ghost font.

[0121] Exemplarily, as Figure 7 shown, after obtaining the cursor position 710 and the target recommended code 720, the target recommended code 720 can be directly displayed in ghost font starting from the cursor position 710. At the same time, the acceptance control 730 corresponding to the target recommended code 720 can be, but is not limited to, displayed in the form of a pop-up window. When a developer wants to directly use the target recommended code 720, the target recommended code 720 can be, but is not limited to, directly clicked on the acceptance control 730 to insert the target recommended code 720 at the cursor position 710, without the user having to complete the insertion and use of the target recommended code 720 by means of copying and pasting, further assisting the developer to improve the efficiency of code writing.

[0122] Next, please refer to Figure 8 , which exemplarily shows a schematic diagram of the implementation process of a code recommendation method provided by an embodiment of the present application. As Figure 8 shown, during the process of a developer using an editor to write a code file, the environment information of the editor can be obtained first, for example, the project information in the editor can be obtained first, and then the file currently being edited in the editor (the current file) is obtained according to the project information, and the cursor information in the current file (such as, but not limited to, the cursor position, the code corresponding to the cursor position, etc.) and the code structure information corresponding to the current file (such as, but not limited to, class code information, function code information, etc.) are obtained. Then, according to the cursor information and the code structure information, the target related code information with complete semantics corresponding to the cursor information in the current file is extracted, and the above extraction method can be, but is not limited to, referring to the above Figure 2-5The extraction method described in the corresponding embodiment will not be elaborated here. Then, the cursor information and the target-related code information are input into the target large model, and the target recommended code information corresponding to the cursor information is output. In addition, the target recommended code length corresponding to the target recommended code information can also be determined. And according to the cursor position, the target recommended code length, and the target recommended code information, the editing interface corresponding to the editor is displayed in a preset display manner.

[0123] Next, please refer to Figure 9 , which is a schematic structural diagram of a code recommendation device provided by an exemplary embodiment of the present application. As Figure 9 shown, the code recommendation device 900 includes:

[0124] An acquisition module 910, configured to acquire cursor information in the editor; the above cursor information includes the cursor position;

[0125] An extraction module 920, configured to extract target-related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor; the above target-related code information includes a target-related code segment with complete semantics corresponding to the cursor information; the above target-related code segment includes at least one of the following: a target upper-context related code segment corresponding to the cursor position, a target lower-context related code segment.

[0126] A code recommendation module 930, configured to input the cursor information and the target-related code information into the target large model to obtain the target recommended code information corresponding to the cursor information.

[0127] In a possible implementation manner, the above extraction module 920 includes:

[0128] A first determination unit, configured to determine a target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor;

[0129] A first extraction unit, configured to extract target-related code information corresponding to the cursor information from the target class code range of the current file.

[0130] In a possible implementation manner, the above extraction unit is specifically configured to:

[0131] When the code length of the above target class code range is less than or equal to a threshold, determine the above target upper-context related code segment according to the first start position of the above target class code range and the cursor position, and / or determine the above target lower-context related code segment according to the first end position of the above target class code range and the cursor position;

[0132] When the code length within the above-mentioned target class code range is greater than the above-mentioned threshold, determine the target function information corresponding to the cursor position within the above-mentioned target class code range;

[0133] When the above-mentioned target function information is less than or equal to the above-mentioned threshold, determine the above-mentioned target upper-context related code segment according to the second start position of the above-mentioned target function information and the above-mentioned cursor position, and / or determine the above-mentioned target lower-context related code segment according to the second end position of the above-mentioned target function information and the above-mentioned cursor position.

[0134] In a possible implementation manner, the above-mentioned extraction module 920 includes:

[0135] A second determination unit, configured to determine the target class code range where the cursor position is located in the above-mentioned current file according to the code structure information of the current file in the above-mentioned editor;

[0136] A second extraction unit, configured to extract the initial relevant code information corresponding to the above-mentioned cursor information from the target class code range of the above-mentioned current file according to the code length of the above-mentioned target class code range;

[0137] A filtering unit, configured to filter the second function variable information outside the above-mentioned target class code range in the above-mentioned current file according to the first function variable information within the above-mentioned target class code range, to obtain target function variable information related to the above-mentioned first function variable information;

[0138] A third determination unit, configured to determine the target relevant code information corresponding to the above-mentioned cursor information according to the above-mentioned initial relevant code information and the above-mentioned target function variable information.

[0139] In a possible implementation manner, the above-mentioned code recommendation device 900 further includes:

[0140] A first determination module, configured to determine the full text information corresponding to the above-mentioned current file as the target relevant code information corresponding to the above-mentioned cursor information when the text length corresponding to the above-mentioned current file is less than or equal to the threshold;

[0141] The above-mentioned extraction module 920 is specifically configured to: when the text length corresponding to the above-mentioned current file is greater than the above-mentioned threshold, execute the step of extracting the target relevant code information corresponding to the above-mentioned cursor information from the above-mentioned current file according to the above-mentioned cursor information and the code structure information of the current file in the above-mentioned editor.

[0142] In a possible implementation manner, the above-mentioned code recommendation device 900 further includes:

[0143] A second determination module, configured to, when the cursor position is not within any function scope of the current file or is only within the class function scope of the current file or is not within any child element in the current file, determine target relevant code information corresponding to the cursor information according to the function information set corresponding to the current file and the cursor position;

[0144] and / or

[0145] A third determination module, configured to, when the current file is a specified language class file, determine the code information of a preset context line number corresponding to the cursor position in the current file as the target relevant code information corresponding to the cursor information.

[0146] In a possible implementation manner, the code recommendation device 900 further includes:

[0147] A fourth determination module, configured to determine the target recommended code length corresponding to the target recommended code information;

[0148] A display module, configured to display the target recommended code information in the editing interface corresponding to the editor according to the cursor position and the target recommended code length in a preset display manner.

[0149] The division of each module in the code recommendation device is only for illustrative purposes. In other embodiments, the code recommendation device may be divided into different modules as needed to correspondingly complete all or part of the functions of the code recommendation device. The implementation of each module in the code recommendation device provided in the embodiments of this specification may be in the form of a computer program. This computer program may run on a terminal or a server. The program module constituted by this computer program may be stored in the memory of the terminal or the server. When this computer program is executed by a processor, all or part of the steps of the code recommendation method described in the embodiments of this specification are implemented.

[0150] Next, please refer to Figure 10 , which is a schematic structural diagram of an electronic device provided by an exemplary embodiment of this specification. As Figure 10 shown, the electronic device 1000 may include: at least one processor 1010, at least one communication bus 1020, a user interface 1030, at least one network interface 1040, and a memory 1050.

[0151] Among them, the communication bus 1020 may be used to implement the connection and communication of the above-mentioned components.

[0152] Among them, the user interface 1030 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 1030 may further include a standard wired interface and a wireless interface.

[0153] Among them, the network interface 1040 may optionally include a Bluetooth module, a Near Field Communication (NFC) module, a Wireless Fidelity (Wi-Fi) module, etc.

[0154] Among them, the processor 1010 may include one or more processing cores. The processor 1010 connects various parts within the entire electronic device 1000 through various interfaces and lines. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 1050, and by calling data stored in the memory 1050, it performs various functions of the routing electronic device 1000 and processes data. Optionally, the processor 1010 may be implemented in at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 1010 may be a combination of one or several of an integrated Central Processing Unit (CPU), a Graphics Processing Unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, the user interface, and application programs, etc.; the GPU is responsible for the rendering and drawing of the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 1010 and may be implemented separately by a single chip.

[0155] Among them, the memory 1050 may include a Random Access Memory (RAM), and may also include a Read-Only Memory (ROM). Optionally, the memory 1050 includes a non-transitory computer-readable medium. The memory 1050 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 1050 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing the operating system, instructions for at least one function (such as a fetch function, an extraction function, a code recommendation function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store the data involved in the above-mentioned various method embodiments. Optionally, the memory 1050 may also be at least one storage device located far from the aforementioned processor 1010. Such as Figure 10As shown, the memory 1050, which is a computer storage medium, may include an operating system, a network communication module, a user interface module, and program instructions.

[0156] In some possible embodiments, the electronic device 1000 may be the aforementioned Figure 9 code recommendation device 900 shown. The processor 1010 may be configured to call the program instructions stored in the memory 1050 and specifically perform the following operations: obtain cursor information in the editor; the cursor information includes the cursor position; extract target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor; the target relevant code information includes a target relevant code segment with complete semantics corresponding to the cursor information; the target relevant code segment includes at least one of the following: a target upper context relevant code segment corresponding to the cursor position, a target lower context relevant code segment; input the cursor information and the target relevant code information into a target large model to obtain target recommended code information corresponding to the cursor information.

[0157] In some possible embodiments, when the processor 1010 executes the operation of extracting the target relevant code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor, it is specifically configured to execute:

[0158] Determine a target class code range in the current file where the cursor position is located according to the code structure information of the current file in the editor; extract the target relevant code information corresponding to the cursor information from the target class code range of the current file.

[0159] In some possible embodiments, when the processor 1010 executes the operation of extracting the target relevant code information corresponding to the cursor information from the target class code range of the current file, it is specifically configured to execute: when the code length of the target class code range is less than or equal to a threshold, determine the target upper context relevant code segment according to the first start position of the target class code range and the cursor position, and / or determine the target lower context relevant code segment according to the first end position of the target class code range and the cursor position; when the code length of the target class code range is greater than the threshold, determine target function information corresponding to the cursor position in the target class code range; when the target function information is less than or equal to the threshold, determine the target upper context relevant code segment according to the second start position of the target function information and the cursor position, and / or determine the target lower context relevant code segment according to the second end position of the target function information and the cursor position.

[0160] In some possible embodiments, when the above-mentioned processor 1010 executes the extraction of the target-related code information corresponding to the above-mentioned cursor information from the above-mentioned current file according to the above-mentioned cursor information and the code structure information of the current file in the above-mentioned editor, it is specifically used to execute: determining the target class code range where the above-mentioned cursor position is located in the above-mentioned current file according to the code structure information of the current file in the above-mentioned editor; extracting the initial relevant code information corresponding to the above-mentioned cursor information from the target class code range of the above-mentioned current file according to the code length of the above-mentioned target class code range; filtering the second function variable information outside the target class code range of the above-mentioned current file according to the first function variable information within the above-mentioned target class code range to obtain the target function variable information related to the above-mentioned first function variable information; and determining the target-related code information corresponding to the above-mentioned cursor information according to the above-mentioned initial relevant code information and the above-mentioned target function variable information.

[0161] In some possible embodiments, before the above-mentioned processor 1010 executes the input of the above-mentioned cursor information and the above-mentioned target-related code information into the target large model to obtain the target recommended code information corresponding to the above-mentioned cursor information, it is further used to execute: in the case where the text length corresponding to the above-mentioned current file is less than or equal to the threshold, determining the full text information corresponding to the above-mentioned current file as the target-related code information corresponding to the above-mentioned cursor information; in the case where the text length corresponding to the above-mentioned current file is greater than the above-mentioned threshold, executing the step of extracting the target-related code information corresponding to the above-mentioned cursor information from the above-mentioned current file according to the above-mentioned cursor information and the code structure information of the current file in the above-mentioned editor.

[0162] In some possible embodiments, before the above-mentioned processor 1010 executes the input of the above-mentioned cursor information and the above-mentioned target-related code information into the target large model to obtain the target recommended code information corresponding to the above-mentioned cursor information, it is further used to execute: in the case where the above-mentioned cursor position is not within any function range of the above-mentioned current file or is only within the class function range of the above-mentioned current file or is not within any sub-element in the above-mentioned current file, determining the target-related code information corresponding to the above-mentioned cursor information according to the function information set corresponding to the above-mentioned current file and the above-mentioned cursor position; and / or, in the case where the above-mentioned current file is a specified language class file, determining the code information of the preset context number of lines corresponding to the cursor position in the above-mentioned current file as the target-related code information corresponding to the above-mentioned cursor information.

[0163] In some possible embodiments, after the above-mentioned processor 1010 inputs the above-mentioned cursor information and the above-mentioned target-related code information into the target large model to obtain the target recommended code information corresponding to the above-mentioned cursor information, it is further used to execute: determining the target recommended code length corresponding to the above-mentioned target recommended code information; and displaying the above-mentioned target recommended code information in the editing interface corresponding to the above-mentioned editor in a preset display manner according to the above-mentioned cursor position and the above-mentioned target recommended code length.

[0164] The embodiment of the present application further provides a computer storage medium, in which instructions are stored. When they run on a computer or a processor, the computer or the processor is enabled to execute one or more steps in any of the above-mentioned methods. If each component module of the above-mentioned code recommendation device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in the above-mentioned storage medium.

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

[0166] Those of ordinary skill in the art can understand that all or part of the processes of implementing the above-mentioned embodiment methods can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned method embodiments. The foregoing storage media include: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes. Without conflict, the technical features in this embodiment and the implementation solutions can be combined arbitrarily.

[0167] The above-mentioned embodiments are only described in the preferred embodiment mode of the present application, and do not limit the scope of the present application. Without departing from the design spirit of the present application, various deformations and improvements made by those of ordinary skill in the art to the technical solution of the present application shall fall within the protection scope determined by the claims of the present application.

Claims

1. A code recommendation method, characterized in that: include: Obtaining cursor information in the editor; the cursor information includes the cursor position; Extracting target-related code information corresponding to the cursor information from the current file according to the cursor information and code structure information of the current file in the editor; The target-related code information includes a target-related code segment with complete semantics corresponding to the cursor information; the target-related code segment includes at least one of the following: a target-previous-context-related code segment and a target-next-context-related code segment corresponding to the cursor position; Inputting the cursor information and the target-related code information into the target macro model to obtain the target recommended code information corresponding to the cursor information; The step of extracting target-related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor includes: According to the code structure information of the current file in the editor, the target class code range where the cursor position is located in the current file is determined; according to the code length of the target class code range, the initial related code information corresponding to the cursor information is extracted from the target class code range of the current file; according to the first function variable information within the target class code range, the second function variable information outside the target class code range in the current file is filtered to obtain the target function variable information related to the first function variable information; according to the initial related code information and the target function variable information, the target related code information corresponding to the cursor information is determined.

2. The method according to claim 1, characterized in that Before inputting the cursor information and the target-related code information into the target macro model to obtain the target recommended code information corresponding to the cursor information, the method further includes: In the case where the text length corresponding to the current file is less than or equal to a threshold, determining the full text information corresponding to the current file as the target-related code information corresponding to the cursor information; When the text length corresponding to the current file is greater than the threshold, the step of extracting target-related code information corresponding to the cursor information from the current file based on the cursor information and the code structure information of the current file in the editor is performed.

3. The method according to claim 1, characterized in that: Before inputting the cursor information and the target-related code information into the target macro model to obtain the target recommended code information corresponding to the cursor information, the method further includes: In a case where the cursor position is not located within any function scope of the current file or is only located within a class function scope of the current file or is not located within any sub-element in the current file, determining target-related code information corresponding to the cursor information according to a function information set corresponding to the current file and the cursor position; and / or In the case that the current file is a file of a specified language, code information corresponding to a preset context line number at a cursor position in the current file is determined as target-related code information corresponding to the cursor information.

4. The method according to claim 1, characterized in that After inputting the cursor information and the target-related code information into the target macro model to obtain the target recommended code information corresponding to the cursor information, the method further includes: Determine the target recommended code length corresponding to the target recommended code information; According to the cursor position and the target recommended code length, the target recommended code information is displayed in an editing interface corresponding to the editor in a preset display manner.

5. A code recommendation device, characterized in that: The code recommendation device comprises: An acquisition module, used for acquiring cursor information in the editor; the cursor information includes a cursor position; An extraction module is used to extract target-related code information corresponding to the cursor information from the current file according to the cursor information and the code structure information of the current file in the editor; the target-related code information includes a target-related code segment with complete semantics corresponding to the cursor information; the target-related code segment includes at least one of the following: a target-previous-context-related code segment and a target-next-context-related code segment corresponding to the cursor position; A code recommendation module, used for inputting the cursor information and the target-related code information into a target macro model to obtain target recommended code information corresponding to the cursor information; The extraction module is specifically used to: determine the target class code range where the cursor position is located in the current file according to the code structure information of the current file in the editor, extract the initial related code information corresponding to the cursor information from the target class code range of the current file according to the code length of the target class code range, filter the second function variable information outside the target class code range in the current file according to the first function variable information within the target class code range to obtain the target function variable information related to the first function variable information, and determine the target related code information corresponding to the cursor information according to the initial related code information and the target function variable information.

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

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

Citation Information

Patent Citations

  • SQL (Structured Query Language) code completion method and device, medium and computing equipment

    CN118210487A

  • Code reusability

    US20190391792A1