A method, apparatus and device for code intelligent completion
The intelligent code completion system addresses inefficiencies in existing systems by employing pre-interception and post-processing to filter requests and optimize code completion, resulting in improved performance and user experience.
Patent Information
- Authority / Receiving Office
- HK · HK
- Patent Type
- Applications
- Current Assignee / Owner
- ALIBABA (CHINA) CO LTD
- Filing Date
- 2026-04-15
- Publication Date
- 2026-07-10
AI Technical Summary
Existing code completion systems face issues such as frequent invalid requests, repeated display of the same results, lack of effective concurrency control, and insufficient intelligence, leading to resource waste, performance decline, and poor user experience.
A method and apparatus for intelligent code completion that involves pre-interception and post-processing interception to filter out invalid and duplicate requests, using a large language model to generate and optimize code completion content based on user behavior patterns and context.
This approach enhances code completion efficiency and accuracy, reducing resource consumption and improving user experience by minimizing invalid requests and duplicate displays.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
(19) State Intellectual Property Office (12) Invention Patent Application (10) Application Publication Number (43) Application Publication Date (21) Application Number 202511676101.5 (22) Application Date 2025.11.14 (71) Applicant Alibaba (China) Co., Ltd. Address 310052, Room 508, 5th Floor, Building 4, No. 699, Wangshang Road, Changhe Street, Binjiang District, Hangzhou City, Zhejiang Province (72) Inventor Ren Jingxin (74) Patent Agency Beijing Ruipai Intellectual Property Agency Co., Ltd. 11597 Patent Attorney Liu Feng Yang Chunxiao (51) Int.Cl. G06F 8 / 33 (2018.01) G06F 8 / 35 (2018.01) G06F 8 / 36 (2018.01) (54) Invention Title A method, apparatus and device for intelligent code completion (57) Abstract The embodiments of this invention disclose a method, apparatus and device for intelligent code completion. In this embodiment of the invention, candidate code completion requests are obtained, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in the code editor; the candidate code completion requests are pre-intercepted to determine the target code completion request; the target code completion request is sent to a large language model, and candidate code completion content sent by the large language model is received; the candidate code completion content is post-processed and intercepted to determine the target code completion content; and the target code completion content is sent to the code editor. Through this method, code completion can be performed efficiently and accurately. Pre-interception reduces invalid requests, and post-processing interception reduces the display of duplicate completion content, thus improving the user experience. Claims 2 pages, Description 12 pages, Drawings 6 pages, CN 121680809 A 2026.03.17 CN 1 21 68 08 09 A 1. A method for intelligent code completion, characterized in that the method includes: acquiring candidate code completion requests, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in a code editor; pre-intercepting the candidate code completion requests to determine a target code completion request; sending the target code completion request to a large language model and receiving candidate code completion content sent by the large language model; post-processing and intercepting the candidate code completion content to determine the target code completion content; sending the target code completion content to a code editor. 2. The method according to claim 1, wherein the step of pre-intercepting the candidate code completion request to determine the target code completion request specifically includes: determining the corresponding code editor based on the candidate code completion request; and, in response to the code editor meeting the preset code completion requirements, performing multi-level pre-interception on the candidate code completion request.3. The method according to claim 2, wherein the pre-set code completion requirements include: the code editor being the main editor and the prediction function of the code editor being enabled. 4. The method according to claim 2, wherein the step of determining the candidate code completion request as the target code completion request in response to the candidate code completion request passing through the multi-level pre-interception specifically includes: determining a non-duplicate code completion request in response to the candidate code completion request passing through repeated display filtering; determining a delayed code completion request in response to the non-duplicate code completion request passing through a delay debouncing mechanism; and determining the target code completion request in response to the delayed code completion request passing through a validity check. 5. The method according to claim 4, wherein determining a non-duplicate code completion request in response to the candidate code completion request through duplicate display filtering specifically includes: querying the rejection cache based on the candidate code completion request, wherein the rejection cache includes code completion content rejected by the user, its corresponding cursor position, and display time; and determining the candidate code completion request as the non-duplicate code completion request in response to the rejection cache not finding user-rejected code completion content corresponding to the candidate code completion request. 6. The method according to claim 4, wherein determining a delayed code completion request in response to the non-duplicate code completion request through a delay debouncing mechanism specifically includes: determining the non-duplicate code completion request as the delayed code completion request in response to the non-duplicate code generation set time period, provided that the code document has not been changed and no cursor movement event has been sent. 7. The method according to claim 1, wherein the step of post-processing and intercepting the candidate code completion content to determine the target code completion content specifically includes: segmenting the candidate code completion content into completion results to determine at least one difference content; filtering the at least one difference content using change amount control to determine at least one candidate valid completion content; performing similarity checks and empty change checks on the at least one candidate valid completion content to determine at least one valid completion content; querying the rejection cache based on the at least one valid completion content, and in response to not finding the code completion content corresponding to the valid completion content in the rejection cache, determining the at least one valid completion content as the target code completion content. 8. The method according to claim 1, wherein the method further includes: saving the target code completion content to a completion result cache; or, saving the target code completion content to a rejection cache.9. The method according to claim 8, characterized in that the method further comprises: querying the completion result cache according to the target code completion request, and determining the code content corresponding to the target code completion request as the code completion content in response to the existence of code content corresponding to the target code completion request in the completion result cache. 10. An apparatus for intelligent code completion, characterized in that the apparatus comprises: an acquisition unit, configured to acquire candidate code completion requests, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in a code editor; a pre-processing unit, configured to pre-intercept the candidate code completion requests to determine a target code completion request; a transmission unit, configured to send the target code completion request to a large language model and receive candidate code completion content sent by the large language model; a post-processing unit, configured to post-process and intercept the candidate code completion content to determine the target code completion content; the transmission unit is further configured to send the target code completion content to the code editor. 11. An electronic device comprising a memory and a processor, characterized in that the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in any one of claims 1-9. 12. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program, which, when executed by a processor, implements the method as described in any one of claims 1-9. Claims 2 / 2 Page 3 CN 121680809 A A Method, Apparatus, and Device for Intelligent Code Completion Technical Field
[0001] This invention relates to the field of computer technology, and more specifically, to a method, apparatus, and device for intelligent code completion. Background Art
[0002] With the popularization of Artificial Intelligence (AI) assisted programming tools, intelligent code completion has become an important tool for improving the programming efficiency of developers.
[0003] In the prior art, common code completion systems have the following problems: for example, the code editor frequently sends invalid requests, resulting in serious waste of system resources and a decline in overall performance; repeatedly displaying the same code completion results interferes with user programming and affects user experience; lacks effective concurrency control and resource management mechanisms, making it difficult to cope with concurrent request conflicts in fast editing scenarios; and has insufficient intelligence, failing to perform accurate completion and intelligent display based on user behavior patterns.
[0004] In summary, how to perform code completion efficiently and accurately and improve user experience is a problem that needs to be solved. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method, apparatus, and device for intelligent code completion, which can efficientlyFurthermore, it accurately performs code completion, employs pre-processing interception to reduce invalid requests, and post-processing interception to reduce the display of duplicate completed content, thereby improving the user experience.
[0006] In a first aspect, embodiments of the present invention provide a method for intelligent code completion, the method comprising: obtaining candidate code completion requests, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in a code editor; pre-processing interception of the candidate code completion requests to determine a target code completion request; sending the target code completion request to a large language model and receiving candidate code completion content sent by the large language model; post-processing interception of the candidate code completion content to determine the target code completion content; and sending the target code completion content to the code editor.
[0007] Optionally, the step of pre-intercepting the candidate code completion request to determine the target code completion request specifically includes: determining the corresponding code editor based on the candidate code completion request; in response to the code editor meeting the preset code completion requirements, performing multi-level pre-interception on the candidate code completion request; and in response to the candidate code completion request passing the multi-level pre-interception, determining the candidate code completion request as the target code completion request.
[0008] Optionally, the preset code completion requirements include: the code editor being the main editor and the prediction function of the code editor being enabled.
[0009] Optionally, the step of determining the candidate code completion request as the target code completion request in response to the candidate code completion request passing through the multi-level pre-interception specifically includes: determining a non-duplicate code completion request in response to the candidate code completion request passing through repeated display filtering; determining a delayed code completion request in response to the non-duplicate code completion request passing through a delay debouncing mechanism; and determining the target code completion request in response to the delayed code completion request passing through a legality check.
[0010] Optionally, the step of determining a non-duplicate code completion request in response to the candidate code completion request passing through repeated display filtering specifically includes: querying the rejection cache according to the candidate code completion request, wherein the rejection cache includes the code completion content rejected by the user, its corresponding cursor position, and display time; and determining the candidate code completion request as the non-duplicate code completion request in response to the rejection cache not finding the user-rejected code completion content corresponding to the candidate code completion request.
[0011] Optionally, the response to the non-duplicate code completion request, through a delay debouncing mechanism, determines the delayed code completion request, specifically including: in response to the non-duplicate code generation set time, the code document has not been changed and has not been published.Send a cursor movement event to determine the non-duplicate code completion request as the delayed code completion request.
[0012] Optionally, the step of post-processing and intercepting the candidate code completion content to determine the target code completion content specifically includes: segmenting the candidate code completion content into completion results to determine at least one difference content; filtering the at least one difference content with change amount control to determine at least one candidate valid completion content; performing similarity checks and empty change checks on the at least one candidate valid completion content to determine at least one valid completion content; querying the rejection cache based on the at least one valid completion content, and in response to the fact that no code completion content corresponding to the valid completion content is found in the rejection cache, determining the at least one valid completion content as the target code completion content.
[0013] Optionally, the method further includes: saving the target code completion content to the completion result cache; or, saving the target code completion content to the rejection cache.
[0014] Optionally, the method further includes: querying the completion result cache according to the target code completion request, and in response to the existence of code content corresponding to the target code completion request in the completion result cache, determining the code content corresponding to the target code completion request as the code completion content.
[0015] In a second aspect, embodiments of the present invention provide an apparatus for intelligent code completion, the apparatus comprising: an acquisition unit, configured to acquire candidate code completion requests, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in a code editor; a pre-processing unit, configured to pre-intercept the candidate code completion requests to determine a target code completion request; a transmission unit, configured to send the target code completion request to a large language model and receive candidate code completion content sent by the large language model; a post-processing unit, configured to post-process and intercept the candidate code completion content to determine the target code completion content; the transmission unit is further configured to send the target code completion content to the code editor.
[0016] Optionally, the pre-processing unit is specifically used to: determine the corresponding code editor based on the candidate code completion request; in response to the code editor meeting the preset code completion requirements, perform multi-level pre-processing interception on the candidate code completion request; in response to the candidate code completion request passing the multi-level pre-processing interception, determine the candidate code completion request as the target code completion request.
[0017] Optionally, the preset code completion requirements include: the code editor being the main editor and the prediction function of the code editor being enabled.
[0018] Optionally, the pre-processing unit is further used to: in response to the candidate code completion request passing the repeated display filter, determine a non-repeating code completion request; in response to the non-repeating code completion request passing the delay debouncing mechanism, determine...Delayed code completion request; in response to the delayed code completion request passing the validity check, the target code completion request is determined.
[0019] Optionally, the front-end unit is further configured to: query the rejection cache according to the candidate code completion request, wherein the rejection cache includes the code completion content rejected by the user, its corresponding cursor position and display time; in response to the rejection cache not finding the user-rejected code completion content corresponding to the candidate code completion request in the rejection cache, the candidate code completion request is determined as the non-duplicate code completion request.
[0020] Optionally, the front-end unit is further configured to: in response to the non-duplicate code generation set time, if the code document has not been changed and no cursor movement event has been sent, the non-duplicate code completion request is determined as the delayed code completion request.
[0021] Optionally, the post-processing unit is further configured to: segment the candidate code completion content to determine at least one difference content; perform change amount control filtering on the at least one difference content to determine at least one candidate valid completion content; perform similarity check and empty change check on the at least one candidate valid completion content to determine at least one valid completion content; query the rejection cache according to the at least one valid completion content, and in response to the fact that no code completion content corresponding to the valid completion content is found in the rejection cache, determine the at least one valid completion content as the target code completion content.
[0022] Optionally, the device further includes: a storage unit, configured to store the target code completion content to the completion result cache; or, store the target code completion content to the rejection cache.
[0023] Optionally, the device further includes a query unit, configured to query the completion result cache according to the target code completion request, and in response to the existence of code content corresponding to the target code completion request in the completion result cache, determine the code content corresponding to the target code completion request as the code completion content.
[0024] In a third aspect, embodiments of the present invention provide an electronic device, including a memory and a processor, the memory being used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect or any one of the possible methods of the first aspect.
[0025] In a fourth aspect, embodiments of the present invention provide a computer-readable storage medium storing computer program instructions thereon, the computer program instructions, when executed by a processor, implementing the method as described in the first aspect or any one of the possible methods of the first aspect.
[0026] In embodiments of the present invention, by obtaining a candidate code completion request, wherein the candidate code completion request is obtained through...This method involves: intercepting candidate code completion requests triggered by code document changes or cursor movement events in the code editor; determining the target code completion request; sending the target code completion request to a large language model and receiving candidate code completion content from the large language model; post-processing the candidate code completion content to determine the target code completion content; and sending the target code completion content to the code editor. This approach enables efficient and accurate code completion, reducing invalid requests through pre-interception and minimizing duplicate completion display through post-processing, thus improving the user experience.
[0027] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the present invention with reference to the accompanying drawings, in which: FIG1 is a schematic diagram of a code intelligent completion system according to an embodiment of the present invention; FIG2 is a flowchart of a code intelligent completion method according to an embodiment of the present invention; FIG3 is a flowchart of a pre-interception method according to an embodiment of the present invention; FIG4 is a flowchart of another pre-interception method according to an embodiment of the present invention; FIG5 is a flowchart of a post-processing interception method according to an embodiment of the present invention; FIG6 is a flowchart of another code intelligent completion method according to an embodiment of the present invention; FIG7 is a schematic diagram of a code intelligent completion device according to an embodiment of the present invention; FIG8 is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Description
[0028] The present application is described below based on embodiments, but the present application is not limited to these embodiments. In the following detailed description of the present application, some specific details are described in detail. The present application can be fully understood by those skilled in the art without these details. In order to avoid obscuring the substance of the present application, well-known methods, processes, flows, elements and circuits are not described in detail.
[0029] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes and are not necessarily drawn to scale.
[0030] Unless the context explicitly requires it, the words "including," "comprising," and similar terms throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to."
[0031] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0032] In the prior art, common code completion systems have the following problems: the code editor frequently sends invalid requests, resulting in serious waste of system resources and a decline in overall performance; repeatedly displaying the same code completion results creates difficulties for users' programming.These problems include: interference and impact on user experience; a lack of effective concurrency control and resource management mechanisms, making it difficult to handle concurrent request conflicts in rapid editing scenarios; and insufficient intelligence, failing to accurately complete and intelligently display content based on user behavior patterns. Traditional rule-based filtering schemes suffer from problems such as rigid rules, inability to adapt to complex scenarios, and low filtering accuracy; simple delay mechanisms have fixed delay times, cannot dynamically adjust according to user behavior, and lack intelligent caching; frequency-based filtering schemes cannot handle new scenarios, statistical data is easily outdated, and lacks context awareness; single-dimensional duplicate detection schemes only consider content similarity, ignoring position and time factors, and are prone to misjudgment; other schemes based on machine learning prediction filtering, dynamic adjustment based on user feedback, and semantic analysis intelligent filtering have drawbacks such as requiring large amounts of training data, cold start, high complexity, and difficulty in meeting real-time requirements. Therefore, it is crucial to find a way to efficiently and accurately complete code, reduce invalid requests, reduce duplicate completion display, lower resource consumption, and improve user experience.
[0033] In this embodiment of the invention, code completion is achieved by designing a code intelligent completion system. Specifically, the code intelligent completion system, as shown in Figure 1, includes a code editor 101, a request interceptor 102, and a large language model 103; wherein, the code editor 101 can be an integrated development environment (IDE). The IDE (Code Explorer) code editor allows users to open code documents and make code changes, including editing and modifying code. When code changes or cursor movement occur in the code editor, candidate code completion requests are triggered. The code editor sends these requests to a request interceptor 102, which performs pre-interception to identify the target code completion request. The request interceptor 102 then sends the target request to a large language model 103, which generates candidate code completion content and sends it to the request interceptor 102. The request interceptor 102 performs post-processing interception on the candidate code completion content to identify the target code completion content, which is then sent to the code editor 101 for display.
[0034] In this embodiment of the invention, in order to solve the above problems, the request interceptor 102 in the code intelligent completion system plays a relatively important role. Taking the request interceptor 102 as the execution subject, a code intelligent completion method is proposed. See Figure 2 for details (page 4 / 12, CN 121680809 A). The method includes: Step S201, obtaining candidate code completion requests.
[0035] Specifically, the candidate code completion request is triggered by a code document change or cursor movement event in the code editor.
[0036] In one possible implementation, the candidate code completion request is sent by the code editor to the request interceptor. The conditions for the code editor to trigger the generation of the candidate code completion request include code document changes in the code editor, cursor movement events, and the IDE syntax service being closed by the user.
[0037] In this embodiment of the invention, the code document changes include operations such as inserting, deleting, and replacing code documents, for example, the user inputs new code, deletes existing code, pastes code snippets, etc.; the cursor movement events include operations such as clicking and keyboard navigation, for example, the user clicks the cursor to a new position, uses the arrow keys to move the cursor, jumps to a definition, etc.
[0038] The code editor is used to listen for the code document changes and the cursor movement events to obtain the candidate code completion request.
[0039] Step S202: The candidate code completion request is pre-intercepted to determine the target code completion request.
[0040] In one possible implementation, the step of pre-intercepting the candidate code completion request to determine the target code completion request, as shown in Figure 3, includes the following steps: Step S301: Determine the corresponding code editor based on the candidate code completion request.
[0041] Specifically, the candidate code completion request carries an identifier of the code editor, which indicates the code editor that sent the candidate code completion request.
[0042] Step S302: In response to the code editor meeting the preset code completion requirements, perform multi-level pre-interception on the candidate code completion request.
[0043] Specifically, the preset code completion requirements include: the code editor is the main editor and the prediction function of the code editor is enabled.
[0044] In one possible implementation, in response to the code editor being the main editor and the existence of the code completion item corresponding to the candidate code completion request, it is ensured that the code editor is executed in the correct environment; if the code editor is not the main editor, the candidate code completion request is in unit test mode, and the subsequent processing of code completion is not triggered to avoid interference from the test environment; when the code editor is determined to be the main editor, it is further determined whether the prediction function of the code editor is enabled; in response to the prediction function of the code editor being enabled, the candidate code completion request is intercepted at multiple levels.
[0045] In one possible implementation, before intercepting the candidate code completion request at multiple levels, it is also necessary to check whether the code editor has a running completion task to avoid resource contention and poor user experience caused by concurrent execution.
[0046] Step S303: In response to the candidate code completion request passing the multi-level pre-interception, determine the candidate code completion request as the target code completion request.
[0047] In one possible implementation, the step of determining the candidate code completion request as the target code completion request in response to the candidate code completion request passing the multi-level pre-interception is as shown in Figure 4, including the following steps: Step S401: In response to the candidate code completion request passing the duplicate display filter, determine the non-duplicate code completion request.
[0048] Specifically, query the rejection cache according to the candidate code completion request, wherein the rejection cache includes the code completion content rejected by the user, its corresponding cursor position, and display time; in response to the rejection cache not finding the user-rejected code completion content corresponding to the candidate code completion request, determine the candidate code completion request as the non-duplicate code completion request.
[0049] In one possible implementation, the displayed time refers to the time when the code completion content rejected by the user is displayed in the code editor interface. The rejection cache can also store the hash value corresponding to the cursor position as a cache key value. The candidate code completion request carries the candidate cursor position. The candidate cursor position is converted into a candidate hash value. The rejection cache is queried according to the candidate hash value. If the code completion content rejected by the user corresponding to the candidate code completion request is not found in the rejection cache, the candidate code completion request is determined as the non-duplicate code completion request. If the code completion content rejected by the user corresponding to the candidate code completion request is found in the rejection cache, the processing ends.
[0050] In one possible implementation, the cursor position is represented by a file path and line number range. By means of the above method, it is checked whether the current cursor position is within the range of the last completion, so as to avoid displaying the code completion content repeatedly in the same position.
[0051] Step S402: In response to the non-duplicate code completion request, a delayed code completion request is determined through a delay debouncing mechanism.
[0052] Specifically, in response to the non-repeating code generation set time, if the code document remains unchanged and no cursor movement event is sent, the non-repeating code completion request is determined as the delayed code completion request.
[0053] In one possible implementation, if the code document changes or a cursor movement event occurs, the non-repeating code completion request is cancelled. Through a cancelable delayed task mechanism, frequent triggering of code completion requests during rapid user editing can be avoided. During the delay period, the code document is checked for changes; if changes are found, the current task is cancelled and the timing restarts.
[0054] Step S403: In response to the delayed code completion request passing the legality check, the target code completion request is determined.
[0055] Specifically, the legality check refers to checking for blank content, single symbols, excessive import statements, etc. For example, filtering blank content can avoid meaningless completion; filtering single symbols, for example, filtering single right curly braces, which do not need to be completed; filtering excessive import statements to avoid the completion result being mainly import statements; if the legality check is passed, the delayed code completion request is determined to be the target code completion request; if the legality check is not passed, the processing ends.
[0056] In this embodiment of the invention, the delay time is dynamically adjusted according to the user's editing mode, combining the cursor position, display time, and the user's editing mode to balance the response speed and request frequency, and precise cache matching is performed in the rejection cache based on the hash value to avoid duplicate processing; a multi-layer filtering and verification mechanism is used for pre-interception before sending the target code completion request.
[0057] Step S203: The target code completion request is sent to the large language model, and the candidate code completion content sent by the large language model is received.
[0058] Specifically, the Large Language Model (LLM) can also be called a large model or a large language model, etc., wherein the large language model is a deep learning model based on a transformer architecture, capable of processing and generating natural language text. It is usually trained on a large amount of text data, has the ability to understand and generate language, and is widely used in dialogue systems, text generation and other natural language processing tasks. In this embodiment of the invention, code completion is mainly performed through context.
[0059] In this embodiment of the invention, after the large language model receives the target code completion request, it constructs a context, generates candidate code completion content according to the context, and sends the candidate code completion content to the request interceptor.
[0060] Step S204: Post-process the candidate code completion content and intercept it to determine the target code completion content.
[0061] Specifically, the post-processing interception of the candidate code completion content to determine the target code completion content, as shown in Figure 5, includes the following steps: Step S501: Segment the completion results of the candidate code completion content to determine at least one difference content.
[0062] Specifically, calculate the difference between the candidate code completion content and the original document, use an inline diff utility to perform precise diff analysis, and determine at least one difference content, each difference content including at least one line of code; if there are multiple difference contents, the difference between the candidate code completion content and the original document includes multiple code segments, and the...The multiple code segments are sorted according to the end line number to ensure the consistency of the processing order.
[0063] Step S502: Perform change amount control filtering on the at least one difference content to determine at least one candidate valid completion content.
[0064] Specifically, change amount control filtering needs to be performed on each difference content, and the change amount of a single completion is controlled by configuration parameters; for example, limit the number of inserted lines to avoid inserting too much code at once; limit the number of deleted lines to avoid accidentally deleting a large amount of code; control the total number of changed lines to maintain the controllability of the completion; the purpose of limiting the number of inserted lines is to avoid inserting too many code blocks at once, resulting in a messy code structure, or inserting long and undesirable code; the purpose of limiting the number of deleted lines is to prevent the completion operation from accidentally deleting a large amount of code already existing by the user; the control of the total number of changed lines is a combination and supplement to the above two, controlling the scope of code disturbance of a single completion operation.
[0065] Step S503: Perform similarity checks and empty change checks on the at least one candidate valid completion content to determine at least one valid completion content.
[0066] Specifically, the similarity check refers to avoiding repeated display through a string similarity algorithm. For example, the similarity between the candidate valid completion content and the current document content is checked using a string similarity utility class. If the candidate valid completion content is too similar to or completely identical to the code in the current document, it is skipped from display. Candidate valid completion content with a similarity less than a set threshold is determined as valid completion content. The empty change check refers to checking whether the candidate valid completion content has produced actual code changes. The source code and the completed code are compared line by line. If any changes are all blank characters, it is considered invalid completion.
[0067] Step S504: Query the rejection cache according to the at least one valid completion content. In response to the fact that the code completion content corresponding to the valid completion content is not found in the rejection cache, the at least one valid completion content is determined as the target code completion content.
[0068] In this embodiment of the invention, a completion identifier is determined based on the valid completion content. The completion identifier can be a hash value. The hash value is matched with the hash value corresponding to the code completion content in the rejection cache. If the match is successful, it means that the valid completion content has been rejected by the user and will not be displayed again to avoid repeatedly displaying rejected content. If the match fails, it means that the valid completion content has not been rejected by the user, and the valid completion content is determined as the target code completion content.
[0069] In one possible implementation, after querying the rejection cache, intelligent detection is also performed. The intelligent detection is used to detect whether the user accepted the completion before reversing it. By analyzing the code document change event and the completion content, the user's operation intention is determined to avoid re-displaying the same completion after the rollback operation.
[0070] In this embodiment of the invention, the post-processing interception is a content filtering and optimization process performed before the target code completion content is displayed. Specification 7 / 12 pages 10 CN 121680809 A
[0071] Step S205: Send the target code completion content to the code editor.
[0072] In this embodiment of the invention, after receiving the target code completion content, the code editor displays the target code completion content in the code editor's interface.
[0073] In one possible implementation, the most suitable completion for the current cursor position is selected from multiple completion code segments in the target code completion content using a nearest completion selection algorithm. Priority is given to selecting completion code segments within the cursor's range. If no direct match is found, the nearest completion code segment is selected. Then, the importance and relevance of the completion are considered for ranking.
[0074] Specifically, the display method of the target code completion content in the code editor is selected based on the complexity of the target code completion content, including Inlay prompts, Popup panels, and Tab buttons. The Inlay prompts are suitable for simple code insertions and are displayed directly in the code editor; the Popup panels are suitable for complex code changes, improving detailed difference comparisons; and the Tab buttons are suitable for completions at greater distances, providing prompts to the user.
[0075] In one possible implementation, the user may perform operations such as accepting, delaying display, and rejecting the target code completion content. The target code completion content accepted and delayed is saved to the completion result cache; the target code completion content rejected is saved to the rejection cache.
[0076] In one possible implementation, before inputting the target code completion request into a large language model, the method further includes: querying the completion result cache according to the target code completion request; and in response to the existence of code content corresponding to the target code completion request in the completion result cache, determining the code content corresponding to the target code completion request as the code completion content.
[0077] In this embodiment of the invention, the intelligent code completion system also sets a task cancellation mechanism and a memory management mechanism to clean up all related resources before code document changes, including cache cleaning, task cancellation, and resource release, to ensure the consistency of the intelligent code completion system and the effective utilization of resources; and uses a disposable mode to manage the resource lifecycle, and determines the timely release of resources by registering cleaning callbacks to avoid memory leaks and resource contention problems.
[0078] The following is a detailed description of the intelligent code completion process of the intelligent code completion system through a complete embodiment, as shown in Figure 6, including the following steps: Step S601: The code editor triggers a code document change or cursor movement event.
[0079] Step S602: The request interceptor obtains candidate code completion requests.
[0080] Specifically, the event listener layer in the request interceptor obtains the candidate code completion requests.
[0081] Step S603: The request interceptor performs code editor status detection. If the code editor status is normal, then step S604 is executed.
[0082] Specifically, the code editor status detection refers to detecting whether the code editor is the main editor. A normal code editor status means that the code editor is the main editor.
[0083] Step S604: The request interceptor performs prediction function switch detection. If the prediction function switch is turned on, then step S605 is executed.
[0084] Step S605: The request interceptor performs duplicate display filtering on the candidate code completion requests to determine non-duplicate code completion requests.
[0085] Step S606: The request interceptor performs a delay debouncing mechanism on the non-duplicate code completion requests to determine delayed code completion requests.
[0086] Step S607: The request interceptor performs a validity check on the delayed code completion request and determines the target code completion request. Specification 8 / 12 Page 11 CN 121680809 A
[0087] Step S608: The request interceptor sends the target code completion request to the large language model.
[0088] Steps S602 to S608 are processed by the pre-interception layer in the request interceptor.
[0089] Step S609: The large language model generates candidate code completion content based on the received target code completion request.
[0090] Step S610: The large language model sends the target code completion content to the code editor.
[0091] Step S611: The code editor segments the candidate code completion content to determine at least one difference content; Step S612: The code editor performs change amount control filtering on the at least one difference content to determine at least one candidate valid completion content; Step S613: The code editor performs similarity checks and empty change checks on the at least one candidate valid completion content to determine at least one valid completion content; Step S614: The code editor queries the rejection cache based on the at least one valid completion content. In response to the fact that no code completion content corresponding to the valid completion content is found in the rejection cache, the at least one valid completion content is determined as the target code completion content; Step S615: The code editor sends the target code completion content to the front-end interface display layer of the code editor.
[0092] Steps S611 to S61 are processed by the post-processing interception layer in the request interceptor.
[0093] Step S616: The front-end display interface of the code editor displays the target code completion content through intelligent display selection Inlay prompts, Popup panels, or Tab buttons.
[0094] Step S617: When the front-end display interface of the code editor receives a user acceptance and delayed display instruction, it saves the target code completion content to the completion result cache; or, upon receiving a user rejection instruction, it saves the target code completion content to the rejection cache.
[0095] In one possible implementation, step S605 uses the content of the rejection cache for duplicate display filtering.
[0096] Through the above embodiments, a multi-layered interception architecture, intelligent anti-shake algorithm, result segmentation based on difference analysis, multi-dimensional similarity detection, adaptive display strategy, and atomic resource management are adopted. Among them, the multi-layered interception architecture designs a dual filtering system of pre-interception and post-processing interception; the intelligent anti-shake algorithm combines a dynamic delay adjustment mechanism based on user behavior patterns; the result segmentation based on difference analysis is used for accurate code difference calculation and intelligent segmentation algorithm; the multi-dimensional similarity detection comprehensively considers the similarity judgment algorithm of content, position, and time; the adaptive display strategy selects intelligent display based on the complexity of the completed content and user preferences; and the atomic resource management is a complete resource management mechanism based on the life cycle. Through the above processing methods, invalid completion requests can be reduced, system response speed can be improved, and repeated display of completed content can be reduced.
[0097] In this embodiment of the invention, a device for intelligent code completion is provided, as shown in FIG7, specifically including: an acquisition unit 701, a pre-processing unit 702, a transmission unit 703, and a post-processing unit 704; wherein, the acquisition unit 701 is used to acquire candidate code completion requests, wherein the candidate code completion requests are triggered by code document changes or cursor movement events in the code editor; the pre-processing unit 702 is used to intercept the candidate code completion requests in advance and determine the target code completion request; the transmission unit 703 is used to send the target code completion request to a large language model and receive the candidate code completion content sent by the large language model; the post-processing unit 704 is used to intercept the candidate code completion content in post-processing and determine the target code completion content; the transmission unit 703 is also used to send the target code completion content to the code editor.
[0098] Further, the pre-processing unit is specifically configured to: determine the corresponding code editor based on the candidate code completion request; in response to the code editor meeting the preset code completion requirements, perform multi-level pre-processing interception on the candidate code completion request; in response to the candidate code completion request passing the multi-level pre-processing interception, determine the candidate...The selected code completion request is the target code completion request.
[0099] Further, the pre-set code completion requirements include: the code editor is the main editor and the prediction function of the code editor is enabled.
[0100] Further, the front-end unit is specifically used to: determine a non-duplicate code completion request in response to the candidate code completion request being filtered for repeated display; determine a delayed code completion request in response to the non-duplicate code completion request being filtered for delayed debouncing; and determine the target code completion request in response to the delayed code completion request being checked for legality.
[0101] Further, the front-end unit is specifically used to: query the rejection cache according to the candidate code completion request, wherein the rejection cache includes the code completion content rejected by the user, its corresponding cursor position, and display time; and determine the candidate code completion request as the non-duplicate code completion request in response to the rejection cache not finding the user-rejected code completion content corresponding to the candidate code completion request.
[0102] Further, the pre-processing unit is specifically used to: in response to the non-repeating code generation set time, if the code document has not been changed and no cursor movement event has been sent, determine the non-repeating code completion request as the delayed code completion request.
[0103] Further, the post-processing unit is specifically used to: segment the candidate code completion content to determine at least one difference content; filter the at least one difference content by change amount control to determine at least one candidate valid completion content; perform similarity check and empty change check on the at least one candidate valid completion content to determine at least one valid completion content; query the rejection cache according to the at least one valid completion content, and in response to the rejection cache not finding the code completion content corresponding to the valid completion content, determine the at least one valid completion content as the target code completion content.
[0104] Further, the device further includes: a storage unit, used to save the target code completion content to the completion result cache; or, save the target code completion content to the rejection cache.
[0105] Further, the device also includes a query unit, configured to query the completion result cache according to the target code completion request, and in response to the existence of code content corresponding to the target code completion request in the completion result cache, determine the code content corresponding to the target code completion request as the code completion content.
[0106] FIG8 is a schematic diagram of the structure of the electronic device in an embodiment of the present invention. As shown in FIG8, it includes a general computer hardware structure, which includes at least a processor 801 and a memory 802. The processor 801 and the memory 802 are connected through a bus 803. The memory 802 is adapted to store instructions or programs executable by the processor 801. The processor 801 may be an independent microprocessor.The processor 801 can be one or more microprocessors. Thus, the processor 801 executes instructions stored in the memory 802 to perform the method flow described above in this embodiment of the invention, thereby processing data and controlling other devices. The bus 803 connects the aforementioned components together, and also connects these components to the display controller 804, the display device, and the input / output (I / O) device 805. The input / output (I / O) device 805 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output device 805 is connected to the system via the input / output (I / O) controller 806.
[0107] The instructions stored in the memory 802 are executed by at least one processor 801 to achieve the following: obtaining a candidate code completion request; pre-intercepting the candidate code completion request to determine a target code completion request; sending the target code completion request to a large language model and receiving the candidate code completion content sent by the large language model; post-processing the candidate code completion content to determine the target code completion content; and sending the target code completion content to the code editor.
[0108] Specifically, the electronic device includes one or more processors 801 and a memory 802. Figure 8 uses one processor 801 as an example. The processor 801 and the memory 802 can be connected by a bus or other means. Figure 8 uses a bus connection as an example. The memory 802, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The processor 801 executes various functional applications and data processing of the device by running non-volatile software programs, instructions, and modules stored in the memory 802, thereby implementing the aforementioned method of intelligent code completion.
[0109] The memory 802 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; the data storage area may store option lists, etc. In addition, the memory 802 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 802 may optionally include memory remotely located relative to the processor 801, and these remote memories can be connected to external devices via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0110] One or more modules are stored in the memory 802 and, when executed by one or more processors 801, execute...The method of intelligent code completion in any of the above method embodiments.
[0111] As those skilled in the art will recognize, various aspects of the embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, various aspects of the embodiments of the present invention can take the form of a completely hardware implementation, a completely software implementation (including firmware, resident software, microcode, etc.), or an implementation that combines software and hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." Furthermore, various aspects of the embodiments of the present invention can take the form of a computer program product implemented in one or more computer-readable media having computer-readable program code implemented thereon.
[0112] Any combination of one or more computer-readable media can be used. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example (but not limited to), an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination thereof. More specific examples (not an exhaustive list) of computer-readable storage media will include the following: an electrical connection having one or more wires, a portable computer floppy disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable optical disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the context of embodiments of the invention, a computer-readable storage medium can be any tangible medium capable of containing or storing a program used by or in connection with an instruction execution system, device, or apparatus.
[0113] A computer-readable signal medium can include a propagated digital signal having computer-readable program code implemented therein, such as in baseband or as part of a carrier wave. Such a propagated signal can take any of a variety of forms, including but not limited to: electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium can be any of the following computer-readable media that is not a computer-readable storage medium and can communicate, propagate, or transmit a program used by or in connection with an instruction execution system, device, or apparatus. Specification page 11 / 12 14 CN 121680809 A
[0114] Program code implemented on a computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, fiber optic cable, RF, or any suitable combination thereof.
[0115] The computer program code for performing operations relating to various aspects of embodiments of the present invention can be in one or more forms.The program can be written using any combination of programming languages, including: object-oriented programming languages such as Java, Smalltalk, C++, etc.; and conventional procedural programming languages such as the "C" programming language or similar programming languages. The program code can be executed as a standalone software package entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer; or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any type of network including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., by using the Internet provided by an Internet service provider).
[0116] The flowchart illustrations and / or block diagrams of the methods, apparatus (systems) and computer program products according to embodiments of the present invention described above illustrate various aspects of the embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions (executed via the processor of the computer or other programmable data processing apparatus) create means for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0117] These computer program instructions can also be stored in a computer-readable medium that can direct a computer, other programmable data processing apparatus, or other apparatus to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing including instructions that implement the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0118] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other apparatus to cause a series of operative steps to be performed on the computer, other programmable apparatus, or other apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide a process for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0119] The above descriptions are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application shall be included within the scope of protection of this application.
[0120] It should be noted that 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, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data shall comply with relevant regulations.The system complies with relevant national and regional laws, regulations, and standards, and provides corresponding access points for users to choose to authorize or refuse processing of personal information beyond what is necessary for basic functions. A user's refusal to process personal information will not affect their use of basic functions. Specification page 12 / 12, 15 CN 121680809 A, Figure 1, Figure 2; Specification drawing page 1 / 6, 16 CN 121680809 A, Figure 3, Figure 4; Specification drawing page 2 / 6, 17 CN 121680809 A, Figure 5; Specification drawing page 3 / 6, 18 CN 121680809 A, Figure 6; Specification drawing page 4 / 6, 19 CN 121680809 A, Figure 7; Specification drawing page 5 / 6, 20 CN 121680809 A, Figure 8; Specification drawing page 6 / 6, 21 CN 121680809 A. Abstract: This invention discloses a method, apparatus, and device for intelligent code completion. In this embodiment, candidate code completion requests are acquired, triggered by code document changes or cursor movement events in a code editor; these requests are pre-intercepted to determine a target code completion request; the target request is sent to a large language model, and candidate code completion content is received from the large language model. the candidate code completion content is post-processed and intercepted to determine the target code completion content; and the target code completion content is sent to the code editor. Thismethod enables efficient and accurate code completion, reducing invalid requests through pre-interception and minimizing duplicate completion content display through post-processing interception, thus improving the user experience.
Claims
1. A method of code intelligence completion, characterized by, The method comprises: obtaining a candidate code completion request, wherein the candidate code completion request is triggered by a code document change or a cursor movement event in a code editor; pre-intercepting the candidate code completion request to determine a target code completion request; sending the target code completion request to a large language model and receiving candidate code completion content sent by the large language model; post-intercepting the candidate code completion content to determine target code completion content; sending the target code completion content to the code editor.
2. The method of claim 1, wherein, The pre-intercepting the candidate code completion request to determine a target code completion request specifically comprises: determining the corresponding code editor of the candidate code completion request; in response to the code editor meeting the pre-set code completion requirements, performing multi-level pre-interception on the candidate code completion request; in response to the candidate code completion request passing the multi-level pre-interception, determining that the candidate code completion request is the target code completion request.
3. The method of claim 2, wherein, The pre-set code completion requirements include that the code editor is a main editor and the prediction function of the code editor is turned on.
4. The method of claim 2, wherein, The response to the candidate code completion request passing the multi-level pre-interception to determine that the candidate code completion request is the target code completion request specifically comprises: in response to the candidate code completion request passing the repeated display filtering, determining a non-repeated code completion request; in response to the non-repeated code completion request passing the delay anti-shake mechanism, determining a delay code completion request; in response to the delay code completion request passing the legality check, determining the target code completion request.
5. The method of claim 4, wherein, The response to the candidate code completion request passing the repeated display filtering to determine a non-repeated code completion request specifically comprises: querying a rejection cache according to the candidate code completion request, wherein the rejection cache includes code completion content rejected by a user, the corresponding cursor position, and the display time; in response to not querying the code completion content rejected by the user corresponding to the candidate code completion request in the rejection cache, determining the candidate code completion request as the non-repeated code completion request.
6. The method of claim 4, wherein, The response to the non-repeated code completion request passing the delay anti-shake mechanism to determine a delay code completion request specifically comprises: in response to the code document not being changed and no cursor movement event being sent within the set time of the non-repeated code completion request, determining the non-repeated code completion request as the delay code completion request.
7. The method of claim 1, wherein, The post-intercepting the candidate code completion content to determine target code completion content specifically comprises: performing completion result segmentation on the candidate code completion content to determine at least one difference content; performing change amount control filtering on the at least one difference content to determine at least one candidate effective completion content; performing similarity check and null change check on the at least one candidate effective completion content to determine at least one effective completion content; According to the at least one valid completion content query rejection cache, in response to not querying the code completion content corresponding to the valid completion content in the rejection cache, the at least one valid completion content is determined as the target code completion content.
8. The method of claim 1, wherein, The method further comprises: saving the target code completion content to a completion result cache; or, saving the target code completion content to a rejection cache.
9. The method of claim 8, wherein, The method further comprises: querying the completion result cache according to the target code completion request, and in response to the code content corresponding to the target code completion request existing in the completion result cache, determining the code content corresponding to the target code completion request as the code completion content.
10. An apparatus for code intelligence completion, the apparatus comprising: The device comprises: an acquisition unit configured to acquire a candidate code completion request, wherein the candidate code completion request is triggered by a code document change or a cursor movement event in a code editor; a pre-processing unit configured to pre-process and intercept the candidate code completion request to determine a target code completion request; a transmission unit configured to send the target code completion request to a large language model and receive candidate code completion content sent by the large language model; a post-processing unit configured to post-process and intercept the candidate code completion content to determine target code completion content; the transmission unit is further configured to send the target code completion content to the code editor.
11. An electronic device comprising a memory and a processor, characterized in that The memory is configured to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, The computer program is stored in the computer readable storage medium, and the computer program is executed by the processor to implement the method according to any one of claims 1-9.