Skip to content

Commit 056da98

Browse files
changes
1 parent 18fd7a7 commit 056da98

File tree

5 files changed

+48
-152
lines changed

5 files changed

+48
-152
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ declare class Codebolt {
150150
executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter<[never]>;
151151
};
152152
codeutils: {
153-
getJsTree: (filePath?: string | undefined) => void;
153+
getJsTree: (filePath?: string | undefined) => Promise<unknown>;
154154
getAllFilesAsMarkDown: () => Promise<string>;
155155
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
156156
getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;

modules/codeutils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare const cbcodeutils: {
88
* @param {string} filePath - The path of the file to retrieve the JS tree for.
99
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
1010
*/
11-
getJsTree: (filePath?: string) => void;
11+
getJsTree: (filePath?: string) => Promise<unknown>;
1212
/**
1313
* Retrieves all files as Markdown.
1414
* @returns {Promise<string>} A promise that resolves with the Markdown content of all files.

modules/codeutils.js

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,21 @@ const cbcodeutils = {
1414
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
1515
*/
1616
getJsTree: (filePath) => {
17-
// return new Promise( async (resolve, reject) => {
18-
// cbws.getWebsocket.send(JSON.stringify({
19-
// "type": "settingEvent",
20-
// "action": "getProjectPath"
21-
// }));
22-
// cbws.getWebsocket.on('message', (data: string) => {
23-
// const response = JSON.parse(data);
24-
// if (response.type === "getProjectPathResponse") {
25-
// // resolve(response);
26-
// try {
27-
// let pathInput= response.projectPath;
28-
// let parser= new Parser();
29-
// // Initialize the parser with the JavaScript language
30-
// parser.setLanguage(JavaScript);
31-
// const trees = [];
32-
// const functionNodes = [];
33-
// const processDirectory = (directory:any) => {
34-
// console.log("isdir")
35-
// // Read all files in the directory
36-
// const files = fs.readdirSync(directory, { withFileTypes: true });
37-
// files.forEach(file => {
38-
// if (file.isDirectory()) {
39-
// if (file.name !== 'node_modules') { // Ignore node_modules directory
40-
// processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
41-
// }
42-
// } else if (path.extname(file.name) === '.js') {
43-
// const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
44-
// console.log(code);
45-
// let tree:any = parser.parse(code);
46-
// tree.rootNode.path = path.join(directory, file.name); // Set file path for t
47-
// trees.push(tree);
48-
// }
49-
// });
50-
// };
51-
// if (fs.lstatSync(pathInput).isDirectory()) {
52-
// processDirectory(pathInput);
53-
// } else if (path.extname(pathInput) === '.js') {
54-
// // Read a single JavaScript file
55-
// const code = fs.readFileSync(pathInput, 'utf-8');
56-
// let tree:any = parser.parse(code);
57-
// tree.rootNode.path = pathInput; // Set file path for t
58-
// trees.push(tree);
59-
// }
60-
// resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
61-
// } catch (error) {
62-
// console.error('An error occurred:', error);
63-
// return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
64-
// }
65-
// }
66-
// });
67-
// // cbws.getWebsocket.send(JSON.stringify({
68-
// // "type": "codeEvent",
69-
// // "action":"getJsTree",
70-
// // payload:{
71-
// // filePath
72-
// // }
73-
// // }));
74-
// // cbws.getWebsocket.on('message', (data: string) => {
75-
// // const response = JSON.parse(data);
76-
// // if (response.type === "getJsTreeResponse") {
77-
// // resolve(response); // Resolve the Promise with the response data
78-
// // }
79-
// // });
80-
// });
17+
return new Promise(async (resolve, reject) => {
18+
websocket_1.default.getWebsocket.send(JSON.stringify({
19+
"type": "codeEvent",
20+
"action": "getJsTree",
21+
payload: {
22+
filePath
23+
}
24+
}));
25+
websocket_1.default.getWebsocket.on('message', (data) => {
26+
const response = JSON.parse(data);
27+
if (response.type === "getJsTreeResponse") {
28+
resolve(response); // Resolve the Promise with the response data
29+
}
30+
});
31+
});
8132
},
8233
/**
8334
* Retrieves all files as Markdown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.77",
3+
"version": "1.1.78",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/modules/codeutils.ts

Lines changed: 30 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,83 +10,28 @@ import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, ge
1010
* A utility module for working with code.
1111
*/
1212
const cbcodeutils = {
13-
13+
1414
/**
1515
* Retrieves a JavaScript tree structure for a given file path.
1616
* @param {string} filePath - The path of the file to retrieve the JS tree for.
1717
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
1818
*/
1919
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+
});
9035
},
9136

9237
/**
@@ -97,13 +42,13 @@ const cbcodeutils = {
9742
return new Promise((resolve, reject) => {
9843
cbws.getWebsocket.send(JSON.stringify({
9944
"type": "codeEvent",
100-
"action":"getAllFilesMarkdown"
45+
"action": "getAllFilesMarkdown"
10146
}));
10247
cbws.getWebsocket.on('message', (data: string) => {
10348
const response = JSON.parse(data);
10449
if (response.type === "getAllFilesMarkdownResponse") {
10550
resolve(response); // Resolve the Promise with the response data
106-
}
51+
}
10752
});
10853
});
10954
},
@@ -119,8 +64,8 @@ const cbcodeutils = {
11964
return new Promise((resolve, reject) => {
12065
cbws.getWebsocket.send(JSON.stringify({
12166
"type": "codeEvent",
122-
"action":"performMatch",
123-
payload:{
67+
"action": "performMatch",
68+
payload: {
12469
matcherDefinition,
12570
problemPatterns,
12671
}
@@ -129,9 +74,9 @@ const cbcodeutils = {
12974
const response = JSON.parse(data);
13075
if (response.type === "getgetJsTreeResponse") {
13176
resolve(response); // Resolve the Promise with the response data
132-
}
77+
}
13378
});
134-
});
79+
});
13580
},
13681

13782
/**
@@ -142,15 +87,15 @@ const cbcodeutils = {
14287
return new Promise((resolve, reject) => {
14388
cbws.getWebsocket.send(JSON.stringify({
14489
"type": "codeEvent",
145-
"action":"getMatcherList",
90+
"action": "getMatcherList",
14691
}));
14792
cbws.getWebsocket.on('message', (data: string) => {
14893
const response = JSON.parse(data);
14994
if (response.type === "getMatcherListTreeResponse") {
15095
resolve(response); // Resolve the Promise with the response data
151-
}
96+
}
15297
});
153-
});
98+
});
15499
},
155100

156101
/**
@@ -162,18 +107,18 @@ const cbcodeutils = {
162107
return new Promise((resolve, reject) => {
163108
cbws.getWebsocket.send(JSON.stringify({
164109
"type": "codeEvent",
165-
"action":"getMatchDetail",
166-
payload:{
167-
match:matcher
110+
"action": "getMatchDetail",
111+
payload: {
112+
match: matcher
168113
}
169114
}));
170115
cbws.getWebsocket.on('message', (data: string) => {
171116
const response = JSON.parse(data);
172117
if (response.type === "matchDetailTreeResponse") {
173118
resolve(response); // Resolve the Promise with the response data
174-
}
119+
}
175120
});
176-
});
121+
});
177122
}
178123

179124
};

0 commit comments

Comments
 (0)