Code prompting method and system

By capturing the cursor position and code area in the code editing interface, identifying the code library and extracting reference code, the problem of slow code suggestion response speed is solved, and a more efficient code suggestion response is achieved.

CN122018873APending Publication Date: 2026-05-12ALIBABA CLOUD COMPUTING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ALIBABA CLOUD COMPUTING CO LTD
Filing Date
2024-11-11
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In existing technologies, code suggestion methods cannot provide timely suggestions when recall times out, resulting in reduced response speed.

Method used

The cursor position is captured in the code editing interface, the area code associated with the cursor position is selected, the code library associated with the target project is determined, and reference code is extracted from the code library based on the code loading parameters. The prompt code is pre-matched to improve the response speed.

Benefits of technology

By pre-extracting reference code, the response speed and accuracy of code suggestions are improved, the frequency of recall operations is reduced, and the efficiency of developers in writing code is increased.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122018873A_ABST
    Figure CN122018873A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code prompting method and system.The code prompting method comprises the steps that a cursor position is collected in a code editing interface of a target item, and an area code associated with the cursor position is selected in the code editing interface; determining at least two code libraries associated with the target project, and determining code loading parameters respectively corresponding to the at least two code libraries according to the region code; extracting reference codes from the at least two code libraries based on the code loading parameters and the area codes; and when it is detected that the cursor position triggers a code editing operation, searching for a prompt code matched with the code editing operation in the reference code and displaying the prompt code. Through a mode of extracting the reference code in advance, when a user edits the code, the prompt code can be directly matched in the extracted reference code, so that the response speed of code prompt is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments in this specification relate to the field of computer technology, and in particular to code completion methods and systems. Background Technology

[0002] In code development scenarios, developers typically rely on code suggestions and completion features during their daily coding process. The speed of code writing depends not only on the developer's typing speed but also on the responsiveness of code suggestions and completion.

[0003] In existing technologies, to simplify the development process and improve the real-time performance of code suggestions, a recall timeout is set. If the recall times out, subsequent code suggestion logic continues to execute. However, this approach suffers from the problem of not providing developers with suggested code in a timely manner. The recall timeout also significantly reduces the response speed of code suggestions. Therefore, a more effective code suggestion method is urgently needed to solve these problems. Summary of the Invention

[0004] In view of this, embodiments of this specification provide a code suggestion method. One or more embodiments of this specification also relate to a code suggestion system, a code suggestion device, a computing device, a computer-readable storage medium, and a computer program product, to address the technical deficiencies existing in the prior art.

[0005] According to a first aspect of the embodiments of this specification, a code suggestion method is provided, comprising: Collect the cursor position in the code editing interface of the target project, and select the region code associated with the cursor position in the code editing interface; Identify at least two code repositories associated with the target project, and determine the code loading parameters corresponding to the at least two code repositories based on the region code; Based on the code loading parameters and the region code, reference code is extracted from at least two code repositories; If a code editing operation is triggered at the cursor position, a prompt code matching the code editing operation is found in the reference code and displayed.

[0006] According to a second aspect of the embodiments of this specification, a code suggestion system is provided, including a server and a client; The client is used to generate a code suggestion request based on the code editing interface of the target project, and send the code suggestion request to the server. The server is configured to: respond to the code suggestion request by collecting the cursor position in the code editing interface and selecting the region code associated with the cursor position in the code editing interface; determine at least two code libraries associated with the target project and determine the code loading parameters corresponding to the at least two code libraries based on the region code; extract reference code from the at least two code libraries based on the code loading parameters and the region code; and, if the cursor position triggers a code editing operation, search for suggestion code matching the code editing operation in the reference code and send it to the client. The client is used to display the prompt code in the code editing interface.

[0007] According to a third aspect of the embodiments of this specification, a code completion device is provided, comprising: The acquisition module is configured to acquire the cursor position in the code editing interface of the target project, and select the region code associated with the cursor position in the code editing interface. The determination module is configured to determine at least two code repositories associated with the target project, and to determine the code loading parameters corresponding to the at least two code repositories based on the region code. The extraction module is configured to extract reference code from at least two codebases based on the code loading parameters and the region code. The search module is configured to, when a code editing operation is triggered at the cursor position, search for and display prompt code in the reference code that matches the code editing operation.

[0008] According to a fourth aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the above-described code hinting method.

[0009] According to a fifth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions that, when executed by a processor, implement the steps of the above-described code hinting method.

[0010] According to a sixth aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described code hinting method.

[0011] This specification provides a code suggestion method in one embodiment. During code editing, the cursor position is captured in the code editing interface of the target project, and a region code associated with the cursor position is selected within the code editing interface. At least two code repositories associated with the target project are identified, and code loading parameters corresponding to each of the at least two code repositories are determined based on the region code. Reference code is extracted from the at least two code repositories based on the code loading parameters and the region code, enabling the extraction of recommended reference code before the user actually begins editing. Extracting reference code from at least two code repositories also improves the accuracy of subsequent code suggestions. When a code editing operation is triggered by the cursor position, the suggestion code matching the code editing operation can be directly found in the reference code and displayed in the code editing interface. By pre-extracting reference code, when the user edits code, the suggestion code can be directly matched among the extracted reference code, thereby improving the response speed of code suggestions. Attached Figure Description

[0012] Figure 1 This is a schematic diagram illustrating the processing procedure of a code suggestion method provided in one embodiment of this specification; Figure 2 This is a flowchart illustrating a code suggestion method provided in one embodiment of this specification; Figure 3 This is a flowchart illustrating the processing procedure of a code suggestion method provided in one embodiment of this specification; Figure 4 This is a schematic diagram of the structure of a code suggestion system provided in one embodiment of this specification; Figure 5 This is a schematic diagram of the structure of a code prompting device provided in one embodiment of this specification; Figure 6 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation

[0013] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.

[0014] 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 be limiting of the one or more embodiments of this specification. The singular forms “a,” “described,” and “the” as used in one or more embodiments of this specification and 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 in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0015] It should be understood that although the terms first, second, 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 may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."

[0016] Furthermore, 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 one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties. Moreover, 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 entry points are provided for users to choose to authorize or refuse.

[0017] First, the terms and concepts used in one or more embodiments of this specification will be explained.

[0018] debounce: Completes debouncing to prevent multiple requests from occurring simultaneously.

[0019] Program Dependence Graph (PDG): A graphical representation of a program. It is a labeled directed multigraph used to represent the control and data dependencies of a program. A PDG is a graph model of source code that shows the dependencies between statements (or nodes) in the program, including control and data dependencies.

[0020] Abstract Syntax Tree (AST): A tree-like data structure used in computer science to represent the structure of program source code. An AST is an intermediate representation generated after lexical and syntactic analysis of the source code. It represents the syntactic structure of the program in a tree-like form, where each node represents a syntactic element in the source code, such as an expression, statement, or function.

[0021] Figure 1 This is a schematic diagram illustrating the processing procedure of a code suggestion method provided in one embodiment of this specification. For example... Figure 1 As shown, during the user's code editing process, the cursor position is captured in the code editing interface of the target project, and the region code associated with the cursor position is selected in the code editing interface. At least two code repositories associated with the target project are identified; these repositories can be local project repositories or enterprise repositories. The code repositories can be stored locally, on a remote server, or on a cloud server. Code loading parameters corresponding to the at least two code repositories are determined based on the region code. Reference code is extracted from the at least two code repositories based on the code loading parameters and the region code, enabling the extraction of recommended reference code to the user before they actually begin editing. Extracting reference code from at least two code repositories also improves the accuracy of subsequent code suggestions.

[0022] When a code editing action is detected at the cursor position, it indicates that the user has initiated code editing and intends to continue editing based on that position. At this point, a matching suggestion code can be directly found in the reference code and displayed in the code editing interface. The suggestion code can be displayed at the cursor position for the user to select, or it can be added directly to the current cursor position in the code editing interface. By pre-extracting reference code, suggestion codes can be directly matched against the extracted reference code when the user edits, thus improving the response speed of code suggestions.

[0023] This specification provides a code suggestion method, and also relates to a code suggestion system, a code suggestion device, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0024] See Figure 2 , Figure 2 A flowchart of a code suggestion method according to an embodiment of this specification is shown, which specifically includes the following steps.

[0025] Step 202: Collect the cursor position in the code editing interface of the target project, and select the region code associated with the cursor position in the code editing interface.

[0026] Specifically, the target project can be an application development project or an engineering project in the software development process. The code editing interface is the interface for editing code during application development, and it can also be the editing interface corresponding to any file in an engineering project. The cursor position is the location of the cursor in the code editing interface, controlled by the mouse or touch screen. The region code refers to the context code of the cursor position.

[0027] Based on this, during the development of the target project, the code editing interface is determined, and the current cursor position is captured as the cursor location. A region code associated with the cursor position is selected within the code editing interface, which is used to determine the tooltip code later.

[0028] Furthermore, after determining the cursor position, to improve the accuracy of subsequent code suggestions, the cursor region can be determined based on the cursor position. Code recall can then be performed based on the region codes within the cursor region. By setting a preset cursor time, frequent code recall can be avoided. The specific implementation is as follows: Based on a preset cursor time, the cursor region associated with the cursor position is determined in the code editing interface; the region code is extracted from the cursor region.

[0029] Specifically, the preset cursor time refers to the delay after a change in cursor position is detected. That is, after a change in cursor position is detected, the preset cursor time is delayed before subsequent code recall operations are performed. The cursor region refers to the code editing area occupied by the context of the cursor position. The cursor region can be obtained by detecting the context of the cursor position.

[0030] Based on this, upon detecting an update of the initial cursor position, wait for a preset cursor time. In the code editing interface, determine the context above and / or below the cursor position, and use the area containing this context as the cursor region associated with the cursor position. Extract the code from the cursor region as the region code.

[0031] For example, during software development, when a user is editing code, the cursor position in the code editing interface can be detected. When a change in the cursor position is detected, after a preset cursor time (1 second), the cursor area where the cursor is located is determined based on the cursor position, and the code in the cursor area is extracted as the region code, so that code retrieval can be performed later based on the region code.

[0032] In summary, by determining the cursor region associated with the cursor position in the code editing interface based on the preset cursor time and extracting the region code from the cursor region, the existence of the preset cursor time can avoid frequent code recall operations, which would affect performance.

[0033] Step 204: Determine at least two code repositories associated with the target project, and determine the code loading parameters corresponding to the at least two code repositories based on the region code.

[0034] Specifically, after capturing the cursor position in the target project's code editing interface and selecting the associated region code within the interface, at least two code repositories associated with the target project can be identified. Based on the region code, the code loading parameters for each of these at least two code repositories are determined. These at least two code repositories can include code repositories from various sources, such as the target project's project repository or an enterprise repository. The code repositories can be stored locally, on a remote server, or on a cloud server. The code loading parameters represent the number of code retrievals and the code retrieval time for each of the at least two code repositories.

[0035] Based on this, after capturing the cursor position in the code editing interface of the target project and selecting the region code associated with the cursor position in the code editing interface, at least two code repositories associated with the target project are identified. A code retrieval timeout is set, and within this timeout, the code loading parameters corresponding to the at least two code repositories are determined based on the region code. It is ensured that the total time spent retrieving code from at least two code repositories is less than or equal to the code retrieval timeout.

[0036] Furthermore, since the target project corresponds to at least two code repositories, the code loading parameters need to be determined in two dimensions: the number of code retrievals and the code retrieval time. The specific implementation is as follows: Determine the number of codes in the region code and the parameter lookup tables corresponding to the at least two code libraries respectively; based on the number of codes, query the parameter lookup tables corresponding to the at least two code libraries respectively to obtain the code loading parameters corresponding to the at least two code libraries respectively.

[0037] Specifically, the code count refers to the number of tokens obtained by segmenting the regional code. Each code repository corresponds to a parameter lookup table used to record the historical code recall information of the code repository. The historical code recall information includes the code count of the regional code, the number of code recalls in the code repository, the recall response time, and the code recall time. The code recall time can be the average time of code recall.

[0038] Based on this, the region code is segmented into at least two code blocks, and the number of code blocks is taken as the code count of the region code. Parameter lookup tables corresponding to at least two code libraries are determined. Based on the code count, the parameter lookup tables corresponding to at least two code libraries are consulted to obtain the code loading parameters for each of the at least two code libraries.

[0039] Following the previous example, after extracting the region code near the cursor position, the region code is segmented. The number of segments, 10, is taken as the code quantity of the region code. Based on the code quantity of 10, the parameter lookup table corresponding to each code library is queried to obtain the code loading parameters corresponding to each code library. The number of codes to be recalled for each code library and the code recall time required are then determined.

[0040] In summary, by querying parameter lookup tables for at least two codebases based on the number of code snippets, the code loading parameters for each codebase can be obtained. This approach determines the code loading parameters for each codebase based on historical information from the parameter lookup tables, balancing the number of code retrievals for each codebase. By determining the code loading parameters based on both the number of code retrievals and the code retrieval time, the accuracy of the code loading parameters is improved.

[0041] Furthermore, since the storage locations of each codebase in at least two codebases are different, the time spent recalling code in each codebase also varies. The appropriate number of target codes to recall can be determined by querying a parameter lookup table, as implemented below: Match the code recall quantity corresponding to the code quantity in the target parameter lookup table corresponding to the target code library, and determine the code loading time in the target parameter lookup table based on the code recall quantity; if the code loading time is less than the time threshold, update the code recall quantity to the target code recall quantity, and use the target code recall quantity as the code loading parameter.

[0042] Specifically, the target code repository is any one of at least two code repositories. Correspondingly, the target parameter lookup table is the parameter lookup table for the target code repository, recording historical recall information for the target database. Historical recall information includes, but is not limited to, the number of historical code instances, the number of code instances recalled, and the code loading time corresponding to the number of recalled code instances. Each parameter in the target parameter lookup table can be divided into multiple parameter ranges according to parameter regions. The time threshold can be a code loading time threshold set according to actual needs. The time threshold can be 50% of the maximum time set for the code recall process. The target code recall quantity can be the larger code recall quantity in the target parameter lookup table whose code loading time is less than the time threshold.

[0043] Based on this, the code recall quantity corresponding to the code quantity is determined in the target parameter lookup table corresponding to the target code library. The code loading time is then determined in the target parameter lookup table based on the code recall quantity. If the code loading time is less than a time threshold, it indicates that the current code recall quantity is insufficient, and the quantity can be appropriately increased. The code loading times less than the time threshold are determined in the target parameter lookup table, and the code recall quantity with the larger code loading time less than the time threshold is taken as the target code recall quantity. The target code recall quantity is then used as the code loading parameter.

[0044] In summary, if the code loading time is less than the time threshold, the code recall count is updated to the target code recall count, thereby recalling more code within the allowable range of code loading time.

[0045] Furthermore, the target parameter lookup table records the historical recall information of the target code repository. Due to the large amount of historical recall information, it is stored in intervals for easier querying, allowing subsequent queries to be performed based on code count intervals. The specific implementation is as follows: Match the code quantity range corresponding to the code quantity in the target parameter lookup table corresponding to the target code library; select the code loading time in the code quantity range based on the preset code loading time, and obtain the code recall quantity corresponding to the code loading time.

[0046] Specifically, the code parameter range refers to the parameter range in the target parameter lookup table divided according to the number of codes. The parameters in the target parameter lookup table can be divided into ranges with equal number of codes based on the range parameter threshold.

[0047] Based on this, the code quantity range corresponding to the code quantity is matched in the target parameter lookup table corresponding to the target code library. The target parameter lookup table is then queried based on the code quantity to determine the target parameter range corresponding to the code quantity, and this target parameter range is used as the code quantity range. Based on a preset code loading time, code loading times shorter than the preset code loading time are selected from the code quantity range, and the code recall quantity corresponding to that loading time is obtained.

[0048] Continuing with the previous example, with the target codebase as A and the target parameter lookup table as a, table a is divided into multiple parameter intervals based on the number of code entries. Each parameter interval records multiple code entries, the code recall count corresponding to each code entry, and the code loading time corresponding to each code recall count. We can query the target parameter lookup table based on the code entry count of 10 to obtain the code recall count of 5. We then check the code loading time of 12 milliseconds corresponding to the code recall count of 5. If the code loading time of 12 milliseconds is less than the time threshold of 20 milliseconds, we determine the candidate code loading times within this parameter interval that are less than the time threshold of 20 milliseconds. We select the code recall count of 7, which is larger among the candidate code loading times, and use the code recall count of 7 as the code loading parameter.

[0049] In summary, based on a preset code loading time, the system selects the code loading time within a range of code counts and retrieves the code recall count corresponding to that time. The code count is then used to locate the code count range in the target parameter lookup table, thereby improving query efficiency.

[0050] Step 206: Extract reference code from the at least two codebases based on the code loading parameters and the region code.

[0051] Specifically, after identifying at least two code repositories associated with the target project and determining the code loading parameters for each repository based on the region code, reference code can be extracted from these repositories based on the code loading parameters and the region code. Reference code refers to code with a high degree of similarity to the region code. Reference code can be displayed in the code editing interface for user selection. The reference code consists of initial reference code extracted from each repository; that is, the reference code is multiple source codes.

[0052] Based on this, after determining the code loading parameters corresponding to the at least two code repositories associated with the target project and determining the code loading parameters corresponding to the at least two code repositories according to the region code, the initial reference code is extracted from each of the at least two code repositories based on the code loading parameters and the region code, and the reference code is composed of the initial reference code corresponding to the at least two code repositories.

[0053] Furthermore, when extracting target reference code, this can be achieved through code similarity calculation, as detailed below: Determine the code loading parameters corresponding to the target code library; based on the code loading parameters, extract the target reference code that matches the code of the region in the target code library through code similarity calculation.

[0054] Specifically, code similarity calculation can be implemented through corresponding algorithms, including but not limited to text comparison algorithms, comparison algorithms based on abstract syntax trees, and comparison algorithms based on program dependency graphs.

[0055] Based on this, the code loading parameters corresponding to the target code library are determined. Based on the code loading parameters, the target reference code with high similarity to the regional code is calculated in the target code library by code similarity calculation. Then, the target reference code matching the regional code is extracted.

[0056] In summary, by using code loading parameters to extract target reference codes that match regional codes from the target code library through code similarity calculation, the usability of the target reference codes is improved.

[0057] Furthermore, after extracting the code to be referenced, the code retrieval is complete. This code retrieval can be recorded, and the relevant parameters can be recorded in a parameter lookup table. The specific implementation is as follows: Determine the code extraction time and the corresponding number of code extractions; add the number of code extractions, the number of code extractions, and the code extraction time to the parameter lookup table.

[0058] Specifically, code extraction time refers to the response time of this code recall, and code extraction quantity refers to the number of codes recalled in this code recall operation.

[0059] Based on this, the code extraction time and the corresponding number of code extractions are determined. The number of code extractions, the number of code extractions, and the code extraction time are then added to the parameter lookup table according to the intervals specified in the parameter lookup table.

[0060] Following the previous example, after determining the code count to be 10, the code extraction count to be 7, and the code extraction time to be 18 milliseconds, the parameters are stored. If the parameter lookup table has not yet been initialized with parameter ranges, the parameters are divided into equal ranges based on a specified range division threshold s.

[0061] Determine if the code quantity 10 belongs to one of the already divided intervals; if the code quantity 10 belongs to one of the already divided intervals, then determine if the size of the interval exceeds s. If it does, then redivide the interval equally according to s; traverse the parameter interval to which the code quantity 10 belongs. If the parameter interval contains the code quantity 10, then recalculate the code retrieval time corresponding to the code quantity 10 and store the code retrieval time; if the parameter interval does not contain the code quantity 10, then store the code quantity 10 and the code retrieval time in the parameter lookup table.

[0062] If the code count of 10 does not belong to any interval, then the interval needs to be re-divided equally between the maximum value of the interval and the current value of 10. After the division, the parameter interval to which the code count of 10 belongs is traversed. If the parameter interval contains the code count of 10, the code retrieval time corresponding to the code count of 10 is recalculated and stored. If the parameter interval does not contain the code count of 10, the code count of 10 and the code retrieval time are stored in the parameter lookup table.

[0063] In summary, the number of codes retrieved, the number of codes extracted, and the time taken for code extraction are added to the parameter lookup table to record the code retrieval results for use in subsequent code retrieval tasks.

[0064] Step 208: If a code editing operation is triggered at the cursor position, find and display the prompt code that matches the code editing operation in the reference code.

[0065] Specifically, after extracting reference code from at least two code repositories based on code loading parameters and region codes, when a code editing operation is detected at the cursor position, a matching suggestion code is searched for and displayed in the reference code. This code editing operation can be the user entering code or characters at the cursor position, or the user deleting or modifying code or characters at the cursor position. The code editing operation will trigger a change in the code at the cursor position. The suggestion code is displayed in the code editing interface for the user to select. The suggestion code has a high degree of matching with the region code corresponding to the cursor position and the change code corresponding to the code editing operation.

[0066] Based on this, after extracting reference code from at least two code repositories using code loading parameters and region codes, if a code editing operation is triggered at the cursor position, it indicates that the user has performed a code change operation at the cursor position. This code change operation can be editing (adding code), deleting code, or modifying code. The system then searches for a matching suggestion code in the reference code and displays it in the code editing interface. This suggestion code can be displayed at the cursor position within the code editing interface.

[0067] In practical applications, after the suggestion code is determined, it can be displayed as a pop-up at the cursor position in the code editing interface, or it can be added directly to the cursor position without user selection. Furthermore, code recall and suggestion times can be set for code editing operations. If a code editing operation is detected and no cached reference code exists, the code recall operation begins after a delay corresponding to the code recall time. If the code recall time is shorter than the suggestion time, the suggestion operation begins after a delay corresponding to the suggestion time, selecting the suggestion code from the already recalled reference code.

[0068] Furthermore, since code recall takes time when a cursor position change triggers the code recall operation, a code recall status can be set, and the suggested code can be found based on the recall status. The specific implementation is as follows: If the cursor position triggers the code editing operation and the code editing operation meets the prompt time condition, the recall status of the reference code is read; based on the recall status, the prompt code that matches the code editing operation is found in the reference code and displayed.

[0069] Specifically, the prompt time condition is used to determine whether the prompt code is searched based on a code editing operation. If the code editing operation meets the prompt time condition, it means that after receiving the code editing operation, there was a delay of code completion time (10 milliseconds, 1 second, or any other time), at which point the subsequent prompt code search operation can be executed. The recall status indicates whether the reference code has been recalled. A recall status of "Start" indicates that the recall of reference code has begun and has not ended; a recall status of "End" indicates that the recall of reference code has been completed.

[0070] Based on this, when a code editing operation is detected at the cursor position, and the operation meets the suggestion timing conditions, it indicates that code editing has begun at the cursor position and the time for code suggestions has been reached. At this point, the suggestion code needs to be searched for in the reference code. The recall status of the reference code is read to determine if the recall is complete. If complete, the suggestion code matching the code editing operation can be found in the reference code and displayed. If not complete, the suggestion code is extracted from the reference code after the recall is complete. It should be noted that a timeout period needs to be set while waiting for the reference code to be recalled. If the reference code is not recalled within the timeout period, the waiting will stop.

[0071] Using the previous example, when a user is detected editing code at the cursor position, the recall status of the reference code is determined. If the reference code has been recalled, and the user inputs "a", the prompt code "abc" is extracted from the reference code after a 10-millisecond delay based on the user's input "a". If the reference code has not been recalled, the system waits for the recall status until the recall status is "end". During the waiting process, a timeout period must be followed, and if the timeout period is exceeded, the system will stop waiting.

[0072] In summary, when a code editing operation is triggered at the cursor position and the code editing operation meets the prompt time condition, the prompt code matching the code editing operation is searched in the reference code based on the recall state, avoiding frequent triggering of searching for prompt code in the reference code.

[0073] This specification provides a code suggestion method in one embodiment. During code editing, the cursor position is captured in the code editing interface of the target project, and a region code associated with the cursor position is selected within the code editing interface. At least two code repositories associated with the target project are identified, and code loading parameters corresponding to each of the at least two code repositories are determined based on the region code. Reference code is extracted from the at least two code repositories based on the code loading parameters and the region code, enabling the extraction of recommended reference code before the user actually begins editing. Extracting reference code from at least two code repositories also improves the accuracy of subsequent code suggestions. When a code editing operation is triggered by the cursor position, the suggestion code matching the code editing operation can be directly found in the reference code and displayed in the code editing interface. By pre-extracting reference code, when the user edits code, the suggestion code can be directly matched among the extracted reference code, thereby improving the response speed of code suggestions.

[0074] The following is in conjunction with the appendix Figure 3 Taking the code suggestion method provided in this manual as an example in code writing, the code suggestion method will be further explained. Among other things, Figure 3 The flowchart of a code suggestion method provided in one embodiment of this specification is shown, which specifically includes the following steps.

[0075] Step 302: Determine the cursor position in the code editing interface.

[0076] During code writing, the system can provide code suggestions based on user actions in the code editing interface. While the user is editing code, changes in the cursor position can be detected in real time, thus providing code writing suggestions.

[0077] Step 304: Collect the region code associated with the cursor position based on the code recall delay time.

[0078] The code recall delay time is denoted as debounceC. When a cursor position change is detected, code recall is performed based on this delay time. For example, if a cursor position change is detected, the code recall operation is triggered after one second to avoid frequent triggering. When code recall is triggered, the region code of the cursor position area is collected as the basis for subsequent code recall. The region code can be the context code near the cursor position.

[0079] Step 306: Query the code recall parameter tables of at least two code repositories based on the number of code segments for each region code.

[0080] Step 308: Determine the number of code retrievals and the code retrieval time for at least two code repositories based on the query results.

[0081] The regional code is segmented into words to determine the number of segmented words, T. Local or remote code repositories, such as project code repositories or enterprise code repositories, can be used as the targets for the recall operation. For each code repository, the code recall quantity and the average time taken to recall the code R are dynamically determined through `recallinterval` (historical recall parameter record table). Specifically, when determining the code recall quantity R, the parameter range corresponding to the code repository can be traversed based on the code segmentation quantity T and the maximum time taken (maxCost). If T is within the parameter range, the average time taken for the recall quantity within that range is traversed. Based on the traversal results, the largest recall value with a time taken less than maxCost is determined and used as the code recall quantity R. The code recall time corresponding to the code recall quantity R is recorded, i.e., the average time taken (avgCost). Furthermore, if the dynamically calculated code recall quantity is not determined, a default value of 1 can be used. If the code recall time (avgCost) is less than a preset threshold, the code recall quantity is R+1.

[0082] Step 310: Extract reference code from at least two codebases based on the number of code recalls and the region code.

[0083] At the start of code retrieval, the code retrieval status is recorded as "Start" until a reference code is obtained, at which point the code retrieval status is updated to "End". Based on the region code and the number of codes retrieved for each code repository, code extraction is performed in at least two code repositories. Reference code is then extracted from at least two code repositories using similarity matching. The time C for extracting reference code from each code repository is recorded.

[0084] In practical applications, after determining the execution time C of the reference code, the number of code segments T, and the number of code recalls R, C, T, and R can be recorded in `recallinterval`. If the parameter interval corresponding to `recallinterval` is not initialized, then T is divided into equal parameter intervals according to the threshold S. If it has been initialized, it is determined whether T belongs to a parameter interval in `recallinterval`. If not, the parameter interval is divided equally between the maximum value of the parameter interval and T. The historical recall count of this parameter interval is traversed. If R exists in the parameter interval, the average execution time (avgCost) of R is recalculated. If R does not exist in the parameter interval, R and C are recorded in this parameter interval. If it does exist, and the size of this parameter interval exceeds the threshold S, the parameter interval is redivided equally according to the threshold S. After the division, the historical recall count of this parameter interval is traversed. If R exists in the parameter interval, the average execution time (avgCost) of R is recalculated. If R does not exist in the parameter interval, R and C are recorded in this parameter interval.

[0085] Step 312: When a code editing operation is triggered at the detected cursor position, select the suggestion code from the reference code based on the code completion delay time.

[0086] Set a code completion delay time `debounceB` for code editing operations. Upon detecting a code editing operation, retrieve context-related data such as code references, similar code, and code truncation based on `debounceB` and the cursor position, and then search the reference code for suggestions to provide to the user. A recall delay time `debounceA` can also be set for code editing operations; that is, when a code editing operation is detected, code recall logic is executed based on the recall delay time `debounceA`. It should be noted that the recall delay time `debounceA` must be less than or equal to the code completion delay time `debounceB`. Based on the debounce time difference, similar code is recalled before triggering code completion.

[0087] The code recall delay time, debounceA, can be dynamically calculated based on the code completion delay time, debounceB. The code recall delay time, debounceA, is dynamically calculated by multiplying the trigger time of the code completion delay time, debounceB, by a coefficient X. Simultaneously, a lower limit value M is set to ensure infrequent recalls. For example, if the code completion delay time is t, then the code recall delay time is max(t*X, M).

[0088] In practical applications, the suggestion code can be determined based on the recall status. Reference code is stored in a cache. When code completion is triggered, the cache is searched. If the cache is not found, the code recall logic is executed. If the cache near the cursor is hit, and the recall status is "Ended," the suggestion code can be directly selected from the reference code. If the recall status is "Started," the system waits for the recall status to change to "Ended," at which point the suggestion code is directly selected from the reference code. This waiting process is subject to a timeout.

[0089] Step 314: Update the code editing interface based on the suggested code.

[0090] The code suggestion can be displayed in the code editing interface to complete the code suggestion.

[0091] In summary, recalling similar code snippets before the user triggers code completion reduces response time for completion requests. Even if the recall logic is time-consuming, it won't significantly impact the user experience. By setting different debounce times, similar code can be recalled before the user starts writing code, ensuring the relevant data is ready when the user actually triggers code completion. Dynamically calculating the debounce time avoids excessive recall, which could impact performance. The recall logic is triggered when the cursor moves and remains stationary for an extended period. This avoids frequent triggering of recalls when the user frequently moves the cursor, reducing unnecessary calculations and network requests. Setting a longer debounce time (typically greater than 1 second) ensures that the recall logic is triggered only when the user is actually ready to start writing code, thus improving the accuracy and efficiency of the recall.

[0092] Corresponding to the above method embodiments, this specification also provides embodiments of a code suggestion system. Figure 4 A schematic diagram of the structure of a code suggestion system provided in one embodiment of this specification is shown. Figure 4 As shown, the code suggestion system 400 includes a server 410 and a client 420. The client 420 is used to generate a code suggestion request based on the code editing interface of the target project and send the code suggestion request to the server 410. The server 410 is used to collect the cursor position in the code editing interface in response to the code suggestion request, and select the region code associated with the cursor position in the code editing interface; determine at least two code libraries associated with the target project, and determine the code loading parameters corresponding to the at least two code libraries respectively according to the region code; extract reference code in the at least two code libraries based on the code loading parameters and the region code; when the cursor position triggers a code editing operation, find the suggestion code that matches the code editing operation in the reference code and send it to the client 420; the client 420 is used to display the suggestion code in the code editing interface.

[0093] In practical applications, during code editing, users can generate code suggestion requests based on the target project's code editing interface. The server collects the cursor position in the code editing interface and selects the region code associated with that position. It identifies at least two code repositories associated with the target project and determines the corresponding code loading parameters for each repository based on the region code. Reference code is extracted from these two repositories based on the loading parameters and the region code, allowing for the extraction of recommended reference code before the user actually begins editing. Extracting reference code from at least two repositories also improves the accuracy of subsequent code suggestions. When a code editing operation is triggered by the cursor position, a matching suggestion code is directly found in the reference code and sent to the client for display in the code editing interface. Users can then select the code they need to edit from the suggestion code. By pre-extracting reference code, the server can directly match suggestion code with the extracted reference code when the user edits, thus improving the response speed of code suggestions.

[0094] The above is an illustrative scheme of a code suggestion system according to this embodiment. It should be noted that the technical solution of this code suggestion system and the technical solution of the code suggestion method described above belong to the same concept. For details not described in detail in the technical solution of the code suggestion system, please refer to the description of the technical solution of the code suggestion method described above.

[0095] Corresponding to the above method embodiments, this specification also provides embodiments of a code hinting device. Figure 5 A schematic diagram of a code prompting device according to one embodiment of this specification is shown. Figure 5 As shown, the device includes: The acquisition module 502 is configured to acquire the cursor position in the code editing interface of the target project, and select the region code associated with the cursor position in the code editing interface. The determination module 504 is configured to determine at least two code libraries associated with the target project, and determine the code loading parameters corresponding to the at least two code libraries respectively based on the region code; Extraction module 506 is configured to extract reference code from at least two codebases based on the code loading parameters and the region code; The search module 508 is configured to search for and display prompt code that matches the code editing operation in the reference code when the cursor position is detected as triggering a code editing operation.

[0096] In an optional embodiment, the acquisition module 502 is further configured to: The cursor region associated with the cursor position is determined in the code editing interface based on a preset cursor time. Extract the region code from the cursor area.

[0097] In an optional embodiment, the determining module 504 is further configured to: Determine the number of codes in the region code, and the parameter lookup tables corresponding to the at least two code libraries respectively; Based on the number of codes, query the parameter lookup tables corresponding to the at least two code libraries respectively to obtain the code loading parameters corresponding to the at least two code libraries respectively.

[0098] In an optional embodiment, the determining module 504 is further configured to: Match the code recall quantity corresponding to the code quantity in the target parameter lookup table corresponding to the target code library, and determine the code loading time in the target parameter lookup table based on the code recall quantity; If the code loading time is less than the time threshold, the code recall quantity is updated to the target code recall quantity, and the target code recall quantity is used as the code loading parameter.

[0099] In an optional embodiment, the determining module 504 is further configured to: Match the code quantity range corresponding to the code quantity in the target parameter lookup table corresponding to the target code library; Based on a preset code loading time, select a code loading time within the code quantity range, and obtain the code recall quantity corresponding to the code loading time.

[0100] In an optional embodiment, the extraction module 506 is further configured to: Determine the code loading parameters corresponding to the target code library; Based on the code loading parameters, the target reference code that matches the code of the region is extracted from the target code library through code similarity calculation.

[0101] In an optional embodiment, the extraction module 506 is further configured to: Determine the time taken for code extraction, and the number of codes extracted corresponding to the time taken for code extraction; Add the number of codes, the number of codes extracted, and the time taken for code extraction to the parameter lookup table.

[0102] In an optional embodiment, the lookup module 508 is further configured to: If the code editing operation is triggered at the cursor position and the code editing operation meets the prompt time condition, the recall status of the reference code is read. Based on the recall status, the system searches for and displays a prompt code in the reference code that matches the code editing operation.

[0103] This specification provides a code suggestion device in one embodiment. During code editing, the cursor position is captured in the code editing interface of the target project, and a region code associated with the cursor position is selected within the code editing interface. At least two code libraries associated with the target project are identified, and code loading parameters corresponding to each of the at least two code libraries are determined based on the region code. Reference code is extracted from the at least two code libraries based on the code loading parameters and the region code, enabling the extraction of recommended reference code before the user actually begins editing. Extracting reference code from at least two code libraries also improves the accuracy of subsequent code suggestions. When a code editing operation is triggered by the cursor position, the suggestion code matching the code editing operation can be directly found in the reference code and displayed in the code editing interface. By pre-extracting reference code, when the user edits code, the suggestion code can be directly matched among the extracted reference code, thereby improving the response speed of code suggestions.

[0104] The above is an illustrative scheme of a code suggestion device according to this embodiment. It should be noted that the technical solution of this code suggestion device and the technical solution of the code suggestion method described above belong to the same concept. For details not described in detail in the technical solution of the code suggestion device, please refer to the description of the technical solution of the code suggestion method described above.

[0105] Figure 6 A structural block diagram of a computing device 600 according to one embodiment of this specification is shown. The components of the computing device 600 include, but are not limited to, a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and a database 650 is used to store data.

[0106] The computing device 600 also includes an access device 640, which enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or combinations of communication networks such as the Internet. The access device 640 may include one or more of any type of wired or wireless network interface (e.g., a network interface card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) wireless interface, a Wi-MAX (Worldwide Interoperability for Microwave Access) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, or a Near Field Communication (NFC) interface.

[0107] In one embodiment of this specification, the above-described components of the computing device 600 and Figure 6 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 6 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0108] The computing device 600 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 600 can also be a mobile or stationary server.

[0109] The processor 620 is configured to execute the following computer-executable instructions, which, when executed by the processor, implement the steps of the above-described code hinting method.

[0110] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the code hinting method described above belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the code hinting method described above.

[0111] An embodiment of this specification also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the above-described code hinting method.

[0112] The above is an illustrative embodiment of a computer-readable storage medium. It should be noted that the technical solution of this storage medium and the technical solution of the code completion method described above belong to the same concept. Details not described in detail in the technical solution of the storage medium can be found in the description of the technical solution of the code completion method described above.

[0113] An embodiment of this specification also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described code hinting method.

[0114] The above is an illustrative scheme of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product and the technical solution of the above-described code hinting method belong to the same concept. For details not described in detail in the technical solution of the computer program product, please refer to the description of the technical solution of the above-described code hinting method.

[0115] 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.

[0116] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or certain intermediate forms. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added or removed according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0117] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.

[0118] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0119] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.

Claims

1. A code completion method, comprising: Collect the cursor position in the code editing interface of the target project, and select the region code associated with the cursor position in the code editing interface; Identify at least two code repositories associated with the target project, and determine the code loading parameters corresponding to the at least two code repositories based on the region code; Based on the code loading parameters and the region code, reference code is extracted from at least two code repositories; If a code editing operation is triggered at the cursor position, a prompt code matching the code editing operation is found in the reference code and displayed.

2. The code suggestion method according to claim 1, wherein selecting the region code associated with the cursor position in the code editing interface includes: The cursor region associated with the cursor position is determined in the code editing interface based on a preset cursor time. Extract the region code from the cursor area.

3. The code completion method according to claim 1, wherein determining the code loading parameters corresponding to the at least two code libraries based on the region code includes: Determine the number of codes in the region code, and the parameter lookup tables corresponding to the at least two code libraries respectively; Based on the number of codes, query the parameter lookup tables corresponding to the at least two code libraries respectively to obtain the code loading parameters corresponding to the at least two code libraries respectively.

4. The code completion method according to claim 3, wherein determining the code loading parameters corresponding to the target code library in the at least two code libraries includes: Match the code recall quantity corresponding to the code quantity in the target parameter lookup table corresponding to the target code library, and determine the code loading time in the target parameter lookup table based on the code recall quantity; If the code loading time is less than the time threshold, the code recall quantity is updated to the target code recall quantity, and the target code recall quantity is used as the code loading parameter.

5. The code suggestion method according to claim 4, wherein matching the code recall quantity corresponding to the code quantity in the target parameter lookup table corresponding to the target code library includes: Match the code quantity range corresponding to the code quantity in the target parameter lookup table corresponding to the target code library; Based on a preset code loading time, select a code loading time within the code quantity range, and obtain the code recall quantity corresponding to the code loading time.

6. The code suggestion method according to claim 1, wherein the extraction of the target reference code corresponding to any one of the at least two code repositories includes: Determine the code loading parameters corresponding to the target code library; Based on the code loading parameters, the target reference code that matches the code of the region is extracted from the target code library through code similarity calculation.

7. The code completion method according to claim 3, further comprising, after extracting reference code based on the code loading parameters and the region code from the at least two code repositories: Determine the time taken for code extraction, and the number of codes extracted corresponding to the time taken for code extraction; Add the number of codes, the number of codes extracted, and the time taken for code extraction to the parameter lookup table.

8. The code suggestion method according to claim 1, wherein when a code editing operation is triggered at the cursor position, finding and displaying suggestion code matching the code editing operation in the reference code includes: If the code editing operation is triggered at the cursor position and the code editing operation meets the prompt time condition, the recall status of the reference code is read. Based on the recall status, the system searches for and displays a prompt code in the reference code that matches the code editing operation.

9. A code suggestion system, comprising a server and a client; The client is used to generate a code suggestion request based on the code editing interface of the target project, and send the code suggestion request to the server. The server is configured to respond to the code suggestion request by collecting the cursor position in the code editing interface and selecting the region code associated with the cursor position in the code editing interface; Identify at least two code repositories associated with the target project, and determine the code loading parameters corresponding to the at least two code repositories based on the region code; extract reference code from the at least two code repositories based on the code loading parameters and the region code; If a code editing operation is triggered at the cursor position, a prompt code matching the code editing operation is found in the reference code and sent to the client; The client is used to display the prompt code in the code editing interface.

10. A computing device, comprising: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions, wherein when the computer programs or instructions are executed by the processor, they implement the steps of the code hinting method according to any one of claims 1-8.

11. A computer-readable storage medium storing a computer program or instructions that, when executed by a processor, implement the steps of the code hinting method according to any one of claims 1-8.

12. A computer program product comprising a computer program or instructions that, when executed by a processor, implement the steps of the code hinting method according to any one of claims 1-8.