CN115951888A - Method for positioning program source code position and computing equipment - Google Patents

Method for positioning program source code position and computing equipment Download PDF

Info

Publication number
CN115951888A
CN115951888A CN202310064875.7A CN202310064875A CN115951888A CN 115951888 A CN115951888 A CN 115951888A CN 202310064875 A CN202310064875 A CN 202310064875A CN 115951888 A CN115951888 A CN 115951888A
Authority
CN
China
Prior art keywords
source code
webpage
position information
program
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310064875.7A
Other languages
Chinese (zh)
Inventor
虞翼翀
张延宏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Hongji Information Technology Co Ltd
Original Assignee
Shanghai Hongji Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Hongji Information Technology Co Ltd filed Critical Shanghai Hongji Information Technology Co Ltd
Priority to CN202310064875.7A priority Critical patent/CN115951888A/en
Publication of CN115951888A publication Critical patent/CN115951888A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the invention relates to the technical field of webpage front ends, in particular to a method and a device for positioning program source code positions, computing equipment and a computer readable storage medium. The method comprises the following steps: acquiring a first webpage element corresponding to the cursor position of a current webpage; determining a target webpage source code corresponding to the first webpage element; determining first position information of a target program source code corresponding to a first webpage element in a target webpage source code; and generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by the browser. The function of automatically displaying the position information of the target program source code corresponding to the first webpage element corresponding to the cursor is realized, the position of the target program source code does not need to be manually searched, time and labor are saved, and the efficiency of positioning the program source code is improved.

Description

Method for positioning program source code position and computing equipment
Technical Field
The embodiment of the invention relates to the technical field of webpage front ends, in particular to a method and a device for positioning program source code positions, computing equipment and a computer readable storage medium.
Background
When a developer at the front end of a webpage browses the webpage, and finds that interaction, style, characters or data processing and the like of a webpage element at a certain position of the webpage need to be modified, the developer needs to find the position of a program source code corresponding to the webpage element by himself to modify the program source code, so that the webpage element in the webpage is modified, and the webpage display effect is optimized.
When the position of the program source code corresponding to the web page element is found, a file in which the program source code is located needs to be found first, and a row and a column in which the program source code is located are found in the file. When the source code position of the existing positioning program is located, manual positioning is needed, time and labor are wasted, efficiency is low, cost is high, and timely repair of a webpage is not facilitated.
Disclosure of Invention
The embodiment of the invention provides a method for positioning a program source code position, which is used for improving the efficiency of positioning the program source code position.
In a first aspect, an embodiment of the present invention provides a method for locating a source code position of a program, including:
acquiring a first webpage element corresponding to the cursor position of a current webpage; determining a target webpage source code corresponding to the first webpage element;
determining first position information of a target program source code corresponding to the first webpage element in the target webpage source code;
and generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by a browser.
The method comprises the steps of obtaining a first webpage element corresponding to a cursor, and determining first position information of a target program source code corresponding to the first webpage element in a target webpage source code of the first webpage element. And generating a temporary webpage source code for describing the first position information, so that the browser can generate a second webpage element for displaying the first position information by analyzing the temporary webpage source code. According to the technical scheme, the function of automatically displaying the position information of the target program source code corresponding to the first webpage element corresponding to the cursor is achieved, the position of the target program source code does not need to be found manually, time and labor are saved, and the efficiency of positioning the program source code is improved.
In some embodiments, determining the target web page source code corresponding to the first web page element comprises:
converting an original program source code file of the webpage file into an abstract syntax tree aiming at the webpage file where the first webpage element is located;
extracting the position information of a program source code corresponding to the webpage element from the program character information of the abstract syntax tree aiming at any webpage element in the webpage file;
adding the position information serving as an execution element into a label or function grammar of a program source code corresponding to the webpage element;
converting the abstract syntax tree added with the execution elements into an updated program source code file; the updating program source code file is used for being compiled by a compiler to obtain a webpage source code corresponding to the webpage file;
and determining the target webpage source code in the webpage source codes.
The original program source code file is converted into the abstract syntax tree, and the position information of the program source code corresponding to any webpage element can be automatically and quickly extracted. And then adding the position information as an execution element to a label or a function syntax of a program source code corresponding to the webpage element, wherein each program source code in the updated program source code file obtained in the way carries the position information of the program source code. The source code of the web page compiled from the source code file of the updated program also carries the location information of the source code of the corresponding program. Therefore, the function of automatically adding the position information corresponding to the program source code in the webpage source code is realized. Then the target web page source code determined in the web page source code will carry the first location information of the target program source code corresponding to the first web page element.
In some embodiments, determining first location information of target program source code corresponding to the first web page element in the target web page source code includes:
if it is determined that the target webpage source code does not contain the position information of the target program source code corresponding to the first webpage element, determining the superior position information of the superior program source code in the superior webpage source code of the target webpage source code, and taking the superior position information as the first position information.
If the target webpage source code does not contain the position information of the target program source code corresponding to the first webpage element, the superior position information of the superior program source code corresponding to the superior webpage source code can be found in the superior webpage source code, and the superior position information is used as the first position information. Therefore, the user can quickly find the source code of the target program through the displayed superior position information. The workload of searching the source code of the target program by the user is reduced.
In some embodiments, before generating the temporary web page source code describing the first location information, further comprising:
determining second position information of the first webpage element in the current webpage;
generating a temporary web page source code for describing the first location information, comprising:
determining third position information of the second webpage element corresponding to the temporary webpage source code in the current webpage according to the second position information; the distance between the second position information and the third position information is smaller than a preset threshold value;
and generating the temporary webpage source code according to the third position information.
In this way, the first location information of the source code of the target program can be displayed at a position closer to the first webpage element, rather than at any position of the webpage at random.
In some embodiments, further comprising:
and adding the temporary webpage source code to the highest layer in the current webpage source code.
Therefore, the problem that the first position information cannot be displayed because the first position information is covered by other webpage elements of the current webpage is avoided.
In some embodiments, before converting the source code file of the original program into the abstract syntax tree, the method further comprises:
receiving a program source code change prompt message sent by a compiler; and the compiler is used for sending a program source code change prompt message after monitoring that the original program source code file is changed.
The compiler has the functions of monitoring whether the original program source code file is changed and sending a prompt message, so that the step of converting the original program source code file into the abstract syntax tree is repeated by intercepting the program source code change prompt message sent by the compiler, and thus, the updated webpage source code can be obtained, and the updated webpage source code contains the updated position information of each program source code.
In some embodiments, the obtaining the web page element corresponding to the cursor position of the cursor on the current web page further includes:
and receiving a positioning code opening position command sent by a user.
In order to avoid that when a user does not want to display the position information of the program source code, the position information of the program source code is displayed, and the use of other functions in a webpage by the user is influenced, therefore, the operation of acquiring the cursor position is started only after a positioning code position starting command sent by the user is received, the user experience can be improved, and the intelligence and flexibility of displaying the position of the program source code are improved.
In some embodiments, after generating the temporary web page source code describing the first location information, further comprising:
after the trigger operation aiming at the second webpage element is detected, acquiring the first position information;
displaying a target page according to the first position information; and the target page comprises a target program source code corresponding to the first webpage element.
In the above technical solution, when the user has a trigger operation on the second web page element, the processor may detect the trigger operation, so as to automatically display the target page including the target program source code corresponding to the first web page element, so that the user can directly modify the target program source code and the like. The target program source code does not need to be searched by the user, so that the time of the user is saved, and the user experience is improved.
In a second aspect, an embodiment of the present invention further provides an apparatus for locating a source code position of a program, including:
an acquisition unit configured to: acquiring a first webpage element corresponding to the cursor position of a cursor on a current webpage; determining a target webpage source code corresponding to the first webpage element;
a processing unit to:
determining first position information of a target program source code corresponding to the first webpage element in the target webpage source code;
and generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by a browser.
In some embodiments, the obtaining unit is specifically configured to:
converting an original program source code file of the webpage file into an abstract syntax tree aiming at the webpage file where the first webpage element is located;
extracting the position information of a program source code corresponding to the webpage element from the program character information of the abstract syntax tree aiming at any webpage element in the webpage file;
adding the position information serving as an execution element into a label or function grammar of a program source code corresponding to the webpage element;
converting the abstract syntax tree added with the execution elements into an updated program source code file; the updating program source code file is used for being compiled by a compiler to obtain a webpage source code corresponding to the webpage file;
and determining the target webpage source code in the webpage source codes.
In some embodiments, the processing unit is specifically configured to:
if it is determined that the target webpage source code does not contain the position information of the target program source code corresponding to the first webpage element, determining the superior position information of the superior program source code in the superior webpage source code of the target webpage source code, and taking the superior position information as the first position information.
In some embodiments, the processing unit is further to:
determining second position information of the first webpage element in the current webpage;
the processing unit is specifically configured to:
determining third position information of the second webpage element corresponding to the temporary webpage source code in the current webpage according to the second position information; the distance between the second position information and the third position information is smaller than a preset threshold value;
and generating the temporary webpage source code according to the third position information.
In some embodiments, the processing unit is further to:
and adding the temporary webpage source code to the highest layer in the current webpage source code.
In some embodiments, the processing unit is further to:
receiving a program source code change prompt message sent by a compiler; and the compiler is used for sending a program source code change prompt message after monitoring that the original program source code file is changed.
In some embodiments, the obtaining unit is further configured to:
and receiving a positioning code opening position command sent by a user.
In some embodiments, the processing unit is further to:
after the triggering operation aiming at the second webpage element is detected, the first position information is obtained;
displaying a target page according to the first position information; and the target page comprises a target program source code corresponding to the first webpage element.
In a third aspect, an embodiment of the present invention further provides a computing device, including:
a memory for storing a computer program;
and the processor is used for calling the computer program stored in the memory and executing the method for positioning the program source code position listed in any mode according to the obtained program.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where a computer-executable program is stored, where the computer-executable program is configured to enable a computer to perform the method for locating a source code position of a program listed in any of the above manners.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating relationships among program source code, web page source code, and web page elements according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for locating a source code position of a program according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a web page source code according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a possible display effect provided by an embodiment of the invention;
FIG. 5 is a flowchart illustrating a method for locating a source code position of a program according to an embodiment of the present invention;
FIG. 6a is a diagram illustrating an abstract syntax tree into which source code of a program for generating source code of a web page by using tags is translated according to an embodiment of the present invention;
FIG. 6b is a diagram of an abstract syntax tree into which program source code for generating a web page source code through a function is transformed according to an embodiment of the present invention;
fig. 7 is a schematic diagram of a possible conversion process of the modified abstract syntax tree- > update program source code file- > web page source code according to an embodiment of the present invention;
fig. 8 is a flowchart illustrating a method for locating a source code position of a program according to an embodiment of the present invention;
FIG. 9 is a schematic structural diagram of an apparatus for locating a source code position of a program according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
Detailed Description
To make the objects, embodiments and advantages of the present application clearer, the following is a clear and complete description of exemplary embodiments of the present application with reference to the attached drawings in exemplary embodiments of the present application, and it is apparent that the exemplary embodiments described are only a part of the embodiments of the present application, and not all of the embodiments.
All other embodiments, which can be derived by a person skilled in the art from the exemplary embodiments described herein without inventive step, are intended to be within the scope of the claims appended hereto. In addition, while the disclosure herein has been presented in terms of exemplary embodiment or embodiments, it should be appreciated that individual aspects of the disclosure can be utilized in a variety of forms and embodiments.
It should be noted that the brief descriptions of the terms in the present application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of the present application. These terms should be understood in their ordinary and customary meaning unless otherwise indicated.
The terms "first," "second," "third," and the like in the description and claims of this application and in the above-described drawings are used for distinguishing between similar or analogous objects or entities and are not necessarily intended to limit the order or sequence of any particular one, unless otherwise indicated. It is to be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments of the application are, for example, capable of operation in sequences other than those illustrated or otherwise described herein.
Furthermore, the terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or device that comprises a list of elements is not necessarily limited to those elements explicitly listed, but may include other elements not expressly listed or inherent to such product or device.
Before describing the method for locating the source code position of a program according to an embodiment of the present invention, the following terms are explained.
1. And (3) program source code: the developer writes code for generating the source code for the web page. The developer modifies the program source code, so that the function of modifying the webpage source code corresponding to the program source code and further modifying the webpage element corresponding to the webpage source code can be realized.
2. And (3) webpage source code: and compiling the program source code by the compiler to generate a webpage source code, namely a source code corresponding to the front-end page. The browser may parse the web page source code to render each web page element in the web page.
3. Webpage elements: any element in the web page, such as input box, text, color, style, etc.
Fig. 1 exemplarily shows the relationship among the program source code, the web page source code and the web page elements.
The RPA (machine Process Automation) technology can simulate the operation of an employee on a computer through a keyboard and a mouse in daily work, and can replace a human to execute operations of logging in a system, operating software, reading and writing data, downloading files, reading mails and the like. The automatic robot is used as the virtual labor force of an enterprise, so that the staff can be liberated from repeated and low-value work, and the energy is put into the work with high added value, so that the enterprise can realize the reduction of cost and the increase of benefit while realizing the digital intelligent transformation.
The RPA is a software robot which replaces manual tasks in business processes and interacts with a front-end system of a computer like a human, so the RPA can be regarded as a software program robot running in a personal PC or a server, and replaces human beings to automatically repeat operations such as mail retrieval, attachment downloading, system logging, data processing and analysis and other activities by imitating the operations performed by users on the computer, and is fast, accurate and reliable. Although the problems of speed and accuracy in human work are solved by specific rules set like the traditional physical robot, the traditional physical robot is a robot combining software and hardware, and can execute work only by matching with software under the support of specific hardware; the RPA robot is a pure software level, and can be deployed to any one PC and server to complete specified work as long as corresponding software is installed.
That is, RPA is a way to perform business operations using "digital employees" instead of people and its related technology. In essence, the RPA realizes unmanned operation of objects such as systems, software, webpages and documents on a computer by a human simulator through a software automation technology, acquires service information, executes service actions, and finally realizes flow automation processing, labor cost saving and processing efficiency improvement.
In the prior art, in the process of browsing a webpage by a user, if a program source code of a certain webpage element is to be modified, the program source code to be modified needs to be searched for in each file containing a large number of program source codes, which is undoubtedly very time-consuming and labor-consuming. The embodiment of the application adopts the RPA technology, and realizes the function of automatically displaying the position information of the program source code of a certain webpage element in the webpage.
In order to directly view the position of a program source code corresponding to any web page element and conveniently modify the program source code in time in the process of browsing web pages by a developer, an embodiment of the present application provides a method for automatically positioning the position of the program source code, as shown in fig. 2.
In the prior art, a programmer writes a program source code, a compiler acquires the program source code and compiles the program source code to obtain a webpage source code, a browser acquires the webpage source code and analyzes and renders the webpage source code to generate a webpage, and the webpage comprises webpage elements. Because the program source code does not contain the position information of the program source code, the webpage source code does not contain the position information, and the finally displayed webpage element does not display the program source code position information corresponding to the webpage element.
In order to solve the above problem, in the embodiment of the present application, a post plug-in is provided after the compiler. After the compiler generates the webpage source code, the post plug-in intercepts the webpage source code, and the following steps are completed. The method comprises the following steps:
step 201, acquiring a first webpage element corresponding to a cursor position of a cursor on a current webpage; and determining a target webpage source code corresponding to the first webpage element.
Step 202, determining first position information of a target program source code corresponding to the first webpage element in the target webpage source code.
Step 203, generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by a browser.
In step 201, the back plug-in monitors the cursor moving process of the user through a W3C (https:// www.w.3. Org /) standard program interface (hereinafter referred to as "standard program interface"), and obtains a first web page element corresponding to the cursor position of the cursor on the current web page. For example, the first web page element corresponding to the position of the cursor may be an input box, an icon, and the like.
And extracting the target webpage source code corresponding to the webpage element by the post plug-in.
In order to avoid that when a user does not want to display the position information of the program source code of a certain webpage element, the position information of the program source code is displayed, and the use of other functions in the webpage by the user is influenced, the post-plug-in can be set, and after receiving a position command of starting a positioning code sent by the user, the post-plug-in acquires the webpage element corresponding to the cursor position of the cursor on the current webpage. Therefore, the operation of acquiring the cursor position is started only after the positioning code position opening command sent by the user is received, so that the user experience can be improved, and the intelligence and flexibility of displaying the program source code position are improved.
For example, the open locate code position command is a shortcut key. And after the user presses the shortcut key, the rear plug-in receives a position command of starting a positioning code, so as to obtain a first webpage element corresponding to the cursor position. The shortcut key may be "Alt", "Ctrl", etc.
In step 202, the post-plug-in determines whether the target web page source code contains the location information of the target program source code corresponding to the first web page element. If so, extracting the position information as first position information. If the position information of the target program source code corresponding to the first webpage element is not included, determining the superior position information of the superior program source code in the superior webpage source code of the target webpage source code, and taking the superior position information as the first position information. The webpage source codes are of tree structures, the superior webpage source codes with the position information are obtained by traversing the superior webpage source codes upwards in a recursion mode, and the superior position information of the superior program source codes determined in the superior webpage source codes can also represent the first position information.
FIG. 3 shows a schematic diagram of one possible web page source code. If the source code of the target webpage corresponding to the first webpage element corresponding to the cursor position is the code of line 4 in fig. 3, it can be seen that the code of line 4 contains the position information "/src/input.js: 5". The position information can be directly used as the first position information.
If the source code of the target webpage corresponding to the first webpage element corresponding to the cursor position is the code of line 5 in fig. 3, it can be seen that the code of line 5 does not include the position information of the source code of the target program corresponding to the first webpage element. And thus, the upper level web page source code with the position information is determined. In this example, a step of upward traversal is performed to obtain a 4 th row of codes, where the 4 th row of codes contains the superior position information "/src/input. Js: 18/" corresponding to the superior program source code corresponding to the superior web page element. The position information can be regarded as the first position information. In this way, although the first position information finally displayed at the first web page element is not the position information of the program source code corresponding to the first web page element, the programmer can quickly find the program source code of the first web page element by using the position information which is displayed to be the upper-level position information corresponding to the upper-level program source code of the upper-level web page element of the first web page element. And the time for searching the program source code can be reduced, and the workload of a user for searching the target program source code by himself is reduced.
After obtaining the first location information, the post-plug-in may generate a temporary web page source code describing the first location information in step 203. Namely, the temporary webpage source code carries the first position information.
After the browser analyzes and renders the temporary webpage source code, a second webpage element can be generated, and the second webpage element can display the first position information.
In a specific implementation manner, the second web page element is: and highlighting the first webpage element and displaying a display frame of the first position information.
In fig. 4, when the user positions the cursor in the input box corresponding to the "text", the post-plug-in acquires the first web page element corresponding to the cursor position, i.e. the input box. The post plug-in obtains the first position information of the program source code corresponding to the input box "\ \ src \ \ pages \ \ dsu \ \ components \ \ basic-configuration. Js: 1537. And generating a temporary webpage source code according to the first position information, wherein the first position information is described in the temporary webpage source code. The browser analyzes the temporary webpage source code to obtain a second webpage element, wherein the second webpage element comprises a highlight part 410 and a position introduction part 420 below the highlight part, the highlight part 410 is a mark for highlighting the first webpage element, and the position introduction part 420 is a display frame for displaying the first position information. It can be seen that the second web page element may display the first location information of the program source code corresponding to the input box. In one possible way, after the user sees the second web page element, the user knows the first position information of the target program source code of the first web page element, and then the user can open the file corresponding to the target program source code (\ \ src \ pages \ dsu \ \ components \ basic-configuration. So as to find the source code of the target program and modify the source code of the target program.
In another possible mode, the user may click on the second web page element, and after detecting the click operation, the processor automatically jumps to a target page including the source code of the target program, so that the user does not need to search by himself and directly modifies the source code of the target program on the target page. Specifically, after generating the temporary web page source code for describing the first location information, the method further includes: after the trigger operation aiming at the second webpage element is detected, acquiring the first position information; displaying a target page according to the first position information; and the target page comprises a target program source code corresponding to the first webpage element. The triggering operation may be left-click, double-click, right-click, or may be a certain key on a keyboard, and the embodiment of the present application does not limit the specific form of the triggering operation.
For example, the user clicks the location information displayed in the location introduction part 420 of the second web page element, and the processor detects the click operation and obtains the 1537 th line and 8 th column of the first location information in the file \ \ src \ pages \ \ dsu \ \ components \ \ basic-configuration. The processor thus automatically opens the file \ \ src \ \ pages \ \ dsu \ \ components \ \ basic-configuration.js, automatically jumping to line 1537, column 8. The user can make direct modifications to the target program source code.
The process of the browser analyzing the temporary webpage source code to generate the second webpage element may be that the browser directly obtains the temporary webpage source code, analyzes the temporary webpage source code, and directly generates the second webpage element.
The temporary webpage source code may also be added to the current webpage source code. And then the browser acquires the webpage source code added with the temporary webpage source code and analyzes the webpage source code, so that the whole webpage is displayed. The entire web page includes a second web page element.
In order to avoid the problem that the first position information cannot be displayed because it is covered by other web page elements of the current web page, the temporary web page source code may be added to the highest layer of the current web page source code. Since the web page source code is a tree structure, the temporary web page source code can be added to the highest layer of the tree structure.
The method comprises the steps of obtaining a first webpage element corresponding to a cursor, and determining first position information of a target program source code corresponding to the first webpage element in a target webpage source code of the first webpage element. And generating a temporary webpage source code for describing the first position information, so that the browser can generate a second webpage element for displaying the first position information by analyzing the temporary webpage source code. According to the technical scheme, the function of automatically displaying the position information of the target program source code corresponding to the first webpage element corresponding to the cursor is achieved, the position of the target program source code does not need to be found manually, time and labor are saved, and the efficiency of positioning the program source code is improved.
In one possible implementation manner, before generating the temporary web page source code for describing the first location information, the method further includes: determining second position information of the first webpage element in the current webpage. Generating temporary web page source code describing the first location information, including: determining third position information of the second webpage element corresponding to the temporary webpage source code in the current webpage according to the second position information; the distance between the second position information and the third position information is smaller than a preset threshold value; and generating the temporary webpage source code according to the third position information.
For example, the first web page element is determined to be an input box, the second position information of the input box in the current web page is coordinates of the lower left corner and the upper right corner, which are (500 ) and (600 ), respectively, and the size of the input box is determined to be 100 × 100. If the distance between the second webpage element and the first webpage element is short, the distance between the third position information and the second position information of the second webpage element in the current webpage is smaller than a preset threshold value, so that the distance between the second webpage element and the first webpage element is not too far. The second webpage element corresponding to the temporary webpage source code generated according to the third position information is not too far away from the first webpage element.
According to a specific implementation manner, the generated temporary webpage source code may carry the position, size, color and style of the mark and the position, size, color and style of a display frame displaying the first position information. The second web page element is generated in a more colorful form. Highlighting the first web page element can prompt the user which web page element's program source code corresponds to the currently displayed position information.
In this way, the first location information of the source code of the target program can be displayed at a position closer to the first webpage element, rather than at any position of the webpage at random.
The following describes a method for including location information in the source code of the target web page.
In a possible implementation manner, a front plug-in is arranged before the compiler, and the front plug-in is used for intercepting program source codes sent to the compiler and modifying the program source codes. The modified program source code carries the position information of the program source code corresponding to each webpage element. And sending the modified program source code into a compiler, and compiling the program source code by the compiler to obtain a webpage source code, wherein the webpage source code carries position information. The target web page source code in such web page source code naturally also contains the first position information of the target program source code.
Specifically, fig. 5 shows a detailed step of determining the target web page source code corresponding to the first web page element, which includes:
step 501, converting an original program source code file of the webpage file into an abstract syntax tree aiming at the webpage file where the first webpage element is located;
step 502, extracting the position information of a program source code corresponding to any webpage element in the abstract syntax tree from the program character information of the abstract syntax tree aiming at the webpage element in the webpage file;
step 503, adding the position information as an execution element to a tag or a function syntax of a program source code corresponding to the web page element;
step 504, converting the abstract syntax tree added with the execution elements into an updated program source code file; the updating program source code file is used for being compiled by a compiler to obtain a webpage source code corresponding to the webpage file;
and 505, determining the target webpage source code in the webpage source codes.
In step 501, for the web page file where the first web page element is located, an original program source code file of the web page file is converted into an abstract syntax tree. Specifically, character streams in source code files of original programs with the suffix names js (javascript file), jsx (javascript syntax extension), mjs (javascript module), ts (typescript file), tsx (typescript syntax extension) and vue (vue component file) are read, and after annotations and blank characters (linefeed characters, spaces and table making characters) in the character streams are filtered out, each keyword, operational character, tag character and punctuation mark in the character streams are extracted, and the result is stored as a program character unit. Analyzing all program character units, converting the program character units into abstract syntax trees with syntax meanings and program character information, verifying syntax, and stopping the program for converting the abstract syntax trees if syntax errors are contained.
The program source code may be a web page source code generated by a tag, or a web page source code generated by a function. The abstract syntax tree for translation is different for different program source codes. FIG. 6a shows a schematic diagram of an abstract syntax tree into which program source code for generating web page source code by tags is translated. FIG. 6b shows a diagram of an abstract syntax tree into which program source code for generating web page source code by a function is translated.
In step 502, for any web page element in the web page file, extracting position information of a program source code corresponding to the web page element from the program character information of the abstract syntax tree.
Because the webpage source code is always generated through the label or the function, the label or the function grammar for generating the webpage source code can be analyzed from the abstract grammar tree through the characteristic, the program character information in the grammars is extracted, and the code position and the file position information contained in the program character information are spliced into the character string for positioning the code. For example, in the current web page file "search. Js", for any web page element in the web page file, the position information of the program source code corresponding to the web page element is extracted from the program character information of the abstract syntax tree, and is shown as the 100 th row and the 8 th column. The spliced character string is "/search. Js: 8". Which indicates that the program source code is located in row 100, column 8 of the search. Js file.
In step 503, the position information is added as an execution element to a tag or a function syntax of the program source code corresponding to the web page element.
And modifying the extracted label or function grammar, and adding the character strings for code positioning as attributes or parameters into the label or function grammar of the program source codes corresponding to the webpage elements, so that the updated program source code file carries the position information of each program source code. For example, the program source code "createlement ('div')" defaults to a generated web page source code of "< div/>, and by parsing and modifying the abstract syntax tree, the final web page source code will become < div data-symbol ="/search. Js:100 "/>.
In step 504, the abstract syntax tree with the added execution elements is converted into an updated program source code file; and the updating program source code file is used for being compiled by a compiler to obtain the webpage source code corresponding to the webpage file.
Because the position information is added to the program source code of each webpage element in the abstract syntax tree, each program source code in the converted updated program source code file carries the position information. The web page source code compiled by the compiler will also carry location information.
Fig. 7 shows a schematic diagram of a possible conversion process of the modified abstract syntax tree- > update program source code file- > web page source code, and it can be seen that the finally generated web page source code carries position information of the corresponding program source code.
The steps 501 to 504 are completed by the front plug-in, and after the completion, the update program source code file is sent to the compiler, and the compiler compiles the update program source code file to obtain the web page source code corresponding to the web page file.
The steps 501 to 504 may be completed after the first web page element is acquired, or may be completed before the first web page element corresponding to the cursor position is acquired, that is, completed in advance in batch, which is not limited in this embodiment of the present invention. The scheme for completing the modification of the program source code before the first web page element corresponding to the cursor position is obtained is shown in the corresponding embodiment of fig. 8.
And 505, determining the target webpage source code in the webpage source codes.
Through the execution of the steps 501 to 504, the webpage source codes carrying the position information of the program source codes corresponding to the webpage elements are obtained. The web page source code is compiled from the update source code file. And determining a target webpage source code corresponding to the first webpage element in the webpage source code, wherein the target webpage source code has first position information of the target program source code.
The original program source code file is converted into the abstract syntax tree, and the position information of the program source code corresponding to any webpage element can be automatically and quickly extracted. And then adding the position information as an execution element to a label or a function syntax of a program source code corresponding to the webpage element, wherein each program source code in the updated program source code file obtained in the way carries the position information of the program source code. The source code of the web page compiled from the source code file of the updated program also carries the location information of the source code of the corresponding program. Therefore, the function of automatically adding the position information corresponding to the program source code in the webpage source code is realized. The target webpage source code determined in the webpage source code carries the first position information of the target program source code corresponding to the first webpage element.
In some embodiments, because the programmer may make changes to the source code, each change may cause the location of some source code to change, for example, it was in line 8 and now becomes line 10. In order to ensure that the location information of the displayed program code is accurate, steps 501-505 need to be performed in a timely manner.
Because the compiler has the capability of monitoring, reading and analyzing files, the compiler can send a program source code change prompt message after monitoring that the original program source code file is changed. Therefore, the front plug-in can be configured to intercept the program source code change prompting message sent by the compiler, and after acquiring the message, the front plug-in can execute steps 501-504. Thus, updated webpage source codes are obtained, wherein the updated webpage source codes comprise updated position information of the program source codes.
For ease of understanding, fig. 8 provides a general description of the method provided in the embodiments of the present application. The method provided by the embodiment of the application is executed and completed by the front plug-in, the compiler, the rear plug-in and the browser.
Step 801, a front plug-in converts an original program source code file of any webpage file into an abstract syntax tree for the webpage file.
Step 802, the front plug-in extracts, for any webpage element in the webpage file, position information of a program source code corresponding to the webpage element from the program character information of the abstract syntax tree.
And 803, the front plug-in adds the position information as an execution element to a label or a function syntax of a program source code corresponding to the webpage element.
And step 804, the front plug-in converts the abstract syntax tree added with the execution elements into an update program source code file.
Step 805, the compiler compiles the source code file of the update program to obtain the webpage source code corresponding to the webpage file.
In step 806, the back plug-in receives a location code opening command sent by the user.
Step 807, the post-plug-in obtains a first webpage element corresponding to the cursor position of the cursor on the current webpage; and determining a target webpage source code corresponding to the first webpage element.
Step 808, the post plug-in determines the target webpage source code from the webpage source codes obtained in step 805, and determines first position information of a target program source code corresponding to the first webpage element from the target webpage source code.
And step 809, generating a temporary webpage source code for describing the first position information by the post plug-in, and adding the temporary webpage source code to the highest layer in the current webpage source code.
And 810, analyzing the current webpage source code added with the temporary webpage source code by the browser, and generating a second webpage element capable of displaying the first position information for the user to view.
Based on the same technical concept, fig. 9 exemplarily shows a structure of an apparatus for locating a program source code position, which can perform a process for locating a program source code position according to an embodiment of the present invention.
As shown in fig. 9, the apparatus specifically includes:
an obtaining unit 901 configured to: acquiring a first webpage element corresponding to the cursor position of a current webpage; determining a target webpage source code corresponding to the first webpage element;
a processing unit 902 for:
determining first position information of a target program source code corresponding to the first webpage element in the target webpage source code;
and generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by a browser.
In some embodiments, the obtaining unit 901 is specifically configured to:
converting an original program source code file of the webpage file into an abstract syntax tree aiming at the webpage file where the first webpage element is located;
extracting the position information of a program source code corresponding to the webpage element from the program character information of the abstract syntax tree aiming at any webpage element in the webpage file;
adding the position information serving as an execution element into a label or a function syntax of a program source code corresponding to the webpage element;
converting the abstract syntax tree added with the execution elements into an updated program source code file; the updating program source code file is used for being compiled by a compiler to obtain a webpage source code corresponding to the webpage file;
and determining the target webpage source code in the webpage source codes.
In some embodiments, the processing unit 902 is specifically configured to:
if it is determined that the target webpage source code does not contain the position information of the target program source code corresponding to the first webpage element, determining the superior position information of the superior program source code in the superior webpage source code of the target webpage source code, and taking the superior position information as the first position information.
In some embodiments, the processing unit 902 is further configured to:
determining second position information of the first webpage element in the current webpage;
the processing unit 902 is specifically configured to:
determining third position information of the second webpage element corresponding to the temporary webpage source code in the current webpage according to the second position information; the distance between the second position information and the third position information is smaller than a preset threshold value;
and generating the temporary webpage source code according to the third position information.
In some embodiments, the processing unit 902 is further configured to:
and adding the temporary webpage source code to the highest layer in the current webpage source code.
In some embodiments, the processing unit 902 is further configured to:
receiving a program source code change prompt message sent by a compiler; and the compiler is used for sending a program source code change prompt message after monitoring that the original program source code file is changed.
In some embodiments, the obtaining unit 901 is further configured to:
and receiving a positioning code opening position command sent by a user.
In some embodiments, the processing unit is further to:
after the triggering operation aiming at the second webpage element is detected, the first position information is obtained;
displaying a target page according to the first position information; and the target page comprises a target program source code corresponding to the first webpage element.
Based on the same technical concept, the embodiment of the present application provides a computer device, as shown in fig. 10, including at least one processor 1001 and a memory 1002 connected to the at least one processor, where a specific connection medium between the processor 1001 and the memory 1002 is not limited in the embodiment of the present application, and the processor 1001 and the memory 1002 in fig. 10 are connected through a bus as an example. The bus may be divided into an address bus, a data bus, a control bus, etc.
In the embodiment of the present application, the memory 1002 stores instructions executable by the at least one processor 1001, and the at least one processor 1001 may execute the steps of the method for locating the source code position of the program by executing the instructions stored in the memory 1002.
The processor 1001 is a control center of the computer device, and may connect various parts of the computer device through various interfaces and lines, and perform positioning of the source code position of the program by executing or executing the instructions stored in the memory 1002 and calling the data stored in the memory 1002. In some embodiments, processor 1001 may include one or more processing units, and processor 1001 may integrate an application processor, which primarily handles operating systems, user interfaces, applications, etc., and a modem processor, which primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 1001. In some embodiments, the processor 1001 and the memory 1002 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 1001 may be a general-purpose processor, such as a Central Processing Unit (CPU), a digital signal processor, an Application Specific Integrated Circuit (ASIC), a field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or the like, and may implement or perform the methods, steps, and logic blocks disclosed in the embodiments of the present Application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of a method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware processor, or may be implemented by a combination of hardware and software modules in a processor.
The memory 1002, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 1002 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and so on. The memory 1002 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 1002 in the embodiments of the present application may also be circuitry or any other device capable of performing a storage function to store program instructions and/or data.
Based on the same technical concept, an embodiment of the present invention further provides a computer-readable storage medium, where a computer-executable program is stored, and the computer-executable program is configured to enable a computer to execute the method for locating a source code position of a program listed in any one of the above manners.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for locating a source code location of a program, comprising:
acquiring a first webpage element corresponding to the cursor position of a cursor on a current webpage; determining a target webpage source code corresponding to the first webpage element;
determining first position information of a target program source code corresponding to the first webpage element in the target webpage source code;
and generating a temporary webpage source code for describing the first position information, wherein the temporary webpage source code is used for generating a second webpage element for displaying the first position information after being analyzed by a browser.
2. The method of claim 1, wherein determining the target web page source code for the first web page element comprises:
converting an original program source code file of the webpage file into an abstract syntax tree aiming at the webpage file where the first webpage element is located;
extracting the position information of a program source code corresponding to the webpage element from the program character information of the abstract syntax tree aiming at any webpage element in the webpage file;
adding the position information serving as an execution element into a label or a function syntax of a program source code corresponding to the webpage element;
converting the abstract syntax tree added with the execution elements into an updated program source code file; the updating program source code file is used for being compiled by a compiler to obtain a webpage source code corresponding to the webpage file;
and determining the target webpage source code in the webpage source codes.
3. The method of claim 1, wherein determining first location information of target program source code corresponding to the first web page element in the target web page source code comprises:
if it is determined that the target webpage source code does not contain the position information of the target program source code corresponding to the first webpage element, determining the superior position information of the superior program source code in the superior webpage source code of the target webpage source code, and taking the superior position information as the first position information.
4. The method of claim 1, prior to generating temporary web page source code describing the first location information, further comprising:
determining second position information of the first webpage element in the current webpage;
generating a temporary web page source code for describing the first location information, comprising:
determining third position information of the second webpage element corresponding to the temporary webpage source code in the current webpage according to the second position information; the distance between the second position information and the third position information is smaller than a preset threshold value;
and generating the temporary webpage source code according to the third position information.
5. The method of claim 1, further comprising:
and adding the temporary webpage source code to the highest layer in the current webpage source code.
6. The method of claim 2, prior to converting the source code file of the original program to the abstract syntax tree, further comprising:
receiving a program source code change prompt message sent by a compiler; and the compiler is used for sending a program source code change prompt message after monitoring that the original program source code file is changed.
7. The method of claim 1, wherein obtaining the web page element with the cursor corresponding to the cursor position of the current web page further comprises:
and receiving a positioning code opening position command sent by a user.
8. The method of claim 1, after generating temporary web page source code describing the first location information, further comprising:
after the trigger operation aiming at the second webpage element is detected, acquiring the first position information;
displaying a target page according to the first position information; and the target page comprises a target program source code corresponding to the first webpage element.
9. A computing device, comprising:
a memory for storing a computer program;
a processor for calling a computer program stored in said memory and executing the method of any one of claims 1 to 8 in accordance with the obtained program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer-executable program for causing a computer to execute the method of any one of claims 1 to 8.
CN202310064875.7A 2023-01-12 2023-01-12 Method for positioning program source code position and computing equipment Pending CN115951888A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310064875.7A CN115951888A (en) 2023-01-12 2023-01-12 Method for positioning program source code position and computing equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310064875.7A CN115951888A (en) 2023-01-12 2023-01-12 Method for positioning program source code position and computing equipment

Publications (1)

Publication Number Publication Date
CN115951888A true CN115951888A (en) 2023-04-11

Family

ID=87290846

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310064875.7A Pending CN115951888A (en) 2023-01-12 2023-01-12 Method for positioning program source code position and computing equipment

Country Status (1)

Country Link
CN (1) CN115951888A (en)

Similar Documents

Publication Publication Date Title
JP7017613B2 (en) Naming Robotic Process Automation activities based on auto-discovered target labels
CN102073490B (en) Method and device for translating database language
CN113822067A (en) Key information extraction method and device, computer equipment and storage medium
US20130185622A1 (en) Methods and systems for handling annotations and using calculation of addresses in tree-based structures
CN108027721B (en) Techniques for configuring a general program using controls
WO2017031459A1 (en) Integrated software development environments, systems, methods, and memory models
US20080244510A1 (en) Visual creation of object/relational constructs
KR102565455B1 (en) Domain-specific language interpreter and interactive visual interface for rapid screening
CN106471476A (en) For to optimized code edit and continue and enhanced optimized debugging technology
US11886895B2 (en) Enhanced target selection for robotic process automation
CN111611468B (en) Page interaction method and device and electronic equipment
CN107203468A (en) A kind of software version evolution comparative analysis method based on AST
JP2022551933A (en) System and method of activity target selection for robotic process automation
CN108170661B (en) Method and system for managing rule text
CN111475196A (en) Compiling alarm tracing method and device, electronic equipment and computer readable medium
CN113419721B (en) Web-based expression editing method, device, equipment and storage medium
CN104778232A (en) Searching result optimizing method and device based on long query
CN115951888A (en) Method for positioning program source code position and computing equipment
CN114089980A (en) Programming processing method, device, interpreter and nonvolatile storage medium
CN112230904A (en) Code generation method and device based on interface document, storage medium and server
CN113176878B (en) Automatic query method, device and equipment
CN117520690B (en) UI (user interface) automation method and related device based on CSS (CSS style) style prerendering contrast
KUMAR et al. A PROJECT
CN110618809B (en) Front-end webpage input constraint extraction method and device
CN115269107B (en) Method, medium and electronic device for processing interface image

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination