11import cbws from './websocket' ;
2+ import { GetJsTreeResponse , MatchProblemResponse , GetMatcherListTreeResponse , getMatchDetail } from '@codebolt/types' ;
23
34/**
45 * A utility module for working with code.
56 */
67const cbcodeutils = {
7-
88
9- getCodeTree : ( ) : Promise < any > => {
10- return new Promise ( ( resolve , reject ) => {
11- cbws . getWebsocket . send ( JSON . stringify ( {
12- "type" : "codeEvent" ,
13- "action" :"getCodeTree"
14- } ) ) ;
15- cbws . getWebsocket . on ( 'message' , ( data : string ) => {
16- const response = JSON . parse ( data ) ;
17- if ( response . type === "getCodeTreeResponse" ) {
18- resolve ( response . markdown ) ; // Resolve the Promise with the response data
19- }
20- } ) ;
21- } ) ;
22- } ,
23- getJsTree : ( filePath :string ) : Promise < any > => {
9+ /**
10+ * Retrieves a JavaScript tree structure for a given file path.
11+ * @param {string } filePath - The path of the file to retrieve the JS tree for.
12+ * @returns {Promise<GetJsTreeResponse> } A promise that resolves with the JS tree response.
13+ */
14+ getJsTree : ( filePath : string ) : Promise < GetJsTreeResponse > => {
2415 return new Promise ( ( resolve , reject ) => {
2516 cbws . getWebsocket . send ( JSON . stringify ( {
2617 "type" : "codeEvent" ,
@@ -32,12 +23,17 @@ const cbcodeutils = {
3223 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
3324 const response = JSON . parse ( data ) ;
3425 if ( response . type === "getJsTreeResponse" ) {
35- resolve ( resolve ) ; // Resolve the Promise with the response data
26+ resolve ( response ) ; // Resolve the Promise with the response data
3627 }
3728 } ) ;
3829 } ) ;
3930 } ,
40- getAllFilesAsMarkDown :( ) => {
31+
32+ /**
33+ * Retrieves all files as Markdown.
34+ * @returns {Promise<string> } A promise that resolves with the Markdown content of all files.
35+ */
36+ getAllFilesAsMarkDown : ( ) : Promise < string > => {
4137 return new Promise ( ( resolve , reject ) => {
4238 cbws . getWebsocket . send ( JSON . stringify ( {
4339 "type" : "codeEvent" ,
@@ -46,12 +42,20 @@ const cbcodeutils = {
4642 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
4743 const response = JSON . parse ( data ) ;
4844 if ( response . type === "getAllFilesMarkdownResponse" ) {
49- resolve ( response . markdown ) ; // Resolve the Promise with the response data
45+ resolve ( response ) ; // Resolve the Promise with the response data
5046 }
5147 } ) ;
5248 } ) ;
5349 } ,
54- performMatch :( matcherDefinition :object , problemPatterns :[ ] , problems :[ ] ) => {
50+
51+ /**
52+ * Performs a matching operation based on the provided matcher definition and problem patterns.
53+ * @param {object } matcherDefinition - The definition of the matcher.
54+ * @param {Array } problemPatterns - The patterns to match against.
55+ * @param {Array } problems - The list of problems.
56+ * @returns {Promise<MatchProblemResponse> } A promise that resolves with the matching problem response.
57+ */
58+ performMatch : ( matcherDefinition : object , problemPatterns : any [ ] , problems : any [ ] ) : Promise < MatchProblemResponse > => {
5559 return new Promise ( ( resolve , reject ) => {
5660 cbws . getWebsocket . send ( JSON . stringify ( {
5761 "type" : "codeEvent" ,
@@ -64,40 +68,49 @@ const cbcodeutils = {
6468 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
6569 const response = JSON . parse ( data ) ;
6670 if ( response . type === "getgetJsTreeResponse" ) {
67- resolve ( resolve ) ; // Resolve the Promise with the response data
71+ resolve ( response ) ; // Resolve the Promise with the response data
6872 }
6973 } ) ;
7074 } ) ;
7175 } ,
72- getMatcherList :( ) => {
76+
77+ /**
78+ * Retrieves the list of matchers.
79+ * @returns {Promise<GetMatcherListTreeResponse> } A promise that resolves with the list of matchers response.
80+ */
81+ getMatcherList : ( ) : Promise < GetMatcherListTreeResponse > => {
7382 return new Promise ( ( resolve , reject ) => {
7483 cbws . getWebsocket . send ( JSON . stringify ( {
7584 "type" : "codeEvent" ,
7685 "action" :"getMatcherList" ,
77-
7886 } ) ) ;
7987 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
8088 const response = JSON . parse ( data ) ;
8189 if ( response . type === "getMatcherListTreeResponse" ) {
82- resolve ( resolve ) ; // Resolve the Promise with the response data
90+ resolve ( response ) ; // Resolve the Promise with the response data
8391 }
8492 } ) ;
8593 } ) ;
8694 } ,
87- matchDetail :( matcher :string ) => {
95+
96+ /**
97+ * Retrieves details of a match.
98+ * @param {string } matcher - The matcher to retrieve details for.
99+ * @returns {Promise<getMatchDetail> } A promise that resolves with the match detail response.
100+ */
101+ matchDetail : ( matcher : string ) : Promise < getMatchDetail > => {
88102 return new Promise ( ( resolve , reject ) => {
89103 cbws . getWebsocket . send ( JSON . stringify ( {
90104 "type" : "codeEvent" ,
91105 "action" :"getMatchDetail" ,
92106 payload :{
93107 match :matcher
94108 }
95-
96109 } ) ) ;
97110 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
98111 const response = JSON . parse ( data ) ;
99112 if ( response . type === "matchDetailTreeResponse" ) {
100- resolve ( resolve ) ; // Resolve the Promise with the response data
113+ resolve ( response ) ; // Resolve the Promise with the response data
101114 }
102115 } ) ;
103116 } ) ;
0 commit comments