@codebolt/codeboltjs 1.1.78 → 1.1.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,57 @@ const cbcodeutils = {
14
14
  * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
15
15
  */
16
16
  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
+ // });
17
68
  return new Promise(async (resolve, reject) => {
18
69
  websocket_1.default.getWebsocket.send(JSON.stringify({
19
70
  "type": "codeEvent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.78",
3
+ "version": "1.1.80",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -20,6 +20,8 @@
20
20
  "dependencies": {
21
21
  "@codebolt/types": "^1.0.10",
22
22
  "js-yaml": "^4.1.0",
23
+ "tree-sitter": "^0.21.1",
24
+ "tree-sitter-javascript": "^0.23.1",
23
25
  "typedoc-plugin-missing-exports": "^2.2.0",
24
26
  "ws": "^8.17.0"
25
27
  },
@@ -40,4 +42,4 @@
40
42
  "jest": {
41
43
  "testTimeout": 50000
42
44
  }
43
- }
45
+ }
@@ -1,8 +1,8 @@
1
1
  import cbws from './websocket';
2
2
  import * as fs from 'fs';
3
3
  import path from 'path';
4
- // import Parser from 'tree-sitter';
5
- // import JavaScript from 'tree-sitter-javascript';
4
+ import Parser from 'tree-sitter';
5
+ import JavaScript from 'tree-sitter-javascript';
6
6
 
7
7
  import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
8
8
 
@@ -17,6 +17,64 @@ const cbcodeutils = {
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
+
77
+ // });
20
78
  return new Promise(async (resolve, reject) => {
21
79
  cbws.getWebsocket.send(JSON.stringify({
22
80
  "type": "codeEvent",