Code processing method and apparatus, device, storage medium, and program product

By combining generative AI and caching technology, and using code feature parameters for feature matching and fuzzy character matching, the problem of low cache hit rate in existing technologies is solved, achieving more efficient code autofill and a better user experience.

WO2026233084A1PCT designated stage Publication Date: 2026-11-12ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2026/091244
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2025-05-09
Filing Date
2026-04-17
Publication Date
2026-11-12

AI Technical Summary

Technical Problem

Existing technologies cannot fully utilize the potential value of similar code snippets in code caching, resulting in low cache hit rates, inability to adapt to dynamically changing code generation needs, and a lack of flexibility and adaptability.

Method used

By combining generative AI code generation and caching technologies, code feature parameters are extracted through language models, and feature matching and character fuzzy matching are performed to identify similar code fragments and automatically fill them in.

Benefits of technology

It improves cache hit rate and code matching efficiency, adapts to dynamically changing code generation needs, enhances user experience, and reduces server-side processing pressure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2026091244_12112026_PF_FP_ABST
    Figure CN2026091244_12112026_PF_FP_ABST
Patent Text Reader

Abstract

The present description provides a code processing method and apparatus, a device, a storage medium, and a program product. By using code preceding a code line currently being edited by a user in a code file as code to be matched, a first feature parameter of the code to be matched and second feature parameters of a plurality of historical code snippets are acquired, the first and second feature parameters being extracted by a language model. Thus, code feature matching between the code to be matched and the historical code snippets is achieved on the basis of the acquired code features, so as to determine, from among the plurality of historical code snippets, a target code snippet having matched code features. Code matching based on the feature parameters characterizing the code features can be achieved, so as to effectively identify code of which characters are not completely identical but essential code features match, thereby improving code matching efficiency. Furthermore, character matching is performed in the target code snippet on the basis of edited code located within a first preset range preceding the current code editing position, so as to determine code to be inserted, for insertion at a position subsequent to the current code editing position.
Need to check novelty before this filing date? Find Prior Art

Description

Code processing methods, apparatus, devices, storage media and program products Technical Field

[0001] This specification relates to one or more embodiments in the field of computer technology, and more particularly to a code processing method, apparatus, device, storage medium, and program product. Background Technology

[0002] As software development scales and complexity continue to increase, developers face more and more challenges when writing code. To improve code development efficiency and reduce human errors, code autofill technology, as an intelligent tool, has gradually become an important development tool in the software development environment.

[0003] In related technologies, the code before and after the cursor position when the user is writing code can be cached as the context. When the user writes code later, the cached context can be used for code matching. If the code written later is the same as the code in the cached context, the code can be automatically filled in based on the cached context. Summary of the Invention

[0004] In view of the above, one or more embodiments of this specification provide the following technical solutions.

[0005] According to a first aspect of one or more embodiments of this specification, a code processing method is proposed, the method comprising: in response to an editing operation by a user in a code file, determining the text preceding the currently edited line of code as code to be matched; acquiring the following feature parameters extracted by a language model: a first feature parameter characterizing the code features of the code to be matched, and a second feature parameter characterizing the code features of each cached historical code segment; performing matching based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each cached historical code segment, to determine a target code segment whose code features match the code features of the code to be matched from a plurality of cached historical code segments; performing character matching in the target code segment based on edited code within a first preset range prior to the current code editing position, and determining code within a second preset range after the matched code in the target code segment as code to be filled, for filling after the current code editing position.

[0006] According to a second aspect of one or more embodiments of this specification, a code processing apparatus is provided, the apparatus comprising: a determining module, configured to, in response to an editing operation by a user in a code file, determine the preceding text of the currently edited code line as code to be matched; an acquiring module, configured to acquire the following feature parameters extracted by a language model: a first feature parameter characterizing the code features of the code to be matched, and a second feature parameter characterizing the code features of each cached historical code segment; the determining module is further configured to perform matching based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each cached historical code segment, to determine a target code segment whose code features match the code features of the code to be matched from a plurality of cached historical code segments; a matching module, configured to perform character matching in the target code segment based on edited code within a first preset range prior to the current code editing position; the determining module is further configured to determine code within a second preset range following the matched code in the target code segment as code to be filled, for filling after the current code editing position.

[0007] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the code processing method as described in the first aspect above by executing the executable instructions.

[0008] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the code processing method as described in the first aspect above.

[0009] According to a fifth aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instructions that, when executed by a processor, implement the code processing method as described in the first aspect above.

[0010] As described in the above embodiments, this specification, in response to a user's editing operation in a code file, determines the text preceding the currently edited line of code as the code to be matched. It then obtains a first feature parameter and multiple second feature parameters extracted by a language model. The first feature parameter characterizes the code features of the code to be matched, while each of the second feature parameters characterizes the code features of cached historical code segments. Matching is then performed based on the first feature parameter of the code to be matched and the corresponding second feature parameters of each cached historical code segment. This allows for the identification of a target code segment whose code features match those of the code to be matched from the cached historical code segments. Furthermore, character matching is performed within the target code segment based on the edited code within a first preset range prior to the current code editing position. The code within a second preset range following the matched code in the target code segment is then identified as the code to be filled in after the current code editing position. The solution provided in this specification enables matching between different codes based on feature parameters characterizing code features, effectively identifying codes with slightly different characters but matching essential code features, thus improving code matching efficiency. Attached Figure Description

[0011] Figure 1 is a schematic diagram of a code processing procedure provided in an exemplary embodiment.

[0012] Figure 2 is a flowchart of a code processing method provided in an exemplary embodiment.

[0013] Figure 3 is a flowchart illustrating a code matching process provided in an exemplary embodiment.

[0014] Figure 4 is a schematic diagram of the flow architecture of a code processing procedure provided in an exemplary embodiment.

[0015] Figure 5 is a schematic structural diagram of an electronic device provided in an exemplary embodiment.

[0016] Figure 6 is a block diagram of a code processing apparatus provided in an exemplary embodiment. Detailed Implementation

[0017] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0018] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the methods may include more or fewer steps than described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments.

[0019] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0020] In related technologies, during the process of a user writing code, the code before and after the cursor position can be cached as code context for use in subsequent automatic code filling.

[0021] Optionally, the Least Recently Used (LRU) algorithm, as a common and simple caching strategy, can be used to cache user-written code. Optionally, the LRU algorithm can also update cached data by evicting the least recently used cached data.

[0022] Optionally, when using the LRU algorithm to implement code caching, when a user writes code later, the code currently written by the user can be matched with the code cached using the LRU cache. If the code matches completely, it is considered a cache hit, and thus automatic code filling can be achieved based on the code that is hit in the cache.

[0023] Optionally, the cache mentioned in the above embodiments can be a local cache. If the code in the local cache fails to match, the latest, possibly updated code can be obtained by requesting the network library, or the code in the local cache can be verified by requesting the network library to see if it needs to be updated, etc. This specification does not limit this.

[0024] Referring to Figure 1, which is a schematic diagram of a code processing process provided by an exemplary embodiment, as shown in Figure 1, the application scenario may include an electronic device 101 and a server 102.

[0025] Optionally, electronic device 101 can be a personal computer (PC), mobile phone, tablet, laptop, PDA (Personal Digital Assistants, PDAs), wearable device (such as smart glasses, smartwatch, etc.), etc., but is not limited to these. Optionally, server 102 can be a physical server containing an independent host, or server 102 can be a virtual server hosted by a host cluster, but is not limited to these.

[0026] Optionally, programming software can be installed and run on the electronic device 101 to provide programming functions for the user. Optionally, the user can write code using the programming software. Optionally, during the process of the user writing code using the programming software, the electronic device 101 can determine from the cached code whether there is code that matches the user's edited code based on the user's editing progress. If a match is found, the electronic device 101 can automatically fill in the code being edited based on the cached code, thereby accelerating code editing and improving code editing efficiency by utilizing caching.

[0027] Optionally, the cache can be a local cache of the electronic device 101, or an application-level cache of the programming software installed on the electronic device 101, etc., but not limited to these.

[0028] Optionally, if the cached code fails to match the code edited by the user, the electronic device 101 may send a request to the server 102 to request the latest, possibly updated, code, or verify whether the code cached in the local cache needs to be updated, so as to ensure that the latest code is obtained for code autofill if necessary.

[0029] Optionally, for the network used for interaction between electronic device 101 and server 102, wired or wireless networks can be selected based on the communication methods supported by the corresponding electronic device. This specification does not impose any restrictions on this. For example, for electronic device 101 that can support both wired and wireless communication, wired or wireless networks can be used to achieve communication between it and server 102 as needed; while for electronic device 101 that only supports wireless communication, wireless networks can be used to achieve communication between it and server 102.

[0030] However, in the aforementioned implementation process, users continuously and rapidly input code, causing the cursor position to change frequently. Consequently, the code before and after the cursor position also changes frequently, placing immense processing pressure on the code matching process in the cache. Furthermore, the current cache hit strategy cannot fully utilize the potential value of similar code snippets; it can only discover code snippets in the cache that are completely identical to the currently edited code. For code snippets that are not entirely identical but have similar content, the current cache hit strategy fails to benefit from these cached code snippets. In addition, the target's cache hit strategy cannot adapt to dynamically changing code generation requirements, lacking flexibility and adaptability.

[0031] With the continuous development of Artificial Intelligence (AI) technology, generative AI-based code generation has gradually become an important application direction of AI technology. Generative AI-based code generation technology can predict code or program structure based on various information such as incomplete data sources, programs written in another programming language, natural language descriptions, and execution logs, thereby achieving automatic code generation. Therefore, combining generative AI code generation technology with caching technology can be considered to achieve code matching in the cache.

[0032] Optionally, context-aware computing, as an intelligent computing model within AI technology, can identify and understand a user's real-time environment, state, and activities, providing personalized and highly adaptive services. In view of this, this specification aims to provide a code matching method that combines context-aware computing technology with caching technology to achieve code matching within the cache.

[0033] The above is merely an exemplary description of the application scenarios of one or more embodiments of this specification, and does not constitute a limitation on the application scenarios of the embodiments of this specification. In more possible implementations, the solutions provided by one or more embodiments of this specification can be applied to more scenarios involving code editing. One or more embodiments of this specification do not limit the specific application scenarios.

[0034] After introducing the application scenarios of one or more embodiments of this specification, the optional implementation process of one or more embodiments of this specification will be described next.

[0035] Referring to Figure 2, which is a flowchart of a code processing method provided in an exemplary embodiment, the method may include the following steps.

[0036] Step 201: In response to the user's editing operation in the code file, determine the text preceding the currently edited line of code as the code to be matched.

[0037] In some embodiments, the user's editing operations in the code file can be monitored in real time to determine the line of code currently being edited by the user based on the current editing position, thereby determining the preceding text of the currently edited line of code as the code to be matched with the code in the cache.

[0038] Optionally, the user's current editing position is the cursor's position in the code file.

[0039] Optionally, the subsequent code matching process can be triggered when the user's editing operation is detected, or the subsequent code completion process can be triggered when a specified user operation is detected. For example, a mechanism to trigger code completion can be set in the code editing page, and a corresponding operation mechanism (for triggering the specified operation) can be provided for the set mechanism, so that the user can trigger the subsequent code completion process through the set operation mechanism.

[0040] Optionally, regardless of whether the triggering mechanism is an editing operation or a specified operation, when the user performs the corresponding operation, it can be considered that the user has triggered a completion request. The completion request is used to complete the code based on the currently edited code, so as to trigger the subsequent code completion process.

[0041] Step 202: Obtain the following feature parameters extracted by the language model: the first feature parameter used to characterize the code features of the code to be matched, and the second feature parameter used to characterize the code features of each cached historical code segment.

[0042] Optionally, after obtaining the code to be matched through step 201, the first feature parameter used to characterize the code features of the code to be matched can be extracted through the language model; and the second feature parameter used to characterize the code features of each cached historical code segment can be determined and stored by the language model when caching the historical code segment, so that after obtaining the code to be matched, the stored second feature parameter used to characterize the code features of each cached historical code segment can be directly obtained.

[0043] Optionally, the language model can be a large language model (LLM), but is not limited to this.

[0044] Step 203: Match the code based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, so as to determine the target code segment whose code features match the code features of the code to be matched from the multiple cached historical code segments.

[0045] In some embodiments, a comparison can be made between the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, so as to determine the historical code segment whose corresponding second feature parameter is consistent with the first feature parameter of the code to be matched from the cached historical code segments. The determined historical code segment is the target code segment whose code feature matches the code feature of the code to be matched.

[0046] Step 204: Based on the edited code within the first preset range before the current code editing position, perform character matching in the target code segment, and determine the code within the second preset range after the matched code in the target code segment as the code to be filled, so as to fill it after the current code editing position.

[0047] Optionally, the edited code within a first preset range preceding the current code editing position can be the code from the starting character of the currently edited code line to the current code editing position, or it can be the first N characters preceding the current code editing position, but is not limited thereto. One or more embodiments of this specification do not limit this. Wherein, N can be any positive integer value.

[0048] In some embodiments, the characters of the code in the target code segment can be matched one by one with the edited code located within a first preset range before the current code editing position to determine the code that matches the edited code from the target code segment. Thus, the code located within a second preset range after the matched code in the target code segment can be determined as the code to be filled, which can be used for subsequent code filling.

[0049] Optionally, the code in the target code snippet that is located within the second preset range after the matched code can be code that starts with the first character after the matched code in the target code and has a specified number of lines. This part will be described in detail below and will not be repeated here.

[0050] After introducing the basic implementation of the code processing methods provided by one or more embodiments of this specification, the optional implementation methods of one or more embodiments of this specification will be introduced below.

[0051] In some embodiments, step 201, when determining the text preceding the currently edited line of code as the code to be matched in response to the user's editing operation in the code file, can be achieved through the following steps.

[0052] Step 2011: In response to the user's editing operation in the code file, determine the perception radius information based on the file information of the code file edited by the user and the line number of the code line currently being edited by the user. The perception radius information includes at least the first line number indicating the number of the code line preceding the code to be matched.

[0053] In one possible implementation, when a user's editing operation in a code file is detected, the file information of the code file and the line number of the code line currently being edited by the user can be obtained. The file information of the code file and the line number of the code line currently being edited by the user can then be input into the context awareness model, and the awareness radius information can be output through the context awareness model.

[0054] Optionally, the file information may include at least one of the following: code file type, file storage path, and code programming language, but is not limited to these.

[0055] The perception radius information can include the number of the first line of code preceding the code to be matched. That is, when processing the code file based on the file information and the line number of the code currently being edited by the user using the context-aware model, the number of preceding lines of code required to achieve subsequent code filling can be determined, which is the number of the first line of code preceding the code to be matched.

[0056] Optionally, the perception radius information may also include a second line number indicating the line number following the code to be matched. That is, when processing the code based on the file information of the code file and the line number of the code currently being edited by the user through the context-aware model, the line number following the code that can be accurately determined based on the first line number can also be determined, which is the second line number following the code to be matched.

[0057] Among them, the context-aware model can be pre-trained. It can take the file information of the code file and the line number of any line of code in the code file as input. Through a series of processes inside the context-aware model, it determines the number of lines of code above that can be matched as accurately as possible, as well as the number of lines of code below that can be matched.

[0058] Optionally, the context-aware model can be a Generative Pre-trained Transformer (GPT), a Bidirectional Encoder Representations from Transformer (BERT), a Transformer with Extra Long Contexts (Transformer-XL), or something similar, but is not limited to these.

[0059] Step 2012: Based on the perception radius information, obtain the code that is located before the currently edited line of code and meets the first line number indicated by the perception radius information from the code file, and use it as the code to be matched.

[0060] In one possible implementation, after determining the perception radius information indicating the first line number through the context-aware model, the code located before the currently edited line and satisfying the first line number indicated by the perception radius information can be obtained from the code file as the code to be matched.

[0061] In some embodiments, after obtaining the code to be matched, step 202 can be used to obtain the first feature parameter extracted by the language model to characterize the code features of the code to be matched, and the second feature parameter extracted by the language model to characterize the code features of each cached historical code segment.

[0062] In some embodiments, when obtaining the first feature parameter extracted by the language model to characterize the code features of the code to be matched in step 202, it can be achieved as follows: input the code to be matched into the language model, extract features from the code to be matched through the language model, and output the first feature parameter to characterize the code features of the code to be matched.

[0063] The language model can be pre-trained. It can take a piece of code as input and, through a series of processes within the language model, determine the code feature parameters that can characterize the code features of the input code.

[0064] Optionally, the code feature parameter can be a feature vector that can characterize the code feature, or it can be a feature value that can characterize the code feature; this specification does not limit this. That is, the first feature parameter can be a feature vector that can characterize the code feature, or it can be a feature value that can characterize the code feature.

[0065] It should be noted that the above embodiment is illustrated by taking the determination of the first feature parameter based on the code to be matched after obtaining the code to be matched. In more possible implementations, in order to improve the accuracy of the feature extraction process, character recognition can also be performed on the code to be matched to identify and delete the non-executable code part in the code to be matched, so as to obtain the code to be matched for input to the language model.

[0066] Optionally, the non-executable code portion may include blank lines, code comments, etc., which are not limited in this specification.

[0067] Through the above embodiments, non-executable code parts such as blank lines and code comments can be removed from the obtained code to be matched, thereby effectively avoiding the impact of non-executable code parts on the code feature extraction process.

[0068] In some embodiments, the process of obtaining the second feature parameters extracted by the language model to characterize the code features of each cached historical code segment in step 202 can be completed before caching the historical code segments. This allows the second feature parameters characterizing the code features of the historical code segments to be cached simultaneously, so that the cached code segments and their corresponding second feature parameters can be directly obtained later. In other words, the second feature parameters characterizing the code features of each cached historical code segment can be extracted in advance by the language model and pre-stored.

[0069] In some embodiments, for any historical code segment, when determining the second feature parameter of the historical code segment through a language model, it can be achieved as follows: input the historical code segment into a language model, extract features from the historical code segment through the language model, and output the second feature parameter used to characterize the code features of the historical code segment.

[0070] As mentioned above, the second code feature parameter can be a feature vector that can characterize code features, or it can be a feature value that can characterize code features. This specification does not limit this, but it must be ensured that the parameter type of the first feature parameter of the code to be matched is consistent with the parameter type of the second feature parameter of the historical code segment.

[0071] It should be noted that the above embodiment is illustrated by directly extracting the second feature parameter based on historical code fragments. In more possible implementations, in order to improve the accuracy of the feature extraction process, character recognition can also be performed on the historical code fragments to identify and delete the non-executable code parts in the historical code fragments, so as to obtain the historical code fragments used for input to the language model.

[0072] Optionally, the non-executable code portion may include blank lines, code comments, etc., which are not limited in this specification.

[0073] It should be noted that the above embodiment uses the extraction process of the second feature parameter of a single historical code segment as an example. The extraction process of the second feature parameter of other historical code segments is similar and will not be repeated here. In other words, each historical code segment can be input into a language model, and the language model can extract features from each historical code segment to output the second feature parameter used to characterize the code features of each historical code segment.

[0074] In some embodiments, after determining the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, step 203 can be used to perform matching based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, so as to determine the target code segment whose code features match the code features of the code to be matched from the multiple cached historical code segments.

[0075] As mentioned earlier, the first and second feature parameters are of the same type; both may be feature vectors or feature values. Regardless of their type, for any historical code segment, the code features of the code to be matched can be determined by comparing the first feature parameter of the code to be matched with the second feature parameter of the historical code segment. This determines whether the code features of the code to be matched match the code features of the historical code segment. By comparing the second feature parameter of each historical code segment with the first feature parameter of the code to be matched, the target code segment whose code features match the code features of the code to be matched can be identified from multiple historical code segments.

[0076] Optionally, after the target code segment is matched, step 204 can be used to perform character matching in the target code segment based on the edited code within a first preset range before the current code editing position, and determine the code within a second preset range after the matched code in the target code segment as the code to be filled.

[0077] In some embodiments, when performing character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position, and determining the code within a second preset range after the matched code in the target code segment as the code to be filled, step 204 can be achieved through the following steps.

[0078] Step 2041: Based on the edited code within the first preset range before the current code editing position in the currently edited line of code, perform character matching in the target code segment to determine the code portion in the target code segment that matches the edited code within the first preset range before the current code editing position.

[0079] As mentioned above, the edited code within the first preset range before the current code editing position can be the edited code within the first preset range before the current code editing position in the currently edited code line, including but not limited to the code from the beginning character of the currently edited code line to the current code editing position, the first N characters in the currently edited code line before the current code editing position, etc.

[0080] In one possible implementation, character-level matching can be performed in the target code segment based on each character of the edited code within a first preset range before the current code editing position in the previously edited code line. This comparison is performed character by character to determine the code portion in the target code segment that matches the characters of the edited code within the first preset range before the current code editing position, and this code portion is then identified as the matched code portion from the target code segment.

[0081] Step 2042: Starting from the code portion matched from the target code snippet, extract the code that belongs to the second preset range as the code to be filled.

[0082] As mentioned earlier, the perception radius information includes not only a first line number indicating the number of code lines preceding the code to be matched, but also a second line number indicating the number of code lines following the code to be matched. The second line number can be used to determine the second preset range. Therefore, when extracting code belonging to the second preset range after the matched code portion from the target code fragment, this can be achieved as follows: taking the first character after the matched code portion in the target code fragment as the starting position, extracting code that satisfies the second line number indicated by the perception radius information from the starting position, and considering this code as belonging to the second preset range.

[0083] Through the above embodiments, after hitting the target code segment in the cache, a secondary fuzzy match can be performed based on the hit target code segment to accurately locate the part of the target code segment that needs to be filled after the current code editing position.

[0084] Referring to Figure 3, which is a flowchart illustrating a code matching process provided in an exemplary embodiment, the code matching process provided in one or more embodiments of this specification can be as follows: when a user triggers a completion request, the context environment can be perceived in step 301 to determine the perception radius information. Then, in step 302, the code to be matched can be obtained based on the determined perception radius information. Then, in step 303, the feature parameters of the code to be matched can be calculated in real time, and it can be determined whether the feature parameters of the code to be matched match the feature parameters of the cached historical code segments, so as to achieve the matching of the code to be matched with the cached historical code segments. Optionally, if the match is successful, step 304 can be used to perform fuzzy matching of the content based on the edited code within the first preset range before the current code editing position. This allows for the matching of the part from the matched historical code segments that is consistent with the edited code within the first preset range before the current code editing position. This part is the code to be filled after the current code editing position. Then, step 305 can be used to trim the cached content according to the determined code part to obtain the code to be filled. At this point, it can be considered that the cache has been hit (i.e., the code to be filled has been successfully obtained). Conversely, if the match fails, it can be considered that the cache has not been hit (i.e., the code to be filled has not been successfully obtained). In addition, if the fuzzy matching of the content in step 304 does not find a part from the matched historical code segments that is consistent with the edited code within the first preset range before the current code editing position, it can be considered that the fuzzy matching of the content has failed, and it can also be considered that the cache has not been hit.

[0085] The solution provided by one or more embodiments in this specification splits the code matching process into two levels of matching. First, a matching is performed based on the code portion preceding the currently edited line. This effectively addresses the issue of rapid cursor position changes during user code editing, providing strong support for improving cache hit rate. Furthermore, the use of feature parameter-based matching during this first matching effectively utilizes the potential value of partially matched or similarly matched code segments, allowing the currently edited code to benefit from the cache even when it is not entirely identical to but similar to the cached code. Building upon this first matching, a fuzzy content matching scheme based on code characters is provided to determine the portion of the code that should actually be filled after the current code editing position within the matched code, further improving the accuracy of the code matching process.

[0086] Furthermore, the two-matching scheme provided in one or more embodiments of this specification can adapt to dynamically changing code generation needs, to adapt to changes in user behavior or different code generation contexts, thereby improving the flexibility and adaptability of the code matching process.

[0087] Experiments show that, through the solutions provided in one or more embodiments of this specification, the overall cache hit rate increased from 4.23% to 27.7%, a significant improvement. Furthermore, the overall code adoption rate of the matched code increased from approximately 22% to 24.22%, a marked improvement. In summary, the solutions provided in one or more embodiments of this specification can effectively improve the cache hit rate and enhance user experience. Moreover, due to the increased cache hit rate, cache matching failures are significantly reduced, consequently decreasing the number of requests made by electronic devices to the server, thereby reducing the processing load on the server.

[0088] In some embodiments, after the code to be filled is determined, it can be displayed after the current code editing position with a set display style. The set display style is different from the display style of the edited code in the code file, so that users can intuitively distinguish which code they edited and which code is recommended to be filled.

[0089] Alternatively, when displaying the code to be filled after the current code editing position with a set display style, it can be achieved in any of the following ways.

[0090] In one possible implementation, if there is no edited code after the current code editing position, the code to be filled is displayed after the current code editing position using a set font style. The set font style is different from the font style of the already edited code.

[0091] For example, if the font style is set to gray and the font style of the edited code is set to black, then if there is no edited code after the current code editing position, the code to be filled will be displayed in gray after the edited code displayed in black.

[0092] It should be noted that the above example uses font color as the font style for illustration. In other possible implementations, font size and font type can also be used as font styles to distinguish between edited code and code to be filled. This manual does not limit this.

[0093] In another possible implementation, if there is no edited code after the current code editing position, a first display control is displayed at the first target position corresponding to the current code editing position, so as to display the code to be filled in the first display control.

[0094] Optionally, the first target position can be a position to the right of the current code editing position, but is not limited to this.

[0095] Optionally, the first display control can be a display text box, but is not limited to this.

[0096] In another possible implementation, if there is already edited code after the current code editing position, a second display control is displayed at the second target position corresponding to the current code editing position, so as to display the code to be filled in the second display control.

[0097] Optionally, the first target position can be located to the right of the current code editing position, but is not limited thereto. Optionally, the positional relationship between the first target position and the current code editing position can be the same as or different from the positional relationship between the second target position and the current code editing position; this specification does not impose any limitations on this.

[0098] Optionally, the second display control can be a text box, but is not limited to this. Optionally, the control type, shape, size, etc. of the second display control and the first display control can be the same or different, and this specification does not limit this.

[0099] Through the above embodiments, the code to be filled can be displayed on the code editing page in a display style that is different from the display style of the edited code, so that users can quickly and accurately distinguish between the code they have edited and the code recommended to be filled.

[0100] Optionally, after displaying the code to be filled in the set display style after the current code editing position, the user can view the displayed code to be filled. If the user confirms that the code to be filled meets their code editing needs, the user can confirm the displayed code to be filled. The electronic device can then respond to the user's confirmation operation and automatically fill the code to be filled in after the current code editing position.

[0101] Optionally, when confirming the displayed code to be filled to trigger the confirmation operation, it can be done through a specified key on the keyboard. For example, the Tab key can be used to trigger the confirmation operation; or, a function button can be provided on the code editing page to provide the function of triggering the confirmation operation of the code to be filled, but it is not limited to this.

[0102] Optionally, when automatically filling the code to be filled after the current code editing position in response to the user's confirmation operation on the displayed code to be filled, if there is no edited code after the current code editing position, the code to be filled can be directly filled after the current code editing position; if there is edited code after the current code editing position, the edited code of the corresponding number of lines after the current code editing position can be replaced according to the number of lines of the code to be filled, so as to realize the filling of the code to be filled.

[0103] Specifically, the display style of the code to be filled after the current code editing position is consistent with the display style of the edited code in the code file. For example, if the code to be filled is displayed with a set font style before being filled, its display style can be changed to the same font style as the edited code after being filled to the current code editing position. As another example, if the code to be filled is displayed in the first display control before being filled, it can be displayed directly after the current code editing position after being filled, and the display of the first display control can be canceled.

[0104] The above embodiments mainly introduce the situation of cache hit and subsequent processing. In more possible implementations, in the case of cache miss, the electronic device can send a request to the server to request the latest, possibly updated code, or verify whether the cached code needs to be updated, so as to ensure that the latest code is obtained for automatic code filling when necessary.

[0105] Referring to Figure 4, which is a schematic diagram of the code processing architecture provided by an exemplary embodiment, as shown in Figure 4, when a user triggers code completion, the decision module of the electronic device can trigger the context-aware computing module to perform a series of processes such as context environment awareness, code matching based on feature parameters, fuzzy content matching, and cached content pruning, according to the user's request. For detailed descriptions, please refer to the above embodiments and the description in Figure 3, which will not be repeated here. Optionally, if the cache is successfully hit through the series of processes of the context-aware computing module 402, the context-aware computing module 402 can return the successfully matched code to be filled to the decision module 401, so that the decision module 401 can feed back the code to be filled to the user side; if the cache is not successfully hit, the context-aware computing module 402 can call the network library 403 to request assistance from the remote server to request the latest, possibly updated code, or to verify whether the cached code needs to be updated, etc.

[0106] Corresponding to the embodiments of the methods described above, this specification also provides corresponding device and apparatus embodiments.

[0107] Figure 5 is a schematic structural diagram of an electronic device provided in an exemplary embodiment. Referring to Figure 5, at the hardware level, the electronic device includes a processor 502, an internal bus 504, a network interface 506, a memory 508, and a non-volatile memory 510, and may also include other hardware required for its functions. One or more embodiments of this specification can be implemented in software, for example, the processor 502 reads the corresponding computer program from the non-volatile memory 510 into the memory 508 and then runs it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0108] One or more embodiments of this specification also provide a code processing apparatus. Please refer to FIG6, which is a block diagram of a code processing apparatus provided in an exemplary embodiment. This code processing apparatus can be applied to the electronic device shown in FIG5 to implement the technical solution of this specification. The code processing device may include: a determining module 601, configured to determine the text preceding the currently edited line of code as the code to be matched in response to a user's editing operation in a code file; an acquiring module 602, configured to acquire the following feature parameters extracted by a language model: a first feature parameter characterizing the code features of the code to be matched, and a second feature parameter characterizing the code features of each cached historical code segment; the determining module 601 is further configured to perform matching based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each cached historical code segment, so as to determine the target code segment whose code features match the code features of the code to be matched from the cached historical code segments; a matching module 603, configured to perform character matching in the target code segment based on the edited code within a first preset range before the current code editing position; the determining module 601 is further configured to determine the code within a second preset range after the matched code in the target code segment as the code to be filled, so as to fill it after the current code editing position.

[0109] In some embodiments, the determining module 601, when determining the preceding text of the currently edited code line as the code to be matched in response to a user's editing operation in a code file, is configured to: in response to a user's editing operation in a code file, determine a perception radius information based on the file information of the code file edited by the user and the line number of the currently edited code line, wherein the perception radius information includes at least a first line number indicating the number of the code line preceding the code to be matched; and, based on the perception radius information, obtain from the code file the code that is located before the currently edited code line and satisfies the first line number indicated by the perception radius information, as the code to be matched.

[0110] In some embodiments, when determining the perception radius information based on the file information of the code file edited by the user and the line number of the code line currently being edited by the user, the determining module 601 is configured to: input the file information of the code file and the line number of the code line currently being edited by the user into the context environment awareness model, and output the perception radius information through the context environment awareness model; wherein, the file information includes at least one of the following: code file type, file storage path, and code programming language.

[0111] In some embodiments, when the matching module 603 is used to perform character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position, it is used to: perform character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position in the currently edited code line, so as to determine from the target code segment a code portion that matches the edited code within the first preset range prior to the current code editing position; when the determining module 601 is used to determine the code within a second preset range after the matched code in the target code segment as the code to be filled, it is used to: extract code belonging to the second preset range starting from the code portion matched in the target code segment, as the code to be filled.

[0112] In some embodiments, the perception radius information further includes a second line number indicating the number of lines of code following the code to be matched, the second line number being used to determine the second preset range; the determining module 601, when extracting code belonging to the second preset range after the code portion matched from the target code segment, is used to: take the first character after the code portion matched from the target code segment as the starting position, and extract code that satisfies the second line number indicated by the perception radius information from the starting position as code belonging to the second preset range.

[0113] In some embodiments, when the acquisition module 602 is used to acquire the first feature parameter extracted by the language model to characterize the code features of the code to be matched, it is used to: input the code to be matched into the language model, extract features from the code to be matched through the language model, and output the first feature parameter to characterize the code features of the code to be matched.

[0114] In some embodiments, the apparatus further includes a deletion module, configured to perform character recognition on the code to be matched, so as to identify and delete the non-executable code portion in the code to be matched, thereby obtaining the code to be matched for input into the language model.

[0115] In some embodiments, the second feature parameter used to characterize the code features of each cached historical code segment is extracted in advance by the language model. The extraction process of the second feature parameter used to characterize the code features of each cached historical code segment includes: inputting each of the historical code segments into the language model, extracting features from each historical code segment by the language model, and outputting the second feature parameter used to characterize the code features of each historical code segment.

[0116] In some embodiments, the apparatus further includes a display module, configured to display the code to be filled in a set display style after the current code editing position, wherein the set display style is different from the display style of the edited code in the code file.

[0117] In some embodiments, when the display module is used to display the code to be filled after the current code editing position with a set display style, it is configured to: if there is no edited code after the current code editing position, display the code to be filled after the current code editing position with a set font style; if there is no edited code after the current code editing position, display a first display control at a first target position corresponding to the current code editing position to display the code to be filled in the first display control; if there is edited code after the current code editing position, display a second display control at a second target position corresponding to the current code editing position to display the code to be filled in the second display control.

[0118] In some embodiments, the apparatus further includes a filling module, configured to automatically fill the code to be filled after the current code editing position in response to the user's confirmation operation on the displayed code to be filled, wherein the display style of the code to be filled after being automatically filled after the current code editing position is consistent with the display style of the edited code in the code file.

[0119] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.

[0120] In a typical configuration, a computer includes one or more processors (Central Processing Units, CPUs), input / output interfaces, network interfaces, and memory.

[0121] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0122] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital video disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device. As defined in this article, computer-readable media do not include transient computer-readable media, such as modulated data signals and carrier waves.

[0123] In some embodiments, this specification also provides a computer program product, including a computer program that, when executed by a processor of a computing device, implements the code processing method provided in any embodiment of this specification.

[0124] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0125] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0126] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this specification. The singular forms “a,” “described,” and “the” used in one or more embodiments of this specification and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0127] It should be understood that although the terms first, second, third, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of one or more embodiments of this specification, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "in response to a determination," or "when," or "in the event of a determination."

[0128] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the protection scope of one or more embodiments of this specification.

Claims

1. A code processing method, the method comprising: In response to a user's editing operation in a code file, the text preceding the currently edited line of code is determined as the code to be matched; The following feature parameters extracted by the language model are obtained respectively: a first feature parameter used to characterize the code features of the code to be matched, and a second feature parameter used to characterize the code features of each cached historical code segment; Matching is performed based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, so as to determine the target code segment whose code features match the code features of the code to be matched from the multiple cached historical code segments. Based on the edited code within a first preset range prior to the current code editing position, character matching is performed in the target code segment, and the code within a second preset range after the matched code in the target code segment is determined as the code to be filled, so as to be filled after the current code editing position.

2. The method according to claim 1, wherein determining the text preceding the currently edited line of code as the code to be matched in response to the user's editing operation in the code file includes: In response to a user's editing operation in a code file, based on the file information of the code file edited by the user and the line number of the code line currently being edited by the user, a perception radius information is determined, wherein the perception radius information includes at least the first line number indicating the number of the code line preceding the code to be matched; Based on the perception radius information, the code located before the currently edited line of code and satisfying the first line number indicated by the perception radius information is obtained from the code file and is used as the code to be matched.

3. The method according to claim 2, wherein determining the perception radius information based on the file information of the code file edited by the user and the line number of the currently edited code line includes: The file information of the code file and the line number of the code line currently being edited by the user are input into the context environment awareness model, and the awareness radius information is output through the context environment awareness model; The file information includes at least one of the following: code file type, file storage path, and code programming language.

4. The method according to claim 2, wherein the step of performing character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position, and determining the code within a second preset range after the matched code in the target code segment as the code to be filled, comprises: Based on the edited code within a first preset range prior to the current code editing position in the currently edited line of code, character matching is performed in the target code segment to determine the code portion that matches the edited code within the first preset range prior to the current code editing position from the target code segment; Starting from the code portion matched from the target code fragment, extract the code that belongs to the second preset range and use it as the code to be filled.

5. The method according to claim 4, wherein the sensing radius information further includes a second line number indicating the line number following the code to be matched, the second line number being used to determine the second preset range; The step of extracting code belonging to the second preset range after the code portion matched from the target code fragment includes: Using the first character after the code portion matched in the target code fragment as the starting position, extract the code that satisfies the second line number indicated by the perception radius information from the starting position, and use it as the code belonging to the second preset range.

6. The method according to claim 1, wherein obtaining the first feature parameter extracted by the language model to characterize the code features to be matched comprises: The code to be matched is input into the language model, and the language model extracts features from the code to be matched, so as to output a first feature parameter that represents the code features of the code to be matched.

7. The method according to claim 6, before inputting the code to be matched into the language model, extracting features from the code to be matched through the language model, and outputting a first feature parameter for characterizing the code features of the code to be matched, the method further includes: Character recognition is performed on the code to be matched to identify and delete the non-executable code portion of the code to be matched, so as to obtain the code to be matched for input into the language model.

8. The method according to claim 1, wherein the second feature parameter used to characterize the code features of each cached historical code fragment is extracted in advance through the language model, wherein, The extraction process of the second feature parameter, used to characterize the code features of each cached historical code segment, includes: Each of the historical code fragments is input into the language model, and features are extracted from each historical code fragment by the language model to output a second feature parameter that represents the code features of each historical code fragment.

9. The method according to claim 1, wherein after performing character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position, and determining the code within a second preset range after the matched code in the target code segment as the code to be filled, the method further comprises: After the current code editing position, the code to be filled is displayed with a set display style, wherein the set display style is different from the display style of the edited code in the code file.

10. The method according to claim 9, wherein displaying the code to be filled with a set display style after the current code editing position includes any one of the following: If there is no edited code after the current code editing position, the code to be filled will be displayed after the current code editing position using the set font style; If there is no edited code after the current code editing position, a first display control is displayed at the first target position corresponding to the current code editing position, so as to display the code to be filled in the first display control; If there is already edited code after the current code editing position, a second display control is displayed at the second target position corresponding to the current code editing position, so as to display the code to be filled in the second display control.

11. The method according to claim 9, wherein after displaying the code to be filled with a set display style after the current code editing position, the method further comprises: In response to the user's confirmation of the displayed code to be filled, the code to be filled is automatically filled after the current code editing position, wherein the display style of the code to be filled after being automatically filled after the current code editing position is consistent with the display style of the edited code in the code file.

12. A code processing apparatus, the apparatus comprising: The determination module is used to determine the text preceding the currently edited line of code in the code file as the code to be matched in response to the user's editing operation in the code file; The acquisition module is used to acquire the following feature parameters extracted by the language model: a first feature parameter used to characterize the code features of the code to be matched, and a second feature parameter used to characterize the code features of each cached historical code segment; The determining module is further configured to perform matching based on the first feature parameter of the code to be matched and the second feature parameter corresponding to each of the cached historical code segments, so as to determine the target code segment whose code features match the code features of the code to be matched from the cached historical code segments. The matching module is used to perform character matching in the target code segment based on the edited code within a first preset range prior to the current code editing position; The determining module is further configured to determine the code within a second preset range after the matched code in the target code segment as the code to be filled, so as to fill it after the current code editing position.

13. An electronic device, comprising: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any one of claims 1-11 by executing the executable instructions.

14. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-11.

15. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-11.