A code positioning method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202611191791.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-06
- Publication Date
- 2026-10-30
AI Technical Summary
[0008]根据本公开的另一方面,提供了一种计算机程序产品,包括计算机程序,计算机程序在被处理器执行时实现上述的方法。
Smart Images

Figure CN123011298A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to the field of code location technology. Specifically, it relates to a code location method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] In intelligent code repository maintenance and problem localization scenarios, it's often necessary to leverage large language model-driven agents to automatically locate defects or anomalies in the code. In relevant examples, the agent selects one tool from multiple tools catering to different types of code query needs, and through multiple rounds of interaction, gradually examines localized code to pinpoint the problem. For instance, the agent can invoke search tools to retrieve keywords, function search tools to find specific function definitions, import relationship retrieval tools to analyze file dependencies, or file reading tools to view specific code content. Summary of the Invention
[0003] This disclosure provides a code location method, apparatus, electronic device, storage medium, and program product.
[0004] According to one aspect of this disclosure, a code location method is provided, comprising: obtaining a code location request, wherein the code location request includes problem description information, a starting code fragment, and the file path of the starting code fragment in a code repository; determining a symbol to be jumped from the starting code fragment based on the problem description information; generating a symbol resolution instruction according to a preset instruction format based on the symbol to be jumped and the file path of the starting code fragment, and sending the symbol resolution instruction to a symbol resolution tool; and receiving the definition code information obtained by the symbol resolution tool from parsing the symbol to be jumped according to the symbol resolution instruction, as the code location result.
[0005] According to another aspect of this disclosure, a code location device is provided, comprising: a first acquisition module, configured to acquire a code location request, wherein the code location request includes problem description information, a starting code fragment, and a file path of the starting code fragment in a code repository; a first determination module, configured to determine a symbol to be jumped to from the starting code fragment based on the problem description information; a generation module, configured to generate a symbol resolution instruction according to a preset instruction format based on the symbol to be jumped to and the file path of the starting code fragment, and send the symbol resolution instruction to a symbol resolution tool; and a second determination module, configured to receive the definition code information obtained by the symbol resolution tool from parsing the symbol to be jumped to according to the symbol resolution instruction, as the code location result.
[0006] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method described above.
[0007] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to perform the methods described above.
[0008] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the method described above.
[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0010] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0011] Figure 1 This illustration schematically shows an exemplary system architecture to which code location methods and apparatus can be applied according to embodiments of the present disclosure;
[0012] Figure 2 A flowchart illustrating a code location method according to an embodiment of the present disclosure is shown schematically.
[0013] Figure 3 The diagram illustrates the determination of the jump symbol according to an embodiment of the present disclosure;
[0014] Figure 4 A schematic diagram illustrating the parsing of a jump symbol according to an embodiment of the present disclosure;
[0015] Figure 5 A flowchart illustrating a code location method according to another embodiment of this disclosure is shown schematically;
[0016] Figure 6 The diagram illustrates the relationship between the access range of the code navigation tool and the target code region according to a disclosed embodiment;
[0017] Figure 7 A block diagram of a code locating device according to an embodiment of the present disclosure is schematically shown; and
[0018] Figure 8 A schematic block diagram of an example electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0019] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0020] In the technical solution disclosed herein, the collection, storage, use, processing, transmission, provision, disclosure, and application of user personal information comply with the provisions of relevant laws and regulations, necessary confidentiality measures have been taken, and there is no violation of public order and good morals.
[0021] In the technical solution disclosed herein, the user's authorization or consent is obtained before acquiring or collecting the user's personal information.
[0022] Large code repositories typically exceed the context window of a large language model. Code issue localization agents need to progressively examine local code through multiple interactions to locate the problem. In relevant examples, the agent selects one of several search or code viewing tools for code searching. For instance, related technologies can provide large language model agents with multiple tools such as SearchClass, SearchFunction, GetImports, and search file contents, allowing the model to select the appropriate tool based on the problem description and current context, and then perform a step-by-step search. Alternatively, the repository can be constructed as a heterogeneous graph of files, classes, functions, call relationships, and import relationships, and then multi-hop searches can be performed using tools such as TraverseGraph and RetrieveEntity. The problem-solving process can be broken down into fixed stages such as file-level localization, class or function-level localization, and code snippet confirmation, completed by different prompts, searchers, or model calls. Alternatively, the agent can be allowed to simultaneously call multiple tools such as the terminal, full-text search, file reading, test running, and web page retrieval, using prompts and engineering learning tools. In addition, one can use the symbol resolution capabilities of go-to-definition or language server in the integrated development environment (IDE) to view a symbol definition, but this capability usually exists as a manual interaction action and does not form a unique action space and multi-turn navigation strategy for the large language model agent.
[0023] However, the above approach has at least the following drawbacks: Multi-tool solutions require the model to select the tool type and fill in parameters at each step; errors can arise from incorrect tool selection, incorrect symbol names, incorrect paths, or misinterpretation of returned results, and these errors amplify over long-chain tasks. Retrieval tools categorized by class, function, file, or import relationship represent high-level abstractions geared towards human understanding and may not correspond to the actual name bindings and control transfer relationships from the call point to the definition point during code runtime. Different tools return file skeletons, function texts, graph nodes, import lists, or search results with significant format differences, requiring the agent to extra infer the relationships between these observations, easily leading to context bloat. While fixed-stage pipelines are suitable for some tasks, they may prematurely prune or miss critical symbol paths when dealing with cross-file calls, indirect references, redistributions, inheritance, and attribute access. Although IDE jump functions can parse individual symbol definitions, they lack symbol selection based on problem descriptions, maintenance of historical observations, multi-round jump sequence decisions, termination judgments, and structured location output, making them difficult to directly use for automated agent location processes.
[0024] Based on this, this disclosure provides a code location method, comprising: obtaining a code location request, wherein the code location request includes problem description information, a starting code fragment, and the file path of the starting code fragment in the code repository; determining the symbol to be jumped to from the starting code fragment according to the problem description information; generating a symbol resolution instruction according to a preset instruction format based on the symbol to be jumped to and the file path of the starting code fragment, and sending the symbol resolution instruction to a symbol resolution tool; and receiving the definition code information obtained by the symbol resolution tool from parsing the symbol to be jumped to according to the symbol resolution instruction, as the code location result. This disclosure's code location method models repository-level problem location as a multi-round agent navigation process, and exposes only one code navigation tool for performing semantic alignment. The code navigation tool, based on the symbol resolution instruction, takes the "reference position of the symbol in a certain file" as input, calls a symbol resolution tool such as a language server or equivalent static analysis service to parse the definition position of the symbol, and returns the definition code information as a structured observation to the agent. In each round, the agent only needs to decide between "continuing natural language inference, calling the code navigation tool, and outputting the final position," thereby compressing the complex multi-tool orchestration problem into a single-action navigation problem along the program symbol dependency path.
[0025] Figure 1 An exemplary system architecture for applying code location methods and apparatus according to embodiments of this disclosure is illustrated.
[0026] It is important to note that Figure 1The examples shown are merely examples of system architectures that can be applied to the embodiments of this disclosure, to help those skilled in the art understand the technical content of this disclosure, but do not mean that the embodiments of this disclosure cannot be used in other devices, systems, environments, or scenarios. For example, in another embodiment, an exemplary system architecture to which the content processing methods and apparatus can be applied may include a terminal device, but the terminal device can implement the code location methods and apparatus provided by the embodiments of this disclosure without interacting with the server.
[0027] like Figure 1 As shown, the system architecture 100 of the code location method in this embodiment includes a Large Language Model Agent (LLM Agent) 110, a single tool 120, and a symbol resolution tool 130.
[0028] The large language model agent 110 is used to perform the operation of "jumping to the definition of a symbol in a file". Specifically, after obtaining a code snippet related to the problem provided by the user or automatically obtained by the system, the large language model agent 110 identifies the symbol to be jumped to from the code snippet and decides to jump to the definition of the symbol to be jumped to.
[0029] A single tool 120 exposes only one code navigation tool to the large language model agent 110. This code navigation tool is the sole interface between the large language model agent 110 and the underlying code parsing service.
[0030] The code navigation tool takes the "reference location of a symbol in a certain file" as input, calls the underlying symbol resolution tool 130 to parse the definition location of the symbol to be jumped to, and returns the definition code snippet as a structured observation to the large language model agent 110. By exposing only a single tool, the large language model agent 110 does not need to choose between multiple tools, nor does it need to learn the calling methods and parameter formats of different tools, thus helping to reduce the decision complexity of the large language model agent 110 and the tool usage threshold.
[0031] The symbol resolution tool 130 can be a language server used for semantic-level parsing of the target code repository. This language server may include the following sub-modules: Abstract Syntax Tree, Symbol Table, Symbol Search Engine, and Source Code. The Abstract Syntax Tree is used to perform syntactic analysis on the source code, generating a tree-structured representation for understanding the syntactic structure and hierarchical relationships of the code. The Symbol Table is an index structure used to store all symbols (including functions, classes, variables, constants, etc.) in the target code repository, along with their definition locations, types, and scope information. The Symbol Search Engine is used to quickly retrieve and locate the definition location of the symbol to be jumped to in the target code repository based on its name. The source code is the source code file of the target code repository, serving as the data foundation for symbol resolution.
[0032] During code location, the large language model agent 110 receives code snippets related to the problem provided by the user or automatically acquired by the system, and identifies the symbol to be jumped to from the code snippets. Then, the large language model agent 110 sends a symbol resolution request to the symbol resolution tool 130 through a single tool 120. The symbol resolution request includes at least the symbol name of the symbol to be jumped to and the location information of the symbol in the code snippet. Afterwards, the symbol resolution tool 130 locates the definition position of the symbol to be jumped to from the source code through abstract syntax tree parsing, symbol table lookup, and symbol search engine retrieval, based on the received symbol resolution request. The definition code snippet corresponding to the located definition position is returned to the large language model agent 110 as the structured observation result for the next round of inference. The large language model agent 110 repeats the above steps based on the returned definition code snippet until a preset termination condition is met, thereby forming an iterative navigation path that starts from the entry code snippet and gradually traces along the symbol definition chain.
[0033] The code location method disclosed herein can be applied to at least one of the following scenarios: code repository-level defect location, pre-location module of automatic repair system, code review and impact analysis tool, enterprise internal R&D knowledge base Q&A, IDE intelligent assistant, code understanding service based on language server protocol, and intelligent software engineering platform that needs to automatically trace call chains and symbol definitions in large code repositories.
[0034] The execution entity of the code location method disclosed herein can be a proxy. Before executing the code location method, a single-tool proxy environment needs to be established. Specifically, an external code navigation tool, `jump`, is registered with the proxy, and the final output format is specified. The proxy is configured to prohibit calls to other repository navigation tools such as `SearchClass`, `SearchFunction`, `GetImports`, full-text search, and arbitrary file reading. The `jump` code navigation tool call uses constrained JSON syntax, such as `{"name":"jump","arguments":{"symbol":"...","file_path":"...","index":0}}`, to reduce formatting errors and parameter ambiguity.
[0035] Based on the above single-tool agent environment Figure 2 A flowchart illustrating a code location method according to an embodiment of the present disclosure is shown schematically.
[0036] like Figure 2 As shown, the code location method 200 of this embodiment includes operations S210 to S240.
[0037] In operation S210, a code location request is obtained, which includes problem description information, starting code snippet, and the file path of the starting code snippet in the code repository.
[0038] Problem description information refers to semantic information provided by users or external systems to describe the code problem to be located. For example, problem description information can be a natural language description such as "After successful order payment, the order status has not been updated from pending payment to paid".
[0039] The starting code snippet refers to the initial source code text used to initiate the code location and exploration process. This snippet can be a code segment that the user deems relevant to the problem, or it can be code automatically extracted from the error stack trace to pinpoint the error location. The starting code snippet serves as the observation window for the agent's first iteration; the agent extracts the target symbol from the starting code snippet and begins tracing. For example, if a user reports "order status update failed," the starting code snippet could be the code segment that calls the status update function. The file path of the starting code snippet in the code repository refers to the storage path of the source code file from which the aforementioned starting code snippet originates.
[0040] In some embodiments, the code location request can be generated by the developer in the code review system by selecting the relevant code and submitting the location operation. In this case, the starting code segment is the code segment selected by the developer, the file path is the source file path where the code segment is located, and the problem description information can be the review content or problem description text entered by the developer.
[0041] In other embodiments, the code location request can be automatically generated by the testing framework when a test case fails. In this case, the starting code snippet is the error location code extracted from the failure stack, the file path is the source file path corresponding to the error location code, and the problem description information is test failure information or exception stack information.
[0042] In operation S220, based on the problem description information, the symbol to be jumped to is determined from the starting code segment.
[0043] A jump target symbol is a code symbol selected by the agent from the currently visible code snippet whose definition location needs further examination. The jump target symbol is the next target for the agent to trace the call chain during code location. For example, a jump target symbol can be a function call symbol (e.g., update_order_status), a property access symbol (e.g., order.status), an instantiation symbol (e.g., Order()), an import name symbol (e.g., datetime), a decorator symbol (e.g., @app.route), an exception type symbol (e.g., ValueError), or a configuration item symbol (e.g., config.TIMEOUT) appearing in the starting code snippet. The agent traces the root cause of the problem step by step along the call chain by selecting a jump target symbol and jumping to its definition location. The agent extracts symbols only from the currently visible code snippet (e.g., the starting code snippet), without performing keyword searches across the entire repository, thus ensuring that each symbol selection has a clear code context.
[0044] The symbol to be jumped to can be determined based on the relevance of each symbol in the starting code snippet to the problem description information.
[0045] The relevance of each symbol in the initial code snippet to the problem description information can be considered as the semantic strength of the association between the symbol and the problem description information. This measures the extent to which the symbol is likely a key node in problem tracing. The relevance can be determined in various ways, including but not limited to: the degree of matching between the symbol name and keywords in the problem description information, the semantic similarity between the code context of the candidate symbol and the problem description information, and whether the candidate symbol appears in the call path or error stack indicated by the problem description information. A higher relevance indicates a stronger association between the symbol and the problem to be located, and a greater likelihood that it points to the root source code of the problem.
[0046] When operating S230, a symbol resolution instruction is generated according to the file path of the symbol to be jumped to and the starting code segment, and then sent to the symbol resolution tool.
[0047] In some embodiments, the agent invokes symbol resolution instructions through a single code navigation tool. Based on this, the preset instruction format is a structured instruction format agreed upon between the agent and the code navigation tool. In this embodiment, the preset instruction format can be a constrained JSON syntax format, and the instruction includes at least two parts: the code navigation tool name and parameters. For example, the preset instruction format is {"name":"jump","arguments":{"symbol":"name of the symbol to jump to","file_path":"file path of the starting code snippet","index":order identifier}}, where the index field is used to specify the specific target symbol when multiple symbols with the same name exist in the starting code snippet. This preset instruction format allows the agent to use the same data structure each time it invokes the tool, eliminating the need to dynamically adjust the parameter structure based on the tool type, thereby reducing the probability of formatting errors. The name field in the preset instruction format is fixed at "jump" to specify that the invocation target is the code navigation tool.
[0048] Symbol resolution instructions are structured invocation commands generated by the agent according to a preset instruction format, which are used to trigger the code navigation tool to call the symbol resolution tool to perform symbol definition resolution.
[0049] The code navigation tool, named Jump, is the only external code navigation tool exposed in this disclosure. It is registered in the proxy environment, serving as the sole interface between the proxy and the underlying symbol resolution tool. The code navigation tool takes the "reference location of a symbol in a file" as input, invokes the symbol resolution tool (such as a language server, compiler frontend, code index, or equivalent static analysis service) to resolve symbol definitions, and returns the resolution result (definition code snippets) as structured observations to the proxy. The code navigation tool itself does not perform symbol resolution; its responsibility is to receive symbol resolution instructions, invoke the symbol resolution tool, format the resolution result into structured observations, and return them to the proxy.
[0050] Symbol resolution tools are program components that actually perform symbol definition resolution, such as language servers, compiler front-ends, code indexing services, or equivalent static analysis services. Symbol resolution tools locate symbol definitions by parsing the abstract syntax tree of the source code, querying symbol tables or index databases, and based on the name binding rules of the programming language, return the defined code snippets to code navigation tools.
[0051] In some embodiments, the agent first obtains the name of the symbol to be jumped to, determined in operation S220, and the file path of the starting code segment obtained in operation S210. Then, it fills in the above information according to a preset instruction format to generate a complete symbol resolution instruction. For example, if the symbol to be jumped to is update_order_status, the file path is src / order.py, and there are two calls to update_order_status in that file, the agent can generate {"name":"jump","arguments":{"symbol":"update_order_status","file_path":"src / order.py","index":0}}", where index:0 indicates that the first occurrence of the update_order_status symbol is selected as the resolution target.
[0052] It's important to note that the file path refers to the path of the file containing the location where the jump symbol appears, not the path to the symbol's definition. The symbol's definition is determined by the symbol resolution tool; the proxy does not need to guess it beforehand. After generating the symbol resolution instruction, the proxy sends it to the code navigation tool. Upon receiving the instruction, the code navigation tool parses the parameters and invokes the symbol resolution tool to perform symbol definition resolution.
[0053] During operation S240, the symbol resolution tool receives the definition code information obtained by parsing the symbol to be jumped to according to the symbol resolution instruction, and uses it as the code location result.
[0054] Definition code information refers to the structured information returned by the symbol resolution tool after parsing the symbol to be jumped to. It describes the definition location and related context of the symbol in the code repository. Definition code information may include the definition file path, the line number range where the definition is located, and code text snippets near the definition location. For example, when the symbol to be jumped to is `update_order_status`, the definition code information may include: the file path `src / status.py`, the line number range 88-92, and the complete implementation code of the function. Definition code information may also include the symbol type (such as function, class, variable, constant, etc.) and necessary contextual comments.
[0055] The code location result can be the definition code information returned by the symbol resolution tool.
[0056] In some embodiments, if the agent performs only a single jump, the agent directly determines the received definition code information as the code location result. If the agent performs multi-round iterative navigation, the agent uses the code fragment in the returned definition code information as the current code fragment for the next iteration, continues symbol extraction and jumps until a preset termination condition is met, and finally outputs all the definition code information obtained from multiple iterations as the code location result. In the iterative scenario, the definition code information received in operation S240 is used to update the agent's current code fragment, serving as the input for operation S220 in the next iteration.
[0057] It should be noted that if the symbol resolution tool succeeds, the code navigation tool Jump returns the definition file path, line and column range, definition code snippet, symbol type, and necessary superscript and superscript comments; if the resolution fails, it returns error messages such as non-existent symbol, unresolved ambiguity, dynamic import, runtime modification, or language server exception. After receiving the error message, the agent can record the error message to the history and trigger the termination judgment to end the exploration of the current branch.
[0058] According to embodiments of this disclosure, by taking problem description information and starting code snippets as input, the symbol to be jumped to is determined from the currently visible code. A symbol resolution instruction is generated according to a preset instruction format, and a symbol resolution tool parses the definition location of the symbol and returns the definition code information as the location result. This method eliminates the need for the agent to select from multiple tools during the entire location process, nor does it require learning the calling methods and parameter formats of different tools. It only needs to jump step-by-step along the program's symbol dependency path to locate the problem code. This reduces the complexity of the agent's multi-tool orchestration, helps reduce the risk of tool selection errors and context bloat, and achieves code location with lower decision-making costs.
[0059] The following explains how to determine the symbol to jump to.
[0060] According to embodiments of this disclosure, determining the symbol to be jumped from the starting code segment based on the problem description information may include: extracting at least one candidate symbol contained in the starting code segment, wherein the candidate symbol includes at least one of the following: function call symbol, method call symbol, instantiation symbol, property access symbol, import name symbol, decorator symbol, exception type symbol, inheritance parent class symbol, configuration item symbol; determining the candidate symbol related to the problem description information from the at least one candidate symbol to obtain the symbol to be jumped.
[0061] Candidate symbols refer to the set of all possible targets for a jump, extracted by the agent from the starting code segment. The agent does not directly determine a symbol as the jump target; instead, it first extracts all candidate symbols appearing in the current code segment and then filters from them. Candidate symbol extraction is based on the code's syntactic structure, not keyword matching. For example, the agent can extract symbols containing the following symbol types from the starting code segment as candidate symbols: function call symbols, method call symbols, instantiation symbols, property access symbols, import name symbols, decorator symbols, exception type symbols, inheritance symbols, and configuration item symbols.
[0062] In some embodiments, extracting at least one candidate symbol contained in the starting code segment may include: performing syntax analysis or lexical analysis on the starting code segment to extract all candidate symbols contained therein. For example, the agent may obtain the aforementioned candidate symbols by means of regular expression matching, parsing with a syntax parser, or calling the symbol extraction interface of a language server.
[0063] After extracting candidate symbols, the agent determines the candidate symbols related to the problem description information from at least one candidate symbol as the jump symbol. Specifically, the jump symbol can be determined from at least one candidate symbol based on the matching degree between each candidate symbol and the problem description information.
[0064] Figure 3 A schematic diagram illustrating the determination of the jump symbol according to an embodiment of the present disclosure is shown.
[0065] like Figure 3 As shown, the method for determining the symbol to be jumped to in this embodiment includes: first, extracting at least one candidate symbol from the starting code segment 310, such as candidate symbol 321, candidate symbol 322, ..., candidate symbol 32n; then, determining the matching degree between each candidate symbol and the problem description information 330 to obtain the matching degree of each candidate symbol, for example, determining the matching degree between candidate symbol 321, candidate symbol 322, ..., candidate symbol 32n and the problem description information 330 respectively to obtain the matching degree of candidate symbol 321, the matching degree of candidate symbol 322, ..., the matching degree of candidate symbol 32n; then, selecting the candidate symbol with the highest matching degree from the matching degree of candidate symbol 321, the matching degree of candidate symbol 322, ..., candidate symbol 32n as the symbol to be jumped to 340.
[0066] In some embodiments, determining the matching degree between each candidate symbol and the problem description information may include: determining the semantic matching degree between each candidate symbol and the problem description information. Specifically, the problem description information can be converted into a semantic vector, and the symbol name and context information of each candidate symbol can also be converted into vectors, and the semantic similarity between the two can be calculated; keywords in the problem description information can also be extracted, and the degree of overlap between the name of each candidate symbol and the keywords can be calculated. Then, the candidate symbols are sorted according to the semantic similarity or keyword overlap, and the candidate symbol with the highest score is determined as the symbol to be redirected. For example, if the problem description information contains words such as "payment," "status," and "update," the agent will preferentially select candidate symbols whose names contain or are semantically close to these words, such as update_order_status.
[0067] According to embodiments of this disclosure, by extracting candidate symbols of various types, including function calls, method calls, instantiation, property access, import names, decorators, exception types, inherited parent classes, and configuration items, from the starting code snippet, and selecting the most relevant symbols as the symbols to be jumped to based on the matching degree between each candidate symbol and the problem description information, the agent can accurately determine the symbol most closely related to the problem semantics as the starting point for tracing. This avoids the inefficiency and positioning deviation caused by the agent blindly searching or randomly selecting symbols throughout the entire repository, and helps to improve the accuracy of symbol selection and problem positioning.
[0068] In some embodiments, there may be multiple candidate symbols with the same name in the starting code snippet, such as multiple calls to a function with the same name in the same file, or multiple references to a variable with the same name in the same line of code. If the agent only provides the symbol name and file path when generating symbol resolution instructions, the symbol resolution tool may not be able to uniquely determine the symbol to jump to, resulting in resolution ambiguity.
[0069] Therefore, according to the embodiments of this disclosure, the above code location method may further include: obtaining the occurrence order identifier of the symbol to be jumped to in the starting code segment; generating a symbol resolution instruction according to a preset instruction format based on the symbol to be jumped to, the file path corresponding to the starting code segment, and the occurrence order identifier of the symbol to be jumped to.
[0070] The occurrence order identifier is an identifier used to distinguish the order in which multiple symbols with the same name appear within the same code segment. When multiple symbols with the same name as the target symbol exist in the starting code segment, the symbol name and file path alone are insufficient to uniquely identify the target symbol. The occurrence order identifier records the order in which the target symbol appears within the code segment (e.g., the first appearance, the second appearance), enabling the agent to accurately locate the target symbol. For example, the occurrence order identifier can be an occurrence number (e.g., 0 for the first appearance, 1 for the second appearance) or an occurrence location identifier (e.g., a combination of line number and occurrence order). When no symbol with the same name as the target symbol exists in the starting code segment, the occurrence order identifier can be omitted or set to a default value (e.g., 0). For instance, in the JSON syntax used by the code navigation tool `jump`, `{"name":"jump","arguments":{"symbol":"...","file_path":"...","index":0}}`, the `index` field is used to distinguish multiple symbols with the same name within the same code segment.
[0071] In some embodiments, when extracting candidate symbols from the starting code segment, the order in which each candidate symbol appears in the starting code segment is recorded simultaneously. For example, the agent can assign an appearance number (e.g., 0, 1, 2, ...) to each candidate symbol in the starting code segment in a top-to-bottom order. After determining the symbol to jump to from the candidate symbols, the appearance number corresponding to the symbol to jump to is obtained as the appearance order identifier. When generating the symbol resolution instruction, the symbol to jump to, the file path corresponding to the starting code segment, and the appearance order identifier are filled into a preset instruction format to generate the symbol resolution instruction. For example, if the symbol to jump to is update_order_status, the file path is src / order.py, and the symbol to jump to is the first appearance in the starting code segment (appearance number 1), then the agent can generate the following symbol resolution instruction: {"name":"jump","arguments":{"symbol":"update_order_status","file_path":"src / order.py","index":1}}, where index:1 is used to specify parsing the second appearance of the update_order_status symbol. Using the above method, even if there are multiple symbols with the same name in the initial code snippet, the symbol resolution tool can uniquely identify the symbol to jump to based on the order of appearance, thus avoiding resolution ambiguity.
[0072] In other embodiments, if there is no symbol with the same name as the symbol to be jumped to in the starting code segment, the agent may omit the step of obtaining the occurrence order identifier, or set the index to a default value (such as 0) in the symbol resolution instruction.
[0073] The following combination Figure 4 This section explains the specific method by which the symbol resolution tool resolves the symbol to be jumped to based on the symbol resolution instructions.
[0074] Figure 4 A schematic diagram illustrating the parsing of a jump symbol according to an embodiment of the present disclosure is shown.
[0075] like Figure 4 As shown, the method for parsing the symbol to be jumped to in this embodiment includes: determining the position information 430 of the symbol to be jumped to in the starting code segment based on the file path 420 of the symbol to be jumped to in the starting code segment; then determining the target symbol type 440 for the symbol to be jumped to in the preset symbol types, and using the parsing method 450 corresponding to the target symbol type 440 to parse the symbol to be jumped to in the starting code segment based on the position information 430 to obtain the definition code information 460.
[0076] The location information can be the coordinates of the symbol to be jumped to within the starting code segment, and may include the file path, line number range, and column number range. In one specific implementation, the location information can be determined by a combination of the file path and the order of appearance identifier in the symbol resolution instruction, or it can be obtained by the symbol resolution tool by parsing the corresponding position of the starting code segment within the starting code segment. In other words, the location information indicates the specific reference position of the symbol to be jumped to within the starting code.
[0077] For example, the symbol to be jumped to is update_order_status. The symbol resolution tool extracts the file path parameter (such as src / order.py) and the occurrence order identifier parameter (such as index:0) from the received symbol resolution instruction. It then locates the specific position of the first occurrence of the update_order_status symbol in the src / order.py file to obtain the line number range and column number range of the symbol to be jumped to, i.e., the position information.
[0078] Symbol type refers to the category of the symbol to be jumped to in the programming language syntax, which is used to determine which parsing rule to use to locate the definition of the symbol to be jumped to.
[0079] In this embodiment of the disclosure, the preset symbol types may include name symbols, attribute access symbols, and cross-file reference symbols. Name symbols refer to independent identifiers that do not contain member access operators (such as the dot ".") or module path prefixes, such as the function name `update_order_status`, the variable name `count`, and the class name `OrderService`. Attribute access symbols refer to symbolic expressions that access object members or namespace members using a dot or similar operator, such as `status` in `order.status`. Cross-file reference symbols refer to symbols whose definition location is not in the same source code file as their current location, and whose definition needs to be resolved through the module import mechanism, such as `update_order_status` imported via `from status import update_order_status`.
[0080] Each preset symbol type corresponds to a specific interpretation method. For name symbols, the resolution method can be to search the symbol table level by level along the scope chain; for attribute access symbols, the resolution method can be to find the member definition location based on type information; and for cross-file reference symbols, the resolution method can be to trace the definition location based on module dependency information.
[0081] According to embodiments of this disclosure, by determining the location information of the symbol to be jumped to in the starting code segment based on the file path, and identifying the target symbol type from preset symbol types, the symbol parsing tool can adaptively select the most suitable parsing strategy for symbols with different syntax structures by adopting the parsing method corresponding to the type based on the location information. It can track the symbol to be jumped to its definition location from the location where the symbol appears, avoiding parsing failure or positioning deviation caused by misjudgment of symbol type or mismatch of parsing method, and improving the accuracy and compatibility of symbol definition parsing.
[0082] The following explains the specific parsing method for the jump symbol without using the parsing method corresponding to the preset symbol type.
[0083] When the target symbol is a named symbol, the search begins with the scope corresponding to the location information and proceeds layer by layer along the scope chain to find the definition of the symbol to be jumped to. Specifically, searching for the definition of the symbol to be jumped to layer by layer along the scope chain can include searching the symbol table sequentially along the following scopes: local scope, closure scope, module scope, and built-in scope. For example, if the symbol to be jumped to is the function call symbol update_order_status, the symbol resolution tool first searches for the definition of update_order_status in the current function scope where the symbol to be jumped to appears. If it is not found, the search is expanded to the outer scope level until the definition is found or the built-in scope is reached.
[0084] Scope is the area of code in a program where a name (such as a variable, function, or class) is declared or defined.
[0085] A scope chain is a chain-like structure of nested scopes arranged from the inside out, used to find the definition of a name across multiple scopes. When a name is referenced in a scope, the program starts from the current scope and searches outwards along the scope chain until it finds the definition of the name or reaches the outermost scope.
[0086] A symbol table is a data structure that stores all symbols (such as variables, functions, classes, constants, etc.) defined in a scope, along with their attribute information (such as type, definition location, and scope). Each level of scope corresponds to a symbol table, and symbol resolution tools determine whether a name is defined in the current scope and its definition location by looking up the symbol table.
[0087] Local scope refers to the code region inside the current function or method, including local variables, internal functions, and parameters defined within the function body.
[0088] If the function is not found in the local scope, it moves to the outer scope, specifically the closure scope. The closure scope refers to the scope of the outer function within a nested function, and it is used to support the closure mechanism.
[0089] If the function is not found in the closure scope, the search continues outwards to the module scope. The module scope refers to the top-level global scope of the current file, which includes functions, classes, and variables defined at the top level of the file.
[0090] If the symbol is not found in the module scope, it will be searched in the built-in scope. The built-in scope refers to the built-in names provided by the programming language. If found in the built-in scope, the corresponding built-in definition information is returned; if not found in any scope, it is determined that the symbol to be jumped to is undefined, and an error message is returned.
[0091] When the target symbol type is an attribute access symbol, the definition location of the symbol to be jumped to is found from the type of the target object of the symbol to be jumped to based on the location information.
[0092] The target object refers to the expression to the left of the dot in the attribute access notation, that is, the carrier or container to which the accessed attribute belongs. For example, in the attribute access notation `order.status`, the target object is `order`; in `get_order().status`, the target object is the return value of `get_order()`. The target object is key to resolving attribute access notation because the definition location of members depends on the type of the target object.
[0093] The type of the target object refers to the class or data type to which the target object belongs, and it is the basis for finding the member definition location. For example, if the target object is `order` and its type is marked as `Order`, then the type of the target object is the `Order` class; if the target object is the return value of `get_order()` and its return type is marked as `Order`, then the type of the target object is the `Order` class. By determining the type of the target object, the symbol resolution tool can locate the code area corresponding to that type and find the member definition location within it.
[0094] The member definition location refers to the position of the member defined within its type in the attribute access symbol to the right of the dot. For example, in `order.status`, the member is `status`, and its definition location is the code location in the `Order` class where the `status` attribute is defined (e.g., `self.status = 'pending'` in the `Order.__init__` method); in `order.save()`, the member is `save`, and its definition location is the code location in the `Order` class where the `save` method is defined. It should be noted that when the symbol to be jumped to is an attribute access type, the member definition location is the same as the definition location of the symbol to be jumped to.
[0095] In some embodiments, the resolution of attribute access symbols is based on at least one of the following methods to locate the member definition location of the symbol to be jumped to: type annotation, control flow analysis, function return type, type stub file, and method resolution order. For example, if the symbol to be jumped to is order.status, the symbol resolution tool first determines the type of the target object order (e.g., by determining the Order type through the type annotation order: Order), and then searches for the member definition location of status in the Order class.
[0096] The type-annotation-based lookup method works as follows: when the target object has a type annotation, the symbol resolution tool directly obtains the type of the target object from the type annotation and then looks for the member definition location within that type. For example, if the code contains `order = get_order(order_id)`, the symbol resolution tool determines that the type of `order` is `Order`, and then looks for the definition location of `status` within the `Order` class.
[0097] The lookup method based on control flow analysis works as follows: When a target object lacks a type annotation, the symbolic resolution tool traces the source of the target object's assignment through control flow analysis, infers the type of the target object, and searches for the member definition location within the inferred type. For example, if the code is `order = get_order(order_id)` and `order` has no type annotation, the symbolic resolution tool traces the source of `order`, analyzes the return type of the `get_order` function, and infers the type of `order`.
[0098] The lookup method based on function return type is as follows: The symbol resolution tool determines the type of the target object based on the return type annotation or inferred return type of the function from which the target object originates, and then searches for the member definition location within that type. For example, if the return type annotation of the get_order function is -> Order, then the symbol resolution tool determines that the type of order is Order.
[0099] The lookup method based on type stub files works as follows: When the target object comes from a third-party library and has no source code, the symbol resolution tool obtains the type information of the target object from the type stub file and searches for the member definition locations within that type. For example, if the target object comes from the requests library, the symbol resolution tool obtains the type information of the target object from the requests-stubs type stub file.
[0100] The method-resolved order-based search method works as follows: when a member is not defined in the current type, the symbol resolution tool continues searching for the member's definition in the parent class according to the method resolution order. For example, if the PremiumOrder class inherits from the Order class, and PremiumOrder does not define status, the symbol resolution tool will search for the definition of status in the parent class Order.
[0101] It should be noted that the above search methods can be used individually or in combination. For example, when the type annotation does not exist, the symbol resolution tool can use control flow analysis and function return type analysis sequentially to infer the type of the target object.
[0102] When the target symbol type is a cross-file reference symbol, the definition location of the symbol to be jumped to is found based on the position information and module dependency information.
[0103] Module dependency information refers to a set of information describing the import and dependency relationships between files, including import dependency graphs, re-export rules, and module loading semantics. Based on this, the definition location of the symbol to be jumped to can be found using at least one of the following methods: import dependency graphs, re-export rules, and module loading semantics.
[0104] An import dependency graph is a directed graph consisting of source code files as nodes and import relationships between files as edges. Symbol resolution tools can trace the definition source of cross-file reference symbols along the import path by traversing the import dependency graph.
[0105] A re-export rule is a set of rules that allow a file to re-export imported symbols for use in other files. Symbol resolution tools, based on these re-export rules, can bypass intermediate exported files and locate the original definition file of the symbol.
[0106] Module loading semantics are module resolution rules defined by a programming language or framework, used to map module names to actual file paths. Symbol resolution tools, based on module loading semantics, can resolve module names in import declarations to actual file paths.
[0107] In some embodiments, the definition location of the symbol to be jumped to is found according to at least one of the following methods: import dependency graph, re-export rules, and module loading semantics. This may include: the symbol resolution tool first resolves the imported module name into a file path according to the module loading semantics, then traces the import edges level by level in the import dependency graph, simultaneously checking for re-export rules, and penetrating the re-export chain until the original definition location of the symbol to be jumped to is found. If the definition is not found in all reachable nodes of the import dependency graph, or if module path resolution fails, an error message is returned.
[0108] According to embodiments of this disclosure, by adopting corresponding resolution methods based on different symbol types (name symbols, attribute access symbols, and cross-file reference symbols) of the symbol to be jumped to: for name symbols, searching outwards from the current scope layer by layer along the scope chain; for attribute access symbols, first determining the type of the target object and then searching for member definitions; for cross-file reference symbols, tracing the definition location along the import path based on module dependency information, the symbol resolution tool can adaptively select the most suitable resolution path for symbols with different syntax structures, achieving accurate mapping from the symbol occurrence location to the definition location, and improving the accuracy and compatibility of symbol definition resolution.
[0109] In some implementations, the code localization process may involve complex tracing scenarios spanning multiple call chains. Key symbols in the initial code snippet provided by the user may not directly point to the root cause of the problem, requiring further examination of other symbols in the symbol definition, delving deeper layer by layer to locate the problematic code. To address this, this disclosure also provides an iterative code localization method that enables the agent to recursively explore along the call chain.
[0110] The following is combined with Figure 5 The iterative code location method according to the embodiments of this disclosure will be described in detail.
[0111] Figure 5 A flowchart illustrating a code location method according to another embodiment of this disclosure is shown.
[0112] like Figure 5 As shown, the code location method in this embodiment includes operations S510 to S570.
[0113] When operating S510, a code location request is obtained. The code location request includes problem description information, starting code snippet, and the file path of the starting code snippet in the code repository.
[0114] The problem description information, starting code snippet, and file path of the starting code snippet in the code repository obtained in operation S510 have the same meaning as the problem description information, starting code snippet, and file path of the starting code snippet in the code repository mentioned above, and will not be repeated here.
[0115] When operating S520, the starting code snippet is determined as the candidate code snippet for the first iteration.
[0116] In operation S530, based on the problem description information, the symbol to be jumped to is determined from the candidate code segments corresponding to the current iteration round.
[0117] The candidate code snippet for the current iteration refers to the code text being observed and analyzed in that iteration. In the first iteration, the candidate code snippet for the current iteration is the initial code snippet; in subsequent iterations, the candidate code snippet for the current iteration is updated to the definition code snippet returned from the previous iteration. The proxy extracts symbols only from the candidate code snippet for the current iteration, without performing keyword searches across the entire repository, thus ensuring that the symbol selection at each step has a clear code context.
[0118] In other embodiments, for the multi-round iterative code location method, when the agent determines the symbol to be jumped to in each round of iteration, it can also combine historical observations to determine it. The historical observations can include accessed code segments and executed jump records.
[0119] When operating the S540, a symbol resolution instruction is generated based on the symbol to be jumped to and the file path of the candidate code segment to which the symbol to be jumped belongs.
[0120] When operating S550, a symbol resolution instruction is sent to the symbol resolution tool, and in response, the symbol resolution tool parses the definition code information of the symbol to be jumped according to the symbol resolution instruction to determine the candidate code segment for the next iteration.
[0121] In operations S540 and S550, the process of generating a symbol resolution instruction based on the symbol to be jumped and the file path of the candidate code segment to which the symbol to be jumped belongs, sending the symbol resolution instruction to the symbol resolution tool, and responding to the symbol resolution tool resolving the definition code information obtained by resolving the symbol to be jumped based on the symbol resolution instruction is the same as that in operations S230 and S240, and will not be described again here.
[0122] In operation S560, determine whether the preset termination condition is met. If it is met, proceed to operation S570; otherwise, proceed to operation S530.
[0123] During iterative execution, the agent needs to determine whether to continue jumping or stop iterating and output the location result based on preset termination conditions. Preset termination conditions include at least one of the following: the relevance between the defined code snippet obtained in the current iteration and the problem description information is greater than a relevance threshold; there are no unresolved symbols in the candidate code snippets corresponding to the current iteration; the number of iterations reaches a preset number; or the remaining capacity of the context window is less than a preset capacity threshold. Here, relevance characterizes the degree of association between the defined code snippet and the problem description information; a higher relevance indicates that the defined code snippet is more likely to be the root cause of the problem. The relevance threshold is a preset benchmark value used to determine whether the current defined code snippet is sufficiently relevant to the problem description. The context window refers to the limited capacity space used by the large language model agent to store historical observation and inference information.
[0124] In some embodiments, in each iteration, after receiving the definition code information returned by the symbol resolution tool, the agent calculates the relevance between the definition code fragment corresponding to the definition code information and the problem description information. If the relevance is greater than a preset relevance threshold, it indicates that the agent has located the code location highly relevant to the problem, stops the iteration, and outputs the definition code fragment as the final location result. For example, if the preset relevance threshold is 0.8, and the relevance between the definition code fragment returned in the current iteration and the problem description information is 0.92, then this termination condition is met, and the agent stops iterating.
[0125] In some embodiments, in each iteration, the agent extracts candidate symbols from the current candidate code segment. If the extracted candidate symbols are empty, or if all extracted candidate symbols have been visited, it indicates that the current path cannot be followed further, and the agent stops iterating.
[0126] In some embodiments, the agent records the number of iteration rounds executed during the iteration process. If the current iteration round count reaches a preset maximum number of iterations, the agent stops iterating to prevent infinite loops or excessive consumption of computing resources.
[0127] In some embodiments, the agent monitors the remaining capacity of the context window of the large language model it employs during iteration. If the remaining capacity of the context window is less than a preset capacity threshold (e.g., less than 5% of the total capacity), the agent stops iteration to avoid information loss or system malfunction due to context window overflow.
[0128] When operating the S570, the code location result is determined based on the definition code information obtained from multiple iterations.
[0129] According to embodiments of this disclosure, by determining the starting code segment as the candidate code segment for the first iteration and iteratively executing the operations of "determining the symbol to jump from the current candidate code segment, generating symbol resolution instructions, sending instructions to the symbol resolution tool, and determining the next round of candidate code segments based on the returned definition code information," the agent can trace the call chain layer by layer, gradually penetrating multiple layers of call relationships from the starting code segment until the preset termination condition is met. This enables the tracing of complex problems spanning multiple layers of call chains in large code repositories, avoiding the limitation that a single jump cannot reach the root cause of the problem, and improving the comprehensiveness and accuracy of code location.
[0130] During the iteration process, a candidate location set can be maintained. Specifically, the agent determines the relevance between the problem description information and the defined code snippets obtained in each iteration. From these snippets, it identifies those with a relevance greater than or equal to a preset threshold (e.g., 0.8) and adds them to the candidate location set, recording which iteration they originated from and the corresponding reason. The candidate location set can be added to, deleted from, or reordered with each new iteration, thus dynamically maintaining a list of candidate locations most likely pointing to the root cause of the problem. When the iteration terminates, the agent outputs the defined code snippets from the candidate location set as the code location result. Since each observation originates from symbol definition resolution, the path source is clear, auditable, and replayable. This facilitates restricting the agent to only read statically parsable code snippets within the repository in enterprise scenarios, improving the controllability and security of the location process.
[0131] In some implementations, the relevance between the problem description information and the definition code snippets obtained in each iteration can be determined in at least one of the following ways: based on the degree of keyword overlap between the definition code snippets and the problem description information; based on the semantic similarity between the definition code snippets and the problem description information; based on whether the definition code snippets are located on the currently explored call chain or import chain; or based on whether the definition code snippets are located on the error path or assertion path indicated by the problem description information.
[0132] The above methods can be used individually or in combination. For example, a weighted combination of multiple dimensions such as keyword matching degree, semantic similarity, and call chain position matching degree can be used as the comprehensive relevance score. The higher the relevance score, the closer the defined code snippet is to the problem to be located, and the more likely it is to point to the root source code of the problem.
[0133] According to embodiments of this disclosure, by determining the relevance between the problem description information and the definition code fragments obtained in each iteration, and by selecting definition code fragments that meet the relevance criteria based on a preset threshold and adding them to the candidate location set, the iteration source and corresponding reasons are recorded. At the same time, the candidate location set is dynamically added, deleted, and reordered according to the new iteration results. This allows the agent to continuously filter and update the candidate positions most likely to point to the root cause of the problem during multiple iterations, avoiding interference from low-relevance code fragments on the location results. This ensures that the final output code location result is the code position most closely related to the problem description in multiple iterations, which helps to improve the accuracy and reliability of the location results.
[0134] As previously stated, this disclosure simplifies the complex multi-tool orchestration problem into a single-action navigation problem along a program symbol dependency path by exposing only a semantically aligned code navigation tool, Jump, to the agent. The following will combine... Figure 6 Access to code navigation tools is constrained by currently visible symbols and language server parsing results, thus limiting the agent's exploration space to semantically accessible code areas for explanation.
[0135] Figure 6 The diagram illustrates the relationship between the access range of the code navigation tool and the target code region according to a disclosed embodiment.
[0136] like Figure 6 As shown, the GT (Generator Too, i.e., the proxy that performs code location operations) does not directly access the entire code repository. Instead, it performs symbol resolution and jumps within the current scope through access operations. Scopes include repository scope and code region scope.
[0137] Specifically, the repository scope represents the overall extent of the target code repository, i.e., the potential search space for code location tasks. However, the actual access scope of the code navigation tool does not directly cover the entire repository scope, but is constrained by the currently visible symbols in the GT (Gross Logic). The GT extracts visible symbols from the current observation window and triggers the code navigation tool through an access operation. The language server then resolves the symbol, thus limiting the access scope to the current scope, which is the target code region semantically reachable from the visible symbols.
[0138] Compared to directly configuring the GT's access scope to cover the entire repository scope, this disclosure restricts the GT's exploration space to the semantically reachable target code region through a two-level constraint of access operations and the current scope. The current scope is dynamically updated as the GT jumps. When the GT jumps to a new defined code snippet, the current scope is updated to the code region corresponding to that defined code snippet. The GT then continues to extract the next visible symbol within the new scope and repeats the above process.
[0139] The scope constraint mechanism described above effectively reduces the number of irrelevant files and functions entering the GT context window, avoiding context bloat and improving the controllability and effectiveness of code location. GT always progresses step by step within the semantically reachable region constrained by both currently visible symbols and the language server's parsing results until the root source code of the problem is located.
[0140] In summary, this disclosure models repository-level problem localization as a multi-round agent navigation process, and on this basis, forms a single-tool action abstraction. Specifically, if repository navigation is modeled as a finite-time-domain decision-making process, the original multi-tool action space A contains various heterogeneous actions such as search tools, search function tools, import relationship acquisition tools, and file reading tools; the agent needs to select one action from the multi-tool action space A to execute in each round of interaction, resulting in a large decision space and high selection complexity. To address this, this disclosure compresses the multi-tool action space A into a single-tool action space A'={Jump}, meaning that the agent only needs to execute the Jump action in each round of interaction. Each Jump action generates a state transition related to the program execution semantics through static symbol resolution (i.e., calling the language server or equivalent static analysis service to resolve symbol definitions), transitioning from the current symbol's occurrence position to its definition position. The state transition corresponds to the control transfer relationship from the call point to the definition point during program runtime. For statically resolvable target symbols, as long as the target symbol is located on a symbol dependency path (i.e., call chain, import chain, or inheritance chain) originating from the entry file, there exists a sequence of Jump actions. The agent can reach the definition location of the target symbol by executing this sequence of Jump actions sequentially. Through the above single-tool action abstraction, this disclosure, while preserving the semantic reachability along the symbol dependency path, helps the agent reduce the effective branching factor (compressing from multiple tool selection to single tool execution) and tool interface complexity (compressing from multiple sets of interfaces to a unified interface) in each round of interaction. This enables the agent to achieve accurate semantic-level code location in the code repository with lower decision-making costs.
[0141] It should be noted that the code location method provided in this disclosure can be used as the repository navigation layer of a code intelligence platform. After a user submits a defect description, requirement change description, error stack trace, or code review issue, the system initializes the agent with the entry file or the starting point provided by an external location module. The agent only uses the code navigation tool Jump to step through the definitions of relevant symbols, and finally outputs candidate modification functions or candidate files. Subsequent processes such as patch generation, test execution, manual review, or submission merging can receive the location results output by this disclosure as input.
[0142] The code navigation method disclosed herein can also be integrated into the existing language server protocol ecosystem. For example, in Python, name symbols, attribute access symbols, and cross-file reference symbols can be resolved via Pyright or an equivalent language service; in programming languages such as Java, C / C++, Go, and TypeScript, the same Jump tool interface can be implemented through the corresponding language server, compiler index, or static analysis service. Because the external actions faced by the proxy remain consistent, the resolution differences between different programming languages are encapsulated within the code navigation tool. The proxy side does not need to learn different calling methods for different languages and always executes a unified jump strategy.
[0143] Regarding the usage of the model, this disclosure does not restrict the agent to adopt a specific training algorithm. The agent can be used directly through prompt word engineering, or it can be trained through supervised fine-tuning, rejection sampling, reinforcement learning, or enterprise log playback. When using reinforcement learning, a single jump action space can effectively reduce the branching factor in the long-term exploration process, but the objective function and reward design of reinforcement learning are optional implementation methods and do not constitute a restriction on the use of the agent.
[0144] Figure 7 A block diagram of a code locating apparatus according to an embodiment of the present disclosure is shown schematically.
[0145] like Figure 7 As shown, the code positioning device 700 includes a first acquisition module 710, a first determination module 720, a generation module 730, and a second determination module 740.
[0146] The first acquisition module 710 is used to acquire a code location request, wherein the code location request includes problem description information, starting code snippet, and the file path of the starting code snippet in the code repository.
[0147] The first determination module 720 is used to determine the symbol to jump to from the starting code segment based on the problem description information.
[0148] The generation module 730 is used to generate symbol resolution instructions according to a preset instruction format based on the file path of the symbol to be jumped to and the starting code segment, and send the symbol resolution instructions to the symbol resolution tool;
[0149] The second determining module 740 is used to receive the definition code information obtained by the symbol resolution tool from parsing the symbol to be jumped according to the symbol resolution instruction, and use it as the code location result.
[0150] According to an embodiment of this disclosure, the first determining module 720 includes an extraction submodule and a first determining submodule.
[0151] Extract submodules are used to extract at least one candidate symbol contained in the starting code snippet, wherein the candidate symbol includes at least one of the following: function call symbol, method call symbol, instantiation symbol, property access symbol, import name symbol, decorator symbol, exception type symbol, inheritance parent class symbol, and configuration item symbol.
[0152] The first determination submodule is used to determine candidate symbols related to the problem description information from at least one candidate symbol to obtain the symbol to be jumped to.
[0153] According to an embodiment of this disclosure, the first determining submodule includes: a determining unit.
[0154] The determining unit is used to determine the symbol to jump to from at least one candidate symbol based on the matching degree between each candidate symbol and the problem description information.
[0155] According to embodiments of this disclosure, the code locating device further includes a second acquisition module.
[0156] The second acquisition module is used to acquire the order of appearance of the symbol to be jumped to in the starting code segment.
[0157] According to an embodiment of this disclosure, the generation module 730 is further configured to generate a symbol resolution instruction according to a preset instruction format based on the symbol to be jumped, the file path corresponding to the starting code segment, and the occurrence order identifier of the symbol to be jumped.
[0158] According to embodiments of this disclosure, the code locating device further includes a third determining module and a parsing module.
[0159] The third determination module is used to determine the position information of the symbol to be jumped to in the starting code segment based on the file path.
[0160] The parsing module is used to parse the symbol to be jumped to based on the location information and obtain the definition code information of the symbol to be jumped to.
[0161] According to embodiments of this disclosure, the parsing module includes a second determining submodule and a parsing submodule.
[0162] The second determination submodule is used to determine the target symbol type for the symbol to be jumped to from the preset symbol types, wherein the preset symbol types include name symbols, attribute access symbols, and cross-file reference symbols.
[0163] The parsing submodule is used to parse the symbol to be jumped to based on the location information using the parsing method corresponding to the target symbol type.
[0164] According to embodiments of this disclosure, the parsing submodule includes: a first parsing unit, a second parsing unit, and a third parsing unit.
[0165] The first parsing unit is used to find the definition location of the symbol to be jumped to, starting from the scope corresponding to the location information and moving outwards along the scope chain, when the target symbol type is a named symbol.
[0166] The second parsing unit is used to find the definition location of the target symbol from the type of the target object of the target symbol based on the location information when the target symbol type is an attribute access symbol.
[0167] The third parsing unit is used to find the definition location of the symbol to be jumped to based on the position information and module dependency information when the target symbol type is a cross-file reference symbol.
[0168] According to embodiments of this disclosure, the code locating device further includes a fourth determining module.
[0169] The fourth determination module is used to determine the starting code segment as the candidate code segment corresponding to the first iteration, and iteratively execute the following sub-modules until the preset termination condition is met.
[0170] The third determination submodule is used to determine the jump symbol from the candidate code segments corresponding to the current iteration round based on the problem description information;
[0171] The generation submodule is used to generate symbol resolution instructions based on the symbol to be jumped to and the file path of the candidate code segment to which the symbol to be jumped belongs;
[0172] The fourth determination submodule is used to send symbol resolution instructions to the symbol resolution tool, and in response to the symbol resolution tool resolving the definition code information obtained by resolving the symbol to be jumped according to the symbol resolution instructions, determine the candidate code fragments for the next iteration.
[0173] According to embodiments of this disclosure, the defined code information includes the defined code snippets.
[0174] According to embodiments of this disclosure, the code location device further includes a fifth determining module and a sixth determining module.
[0175] The fifth determination module is used to determine the correlation between the problem description information and the definition code fragments obtained in each iteration.
[0176] The sixth determination module is used to determine the defined code segments whose relevance is greater than or equal to a preset threshold from each defined code segment, and obtain the code location result.
[0177] According to embodiments of this disclosure, the preset termination condition includes at least one of the following:
[0178] The definition code snippet obtained in the current iteration has a relevance greater than the relevance threshold to the problem description information;
[0179] There are no unresolved symbols in the candidate code snippet corresponding to the current iteration round;
[0180] The preset number of iterations has been reached;
[0181] The remaining capacity of the context window is less than the preset capacity threshold.
[0182] The modules described above can be deployed in IDE plugins, local code indexing services, cloud-based code intelligence platforms, or enterprise private development platforms. The deployment method can be flexibly selected based on the specific application scenario.
[0183] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0184] According to an embodiment of the present disclosure, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method described above.
[0185] According to embodiments of the present disclosure, a non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions are used to cause a computer to perform the method described above.
[0186] According to an embodiment of this disclosure, a computer program product includes a computer program that, when executed by a processor, implements the method described above.
[0187] Figure 8A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0188] like Figure 8 As shown, device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 802 or a computer program loaded from storage unit 808 into random access memory (RAM) 803. RAM 803 may also store various programs and data required for the operation of device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via bus 804. Input / output (I / O) interface 805 is also connected to bus 804.
[0189] Multiple components in device 800 are connected to input / output (I / O) interface 805, including: input unit 806, such as a keyboard, mouse, etc.; output unit 807, such as various types of displays, speakers, etc.; storage unit 808, such as a disk, optical disk, etc.; and communication unit 809, such as a network card, modem, wireless transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0190] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as the code location method. For example, in some embodiments, the code location method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the code location method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the code location method by any other suitable means (e.g., by means of firmware).
[0191] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0192] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0193] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0194] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0195] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0196] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, distributed system servers, or servers incorporating blockchain technology.
[0197] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0198] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A code location method, comprising: Obtain a code location request, wherein the code location request includes problem description information, starting code snippet, and the file path of the starting code snippet in the code repository; Based on the problem description information, determine the symbol to jump to from the starting code segment; Based on the file path of the symbol to be jumped to and the starting code segment, generate a symbol resolution instruction according to a preset instruction format, and send the symbol resolution instruction to the symbol resolution tool; and The symbol resolution tool receives the definition code information obtained by parsing the symbol to be jumped to according to the symbol resolution instruction, and uses it as the code location result.
2. The method according to claim 1, wherein, The step of determining the jump symbol from the starting code segment based on the problem description information includes: Extract at least one candidate symbol contained in the starting code snippet, wherein the candidate symbol includes at least one of the following: function call symbol, method call symbol, instantiation symbol, property access symbol, import name symbol, decorator symbol, exception type symbol, inheritance symbol, and configuration item symbol; The candidate symbol related to the problem description information is determined from the at least one candidate symbol to obtain the symbol to be jumped to.
3. The method according to claim 2, wherein, The step of determining the candidate symbol related to the problem description information from the at least one candidate symbol to obtain the symbol to be jumped to includes: The symbol to be jumped to is determined from the at least one candidate symbol based on the degree of matching between each candidate symbol and the problem description information.
4. The method according to any one of claims 1 to 3, further comprising: Obtain the order of appearance of the symbol to be jumped to in the starting code segment; The step of generating symbol resolution instructions according to a preset instruction format based on the file path corresponding to the symbol to be jumped to and the starting code fragment includes: Based on the symbol to be jumped to, the file path corresponding to the starting code segment, and the order of appearance of the symbol to be jumped to, a symbol resolution instruction is generated according to a preset instruction format.
5. The method according to any one of claims 1 to 4, wherein, The symbol parsing tool parses the symbol to be jumped to according to the symbol parsing instructions, including: Based on the file path, determine the position information of the symbol to be jumped to within the starting code segment; and Based on the location information, the symbol to be jumped to is parsed to obtain the definition code information of the symbol to be jumped to.
6. The method according to claim 5, wherein, The step of parsing the symbol to be redirected based on the location information includes: The target symbol type for the symbol to be jumped to is determined from a preset symbol type, wherein the preset symbol types include name symbols, attribute access symbols, and cross-file reference symbols; and The target symbol type is parsed using the parsing method corresponding to it, based on the location information.
7. The method according to claim 6, wherein, The step of parsing the symbol to be jumped to based on the location information using the parsing method corresponding to the target symbol type includes: When the target symbol type is a named symbol, starting from the scope corresponding to the location information, the definition location of the symbol to be jumped to is found layer by layer along the scope chain to the outer scope; When the target symbol type is an attribute access symbol, the definition location of the symbol to be jumped to is found from the type of the target object of the symbol to be jumped to based on the location information; When the target symbol type is a cross-file reference symbol, the definition location of the symbol to be jumped to is found based on the location information and the module dependency information.
8. The method according to any one of claims 1 to 7, further comprising: The starting code segment is determined as the candidate code segment for the first iteration, and the following operations are performed iteratively until a preset termination condition is met: Based on the problem description information, determine the jump symbol from the candidate code snippets corresponding to the current iteration round; Generate symbol resolution instructions based on the symbol to be jumped to and the file path of the candidate code segment to which the symbol to be jumped belongs; The symbol resolution instruction is sent to the symbol resolution tool, and in response to the symbol resolution tool resolving the definition code information obtained by resolving the symbol to be jumped according to the symbol resolution instruction, the candidate code segment for the next iteration is determined.
9. The method according to claim 8, wherein, The defined code information includes defined code snippets; The method further includes: Determine the correlation between the problem description information and the definition code snippets obtained in each iteration round; From each of the defined code snippets, identify the code snippets with a relevance greater than or equal to a preset threshold to obtain the code location result.
10. The method according to claim 9, wherein, The preset termination condition includes at least one of the following: The definition code snippet obtained in the current iteration has a correlation greater than the problem description information; There are no unresolved symbols in the candidate code snippet corresponding to the current iteration round; The preset number of iterations has been reached; The remaining capacity of the context window is less than the preset capacity threshold.
11. A code locating device, comprising: The first acquisition module is used to acquire a code location request, wherein the code location request includes problem description information, starting code snippet, and the file path of the starting code snippet in the code repository; The first determining module is used to determine the symbol to jump to from the starting code segment based on the problem description information; The generation module is used to generate a symbol resolution instruction according to a preset instruction format based on the file path of the symbol to be jumped to and the starting code fragment, and send the symbol resolution instruction to the symbol resolution tool; The second determining module is used to receive the definition code information obtained by the symbol parsing tool from parsing the symbol to be jumped according to the symbol parsing instruction, as the code location result.
12. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method of any one of claims 1-10.
13. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-10.
14. A computer program product comprising a computer program stored on at least one of a readable storage medium and an electronic device, the computer program implementing the method according to any one of claims 1-10 when executed by a processor.
