@@ -107,6 +107,12 @@ function timeout(ms: number): Promise<never> {
107
107
) ;
108
108
}
109
109
110
+ function formatResponseText ( text : string ) : string {
111
+ return text
112
+ . replace ( / t i m e / gi, '<span style="color: lightgreen;">time complexity</span>' )
113
+ . replace ( / s p a c e / gi, '<span style="color: lightgreen;">space complexity</span>' ) ;
114
+ }
115
+
110
116
function processCode (
111
117
chatGPTProvider : ChatGPTProvider ,
112
118
codeText : string ,
@@ -154,21 +160,28 @@ function processCode(
154
160
prompt : prompt ,
155
161
onEvent : ( event : { type : string ; data ?: { text : string } } ) => {
156
162
if ( event . type === 'answer' && event . data ) {
157
- response += event . data . text ;
158
163
if ( action === 'fix' && fixCodeResponse ) {
164
+ response += event . data . text ;
159
165
fixCodeResponse . textContent = response ;
166
+ ( window as any ) . Prism . highlightAll ( ) ;
167
+
160
168
}
161
169
else if ( action === 'analyze' && analyzeCodeResponse ) {
162
- analyzeCodeResponse . textContent = response ;
170
+ response += formatResponseText ( event . data . text ) ; // Use the helper function here
171
+ analyzeCodeResponse . innerHTML = response ;
163
172
}
164
173
}
165
174
if ( event . type === 'done' ) {
166
- analyzeCodeResponse && chrome . storage . local . set ( { 'analyzeCodeResponse' : analyzeCodeResponse . textContent } ) ;
167
- fixCodeResponse && chrome . storage . local . set ( { 'fixCodeResponse' : fixCodeResponse . textContent } ) ;
175
+ disableAllButtons ( false ) ;
168
176
chrome . storage . local . set ( { 'lastAction' : action } ) ;
169
177
infoMessage && ( infoMessage . textContent = problemTitle ) ;
170
- disableAllButtons ( false ) ;
171
- ( window as any ) . Prism . highlightAll ( ) ;
178
+ if ( action === 'fix' ) {
179
+ fixCodeResponse && chrome . storage . local . set ( { 'fixCodeResponse' : fixCodeResponse . textContent } ) ;
180
+ ( window as any ) . Prism . highlightAll ( ) ;
181
+ }
182
+ if ( action === 'analyze' ) {
183
+ analyzeCodeResponse && chrome . storage . local . set ( { 'analyzeCodeResponse' : analyzeCodeResponse . innerHTML } ) ;
184
+ }
172
185
}
173
186
} ,
174
187
} ) ,
@@ -209,7 +222,7 @@ async function main(): Promise<void> {
209
222
210
223
chrome . storage . local . get ( 'analyzeCodeResponse' , function ( data ) {
211
224
if ( data . analyzeCodeResponse ) {
212
- analyzeCodeResponse && ( analyzeCodeResponse . textContent = data . analyzeCodeResponse ) ;
225
+ analyzeCodeResponse && ( analyzeCodeResponse . innerHTML = data . analyzeCodeResponse ) ;
213
226
( window as any ) . Prism . highlightAll ( ) ;
214
227
}
215
228
} ) ;
0 commit comments