@@ -10,83 +10,28 @@ import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, ge
10
10
* A utility module for working with code.
11
11
*/
12
12
const cbcodeutils = {
13
-
13
+
14
14
/**
15
15
* Retrieves a JavaScript tree structure for a given file path.
16
16
* @param {string } filePath - The path of the file to retrieve the JS tree for.
17
17
* @returns {Promise<GetJsTreeResponse> } A promise that resolves with the JS tree response.
18
18
*/
19
19
getJsTree : ( filePath ?: string ) => {
20
- // return new Promise( async (resolve, reject) => {
21
- // cbws.getWebsocket.send(JSON.stringify({
22
- // "type": "settingEvent",
23
- // "action": "getProjectPath"
24
- // }));
25
- // cbws.getWebsocket.on('message', (data: string) => {
26
- // const response = JSON.parse(data);
27
- // if (response.type === "getProjectPathResponse") {
28
- // // resolve(response);
29
- // try {
30
- // let pathInput= response.projectPath;
31
- // let parser= new Parser();
32
- // // Initialize the parser with the JavaScript language
33
- // parser.setLanguage(JavaScript);
34
- // const trees = [];
35
- // const functionNodes = [];
36
-
37
- // const processDirectory = (directory:any) => {
38
- // console.log("isdir")
39
- // // Read all files in the directory
40
- // const files = fs.readdirSync(directory, { withFileTypes: true });
41
-
42
- // files.forEach(file => {
43
- // if (file.isDirectory()) {
44
- // if (file.name !== 'node_modules') { // Ignore node_modules directory
45
- // processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
46
- // }
47
- // } else if (path.extname(file.name) === '.js') {
48
- // const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
49
- // console.log(code);
50
- // let tree:any = parser.parse(code);
51
- // tree.rootNode.path = path.join(directory, file.name); // Set file path for t
52
- // trees.push(tree);
53
- // }
54
- // });
55
- // };
56
-
57
- // if (fs.lstatSync(pathInput).isDirectory()) {
58
- // processDirectory(pathInput);
59
- // } else if (path.extname(pathInput) === '.js') {
60
- // // Read a single JavaScript file
61
- // const code = fs.readFileSync(pathInput, 'utf-8');
62
- // let tree:any = parser.parse(code);
63
- // tree.rootNode.path = pathInput; // Set file path for t
64
-
65
- // trees.push(tree);
66
- // }
67
-
68
- // resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
69
- // } catch (error) {
70
- // console.error('An error occurred:', error);
71
- // return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
72
- // }
73
- // }
74
- // });
75
-
76
- // // cbws.getWebsocket.send(JSON.stringify({
77
- // // "type": "codeEvent",
78
- // // "action":"getJsTree",
79
- // // payload:{
80
- // // filePath
81
- // // }
82
- // // }));
83
- // // cbws.getWebsocket.on('message', (data: string) => {
84
- // // const response = JSON.parse(data);
85
- // // if (response.type === "getJsTreeResponse") {
86
- // // resolve(response); // Resolve the Promise with the response data
87
- // // }
88
- // // });
89
- // });
20
+ return new Promise ( async ( resolve , reject ) => {
21
+ cbws . getWebsocket . send ( JSON . stringify ( {
22
+ "type" : "codeEvent" ,
23
+ "action" : "getJsTree" ,
24
+ payload : {
25
+ filePath
26
+ }
27
+ } ) ) ;
28
+ cbws . getWebsocket . on ( 'message' , ( data : string ) => {
29
+ const response = JSON . parse ( data ) ;
30
+ if ( response . type === "getJsTreeResponse" ) {
31
+ resolve ( response ) ; // Resolve the Promise with the response data
32
+ }
33
+ } ) ;
34
+ } ) ;
90
35
} ,
91
36
92
37
/**
@@ -97,13 +42,13 @@ const cbcodeutils = {
97
42
return new Promise ( ( resolve , reject ) => {
98
43
cbws . getWebsocket . send ( JSON . stringify ( {
99
44
"type" : "codeEvent" ,
100
- "action" :"getAllFilesMarkdown"
45
+ "action" : "getAllFilesMarkdown"
101
46
} ) ) ;
102
47
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
103
48
const response = JSON . parse ( data ) ;
104
49
if ( response . type === "getAllFilesMarkdownResponse" ) {
105
50
resolve ( response ) ; // Resolve the Promise with the response data
106
- }
51
+ }
107
52
} ) ;
108
53
} ) ;
109
54
} ,
@@ -119,8 +64,8 @@ const cbcodeutils = {
119
64
return new Promise ( ( resolve , reject ) => {
120
65
cbws . getWebsocket . send ( JSON . stringify ( {
121
66
"type" : "codeEvent" ,
122
- "action" :"performMatch" ,
123
- payload :{
67
+ "action" : "performMatch" ,
68
+ payload : {
124
69
matcherDefinition,
125
70
problemPatterns,
126
71
}
@@ -129,9 +74,9 @@ const cbcodeutils = {
129
74
const response = JSON . parse ( data ) ;
130
75
if ( response . type === "getgetJsTreeResponse" ) {
131
76
resolve ( response ) ; // Resolve the Promise with the response data
132
- }
77
+ }
133
78
} ) ;
134
- } ) ;
79
+ } ) ;
135
80
} ,
136
81
137
82
/**
@@ -142,15 +87,15 @@ const cbcodeutils = {
142
87
return new Promise ( ( resolve , reject ) => {
143
88
cbws . getWebsocket . send ( JSON . stringify ( {
144
89
"type" : "codeEvent" ,
145
- "action" :"getMatcherList" ,
90
+ "action" : "getMatcherList" ,
146
91
} ) ) ;
147
92
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
148
93
const response = JSON . parse ( data ) ;
149
94
if ( response . type === "getMatcherListTreeResponse" ) {
150
95
resolve ( response ) ; // Resolve the Promise with the response data
151
- }
96
+ }
152
97
} ) ;
153
- } ) ;
98
+ } ) ;
154
99
} ,
155
100
156
101
/**
@@ -162,18 +107,18 @@ const cbcodeutils = {
162
107
return new Promise ( ( resolve , reject ) => {
163
108
cbws . getWebsocket . send ( JSON . stringify ( {
164
109
"type" : "codeEvent" ,
165
- "action" :"getMatchDetail" ,
166
- payload :{
167
- match :matcher
110
+ "action" : "getMatchDetail" ,
111
+ payload : {
112
+ match : matcher
168
113
}
169
114
} ) ) ;
170
115
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
171
116
const response = JSON . parse ( data ) ;
172
117
if ( response . type === "matchDetailTreeResponse" ) {
173
118
resolve ( response ) ; // Resolve the Promise with the response data
174
- }
119
+ }
175
120
} ) ;
176
- } ) ;
121
+ } ) ;
177
122
}
178
123
179
124
} ;
0 commit comments