Code completion method and device

By using the probability prediction model in the code completion system, the problem of delay in calculation results under multiple algorithms is solved, and resource conservation and user experience improvement is achieved.

CN113867710BActive Publication Date: 2025-05-09HUAWEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010607745.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-30
Publication Date
2025-05-09
Estimated Expiration
2040-06-30

AI Technical Summary

Technical Problem

In the case of many code completion algorithms, the power consumption overhead of calculating the final code completion result increases, resulting in the length of time the user waits for the code completion result.

Method used

By receiving the code completion request, the prefix of the target code snippet is determined, and the probability prediction model is used to calculate the potential application probability of each code completion algorithm, and an algorithm with a high potential application probability is selected for calculation, thereby reducing the calculation resource overhead.

Benefits of technology

While ensuring code accuracy, it reduces the power consumption and overhead of calculating code completion results, reduces the delay of users waiting for code completion results, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113867710B_ABST
    Figure CN113867710B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for code completion. The method includes: receiving a code completion request from a code completion client, and determining the prefix of the target code snippet to be completed according to the target code snippet to be completed in the code completion request and the position to be completed of the target code snippet to be completed, and then obtaining the potential application probability corresponding to each code completion algorithm in a plurality of code completion algorithms according to the probability prediction model in the code completion request, the programming language type of the target code snippet to be completed and the prefix of the target code snippet to be completed, and then determining the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm, and finally sending the completion result to the code completion client. In this way, while ensuring the accuracy of the code, the power consumption overhead of calculating the completion result of the code is reduced, thereby reducing the delay of the user waiting for the result of the code completion, and improving the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and more specifically, to a method and device for code completion. Background Art

[0002] A code editor is a tool used by programmers to develop and edit code. In order to reduce the amount of code that programmers enter and improve code development efficiency, a code editor provides a code completion function. The code completion function means that when a programmer types in part of the code, the code editor displays multiple predicted subsequent partial codes in a list. When the predicted subsequent code is consistent or partially consistent with the code that the programmer wants to type in, the programmer will select an item from the list to automatically complete it in the code editor. The longer the length of the code that the programmer chooses to automatically complete, the less code the programmer needs to enter manually, which can reduce the amount of code that the programmer can enter to a greater extent and improve development efficiency more effectively.

[0003] There are many code completion technologies in traditional solutions. For example, the language server specific to each programming language (such as Java, C++, Python, etc.) can parse the source code at the syntax level to obtain the currently available variable names, class names, method names, and function names as the code completion results. Another example is to build a natural language generation model for the code in the code library to generate code completion results.

[0004] With the increase in code completion tools or services, the advantages of multiple code completion algorithms can be comprehensively considered to complement each other and provide better code completion results. For example, for each code completion request, multiple code completion algorithms are used to calculate the code completion results separately, and then the results calculated by multiple code completion algorithms are merged. However, when there are many code completion algorithms, the amount of calculation required to obtain the final code completion result increases accordingly, which in turn increases the time users have to wait for the code completion results. Therefore, how to reduce the time users have to wait for the code completion results is a technical problem that needs to be solved urgently. Summary of the invention

[0005] The present application provides a code completion method, which can reduce the power consumption overhead of calculating the result of code completion.

[0006] In a first aspect, a method for code completion is provided, the method comprising: receiving a code completion request from a code completion client, the code completion request comprising a target code snippet to be completed, a programming language type of the target code snippet to be completed, and a position to be completed of the target code snippet to be completed; determining a prefix of the target code snippet to be completed according to the target code snippet to be completed and the position to be completed of the target code snippet to be completed; determining a potential application probability of each of a plurality of code completion algorithms according to a probability prediction model, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed, the potential application probability referring to a probability that a potential completion code calculated by using each of the code completion algorithms for the code completion request is adopted by a user; determining a completion result of the target code snippet to be completed according to the potential application probability of each of the code completion algorithms; and sending the completion result of the target code snippet to the code completion client.

[0007] The code completion device receives a code completion request from a code completion client, and determines the prefix of the target code snippet to be completed according to the target code snippet to be completed in the code completion request and the position to be completed of the target code snippet to be completed, and then obtains the potential application probability corresponding to each code completion algorithm in a plurality of code completion algorithms according to the probability prediction model in the code completion request, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed, and then determines the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm, and finally sends the completion result of the target code snippet to be completed to the code completion client. In this way, the code completion device stores the probability prediction model in advance, and selects part of the code completion algorithm according to the potential application probability in the probability prediction model, so that the completion result can be calculated only according to part of the code completion algorithm, that is, while ensuring the accuracy of the code, the power consumption of calculating the completion result of the code is reduced, thereby reducing the time for the user to wait for the result of the code completion, and improving the user experience.

[0008] In some possible implementations, determining the completion result of the target code snippet to be completed based on the potential application probability of each code completion algorithm includes: selecting a target code completion algorithm from the multiple code completion algorithms based on the potential application probability of each code completion algorithm; and determining the completion result of the target code snippet to be completed based on the target code completion algorithm, the completion result including the completion code.

[0009] The code completion device can select a target code completion algorithm from the multiple code completion algorithms according to the potential application probability of each code completion algorithm. For example, the code completion device can use a code completion algorithm with a high potential application probability and / or a short time to calculate the completion result as the target code completion algorithm. More specifically, the code completion device can use a code completion algorithm with a potential application probability greater than or equal to a second preset probability threshold as the target code completion algorithm. In other words, the code completion device selects several code completion algorithms with a high potential application probability for code completion, thereby improving the effectiveness of the calculation, or reducing resource overhead while ensuring the code completion effect.

[0010] In some possible implementations, the target code completion algorithm includes some code completion algorithms among the multiple code completion algorithms, wherein determining the completion result of the target code snippet to be completed according to the target code completion algorithm includes: determining, according to the partial code completion algorithm, potential completion codes calculated by each of the partial code completion algorithms; merging and / or deduplicating potential completion codes calculated by the partial code completion algorithms to obtain the completion result of the target code snippet to be completed.

[0011] In the case where the target code completion algorithm is a plurality of code completion algorithms, the code completion device determines the completion result of the target code segment to be completed according to the target code completion algorithm, which may be to merge and / or remove duplicates of potential completion codes calculated by some code completion algorithms to obtain the final completion result, thereby obtaining a more accurate completion result.

[0012] In some possible implementations, determining the completion result of the target code snippet to be completed based on the potential application probability of each code completion algorithm includes: when the potential application probability of each code completion algorithm is lower than a preset probability threshold, the completion result of the target code snippet to be completed is empty.

[0013] The code completion device may set the completion result of the target code segment to be completed to empty when the potential application probability of each code completion algorithm is less than or equal to the preset probability threshold. For example, in this case, the device to be completed may not output the completion code, so as to avoid the interference of inappropriate completion code on code programming.

[0014] In some possible implementations, the method further includes: generating the probability prediction model according to the multiple code completion algorithms and one or more code files in a code library.

[0015] Pre-generating a probability prediction model based on multiple code completion algorithms and one or more code files in the code library helps the code completion device obtain the potential application probability corresponding to each of the multiple code completion algorithms, and then determine the completion result of the target code fragment to be completed based on the potential application probability of each code completion algorithm, and finally send the completion result of the target code fragment to be completed to the code completion client. That is, while ensuring the accuracy of the code, the power consumption of calculating the completion result of the code is reduced, and further, the delay of the user waiting for the code completion result is reduced, thereby improving the user experience.

[0016] In some possible implementations, the method for generating the probability prediction model based on the multiple code completion algorithms and one or more code files in the code library includes: sampling multiple positions to be completed from one or more code files in the code library; determining the probability of a first potential completion code calculated by a first code completion algorithm being adopted by a user based on a first position to be completed among the multiple positions to be completed and a first code file corresponding to the first position to be completed; determining a prefix word of a code snippet to be completed in a first code file corresponding to the first position to be completed based on the first position to be completed; generating the probability prediction model based on a programming language type of the first code file, a prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user, the probability prediction model including one or more mapping relationships, the one or more mapping relationships including a mapping relationship between the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user.

[0017] By pre-generating a probability prediction model based on the programming language type of the first code file, the prefix of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user, the code completion device can obtain the potential application probability corresponding to each of the multiple code completion algorithms, and then determine the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm, and finally send the completion result of the target code snippet to be completed to the code completion client. That is, while ensuring the accuracy of the code, the power consumption of calculating the completion result of the code is reduced, and further, the delay of the user waiting for the result of the code completion is reduced, thereby improving the user experience.

[0018] In some possible implementations, determining the probability that a first potential completion code calculated by a first code completion algorithm is adopted by a user based on the first position to be completed and a first code file corresponding to the first position to be completed includes: determining the first potential completion code calculated by the first code completion algorithm based on a programming language type of the first code file, the first position to be completed, and a code fragment to be completed in the first code file; and determining the probability that the first potential completion code is adopted by the user based on the code after the first position to be completed in the first code file and the first potential completion code.

[0019] The code after the first position to be completed in the first code file is the actual code in the first code file. The ratio of the length of the first potential completion code matching the actual code to the length of the actual code is the probability that the first potential completion code is adopted by the user. In other words, the closer the first potential completion code is to the actual code, the more willing the user is to adopt the potential completion code. That is, the delay of the user waiting for the result of code completion is reduced, and the user experience is improved.

[0020] In some possible implementations, the method further includes: determining description information of the code snippet to be completed in the first code file based on the code snippet to be completed in the first code file; wherein, generating the probability prediction model based on the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, and the probability of the first completion result being adopted by the user includes: generating the probability prediction model based on the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, the probability of the first potential completion code being adopted by the user, and the description information of the code snippet to be completed in the first code file.

[0021] The code completion device can determine more information about the code segment to be completed, such as description information, based on the code segment to be completed in the first code file. In this way, the code completion device can generate a probability prediction model in combination with the description information, thereby further improving the accuracy of the probability prediction model.

[0022] In some possible implementations, the method further includes: determining, based on the target code snippet to be completed, description information of the target code snippet to be completed; wherein, determining the potential application probability of each of the multiple code completion algorithms based on the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix word of the target code snippet to be completed includes: determining the potential application probability of each of the code completion algorithms based on the programming language type of the target code snippet to be completed, the prefix word of the target code snippet to be completed, the probability prediction model, and the description information of the target code snippet to be completed.

[0023] If the generation of the probability prediction model is combined with the description information of the to-be-completed snippet, the code completion device can also determine the potential application probability of each of the multiple code completion algorithms based on the probability prediction model, the programming language type of the target to-be-completed code snippet, the description information of the target to-be-completed code snippet, and the prefix of the target to-be-completed code snippet. In this way, more factors are referred to to obtain the completion result of the target to-be-completed code snippet, thereby further improving the accuracy of code completion.

[0024] In some possible implementations, the description information includes at least one of the consistency of the code length before the position to be completed, the first S words or characters at the beginning of the current line, and the number of words contained in the first M lines of code of the current line, where S and M are both positive integers.

[0025] The longer the length of the code snippet before the position to be completed, the higher the potential application probability of the completion result obtained by some completion algorithms. The characters or words at the beginning of the current line of the snippet to be completed can also increase the potential application probability of the completion result obtained by some completion algorithms. When the number of words contained in the first M lines of code of the current line is the same, the potential application probability of the completion result obtained by some completion algorithms can be further improved.

[0026] In some possible implementations, determining the probability that the first potential completion code is adopted by the user based on the code after the first position to be completed in the first code file and the first potential completion code includes: taking the ratio of the matching length in the first potential completion code to the code length after the first position to be completed in the first code file as the probability that the first potential completion code is adopted by the user.

[0027] The matching length in the first potential completion code may be a code length that is the same as the actual code after the first position to be completed in the first code file. Thus, the code completion device provides a method for obtaining the probability of the first potential completion code being adopted by the user by calculating the ratio of the matching length to the actual length.

[0028] In some possible implementations, determining the prefix word of the target code snippet to be completed based on the target code snippet to be completed and the to-be-completed position of the target code snippet to be completed includes: taking N words from the back to the front of the to-be-completed position of the target code snippet to be completed as the prefix word of the target code snippet to be completed, where N is a positive integer.

[0029] In a second aspect, a device for code completion is provided, the device having a method for implementing the functions of the first aspect and any one of various possible implementations. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions.

[0030] In one possible design, the device includes: a transceiver module and a processing module. The transceiver module may include a receiving module and a sending module. The transceiver module may be, for example, at least one of a transceiver, a receiver, and a transmitter, and the transceiver module may include a radio frequency circuit or an antenna. The processing module may be a processor. Optionally, the device also includes a storage module, which may be, for example, a memory. When a storage module is included, the storage module is used to store instructions. The processing module is connected to the storage module, and the processing module may execute instructions stored in the storage module or instructions derived from other methods, so that the device performs the method described in any one of the functions of the first aspect and various possible implementation methods.

[0031] In another possible design, when the device is a chip, the chip includes: a transceiver module and a processing module, and the transceiver module may include a receiving module and a sending module. The transceiver module may be, for example, an input / output interface, a pin or a circuit on the chip. The processing module may be, for example, a processor. The processing module may execute instructions so that the chip in the device performs the method described in any one of the functions of the first aspect and various possible implementations. Optionally, the processing module may execute instructions in a storage module, and the storage module may be a storage module in the chip, such as a register, a cache, etc. The storage module may also be located in the communication device but outside the chip, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0032] Among them, the processor mentioned in any of the above places can be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of programs of the methods in the functions of the above-mentioned first aspect and various possible implementation methods.

[0033] In a third aspect, a computer storage medium is provided, in which a program code is stored, and the program code is used to indicate instructions for executing the method described in any one of the functions of the first aspect and various possible implementation methods.

[0034] In a fourth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the method described in the first aspect above and any one of the functions of various possible implementation modes.

[0035] In a fifth aspect, a system is provided, which includes the device described in the second aspect and a code completion client.

[0036] Based on the above technical solution, the code completion device receives a code completion request from a code completion client, and determines the prefix of the target code snippet to be completed according to the target code snippet to be completed in the code completion request and the position to be completed of the target code snippet to be completed, and then obtains the potential application probability corresponding to each code completion algorithm in a plurality of code completion algorithms according to the probability prediction model in the code completion request, the programming language type of the target code snippet to be completed and the prefix of the target code snippet to be completed, and then determines the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm, and finally sends the completion result of the target code snippet to be completed to the code completion client. In this way, while ensuring the accuracy of the code, the power consumption of calculating the completion result of the code is reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 is a schematic diagram of a system for completing codes according to an embodiment of the present application;

[0038] Figure 2 is a schematic flow chart of a code completion method according to an embodiment of the present application;

[0039] Figure 3 is a schematic block diagram of a device for code completion according to an embodiment of the present application;

[0040] Figure 4 It is a schematic structural diagram of a code completion device of an example of the present application. DETAILED DESCRIPTION

[0041] The technical solution in this application will be described below in conjunction with the accompanying drawings.

[0042] Figure 1 FIG. 1 is a schematic diagram of a system for completing codes according to an embodiment of the present application. Figure 1 As shown, the system includes a code completion device 110 and a code completion client 120. The code completion device 110 includes a completion algorithm selection module 111, a code completion algorithm probability prediction module 112, a code completion algorithm library 113 and a completion result return module 114. Among them, the code completion algorithm probability prediction module 112 includes a probability prediction model generation unit, a probability prediction model library, a prefix word extraction unit and a probability prediction unit. The code completion algorithm library 113 may include one or more code completion modules.

[0043] It is understandable that the probability prediction model generation unit may also be referred to as a "probability prediction model training unit", which is not limited in this application.

[0044] Code completion client 120:

[0045] Responsible for sending code completion request messages, and receiving and presenting code completion results.

[0046] It is understandable that the code completion client may be a code editor or an integrated development environment (IDE) including code editing capabilities.

[0047] Code completion device 110:

[0048] Used to receive code completion requests and provide code completion results.

[0049] It is understandable that the code completion device can be integrated into the code completion client in the form of a plug-in. The code completion device can also exist in the form of a service to provide code service capabilities to multiple code completion clients.

[0050] It can also be understood that the code completion client 120 and the code completion apparatus 110 can be deployed on the same physical device.

[0051] Code completion algorithm probability prediction module 112:

[0052] The code completion algorithm probability prediction module 112 mainly includes the ability to generate probability prediction models of various code completion algorithms offline and to predict online the probability of potential completion codes calculated by each code completion algorithm being adopted by the user.

[0053] The prefix word extraction unit in the code completion algorithm probability prediction module 112:

[0054] It is responsible for extracting prefix words from the code snippet before any specified position in the code file or extracting prefix words from the code snippet before the specified position. The prefix words are several (preconfigurable) words or characters from the back to the front of the code snippet before the specified position. The number of prefix words or characters can be fixed or variable. For example, the words or characters from the back to the beginning of the current line in the code snippet before the specified position. The number can be 1 or other positive integers.

[0055] The probability prediction model generation unit in the code completion algorithm probability prediction module 112:

[0056] Based on the programming language type of the code in the code library, the code prefix extracted by the prefix extraction unit from the code fragment before the specified position in the code, and the probability of the potential completion code calculated by each code completion algorithm being adopted by the user, a probability prediction model corresponding to each code completion algorithm is generated to form a probability prediction model library; so that when the programmer is writing the code, the probability of the potential completion code calculated by each code completion algorithm being adopted by the user can be predicted in real time and dynamically according to the programming language type and the prefix of the code to be completed.

[0057] Generating a probability prediction model includes constructing a sample set containing the following information (programming language type, code snippet prefix, and probability of potential completion codes calculated by the completion algorithm being adopted by users) from the code base.

[0058] It is understandable that the closer the code completion result is to the code snippet after the specified position in the code file, the more willing the user is to adopt the code completion result, that is, the better the code completion effect is. Therefore, the matching degree between the code completion result and the code snippet after the specified position in the code file is used as the probability of the potential completion code calculated by the code completion algorithm being adopted by the user.

[0059] After collecting enough samples, for each code completion algorithm, use its corresponding samples to generate the corresponding probability prediction model of the completion algorithm. The probability prediction model can be a regression model, in which the language type and code prefix are features, and the probability is the target of the model. A regression algorithm (such as a linear regression algorithm) is used to generate the corresponding probability prediction model. That is, according to the language type and code prefix in the sample, a regression function is constructed to fit the probability of the potential completion code being adopted by the user. The function with the highest fit is the probability prediction model.

[0060] In other words, the probability prediction model establishes a mapping relationship between the coding language type, code prefix word and the probability of the potential completion code being adopted by the user. That is, for each code completion algorithm, when the programming language type and code prefix word are input, the probability prediction model can output the probability of the potential completion code corresponding to the code completion algorithm being adopted by the user.

[0061] The probability prediction unit in the code completion algorithm probability prediction module 112:

[0062] According to the probability prediction model of each code completion algorithm, the programming language type of the code to be completed, and the prefix word at the position to be completed, the probability of the potential completion code calculated by each code completion algorithm being adopted by the user is predicted online.

[0063] Specifically, the prefix word extraction unit is first called to extract the code prefix word from the code snippet before the position to be completed. The code snippet may be the code snippet to be completed in the code request message, or may be a code snippet extracted from the code file to be completed in the code request message.

[0064] Then, according to the programming language type and code prefix, the probability model library corresponding to each code completion algorithm generated by the probability prediction model generation unit is used to predict the probability of the potential completion code calculated by each code completion algorithm being adopted by the user.

[0065] Completion algorithm selection module 111:

[0066] According to the probability of the potential completion code being adopted by the user calculated by each code completion algorithm predicted by the probability prediction unit, a code completion algorithm with a high probability of the potential completion code being adopted by the user is selected. The number of selected code completion algorithms can be set to select code completion algorithms with a probability of the potential completion code being adopted by the user higher than a certain threshold or a fixed number (one or more) of code completion algorithms.

[0067] It is understandable that when a fixed number of code completion algorithms are selected, when the predicted probabilities of potential completion codes of multiple code completion algorithms being adopted by users are the same or not much different (for example, within a certain threshold range), the completion algorithm that is expected to take less time, occupy less resources, and does not occupy scarce resources can be preferentially selected.

[0068] It is also understandable that the information of the code completion algorithm can be collected or calculated in advance. For example, some natural language generation code completion algorithms need to occupy scarce computing resources such as GPU, or some code completion algorithms require network (resource) access, and some code completion algorithms take a long time to complete each code completion request on average.

[0069] It is understandable that when the probability of the potential completion code calculated by each code completion algorithm predicted by the probability prediction unit being adopted by the user is lower than the preset probability threshold, zero code completion algorithm can be selected, that is, the completion result of the target code snippet to be completed is empty.

[0070] Code completion algorithm library 113:

[0071] The code completion algorithm library contains multiple code completion modules, each of which has the ability to complete code. In addition, each code completion module corresponds to a code completion algorithm, and each code completion algorithm can independently output the code completion result based on the language type of the code, the code snippet that the programmer has entered, and the specified code completion location.

[0072] The code completion result returns module 114:

[0073] The code completion result returning module 114 can merge the prediction results of multiple code completion algorithms. Specifically, the code completion result returning module 114 can remove duplicate code completion result items in multiple code completion algorithms, or sort the code completion result items according to certain rules (according to the length of the completion result item, or the alphabetical order of the first letter of the completion result item, etc.), and return the code completion result to the code completion client.

[0074] In traditional solutions, with the increase in code completion tools or services, the advantages of multiple code completion algorithms can be comprehensively considered to complement each other and provide better code completion results. For example, for each code completion request, multiple code completion algorithms are used to calculate the code completion results separately, and then the results calculated by multiple code completion algorithms are merged. However, when there are many code completion algorithms, the amount of calculation required to obtain the final code completion result is very large. Therefore, how to reduce the power consumption overhead of calculating the code completion result, and thereby reduce the delay for users to wait for the code completion result, needs to be solved urgently.

[0075] Figure 2 A schematic flow chart of a code completion method according to an embodiment of the present application is shown.

[0076] 201, a code completion apparatus receives a code completion request from a code completion client, the code completion request including a target code snippet to be completed, a programming language type of the target code snippet to be completed, and a location to be completed of the target code snippet to be completed. Accordingly, the code completion client sends the code completion request to the code completion apparatus.

[0077] Specifically, the target code snippet to be completed may be a piece of code represented in the form of a string. Alternatively, the target code snippet to be completed may also be provided in the form of a file containing the code snippet to be completed. The position to be completed may be represented by a row or column of the code file to which the position to be completed belongs, or by the position of a pre-set special character or string. The code file may be represented in the form of a path.

[0078] Optionally, the programming language type includes at least one of machine language, assembly language or high-level language.

[0079] 202 , the code completion apparatus determines a prefix word of the target code snippet to be completed according to the target code snippet to be completed and the position to be completed of the target code snippet to be completed.

[0080] Specifically, the prefix word is extracted from the target code snippet to be completed. In other words, the prefix word is extracted from the code snippet before the position to be completed in the code file.

[0081] Optionally, step 202 may specifically be to use N words from the back to the front of the to-be-completed position of the target to-be-completed code snippet as prefix words of the target to-be-completed code snippet.

[0082] For example, if the code snippet before the position to be completed is "for line in lines:", and the first three words of the position to be completed are used as prefix words of the target code snippet to be completed, then the prefix words of the target code snippet to be completed are ["in", "lines", ":"].

[0083] It is understandable that the prefix word of the target code snippet to be completed may be N consecutive words before the position to be completed, or may be discontinuous words (for example, the intervals between adjacent words are the same), and this application does not limit this.

[0084] 203. The code completion device determines the potential application probability of each of the multiple code completion algorithms based on the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix word of the target code snippet to be completed. The potential application probability refers to the probability of the potential completion code calculated by each code completion algorithm for the code completion request being adopted by the user.

[0085] Specifically, the probability prediction model may include a correspondence between at least one programming language type, at least one prefix word, at least one code completion algorithm, and at least one potential application probability. In this way, the code completion device can obtain the potential application probability corresponding to the first code completion algorithm based on the probability prediction model, the programming language type of the target code snippet to be completed, the prefix word of the target code snippet to be completed, and any code completion algorithm (for example, the first code completion algorithm). Accordingly, the code completion device can obtain the potential application probability corresponding to each of the multiple code completion algorithms.

[0086] It is understandable that the code completion device may obtain the probability prediction model in advance. For example, the code completion device may obtain the probability prediction model from other devices in advance, or may generate the probability prediction model itself.

[0087] In one embodiment, before step 203, the code completion device may also generate the probability prediction model according to the multiple code completion algorithms and one or more code files in the code library.

[0088] Specifically, a probability prediction model is pre-generated based on multiple code completion algorithms and one or more code files in the code library, which helps the code completion device obtain the potential application probability corresponding to each of the multiple code completion algorithms, and then determine the completion result of the target code fragment to be completed based on the potential application probability of each code completion algorithm, and finally send the completion result of the target code fragment to be completed to the code completion client. That is, while ensuring the accuracy of the code, the power consumption of calculating the completion result of the code is reduced, and further, the delay of the user waiting for the result of the code completion is reduced, thereby improving the user experience.

[0089] It is understandable that the code library includes code files written in at least one programming language. The code completion device can randomly sample the positions to be completed in one or more code files. For the convenience of describing the embodiment of the present application, the sampling of the positions to be completed in the same code file is used as an example for description, but the present application is not limited to this.

[0090] Optionally, the code completion device can specifically sample multiple positions to be completed from one or more code files in the code library, and determine the prefix of the code fragment to be completed in the first code file corresponding to the first position to be completed according to one of the multiple positions to be completed (for example, the first position to be completed), and determine the probability of the first potential completion code calculated by the first code completion algorithm being adopted by the user according to the first position to be completed and the first code file corresponding to the first position to be completed, and then generate the probability prediction model according to the programming language type of the first code file, the prefix of the code fragment to be completed in the first code file, the first code completion algorithm and the probability of the first potential completion code being adopted by the user.

[0091] Specifically, a probability prediction model can be generated in advance based on the programming language type of the first code file, the prefix of the code fragment to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user, which helps the code completion device to obtain the potential application probability corresponding to each code completion algorithm among multiple code completion algorithms, and then determine the completion result of the target code fragment to be completed according to the potential application probability of each code completion algorithm, and finally send the completion result of the target code fragment to be completed to the code completion client. That is, while ensuring the accuracy of the code, the power consumption overhead of calculating the completion result of the code is reduced, and further, the delay of the user waiting for the result of the code completion is reduced, thereby improving the user experience.

[0092] Optionally, the code completion device can also determine the first potential completion code calculated by the first code completion algorithm based on the programming language type of the first code file, the first position to be completed, and the code fragment to be completed in the first code file, and determine the probability of the first potential completion code being adopted by the user based on the code after the first position to be completed in the first code file and the first potential completion code.

[0093] Specifically, the code after the first position to be completed in the first code file is the actual code in the first code file. The ratio of the length of the first potential completion code matching the actual code to the length of the actual code is the probability that the first potential completion code is adopted by the user. In other words, the closer the first potential completion code is to the actual code, the more willing the user is to adopt the potential completion code.

[0094] It is understandable that the other positions to be completed among the multiple positions to be completed can also generate a probability prediction model according to the above-mentioned first position to be completed. To avoid repetition, this application will not go into details.

[0095] It can also be understood that the code completion device can determine whether the number of samples is sufficient to generate the probability prediction model. For example, the programming language type, the code snippet prefix, and the probability of the potential completion code being adopted by the user calculated by the completion algorithm are regarded as a sample. If the number of samples is greater than or equal to the preset sample number threshold, it can be considered sufficient to generate the probability prediction model. If the number of samples is less than the preset sample number threshold, continue to generate samples.

[0096] Optionally, the code completion device determines the probability that the first potential completion code is adopted by the user by taking the ratio of the matching length in the first potential completion code to the code length after the first position to be completed in the first code file as the probability that the first potential completion code is adopted by the user.

[0097] Specifically, the matching length in the first potential completion code may be the same code length as the actual code after the first position to be completed in the first code file. In this way, the code completion device can obtain the probability of the first potential completion code being adopted by the user by calculating the ratio of the matching length to the actual length.

[0098] For example, the first potential completion code after the first position to be completed in the first code file is " this.m odelParams.acctBaseInfo.acct Id", and the actual code after the first position to be completed in the first code file is " this.modelParams.acctBaseInfo.acct Code," then the matching length is 34 (this.modelParams.acctBaseInfo.acct).

[0099] Optionally, the actual code after the first position to be completed in the first code file is not limited to the code from the first position to be completed in the first code file to the end of the line, the code from the first position to be completed in the first code file to the end of the file, the code of a preset number of characters or words after the first position to be completed in the first code file, etc. truncated in various ways.

[0100] It is understandable that in order to avoid the situation where the completed code in the potential completion code is too long even though the prefix is ​​partially matched, and the programmer needs to delete too many unmatched characters, the length of the matching prefix and the length of the unmatched suffix in the completion result item can be comprehensively considered. For example, in the above example, the length of the matching prefix is ​​34 (this.modelParams.acctBaseInfo.acct), and the length of the unmatched suffix is ​​2 (Id), then the length of the unmatched suffix can be penalized according to a certain proportion of the weight to the matching length. Assuming the weight is 1, the penalized matching length is: 34-1*2=32.

[0101] In another embodiment, the code completion device generates a probability prediction model by sampling multiple positions to be completed from one or more code files in the code library, and determining the prefix of the code fragment to be completed in the first code file corresponding to the first position to be completed according to one of the multiple positions to be completed (for example, the first position to be completed), and determining the description information of the code fragment to be completed in the first code file according to the code fragment to be completed in the first code file, and then determining the first completion result including the first potential completion code calculated by the first code completion algorithm according to the programming language type of the first code file, the first position to be completed and the fragment to be completed in the first code file, and then determining the probability of the first potential completion code being adopted by the user according to the code after the first position to be completed in the first code file and the first potential completion code. In this way, the code completion device can generate the probability prediction model according to the programming language type of the first code file, the prefix of the code fragment to be completed in the first code file, the description information of the fragment to be completed in the first code file, the first code completion algorithm and the probability of the first potential completion code being adopted by the user.

[0102] Specifically, the code completion device can determine more information about the code segment to be completed, such as description information, based on the code segment to be completed in the first code file. In this way, the code completion device can generate a probability prediction model in combination with the description information, thereby further improving the accuracy of the probability prediction model.

[0103] It is understandable that the other positions to be completed among the multiple positions to be completed can also generate a probability prediction model according to the above-mentioned first position to be completed. To avoid repetition, this application will not go into details.

[0104] Optionally, the description information of the to-be-completed segment includes at least one of the following: the length of the code before the to-be-completed position, the first S words or characters at the beginning of the current line, and the consistency of the number of words contained in the first M lines of code of the current line.

[0105] Specifically, the length of the code snippet before the position to be completed can be expressed in terms of the number of characters, the number of words, etc. The longer the length of the code snippet before the position to be completed, the higher the potential application probability of the completion result obtained by certain completion algorithms. The characters or words at the beginning of the current line of the snippet to be completed can also increase the potential application probability of the completion result obtained by certain completion algorithms. When the number of words contained in the first M lines of code of the current line is the same, the potential application probability of the completion result obtained by certain completion algorithms can be further improved. For example, M=2.

[0106] It is understandable that the word or character at the beginning of the line may be for, if, / / , ##, etc.

[0107] Optionally, if the generation of the probability prediction model is combined with the description information of the snippet to be completed, then in step 203, the code completion device can also determine the potential application probability of each of the multiple code completion algorithms based on the probability prediction model, the programming language type of the target code snippet to be completed, the description information of the target code snippet to be completed, and the prefix word of the target code snippet to be completed.

[0108] 204 , the code completion apparatus determines a completion result of the target code segment to be completed according to the potential application probability of each code completion algorithm.

[0109] In a possible implementation, step 204 may specifically be that when the potential application probability of each code completion algorithm is lower than a first preset probability threshold, the completion result of the target code segment to be completed is empty.

[0110] Specifically, the code completion device may set the completion result of the target code segment to be completed to empty when the potential application probability of each code completion algorithm is less than or equal to the preset probability threshold. For example, in this case, the device to be completed may not output the completion code, so as to avoid the interference of inappropriate completion code on code programming.

[0111] It is understandable that the first preset probability threshold may be pre-set. For example, the first preset probability threshold is between 0 and 0.5, and may specifically be 0.3.

[0112] In another possible implementation, step 204 may specifically be to select a target code completion algorithm from the multiple code completion algorithms according to the potential application probability of each code completion algorithm, and determine a completion result of the target code fragment to be completed according to the target code completion algorithm, wherein the completion result includes the completion code.

[0113] Specifically, the code completion device can select a target code completion algorithm from the multiple code completion algorithms according to the potential application probability of each code completion algorithm. For example, the code completion device can use a code completion algorithm with a high potential application probability and / or a short time to calculate the completion result as the target code completion algorithm. More specifically, the code completion device can use a code completion algorithm with a potential application probability greater than or equal to a second preset probability threshold as the target code completion algorithm. In other words, the code completion device selects several code completion algorithms with a high potential application probability for code completion, thereby improving the effectiveness of the calculation, or reducing resource overhead while ensuring the code completion effect.

[0114] For example, the actual code after the completion position of the target code snippet to be completed is "this.modelParams.acctBaseInfo.acctCode," with a length of 39. The code completion device determines the potential completion code through code completion algorithm A and code completion algorithm B respectively. As shown in Table 1 below. The longest common prefix length between completion algorithm A and the code snippet "this.modelParams.acctBaseInfo.acctCode," from the completion position of the target code snippet to be completed to the end of the line is "this", and the matching length is 4. The longest common prefix length between completion algorithm B and the code snippet from the specified position to the end of the line is "this.modelParams.acctBaseInfo.acct", with a matching length of 34. In this way, the potential application probability of completion algorithm A is 4 / 39=0.1; the potential application probability of completion algorithm B is 34 / 39=0.87.

[0115] Table 1

[0116] Completion algorithm Potential completion code Completion Algorithm A this Completion Algorithm B this.modelParams.acctBaseInfo.acctId

[0117] It is understandable that the second preset probability threshold may be pre-set, wherein the second preset probability threshold may be the same as or different from the first preset probability threshold, which is not limited in the present application.

[0118] It can also be understood that the target code completion algorithm can be a code completion algorithm, or a partial code completion algorithm (ie, more than one code completion algorithm) among the aforementioned multiple code completion algorithms, and this application does not limit this.

[0119] Optionally, when the target code completion algorithm is a plurality of code completion algorithms, the code completion device determines the completion result of the target code segment to be completed according to the target code completion algorithm, which may be to merge and / or deduplicate the potential completion codes calculated by some code completion algorithms to obtain the final completion result, thereby obtaining a more accurate completion result.

[0120] 205, the code completion apparatus sends the completion result of the target code segment to be completed to the code completion client. Correspondingly, the code completion client receives the completion result of the target code segment to be completed from the code completion apparatus.

[0121] Specifically, the code completion device receives a code completion request from a code completion client, and determines the prefix of the target code snippet to be completed according to the target code snippet to be completed in the code completion request and the position to be completed of the target code snippet to be completed, and then obtains the potential application probability corresponding to each code completion algorithm in a plurality of code completion algorithms according to the probability prediction model in the code completion request, the programming language type of the target code snippet to be completed and the prefix of the target code snippet to be completed, and then determines the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm, and finally sends the completion result of the target code snippet to be completed to the code completion client. In this way, the code completion device can select in advance the code completion algorithm with a higher probability of being adopted by the user for the completion result of the calculated target code snippet to be completed according to the potential application probability of each code completion algorithm, and then calculate the completion result according to the selected code completion algorithm, thereby reducing the power consumption overhead of calculating the completion result of the code while ensuring the accuracy of the code completion, and further reducing the delay of the user waiting for the result of the code completion, thereby improving the user experience.

[0122] The above mainly introduces the scheme provided by the embodiments of the present application from the perspective of various interactions. It can be understood that each network element, such as a transmitting device or a receiving device, includes a hardware structure and / or software module corresponding to each function in order to implement the above functions. Those skilled in the art should be aware that, in combination with the units and algorithm steps of each example described in the embodiments disclosed in this document, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in hardware or in a computer software-driven hardware manner depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0123] The embodiment of the present application can divide the functional modules of the transmitting end device or the receiving end device according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation. The following is an example of using each functional module divided according to each function to illustrate.

[0124] It should be understood that the specific examples in the embodiments of the present application are only intended to help those skilled in the art to better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application.

[0125] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0126] Above, combined Figure 2 The method provided by the embodiment of the present application is described in detail. Figure 3 to Figure 4 The device provided in the embodiment of the present application is described in detail. It should be understood that the description of the device embodiment corresponds to the description of the method embodiment, so the contents not described in detail can be referred to the method embodiment above, and for the sake of brevity, they will not be repeated here.

[0127] Figure 3 A schematic block diagram of a code completion apparatus 300 according to an embodiment of the present application is shown.

[0128] It should be understood that the device 300 may correspond to Figure 1 The code completion device 110 in the system shown in the figure. The device 300 includes a transceiver module 310 and a processing module 320.

[0129] It is understandable that the transceiver module 310 may be Figure 1 In the system shown, the receiving interface of the completion algorithm selection module 111 or the output interface of the completion result return module 114. Alternatively, the transceiver module 310 may also be a separate transceiver module in the code completion device 110, which is not limited in the present application.

[0130] It is understandable that the processing module 320 may be Figure 1 At least one of the completion algorithm selection module 111, the code completion algorithm probability prediction module 112 or the code completion algorithm library 113 in the system shown.

[0131] The transceiver module 310 is used to receive a code completion request from a code completion client, where the code completion request includes a target code snippet to be completed, a programming language type of the target code snippet to be completed, and a location to be completed of the target code snippet to be completed;

[0132] The processing module 320 (for example, the prefix word extraction unit in the code completion algorithm probability prediction module 112) is used to determine the prefix word of the target code snippet to be completed according to the target code snippet to be completed and the to-be-completed position of the target code snippet to be completed;

[0133] The processing module 320 (for example, the probability prediction unit in the code completion algorithm probability prediction module 112) is further used to determine the potential application probability of each code completion algorithm among the multiple code completion algorithms according to the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed, wherein the potential application probability refers to the probability of the potential completion code calculated by each code completion algorithm for the code completion request being adopted by the user;

[0134] The processing module 320 (for example, the completion algorithm selection module 111 and the code completion algorithm library 113) is further used to determine the completion result of the target code segment to be completed according to the potential application probability of each code completion algorithm;

[0135] The transceiver module 310 is further configured to send the completion result of the target code segment to be completed to the code completion client.

[0136] Optionally, the processing module 320 is specifically used for:

[0137] Selecting a target code completion algorithm from the multiple code completion algorithms according to the potential application probability of each code completion algorithm;

[0138] According to the target code completion algorithm, a completion result of the target code fragment to be completed is determined, and the completion result includes a completion code.

[0139] Optionally, the target code completion algorithm includes some code completion algorithms among the multiple code completion algorithms, wherein the processing module 320 is specifically used to:

[0140] According to the part of code completion algorithms, determining potential completion codes calculated by each code completion algorithm in the part of code completion algorithms;

[0141] The completion results calculated by the code completion algorithm are merged and / or deduplicated to obtain potential completion codes for the target code snippet to be completed.

[0142] Optionally, the processing module 320 is specifically used for:

[0143] When the potential application probability of each code completion algorithm is lower than the preset probability threshold, the completion result of the target code snippet to be completed is empty.

[0144] Optionally, the processing module 320 (eg, the probability prediction model generation unit in the code completion algorithm probability prediction module 112) is further configured to generate the probability prediction model according to the plurality of code completion algorithms and one or more code files in the code library.

[0145] Optionally, the processing module 320 (for example, the probability prediction model generation unit in the code completion algorithm probability prediction module 112) is specifically used to:

[0146] Sample multiple locations to be completed from one or more code files in the code base;

[0147] Determining, according to the first position to be completed and a first code file corresponding to the first position to be completed, a probability that a first potential completion code calculated by a first code completion algorithm is adopted by a user;

[0148] According to a first position to be completed among the multiple positions to be completed, determining a prefix word of a code fragment to be completed in a first code file corresponding to the first position to be completed;

[0149] The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user. The probability prediction model includes one or more mapping relationships, and the one or more mapping relationships include the mapping relationship between the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user.

[0150] Optionally, the processing module 320 (for example, the probability prediction model generation unit in the code completion algorithm probability prediction module 112) is specifically used to:

[0151] Determine, according to the programming language type of the first code file, the first position to be completed, and the code fragment to be completed in the first code file, a first potential completion code calculated by a first code completion algorithm;

[0152] The probability that the first potential completion code is adopted by the user is determined according to the code after the first to-be-completed position in the first code file and the first potential completion code.

[0153] Optionally, the processing module 320 is further configured to determine description information of the code snippet to be completed in the first code file according to the code snippet to be completed in the first code file;

[0154] The processing module 320 is specifically used for:

[0155] The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code fragment to be completed in the first code file, the first code completion algorithm, the probability of the first potential completion code being adopted by the user, and the description information of the code fragment to be completed in the first code file.

[0156] Optionally, the processing module 320 is further configured to determine description information of the target code snippet to be completed according to the target code snippet to be completed;

[0157] The processing module 320 is specifically used for:

[0158] The potential application probability of each code completion algorithm is determined according to the programming language type of the target code snippet to be completed, the prefix word of the target code snippet to be completed, the probability prediction model and the description information of the target code snippet to be completed.

[0159] Optionally, the description information includes at least one of the consistency of the code length before the position to be completed, the first S words or characters at the beginning of the current line, and the number of words contained in the first M lines of code of the current line, where S and M are both positive integers.

[0160] Optionally, the processing module 320 is specifically used for:

[0161] The ratio of the matching length in the first potential completion code to the code length after the first position to be completed in the first code file is used as the probability that the first potential completion code is adopted by the user.

[0162] Optionally, the processing module 320 is specifically used for:

[0163] The N words from the back to the front of the to-be-completed position of the target to-be-completed code snippet are used as prefix words of the target to-be-completed code snippet, where N is a positive integer.

[0164] Figure 4 The code completion device 400 provided in the embodiment of the present application is shown. The device 400 can be Figure 2 The code completion device described in . The device can be used as follows Figure 4 The hardware architecture shown in FIG. 4 is a schematic diagram of a device for displaying a processor 410 and a transceiver 430. Optionally, the device may further include a memory 440. The processor 410, the transceiver 430 and the memory 440 communicate with each other via an internal connection path. Figure 3 The related functions implemented by the processing module 320 in the embodiment can be implemented by the processor 410, and the related functions implemented by the transceiver module 310 can be implemented by the processor 410 controlling the transceiver 430.

[0165] Optionally, processor 410 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), a dedicated processor, or one or more integrated circuits for executing the technical solutions of the embodiments of the present application. Alternatively, a processor may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions). For example, it may be a baseband processor or a central processing unit. The baseband processor may be used to process communication protocols and communication data, and the central processing unit may be used to control the device for code completion, execute software programs, and process data of software programs.

[0166] Optionally, the processor 410 may include one or more processors, for example, one or more central processing units (CPUs). When the processor is a CPU, the CPU may be a single-core CPU or a multi-core CPU.

[0167] The transceiver 430 is used to send and receive data and / or signals, and receive data and / or signals. The transceiver may include a transmitter and a receiver, the transmitter is used to send data and / or signals, and the receiver is used to receive data and / or signals.

[0168] The memory 440 includes but is not limited to random access memory (RAM), read-only memory (ROM), erasable programmable readonly memory (EPROM), and compact disc read-only memory (CD-ROM). The memory 440 is used to store relevant instructions and data.

[0169] The memory 440 is used to store program codes and data, and may be a separate device or integrated in the processor 410 .

[0170] Specifically, the processor 410 is used to control the transceiver to transmit information with the media server or the advertisement management server. For details, please refer to the description in the method embodiment, which will not be repeated here.

[0171] In a specific implementation, as an embodiment, the device 400 may also include an output device and an input device. The output device communicates with the processor 410 and can display information in a variety of ways. For example, the output device may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector. The input device communicates with the processor 601 and can receive user input in a variety of ways. For example, the input device may be a mouse, a keyboard, a touch screen device, or a sensor device.

[0172] Understandably, Figure 4 Only a simplified design of the device for code completion is shown. In practical applications, the device may also include other necessary components, including but not limited to any number of transceivers, processors, controllers, memories, etc., and all code completion devices that can implement the present application are within the protection scope of the present application.

[0173] In a possible design, the device 400 may be a chip, for example, a communication chip that can be used in a code completion device, and is used to implement the relevant functions of the processor 410 in the code completion device. The chip may be a field programmable gate array, a dedicated integrated chip, a system chip, a central processing unit, a network processor, a digital signal processing circuit, a microcontroller, and a programmable controller or other integrated chips for implementing relevant functions. The chip may optionally include one or more memories for storing program codes, and when the codes are executed, the processor implements the corresponding functions.

[0174] The present application also provides a device, which may be a code completion device or a circuit. The device may be used to execute the actions executed by the code completion device in the above method embodiment.

[0175] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application 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 a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. 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 (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a high-density digital video disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

[0176] It should be understood that the processor can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method embodiment can be completed by the hardware integrated logic circuit in the processor or the instruction in the form of software. The above processor can be a general processor, a digital signal processor (digital signal processor, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (field programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor can be combined to perform. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0177] It can be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0178] In the present application, "at least one" means one or more, and "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.

[0179] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0180] The terms "component", "module", "system", etc. used in this specification are used to represent computer-related entities, hardware, firmware, a combination of hardware and software, software, or software in execution. For example, a component can be, but is not limited to, a process running on a processor, a processor, an object, an executable file, an execution thread, a program and / or a computer. By way of illustration, both applications running on a computing device and a computing device can be components. One or more components may reside in a process and / or an execution thread, and a component may be located on a computer and / or distributed between two or more computers. In addition, these components may be executed from various computer-readable media having various data structures stored thereon. Components may, for example, communicate through local and / or remote processes according to signals having one or more data packets (e.g., data from two components interacting with another component between a local system, a distributed system and / or a network, such as the Internet interacting with other systems through signals).

[0181] It should also be understood that the first, second and various numerical numbers involved in this document are only distinguished for the convenience of description and are not used to limit the scope of the embodiments of the present application.

[0182] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. Among them, the existence of A or B alone does not limit the number of A or B. Taking the existence of A alone as an example, it can be understood that there are one or more A.

[0183] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0184] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0185] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0186] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0187] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0188] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.

[0189] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A code completion method, characterized in that: include: Receiving a code completion request from a code completion client, the code completion request including a target code snippet to be completed, a programming language type of the target code snippet to be completed, and a location to be completed of the target code snippet to be completed; Determining a prefix word of the target code snippet to be completed according to the target code snippet to be completed and the to-be-completed position of the target code snippet to be completed; Determine, according to the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed, the potential application probability of each code completion algorithm among the multiple code completion algorithms, wherein the potential application probability refers to the probability of a potential completion code calculated by using each code completion algorithm for the code completion request being adopted by the user; Determining a completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm; Sending the completion result of the target code snippet to be completed to the code completion client.

2. The method according to claim 1, characterized in that: Determining the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm includes: selecting a target code completion algorithm from the plurality of code completion algorithms according to the potential application probability of each of the code completion algorithms; According to the target code completion algorithm, a completion result of the target code fragment to be completed is determined, and the completion result includes a completion code.

3. The method according to claim 2, characterized in that The target code completion algorithm includes some code completion algorithms among the multiple code completion algorithms, wherein determining the completion result of the target code segment to be completed according to the target code completion algorithm includes: According to the partial code completion algorithm, determining a potential completion code calculated by each code completion algorithm in the partial code completion algorithm; The potential completion codes calculated by the partial code completion algorithm are merged and / or deduplicated to obtain a completion result of the target code fragment to be completed.

4. The method according to claim 1, characterized in that Determining the completion result of the target code snippet to be completed according to the potential application probability of each code completion algorithm includes: When the potential application probability of each of the code completion algorithms is lower than a preset probability threshold, the completion result of the target code segment to be completed is empty.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: The probability prediction model is generated according to the multiple code completion algorithms and one or more code files in a code library.

6. The method according to claim 5, characterized in that The method for generating the probability prediction model according to the multiple code completion algorithms and one or more code files in the code library includes: Sample multiple locations to be completed from one or more code files in the code base; Determining, according to a first position to be completed among the multiple positions to be completed and a first code file corresponding to the first position to be completed, a probability that a first potential completion code calculated by a first code completion algorithm is adopted by a user; Determine, according to the first position to be completed, a prefix word of the code snippet to be completed in the first code file corresponding to the first position to be completed; The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user. The probability prediction model includes one or more mapping relationships, and the one or more mapping relationships include the mapping relationship between the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user.

7. The method according to claim 6, characterized in that The feature is that The determining, according to the first position to be completed and the first code file corresponding to the first position to be completed, the probability that the first potential completion code calculated by the first code completion algorithm is adopted by the user comprises: Determine, according to the programming language type of the first code file, the first position to be completed, and the code fragment to be completed in the first code file, a first potential completion code calculated by a first code completion algorithm; The probability that the first potential completion code is adopted by the user is determined according to the code after the first to-be-completed position in the first code file and the first potential completion code.

8. The method according to claim 7, characterized in that The determining, according to the first position to be completed and the first code file corresponding to the first position to be completed, the probability that the first potential completion code calculated by the first code completion algorithm is adopted by the user comprises: The ratio of the matching length in the first potential completion code to the code length after the first position to be completed in the first code file is used as the probability that the first potential completion code is adopted by the user.

9. The method according to claim 6, characterized in that The method further comprises: Determine description information of the code snippet to be completed in the first code file according to the code snippet to be completed in the first code file; The generating the probability prediction model according to the programming language type of the first code file, the prefix of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user comprises: The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code fragment to be completed in the first code file, the first code completion algorithm, the probability of the first potential completion code being adopted by the user, and the description information of the code fragment to be completed in the first code file.

10. The method according to claim 9, characterized in that The method further comprises: Determining description information of the target code snippet to be completed according to the target code snippet to be completed; The step of determining the potential application probability of each of the plurality of code completion algorithms according to the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed includes: The potential application probability of each code completion algorithm is determined according to the programming language type of the target code snippet to be completed, the prefix word of the target code snippet to be completed, the probability prediction model and the description information of the target code snippet to be completed.

11. The method according to claim 9, characterized in that The description information includes at least one of the following: the length of the code before the position to be completed, the first S words or characters at the beginning of the current line, and the consistency of the number of words contained in the first M lines of code of the current line, where S and M are both positive integers.

12. The method according to any one of claims 1 to 4, characterized in that The determining, according to the target code snippet to be completed and the to-be-completed position of the target code snippet to be completed, a prefix word of the target code snippet to be completed comprises: The N words from the back to the front of the to-be-completed position of the target to-be-completed code snippet are used as prefix words of the target to-be-completed code snippet, where N is a positive integer.

13. A code completion device, characterized in that: include: A transceiver module, configured to receive a code completion request from a code completion client, wherein the code completion request includes a target code snippet to be completed, a programming language type of the target code snippet to be completed, and a position to be completed of the target code snippet to be completed; A processing module, configured to determine a prefix word of the target code snippet to be completed according to the target code snippet to be completed and a position to be completed of the target code snippet to be completed; The processing module is further configured to determine a potential application probability of each of the multiple code completion algorithms according to the probability prediction model, the programming language type of the target code snippet to be completed, and the prefix of the target code snippet to be completed, wherein the potential application probability refers to a probability of a potential completion code calculated by using each code completion algorithm for the code completion request being adopted by the user; The processing module is further configured to determine a completion result of the target code segment to be completed according to a potential application probability of each code completion algorithm; The transceiver module is further used to send the completion result of the target code snippet to be completed to the code completion client.

14. The device according to claim 13, characterized in that The processing module is specifically used for: selecting a target code completion algorithm from the plurality of code completion algorithms according to the potential application probability of each of the code completion algorithms; According to the target code completion algorithm, a completion result of the target code fragment to be completed is determined, and the completion result includes a completion code.

15. The device according to claim 14, characterized in that The target code completion algorithm includes some code completion algorithms among the multiple code completion algorithms, wherein the processing module is specifically used for: According to the partial code completion algorithm, determining a potential completion code calculated by each code completion algorithm in the partial code completion algorithm; The potential completion codes calculated by the partial code completion algorithm are merged and / or deduplicated to obtain a completion result of the target code fragment to be completed.

16. The device according to claim 13, characterized in that The processing module is specifically used for: When the potential application probability of each of the code completion algorithms is lower than a preset probability threshold, the completion result of the target code segment to be completed is empty.

17. The device according to any one of claims 13 to 16, characterized in that The processing module is further used to generate the probability prediction model according to the multiple code completion algorithms and one or more code files in the code library.

18. The device according to claim 17, characterized in that The processing module is specifically used for: Sample multiple locations to be completed from one or more code files in the code base; Determining, according to a first position to be completed among the multiple positions to be completed and a first code file corresponding to the first position to be completed, a probability that a first potential completion code calculated by a first code completion algorithm is adopted by a user; Determine, according to the first position to be completed, a prefix word of the code snippet to be completed in the first code file corresponding to the first position to be completed; The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user. The probability prediction model includes one or more mapping relationships, and the one or more mapping relationships include the mapping relationship between the programming language type of the first code file, the prefix word of the code snippet to be completed in the first code file, the first code completion algorithm, and the probability of the first potential completion code being adopted by the user.

19. The device according to claim 18, characterized in that The feature is that The processing module is specifically used for: Determine, according to the programming language type of the first code file, the first position to be completed, and the code fragment to be completed in the first code file, a first potential completion code calculated by a first code completion algorithm; The probability that the first potential completion code is adopted by the user is determined according to the code after the first to-be-completed position in the first code file and the first potential completion code.

20. The device according to claim 19, characterized in that The processing module is specifically used for: The ratio of the matching length in the first potential completion code to the code length after the first position to be completed in the first code file is used as the probability that the first potential completion code is adopted by the user.

21. The device according to claim 18, characterized in that The processing module is further configured to determine description information of the code snippet to be completed in the first code file according to the code snippet to be completed in the first code file; Wherein, the processing module is specifically used for: The probability prediction model is generated according to the programming language type of the first code file, the prefix word of the code fragment to be completed in the first code file, the first code completion algorithm, the probability of the first potential completion code being adopted by the user, and the description information of the code fragment to be completed in the first code file.

22. The device according to claim 21, characterized in that The processing module is further configured to determine description information of the target code snippet to be completed according to the target code snippet to be completed; Wherein, the processing module is specifically used for: The potential application probability of each code completion algorithm is determined according to the programming language type of the target code snippet to be completed, the prefix word of the target code snippet to be completed, the probability prediction model and the description information of the target code snippet to be completed.

23. The device according to claim 21, characterized in that The description information includes at least one of the following: the length of the code before the position to be completed, the first S words or characters at the beginning of the current line, and the consistency of the number of words contained in the first M lines of code of the current line, where S and M are both positive integers.

24. The device according to any one of claims 13 to 16, characterized in that The processing module is specifically used for: The N words from the back to the front of the to-be-completed position of the target to-be-completed code snippet are used as prefix words of the target to-be-completed code snippet, where N is a positive integer.

25. A code completion system, characterized in that: The code completion system comprises: a code completion device and a code completion client according to any one of claims 13 to 24.

26. A code completion device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store program instructions, and the processor is used to call the program instructions to execute the method according to any one of claims 1 to 12.

27. A computer-readable storage medium, characterized in that: The computer-readable medium stores a program code for execution by a device, wherein the program code includes a program for executing the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Program testing method, apparatus and system

    CN107562613A

  • Python code reference information generation method based on program analysis and text analysis

    CN110750297A