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
@@ -16,77 +16,77 @@ const cbcodeutils = {
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
- getJsTree : ( filePath ?: string ) : Promise < any > => {
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 = [ ] ;
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
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 } ) ;
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
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
- } ;
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
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
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
64
65
- trees . push ( tree ) ;
66
- }
65
+ // trees.push(tree);
66
+ // }
67
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
- } ) ;
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
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
- } ) ;
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
+ // });
90
90
} ,
91
91
92
92
/**
0 commit comments