Source code fault-tolerant segmentation method suitable for real-time collaborative programming environment

By dynamically updating the boundary information of code area in real-time collaborative programming environment, the syntax error problem caused by unfinished code snippets in real-time collaborative programming is solved, the semantic conflict prevention ability is improved, and the stability and accuracy of code snippets are ensured.

CN118963723APending Publication Date: 2024-11-15TONGJI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411020834.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

In a real-time collaborative programming environment, multiple developers edit source code at the same time may lead to syntax errors caused by unfinished code snippets, affecting the effectiveness of dependency-based automatic locking (DAL) methods, and thus affecting semantic conflict prevention.

Method used

By obtaining the target source code file, generating an abstract syntax tree, dynamically identifying and updating the boundary information of the code area, using offset adjustment algorithm, insertion processing algorithm and delete processing algorithm, ensuring the accuracy and stability of the boundary information of the code area, and re-repeat regularly Divide code areas.

Benefits of technology

It realizes accurate identification and tracking of source code logical segmentation in a real-time collaborative programming environment, improves semantic conflict prevention capabilities, ensures the stability and accuracy of code segmentation, and avoids the impact of syntax errors on the DAL method.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963723A_ABST
    Figure CN118963723A_ABST
Patent Text Reader

Abstract

The invention relates to a source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment, and the method comprises the following steps: obtaining a target source code file, preliminarily dividing a source code into a plurality of code regions through a code analysis technology, and constructing a code region list; editing operation in the real-time collaborative programming process is obtained, the editing operation comprises insertion operation and deletion operation, and according to the type of the editing operation, boundary information of each code area is dynamically updated through an offset adjustment algorithm, an insertion processing algorithm and a deletion processing algorithm; and regularly performing code region division on the source code of the target file again through a code analysis technology, and updating the code region list. Compared with the prior art, the method has the advantages that the source code logic segments of the target file can be dynamically identified and continuously tracked, and the semantic conflict prevention capability of the real-time collaborative programming environment is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of software development, and in particular relates to a source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment. Background Art

[0002] Real-time collaborative programming is a novel software development technology that allows multiple developers to edit the same set of software project source code files at the same time and see each other's modifications instantly. The technology maintains the consistency of all collaborators' local source code copies by detecting, converting, and broadcasting editing operations. This approach simulates the experience of programmers working side by side, improving collaboration efficiency and productivity. Due to its ability to promote seamless cooperation between team members, real-time collaborative programming is increasingly being used in various programming scenarios, including pair programming, code review, remote technical support, and interactive education.

[0003] In a real-time collaborative session, programmers' tasks are often highly related, which may lead to semantic conflicts when programmers work on code regions with dependencies (such as functions). To address this problem, dependency-based automatic locking (DAL) technology has emerged, which prevents semantic conflicts by prohibiting concurrent editing of specific code regions. However, one of the limitations of the DAL method is that it is highly dependent on source code analysis technology, and its effectiveness may be greatly reduced once syntax errors appear in the source code. A core step of the DAL process is to identify code regions from source code files. However, in the real-time collaborative programming process, due to the simultaneous editing of multiple developers, there may be unfinished code fragments, resulting in syntax errors. Therefore, the technology used to analyze source code elements to identify code regions may fail, affecting the effectiveness of the DAL method. Therefore, it is necessary to design a source code fault-tolerant segmentation method suitable for real-time collaborative programming environments, which can dynamically identify and continuously track the logical segmentation of source code, and further improve the semantic conflict prevention capability of real-time collaborative programming environments. Summary of the invention

[0004] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment, dynamically identify and continuously track the logical segmentation of the source code, and further enhance the semantic conflict prevention capability of the real-time collaborative programming environment.

[0005] The purpose of the present invention can be achieved by the following technical solutions:

[0006] The present invention provides a source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment, comprising the following steps:

[0007] Obtain a target source code file, preliminarily divide the source code of the target file into several code regions by using code analysis technology, and construct a code region list;

[0008] Obtain the editing operations in the real-time collaborative programming process, including insertion operations and deletion operations, and dynamically update the boundary information of each code area through the offset adjustment algorithm, insertion processing algorithm, and deletion processing algorithm according to the type of editing operation;

[0009] The source code of the target file is periodically re-divided into code areas by using code analysis technology, and the code area list is updated.

[0010] Furthermore, the source code of the target file is initially divided into several code regions through code analysis technology, and the specific process of constructing a code region list is as follows:

[0011] Generate an abstract syntax tree of the source code in the target file;

[0012] Obtaining an abstract syntax tree node representing a function from the abstract syntax tree;

[0013] Convert an abstract syntax tree node representing a function into code region information to obtain multiple code regions;

[0014] Group these code regions into a code region list.

[0015] Furthermore, the specific steps of the offset adjustment algorithm are as follows:

[0016] Get the offset offset caused by the editing operation, the serial number regionNum of the code region affected by the editing operation, and the code region list Regions;

[0017] Traverse all elements in the code region list Regions from regionNum to the end, and adjust the boundary information of the traversed region according to the value of offset.

[0018] Furthermore, when the editing operation is an insert operation, the boundary information of each code region is dynamically updated according to the position of the insertion point through the insertion processing algorithm.

[0019] Furthermore, in the insertion processing algorithm, when the insertion point is within the boundary of a code region, this operation is regarded as a modification of the code region, the length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the code region and its subsequent code regions.

[0020] Furthermore, in the insertion processing algorithm, when the insertion point is located between two adjacent code areas, a new code area is created and added to the code area list, and the length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of subsequent code areas.

[0021] Furthermore, when the editing operation is a deletion operation, the boundary information of each code area is dynamically updated according to the range of the deletion area through the deletion processing algorithm.

[0022] Furthermore, in the deletion processing algorithm, when the deleted area does not involve any code area, the negative value of the length of the deleted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the subsequent code area.

[0023] Furthermore, in the deletion processing algorithm, when the deletion area involves a code area, if the deletion area completely contains the code area, the code area is added to the list of areas to be deleted; otherwise, the negative value of the length of the deleted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the code area and its subsequent code areas.

[0024] Furthermore, in the deletion processing algorithm, when the deletion area involves multiple code areas, the boundary information of the first code area involved is adjusted through the offset adjustment algorithm, and its sequence number is designated as the area to be merged, and the remaining code areas involved are merged.

[0025] Compared with the prior art, the present invention has the following beneficial effects:

[0026] 1. The present invention firstly divides the source code of the target file into several code areas and constructs a code area list through code analysis technology, then obtains the editing operations in the real-time collaborative programming process, and dynamically updates the boundary information of each code area through an offset adjustment algorithm, an insertion processing algorithm and a deletion processing algorithm according to the type of editing operation. The editing operation includes an insertion operation and a deletion operation (basic operations in programming work). The source code of the target file is regularly re-divided into code areas through code analysis technology, and the code area list is updated; through the above steps, the logical segmentation of the source code of the target file can be dynamically identified and continuously tracked, and the boundary information of each code area can be accurately maintained. Even if the source code is in an active state of continuous editing, the stability and accuracy of the segmentation can be ensured without the need to deeply intervene in the complex syntax parsing process.

[0027] 2. When the present invention preliminarily divides the target source code file into several code regions, it first generates an abstract syntax tree of the source code in the target file, then obtains the abstract syntax tree nodes representing the functions therefrom, and then converts the abstract syntax tree nodes representing the functions into code region information to obtain multiple code regions, and finally organizes these code regions into a code region list. The above process uses functions as the unit of code segmentation, which can make the code segmentation more refined. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 is a flow chart of the method of the present invention;

[0029] Figure 2 An instance in which an unfinished code causes the Abstract Syntax Tree (AST) generation mechanism and the DAL mechanism to fail during real-time collaborative programming;

[0030] Figure 3 The figure is a general working flow chart of the method of the present invention. DETAILED DESCRIPTION

[0031] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.

[0032] Example:

[0033] In the process of real-time collaborative programming, semantic conflicts may occur when programmers work on code areas with dependencies (such as functions). To solve this problem, dependency-based automatic locking (DAL) technology has emerged, which prevents semantic conflicts by prohibiting concurrent editing of specific code areas. One of the core steps of the DAL process is to identify code areas from source code files, such as Figure 2 As shown in the figure, when there are no syntax errors, the system can obtain the code area (functions foo and bar) in the code by generating an abstract syntax tree (AST), and then lock the code area according to the calling relationship between the foo and bar functions and the position that the programmer is editing. At this time, other collaborative programmers cannot modify the locked code area, thus preventing semantic conflicts. However, in the process of real-time collaborative programming, due to multiple programmers editing at the same time, there may be unfinished code fragments, which may lead to syntax errors. When there are syntax errors (such as Figure 2 As shown, the existence of unfinished code 'b=') will cause the Abstract Syntax Tree (AST) generation mechanism and the DAL mechanism to fail, thereby affecting the effectiveness of the DAL method.

[0034] This embodiment provides a source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment, aiming to support accurate code segmentation in the real-time collaborative programming process, so as to ensure the effectiveness of the DAL method and further enhance the semantic conflict prevention capability of the real-time collaborative programming environment. Figure 1 As shown, the specific steps include:

[0035] S1. Obtain the target source code file, and use code analysis technology to preliminarily divide the source code of the target file into several code regions and form a code region list. The specific process is as follows:

[0036] S101. Generate an abstract syntax tree of the source code in the target file.

[0037] S102: Obtain an abstract syntax tree node representing the function from the abstract syntax tree.

[0038] S103: Convert the abstract syntax tree node representing the function into code region information to obtain multiple code regions.

[0039] S104: These code regions are combined into a code region list.

[0040] S2. Obtain the editing operations of real-time collaborative programming, including insert operations and delete operations, and dynamically update the boundary information of each code area through an offset adjustment algorithm, an insertion processing algorithm, and a deletion processing algorithm according to the type of the editing operation.

[0041] Insertion and deletion operations are the basic operations of programming. Insertion operation is to insert content (string) into a given position, which is defined as follows:

[0042] insert(position,content)

[0043] The parameter "position" indicates the character offset from the beginning of the document to the insertion point, and the parameter "content" indicates the string type text to be inserted.

[0044] The delete operation is to delete the content (string) of the specified length from the specified position, which is defined as follows:

[0045] deleta(position,length)

[0046] The parameter "position" indicates the character distance from the operation position to the beginning of the file, and "length" indicates the length of the content to be deleted.

[0047] When a programmer modifies source code through a series of editing operations, each operation may introduce temporary syntax errors, so the code region cannot be identified by simple AST-based parsing. In this case, the system will dynamically update the boundary information of the code region based on the operation location and the content of each editing operation.

[0048] When editing a file, regardless of the type of operation, the position of each character after the operation position will change. Therefore, the corresponding range data of the code area should also be adjusted to reflect the offset caused by the operation. The specific steps of the offset adjustment algorithm are as follows:

[0049] Get the offset offset caused by the editing operation, the serial number regionNum of the code region affected by the editing operation, and the code region list Regions;

[0050] Traverse all elements in the code region list Regions from regionNum to the end, and adjust the boundary information of the traversed region according to the value of offset.

[0051] The offset adjustment algorithm can be implemented by the following pseudo code:

[0052]

[0053] The parameter "Regions" is a list of code regions identified by the AST, the parameter "regionNum" is the sequence number of the region affected by the operation, and the parameter "offset" is an integer representing the offset caused by the operation. Insertion operations produce a positive offset, while deletion operations produce a negative offset. The offset adjustment algorithm is a fundamental part of the update process and is called by both insertion and deletion operations.

[0054] When the editing operation is an insert operation, the boundary information of each code area is dynamically updated according to the position of the insertion point through the insertion processing algorithm, which is divided into the following two cases:

[0055] (1) When the insertion point is within the boundary of an existing code region, this operation is regarded as a modification of the code region, the length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the code region and its subsequent code regions.

[0056] (2) When the insertion point is between two adjacent code regions, this operation is regarded as an attempt to add a new code region. A new code region is created and added to the code region list. The length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the subsequent code region.

[0057] The above process can be implemented by the following pseudo code:

[0058]

[0059] The parameter "Region" refers to the data structure of a single code region, which is the basic element of the "Regions" collection. The variable "adjust" indicates whether all other steps are completed, so that the offset adjustment algorithm can be executed. In both cases, the algorithm will set the "adjust" flag to true at the end, indicating that the region data has been updated and the offset adjustment algorithm can be executed.

[0060] When the editing operation is a deletion operation, the boundary information of each code area is dynamically updated according to the range of the deletion area through the deletion processing algorithm, which is divided into the following six cases:

[0061] (1) Non-region range is deleted: If the deletion range ends before a code region begins, that is, the deletion does not involve this code region, it will not affect the content of this region. The algorithm then performs an offset adjustment algorithm to reflect the boundary value changes caused by the deletion.

[0062] (2) Region is completely deleted: If the deletion range completely includes a code region, the region will be completely deleted. At this time, the region will be added to the "Regions to be deleted" list, indicating that it will be completely removed.

[0063] (3) The end position of the region is deleted exactly: When the end position of the deletion range matches the end position of a code region, no more regions will be deleted after this region. At this time, the algorithm sets the "adjust" variable to true.

[0064] (4) The end position of the region is deleted and may affect the next region: If the deletion range includes the end position of a region and may affect the next region, the algorithm will adjust the end position of this code region and specify its sequence number as "region to be merged" to prepare for a possible merger with the next affected region.

[0065] (5) The start position of the region is deleted: If the deletion range affects the start position of a region, the algorithm will check whether there is a "region to be merged" to determine whether other regions are also affected. If such a region is found, the algorithm will merge all "regions to be merged" and set "adjust" to true. The above process shows how this algorithm handles the case where the end and start parts of two code regions are deleted separately to merge the two code regions into one code region.

[0066] (6) Deletion inside a region: For deletions that occur inside a region, that is, the deletion range is between the start and end positions of a region, the algorithm adjusts the end position of the affected region and sets "adjust" to true.

[0067] After the "adjust" flag is set to true, the system will execute the offset adjustment algorithm and finally delete all code areas in the "areas to be deleted" in the code area list.

[0068] The above process can be implemented by the following pseudo code:

[0069]

[0070]

[0071]

[0072] S3. Regularly re-divide the source code of the target file into code areas through code analysis technology, and update the code area list.

[0073] Although step S2 can maintain a set of area range data without reporting an error, it cannot fully guarantee the accuracy of the code segmentation. Figure 3 As shown, the source code parsing, AST node extraction, and range data conversion processes are periodically repeated to adjust the code region lists maintained by multiple update processes. This iterative process can be triggered at predetermined time intervals or when an edit operation is detected.

[0074] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention can essentially be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: hard disk, flash memory, mobile hard disk, read-only memory, magnetic disk or optical disk, etc., which can store program codes.

[0075] The above description of the embodiments is to facilitate the understanding and use of the invention by those skilled in the art. It is obvious that those skilled in the art can easily make various modifications to these embodiments and apply the general principles described herein to other embodiments without creative work. Therefore, the present invention is not limited to the above embodiments, and improvements and modifications made by those skilled in the art based on the disclosure of the present invention without departing from the scope of the present invention should be within the scope of protection of the present invention.

Claims

1. A source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment, characterized in that: The following steps are involved: Obtain a target source code file, preliminarily divide the source code of the target file into several code regions by using code analysis technology, and construct a code region list; Obtain the editing operations in the real-time collaborative programming process, including insertion operations and deletion operations, and dynamically update the boundary information of each code area through the offset adjustment algorithm, insertion processing algorithm and deletion processing algorithm according to the type of editing operation; The source code of the target file is periodically re-divided into code areas by using code analysis technology, and the code area list is updated.

2. A source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 1, characterized in that: The specific process of preliminarily dividing the source code of the target file into several code regions through code analysis technology and constructing the code region list is as follows: Generate an abstract syntax tree of the source code in the target file; Obtaining an abstract syntax tree node representing a function from the abstract syntax tree; Converting an abstract syntax tree node representing a function into code region information to generate multiple code regions; Group these code regions into a code region list.

3. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 1, characterized in that: The specific steps of the offset adjustment algorithm are as follows: Get the offset offset caused by the editing operation, the serial number regionNum of the code region affected by the editing operation, and the code region list Regions; Traverse all elements in the code region list Regions from regionNum to the end, and adjust the boundary information of the traversed region according to the value of offset.

4. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 1, characterized in that: When the editing operation is an insert operation, the boundary information of each code region is dynamically updated according to the position of the insertion point through the insertion processing algorithm.

5. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 4, characterized in that: In the insertion processing algorithm, when the insertion point is within the boundary of a code region, this operation is regarded as a modification of the code region, the length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the code region and its subsequent code regions.

6. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 4, characterized in that: In the insertion processing algorithm, when the insertion point is located between two adjacent code regions, a new code region is created and added to the code region list, the length of the inserted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the subsequent code region.

7. The method for fault-tolerant segmentation of source code suitable for a real-time collaborative programming environment according to claim 1, characterized in that: When the editing operation is a deletion operation, the boundary information of each code area is dynamically updated according to the range of the deletion area through the deletion processing algorithm.

8. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 7, characterized in that: In the deletion processing algorithm, when the deleted area does not involve any code area, the negative value of the length of the deleted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the subsequent code area.

9. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 7, characterized in that: In the deletion processing algorithm, when the deletion area involves a code area, if the deletion area completely contains the code area, the code area is added to the list of areas to be deleted; otherwise, the negative value of the length of the deleted content is used as the offset, and the offset adjustment algorithm is called to adjust the boundary information of the code area and its subsequent code areas.

10. The source code fault-tolerant segmentation method suitable for a real-time collaborative programming environment according to claim 7, characterized in that: In the deletion processing algorithm, when the deletion area involves multiple code areas, the boundary information of the first code area involved is adjusted through the offset adjustment algorithm, and its sequence number is designated as the area to be merged, and the remaining code areas involved are merged.