@@ -25,6 +25,7 @@ import { firstToUpperCase, firstToLowerCase } from '../common/utils';
25
25
import { Port } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb' ;
26
26
import { nls } from '@theia/core' ;
27
27
import { MonitorManager } from './monitor-manager' ;
28
+ import { OutputPanelBufferProvider } from './output-panel-buffer-provider' ;
28
29
29
30
@injectable ( )
30
31
export class CoreServiceImpl extends CoreClientAware implements CoreService {
@@ -39,25 +40,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
39
40
40
41
protected uploading = false ;
41
42
42
- private outputString : string ;
43
-
44
43
private FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS = 32 ;
45
44
46
- private flushOutputMessagesInterval ?: NodeJS . Timeout ;
47
-
48
- setOutputMessagesInterval ( ) : void {
49
- this . flushOutputMessagesInterval = setInterval ( ( ) => {
50
- this . responseService . appendToOutput ( {
51
- chunk : this . outputString ,
52
- } ) ;
53
- } , this . FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS ) ;
54
- }
55
-
56
- clearOutputMessagesInterval ( ) : void {
57
- clearInterval ( this . flushOutputMessagesInterval ) ;
58
- this . flushOutputMessagesInterval = undefined ;
59
- }
60
-
61
45
async compile (
62
46
options : CoreService . Compile . Options & {
63
47
exportBinaries ?: boolean ;
@@ -92,18 +76,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
92
76
this . mergeSourceOverrides ( compileReq , options ) ;
93
77
94
78
const result = client . compile ( compileReq ) ;
79
+
80
+ const compileBuffer = new OutputPanelBufferProvider (
81
+ this . flushOutputPanelMessages ,
82
+ this . FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
83
+ ) ;
95
84
try {
96
85
await new Promise < void > ( ( resolve , reject ) => {
97
86
result . on ( 'data' , ( cr : CompileResponse ) => {
98
- this . responseService . appendToOutput ( {
99
- chunk : Buffer . from ( cr . getOutStream_asU8 ( ) ) . toString ( ) ,
100
- } ) ;
101
- this . responseService . appendToOutput ( {
102
- chunk : Buffer . from ( cr . getErrStream_asU8 ( ) ) . toString ( ) ,
103
- } ) ;
87
+ compileBuffer . addChunk ( cr . getOutStream_asU8 ( ) ) ;
88
+ compileBuffer . addChunk ( cr . getErrStream_asU8 ( ) ) ;
89
+ } ) ;
90
+ result . on ( 'error' , ( error ) => {
91
+ compileBuffer . clearFlushInterval ( ) ;
92
+ reject ( error ) ;
93
+ } ) ;
94
+ result . on ( 'end' , ( ) => {
95
+ compileBuffer . clearFlushInterval ( ) ;
96
+ resolve ( ) ;
104
97
} ) ;
105
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
106
- result . on ( 'end' , ( ) => resolve ( ) ) ;
107
98
} ) ;
108
99
this . responseService . appendToOutput ( {
109
100
chunk : '\n--------------------------\nCompilation complete.\n' ,
@@ -193,19 +184,22 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
193
184
194
185
const result = responseHandler ( client , req ) ;
195
186
196
- this . setOutputMessagesInterval ( ) ;
197
-
187
+ const uploadBuffer = new OutputPanelBufferProvider (
188
+ this . flushOutputPanelMessages ,
189
+ this . FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
190
+ ) ;
198
191
try {
199
192
await new Promise < void > ( ( resolve , reject ) => {
200
193
result . on ( 'data' , ( resp : UploadResponse ) => {
201
- this . outputString =
202
- this . outputString +
203
- Buffer . from ( resp . getOutStream_asU8 ( ) ) . toString ( ) +
204
- Buffer . from ( resp . getErrStream_asU8 ( ) ) . toString ( ) ;
194
+ uploadBuffer . addChunk ( resp . getOutStream_asU8 ( ) ) ;
195
+ uploadBuffer . addChunk ( resp . getErrStream_asU8 ( ) ) ;
196
+ } ) ;
197
+ result . on ( 'error' , ( error ) => {
198
+ uploadBuffer . clearFlushInterval ( ) ;
199
+ reject ( error ) ;
205
200
} ) ;
206
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
207
201
result . on ( 'end' , ( ) => {
208
- this . clearOutputMessagesInterval ( ) ;
202
+ uploadBuffer . clearFlushInterval ( ) ;
209
203
resolve ( ) ;
210
204
} ) ;
211
205
} ) ;
@@ -260,18 +254,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
260
254
burnReq . setVerify ( options . verify ) ;
261
255
burnReq . setVerbose ( options . verbose ) ;
262
256
const result = client . burnBootloader ( burnReq ) ;
257
+
258
+ const bootloaderBuffer = new OutputPanelBufferProvider (
259
+ this . flushOutputPanelMessages ,
260
+ this . FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
261
+ ) ;
263
262
try {
264
263
await new Promise < void > ( ( resolve , reject ) => {
265
264
result . on ( 'data' , ( resp : BurnBootloaderResponse ) => {
266
- this . responseService . appendToOutput ( {
267
- chunk : Buffer . from ( resp . getOutStream_asU8 ( ) ) . toString ( ) ,
268
- } ) ;
269
- this . responseService . appendToOutput ( {
270
- chunk : Buffer . from ( resp . getErrStream_asU8 ( ) ) . toString ( ) ,
271
- } ) ;
265
+ bootloaderBuffer . addChunk ( resp . getOutStream_asU8 ( ) ) ;
266
+ bootloaderBuffer . addChunk ( resp . getErrStream_asU8 ( ) ) ;
267
+ } ) ;
268
+ result . on ( 'error' , ( error ) => {
269
+ bootloaderBuffer . clearFlushInterval ( ) ;
270
+ reject ( error ) ;
271
+ } ) ;
272
+ result . on ( 'end' , ( ) => {
273
+ bootloaderBuffer . clearFlushInterval ( ) ;
274
+ resolve ( ) ;
272
275
} ) ;
273
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
274
- result . on ( 'end' , ( ) => resolve ( ) ) ;
275
276
} ) ;
276
277
} catch ( e ) {
277
278
const errorMessage = nls . localize (
@@ -303,4 +304,13 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
303
304
}
304
305
}
305
306
}
307
+
308
+ private flushOutputPanelMessages ( chunk : string ) : void {
309
+ this . responseService . appendToOutput ( {
310
+ chunk,
311
+ } ) ;
312
+ this . responseService . appendToOutput ( {
313
+ chunk,
314
+ } ) ;
315
+ }
306
316
}
0 commit comments