@@ -4,13 +4,8 @@ import cbws from './websocket';
4
4
* A utility module for working with code.
5
5
*/
6
6
const cbcodeutils = {
7
- /**
8
- * Asynchronously generates a code tree from the provided source code.
9
- * @param {any } fileName - The name of the file.
10
- * @param {any } source - The source code to generate the tree from.
11
- * @param {any } filePath - The file path where the source code is located.
12
- * @returns {Promise<any> } A promise that resolves with the code tree.
13
- */
7
+
8
+
14
9
getCodeTree : ( ) : Promise < any > => {
15
10
return new Promise ( ( resolve , reject ) => {
16
11
cbws . getWebsocket . send ( JSON . stringify ( {
@@ -25,6 +20,23 @@ const cbcodeutils = {
25
20
} ) ;
26
21
} ) ;
27
22
} ,
23
+ getJsTree : ( filePath :string ) : Promise < any > => {
24
+ return new Promise ( ( resolve , reject ) => {
25
+ cbws . getWebsocket . send ( JSON . stringify ( {
26
+ "type" : "codeEvent" ,
27
+ "action" :"getJsTree" ,
28
+ payload :{
29
+ filePath
30
+ }
31
+ } ) ) ;
32
+ cbws . getWebsocket . on ( 'message' , ( data : string ) => {
33
+ const response = JSON . parse ( data ) ;
34
+ if ( response . type === "getgetJsTreeResponse" ) {
35
+ resolve ( response . payload ) ; // Resolve the Promise with the response data
36
+ }
37
+ } ) ;
38
+ } ) ;
39
+ } ,
28
40
getAllFilesAsMarkDown :( ) => {
29
41
return new Promise ( ( resolve , reject ) => {
30
42
cbws . getWebsocket . send ( JSON . stringify ( {
@@ -38,6 +50,25 @@ const cbcodeutils = {
38
50
}
39
51
} ) ;
40
52
} ) ;
53
+ } ,
54
+ matchProblem :( matcherDefinition :object , problemPatterns :[ ] , problems :[ ] ) => {
55
+ return new Promise ( ( resolve , reject ) => {
56
+ cbws . getWebsocket . send ( JSON . stringify ( {
57
+ "type" : "codeEvent" ,
58
+ "action" :"getJsTree" ,
59
+ payload :{
60
+ matcherDefinition,
61
+ problemPatterns,
62
+ problems
63
+ }
64
+ } ) ) ;
65
+ cbws . getWebsocket . on ( 'message' , ( data : string ) => {
66
+ const response = JSON . parse ( data ) ;
67
+ if ( response . type === "getgetJsTreeResponse" ) {
68
+ resolve ( response . payload ) ; // Resolve the Promise with the response data
69
+ }
70
+ } ) ;
71
+ } ) ;
41
72
}
42
73
} ;
43
74
0 commit comments