Code searching method, device and system
Through the language service protocol LSP, a cross-programming language code search method is implemented, which solves the problem of missing code jumps and reference search services in multiple programming language environments, improves code reading efficiency, and simplifies cross-language service adaptation.
Patent Information
- Application Number
- CN202310384330.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-07
- Publication Date
- 2024-10-15
AI Technical Summary
In a development environment with multiple programming languages, existing technology cannot provide cross-programming language code jump and reference search services, affecting the efficiency of developers in reading code.
By using the language service protocol LSP, a cross-programming language code search method is implemented, including the first device sending a request to the service device of the second programming language, receiving a response, and determining whether the search in the second programming language file is consistent with the search in the first programming language file. The location associated with the code supports jumps and reference lookups across programming languages.
It improves code reading efficiency, realizes universal service capabilities across programming languages, solves the problem of strong platform binding, and simplifies the rapid adaptation of cross-language services for multiple languages and multiple compilers.
Smart Images

Figure CN118778933A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device and system for searching for a code. Background Art
[0002] For developers, reading code is one of their jobs. In a single programming language development environment, most programming languages support code jumps and reference searches, which can quickly read the code. However, in a multi-programming language development environment, most integrated development environments (IDEs) cannot provide cross-programming language services, such as code jumps and reference searches across programming languages, which greatly affects the efficiency of developers in reading code. Summary of the invention
[0003] The present application provides a method, device and system for searching codes, which can support cross-programming language services, thereby improving the efficiency of reading codes.
[0004] In order to achieve the above objectives, this application adopts the following technical solutions:
[0005] In a first aspect, a method for searching for code is provided, which is applied to a first device. The method can be executed by the first device, or by a component of the first device, such as a processor, a chip, or a chip system of the first device, or by a logic module or software that can realize all or part of the functions of the first device. The method includes: the first device determines to search for code associated with a first function in a first programming language file from a second programming language file, the first device sends a first request to a service device of the second programming language through a first protocol, and the first device receives a first response from the service device of the second programming language through the first protocol. The second programming language file and the first programming language file are files of different programming languages. The first protocol is related to the language service protocol LSP, and the first request includes: the name of the first function and search information, and the search information includes searching for code associated with the code in the first programming language file from the second programming language file. The first response includes first information, and the first information indicates the location of the code associated with the first function.
[0006] Based on the method provided in the first aspect, the first device interacts with the service device of the second programming language through the first protocol, sends the name of the first function and search information to the service device of the second programming language, and receives the first information. The search information includes searching for code associated with the code in the first programming language file from the second programming language file, and the first information indicates the location of the code associated with the first function, which can realize cross-programming language services, thereby improving code reading efficiency.
[0007] In a possible design, the first protocol includes a name field, a search field, and a location field, wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
[0008] Optionally, the first protocol may be called a cross-programming language jump protocol or a cross-programming language reference lookup protocol.
[0009] In a possible design, the above determination to search for the code associated with the first function in the first programming language file from the second programming language file includes: determining to search for the function called by the first function from the second programming language file. The first information includes the location of the second function, and the second function is the function in the second programming language file called by the first function. For example, the first programming language is the eTS programming language, and the second programming language is the C++ programming language. In this way, cross-programming language jumps can be achieved.
[0010] In a possible design, determining to search for code associated with a first function in a first programming language file from a second programming language file includes: determining to search for a function that references the first function from the second programming language file. The first information includes a location of a third function, and the third function is a function that references the first function in the second programming language file. For example, the first programming language is the C++ programming language, and the second programming language is the eTS programming language. In this way, cross-programming language reference search can be implemented.
[0011] In a possible design, the first information is determined based on the name of the first function, the search information and a first mapping relationship, where the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
[0012] In a possible design, the first device determines to search for code associated with a first function in a first programming language file from a second programming language file, including: the first device detects a code search instruction. The code search instruction is used to indicate a search for code associated with the first function. The first device sends first location information to a service device of the first programming language. The first location information is used to indicate a location of the first function in the first programming language file. The first device receives first indication information from the service device of the first programming language. The first indication information is used to indicate a search for code associated with the first function in the first programming language file from the second programming language file.
[0013] In a possible design, a first device includes a first programming language client plug-in and a second programming language client plug-in, and the first device detects a code search instruction, including: the first programming language client plug-in of the first device detects the code search instruction. Before the first device sends a first request to a service device of the second programming language through a first protocol, the method provided in the first aspect also includes: the first programming language client plug-in of the first device sends a name of a first function to the second programming language client plug-in of the first device.
[0014] In this way, different client plug-ins can interact through jump interfaces or communication protocols between different programming languages, thereby supporting cross-programming language services.
[0015] In a second aspect, a method for searching for code is provided, which is applied to a service device of a second programming language. The method can be executed by a service device of the second programming language, or by a component of the service device of the second programming language, such as a processor, a chip, or a chip system of the service device of the second programming language, or can be implemented by a logic module or software that can implement all or part of the functions of the service device of the second programming language. The method includes: a service device of the second programming language receives a first request from a first device through a first protocol, and the service device of the second programming language sends a first response to the first device through the first protocol. The first protocol is related to the language service protocol LSP, and the first request includes: the name of the first function and search information, and the search information includes searching for code associated with the code in the first programming language file from the second programming language file. The first response includes first information, and the first information indicates the location of the code associated with the first function.
[0016] In a possible design, the first protocol includes a name field, a search field, and a location field, wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
[0017] In one possible design, searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function called by the first function, the first information includes the location of the second function, and the second function is a function in the second programming language file called by the first function.
[0018] In one possible design, searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function that references the first function, the first information includes the location of a third function, and the third function is the function in the second programming language file that references the first function.
[0019] In a possible design, the first information is determined based on the name of the first function, the search information and a first mapping relationship, where the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
[0020] In addition, the technical effects of the method described in the second aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.
[0021] In a third aspect, a method for searching for code is provided, which is applied to a service device of a first programming language. The method can be executed by the service device of the first programming language, or by a component of the service device of the first programming language, such as a processor, a chip, or a chip system of the service device of the first programming language, or by a logic module or software that can implement all or part of the functions of the service device of the first programming language. The method includes: the service device of the first programming language receives first location information from the first device, and the service device of the first programming language sends first indication information to the first device. The first location information is used to indicate the location of the first function in the first programming language file, and the first indication information is used to indicate to search for code associated with the first function in the first programming language file from the second programming language file.
[0022] In addition, the technical effects of the method described in the third aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.
[0023] In a fourth aspect, a first device is provided, comprising: a processing unit, a sending unit and a receiving unit.
[0024] The processing unit is used to determine to search for code associated with the first function in the first programming language file from the second programming language file. The sending unit is used to send a first request to the service device of the second programming language through the first protocol. The receiving unit is also used to receive a first response from the service device of the second programming language through the first protocol. The second programming language file and the first programming language file are files of different programming languages. The first protocol is related to the language service protocol LSP, and the first request includes: the name of the first function and search information, and the search information includes searching for code associated with the code in the first programming language file from the second programming language file. The first response includes first information, and the first information indicates the location of the code associated with the first function.
[0025] In a possible design, the first protocol includes a name field, a search field, and a location field, wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
[0026] Optionally, the first protocol may be called a cross-programming language jump protocol or a cross-programming language reference lookup protocol.
[0027] In a possible design, the processing unit is further used to determine the function called by the first function from the second programming language file. The first information includes the location of the second function, and the second function is a function in the second programming language file called by the first function. For example, the first programming language is the eTS programming language, and the second programming language is the C++ programming language.
[0028] In a possible design, the processing unit is further used to determine to search for a function that references the first function from a second programming language file. The first information includes the location of a third function, and the third function is a function that references the first function in the second programming language file. For example, the first programming language is the C++ programming language, and the second programming language is the eTS programming language. In a possible design, the first information is determined based on the name of the first function, the search information, and the first mapping relationship, and the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
[0029] In a possible design, the processing unit is further used to detect a code search instruction. The code search instruction is used to instruct to search for code associated with a first function. The sending unit is further used to send first location information to a service device of a first programming language. The first location information is used to indicate the location of the first function in a file of the first programming language. The receiving unit is further used to receive first indication information from the service device of the first programming language. The first indication information is used to instruct to search for code associated with the first function in a file of the first programming language from a file of a second programming language.
[0030] In a possible design, the processing unit includes a first programming language client plug-in and a second programming language client plug-in, wherein the first programming language client plug-in of the first device is used to detect the search code instruction and the first programming language client plug-in of the first device is also used to send the name of the first function to the second programming language client plug-in of the first device.
[0031] It should be noted that the receiving unit and the sending unit can be integrated into one module, namely, a transceiver unit, or can be separately provided. The present application does not specifically limit the specific implementation of the receiving unit and the sending unit.
[0032] Optionally, the first device described in the fourth aspect may further include a storage unit, wherein the storage unit stores a program or an instruction. When the processing unit executes the program or the instruction, the first device described in the fourth aspect may execute the method described in the first aspect.
[0033] It should be noted that the first device described in the fourth aspect may be a computer, etc., or may be a chip (system) or other parts or components that can be set in a computer or other device, and this application does not limit this.
[0034] In addition, the technical effects of the first device described in the fourth aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.
[0035] In a fifth aspect, a second device is provided, and the second device includes: a sending unit and a receiving unit.
[0036] The receiving unit is used to receive a first request from the first device through the first protocol. The sending unit is used to send a first response to the first device through the first protocol. The first protocol is related to the language service protocol LSP, and the first request includes: the name of the first function and search information, and the search information includes searching for code associated with the code in the first programming language file from the second programming language file. The first response includes first information, and the first information indicates the location of the code associated with the first function.
[0037] In a possible design, the first protocol includes a name field, a search field, and a location field, wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
[0038] In one possible design, searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function called by the first function, the first information includes the location of the second function, and the second function is a function in the second programming language file called by the first function.
[0039] In one possible design, searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function that references the first function, the first information includes the location of a third function, and the third function is the function in the second programming language file that references the first function.
[0040] In a possible design, the first information is determined based on the name of the first function, the search information and a first mapping relationship, where the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
[0041] It should be noted that the receiving unit and the sending unit can be integrated into one module, namely, a transceiver unit, or can be separately provided. The present application does not specifically limit the specific implementation of the receiving unit and the sending unit.
[0042] Optionally, the second device described in the fifth aspect may further include a storage unit, wherein the storage unit stores a program or an instruction. When the processing unit executes the program or the instruction, the second device described in the fifth aspect may execute the method described in the first aspect.
[0043] It should be noted that the second device described in the fifth aspect can be a server or a second server of a second programming language, or it can be a chip (system) or other parts or components that can be set on a server or a second server of a second programming language, etc. This application does not limit this.
[0044] In addition, the technical effects of the second device described in the fifth aspect can refer to the technical effects of the method described in any possible implementation method in the first aspect, and will not be repeated here.
[0045] In a sixth aspect, a server of a first programming language is provided, and the server of a second programming language includes: a sending unit and a receiving unit.
[0046] The receiving unit is used to receive first location information from the first device. The sending unit is used for the service device of the first programming language to send first indication information to the first device. The first location information is used to indicate the location of the first function in the first programming language file, and the first indication information is used to indicate to search for code associated with the first function in the first programming language file from the second programming language file.
[0047] It should be noted that the receiving unit and the sending unit can be integrated into one module, namely, a transceiver unit, or can be separately provided. The present application does not specifically limit the specific implementation of the receiving unit and the sending unit.
[0048] Optionally, the server of the first programming language described in the sixth aspect may further include a storage unit, wherein the storage unit stores a program or instruction. When the processing unit executes the program or instruction, the server of the first programming language described in the sixth aspect may execute the method described in the first aspect.
[0049] It should be noted that the server of the first programming language described in the sixth aspect can be the first server, etc., or it can be a chip (system) or other parts or components that can be set on the first server and other devices. This application does not limit this.
[0050] In addition, the technical effects of the server of the first programming language described in the sixth aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.
[0051] In a seventh aspect, a first device is provided, the first device comprising: one or more processors; one or more memories; the memories storing one or more programs, when the one or more programs are executed by the one or more processors, the first device executes the method in any possible implementation manner of the first aspect. Optionally, the first device may also include a display screen.
[0052] In an eighth aspect, a second device is provided, comprising: one or more processors; one or more memories; the memories storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the second device executes a method as in any possible implementation of the first aspect.
[0053] In a ninth aspect, a server of a first programming language is provided, the server of the first programming language comprising: one or more processors; one or more memories; the memories storing one or more programs, and when the one or more programs are executed by the one or more processors, the server of the first programming language executes a method as in any possible implementation of the first aspect.
[0054] In a tenth aspect, an embodiment of the present application provides a circuit system, the circuit system includes a processing circuit, and the processing circuit is configured to execute a method as in any one of the implementations in the first aspect.
[0055] In an eleventh aspect, a communication system is provided, the communication system comprising the first device as described in the first aspect, and the first device as described in the second aspect, and may further comprise a server of the first programming language as described in the third aspect. Alternatively, the communication system comprises the first device as described in the fourth aspect for implementing the method as described in the first aspect, and the second device as described in the fifth aspect for implementing the method as described in the second aspect, and may further comprise a server of the first programming language for implementing the method as described in the third aspect as described in the sixth aspect.
[0056] In a twelfth aspect, a readable storage medium is provided, which includes a program. When the program is run on a device, the device executes a method in any possible implementation manner of the first to third aspects.
[0057] In a thirteenth aspect, a chip system is provided, the chip system includes a processor and a memory, wherein a program is stored in the memory; when the program is executed by the processor, the processor implements the method in any possible implementation of the first to third aspects. The chip system may be composed of a chip, or may include a chip and other discrete devices.
[0058] In a fourteenth aspect, a program product is provided. When the program product is run on a computer or a device, the computer or the device implements the method in any possible implementation manner of the first to third aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1A A schematic diagram of a scenario provided for an embodiment of the present application;
[0060] Figure 1B A schematic diagram of a scenario provided for an embodiment of the present application;
[0061] Figure 1C A schematic diagram of a scenario provided for an embodiment of the present application;
[0062] Figure 1D A schematic diagram of a scenario provided for an embodiment of the present application;
[0063] Figure 1E A schematic diagram of a communication system provided in an embodiment of the present application;
[0064] Figure 2 A schematic diagram of the hardware structure of a first device and a second device provided in an embodiment of the present application;
[0065] Figure 3 A schematic diagram of the software structure of a first device and a second device provided in an embodiment of the present application;
[0066] Figure 4 A flowchart of a method for searching a code provided in an embodiment of the present application;
[0067] Figure 5-6B Some schematic diagrams of scenarios provided for embodiments of the present application;
[0068] Figure 7 A flowchart of another method for searching codes provided in an embodiment of the present application;
[0069] Figure 8 A schematic diagram of a scenario provided for an embodiment of the present application;
[0070] Fig. 9 A flowchart of another method for searching codes provided in an embodiment of the present application;
[0071] Fig.10 A schematic diagram of the structure of a device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0072] The technical solutions in the embodiments of the present application are described below in conjunction with the accompanying drawings in the embodiments of the present application. Wherein, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to include expressions such as "one or more", unless there is a clear indication to the contrary in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two).
[0073] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise specified. "First" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.
[0074] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0075] In some embodiments, the development language of the IDE or editor can be used to implement the language compiler front-end functions (scanner, analyzer, type checking, etc.) and provide language service capabilities. Specifically, the mapping relationship between different programming language functions can be combined to implement cross-language service functions on the IDE platform.
[0076] Exemplarily, the Android Studio editor can implement the language service function between Java and C++ on the Intellij platform through the program structure interface (PSI) provided by the Intellij platform, combined with the mapping relationship between Java and C++ and the Intellij platform plug-in, where PSI is mainly responsible for parsing files, creating grammatical and semantic codes, etc.
[0077] For example, the mapping relationship between Java and C++ includes the corresponding relationship between at least one Java function and at least one C++ function. For example, the Java function: package name + class name + function name corresponds to the C++ function: Java_package name_class name_function name. Among them, the package name, class name and function name in the C++ function are the package name of the Java function, the class name of the Java function and the function name of the Java function respectively.
[0078] like Figure 1A As shown in the figure, in the Java programming language, the package name of the function stringFromJNI() is com_example_nativeLib, and the class name is NativeLib. In the C++ programming language, the C++ function corresponding to the Java function stringFromJNI() is Java_com_example_nativeLib_NativeLib_stringFromJNI(), see Figure 1A Line 7 of the nativeLib.cpp file. The C++ programming language file includes the correspondence between Java functions and C++ functions. For example, the C++ function Java_com_example_nativeLib_NativeLib_stringFromJNI() can indicate the corresponding Java function.
[0079] The cross-language service function between Java and C++ implemented by the above Android Studio editor needs to be strongly bound to the Intellij platform and implemented through the Intellij platform plug-in. If you change to a non-Intellij editor, such as the VSCode editor, you need to re-adapt it, the switching cost is high, and it is not universal.
[0080] In addition, using the above mapping relationship to implement the language service function between Java and C++ may result in some function name errors. Figure 1BAs shown in the figure, the function Java_com_example_T_stringFromJNI() in the C++ file will be recognized as a method with a corresponding Java function. Since the class name T is not defined in the Java file, the function Java_com_example_T_stringFromJNI() in the C++ file reports an error, that is, the JNI function call may be using an incorrect linkage.
[0081] In some embodiments, mainstream IDEs (such as VSCode / Vim / Eclipse) all build language service capabilities based on the language server protocol (LSP). LSP has strong versatility. In a single programming language development environment, IDE can implement language service functions based on LSP. However, in a multi-programming language development environment, LSP cannot support cross-programming language services.
[0082] Exemplarily, LSP defines a protocol used between an editor or IDE and a language server, which is used to provide language functions such as auto-completion, go to definition, and find all references. Figure 1C As shown in (a), under the LSP declaration, if there are m editors, each supporting n programming languages, when both the editor and the programming language support LSP, only m+n development times are required. The language service capability is provided by the language server, which can be reused on different IDEs and has universality, but does not support cross-programming language services. Figure 1C As shown in (b), in the non-LSP (NO LSP) scenario, the language compiler front-end function is implemented using the development language of the IDE or editor. The language service capability is provided by the plug-in, and the function needs to be re-implemented on different IDEs. If there are m editors, each supporting n programming languages, m*n development times are required.
[0083] based on Figure 1C In the methods shown in (a) and (b), the IDE can only implement single programming language service functions based on LSP, and does not support cross-programming language services. There is no communication between different programming languages, such as Figure 1D As shown, it is impossible to support services across programming languages.
[0084] For example, Figure 1E A schematic diagram of a communication system to which a method for searching for a code is applied according to an embodiment of the present application.
[0085] The method for searching for a code provided in an embodiment of the present application is applied to a communication system. The communication system includes a first device and at least two second devices, such as a first server and a second server. Figure 1E shown.
[0086] The first device may be a computer, a tablet computer, a laptop computer, a host or other product forms, which are not specifically limited. The second device may be a server of a programming language, for example, the first server is a server of a first programming language, and the second server is a server of a second programming language, and the first programming language is different from the second programming language. The embodiments of the present application do not impose any special restrictions on the specific forms of the first device and the second device. The operating systems installed on the first device and the second device include but are not limited to Or other operating systems. This application does not limit the specific types of the first device and the second device, or the installed operating systems.
[0087] Optionally, the first device and the second device may establish a wired connection or a wireless communication connection via a local area network. Optionally, the first device and the second device may also establish a communication connection via a third-party device in the local area network, such as a router, a gateway, a wireless access point (AP) device, etc.
[0088] Optionally, the first device and at least two second devices in the communication system can be deployed in the same device, or some devices can be deployed in the same device, for example, the first device and the first server and the second server can be deployed in the same device, or any two of the first device, the first server and the second server can be deployed in the same device.
[0089] It should be noted that the method provided in the embodiment of the present application can be applied to Figure 1E In the communication system or network architecture shown, the specific implementation can refer to the following method embodiment, which will not be repeated here.
[0090] It should be understood that Figure 1E This is a simplified schematic diagram for ease of understanding only. The communication system or network architecture may also include other network devices. Figure 1E Not drawn in.
[0091] For example, Figure 2 A schematic diagram of the hardware structure of a first device and a second device provided in an embodiment of the present application.
[0092] The first device includes one or more processors 201. Optionally, the first device may also include a communication line 202 and at least one communication interface ( Figure 2The description is merely illustrative, taking as an example a communication interface 204 and a processor 201), and / or a memory 203.
[0093] The second device includes one or more processors 201. Optionally, the second device may also include a communication line 202 and at least one communication interface ( Figure 2 The description is merely illustrative, taking as an example a communication interface 204 and a processor 201), and / or a memory 203.
[0094] The processor 201 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0095] The communication line 202 may include a path for connecting different components.
[0096] The communication interface 204 may be a transceiver module for communicating with other devices or communication networks, such as Ethernet, wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), RDMA networks and other wireless communications. For example, the transceiver module may be a device such as a transceiver or a transceiver. Optionally, the communication interface 204 may also be a transceiver circuit located in the processor 201 to implement signal input and signal output of the processor.
[0097] The memory 203 may be a device with a storage function. For example, it may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line 202. The memory may also be integrated with the processor.
[0098] The memory 203 is used to store computer-executable instructions for executing the solution of the present application, and the execution is controlled by the processor 201. The processor 201 is used to execute the computer-executable instructions stored in the memory 203, thereby implementing the method provided in the embodiment of the present application.
[0099] Alternatively, in the embodiment of the present application, the processor 201 may also perform functions related to the processing of the method provided in the following embodiments of the present application, and the communication interface 204 is responsible for communicating with other devices or communication networks, which is not specifically limited in the embodiment of the present application.
[0100] Optionally, the memory 203 in the embodiment of the present application may also be used to store information or parameters described in the following embodiments.
[0101] The computer-executable instructions in the embodiments of the present application may also be referred to as application program codes, which is not specifically limited in the embodiments of the present application.
[0102] In a specific implementation, as an embodiment, the processor 201 may include one or more CPUs, such as Figure 2 CPU0 and CPU1 in.
[0103] In a specific implementation, as an embodiment, the coordination node and the data node may include multiple processors, such as Figure 2201 and processor 207 in the embodiment of the present invention. Each of these processors may be a single-CPU processor or a multi-CPU processor. The processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0104] In a specific implementation, as an embodiment, the coordination node and the data node may further include an output device 205 and an input device 206. The output device 205 communicates with the processor 201 and may display information in a variety of ways.
[0105] It can be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the structure and form of the coordination node and the data node, and the embodiment of the present application does not limit the structure and form of the coordination node and the data node.
[0106] In other embodiments of the present application, the coordination node and the data node may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0107] in addition, Figure 2 The interface connection relationship between the modules shown is only a schematic illustration and does not constitute a structural limitation on the coordination node and the data node. Figure 2 Different interface connection methods, or a combination of multiple interface connection methods.
[0108] Exemplarily, the software architecture of the first device and the second device may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture, etc. Figure 3 A schematic diagram of the software structure of a first device and a second device provided in an embodiment of the present application is shown. Figure 3 In the example, a communication system includes two second devices, such as a first server and a second server.
[0109] The solution provided in this application can be applied to Figure 3 In the IDE 300 shown in FIG. 1 , the IDE 300 can be deployed in Figure 1E on the first device shown. Figure 3 The illustrated IDE 300 includes but is not limited to the following one or more software modules: a first client plug-in 301 and a second client plug-in 302 , a first server including but not limited to an auxiliary module 303 , and a first server including but not limited to an auxiliary module 304 .
[0110] Exemplarily, IDE 300 is used to provide tools such as a code editor, a compiler, a debugger, and a graphical user interface.
[0111] Exemplarily, the first client plug-in 301 is a client of a first programming language, used to communicate with the first server based on the LSP extended protocol, and used to interact with the second client plug-in 302 based on the LSP extended protocol.
[0112] Exemplarily, the second client plug-in 302 is a client of a second programming language, used for communicating with the second server based on the LSP extended protocol, and used for interacting with the first client plug-in 301 based on the LSP extended protocol.
[0113] Optionally, IDE300 may include three or more client plug-ins. Figure 3 Two client plug-ins are used as an example, and three or more client plug-ins can interact with each other, for example, based on the LSP extension protocol.
[0114] Optionally, the first client plug-in 301 and the second client plug-in 302 may be deployed in an extension module. The IDE 300 includes an extension module, such as an extension host, which is used to provide a running environment for the plug-in.
[0115] Exemplarily, the first server is a server of a first programming language, and the auxiliary module 303 in the first server is used to communicate with the first client plug-in 301 based on the LSP extended protocol.
[0116] Exemplarily, the second server is a server of a second programming language, and the auxiliary module 304 in the second server is used to communicate with the second client plug-in 302 based on the LSP extended protocol.
[0117] For example, the LSP extension protocol may be a cross-programming language jump protocol or a cross-programming language reference search protocol.
[0118] Understandably, Figure 3 The software modules included in the first device, the first server, and the second server shown are only used as a possible division method. They may also include more or fewer modules, or there may be other division methods, which are not limited in this application.
[0119] The technical solutions involved in the following embodiments can all be implemented in Figure 2 and / or Figure 3 The invention is implemented in the device of the structure shown.
[0120] It is understandable that in the embodiment of the present application, the first device or the second device can perform some or all of the steps in the embodiment of the present application, and these steps or operations are only examples. The embodiment of the present application can also perform other operations or variations of various operations. In addition, the various steps can be performed in different orders presented in the embodiment of the present application, and it is possible that not all operations in the embodiment of the present application need to be performed.
[0121] The method provided in the embodiment of the present application is described below by taking a communication system including a first device and two second devices (such as a first server and a second server) as an example.
[0122] The following will be combined Figure 4-Figure 8 The method for searching codes provided in the embodiments of the present application is described in detail.
[0123] For example, Figure 4 A flowchart of a method for searching for codes provided in an embodiment of the present application. Figure 4 The method shown describes code jumps between different programming languages. The method provided in this application is applicable to code jumps between two or more programming languages. Figure 4 The method shown is explained using the example of code jump between two programming languages.
[0124] Figure 4 The first client plug-in is a client plug-in of a first programming language, the first server is a server of the first programming language, the second client plug-in is a client plug-in of a second programming language, the second server is a server of the second programming language, and the language in this application refers to a programming language. Figure 4 The method shown uses the cross-language jump between the first programming language and the second programming language as an example to illustrate the method process provided by the present application. For example, the user wants to view the underlying implementation of the first function in the first programming language file, and the underlying implementation of the first function is in the second programming language file.
[0125] like Figure 4 As shown, the method includes the following steps.
[0126] S401: A first client plug-in of a first device sends first location information to a first server.
[0127] Exemplarily, the first location information is used to indicate the location of the first function in the first programming language file. For example, the location information of the first function includes but is not limited to one or more of the following: the package name where the first function is located, the class name where the first function is located, the module name where the first function is located, and / or the line where the first function is located.
[0128] In the present application, the package name where the first function is located refers to the name of the package where the first function is located, the class name where the first function is located refers to the name of the class where the first function is located, and the module name where the first function is located refers to the name of the module where the first function is located.
[0129] Optionally, the above S401 includes: after the first device detects the first operation, the first client plug-in of the first device sends the first location information to the first server.
[0130] For example, the first operation may be a jump operation performed by the user based on the first function.
[0131] Assume that the first programming language is the eTS programming language and the second programming language is the C++ programming language. Figure 5 In this article, we take the cross-language code jump between eTS and C++ in the DevEcoStudio editor as an example. Figure 5 , assuming that the first function is the testNapi.add() function, if the user wants to find the corresponding function in the C++ file from the testNapi.add() function in the eTS file, the first operation can be that the user clicks Go To in the right-click menu of the testNapi.add() function, and then clicks Implementation. Alternatively, the first operation can be a jump operation performed by the user on the testNapi.add() function using a shortcut key.
[0132] Combination Figure 5 After detecting the first operation, the first device sends the location information of the testNapi.add() function to the first server, such as line 17.
[0133] S402: The first server sends a cross-language calling flag to a first client plug-in of the first device according to the first location information.
[0134] Optionally, the above S402 may include: the first server determines whether the first function is a cross-programming language calling function according to the first location information, and if the first function is a cross-programming language calling function, sends a cross-language calling flag to the first client plug-in of the first device.
[0135] For example, the first function is a cross-programming language calling function, which means that the first function in a first programming language file calls a function in another programming language file, or the source code of the first function is in a second programming language file.
[0136] Exemplarily, the first server obtains the package name of the first function according to the first location information, and determines whether the first function is a cross-programming language calling function according to the package name constraint. Optionally, if the location information of the first function is the row where the first function is located, the first server can determine the package name of the first function according to the row where the first function is located.
[0137] Combination Figure 5 The first server obtains the package name of the testNapi.add() function as libentry based on the location information of the testNapi.add() function, and determines that the source code of the testNapi.add() function used in the eTS programming language is in the C++ programming language file based on the package name constraint .so, and then determines that testNapi.add(2,3) is a cross-programming language calling function, which is only an example.
[0138] Or, optionally, the first server may determine whether the first function is a cross-programming language calling function according to a configuration file of a package where the first function is located, where the configuration file includes the type of package.
[0139] S403: The first client plug-in of the first device sends information of the first function to the second client plug-in of the first device.
[0140] Exemplarily, the information of the first function includes one or more of the following: the function name of the first function, the class name where the first function is located, the module name where the first function is located, and the package name where the first function is located. For different programming languages, the content included in the information of the first function may be different.
[0141] Optionally, S403 may include: the first client plug-in of the first device sends the information of the first function to the second client plug-in of the first device through a jump interface or a communication protocol between different programming languages (for example, a protocol obtained based on LSP). The jump interface is used for interaction between the first client plug-in of the first device and the second client plug-in of the first device. In this way, different client plug-ins can interact through the jump interface or the communication protocol between different programming languages, thereby supporting cross-programming language services.
[0142] S404: The second client plug-in of the first device sends a first cross-language jump request to the second server.
[0143] Exemplarily, the first cross-language jump request is used to request a function called by the first function.
[0144] Exemplarily, the first cross-language jump request includes: the name of the first function and information about the cross-language jump strategy, and may also include one or more of the following: the class name where the first function is located, the module name where the first function is located, and the package name where the first function is located.
[0145] For example, the information of the cross-language jump strategy may include an identifier of the cross-language jump strategy, and the cross-language jump strategy includes but is not limited to: the first programming language jumps to the second programming language, and the first programming language jumps to the third programming language, etc. For example, the ETS programming language jumps to the C++ programming language, the ETS programming language jumps to the Java programming language, etc. The second server may determine a corresponding jump solution according to the information of the cross-language jump strategy.
[0146] In some embodiments, S404 may include: the second client plug-in of the first device sends a first cross-language jump request to the second server through a cross-programming language jump protocol. The present application does not limit the name of the cross-programming language jump protocol.
[0147] In this way, the client plug-in of the programming language and the server of the programming language can communicate through the cross-programming language jump protocol. The cross-programming language jump protocol is obtained based on the LSP extension, which can realize general cross-language service capabilities and solve the problem of strong platform binding.
[0148] S405: The second server determines second location information according to the first cross-language jump request and the first mapping relationship.
[0149] For example, the second location information is used to indicate the location of the second function in the second programming language file, the second function is a function in the second programming language file corresponding to the first function, and the first function in the first programming language file calls the second function in the second programming language file.
[0150] For example, the location information of the second function includes, but is not limited to, one or more of the following: the package name where the second function is located, the class name where the second function is located, the module name where the second function is located, and / or the row where the second function is located.
[0151] Optionally, the first mapping relationship includes a correspondence between at least one function in the first programming language and at least one function in the second programming language.
[0152] For example, the first mapping relationship includes the correspondence between the add function in the ETS programming language file and the Add function in the C++ programming language file. The first mapping relationship provided by the present application will not cause the function name error problem.
[0153] For example, assuming that the cross-language jump strategy is to jump from the ETS programming language to the C++ programming language, the second server obtains the first mapping relationship from the C++ programming language file according to the information of the cross-language jump strategy, determines the second function according to the name of the first function and the first mapping relationship, and determines the position of the second function in the second programming language file. Optionally, the second server may also consider the class name of the first function, the module name of the first function, and / or the package name of the first function in the process of determining the second position information.
[0154] S406: The second server sends a first cross-language jump response to the second client plug-in of the first device.
[0155] Exemplarily, the first cross-language jump response includes: empty or second position information.
[0156] For example, the second server may not find the second function corresponding to the first function and may not determine the second location information, so it returns null.
[0157] Optionally, the first cross-language jump response may further include: an error code and error information, where the error information may be used to indicate the cause of the error. For example, if the second server does not support the jump from the first programming language to the second programming language and fails to determine the second location information, the error code and error information are returned.
[0158] In some embodiments, S406 may include: the second server sending a first cross-language jump response to the second client plug-in of the first device through a cross-programming language jump protocol.
[0159] In combination with S404 and S406, exemplarily, the cross-programming language jump protocol includes: a request part and a response part. Among them, the request part can be expressed as: textDocument / crossJumpDefinition(CrossLanguageJumpParams). Among them, CrossLanguageJumpParams represents the cross-language jump parameters, and textDocument / crossJumpDefinition represents the name of the cross-programming language jump protocol. The response part includes result information and may also include other information. The result information can be expressed as: null|Location|Location[]. Among them, null means empty, | means or, Location means a second location information, and Location[] means multiple second location information. Other information includes: error code and error information.
[0160] Optionally, the cross-language jump parameter in the request part may include one or more of the following: a name field, a policy field, and an extension field. The fields in the cross-language jump parameter are described below in conjunction with Table 1.
[0161] Exemplarily, the name field is used to indicate the name of the first function.
[0162] Exemplarily, the policy field is used to indicate a cross-language jump policy. For example, the policy field includes information about the cross-language jump policy, such as an identifier of the cross-language jump policy.
[0163] Exemplarily, the extension field may also be referred to as a reserved field. For example, the extension field may be an extension field of a cross-language jump strategy. The extension field may be used to add independent parameters required by each cross-language jump strategy. Different cross-language jump strategies may require different parameters. The content included in the extension field may be adjusted according to the actual cross-language jump strategy. Optionally, the class name where the first function is located, the module name where the first function is located, and / or the package name where the first function is located may be carried in the extension field of the cross-programming language jump protocol.
[0164] Table 1
[0165]
[0166]
[0167] Optionally, the location parameter (Location or Location[]) in the response part may include one or more of the following: a uniform resource identifier (URI) field, and a range field. The fields in the location parameter are described below in conjunction with Table 2.
[0168] Exemplarily, the URI field is used to indicate the URI of the second programming language file where the second function (also referred to as the target language function) is located, and may also be used to indicate the storage path of the second programming language file in the computer's external memory.
[0169] Exemplarily, the scope field is used to indicate the scope of the function name of the second function.
[0170] Table 2
[0171]
[0172] For example, taking the cross-programming language jump protocol name represented as textDocument / crossJumpDefinition as an example, combined with the description of the cross-programming language jump protocol in Table 1 and Table 2 above, the cross-programming language jump protocol obtained based on LSP can be as follows:
[0173]
[0174]
[0175] In this way, through the cross-programming language jump protocol obtained based on LSP extension, the programming language client and the programming language server can support cross-language jump, and can also solve the problem of strong binding between cross-programming language services and platforms, and can quickly migrate and adapt.
[0176] S407: The second client plug-in of the first device sends second location information to the first client plug-in of the first device.
[0177] Optionally, S407 may include: the second client plug-in of the first device sends the second location information to the first client plug-in of the first device through a jump interface or a communication protocol between different programming languages (eg, a protocol obtained based on an LSP).
[0178] Optionally, the method provided in the embodiment of the present application may further include: the interface displayed by the first device jumps from the first interface to the second interface, the first interface includes a first function, and the second interface includes a second function.
[0179] Exemplarily, the interface displayed by the first device is Figure 5 The first interface shown jumps to the interface displaying the second programming language file. In this way, the DevEco Studio editor supports the view jump function. Compared with the user viewing the underlying implementation corresponding to the function in an inefficient manual way, the code reading efficiency can be improved, and it can be quickly migrated to other IDE platforms later.
[0180] Exemplary, combined Fig. 6A and Figure 6B , explains the inefficient manual way for users to view the underlying implementation of the add function. Fig. 6A After the first device detects that the user clicks the testNapi.add() function in the eTS file, it jumps to the ets file where the definition is located and displays the following Fig. 6A The interface shown in the figure. Fig. 6A The second line of code in the interface shown imports testNapi from'libentry.so'( Fig. 6A Not shown, see Figure 5 After confirming that the testNapi.add() function is a cross-language call function, search for the function name add and set it to search only .cpp files. The search results are as follows Fig. 6A Then, in the search results (such as Fig. 6A The code starting from line 40 in the pop-up window is the search result) is manually identified in the C++ file containing the mapping relationship between eTS functions and C++ functions, such as Fig. 6AIn the search results, the user finds "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr. Based on the search results, the user manually finds line 44 in the hello.cpp file, such as Figure 6B As shown, manually confirm the mapping relationship between eTS functions and C++ functions again, for example, manually find the registered entry RegisterEntryModul, and follow Figure 6B Follow the sequence shown in the figure, and then manually jump to the C++ underlying implementation after confirming that it is correct.
[0181] In the present application, after the first device detects a jump operation performed by the user based on the first function, it can automatically jump to the second function in the second programming language file, without the need to manually search for the second function in the second programming language file, thereby improving code reading efficiency.
[0182] based on Figure 4 The method shown implements cross-language jump based on the cross-programming language jump protocol, which not only solves the problem of strong binding between cross-programming language services and platforms, but also enables cross-language interaction, realizes general cross-language service capabilities, and improves the rapid adaptation of multi-language and multi-compiler cross-language services.
[0183] For example, Figure 7 A flowchart of another method for searching codes provided in an embodiment of the present application. Figure 7 The provided method is suitable for reference search between two or more programming languages. Figure 7 The method shown is explained using the example of reference search between two programming languages.
[0184] Figure 7 The method shown uses cross-language reference search between a first programming language and a second programming language as an example to illustrate the method process provided by the present application. For example, a user wants to view the references of functions in other programming language files (programming language files other than the second programming language file) to a second function in a second programming language file.
[0185] like Figure 7 As shown, the method includes the following steps.
[0186] S701: A second client plug-in of a first device sends second location information to a second server.
[0187] Exemplarily, the second location information is used to indicate the location of the second function in the second programming language file. For example, the location information of the second function includes but is not limited to one or more of the following: the package name where the second function is located, the class name where the second function is located, the module name where the second function is located, and / or the line where the second function is located.
[0188] In the present application, the package name where the second function is located refers to the name of the package where the second function is located, the class name where the second function is located refers to the name of the class where the second function is located, and the module name where the second function is located refers to the name of the module where the second function is located.
[0189] Optionally, the above S701 includes: after the first device detects the second operation, the second client plug-in of the first device sends the second location information to the second server.
[0190] For example, the second operation may be a reference search operation performed by the user based on the second function, such as a code search operation performed by the user that references the second function.
[0191] Assuming that the first programming language is the eTS programming language and the second programming language is the C++ programming language, the second operation may be a reference search operation performed by the user on the second function in the C++ programming language file. For example, the user may perform the reference search operation through a tool in a menu or a shortcut key.
[0192] S702: The second server sends a cross-language call flag and information about the first function to a second client plug-in of the first device according to the second location information.
[0193] Exemplarily, the information of the first function includes one or more of the following: the function name of the first function, the class name where the first function is located, the module name where the first function is located, and the package name where the first function is located. For different programming languages, the content included in the information of the first function may be different.
[0194] Optionally, the above S702 may include: the second server determines the information of the first function according to the first mapping relationship and the second location information. The implementation of the first mapping relationship may refer to the corresponding description in the above S405.
[0195] Optionally, the above S702 may include: the second server determines a cross-language call flag according to the first mapping relationship and the function name of the second function.
[0196] For example, if the first mapping relationship includes a correspondence between the second function and other functions, and it is confirmed that the second function is referenced in other programming language files (files of programming languages other than the second programming language file), a cross-language call flag is sent. Otherwise, no cross-language call flag is sent.
[0197] S703: The second client plug-in of the first device sends information of the first function to the first client plug-in of the first device.
[0198] Optionally, S703 may include: the second client plug-in of the first device sends the information of the first function to the first client plug-in of the first device through a jump interface or a communication protocol between different programming languages (for example, a protocol obtained based on LSP). The jump interface is used for interaction between the first client plug-in of the first device and the second client plug-in of the first device. In this way, different client plug-ins can interact with each other through the jump interface or the communication protocol between different programming languages, thereby supporting cross-programming language services.
[0199] S704: The first client plug-in of the first device sends a first cross-language reference search request to the first server.
[0200] Exemplarily, the first cross-language reference search request is used to request a search for a first function.
[0201] Exemplarily, the first cross-language reference search request includes: the name of the first function and information about the cross-language reference policy, and may also include one or more of the following: the class name where the first function is located, the module name where the first function is located, and the package name where the first function is located.
[0202] For example, the information of the cross-language reference strategy may include an identifier of the cross-language reference strategy, and the cross-language reference strategy includes but is not limited to: the first programming language references the second programming language, and the first programming language references the third programming language, etc. For example, the ETS programming language references the C++ programming language, the ETS programming language references the Java programming language, etc. The first server may determine a corresponding reference search solution according to the information of the cross-language reference strategy.
[0203] In some embodiments, S704 may include: a first client plug-in of the first device sends a first cross-language reference search request to the first server through a cross-programming language reference search protocol. The present application does not limit the name of the cross-programming language reference search protocol.
[0204] In this way, the client plug-in of the programming language and the server of the programming language can communicate through the cross-programming language reference lookup protocol. The cross-programming language reference lookup protocol is based on the LSP extension, which can realize general cross-language service capabilities and solve the problem of strong platform binding.
[0205] S705: The first server determines first location information according to the first cross-language reference search request.
[0206] For example, the first location information is used to indicate the location of the first function in the first programming language file. For example, the location information of the first function includes but is not limited to one or more of the following: the package name where the first function is located, the class name where the first function is located, the module name where the first function is located, and / or the line where the first function is located.
[0207] For example, assuming that the cross-language reference strategy is to jump from the ETS programming language to the C++ programming language, the first server determines the first location information according to the name of the first function. Optionally, the first server may also consider the class name of the first function, the module name of the first function, and the package name of the first function in the process of determining the first location information.
[0208] S706: The first server sends a first cross-language reference search response to the first client plug-in of the first device.
[0209] Exemplarily, the first cross-language reference search response includes: null or first location information.
[0210] For example, the first server may not find the first function and cannot determine the first location information, so it returns empty.
[0211] Optionally, the first cross-language redirect response may further include: an error code and error information, where the error information may be used to indicate the cause of the error. For example, if the first server does not support reference search from the second programming language to the first programming language and fails to determine the first location information, the error code and error information are returned.
[0212] In some embodiments, S706 may include: the first server sending a first cross-language reference lookup response to the first client plug-in of the first device through a cross-programming language reference lookup protocol.
[0213] In combination with S704 and S706, exemplarily, a cross-programming language reference search protocol includes: a request part and a response part. The request part can be expressed as: textDocument / crossReferences(CrossLanguageReferencesParams). CrossLanguageReferencesParams represents the cross-language reference parameter, and textDocument / crossReferences represents the name of the cross-programming language reference search protocol. The response part includes result information and may also include other information. The result information can be expressed as: null|Location[]. Null represents empty, | represents or, and Location[] represents one or more first location information. Other information includes: error code and error information.
[0214] Optionally, the cross-language reference parameter in the request part may include one or more of the following: a name field, a policy field, and an extension field. The fields in the cross-language reference parameter are described below in conjunction with Table 3.
[0215] Exemplarily, the name field is used to indicate the name of the first function.
[0216] Exemplarily, the policy field is used to indicate a cross-language reference policy. For example, the policy field includes information about the cross-language reference policy, such as an identifier of the cross-language reference policy.
[0217] Exemplarily, the extension field may also be referred to as a reserved field. For example, the extension field may be an extension field of a cross-language reference strategy. The extension field may be used to add independent parameters required by each cross-language reference strategy. Different cross-language reference strategies may require different parameters. The content included in the extension field may be adjusted according to the actual cross-language reference strategy. Optionally, the class name where the first function is located, the module name where the first function is located, and / or the package name where the first function is located may be carried in the extension field of the cross-programming language reference lookup protocol.
[0218] Table 3
[0219]
[0220] Optionally, the location parameter (Location or Location[]) in the response part may include one or more of the following: a URI field, and a range field. The fields in the location parameter are described below in conjunction with Table 4.
[0221] Exemplarily, the URI field is used to indicate the URI of the first programming language file where the first function (also referred to as the target language function) is located, and may also be used to indicate the storage path of the first programming language file in the computer's external memory.
[0222] Exemplarily, the scope field is used to indicate the scope of the function name of the first function.
[0223] Table 4
[0224]
[0225] For example, taking the cross-programming language reference search protocol represented as textDocument / crossReferences as an example, combined with the description of the cross-programming language reference search protocol in Table 3 and Table 4 above, the cross-programming language reference search protocol obtained based on LSP can be as follows:
[0226]
[0227]
[0228] In this way, through the cross-programming language reference search protocol obtained based on LSP extension, the programming language client and the programming language server can support the search for cross-language references, and can also solve the problem of strong binding between cross-programming language services and platforms, and can quickly migrate and adapt.
[0229] S707: The first client plug-in of the first device sends first location information to the second client plug-in of the first device.
[0230] Optionally, S407 may include: the first client plug-in of the first device sends the first location information to the second client plug-in of the first device through a jump interface or a communication protocol between different programming languages (eg, a protocol obtained based on an LSP).
[0231] Optionally, the method provided in the embodiment of the present application may further include: the first device searches for the first function according to the first location information, and displays a reference search result.
[0232] Combination Figure 8 After the first device detects the user's search for the Add function in the hello.cpp file, it executes Figure 7 The method shown in Figure 8 The interface shown includes: the index.ets file includes a search result that references the Add function. Specifically, the function that references the Add function in the index.ets file is the testNapi.add(2,3) function in line 17.
[0233] Optionally, after the first device detects that the user searches for the Add function in the hello.cpp file, the first device may also search for references to the Add function in the hello.cpp file. Specifically, Figure 8 As shown, the hello.cpp file includes two search results that reference the Add function, which are located in line 13 and line 44 of the hello.cpp file respectively.
[0234] based on Figure 7 The method shown implements cross-language reference lookup of functions based on the cross-programming language reference lookup protocol, which not only solves the problem of strong binding between cross-programming language services and platforms, but also enables cross-language interaction, realizes general cross-language service capabilities, and improves the rapid adaptation of multi-language and multi-compiler cross-language services.
[0235] For example, Fig. 9 A flowchart of another method for searching codes provided in an embodiment of the present application. Fig. 9 The provided method is suitable for reference search between two or more programming languages. Fig. 9 The method shown is explained using the example of reference search between two programming languages. Fig. 9 For cross-language scenarios, the universal cross-language service method based on LSP extension unifies the data format of cross-language requests and responses, and provides IDE developers with a universal solution for quickly adapting cross-language code jumps and reference search features on different platforms.
[0236] like Fig. 9 As shown, the method includes the following steps.
[0237] S901: The first device determines to search a second programming language file for a code associated with a first function in a first programming language file.
[0238] Exemplarily, the second programming language file and the first programming language file are files in different programming languages.
[0239] In some embodiments, the above S901 may include: determining to search for a function called by the first function from a second programming language file.
[0240] In some other embodiments, the above S901 may include: determining to search for a function that references the first function from a second programming language file.
[0241] In a possible design scheme, the above S901 may include: the following S901a to S901c.
[0242] S901a, the first device detects a code search instruction.
[0243] Optionally, the find code instruction is used to instruct to find a code associated with the first function.
[0244] Optionally, the code search instruction may be the first operation in S401 or the second operation in S701.
[0245] S901b: The first device sends first location information to a service device of the first programming language.
[0246] Optionally, the first position information is used to indicate the position of the first function in the first programming language file.
[0247] Optionally, the first location information may be the above Figure 4 The first position information in the method shown or the above Figure 7 The second position information in the method shown.
[0248] Optionally, the specific implementation of S901b may refer to the corresponding description in the above S401 or the above S701.
[0249] S901c: The first device receives first indication information from a service device of a first programming language.
[0250] Optionally, the first indication information is used to instruct to search the second programming language file for code associated with the first function in the first programming language file.
[0251] Optionally, the first device may also receive information about a function referenced by the first function from a service device of the first programming language. Exemplarily, the information about the function referenced by the first function includes one or more of the following: a function name of the function referenced by the first function, a class name of the function referenced by the first function, a module name of the function referenced by the first function, and a package name of the function referenced by the first function. For different programming languages, the information about the function referenced by the first function may include different contents.
[0252] Optionally, the first indication information may be the above Figure 4 or Figure 7 The cross-language call flag in the method shown.
[0253] Optionally, the specific implementation of S901c may refer to the corresponding description in the above S402 or the above S702.
[0254] In some embodiments, the first device includes a first programming language client plug-in and a second programming language client plug-in, and the first device detecting the search code instruction may include: the first programming language client plug-in of the first device detecting the search code instruction.
[0255] Optional, Figure 8 The method shown may also include: the first programming language client plug-in of the first device sends the name of the first function to the second programming language client plug-in of the first device. For specific implementation, refer to the corresponding description in the above S403 or the above S703.
[0256] S902: The first device sends a first request to the service device of the second programming language through the first protocol. Correspondingly, the service device of the second programming language receives the first request from the first device through the first protocol.
[0257] Exemplarily, the first protocol is related to the language service protocol LSP, and the first request includes: the name of the first function and search information, and the search information includes searching for code associated with the code in the first programming language file from the second programming language file.
[0258] Optionally, the search information may be the information of the above-mentioned cross-language jump strategy or the information of the cross-language reference strategy.
[0259] In some embodiments, the first protocol includes a name field, a search field, and a location field. The name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information. The specific implementation of the first protocol can refer to the specific implementation of the above-mentioned cross-programming language jump protocol or cross-programming language reference search protocol, which will not be repeated here.
[0260] Optionally, the search field may be the above-mentioned policy field. The implementation of the location field may refer to the above-mentioned Figure 4 or Figure 7 The description of the position parameters in the method shown will not be repeated here.
[0261] In some embodiments, searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function called by the first function, or searching from the second programming language file for code associated with code in the first programming language file is searching from the second programming language file for a function that references the first function.
[0262] Optionally, the specific implementation of S902 may refer to the corresponding description in the above S404 or the above S704.
[0263] S903, the service device of the second programming language sends a first response to the first device through the first protocol. Correspondingly, the first device receives the first response from the service device of the second programming language through the first protocol.
[0264] Exemplarily, the first response includes first information indicating a location of code associated with the first function.
[0265] Optionally, the first response may be called a first cross-language jump response or a first cross-language reference search response. For specific implementation, refer to the above Figure 4 or Figure 7 The description of the position parameters in the method shown will not be repeated here.
[0266] In some embodiments, the first information includes a location of a second function, where the second function is a function in a second programming language file called by the first function.
[0267] In other embodiments, the first information includes the location of a third function, where the third function is a function in the second programming language file that references the first function.
[0268] In some embodiments, the first information is determined based on the name of the first function, the search information, and the first mapping relationship, and the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file. The specific implementation method can refer to the corresponding description in S405 or S705 above, which will not be repeated here.
[0269] The specific implementation method of S903 may refer to the corresponding description in the above S406 or S706, which will not be repeated here.
[0270] based on Fig. 9In the provided method, a first device interacts with a service device of a second programming language through a first protocol, sends the name of a first function and search information to the service device of the second programming language, and receives the first information. The search information includes searching for code associated with the code in the first programming language file from the second programming language file, and the first information indicates the location of the code associated with the first function, which can realize cross-programming language services, thereby improving code reading efficiency.
[0271] In this application, unless otherwise specified, the same or similar parts between the various embodiments can refer to each other. In each embodiment of this application, and each implementation method / implementation method / implementation method in each embodiment, if there is no special description and logical conflict, the terms and / or descriptions between different embodiments and each implementation method / implementation method / implementation method in each embodiment are consistent and can be referenced to each other. The technical features in different embodiments and each implementation method / implementation method / implementation method in each embodiment can be combined to form new embodiments, implementation methods, implementation methods, or implementation methods according to their inherent logical relationships. In each example or each optional method described in the above embodiments, any content can be freely combined, and the combined content is also within the scope of this application. The above-described implementation methods of this application do not constitute a limitation on the scope of protection of this application.
[0272] Combination of the above Figure 4-Figure 9 The input method provided by the embodiment of the present application is described in detail. Fig.10 The first device and the second device provided in the embodiments of the present application are described in detail.
[0273] Fig.10 A schematic diagram of a device provided in an embodiment of the present application. For example, the device may be a first device or a second device. Fig.10 As shown, the device 1000 may include: a sending unit 1001, a receiving unit 1002, and may also include a processing unit 1003, a display unit ( Fig.10 ) and / or a communication unit ( Fig.10 not shown).
[0274] In one possible design, device 1000 is a first device, and device 1000 can be used to implement the functions of the first device involved in the above method embodiment.
[0275] Optionally, the sending unit 1001 is configured to support the first device to execute Figure 4-Figure 9 Any of the sending functions in .
[0276] Optionally, the receiving unit 1002 is configured to support the first device to execute Figure 4-Figure 9 Any receiving function in .
[0277] Optionally, the processing unit 1003 is configured to support the first device to execute Figure 4-Figure 9 Any processing function in .
[0278] Optionally, the display unit is used to support the first device to execute Figure 4-Figure 9 Any display function and / or touch function.
[0279] Optionally, a communication unit is used to support the first device to execute Figure 4-Figure 9 Any communication function in the network, such as accessing a local area network through a routing device.
[0280] Among them, the receiving unit 1002 and the sending unit 1001 can be implemented by a transceiver or a transceiver-related circuit component, and can be a transceiver or a transceiver unit. The operations and / or functions of each unit in the device 1000 are respectively to implement the corresponding process of the method described in the above method embodiment. All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional unit, and for the sake of brevity, they are not repeated here.
[0281] Optionally, Fig.10 The device 1000 shown may also include a storage unit ( Fig.10 (not shown), the storage unit stores a program or instruction. When the sending unit 1001, the receiving unit 1002, the processing unit 1003 and the display unit execute the program or instruction, Fig.10 The device 1000 shown can execute the method described in the above method embodiments.
[0282] Fig.10 The technical effects of the device 1000 shown can refer to the technical effects of the methods described in the above method embodiments, which will not be repeated here.
[0283] In addition to being in the form of device 1000, the technical solution provided in the present application may also be a functional unit or chip in the first device, or a device used in conjunction with the first device.
[0284] In another possible design, device 1000 is a first server, and device 1000 can be used to implement the functions of the first server involved in the above method embodiment.
[0285] Optionally, the sending unit 1001 is used to support the first server to execute Figure 4-Figure 9 Any of the sending functions in .
[0286] Optionally, the receiving unit 1002 is configured to support the first server to execute Figure 4-Figure 9 Any receiving function in .
[0287] Optionally, the processing unit 1003 is configured to support the first server to execute Figure 4-Figure 9 Any processing function in .
[0288] Optionally, the display unit is used to support the first server to execute Figure 4-Figure 9 Any display function and / or touch function.
[0289] Optionally, a communication unit is used to support the first server to execute Figure 4-Figure 9 Any communication function in the network, such as accessing a local area network through a routing device.
[0290] Among them, the receiving unit 1002 and the sending unit 1001 can be implemented by a transceiver or a transceiver-related circuit component, and can be a transceiver or a transceiver unit. The operations and / or functions of each unit in the device 1000 are respectively to implement the corresponding process of the method described in the above method embodiment. All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional unit, and for the sake of brevity, they are not repeated here.
[0291] Optionally, Fig.10 The device 1000 shown may also include a storage unit ( Fig.10 (not shown), the storage unit stores a program or instruction. When the sending unit 1001, the receiving unit 1002, the processing unit 1003 and the display unit execute the program or instruction, Fig.10 The device 1000 shown can execute the method described in the above method embodiments.
[0292] Fig.10 The technical effects of the device 1000 shown can refer to the technical effects of the methods described in the above method embodiments, which will not be repeated here.
[0293] In addition to being in the form of device 1000, the technical solution provided by the present application may also be a functional unit or chip in the first server, or a device used in conjunction with the first server.
[0294] In another possible design, device 1000 is a second server, and device 1000 can be used to implement the functions of the second server involved in the above method embodiment.
[0295] Optionally, the sending unit 1001 is used to support the second server to execute Figure 4-Figure 9 Any of the sending functions in .
[0296] Optionally, the receiving unit 1002 is configured to support the second server to execute Figure 4-Figure 9 Any receiving function in .
[0297] Optionally, the processing unit 1003 is used to support the second server to execute Figure 4-Figure 9 Any processing function in .
[0298] Optionally, the display unit is used to support the second server to execute Figure 4-Figure 9 Any display function and / or touch function.
[0299] Optionally, a communication unit is used to support the second server to execute Figure 4-Figure 9 Any communication function in the network, such as accessing a local area network through a routing device.
[0300] Among them, the receiving unit 1002 and the sending unit 1001 can be implemented by a transceiver or a transceiver-related circuit component, and can be a transceiver or a transceiver unit. The operations and / or functions of each unit in the device 1000 are respectively to implement the corresponding process of the method described in the above method embodiment. All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional unit, and for the sake of brevity, they are not repeated here.
[0301] Optionally, Fig.10 The device 1000 shown may also include a storage unit ( Fig.10 (not shown), the storage unit stores a program or instruction. When the sending unit 1001, the receiving unit 1002, the processing unit 1003 and the display unit execute the program or instruction, Fig.10 The device 1000 shown can execute the method described in the above method embodiments.
[0302] Fig.10 The technical effects of the device 1000 shown can refer to the technical effects of the methods described in the above method embodiments, which will not be repeated here.
[0303] In addition to being in the form of device 1000, the technical solution provided by the present application may also be a functional unit or chip in the second server, or a device used in conjunction with the second server.
[0304] An embodiment of the present application also provides a communication system, including: a first device and at least two second devices.
[0305] Optionally, each device in the communication system provided in the embodiment of the present application may execute the method described in the above method embodiment. The technical effect of the communication system may refer to the technical effect of the method described in the above method embodiment, which will not be described in detail here.
[0306] An embodiment of the present application also provides a chip system, including: a processor, the processor is coupled to a memory, the memory is used to store programs or instructions, when the program or instructions are executed by the processor, the chip system implements the method in any of the above method embodiments.
[0307] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0308] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.
[0309] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0310] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0311] An embodiment of the present application also provides a readable storage medium, in which a program is stored. When the program is executed on a computer or a device, the computer or the device executes the above-mentioned related steps to implement the method in the above-mentioned embodiment.
[0312] The embodiments of the present application also provide a program product. When the program product is run on a computer or a device, the computer or the device executes the above-mentioned related steps to implement the method in the above-mentioned embodiments.
[0313] In addition, an embodiment of the present application further provides a device. The device may be a component or a module, and the device may include one or more processors and a memory connected to each other. The memory is used to store a program. When the program is executed by one or more processors, the device executes the method in each of the above method embodiments.
[0314] Among them, the device, readable storage medium, program product or chip provided in the embodiments of the present application are used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0315] The steps of the method or algorithm described in conjunction with the disclosed content of the embodiments of the present application can be implemented in hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, read-only compact disks (CD-ROMs) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC).
[0316] Through the description of the above implementation methods, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed; that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0317] In the several embodiments provided in the present application, it should be understood that the disclosed method can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of modules or units, which can be electrical, mechanical or other forms.
[0318] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0319] The readable storage medium includes but is not limited to any of the following: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0320] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for searching a code, characterized in that: include: The first device determines to search a second programming language file for a code associated with a first function in a first programming language file; wherein the second programming language file and the first programming language file are files in different programming languages; The first device sends a first request to a service device of a second programming language through a first protocol; wherein the first protocol is related to a language service protocol LSP, and the first request includes: a name and search information of the first function, wherein the search information includes searching for code associated with the code in the first programming language file from the second programming language file; The first device receives a first response from a service device of the second programming language through the first protocol; wherein the first response includes first information indicating a location of the code associated with the first function.
2. The method according to claim 1, characterized in that The first protocol includes a name field, a search field and a location field; wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
3. The method according to claim 1 or 2, characterized in that: The determining to search from the second programming language file for a code associated with the first function in the first programming language file comprises: determining to search from the second programming language file for a function called by the first function; The first information includes a location of a second function, where the second function is a function in the second programming language file called by the first function.
4. The method according to claim 1 or 2, characterized in that: The determining to search from the second programming language file for a code associated with the first function in the first programming language file comprises: determining to search from the second programming language file for a function that references the first function; The first information includes a location of a third function, where the third function is a function in the second programming language file that references the first function.
5. The method according to any one of claims 1 to 4, characterized in that The first information is determined according to the name of the first function, the search information and a first mapping relationship, wherein the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
6. The method according to any one of claims 1 to 5, characterized in that The first device determines to search the second programming language file for code associated with the first function in the first programming language file, including: The first device detects a code search instruction; wherein the code search instruction is used to instruct to search for a code associated with the first function; The first device sends first location information to a service device of a first programming language; wherein the first location information is used to indicate the location of the first function in the first programming language file; The first device receives first indication information from a service device of the first programming language; wherein the first indication information is used to instruct to search the second programming language file for code associated with the first function in the first programming language file.
7. The method according to any one of claims 1 to 6, characterized in that The first device includes a first programming language client plug-in and a second programming language client plug-in, and the first device detects a code search instruction, including: The first programming language client plug-in of the first device detects the find code instruction; Before the first device sends the first request to the service device of the second programming language through the first protocol, the method further includes: The first programming language client plug-in of the first device sends the name of the first function to the second programming language client plug-in of the first device.
8. A method for finding a code, characterized in that: include: The service device of the second programming language receives a first request from the first device through a first protocol; wherein the first protocol is related to a language service protocol LSP, and the first request includes: a name of a first function and search information, wherein the search information includes searching for code associated with the code in the first programming language file from the second programming language file; The service device of the second programming language sends a first response to the first device through the first protocol; wherein the first response includes first information indicating the location of the code associated with the first function.
9. The method according to claim 8, characterized in that The first protocol includes a name field, a search field and a location field; wherein the name field is used to carry the name of the first function, the search field is used to carry the search information, and the location field is used to carry the first information.
10. The method according to claim 8 or 9, characterized in that: The step of searching from the second programming language file for code associated with the code in the first programming language file is searching from the second programming language file for a function called by the first function, the first information includes a location of the second function, and the second function is a function in the second programming language file called by the first function.
11. The method according to claim 8 or 9, characterized in that: The step of searching from the second programming language file for code associated with the code in the first programming language file is searching from the second programming language file for a function that references the first function. The first information includes a location of a third function, and the third function is a function in the second programming language file that references the first function.
12. The method according to any one of claims 8 to 11, characterized in that The first information is determined according to the name of the first function, the search information and a first mapping relationship, wherein the first mapping relationship includes a mapping relationship between at least one function in the first programming language file and at least one function in the second programming language file.
13. A first device, characterized in that: The first device comprises: one or more processors; one or more memories; The memory stores one or more programs, and when the one or more programs are executed by the one or more processors, the first device executes the method according to any one of claims 1 to 7.
14. A second device, characterized in that: The second device comprises: one or more processors; one or more memories; The memory stores one or more programs, and when the one or more programs are executed by the one or more processors, the second device executes the method according to any one of claims 8 to 12.
15. A communication system, characterized in that: The communication system comprises: The first device as claimed in claim 13; and The second device as claimed in claim 14.
16. The communication system according to claim 15, characterized in that: The communication system further comprises: a service device of a first programming language; wherein the service device of the first programming language is used to receive first location information from the first device; the first location information is used to indicate the location of the first function in the first programming language file; The service device of the first programming language is further used to send first indication information to the first device, where the first indication information is used to instruct to search the second programming language file for code associated with the first function in the first programming language file.
17. A readable storage medium, characterized in that: The readable storage medium includes a program, and when the program is executed on a device, the device is caused to execute the method according to any one of claims 1 to 12.
Citation Information
Cited By
Code search method, device and system
EP4645066A1
Code search method, device and system
WO2024207878A1
