1
1
import cbws from './websocket' ;
2
+ import { GetJsTreeResponse , MatchProblemResponse , GetMatcherListTreeResponse , getMatchDetail } from '@codebolt/types' ;
2
3
3
4
/**
4
5
* A utility module for working with code.
5
6
*/
6
7
const cbcodeutils = {
7
-
8
8
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 > => {
24
15
return new Promise ( ( resolve , reject ) => {
25
16
cbws . getWebsocket . send ( JSON . stringify ( {
26
17
"type" : "codeEvent" ,
@@ -32,12 +23,17 @@ const cbcodeutils = {
32
23
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
33
24
const response = JSON . parse ( data ) ;
34
25
if ( response . type === "getJsTreeResponse" ) {
35
- resolve ( resolve ) ; // Resolve the Promise with the response data
26
+ resolve ( response ) ; // Resolve the Promise with the response data
36
27
}
37
28
} ) ;
38
29
} ) ;
39
30
} ,
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 > => {
41
37
return new Promise ( ( resolve , reject ) => {
42
38
cbws . getWebsocket . send ( JSON . stringify ( {
43
39
"type" : "codeEvent" ,
@@ -46,12 +42,20 @@ const cbcodeutils = {
46
42
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
47
43
const response = JSON . parse ( data ) ;
48
44
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
50
46
}
51
47
} ) ;
52
48
} ) ;
53
49
} ,
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 > => {
55
59
return new Promise ( ( resolve , reject ) => {
56
60
cbws . getWebsocket . send ( JSON . stringify ( {
57
61
"type" : "codeEvent" ,
@@ -64,40 +68,49 @@ const cbcodeutils = {
64
68
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
65
69
const response = JSON . parse ( data ) ;
66
70
if ( response . type === "getgetJsTreeResponse" ) {
67
- resolve ( resolve ) ; // Resolve the Promise with the response data
71
+ resolve ( response ) ; // Resolve the Promise with the response data
68
72
}
69
73
} ) ;
70
74
} ) ;
71
75
} ,
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 > => {
73
82
return new Promise ( ( resolve , reject ) => {
74
83
cbws . getWebsocket . send ( JSON . stringify ( {
75
84
"type" : "codeEvent" ,
76
85
"action" :"getMatcherList" ,
77
-
78
86
} ) ) ;
79
87
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
80
88
const response = JSON . parse ( data ) ;
81
89
if ( response . type === "getMatcherListTreeResponse" ) {
82
- resolve ( resolve ) ; // Resolve the Promise with the response data
90
+ resolve ( response ) ; // Resolve the Promise with the response data
83
91
}
84
92
} ) ;
85
93
} ) ;
86
94
} ,
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 > => {
88
102
return new Promise ( ( resolve , reject ) => {
89
103
cbws . getWebsocket . send ( JSON . stringify ( {
90
104
"type" : "codeEvent" ,
91
105
"action" :"getMatchDetail" ,
92
106
payload :{
93
107
match :matcher
94
108
}
95
-
96
109
} ) ) ;
97
110
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
98
111
const response = JSON . parse ( data ) ;
99
112
if ( response . type === "matchDetailTreeResponse" ) {
100
- resolve ( resolve ) ; // Resolve the Promise with the response data
113
+ resolve ( response ) ; // Resolve the Promise with the response data
101
114
}
102
115
} ) ;
103
116
} ) ;
0 commit comments