@@ -135,8 +135,14 @@ export enum ActionType {
135
135
WebSocketConnected = 'WEBSOCKET_CONNECTED' ,
136
136
WebSocketDisconnected = 'WEBSOCKET_DISCONNECTED' ,
137
137
WebSocketFeatureFlagEnabled = 'WEBSOCKET_FEATURE_FLAG_ENABLED' ,
138
+ WSRequest = 'WS_REQUEST' ,
139
+ WSResponse = 'WS_RESPONSE' ,
140
+ WSStdoutPacket = 'WS_STDOUT_PACKET' ,
141
+ WSStderrPacket = 'WS_STDERR_PACKET' ,
138
142
WSExecuteRequest = 'WS_EXECUTE_REQUEST' ,
139
143
WSExecuteResponse = 'WS_EXECUTE_RESPONSE' ,
144
+ WSCompileRequest = 'WS_COMPILE_REQUEST' ,
145
+ WSCompileResponse = 'WS_COMPILE_RESPONSE' ,
140
146
}
141
147
142
148
export const WebSocketError = z . object ( {
@@ -159,6 +165,16 @@ export const WSExecuteResponse = z.object({
159
165
} ) ;
160
166
export type WSExecuteResponse = z . infer < typeof WSExecuteResponse > ;
161
167
168
+ export const WSCompileResponse = z . object ( {
169
+ type : z . literal ( ActionType . WSCompileResponse ) ,
170
+ success : z . boolean ( ) ,
171
+ code : z . string ( ) ,
172
+ stdout : z . string ( ) ,
173
+ stderr : z . string ( ) ,
174
+ extra : ExecuteExtra ,
175
+ } ) ;
176
+ export type WSCompileResponse = z . infer < typeof WSCompileResponse > ;
177
+
162
178
export const initializeApplication = ( ) => createAction ( ActionType . InitializeApplication ) ;
163
179
164
180
export const disableSyncChangesToStorage = ( ) => createAction ( ActionType . DisableSyncChangesToStorage ) ;
@@ -363,8 +379,6 @@ function performCompileShow(
363
379
} ) : ThunkAction {
364
380
// TODO: Check a cache
365
381
return function ( dispatch , getState ) {
366
- dispatch ( request ( ) ) ;
367
-
368
382
const state = getState ( ) ;
369
383
const code = codeSelector ( state ) ;
370
384
const { configuration : {
@@ -378,23 +392,29 @@ function performCompileShow(
378
392
const crateType = getCrateType ( state ) ;
379
393
const tests = runAsTest ( state ) ;
380
394
const backtrace = state . configuration . backtrace === Backtrace . Enabled ;
381
- const body : CompileRequestBody = {
382
- channel,
383
- mode,
384
- edition,
385
- crateType,
386
- tests,
387
- code,
388
- target,
389
- assemblyFlavor,
390
- demangleAssembly,
391
- processAssembly,
392
- backtrace,
393
- } ;
394
395
395
- return jsonPost < CompileResponseBody > ( routes . compile , body )
396
- . then ( json => dispatch ( success ( json ) ) )
397
- . catch ( json => dispatch ( failure ( json ) ) ) ;
396
+ if ( useWebsocketSelector ( state ) ) {
397
+ return dispatch ( wsCompileRequest ( channel , mode , edition , crateType , tests , code , target , assemblyFlavor , demangleAssembly , processAssembly , backtrace ) ) ;
398
+ } else {
399
+ dispatch ( request ( ) ) ;
400
+ const body : CompileRequestBody = {
401
+ channel,
402
+ mode,
403
+ edition,
404
+ crateType,
405
+ tests,
406
+ code,
407
+ target,
408
+ assemblyFlavor,
409
+ demangleAssembly,
410
+ processAssembly,
411
+ backtrace,
412
+ } ;
413
+
414
+ return jsonPost < CompileResponseBody > ( routes . compile , body )
415
+ . then ( json => dispatch ( success ( json ) ) )
416
+ . catch ( json => dispatch ( failure ( json ) ) ) ;
417
+ }
398
418
} ;
399
419
}
400
420
@@ -526,6 +546,34 @@ const wsExecuteRequest = (
526
546
extra : makeExtra ( ) ,
527
547
} ) ;
528
548
549
+ const wsCompileRequest = (
550
+ channel : Channel ,
551
+ mode : Mode ,
552
+ edition : Edition ,
553
+ crateType : string ,
554
+ tests : boolean ,
555
+ code : string ,
556
+ target : string ,
557
+ assemblyFlavor : AssemblyFlavor ,
558
+ demangleAssembly : DemangleAssembly ,
559
+ processAssembly : ProcessAssembly ,
560
+ backtrace : boolean
561
+ ) =>
562
+ createAction ( ActionType . WSCompileRequest , {
563
+ channel,
564
+ mode,
565
+ edition,
566
+ crateType,
567
+ tests,
568
+ code,
569
+ target,
570
+ assemblyFlavor,
571
+ demangleAssembly,
572
+ processAssembly,
573
+ backtrace,
574
+ extra : makeExtra ( ) ,
575
+ } ) ;
576
+
529
577
export const performPrimaryAction = ( ) : ThunkAction => ( dispatch , getState ) => {
530
578
const state = getState ( ) ;
531
579
const primaryAction = PRIMARY_ACTIONS [ state . configuration . primaryAction ] ;
@@ -1036,5 +1084,7 @@ export type Action =
1036
1084
| ReturnType < typeof websocketDisconnected >
1037
1085
| ReturnType < typeof websocketFeatureFlagEnabled >
1038
1086
| ReturnType < typeof wsExecuteRequest >
1087
+ | ReturnType < typeof wsCompileRequest >
1039
1088
| WSExecuteResponse
1089
+ | WSCompileResponse
1040
1090
;
0 commit comments